tNew function to register events on window - libwm - X windows manipulation library
(HTM) git clone git://z3bra.org/libwm
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 15d174927a115d9ce34b50c5cf9025cdc12f5cc4
(DIR) parent 208dfb86eb0b9740a0a909def3570d5d1eb6457a
(HTM) Author: Willy <willyatmailoodotorg>
Date: Fri, 12 Aug 2016 02:08:50 +0200
New function to register events on window
Diffstat:
M libwm.c | 45 +++++++++++++++++++++++++++++---
M wm.h | 14 +++++++++++++-
2 files changed, 55 insertions(+), 4 deletions(-)
---
(DIR) diff --git a/libwm.c b/libwm.c
t@@ -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;
t@@ -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);
t@@ -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;
}
t@@ -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);
t@@ -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;
+}
(DIR) diff --git a/wm.h b/wm.h
t@@ -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();
t@@ -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.
t@@ -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__ */