Guest User

Untitled

a guest
Jun 23rd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. // I am omiting (tons of) cleanup code and where I set the display and toplevel variables.
  2.  
  3. Display* display;
  4. Widget toplevel;
  5.  
  6. bool has_name(Window window)
  7. {
  8. XTextProperty data = XTextProperty ();
  9. return (!XGetWMName (display, window, &data));
  10. }
  11.  
  12. bool has_client_leader(Window window)
  13. {
  14. unsigned long nitems = 0;
  15. unsigned char* data = 0;
  16. Atom actual_type;
  17. int actual_format;
  18. unsigned long bytes;
  19. // WM_CLIENT_LEADER is an interned Atom for the WM_CLIENT_LEADER property
  20. int status = XGetWindowProperty (display, window, WM_CLIENT_LEADER, 0L, (~0L), False,
  21. AnyPropertyType, &actual_type, &actual_format, &nitems, &bytes, &data);
  22. if (status != Success || acutal_type == None) return false;
  23. Window* leader = reinterpret_cast<Window*> (data);
  24. return (*leader != 0);
  25. }
  26.  
  27. bool has_class(Window window)
  28. {
  29. XClassHint data = XClassHint ();
  30. return (!GetClassHint (display, window, &data));
  31. }
  32.  
  33. void handle_event(Widget widget, XtPointer, XEvent* event, Boolean*)
  34. {
  35. if (event->type != CreateNotify) return;
  36.  
  37. Window w = event->xcreatewindow.window;
  38.  
  39. // confirm window has a name
  40. if (!has_name (w)) return;
  41.  
  42. // confirm window is a client window
  43. Window client = XmuClientWindow (display, w);
  44. if (!client || client != w) return;
  45.  
  46. // confirm window has a client leader that is not 0x0
  47. if (!has_client_leader (client)) return;
  48.  
  49. // confirm window has a class
  50. if (!has_class (client)) return;
  51.  
  52. // The window has passed all our checks!
  53. // Go on to do stuff with the window ...
  54. }
  55.  
  56. int main(int argc, char* argv[])
  57. {
  58. // ...
  59.  
  60. // Setting up the event handler for SubstructureNotify on root window
  61. Window root_window = XDefaultRootWindow (display);
  62. Widget dummy = XtCreateWidget ("dummy", coreWidgetClass, toplevel, 0, 0);
  63. XtRegisterDrawable (display, root_window, dummy);
  64. XSelectInput (display, root_window, SubstructureNotifyMask);
  65. XtAddRawEventHandler (dummy, SubstructureNotifyMask, False, handle_event, 0);
  66.  
  67. // ...
  68. }
Add Comment
Please, Sign In to add comment