tAdd default event handler for mouse buttons - glazier - window management experiments
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
(DIR) commit 1a4aed801eee308cf67522115e8cedfb3d9e0172
(DIR) parent 6c124a8138ad6a671c8f65cec5e4ea1bc419ac2d
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Fri, 18 Oct 2019 22:41:34 +0200
Add default event handler for mouse buttons
Diffstat:
M glazier.c | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)
---
(DIR) diff --git a/glazier.c b/glazier.c
t@@ -11,19 +11,33 @@ struct ev_callback_t {
int (*handle)(xcb_generic_event_t *);
};
-static int cb_create(xcb_generic_event_t *);
static int ev_callback(xcb_generic_event_t *);
+/* XCB events callbacks */
+static int cb_default(xcb_generic_event_t *);
+static int cb_create(xcb_generic_event_t *);
+
int verbose = 1;
xcb_connection_t *conn;
xcb_screen_t *scrn;
static const struct ev_callback_t cb[] = {
- /* event, function */
- { XCB_CREATE_NOTIFY, cb_create },
+ /* event, function */
+ { XCB_CREATE_NOTIFY, cb_create },
+ { XCB_BUTTON_PRESS, cb_default },
+ { XCB_BUTTON_RELEASE, cb_default },
};
static int
+cb_default(xcb_generic_event_t *ev)
+{
+ if (verbose)
+ fprintf(stderr, "event not handled: %d\n", ev->response_type);
+
+ return 0;
+}
+
+static int
cb_create(xcb_generic_event_t *ev)
{
uint32_t val[2];
t@@ -59,6 +73,12 @@ main (int argc, char *argv[])
wm_init_xcb();
wm_get_screen();
+ /* grab mouse clicks for window movement */
+ xcb_grab_button(conn, 1, scrn->root,
+ XCB_EVENT_MASK_BUTTON_PRESS | XCB_EVENT_MASK_BUTTON_RELEASE,
+ XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, XCB_NONE, XCB_NONE,
+ XCB_BUTTON_INDEX_ANY, MODMASK);
+
/* needed to get notified of windows creation */
wm_reg_event(scrn->root, XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY);
xcb_flush(conn);