GTK3 support for wayland

My app uses GTK3. It runs fine on Kubuntu 24.04 and Raspberry Pi OS 12, but I am worried about support for the backend.

First question: Is there a way to determine what backend my application is actually using? Should I assume that it is running x11 unless I tell it otherwise? If I tell it otherwise, can I assume that it is actually using what I specified?

Second question: I read that I can specify the backend to use on the command line. To find out what backends are supported, I am supposed to specify “help” as the backend:

GDK_BACKEND=help python myapplication.py

The output declares support for x11, wayland, and broadway on both platforms. On Kubuntu, I can run

GDK_BACKEND=x11 python myapplication.py

but if I specify either of the other two “supported” backends, the program crashes with

Gtk-CRITICAL **: 09:25:14.487: _gtk_css_lookup_resolve: assertion ‘(((extension ({ GTypeInstance __inst = (GTypeInstance) ((provider)); GType __t = ((_gtk_style_provider_private_get_type ())); gboolean __r; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))’ failed
/usr/lib/python3/dist-packages/gi/overrides/init.py:313: Warning: g_object_set_data_full: assertion ‘G_IS_OBJECT (object)’ failed
return super_init_func(self, **new_kwargs)

(wax.py:3269): Gtk-ERROR **: 09:25:14.488: Can’t create a GtkStyleContext without a display connection
Trace/breakpoint trap (core dumped)

On Raspberry Pi OS, I get the same list of “supported” backends. x11 and wayland work, but broadway produces the same crash.

I would love to be able to use broadway, but it has never worked reliably for me. However, it seems important that I be able to specify wayland when the program is running on a platform that uses wayland. Considering that my program crashes on Kubuntu 24.04 when I specify wayland, I suppose that Kubuntu must be running x11. I believe that wayland is optional in 24.04 (and standard in 24.10), but as far as I know I have done nothing to exercise the option. However, I am pretty sure that Raspberry Pi OS 12 uses wayland by default. Is it possible that GTK detects that Raspberry Pi OS supports wayland and automatically configures itself to use the wayland backend, or do I need to tell it explicitly to use wayland?

Use the GTK inspector.

You forgot to initialise GTK.

Broadway is a science experiment: it’s not really maintained, and it has seen no changes in GTK3.

You don’t need to do anything: GTK will check if a Wayland compositor is available first, and then fall back to X11 automatically.

Unless you specified GDK_BACKEND=wayland, then GTK will use X11 when running under X11. If you did not override the backend, then the crash is caused by something else entirely.

gtk approach is to throw away gtk3 when gtk5 is shipped. And although it is not yet on official roadmap, be prepared is better way and also with css preparation in between on gtk road…

GTK3 will be EOL when GTK5 is out, yes, just like GTK2 has been EOL when GTK4 was released; keep in mind that GTK5 development hasn’t even started yet, and until the 5.0 release, GTK3 is still supported.

Newly written code should, of course, target GTK4; there’s legacy GTK3 code still in the wild, so it’s perfectly fine to keep using it.

I would consider porting my project to GTK4, but the main obstacle that has been holding me back is that my code uses 22 glade files but GTK4 does not have Glade. Is there an easy way to handle the integration of Glade files?

Glade is GTK3-only, but it’s also only a UI tool to generate XML.

In general, Glade is a terrible tool for UI development: it’s only ever useful to start a UI definition file, but you are always supposed to manage the result and changes by hand, because Glade encodes a bunch of patterns into the UI definition file, which means you’re going to lose any change you make out of band, or any change introduced by the toolkit’s best practices.

You have various replacements for Glade in GTK4; first, you have to start by converting the GTK3 UI definition files to GTK4, using gtk4-builder-tool.

After that, you have these options:

  • write your UI definition files by hand, taking advantage of derived classes and widget templates to keep them small and tractable
  • use blueprint-compiler, which gives you an easier to edit grammar that gets converted into XML at build time
  • use Cambalache, a UI tool written by the former Glade maintainer, and that is capable of dealing with UI definition files for GTK3, GTK4, and other libraries

gnome-builder is prehistoric mastodont, cambalache not in repos(only flatpak and thats restricted on some environments) and vscode support for a wider developer community also missing… and paid or freemium plugins(in wide amount of langs supported for gnome) also missing when also not in vscode archives after unsupported phase… if somehow searchable…

If you don’t have any positive thing to say about anything, why say anything at all?

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.