Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <xcb/xcb.h>
- #include <xcb/xcb_ewmh.h>
- xcb_atom_t intern_atom(xcb_connection_t *c, const char *name){
- xcb_intern_atom_cookie_t atomCookie;
- xcb_intern_atom_reply_t *atomReply;
- atomCookie = xcb_intern_atom(c, 0, strlen(name), name);
- atomReply = xcb_intern_atom_reply(c, atomCookie, NULL);
- xcb_atom_t res = atomReply->atom;
- free(atomReply);
- return res;
- }
- int main(void){
- xcb_ewmh_connection_t c;
- xcb_screen_t *screen;
- xcb_intern_atom_cookie_t *cookies;
- c.connection = xcb_connect(NULL, NULL);
- cookies = xcb_ewmh_init_atoms(c.connection, &c);
- xcb_ewmh_init_atoms_replies(&c, cookies, NULL);
- xcb_atom_t activeWindowAtom = intern_atom(c.connection, "_NET_ACTIVE_WINDOW");
- if(activeWindowAtom == XCB_NONE){
- xcb_disconnect(c.connection);
- return EXIT_FAILURE;
- }
- const xcb_setup_t *setup = xcb_get_setup(c.connection);
- screen = xcb_setup_roots_iterator(setup).data;
- uint32_t values[] = {XCB_EVENT_MASK_PROPERTY_CHANGE};
- xcb_change_window_attributes(c.connection, screen->root, XCB_CW_EVENT_MASK, values);
- xcb_flush(c.connection);
- xcb_generic_event_t *ev;
- while((ev = xcb_wait_for_event(c.connection)) != NULL){
- if(ev->response_type == XCB_PROPERTY_NOTIFY){
- xcb_get_property_cookie_t cookie;
- xcb_window_t activeWindow;
- cookie = xcb_ewmh_get_active_window(&c, 0);
- xcb_ewmh_get_active_window_reply(&c, cookie, &activeWindow, NULL);
- printf("active window id: %u\n", activeWindow);
- }
- }
- xcb_disconnect(c.connection);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment