Create and set up window
This commit is contained in:
@@ -14,3 +14,6 @@ if(${SANITIZERS})
|
|||||||
target_compile_options(maze-thing PRIVATE -fsanitize=address,undefined)
|
target_compile_options(maze-thing PRIVATE -fsanitize=address,undefined)
|
||||||
target_link_options(maze-thing PRIVATE -fsanitize=address,undefined)
|
target_link_options(maze-thing PRIVATE -fsanitize=address,undefined)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
find_package(X11 REQUIRED)
|
||||||
|
target_link_libraries(maze-thing PRIVATE X11::X11)
|
||||||
|
|||||||
46
main.c
46
main.c
@@ -3,7 +3,53 @@
|
|||||||
* SPDX-License-Identifier: AGPL-3.0-only
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <X11/Xlib.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#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)
|
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;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user