garrigue / lablgtk

LablGTK 2 and 3: an interface to the GIMP Tool Kit
https://garrigue.github.io/lablgtk
Other
89 stars 40 forks source link

Gdk.Cursor.create returns NULL on lablgtk3 + WSLg + Wayland #143

Open maroneze opened 2 years ago

maroneze commented 2 years ago

A user of Frama-C on WSLg with Ubuntu 20.04 just reported a crash in our GUI, and it boils down to:

let arrow_cursor = Gdk.Cursor.create `ARROW in (...)

Under their specific configuration (which I could reproduce using a Windows Insider Build, to have access to WSL2 and WSLg), this call results in a warning in the terminal, and a Gpointer.Null exception in the code:

Unable to load arrow from the cursor theme
Fatal error: exception Gpointer.Null

Strangely, the code works with other cursors, such as WATCH.

Note that this only happens when Frama-C is compiled with lablgtk3; with lablgtk2, there is no such issue.

I then investigated and found out that, among the 77 tags listed in type cursor_type, in src/gdk_tags.var, only 13 seem to work in that configuration:

BOTTOM_LEFT_CORNER
BOTTOM_RIGHT_CORNER
BOTTOM_SIDE
CROSSHAIR
HAND1
LEFT_PTR
LEFT_SIDE
RIGHT_SIDE
TOP_LEFT_CORNER
TOP_RIGHT_CORNER
TOP_SIDE
WATCH
XTERM

All the others (such as ARROW in our case) result in an error.

I tried installing almost all Ubuntu cursor theme packages and changing them as indicated here, that is, running sudo update-alternatives --config x-cursor-theme, choosing a different set, and then rebooting the Ubuntu instance; but that didn't work.

I then tried adding GDK_BACKEND=x11 before running the Frama-C GUI, and it worked again.

So, it seems to happen in a very narrow set of circumstances: lablgtk3, under WSLg, under Ubuntu 20.04 (I couldn't try other WSL distros), and when running Wayland.

I couldn't find much documentation about possible root causes, other than the fact that gdk_cursor_new seems to be deprecated.

Anyway, I'm not even sure the issue is related to lablgtk, or if there is a way to get those cursors working under WSLg. In any case, we'll probably switch to LEFT_PTR, which seems almost identical to the ARROW we were using, and seems to be in the subset of supported cursors. I'm reporting it in case others have similar issues, or someone finds a better workaround.