tAdd function to register cursor events on a 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 ead66d8b2d01d853ac9b27fa4bb6f6120433b71d
 (DIR) parent de8f4882f68f284cce23d506144d0082eb8db054
 (HTM) Author: Willy Goiffon <dev@z3bra.org>
       Date:   Sat, 26 Oct 2019 13:09:24 +0200
       
       Add function to register cursor events on a window
       
       This commit will also change the name of the wm_reg_event() to
       wm_reg_window_event() to differentiate event types.
       
       Diffstat:
         M libwm.c                             |      32 ++++++++++++++++++++++++++++++-
         M wm.h                                |      10 +++++++++-
       
       2 files changed, 40 insertions(+), 2 deletions(-)
       ---
 (DIR) diff --git a/libwm.c b/libwm.c
       t@@ -1,4 +1,5 @@
        #include <xcb/xcb.h>
       +#include <xcb/xcb_cursor.h>
        #include <stdlib.h>
        #include <stdio.h>
        #include <string.h>
       t@@ -399,7 +400,7 @@ wm_set_focus(xcb_window_t wid)
        }
        
        int
       -wm_reg_event(xcb_window_t wid, uint32_t mask)
       +wm_reg_window_event(xcb_window_t wid, uint32_t mask)
        {
                uint32_t val[] = { mask };
                xcb_void_cookie_t c;
       t@@ -413,3 +414,32 @@ wm_reg_event(xcb_window_t wid, uint32_t mask)
                free(e);
                return 0;
        }
       +
       +
       +int
       +wm_reg_cursor_event(xcb_window_t wid, uint32_t mask, char *cursor)
       +{
       +        xcb_cursor_t p;
       +        xcb_cursor_context_t *cx;
       +        xcb_grab_pointer_cookie_t c;
       +        xcb_grab_pointer_reply_t *r;
       +
       +        p = XCB_NONE;
       +        if (cursor) {
       +                if (xcb_cursor_context_new(conn, scrn, &cx) < 0)
       +                        return -1;
       +
       +                p = xcb_cursor_load_cursor(cx, cursor);
       +        }
       +
       +        c = xcb_grab_pointer(conn, 1, scrn->root, mask,
       +                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)
       +                return -1;
       +
       +        xcb_cursor_context_free(cx);
       +        return 0;
       +}
 (DIR) diff --git a/wm.h b/wm.h
       t@@ -207,6 +207,14 @@ 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);
       +int wm_reg_window_event(xcb_window_t wid, uint32_t mask);
       +
       +/*
       + * Register the given cursor event(s) on the window.
       + * Multiple events can be registered by ORing them together.
       + * The cursor will be changed to the `cursor` while the pointer is
       + * grabbed, if not NULL.
       + */
       +int wm_reg_cursor_event(xcb_window_t wid, uint32_t mask, char *cursor);
        
        #endif /* __LIBWM_H__ */