Guest User

Untitled

a guest
Oct 26th, 2019
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.02 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. #include <xcb/xcb.h>
  6.  
  7. int main(void){
  8.     xcb_connection_t *connection;
  9.     xcb_screen_t *screen;
  10.     xcb_window_t rootWindow;
  11.  
  12.     connection = xcb_connect(NULL, NULL);
  13.  
  14.     screen = xcb_setup_roots_iterator(xcb_get_setup(connection)).data;
  15.     rootWindow = screen->root;
  16.  
  17.     uint32_t values[] = {XCB_EVENT_MASK_PROPERTY_CHANGE};
  18.     xcb_change_window_attributes(connection, rootWindow, XCB_CW_EVENT_MASK, values);
  19.  
  20.     xcb_property_notify_event_t *ev;
  21.     while((ev = (xcb_property_notify_event_t*)xcb_wait_for_event(connection)) != NULL){
  22.         xcb_get_atom_name_cookie_t nameCookie;
  23.         xcb_get_atom_name_reply_t *nameReply;
  24.         xcb_generic_error_t *e = NULL;
  25.  
  26.         nameCookie = xcb_get_atom_name(connection, ev->atom);
  27.         nameReply = xcb_get_atom_name_reply(connection, nameCookie, &e);
  28.         char *atomName = xcb_get_atom_name_name(nameReply);
  29.  
  30.         if(strcmp("_NET_ACTIVE_WINDOW", atomName) == 0){
  31.             puts("active window changed");
  32.         }
  33.     }
  34.  
  35.     xcb_disconnect(connection);
  36.  
  37.     return EXIT_SUCCESS;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment