Untitled
unknown
c_cpp
3 years ago
1.8 kB
8
Indexable
#include <stdio.h>
#include <X11/Xlib.h>
#define WINDOW_COUNT 2
void draw_header_bar(Display *display, Window window, GC gc, const char *title) {
XDrawRectangle(display, window, gc, 0, 0, 799, 30);
XDrawString(display, window, gc, 10, 20, title, strlen(title));
}
int main() {
Display *display;
Window windows[WINDOW_COUNT];
XEvent event;
int screen;
display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Erro ao abrir o display.\n");
return 1;
}
screen = DefaultScreen(display);
// Criar várias janelas simples
for (int i = 0; i < WINDOW_COUNT; ++i) {
windows[i] = XCreateSimpleWindow(display, RootWindow(display, screen),
10 + i * 50, 10 + i * 50, 800, 600, 1,
BlackPixel(display, screen), WhitePixel(display, screen));
XSelectInput(display, windows[i], ExposureMask | KeyPressMask);
XMapWindow(display, windows[i]);
}
GC gc = XCreateGC(display, windows[0], 0, NULL);
while (1) {
XNextEvent(display, &event);
for (int i = 0; i < WINDOW_COUNT; ++i) {
if (event.xany.window == windows[i]) {
if (event.type == Expose) {
char title[32];
snprintf(title, sizeof(title), "Janela %d", i + 1);
draw_header_bar(display, windows[i], gc, title);
} else if (event.type == KeyPress) {
KeySym key = XLookupKeysym(&event.xkey, 0);
if (key == 'q') {
XCloseDisplay(display);
return 0;
}
}
}
}
}
return 0;
}
Editor is loading...