app: [Wayland] load KDE cursor theme
On Linux with Wayland (KWin) and KDE there are several issues related to the cursor:
- Most cursors like
CursorEastWestResizedo not work at all and the default cursor is shown each time - The cursor is very very small and hard for the user to see and work with (scale is off)
- The cursor theme is not recognised
This PR fixes the above issues. It detects weather a KDE theme is set and uses it. Otherwise it iterates through reasonable fallbacks. The order of preference:
- Explicitly configured theme and size via environment variables
- KDE configuration file
- KDE or Gnome default
- Wayland default
About the performance: I researched other projects and it seams to be quite common to explicitly load cursor configuration from disk. As it is an IO operation I was concerned about performance impact but had difficulties to benchmark this properly. During testing, reading the config file is in the range of: 33µs - 63µs (probably cached) with application start to first-frame-drawn in the range of: 260ms - 463ms Based on the variation of the application start there seams to be a lot going on and I am fine with reading the file right now.
About Gnome and others: I am not familiar with Gnome. If Gnome offers cursor themes, then they are not loaded (as before) and the default theme is used (improvement compared to before) I can even say less about any other environment like LXDE, but could imagine they use the Gnome cursors as well.
- The cursor is very very small and hard for the user to see and work with (scale is off)
I think this is a separate fix by adjusting the cursor surface when the scale changes. This is done for the window surface but not for the cursor surface(s).
You probably need to reload the cursor theme when the scale changes. The following hack forces scale to 2 to test this theory:
diff --git a/app/os_wayland.go b/app/os_wayland.go
index b020c6d173..050aa3fc24 100644
--- a/app/os_wayland.go
+++ b/app/os_wayland.go
@@ -354,6 +354,7 @@
wakeups: make(chan struct{}, 1),
clipReads: make(chan transfer.DataEvent, 1),
}
+ w.scale = 2
w.surf = C.wl_compositor_create_surface(d.compositor)
if w.surf == nil {
w.destroy()
- The cursor theme is not recognised
The wayland-cursor library is supposed to give us the default cursor theme and I'm surprised it doesn't work under KDE. Reading the documentation I noticed that to get the default theme you need to pass NULL as the name, whereas we seem to pass the empty string. Does the following hack make any difference?
diff --git a/app/os_wayland.go b/app/os_wayland.go
index b020c6d173..ac3b526e14 100644
--- a/app/os_wayland.go
+++ b/app/os_wayland.go
@@ -386,7 +386,7 @@
}
}
- w.cursor.theme = C.wl_cursor_theme_load(cursorTheme, C.int(cursorSize*w.scale), d.shm)
+ w.cursor.theme = C.wl_cursor_theme_load(nil, C.int(cursorSize*w.scale), d.shm)
if w.cursor.theme == nil {
w.destroy()
return nil, errors.New("wayland: wl_cursor_theme_load failed")
Most cursors like CursorEastWestResize do not work at all and the default cursor is shown each time
This may be a consequence of the wrong theme issue above.