/* * Copyright (c) Camden Dixie O'Brien * SPDX-License-Identifier: AGPL-3.0-only */ #include #include #include #include #include #define MAZE_SIZE 24 #define GRID_SIZE (2 * MAZE_SIZE - 1) #define MARGIN 2 #define WALL_THICKNESS 1 #define WINDOW_SIZE (GRID_SIZE + 2 * (WALL_THICKNESS + MARGIN)) #define PX(x) ((x) << 3) int main(void) { XEvent evt; Display *dpy = XOpenDisplay(NULL); assert(dpy); // Create window and configure graphics context const int black = BlackPixel(dpy, DefaultScreen(dpy)); const int white = WhitePixel(dpy, DefaultScreen(dpy)); Window w = XCreateSimpleWindow( dpy, DefaultRootWindow(dpy), 0, 0, PX(WINDOW_SIZE), PX(WINDOW_SIZE), 0, white, white); Atom del = XInternAtom(dpy, "WM_DELETE_WINDOW", false); XSetWMProtocols(dpy, w, &del, 1); GC gc = DefaultGC(dpy, DefaultScreen(dpy)); XSetForeground(dpy, gc, black); // Map window XSelectInput(dpy, w, StructureNotifyMask); XMapWindow(dpy, w); do XNextEvent(dpy, &evt); while (MapNotify != evt.type); // Wait for window exit bool is_del = false; do { XNextEvent(dpy, &evt); if (ClientMessage == evt.type) is_del = (unsigned long)evt.xclient.data.l[0] == del; } while (!is_del); XCloseDisplay(dpy); return EXIT_SUCCESS; }