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

KeePassXC does not show in Alt+Tab under GNOME Wayland until StartupNotify times out #6423

Closed
chenxiaolong opened this issue Apr 18, 2021 · 15 comments
Labels

Comments

@chenxiaolong
Copy link

Overview

KeePass currently does not show in Alt+Tab under GNOME Wayland until StartupNotify (from the .desktop file) times out. I suspect this is because of the naming differences between the X11 WM_CLASS and Wayland/xdg-shell's app_id.

Under X11, I believe the Qt XCB platform plugin uses QCoreApplication::applicationName() to set the WM_CLASS property. KeePassXC's WM_CLASS is:

$ xprop WM_CLASS
WM_CLASS(STRING) = "keepassxc", "KeePassXC"

Under Wayland, qtwayland uses the .desktop filename to set the app_id: https://github.com/qt/qtwayland/blob/20d7cc45933a4a26c886b47c0b69da82195e7204/src/client/qwaylandwindow.cpp#L159-L163 Thus, the value is set to org.keepassxc.KeePassXC. This can be confirmed by using gnome-shell's "looking glass" feature:
image

Because KeePassXC's .desktop file specifies:

StartupWMClass=keepassxc

it will never match under a Wayland session.

Steps to Reproduce

  1. Load Wayland gnome-shell session
  2. Start KeePassXC via its .desktop file
  3. Immediately try to Alt+Tab

Expected Behavior

KeePassXC should immediately show up in the Alt+Tab list.

Actual Behavior

KeePassXC is missing from Alt+Tab list until StartupNotify times out.

Context

KeePassXC - Version 2.6.4
Revision: 34a78f0

Qt 5.15.2
Debugging mode is disabled.

Operating system: Fedora 34 (Workstation Edition)
CPU architecture: x86_64
Kernel: linux 5.10.19-200.fc33.x86_64

Enabled extensions:
- Auto-Type
- Browser Integration
- SSH Agent
- KeeShare (signed and unsigned sharing)
- YubiKey
- Secret Service Integration

Cryptographic libraries:
- libgcrypt 1.9.2-unknown

Operating System: Fedora 34 (also reproducible under 33)
Desktop Env: Gnome
Windowing System: Wayland

@chenxiaolong
Copy link
Author

chenxiaolong commented Apr 18, 2021

I think this can be fixed by changing:

Application::setApplicationName("KeePassXC");

to call:

    Application::setApplicationName("org.keepassxc.KeePassXC");

and then changing the .desktop file to:

StartupWMClass=org.keepassxc.KeePassXC

Another option would be to rename the .desktop file to keepassxc.desktop.

Both solutions should work under both X11 and Wayland, but I'm not sure if either would have undesired side effects.

EDIT: Maybe renaming the .desktop file isn't a good idea. The latest desktop entry spec says the filename should follow the reverse DNS pattern: https://specifications.freedesktop.org/desktop-entry-spec/latest/ar01s02.html

@droidmonkey
Copy link
Member

droidmonkey commented Apr 18, 2021

This is stupid, but thank you for finding this problem.
Our application name is not "org.keepassxc.KeePassXC" so that would be an incorrect change. The application name is used for a lot of different things in Qt.

@droidmonkey
Copy link
Member

I think just changing StartupWMClass to the reverse DNS pattern should be sufficient. Does X11 even care about that attribute?

@chenxiaolong
Copy link
Author

I think just changing StartupWMClass to the reverse DNS pattern should be sufficient. Does X11 even care about that attribute?

Good question. I'll try that out really quick.

@chenxiaolong
Copy link
Author

By only making the:

StartupWMClass=org.keepassxc.KeePassXC

change, it works properly in Wayland. KeePassXC shows up in Alt-Tab immediately. On X11, KeePassXC still immediately shows up in Alt+Tab, but gnome-shell's looking glass shows the window as untracked:

image

likely because WM_CLASS ("KeePassXC") now no longer matches StartupWMClass. I suspect this breaks StartupNotify behavior on X11.

@droidmonkey
Copy link
Member

We can also just do QGuiApplication::setDesktopFileName("keepassxc") which will use the common WMClass name on Wayland instead of Qt building it dynamically.

@chenxiaolong
Copy link
Author

I can test that out really quickly. Do you know if that would have other side effects in Qt?

@droidmonkey
Copy link
Member

The docs state it is only used in this specific use case:

This property holds the base name of the desktop entry for this application

This is the file name, without the full path, of the desktop entry that represents this application according to the freedesktop desktop entry specification.

This property gives a precise indication of what desktop entry represents the application and it is needed by the windowing system to retrieve such information without resorting to imprecise heuristics.

The latest version of the freedesktop desktop entry specification can be obtained here.

This property was introduced in Qt 5.7.

@droidmonkey
Copy link
Member

Might there also be a better attribute to put in the desktop file for Wayland's use? I feel like this would be a problem for a lot of applications.

@chenxiaolong
Copy link
Author

chenxiaolong commented Apr 18, 2021

I wasn't able to find a better attribute unfortunately, but maybe I missed something. This would indeed be a problem for a lot of applications, but it seems most Qt applications don't meet all these conditions:

  • StartupNotify is set to true
  • StartupWMClass == X11's WM_CLASS
  • .desktop filename (and thus Wayland's app_id) != X11's WM_CLASS

The only other program I have installed that behaves this way is KDE's Konsole.

@chenxiaolong
Copy link
Author

chenxiaolong commented Apr 18, 2021

I looked through gnome-shell's code a bit and I think this is a GNOME bug. If the Wayland app_id (or X11 WM_CLASS) doesn't match StartupWMClass, it's supposed to try and match the name with the .desktop file: https://gitlab.gnome.org/GNOME/gnome-shell/-/blob/40.0/src/shell-window-tracker.c#L192-212

I still don't know if StartupWMClass is meant to be used under Wayland or if this naming mismatch affects other desktop environments.

@chenxiaolong
Copy link
Author

chenxiaolong commented Apr 18, 2021

Yep, looks like this is a known issue on GNOME + Wayland: https://gitlab.gnome.org/GNOME/mutter/-/issues/1330

I think this can be closed, unless KeePassXC would be willing to work around this issue with StartupNotify=false.

@chenxiaolong
Copy link
Author

chenxiaolong commented Apr 18, 2021

Looks like startup notifications will be properly supported by a new xdg_activation Wayland protocol that will be implemented by toolkits and desktop environments. https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/50

I'm going to close this issue since KeePassXC is not doing anything incorrectly.

@droidmonkey
Copy link
Member

Great! Now I'm upset I deleted my comment blaming Gnome itself.

@Gert-dev
Copy link

Gert-dev commented Mar 13, 2023

FWIW, there has been an update on this from GNOME's side, see also this ticket, especially this reply and this reply.

If I understood correctly, this means that since the previous posts, xdg_activation is now supported by GNOME with StartupNotify=true on Wayland, but the issue won't be fixed until KeePassXC can upgrade to Qt 6.2, which is related to #7774.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants