Bug 464706 - Global shortcuts only work once
Summary: Global shortcuts only work once
Status: RESOLVED FIXED
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: unspecified
Platform: Other Linux
: VHI major
Target Milestone: ---
Assignee: Boudhayan Gupta
URL:
Keywords: regression
: 465014 (view as bug list)
Depends on:
Blocks:
 
Reported: 2023-01-23 18:09 UTC by Kai Uwe Broulik
Modified: 2023-02-06 18:21 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kai Uwe Broulik 2023-01-23 18:09:18 UTC
The global shortcuts for taking screenshots with Spectacle (Print Screen and its modifier derivates) only work once.

STEPS TO REPRODUCE
1. Press Print
2. Close Spectacle
3. Press Print again

OBSERVED RESULT
Nothing happens

EXPECTED RESULT
Spectacle opens again

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: git master as of 2023-01-22

ADDITIONAL INFORMATION
Spectacle uses actions defined in its desktop file for those shortcuts, however since the QML rewrite it also calls  KGlobalAccel::self()->setGlobalShortcut in its SpectacleCore.cpp.
This has KGlobalAccel track the shortcut and set it "inactive" when the app quits because the action normally couldn't be invoked with the app gone.
It didn't surface until now where Spectacle actually quits properly again after taking a screenshot.
The reason for calling KGlobalAccel isn't clear and might be superfluous, since the actions are handled by the desktop file. If the shortcut is shown in the UI, then I think something else needs to be done than call KGlobalAccel.
Comment 1 Nate Graham 2023-01-23 18:40:34 UTC
Can confirm. Seems to have started happening in the last day or two.
Comment 2 ratijas 2023-01-23 19:10:44 UTC
Can confirm. I though I was going insane
Comment 3 Noah Davis 2023-01-25 10:30:23 UTC
(In reply to Kai Uwe Broulik from comment #0)
> Spectacle uses actions defined in its desktop file for those shortcuts,
> however since the QML rewrite it also calls 
> KGlobalAccel::self()->setGlobalShortcut in its SpectacleCore.cpp.
> This has KGlobalAccel track the shortcut and set it "inactive" when the app
> quits because the action normally couldn't be invoked with the app gone.
> It didn't surface until now where Spectacle actually quits properly again
> after taking a screenshot.
> The reason for calling KGlobalAccel isn't clear and might be superfluous,
> since the actions are handled by the desktop file. If the shortcut is shown
> in the UI, then I think something else needs to be done than call
> KGlobalAccel.

It used `KGlobalAccel::self()->setGlobalShortcut()` before the rewrite though. They were done in `SpectacleCore::setUpShortcuts()`, but that function did exactly the same thing as what is being done now. It also should have been closing properly before the rewrite and it only didn't close properly for certain modes after the rewrite, so I'm still not sure why the issue has come up now. `setGlobalShotcut()` seems to be needed in order to actually set a default key sequence for a global shortcut.
Comment 4 David Redondo 2023-01-25 10:56:47 UTC
The actions are now properly cleaned up since https://invent.kde.org/graphics/spectacle/-/commit/dbb7e5c507c51b2974ebab2e7b69d33ac8bc7dc0
Comment 5 Bug Janitor Service 2023-01-25 11:07:40 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/spectacle/-/merge_requests/187
Comment 6 Noah Davis 2023-01-25 13:41:48 UTC
Git commit aa51a0bdad4d861240227dfb80d67f7c856e467d by Noah Davis.
Committed on 25/01/2023 at 11:07.
Pushed by ndavis into branch 'master'.

Fix global shortcuts only working once

This happened because the actions were given a parent in a previous
commit. They worked more than once before the commit because the actions
were being leaked. `action->setProperty("isConfigurationAction", true)`
fixes the single use action problem.

M  +7    -0    src/ShortcutActions.cpp

https://invent.kde.org/graphics/spectacle/commit/aa51a0bdad4d861240227dfb80d67f7c856e467d
Comment 7 Nate Graham 2023-02-06 18:21:10 UTC
*** Bug 465014 has been marked as a duplicate of this bug. ***