2026-06-06 23:30:07 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <X11/Xlib.h>
|
2026-06-07 00:23:58 -04:00
|
|
|
#include <X11/Xutil.h>
|
2026-06-06 23:30:07 -04:00
|
|
|
|
|
|
|
|
int main()
|
|
|
|
|
{
|
|
|
|
|
Display *display = XOpenDisplay(NULL);
|
|
|
|
|
Window main_window = XDefaultRootWindow(display);
|
2026-06-07 01:59:52 -04:00
|
|
|
int screen = DefaultScreen(display);
|
|
|
|
|
GC context = XDefaultGC(display, screen);
|
|
|
|
|
|
|
|
|
|
XSetWindowAttributes attributes = {};
|
|
|
|
|
attributes.background_pixel = 0xffffccaa;
|
|
|
|
|
attributes.event_mask = ResizeRedirectMask | ExposureMask;
|
|
|
|
|
Window window = XCreateWindow(display, main_window,
|
|
|
|
|
0, 0, 1920, 1080,
|
|
|
|
|
1, CopyFromParent, CopyFromParent, CopyFromParent,
|
|
|
|
|
CWBackPixel | CWEventMask, &attributes);
|
|
|
|
|
|
2026-06-06 23:30:07 -04:00
|
|
|
XMapWindow(display, window);
|
|
|
|
|
XFlush(display);
|
|
|
|
|
|
2026-06-07 00:23:58 -04:00
|
|
|
Atom WM_DELETE_WINDOW = XInternAtom(display, "WM_DELETE_WINDOW", False);
|
|
|
|
|
if(!XSetWMProtocols(display, window, &WM_DELETE_WINDOW, 1))
|
|
|
|
|
{
|
2026-06-07 00:26:17 -04:00
|
|
|
printf("Couldn't register WM_DELETE_WINDOW property \n");
|
2026-06-07 00:23:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int is_open = 1;
|
|
|
|
|
while(is_open)
|
|
|
|
|
{
|
|
|
|
|
XEvent general_event = {};
|
2026-06-07 00:26:17 -04:00
|
|
|
XNextEvent(display, &general_event);
|
2026-06-07 00:23:58 -04:00
|
|
|
|
2026-06-07 01:59:52 -04:00
|
|
|
printf("Type: %d \n", general_event.type);
|
2026-06-07 00:23:58 -04:00
|
|
|
switch(general_event.type)
|
|
|
|
|
{
|
|
|
|
|
case ClientMessage:
|
2026-06-07 00:26:17 -04:00
|
|
|
{
|
|
|
|
|
XClientMessageEvent *event = (XClientMessageEvent *) &general_event;
|
|
|
|
|
if((Atom)event->data.l[0] == WM_DELETE_WINDOW) {
|
|
|
|
|
XDestroyWindow(display, window);
|
|
|
|
|
is_open = 0;
|
|
|
|
|
printf("Window destroyed \n");
|
|
|
|
|
}
|
|
|
|
|
} break;
|
2026-06-07 01:24:14 -04:00
|
|
|
case ResizeRequest:
|
|
|
|
|
{
|
|
|
|
|
static unsigned long color = 0x00aade87;
|
|
|
|
|
if(color == 0x00aade87)
|
2026-06-07 01:59:52 -04:00
|
|
|
color = 0xd000d087;
|
2026-06-07 01:24:14 -04:00
|
|
|
else
|
|
|
|
|
color = 0x00aade87;
|
|
|
|
|
|
|
|
|
|
XSetWindowBackground(display, window, color);
|
|
|
|
|
} break;
|
2026-06-07 00:23:58 -04:00
|
|
|
}
|
2026-06-07 01:59:52 -04:00
|
|
|
|
|
|
|
|
XClearWindow(display, window);
|
2026-06-07 00:23:58 -04:00
|
|
|
}
|
2026-06-06 23:30:07 -04:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|