-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WindowManager: Linux Wayland support #36
Comments
wgpu-native just got support: gfx-rs/wgpu-native#160 but apparently GLFW's support for Wayland is still experimental and pyGLFW may not support it yet. |
It looks like all the components are there to connect things up (with glfw), but when I run it, the system crashes and I'm back in my login screen 😆 I've spend some time checking and trying things, but no luck. For Qt, this seems like a good staring point: https://doc.qt.io/qt-5/wayland-and-qt.html I have not looked at that myself yet. |
Current status: it's not known if the latest versions of GLFW and wgpu-py together support wayland or not. Needs verification before we can close. |
I'm not too sure about the packages on pypi, but I've compiled qt and wayland for conda-forge: conda-forge/qt-main-feedstock#120 (comment) let me know if that helps. If you feel that an other package is missing wayland support, I've found that:
2 has been largely alleviated recently with the introduction of things like manylinux_20YY. |
can you expand on this? I was trying this a while back too, it seems that Python for Qt (PyQt6 and PySide6) likely doesn't expose the API required to make this work. My next attempt was to dig deeper into the C++ API to see if there was a small patch I could make to pyside2 to expose the required functions. I'm not sure if you already tried this. |
regarding undecorated windows, it seems that this is a "choice" by Wayland, they are pushing the decorations on the client side, many frameworks now have a "switch" that you have to toggle if you want the "default" decorations. I the decison to make the the client's (the application we are writing in our python+wgpu context) choice was one that came about because Chrome + Firefox were starting to try to make more use of the space typically reserved for "decorations". |
Basically, we need the display handle (pointer to display object), and although Qt has API to get it, this is not exposed in PySide nor PyQt5. In X we deal with this by creating our own display object. Unfortunately, Wayland does not accept this trick (and the app segfaults). IIRC window ids on X are pretty big numbers, while on Wayland they're small ints. Which makes me think X uses globally unique window ids, where in Wayland they are namespaced to the display object. I have not thought about submitting a patch to PySide / PyQt yet.
Yeah, and I think glfw now does the decoration, but from what I read, I think it does this in glfw 3.4, which is not yet available via pyglfw. |
Do you recall the function we need to call from Qt's C++ API? If so, it would make it easier to open an issue on the PySide Bugtracker. They don't seem to have an active tracking issue: https://bugreports.qt.io/browse/PYSIDE-2190?jql=project+%3D+PYSIDE+AND+text+%7E+wayland
I tried to just install pyglfw from conda-forge, and for some reason I got:
the qt wayland example works!!!! and consequently my own personal application seems to be doing fine on intel + wayland. |
I mean this. It looks like this patch implements it for PySide. It's very recent, so not yet available in a release.
Do you mean the qt triangle example, running on Wayland?
I suppose this is related to glfw 3.4 having one binary that supports both X11 and Wayland, and the |
Notes to self: But QNativeInterface on qt 6.7.1 + pyside6 on conda-forge only exposes the X11 interface
Will try to investigate -- https://bugreports.qt.io/browse/PYSIDE-2787 |
Hi @hmaarrfk in the Pyside bug report there a new comment there. Thanks for helping with that, it can be very helpful. About GLFW it's running very well on Wayland, i just needed to comment
in |
Also, commenting |
@tfmoraes what OS is that on, and have you install glfw via |
@almarklein I'm using Fedora 41, Gnome 47 and Nvidia 4070 with proprietary drivers. I installed using
|
Also, using GLFW just from pip package:
|
Updated 17-09-2024
Current status
Up to 17-09-2024:
Introduction
Since Ubuntu 21.04, Wayland is the default display server. This means that this issue potentially affects a lot of users.
The
XDG_SESSION_TYPE
env variable is eitherx11
orwayland
. This variable is used by many applications to select the window system. What's important for us is that glfw and qt (and wx?) use this variable too.Forntunately, there is XWayland, a compatibility layer that allows applications to "talk X", but still run on Wayland. XWayland is installed by default on Ubuntu too.
This means we can tell glfw and qt to just use X, even when on Wayland. There are env vars for that.
How does it affect us exactly?
To obtain a surface id for the canvas to render to, we call
wgpuInstanceCreateSurface()
, the descriptor argument for that function is platform specific; there is a different struct for Windows, Metal, X11, Wayland, and Xcb.On Windows and MacOS, that struct can be composed with just the "window id". Glfw, Qt and Wx have a metthod to obtain it. So Windows and MacOS are relatievely easy.
On Linux, apart from having to deal with multiple window platforms, we also need an additional value: the display id. This is basically a pointer to a display context: the thing an app creates to start doing things with x11/Wayland. A bit similar to a device of wgpu. This is where the hard part is.
Support for glfw
GLFW has improved support over the past years/months, but seems not quite 100% yet. Pyglfw on Linux includes one lib for x11 and one for Wayland, and selects one based on
XDG_SESSION_TYPE
and a few other variables.The latest glfw (3.4, released 23-02-2024) ought to have better support for Wayland. And includes that support in a single binary lib. Unfortunately, there are some build problems, so pyglfw cannot ship with these binaries yet. It ships glfw 3.3.9 instead.
When I
apt install libglfw3
it installs version 3.3.6 (on Ubunty 22.04). I don't feel like compiling glfw from source right now. So I have not tested the new glfw 3.4.This snippet can be used to create a glfw window. Without the
PYGLFW_LIBRARY_VARIANT
this produces an unresponsive window without decorations on Wayland (with glfw 3.3.9).Also see gfx-rs/wgpu#4775 and gfx-rs/wgpu-native#377.
The solution for now (March 2024) is to force glfw to use X11 (i.e. XWayland on Wayland).
Support for Qt
The problem with Qt is that we cannot obtain the display id that Qt uses internally. There is QGuiApplication.nativeInterface but ... it's not implemented in PySide or PyQt. See e.g. https://wiki.qt.io/Qt_for_Python_Missing_Bindings. Though maybe its available soon?
Another thing I tried was to mage qt's
WgpuCanvas
aQWindow
instead of aQWidget
. This class has asurfaceHandle()
method ... except it raises an exception saying the method is private.Instead of using the actual display id that Qt uses, we can also create our own "display object" and use that. That works fine for X11. Unfortunately, this does not work for Wayland.
Then there is
QT_QPA_PLATFORM
, which can be set to (amongst other things "wayland-egl" and "xcb".The solution for now (March 2024) is to set
QT_QPA_PLATFORM
toxcb
to tell Qt to use X11 (i.e. XWayland on Wayland).Support for wx
Can force to use x11 by setting
GDK_BACKEND
to "x11". But I haven't tested because cannot installwxPython
with apt or pip.The text was updated successfully, but these errors were encountered: