I'm learning GTK4 and working with wayland (hyprland) on linux.
When I try to retrieve the default display, my python code returns an X11Display.
I figured out that the GDK_BACKEND
environment variable was not set to wayland
.
However, my question is, why is the code even able to return an X11Monitor? Could the reason be that it is using XWayland? Are there potential problems (overhead etc) when accessing X11Monitor on wayland?
also, to quote https://docs.gtk.org/gtk4/wayland.html#wayland_display:
The GDK Wayland backend provides support for running GTK applications under a Wayland compositor. To run your application in this way, select the Wayland backend by setting GDK_BACKEND=wayland.
On UNIX, the Wayland backend is enabled by default, so you don’t need to do anything special when compiling it, and everything should “just work.”
So why is it not enabled by default on my system? should hyprland to set this variable?
import gi
gi.require_version("Gtk", "4.0")
from gi.repository import Gtk, Gdk
display = Gdk.Display.get_default()
assert display is not None
print(display.__class__)
monitors = display.get_monitors()
for monitor in monitors:
print(monitor.__class__)
output:
<class 'gi.repository.GdkX11.X11Display'>
<class 'gi.repository.GdkX11.X11Monitor'>
<class 'gi.repository.GdkX11.X11Monitor'>
output when setting GDK_BACKEND=wayland
:
<class '__gi__.GdkWaylandDisplay'>
<class '__gi__.GdkWaylandMonitor'>
<class '__gi__.GdkWaylandMonitor'>