Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## build.sh
- gcc -lX11 windowlist.c -o windowlist -L/usr/X11R6/lib -I/usr/X11R6/include
- ## widowlist.c
- #include <X11/Xlib.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- Display *display;
- Window window;
- XEvent event;
- int screen;
- Atom type;
- int format;
- unsigned char **clientlist, *titletext;
- unsigned long nitems, bytes;
- int clientcount, activewin;
- void *getproperty (Window win, Atom at, Atom type, int *num_results) {
- Atom type_ret;
- int format = 0;
- 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(Window window) {
- char *windowname;
- int items;
- windowname = getproperty(window, XInternAtom(display, "WM_ICON_NAME", True), AnyPropertyType, &items);
- return (char *)(windowname ? windowname : "Unnamed Window");
- }
- unsigned char **getwindowlist(int *clientcount) {
- int i;
- clientlist = getproperty(RootWindow(display, 0), XInternAtom(display, "_NET_CLIENT_LIST", True), AnyPropertyType, clientcount);
- return clientlist;
- }
- int main(void) {
- int i = 0;
- if( !(display = XOpenDisplay(NULL)) ){
- fprintf(stderr, "Cannot open display\n");
- exit(1);
- }
- clientlist = getwindowlist((int *)&clientcount);
- for (i = 0; i < clientcount; i++) {
- XSelectInput (display, (int)clientlist[i], StructureNotifyMask | FocusChangeMask | VisibilityChangeMask);
- printf("%u: %s\n", clientlist[i], getwindowname((int)clientlist[i]));
- }
- }
Add Comment
Please, Sign In to add comment