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

global shortcuts: fix crash by ignoring duplicate shortcuts #241

Merged
merged 3 commits into from
Jul 23, 2024

Conversation

dec05eba
Copy link
Contributor

hyprland_global_shortcuts_manager_v1_register_shortcut will cause an error if the (app_id, shortcut_id) combination has already been registered. Ignore shortcuts that have already been registered.

When a shortcut is registered again it should also overwrite the session for the keybind to make the shortcut work after restarting an application, otherwise the key can't be used again.

Fixes #236

hyprland_global_shortcuts_manager_v1_register_shortcut will cause an
error if the (app_id, shortcut_id) combination has already been
registered. Ignore shortcuts that have already been registered.

When a shortcut is registered again it should also overwrite the
session for the keybind to make the shortcut work after restarting
an application, otherwise the key can't be used again.
@dec05eba
Copy link
Contributor Author

dec05eba commented Jul 21, 2024

I also noticed that "shortcuts" in CreateSession will never exist since xdg-desktop-portal ignores that key in CreateSession. This means that to make sure shortcuts work applications need to call BindShortcut on program startup. The issue with that is that BindShortcut documentation says that the portal can show a dialog when this happens (https://github.com/flatpak/xdg-desktop-portal/blob/a74c2ee93befca1f8583e86e165dbe90a0e72a15/data/org.freedesktop.portal.GlobalShortcuts.xml#L88) and that is the case with KDE. It will show the global shortcuts dialog where you can setup keys.
That means you cant call BindShortcut on program startup as that would show the dialog everytime. The only solution I know right now is to only call BindShortcut on program startup if the desktop portal running on the system is Hyprland.

KDE handles this differently. It saves the "session_handle_token" (to disk, it remembers it even after you restart your computer) and automatically registers the shortcuts the next time you call CreateSession with the same "session_handle_token". This difference in behavior means programs cant create one global shortcut solution that works with every desktop portal.

@dec05eba
Copy link
Contributor Author

(I tested these changes with a real program (https://git.dec05eba.com/gpu-screen-recorder-gtk/about/), after allowing it to run on hyprland)

Copy link
Member

@vaxerski vaxerski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks!

@vaxerski vaxerski merged commit 3b8c781 into hyprwm:master Jul 23, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crashes when registering a taken global shortcut id
2 participants