Skip to content
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

Wayland support #958

Open
2 of 5 tasks
ManuelSchneid3r opened this issue Dec 7, 2020 · 10 comments
Open
2 of 5 tasks

Wayland support #958

ManuelSchneid3r opened this issue Dec 7, 2020 · 10 comments
Labels
C: App Issue related to the core application/library

Comments

@ManuelSchneid3r
Copy link
Member

ManuelSchneid3r commented Dec 7, 2020

This is a parent issue to agglomerate all the wayland issues.

Wayland and Qt Wayland are far from mature. I know Wayland is quite popular and I'd like to support it but working with it is simply a pain and incredibly (and I mean incredibly, honestly other platforms just work out of the box) time consuming. Thats why I decided to not support Wayland officially.

The minimum OOTB experience I expect to consider supporting Wayland again is (at least):

@johanhelsing
Copy link
Contributor

Hey, previous Qt Wayland maintainer here.

Since a lot of potentially different issues were closed and linked to this one, I'll try to summarize what I know.

Most of the segfault reports linked to this one seems to be due to X11 code for the hotkey manager being called directly on linux without checking whether wayland or x11 was used. It was recently fixed in #804 . So these crashes should not be an issue anymore.

If you have problems after that patch, it's probably a good idea to send logs with

export QT_LOGGING_RULES="qt.qpa.*=true"
export WAYLAND_DEBUG=1

Set in the environment, which should hopefully give a lot more information about what went wrong.

Also note that many X features do not have a direct replacement in wayland, two of which are important for apps like Albert:

1. Registering global key listeners is not possible on Wayland

Allowing apps without window focus to listen to key strokes is considered insecure on Wayland. This is in order to have the possibility to sandbox apps that you don't trust completely. I.e. similar to what android does. Unfortunately there is (as far as I know) no standard way for apps to request this sort of permission. This means that each compositor handles global shortcut key configuration in their own way, and you need to check how it's done on your compositor and make it run albert on some key combination.

TL;DR: Global key shortcuts are configured in the compositor on Wayland.

2. Positioning a window on the screen is not allowed in xdg-shell (the desktop wayland protocol).

Qt has APIs for positioning a window, i.e. QWindow::setPosition, however this is not possible to implement on Wayland, and it currently does nothing. Global window positioning is more or less considered evil, the reasoning being it should be up to the compositor to decide how to arrange windows. This has caused lots of issues for Qt, as it relies quite heavily on global positioning for placing menus for instance. There are lots of really ugly hacks in QtWayland to adhere to the relative positioning with a strict hierarchy that Wayland requires.

As for albert, I guess the issue is that you probably want the window to be handled somewhat specially and always appear in the same position (i.e. centered), which may not be what the compositor has in mind for it. i.e. it may just put the window somewhere where there is free space. Or tile it, or whatever. Solving this is not currently possible without resorting to some kind of hack, like asking to be maximized and draw a mostly transparent window with albert centered in the middle, and you're still not guaranteed the compositor will honor your request to be maximized.

There was some effort done in trying to solve these kinds of issues properly by creating an alternative wayland shell protocol, https://github.com/swaywm/wlr-protocols/blob/master/unstable/wlr-layer-shell-unstable-v1.xml that did allow some of these things. It's implemented in Sway, and even some prototyping was done to support it through Qt. If memory serves me, some of the other launcher apps (not Qt-based, though) use this shell to work properly on sway.

Another way would be to try to write an extension for xdg-shell to add absolute window positioning. This would likely be easier to implement and get merged into Qt, but getting it into wayland protocols will probably be a lot harder.

TL;DR: Wayland is the only desktop that doesn't allow apps to set their own screen position, which means neither Qt nor albert has any control over where the albert window appears.

The pragmatic solution

Most wayland compositors support X11 apps through XWayland. If you launch albert with QT_QPA_PLATFORM=xcb albert to run it through the X protocol, you will probably be allowed many of the luxuries that are considered insecure or evil on Wayland, but also have some of its drawbacks, like poor hidpi handling. For albert, it looks to me as if X11 is currently the lesser of two evils.

