Guest User

Untitled

a guest
Jun 21st, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. #include <X11/Xlib.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. void *getproperty (Display *display, Window win, Atom at, Atom type, int *num_results) {
  7.  
  8. Atom type_ret;
  9. int format = 0;
  10. unsigned long nitems;
  11. unsigned long items = 0;
  12. unsigned long bytes = 0;
  13. unsigned char **prop_value;
  14. int result;
  15.  
  16. result = XGetWindowProperty(display, win, at, 0, 0x7fffffff, False, type, &type_ret, &format, &nitems, &bytes, (unsigned char **)&prop_value);
  17.  
  18. if (result != 0) {
  19. printf ("result from XGetWindowProperty not 0, %d instead!\n", result);
  20. }
  21.  
  22. *num_results = nitems;
  23.  
  24. return prop_value;
  25.  
  26. }
  27.  
  28. char *getwindowname(Display *display, Window window) {
  29.  
  30. char *windowname;
  31. int items;
  32.  
  33. windowname = getproperty(display, window, XInternAtom(display, "WM_ICON_NAME", True), AnyPropertyType, &items);
  34.  
  35. return (char *)(windowname ? windowname : "Unnamed Window");
  36.  
  37. }
  38.  
  39. unsigned char **getwindowlist(Display *display, int *clientcount) {
  40.  
  41. int i;
  42. unsigned char **clientlist;
  43.  
  44. clientlist = getproperty(display, RootWindow(display, 0), XInternAtom(display, "_NET_CLIENT_LIST", True), AnyPropertyType, clientcount);
  45.  
  46. return clientlist;
  47.  
  48. }
  49.  
  50. int main(void) {
  51.  
  52. Display *display;
  53. Window window;
  54. XEvent event;
  55. int clientcount,i = 0;
  56. unsigned char **clientlist;
  57.  
  58. if( !(display = XOpenDisplay(NULL)) ){
  59. fprintf(stderr, "Cannot open display\n");
  60. exit(1);
  61. }
  62.  
  63. clientlist = getwindowlist(display, (int *)&clientcount);
  64.  
  65. for (i = 0; i < clientcount; i++) {
  66.  
  67. XSelectInput (display, (int)clientlist[i], StructureNotifyMask | FocusChangeMask | VisibilityChangeMask);
  68.  
  69. printf("%u: %s\n", clientlist[i], getwindowname(display, (int)clientlist[i]));
  70.  
  71. }
  72.  
  73. return 0;
  74.  
  75. }
Add Comment
Please, Sign In to add comment