libwm

library for X windows manipulations
git clone git://z3bra.org/libwm
Log | Files | Refs | LICENSE

commit 15d174927a115d9ce34b50c5cf9025cdc12f5cc4
parent 208dfb86eb0b9740a0a909def3570d5d1eb6457a
Author: Willy <willyatmailoodotorg>
Date:   Fri Aug 12 02:08:50 +0200

New function to register events on window

Diffstat:
libwm.c | 45++++++++++++++++++++++++++++++++++++++++++---
wm.h | 14+++++++++++++-
2 files changed, 55 insertions(+), 4 deletions(-)
diff --git a/libwm.c b/libwm.c @@ -162,6 +162,34 @@ wm_get_attribute(xcb_window_t w, int attr) } int +wm_get_atom_string(xcb_window_t wid, xcb_atom_t atom, char **value) +{ + int len; + xcb_get_property_cookie_t cookie; + xcb_get_property_reply_t *reply; + + cookie = xcb_get_property(conn, 0, wid, atom, XCB_ATOM_STRING, 0, 0); + reply = xcb_get_property_reply(conn, cookie, NULL); + + if (reply == NULL) { + free(reply); + *value = NULL; + return 1; + } + + len = xcb_get_property_value_length(reply); + *value = realloc(value, len); + + if (value == NULL) + return 1; + + *value = (char*)xcb_get_property_value(reply); + free(reply); + + return 0; +} + +int wm_get_cursor(int mode, uint32_t wid, int *x, int *y) { xcb_query_pointer_reply_t *r; @@ -254,7 +282,7 @@ wm_move(xcb_window_t wid, int mode, int x, int y) if (!wm_is_mapped(wid) || wid == scrn->root) return -1; - + curb = wm_get_attribute(wid, ATTR_B); curx = wm_get_attribute(wid, ATTR_X); cury = wm_get_attribute(wid, ATTR_Y); @@ -281,13 +309,15 @@ wm_move(xcb_window_t wid, int mode, int x, int y) return 1; } -void +int wm_set_override(xcb_window_t w, int or) { uint32_t mask = XCB_CW_OVERRIDE_REDIRECT; uint32_t val[] = { or }; xcb_change_window_attributes(conn, w, mask, val); + + return 1; } @@ -319,7 +349,7 @@ wm_resize(xcb_window_t wid, int mode, int w, int h) if (!wm_is_mapped(wid) || wid == scrn->root) return -1; - + curb = wm_get_attribute(wid, ATTR_B); curx = wm_get_attribute(wid, ATTR_X); cury = wm_get_attribute(wid, ATTR_Y); @@ -369,3 +399,12 @@ wm_set_focus(xcb_window_t wid) xcb_flush(conn); return 1; } + +int +wm_reg_event(xcb_window_t wid, uint32_t mask) +{ + uint32_t val[] = { mask }; + + xcb_change_window_attributes(conn, wid, XCB_CW_EVENT_MASK, val); + return 0; +} diff --git a/wm.h b/wm.h @@ -92,6 +92,12 @@ int wm_is_listable(xcb_window_t wid, int mask); int wm_is_mapped(xcb_window_t wid); /* + * Fills the given pointer with the value of the atom for the given window + * Returns 1 if a value can't be retrieved + */ +int wm_get_atom_string(xcb_window_t wid, xcb_atom_t atom, char **value); + +/* * Get the first screen, and set the `scrn` global variable accordingly. */ int wm_get_screen(); @@ -152,7 +158,7 @@ int wm_set_cursor(int x, int y, int mode); * set override_redirect on window * args: wid, {0,1} */ -void wm_set_override(xcb_window_t, int); +int wm_set_override(xcb_window_t, int); /* * Teleport a window to the given position. @@ -197,4 +203,10 @@ int wm_resize(xcb_window_t wid, int mode, int w, int h); */ int wm_restack(xcb_window_t wid, uint32_t mode); +/* + * Register the given event(s) on the window. + * Multiple events can be registered by ORing them together + */ +int wm_reg_event(xcb_window_t wid, uint32_t mask); + #endif /* __LIBWM_H__ */