]> git.sur5r.net Git - i3/i3/commitdiff
i3-nagbar: explicitly set cursor using libxcursor if available
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 4 Jan 2016 08:26:45 +0000 (09:26 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Mon, 4 Jan 2016 08:26:45 +0000 (09:26 +0100)
See commit b1f1da432 for context.

fixes #2114

i3-nagbar/i3-nagbar.mk
i3-nagbar/main.c

index aba3c09ab49223fce156f0a61cf5b83d307a5dc4..b10e389e534be45fa128eda1bf198200d0f2d8e8 100644 (file)
@@ -4,8 +4,8 @@ CLEAN_TARGETS += clean-i3-nagbar
 
 i3_nagbar_SOURCES := $(wildcard i3-nagbar/*.c)
 i3_nagbar_HEADERS := $(wildcard i3-nagbar/*.h)
-i3_nagbar_CFLAGS   = $(XCB_CFLAGS) $(XCB_WM_CFLAGS) $(PANGO_CFLAGS)
-i3_nagbar_LIBS     = $(XCB_LIBS) $(XCB_WM_LIBS) $(PANGO_LIBS)
+i3_nagbar_CFLAGS   = $(XCB_CFLAGS) $(XCB_CURSOR_CFLAGS) $(XCB_WM_CFLAGS) $(PANGO_CFLAGS)
+i3_nagbar_LIBS     = $(XCB_LIBS) $(XCB_CURSOR_LIBS) $(XCB_WM_LIBS) $(PANGO_LIBS)
 
 i3_nagbar_OBJECTS := $(i3_nagbar_SOURCES:.c=.o)
 
index cbbe9ef8ff5fb3feafc419507969a974e8cf07b9..38740774ee056d55c9acf647316bc4d177d86c03 100644 (file)
 #include <xcb/xcb_aux.h>
 #include <xcb/xcb_event.h>
 #include <xcb/randr.h>
+#include <xcb/xcb_cursor.h>
 
 #include "libi3.h"
 #include "i3-nagbar.h"
 
+/** This is the equivalent of XC_left_ptr. I’m not sure why xcb doesn’t have a
+ * constant for that. */
+#define XCB_CURSOR_LEFT_PTR 68
+
 static char *argv0 = NULL;
 
 typedef struct {
@@ -467,6 +472,25 @@ int main(int argc, char *argv[]) {
 
     xcb_rectangle_t win_pos = get_window_position();
 
+    xcb_cursor_t cursor;
+    xcb_cursor_context_t *cursor_ctx;
+    if (xcb_cursor_context_new(conn, root_screen, &cursor_ctx) == 0) {
+        cursor = xcb_cursor_load_cursor(cursor_ctx, "left_ptr");
+        xcb_cursor_context_free(cursor_ctx);
+    } else {
+        cursor = xcb_generate_id(conn);
+        i3Font cursor_font = load_font("cursor", false);
+        xcb_create_glyph_cursor(
+            conn,
+            cursor,
+            cursor_font.specific.xcb.id,
+            cursor_font.specific.xcb.id,
+            XCB_CURSOR_LEFT_PTR,
+            XCB_CURSOR_LEFT_PTR + 1,
+            0, 0, 0,
+            65535, 65535, 65535);
+    }
+
     /* Open an input window */
     win = xcb_generate_id(conn);
 
@@ -479,13 +503,14 @@ int main(int argc, char *argv[]) {
         0,                                                   /* x11 border = 0, we draw our own */
         XCB_WINDOW_CLASS_INPUT_OUTPUT,
         XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
-        XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
+        XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK | XCB_CW_CURSOR,
         (uint32_t[]){
             0, /* back pixel: black */
             XCB_EVENT_MASK_EXPOSURE |
                 XCB_EVENT_MASK_STRUCTURE_NOTIFY |
                 XCB_EVENT_MASK_BUTTON_PRESS |
-                XCB_EVENT_MASK_BUTTON_RELEASE});
+                XCB_EVENT_MASK_BUTTON_RELEASE,
+            cursor});
 
     /* Map the window (make it visible) */
     xcb_map_window(conn, win);