From a9f31b9dc98f4f9cada46c48b5caa97de8bef34b Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Mon, 4 Jan 2016 09:26:45 +0100 Subject: [PATCH] i3-nagbar: explicitly set cursor using libxcursor if available See commit b1f1da432 for context. fixes #2114 --- i3-nagbar/i3-nagbar.mk | 4 ++-- i3-nagbar/main.c | 29 +++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/i3-nagbar/i3-nagbar.mk b/i3-nagbar/i3-nagbar.mk index aba3c09a..b10e389e 100644 --- a/i3-nagbar/i3-nagbar.mk +++ b/i3-nagbar/i3-nagbar.mk @@ -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) diff --git a/i3-nagbar/main.c b/i3-nagbar/main.c index cbbe9ef8..38740774 100644 --- a/i3-nagbar/main.c +++ b/i3-nagbar/main.c @@ -28,10 +28,15 @@ #include #include #include +#include #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); -- 2.39.5