If someone wants to work on this, I would recommend asking the sway developers (they've been involved in lots of great other standardization work for the desktop, like middle-mouse pasting and server-side window decorations) what they think and if there's anything you can do to help standardization and adoption of the protocols needed to get albert working properly on Wayland.

@tukanos
Copy link

tukanos commented Feb 10, 2022

@johanhelsing excellent summary. I may take wisdom to a different project. Thank you.

One question:

Global window positioning is more or less considered evil, the reasoning being it should be up to the compositor to decide how to arrange windows.

Why should "compositor to decide how to arrange windows."? The logic here is avoiding me.

You have many use cases where you want to have windows in certain places like monitoring, logs, mails, launcher, etc. Why those applications can not sent hints that the user wants to have it there? The compositor should, if possible, listen to the wishes of the user.

@johanhelsing
Copy link
Contributor

Why should "compositor to decide how to arrange windows."? The logic here is avoiding me.

I can only speculate, personally I think a soft hint would have been great, but these are some possible reasons:

  • You can write really weird compositors and still have things like popups and menus working. VR-compositors, tiling compositors, devices with non-rectangular screen (watches). They are a lot easier to write when the client doesn't assume you have a rectangular screen and they can pop up wherever they want. Then "please put me 100 pixels to the right of this parent" makes a lot more sense than please put me at 340x400.
  • Maybe there is some resistance against it due to the fact that if it was allowed, even as an optional hint, kwin/qt and some others would probably immediately adopt it to solve all the issues Qt has been having with it, and there would be less focus on fixing relative positioning bugs in Qt for instance, making relative positioning-only compositors second-class citizens.
  • More options means more things to support/maintain and more ways for bugs to appear

Tiny disclaimer: I haven't worked with Wayland or Qt for a couple of years, so some of this might have changed recently. I suspect the extension standardization process is a lot easier now than it used to be for instance.

@thorsten-passfeld
Copy link

For anyone coming here because they tried out Wayland (KDE Plasma in my case) and suddenly their beloved Albert did not seem to work anymore, @ManuelSchneid3r has explained how shortcuts are handled very differently in this comment.

I want to add that the way you do this in KDE Plasma is simply to go into the settings -> Shortcuts -> Add Application -> Here, you type the command "albert toggle" and click "Ok" -> Now a new entry appeared in the "Applications" section under Shortcuts. Click on it -> Custom shortcut -> Press the key you want to use to open Albert -> Hit apply and you're good.

Now you can use Albert as expected. The only little problem I have with the latest version 0.19.2 is that the search bar that opens is slightly off-center on subsequent toggles and often times it doesn't show up on the correct monitor. If it helps, I have two monitors connected and it tends to prefer showing up on my second (non-primary) monitor, even if I click and have my cursor on the primary monitor. So it's not quite perfect as of now, but damn I'm happy to keep enjoying Albert. What a great application!

@christoph2497
Copy link

christoph2497 commented Oct 9, 2023

I'm on Ubuntu 23.04 and I experienced an issue regarding albert not recognizing keyboard inputs when I open albert with a shortcut. What fixed it for me was to change the exec command in the albert.desktop file. I just removed the QT_QPA_PLATFORM=xcb part that sets the environment variable and restarted albert. Since then everything works fine for me on wayland.

@ManuelSchneid3r
Copy link
Member Author

I just removed the QT_QPA_PLATFORM=xcb part that sets the environment variable and restarted albert.

This introduces several other issues. wayland QPA is not supported atm. https://packages.ubuntu.com/search?suite=lunar-updates&keywords=gnome yields gnome 44 which introduces this bug: #1231

See also https://gitlab.gnome.org/GNOME/mutter/-/issues/2690

@ManuelSchneid3r ManuelSchneid3r added the C: App Issue related to the core application/library label Nov 8, 2023
@ManuelSchneid3r ManuelSchneid3r removed the Bug P3 Medium Fix, but can wait if there's more import stuff to do. label Nov 18, 2023
@ManuelSchneid3r ManuelSchneid3r added the Suggestion Feature request or some other idea label Nov 18, 2023
@ManuelSchneid3r ManuelSchneid3r changed the title Wayland Wayland support Nov 18, 2023
@Tomptez
Copy link

Tomptez commented Dec 14, 2023

The above mentioned mutter bug seems to be fixed from what I can tell. Does that mean Albert should work fine on wayland when used as described by christoph2497?

@myownfriend
Copy link

Why not use the Global Shortcut's Portal. It's kind of the only way to actually register a hotkey on Linux and it works on X11 and Wayland.

@ManuelSchneid3r
Copy link
Member Author

Skycoder42/QHotkey#89

Nobody implemented it yet.

@RichardFevrier
Copy link

+1 for the support of layer shell under wayland; with the help of layer-shell-qt maybe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: App Issue related to the core application/library
Development

No branches or pull requests

8 participants