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 +