Created
August 10, 2023 09:45
-
-
Save leite/af3813fd6d4dde2bac0d42abc393ab05 to your computer and use it in GitHub Desktop.
list windows, coordinates, geometry and title
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <X11/Xutil.h> | |
/** | |
* $ gcc windows.c -o windows -lX11 && ./windows | |
*/ | |
int main () { | |
Atom actual_type; | |
int format; | |
unsigned long n_items, b_after; | |
unsigned char *data = 0; | |
Display *display = XOpenDisplay(NULL); | |
Window root = DefaultRootWindow(display); | |
Atom a = XInternAtom(display, "_NET_CLIENT_LIST", 1); | |
int status = XGetWindowProperty( | |
display, root, a, 0L, (~0L), 0, AnyPropertyType, | |
&actual_type, &format, &n_items, &b_after, &data | |
); | |
printf("xid\t\tx\ty\tw\th\ttitle\n"); | |
if (status >= Success && n_items) { | |
long *array = (long*) data; | |
for (long k = 0; k < n_items; k++) { | |
Window c_win = (Window) array[k]; | |
Window _win; | |
XTextProperty t_prop; | |
XWindowAttributes attrs; | |
int rx, ry; | |
if ( | |
XGetWMName(display, c_win, &t_prop) != 1 || | |
XGetWindowAttributes(display, c_win, &attrs) != 1 || | |
XTranslateCoordinates( | |
display, c_win, attrs.root, -attrs.border_width, | |
-attrs.border_width, &rx, &ry, &_win | |
) != 1 | |
) { | |
printf("warning: failed to get window properties, skipping\n"); | |
continue; | |
} | |
printf( | |
"%d\t%d\t%d\t%d\t%d\t%s\n", | |
(int) c_win, rx, ry, (attrs.x + attrs.width + attrs.x), | |
(attrs.x + attrs.height + attrs.y), t_prop.value | |
); | |
} | |
XFree(data); | |
} | |
return 0; | |
} | |
// vim: ts=2 sw=2 et : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment