From decef894bdd3adf991a7d96300ee32c9fc41aa6d Mon Sep 17 00:00:00 2001 From: randomuser Date: Tue, 3 Jan 2023 23:28:16 -0600 Subject: [PATCH] add xgetnewwindow, which waits the creation of a new window in the xorg server --- c/xgetnewwindow.c | 29 +++++++++++++++++++++++++++++ man/xgetnewwindow.1 | 10 ++++++++++ 2 files changed, 39 insertions(+) create mode 100644 c/xgetnewwindow.c create mode 100644 man/xgetnewwindow.1 diff --git a/c/xgetnewwindow.c b/c/xgetnewwindow.c new file mode 100644 index 0000000..923ee64 --- /dev/null +++ b/c/xgetnewwindow.c @@ -0,0 +1,29 @@ +#include +#include + +int main(void) { + Display* display = XOpenDisplay(NULL); + if(!display) { + printf("Error: Unable to open display.\n"); + return 1; + } + + int screen = DefaultScreen(display); + Window root = RootWindow(display, screen); + + /* SubstructureNotifyMask allows us to be notified of CreateNotify events */ + XSelectInput(display, root, SubstructureNotifyMask); + + XEvent event; + for(;;) { + XNextEvent(display, &event); + if(event.type == CreateNotify) { + /* print window id */ + printf("0x%x\n", event.xcreatewindow.window); + break; + } + } + + XCloseDisplay(display); + return 0; +} diff --git a/man/xgetnewwindow.1 b/man/xgetnewwindow.1 new file mode 100644 index 0000000..8c5adab --- /dev/null +++ b/man/xgetnewwindow.1 @@ -0,0 +1,10 @@ +.TH XGETNEWWINDOW 1 xgetnewwindow +.SH NAME +xgetnewwindow +.SH SYNOPSIS +xgetnewwindow blocks until it recieves a CreateNotify event; that is, until a new window is created within the current Xorg instance. Once a new window is created, xgetnewwindow prints the window id (in hexadecimal) to stdout and exits. +.SH EXIT CODES +1 for abnormal termination, 0 for success. +.SH AUTHOR +randomuser +