From 9151009b2a2c30cd392f537c44752c4b02190aa3 Mon Sep 17 00:00:00 2001 From: Chris Waldon Date: Thu, 23 Jun 2022 17:16:21 -0400 Subject: [PATCH] app: [Wayland] respect XCURSOR_* environment variables This commit adds support for the commonly-used XCURSOR_THEME and XCURSOR_SIZE environment variables. Wayland lacks a protocol-level way to standardize cursor size right now, but these variables are used consistently by many applications and compositors. Many users (including me) will find that their environment is already configuring these for them, and will get consistent cursor sizing for free. I explored a lot of ways to tackle this, but it looks like nobody has ever gotten around to implementing the cursor theme protocol discussed here: https://wayland-devel.freedesktop.narkive.com/VuMSOO55/possible-wayland-extension-to-publish-mouse-pointer-size Given that it doesn't seem to be resolved anytime soon, supporting a widely-used convention to tweak these things seems reasonable to me. I say that it fixes issue 382 because it enables the user to make Gio's cursor size match the rest of their system. Fixes: https://todo.sr.ht/~eliasnaur/gio/382 Signed-off-by: Chris Waldon --- app/os_wayland.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/os_wayland.go b/app/os_wayland.go index fe9daa7d..4ce42d29 100644 --- a/app/os_wayland.go +++ b/app/os_wayland.go @@ -374,7 +374,17 @@ func (d *wlDisplay) createNativeWindow(options []Option) (*window, error) { w.destroy() return nil, errors.New("wayland: xdg_surface_get_toplevel failed") } - w.cursor.theme = C.wl_cursor_theme_load(nil, C.int(32*w.scale), d.shm) + cursorTheme := C.CString(os.Getenv("XCURSOR_THEME")) + defer C.free(unsafe.Pointer(cursorTheme)) + cursorSize := 32 + if envSize, ok := os.LookupEnv("XCURSOR_SIZE"); ok && envSize != "" { + size, err := strconv.Atoi(envSize) + if err == nil { + cursorSize = size + } + } + + w.cursor.theme = C.wl_cursor_theme_load(cursorTheme, C.int(cursorSize*w.scale), d.shm) if w.cursor.theme == nil { w.destroy() return nil, errors.New("wayland: wl_cursor_theme_load failed")