gm

(orphaned) group manager using libcxb
git clone git://z3bra.org/gm
Log | Files | Refs | README | LICENSE

commit fc301645ad33d31c0b2c09f292797209a40d8532
parent eeb27b3fb7e9add340137d905a0f5763bb5aef51
Author: z3bra <willy@mailoo.org>
Date:   Mon Nov 17 19:28:29 2014

Revert "removed 'grabkeys and regevnt' functions: need to fix things now"

This reverts commit eeb27b3fb7e9add340137d905a0f5763bb5aef51.

Diffstat:
 gm.c | 65 ++++++++++++++++++++++++++++++++++++++++-------------------------
 1 file changed, 40 insertions(+), 25 deletions(-)

diff --git a/gm.c b/gm.c @@ -46,6 +46,7 @@ void usage(char *); void cleanup (void); void init (void); void run (void); +void regevnt (uint32_t *); void grabkeys (void); xcb_keysym_t getkeysym (xcb_keycode_t); xcb_keycode_t * getkeycode (xcb_keysym_t); @@ -76,6 +77,7 @@ static struct window *groups[GROUPNUM + 1]; static xcb_connection_t *con; /* connection to the X server */ static xcb_screen_t *scn; /* default screen */ +static const uint32_t winev = XCB_EVENT_MASK_ENTER_WINDOW; static xcb_window_t focus; static uint8_t verbose = 0; /* verbose mode ? */ @@ -98,7 +100,7 @@ struct window *newnod(xcb_window_t w) return NULL; } - val[0] = XCB_EVENT_MASK_KEY_PRESS; + val[0] = winev; xcb_change_window_attributes(con, w, mask, val); xcb_flush(con); @@ -374,12 +376,12 @@ void evnt_keypress (xcb_generic_event_t *e) struct window *np; /* don't add the root window to a group */ - if (ev->event == scn->root) { + if (focus == scn->root) { return; } ks = getkeysym(ev->detail); - np = getnod(ev->event); + np = getnod(focus); if (!np) { warnx("evnt_keypress: cannot get focused window\n"); @@ -446,6 +448,33 @@ void cleanup() return; /* void */ } +/* change the events registration attribute of all the childs of parent */ +void regevnt(uint32_t *val) +{ + int i; + xcb_query_tree_reply_t *rep; + xcb_window_t *win; + static const uint32_t mask = XCB_CW_EVENT_MASK; + + /* we fetch the win tree of the window */ + rep = xcb_query_tree_reply(con, xcb_query_tree(con, scn->root), NULL); + + if (rep == NULL) { + warnx("xcb_query_tree_reply"); + } + + win = xcb_query_tree_children(rep); + + for (i = 0; i < rep->children_len; i++) { + xcb_change_window_attributes(con, win[i], mask, val); + } + xcb_flush(con); + + free(rep); + + return; /* void */ +} + xcb_keysym_t getkeysym (xcb_keycode_t keycode) { xcb_key_symbols_t *keysyms; @@ -532,33 +561,18 @@ void discover() void run() { - int i; xcb_generic_event_t *e; - static const uint32_t mask = XCB_CW_EVENT_MASK; - static uint32_t val[] = { XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY }; - xcb_query_tree_reply_t *r; - xcb_window_t *w; - - /* we fetch the win tree of the window */ - r = xcb_query_tree_reply(con, xcb_query_tree(con, scn->root), NULL); - - if (r == NULL) { - warnx("xcb_query_tree_reply"); - } - - w = xcb_query_tree_children(r); - - for (i = 0; i < r->children_len; i++) { - newnod(w[i]); - } - xcb_flush(con); - - free(r); - + static uint32_t mask = XCB_CW_EVENT_MASK; + static uint32_t val[] = { + XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY + }; xcb_change_window_attributes(con, scn->root, mask, val); xcb_flush(con); + val[0] = winev; + regevnt(val); + for (;;) { e = xcb_wait_for_event(con); @@ -591,6 +605,7 @@ int main (int c, char **v) /* setup the X connection */ init(); discover(); + grabkeys(); /* ready... GO! */ run();