Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.85 KB | None | 0 0
  1. WId ImageGrabber::getActiveWindow()
  2. {
  3.     int screenNum;
  4.     xcb_connection_t* connection = xcb_connect (NULL, &screenNum);;
  5.     xcb_get_input_focus_reply_t *replyFocus = xcb_get_input_focus_reply(connection, xcb_get_input_focus(connection), nullptr);
  6.     xcb_query_tree_cookie_t cookie;
  7.     xcb_query_tree_reply_t *replyTree;
  8.  
  9.     cookie = xcb_query_tree(connection, replyFocus->focus);
  10.     xcb_window_t w = replyFocus->focus;
  11.     while((replyTree = xcb_query_tree_reply(connection, cookie, NULL)) && (replyTree->parent != replyTree->root)) {
  12.         printf("root = %d\n", replyTree->root);
  13.         printf("parent = %d\n", replyTree->parent);
  14.         printf("Focus = %d\n", replyFocus->focus);
  15.         cookie = xcb_query_tree(connection, replyTree->parent);
  16.         w = replyTree->parent;
  17.     }
  18.     printf("**Returned = %d\n", w);
  19.     return w;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement