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 <christopher.waldon.dev@gmail.com>
---
app/os_wayland.go | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/app/os_wayland.go b/app/os_wayland.go
index 6ad40974..7f393e59 100644
--- a/app/os_wayland.go+++ b/app/os_wayland.go
@@ -358,7 +358,16 @@ 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"))+ 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")
--
2.36.1
Thanks. Merged with a cleanup change.
On Thu, 23 Jun 2022 at 23:16, Chris Waldon
<christopher.waldon.dev@gmail.com> wrote:
>> 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 <christopher.waldon.dev@gmail.com>> ---> app/os_wayland.go | 11 ++++++++++-> 1 file changed, 10 insertions(+), 1 deletion(-)>> diff --git a/app/os_wayland.go b/app/os_wayland.go> index 6ad40974..7f393e59 100644> --- a/app/os_wayland.go> +++ b/app/os_wayland.go> @@ -358,7 +358,16 @@ 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"))
Added a C.free.
> + 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")> --