Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <X11/Xlib.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- void *getproperty (Display *display, Window win, Atom at, Atom type, int *num_results) {
- Atom type_ret;
- int format = 0;
- unsigned long nitems;
- unsigned long items = 0;
- unsigned long bytes = 0;
- unsigned char **prop_value;
- int result;
- result = XGetWindowProperty(display, win, at, 0, 0x7fffffff, False, type, &type_ret, &format, &nitems, &bytes, (unsigned char **)&prop_value);
- if (result != 0) {
- printf ("result from XGetWindowProperty not 0, %d instead!\n", result);
- }
- *num_results = nitems;
- return prop_value;
- }
- char *getwindowname(Display *display, Window window) {
- char *windowname;
- int items;
- windowname = getproperty(display, window, XInternAtom(display, "WM_ICON_NAME", True), AnyPropertyType, &items);
- return (char *)(windowname ? windowname : "Unnamed Window");
- }
- unsigned char **getwindowlist(Display *display, int *clientcount) {
- int i;
- unsigned char **clientlist;
- clientlist = getproperty(display, RootWindow(display, 0), XInternAtom(display, "_NET_CLIENT_LIST", True), AnyPropertyType, clientcount);
- return clientlist;
- }
- int main(void) {
- Display *display;
- Window window;
- XEvent event;
- int clientcount,i = 0;
- unsigned char **clientlist;
- if( !(display = XOpenDisplay(NULL)) ){
- fprintf(stderr, "Cannot open display\n");
- exit(1);
- }
- clientlist = getwindowlist(display, (int *)&clientcount);
- for (i = 0; i < clientcount; i++) {
- XSelectInput (display, (int)clientlist[i], StructureNotifyMask | FocusChangeMask | VisibilityChangeMask);
- printf("%u: %s\n", clientlist[i], getwindowname(display, (int)clientlist[i]));
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment