tGrab pointer and change cursor on mouse press - glazier - window management experiments
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
(DIR) commit 45a966a1559ea5c24b85b9a988e70f9e21eb5ca6
(DIR) parent 2af6916320279d2f43d45b2d6a2eed5e4a2e3aef
(HTM) Author: Willy Goiffon <dev@z3bra.org>
Date: Fri, 18 Oct 2019 23:59:47 +0200
Grab pointer and change cursor on mouse press
Diffstat:
M config.def.h | 3 +++
M config.mk | 2 +-
M glazier.c | 35 +++++++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 1 deletion(-)
---
(DIR) diff --git a/config.def.h b/config.def.h
t@@ -1,6 +1,9 @@
/* modifier key used for wm actions */
#define MODMASK XCB_MOD_MASK_4
+#define XHAIR_MOVE "hand1"
+#define XHAIR_SIZE "tcross"
+
/* window borders */
int border = 8;
int border_color = 0xdeadca7;
(DIR) diff --git a/config.mk b/config.mk
t@@ -9,4 +9,4 @@ MANDIR = ${PREFIX}/man
CPPFLAGS = -I./libwm -DVERSION=\"${VERSION}\"
CFLAGS = $(CPPFLAGS) -Wall -Wextra -pedantic -g
LDFLAGS = -L./libwm
-LDLIBS = -lxcb -lwm
+LDLIBS = -lxcb -lxcb-cursor -lwm
(DIR) diff --git a/glazier.c b/glazier.c
t@@ -1,5 +1,7 @@
#include <stdio.h>
+#include <stdlib.h>
#include <xcb/xcb.h>
+#include <xcb/xcb_cursor.h>
#include "wm.h"
#include "config.h"
t@@ -62,12 +64,45 @@ cb_create(xcb_generic_event_t *ev)
static int
cb_mouse_press(xcb_generic_event_t *ev)
{
+ xcb_cursor_t p;
+ xcb_cursor_context_t *cx;
+ xcb_grab_pointer_cookie_t c;
+ xcb_grab_pointer_reply_t *r;
xcb_button_press_event_t *e;
e = (xcb_button_press_event_t *)ev;
if (verbose)
fprintf(stderr, "mouse_press: 0x%08x\n", e->child);
+ if (xcb_cursor_context_new(conn, scrn, &cx) < 0) {
+ fprintf(stderr, "cannont instantiate cursor\n");
+ exit(1);
+ }
+
+ switch(e->detail) {
+ case 1:
+ p = xcb_cursor_load_cursor(cx, XHAIR_MOVE);
+ break;
+ case 3:
+ p = xcb_cursor_load_cursor(cx, XHAIR_SIZE);
+ break;
+ default:
+ return 1;
+ }
+
+ /* grab pointer and watch motion events */
+ c = xcb_grab_pointer(conn, 0, scrn->root, XCB_EVENT_MASK_BUTTON_MOTION,
+ XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC,
+ XCB_NONE, p, XCB_CURRENT_TIME);
+
+ r = xcb_grab_pointer_reply(conn, c, NULL);
+ if (!r || r->status != XCB_GRAB_STATUS_SUCCESS) {
+ fprintf(stderr, "cannot grab pointer\n");
+ return 1;
+ }
+
+ xcb_flush(conn);
+
return 0;
}