add xgetnewwindow, which waits the creation of a new window in the xorg server

This commit is contained in:
randomuser 2023-01-03 23:28:16 -06:00
parent ca3faec6ce
commit decef894bd
2 changed files with 39 additions and 0 deletions

29
c/xgetnewwindow.c Normal file
View File

@ -0,0 +1,29 @@
#include <X11/Xlib.h>
#include <stdio.h>
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;
}

10
man/xgetnewwindow.1 Normal file
View File

@ -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