diff --git a/CMakeLists.txt b/CMakeLists.txt index 915582c..81057d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,3 +14,6 @@ if(${SANITIZERS}) target_compile_options(maze-thing PRIVATE -fsanitize=address,undefined) target_link_options(maze-thing PRIVATE -fsanitize=address,undefined) endif() + +find_package(X11 REQUIRED) +target_link_libraries(maze-thing PRIVATE X11::X11) diff --git a/main.c b/main.c index b18075b..e39b4bd 100644 --- a/main.c +++ b/main.c @@ -3,7 +3,53 @@ * 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; }