Bug 430388 - Custom Shortcuts cannot record key presses
Summary: Custom Shortcuts cannot record key presses
Status: RESOLVED FIXED
Alias: None
Product: frameworks-kxmlgui
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: 5.77.0
Platform: Arch Linux Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
: 430460 430481 430495 430635 430710 431028 431225 431243 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-12-14 17:40 UTC by CUI Hao
Modified: 2021-01-26 19:17 UTC (History)
19 users (show)

See Also:
Latest Commit:
Version Fixed In: 5.78


Attachments
A short video to demonstrate the issue (1.58 MB, image/gif)
2020-12-14 17:40 UTC, CUI Hao
Details

Note You need to log in before you can comment on or make changes to this bug.
Description CUI Hao 2020-12-14 17:40:45 UTC
Created attachment 134075 [details]
A short video to demonstrate the issue

SUMMARY

I couldn't set shortcut keys in "Custom Shortcuts" setting because it failed to record my key presses.

STEPS TO REPRODUCE
1. Open "Custom Shortcuts" tab in KDE System Settings.
2. Create a new shortcut or edit an existing one.
3. Switch to the "Trigger" tab, activate the shortcut button following "Shortcut:" text.
3. Press desired key or key combination to set the shortcut.

OBSERVED RESULT

Key presses were not recorded. The shortcut button still showed "None".

A line of error "kf.guiaddons: Cannot record without a window" appeared in stderr every time when pressing the shortcut button.

EXPECTED RESULT

Key presses are correctly recorded.

SOFTWARE/OS VERSIONS

Operating System: Arch Linux
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2
Comment 1 YAFU 2020-12-15 23:45:39 UTC
Hi.
The same thing is happening to me when I want to configure keyboard shortcuts from KDE Menu Editor.

KDE Neon (Testing)
KDE Frameworks Version: 5.77.0
Comment 2 Nate Graham 2020-12-16 00:16:38 UTC
This bug report is about the "Custom Shortcuts" page in System Settings, not the different system used by the "Shortcuts" page and KMenuEdit.
Comment 3 YAFU 2020-12-16 08:40:12 UTC
In both cases from System Settings or KDE Menu Editor the same thing happens, when you click on the field to enter a new key combination, the field does not react and it keeps showing "none" (or old key combination) and new key combination is not entered. The problem is recent and happens in both cases at the same time. The source of the problem should be the same, or is it really a very strange coincidence.
Comment 4 YAFU 2020-12-16 08:48:48 UTC
And I get the same error with kmenuedit:
kf.guiaddons: Cannot record without a window
Comment 5 Nate Graham 2020-12-16 15:02:24 UTC
No, the sources of the problem are different. This KCM has a totally custom implementation, while KMenuEdit and the Shortcuts KCM use KGlobalAccel

Please file a new bug for your issues with the kglobalaccel-based issue seen in KMenuEdit and the Shortcuts page, which doesn't have anything to do with this bug report. :)
Comment 6 Nate Graham 2020-12-16 16:00:00 UTC
*** Bug 430460 has been marked as a duplicate of this bug. ***
Comment 7 YAFU 2020-12-16 19:04:56 UTC
If they have different system shortcuts, then you look for the source of the problem in Qt/GUI and the field type for shortcut input. I don't believe in these kinds of coincidences.
Comment 8 Nate Graham 2020-12-16 19:06:28 UTC
I'm a KDE developer familiar with the code in question and I'm telling you that they are unrelated. If you don't want to file a new bug report to track your issue, that's fine, but then we won't be able to investigate it and hopefully provide a fix.
Comment 9 Jeff Tratt 2020-12-16 19:45:25 UTC
I've edited:
~/.config/kglobalshortcutsrc
~/.config/khotkeysrc
and changed the hotkey to what I want. When I reboot and log into tty F1 and look at the files they are what I edited. When I login to the gui the hotkey is replaced with "none" in both files.

As a kludge I did this:
sudo chattr +i ~/.config/kglobalshortcutsrc
sudo chattr +i ~/.config/khotkeysrc
to make the files immutable. Reboot and login now keeps the hotkeys and they work. I don't know what is overwriting the files on login.

I'm on up to date kde neon plasma.
Comment 10 Heu Fui 2020-12-16 20:31:41 UTC
(In reply to Jeff Tratt from comment #9)
> I've edited:
> ~/.config/kglobalshortcutsrc
> ~/.config/khotkeysrc
> and changed the hotkey to what I want. When I reboot and log into tty F1 and
> look at the files they are what I edited. When I login to the gui the hotkey
> is replaced with "none" in both files.
> 
> As a kludge I did this:
> sudo chattr +i ~/.config/kglobalshortcutsrc
> sudo chattr +i ~/.config/khotkeysrc
> to make the files immutable. Reboot and login now keeps the hotkeys and they
> work. I don't know what is overwriting the files on login.
> 
> I'm on up to date kde neon plasma.

I did just that, but only editing khotkeysrc. Unfortunately, I couldn't change it manually, as it gets rewritten as soon KDE starts.
Comment 11 Jeff Tratt 2020-12-16 22:46:02 UTC
(In reply to Heu Fui from comment #10)
> I did just that, but only editing khotkeysrc. Unfortunately, I couldn't
> change it manually, as it gets rewritten as soon KDE starts.

Edit the file ~/.config/khotkeysrc
then in terminal enter
sudo chattr +i ~/.config/khotkeysrc

Verify the file is immutable:
lsattr ~/.config/khotkeysrc
----i---------e----- ~/.config/khotkeysrc
The "i" validates the file is immutable.

You may need to edit both files for this kludge to work. I didn't try editing only the one file.
Comment 12 Heu Fui 2020-12-17 00:05:18 UTC
(In reply to Jeff Tratt from comment #11)
> (In reply to Heu Fui from comment #10)
> > I did just that, but only editing khotkeysrc. Unfortunately, I couldn't
> > change it manually, as it gets rewritten as soon KDE starts.
> 
> Edit the file ~/.config/khotkeysrc
> then in terminal enter
> sudo chattr +i ~/.config/khotkeysrc
> 
> Verify the file is immutable:
> lsattr ~/.config/khotkeysrc
> ----i---------e----- ~/.config/khotkeysrc
> The "i" validates the file is immutable.
> 
> You may need to edit both files for this kludge to work. I didn't try
> editing only the one file.

Thank you. Will do that. When all else fails, manual editing files is a great solution.
Comment 13 Jeff Tratt 2020-12-17 00:13:45 UTC
(In reply to Heu Fui from comment #12)
> Thank you. Will do that. When all else fails, manual editing files is a
> great solution.

You're welcome. You will need to run the following to make the files editable in the future:
sudo chattr -i ~/.config/kglobalshortcutsrc
sudo chattr -i ~/.config/khotkeysrc

the '-i' will remove the immutable bit. As immutable nothing can edit these files ;)
Comment 14 Heu Fui 2020-12-17 02:03:00 UTC
(In reply to Jeff Tratt from comment #13)
> (In reply to Heu Fui from comment #12)
> > Thank you. Will do that. When all else fails, manual editing files is a
> > great solution.
> 
> You're welcome. You will need to run the following to make the files
> editable in the future:
> sudo chattr -i ~/.config/kglobalshortcutsrc
> sudo chattr -i ~/.config/khotkeysrc
> 
> the '-i' will remove the immutable bit. As immutable nothing can edit these
> files ;)

Thanks again! You've pointed out in the right direction. Did exactly what you proposed and now my much needed custom shortcut is finally working.

Will keep those files immutable until this bug is solved.
Comment 15 Juan Simón 2020-12-17 09:31:25 UTC
Operating System: Arch Linux
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2

Same problem. The error in console is: "kf.guiaddons: Cannot record without a window"
Comment 16 Weng Xuetian 2020-12-17 19:15:40 UTC
(In reply to Nate Graham from comment #5)
> No, the sources of the problem are different. This KCM has a totally custom
> implementation, while KMenuEdit and the Shortcuts KCM use KGlobalAccel
> 
> Please file a new bug for your issues with the kglobalaccel-based issue seen
> in KMenuEdit and the Shortcuts page, which doesn't have anything to do with
> this bug report. :)

But looks like "kcmshell5 khotkeys" would also produced the same error.

Looking closer, I think the bug is in kxmlgui, when it is ported to KeySequenceRecorder.

I think the issue is when it is constructed, the widget may not yet added to a window. So pass the window to KeySequenceRecorder in constructor doesn't work.

Sent a merge request to fix this.
Comment 17 Bug Janitor Service 2020-12-17 19:15:52 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kxmlgui/-/merge_requests/34
Comment 18 Nate Graham 2020-12-17 21:15:34 UTC
*** Bug 430495 has been marked as a duplicate of this bug. ***
Comment 19 Nate Graham 2020-12-17 21:29:31 UTC
*** Bug 430481 has been marked as a duplicate of this bug. ***
Comment 20 Heu Fui 2020-12-21 08:23:37 UTC
I just found another workaround.

All you do is to go to the System Settings > Shortcuts, and on the search field you look up the custom shortcut you need to add/change. On the results box, press the desired result and click the corresponding buttons either to add/change shortcut or to add another. Your shortcut combination will now be registered and accepted.

Example: https://i.imgur.com/rWKvvWy.png
Comment 21 Ricky Kresslein 2020-12-21 14:50:29 UTC
Thank you, Heu Fui, your workaround of doing a search in the standard shortcuts menu worked for me.
Comment 22 Jeff Tratt 2020-12-21 17:47:49 UTC
(In reply to Heu Fui from comment #20)
> I just found another workaround.
> 
> All you do is to go to the System Settings > Shortcuts, and on the search
> field you look up the custom shortcut you need to add/change. On the results
> box, press the desired result and click the corresponding buttons either to
> add/change shortcut or to add another. Your shortcut combination will now be
> registered and accepted.
> 
> Example: https://i.imgur.com/rWKvvWy.png

Great find, Heu Fui. Your solution survived reboot and kept the change I made manually. Much better solution! Thank you.
Comment 23 Weng Xuetian 2020-12-22 12:54:06 UTC
Git commit 1bd9ac05b0eed3582937829150b31ea48fd95bb0 by Xuetian Weng, on behalf of Weng Xuetian.
Committed on 22/12/2020 at 05:19.
Pushed by xuetianweng into branch 'master'.

Fix key recording by setWindow before capture starts.

It is common that during the construction of widget, it is not yet added to
a window. Thus windowHandle will simply return null in this case. Always set
the window to before the capture starts.

M  +1    -0    src/kkeysequencewidget.cpp

https://invent.kde.org/frameworks/kxmlgui/commit/1bd9ac05b0eed3582937829150b31ea48fd95bb0
Comment 24 Patrick Silva 2020-12-23 18:54:29 UTC
*** Bug 430710 has been marked as a duplicate of this bug. ***
Comment 25 geisserml 2020-12-23 20:27:48 UTC
(In reply to Nate Graham from comment #8)
> I'm a KDE developer familiar with the code in question and I'm telling you
> that they are unrelated. If you don't want to file a new bug report to track
> your issue, that's fine, but then we won't be able to investigate it and
> hopefully provide a fix.

khotkeys was changed to use KGlobalAccel in this commit: https://invent.kde.org/plasma/khotkeys/-/commit/f42a8446be7657ec3397be7fc253f7f64cb31392
Comment 26 geisserml 2020-12-23 20:35:20 UTC
and kmenuedit too with this commit: https://invent.kde.org/plasma/kmenuedit/-/commit/507bc58bf3e8704cdb4eab51ca16a2eb28299bb6
Comment 27 Nate Graham 2020-12-23 21:02:13 UTC
Hah I totally missed that it was ported to kglobalaccel. My bad, sorry.
Comment 28 YAFU 2020-12-23 23:23:46 UTC
Entering new shortcuts now works here in KDE Neon (Testing). Thanks to all the developers.
@Nate Graham, sorry for my attitude. Regardless of what was causing the problem, perhaps I should have opened the new report from the beginning just in case.
Comment 29 Benjamin Robin 2020-12-29 14:18:19 UTC
*** Bug 430635 has been marked as a duplicate of this bug. ***
Comment 30 Nate Graham 2021-01-05 02:18:51 UTC
*** Bug 431028 has been marked as a duplicate of this bug. ***
Comment 31 Nate Graham 2021-01-06 15:50:45 UTC
*** Bug 431225 has been marked as a duplicate of this bug. ***
Comment 32 Armando Ota 2021-01-06 15:58:24 UTC
when can we expect the fix to be released?
Comment 33 Nate Graham 2021-01-06 16:02:56 UTC
3 days :)
Comment 34 Nate Graham 2021-01-07 18:21:07 UTC
*** Bug 431243 has been marked as a duplicate of this bug. ***
Comment 35 r.j.skolasinski 2021-01-09 21:48:33 UTC
> 3 days :)

Does this mean that fix will land today in KDE Neon? :)
Comment 36 Armando Ota 2021-01-10 07:40:10 UTC
tried it after yesterdays update ... no joy ;)
Comment 37 geisserml 2021-01-10 18:04:04 UTC
In general, for the KDE Neon User Edition, it would be nice if small, non-breaking bugfixes like this one could be released earlier, for example together with or one day after Neon Testing.
Comment 38 Toadfield 2021-01-12 19:06:50 UTC
Guys,does it work now for you?
Comment 39 Jeff Tratt 2021-01-12 19:34:11 UTC
I created a new shortcut today and it worked fine. Thanks to everyone who contributed.
Comment 40 geisserml 2021-01-13 18:12:12 UTC
I can also confirm that it works again :)
Comment 41 Toadfield 2021-01-16 23:28:53 UTC
I tried it and it doesn't work for me.
Comment 42 geisserml 2021-01-17 16:43:54 UTC
(In reply to Toadfield from comment #41)
> I tried it and it doesn't work for me.

Could you describe more detailed, please? Is the behaviour you are experiencing still exactly the same as in the issue description?
Is your system up-to-date? Which distribution are you using?
Comment 43 Armando Ota 2021-01-17 18:01:01 UTC
I can cofirm .. fixed it for me
Comment 44 Toadfield 2021-01-21 20:52:48 UTC
(In reply to Manuel Geißer from comment #42)
> (In reply to Toadfield from comment #41)
> > I tried it and it doesn't work for me.
> 
> Could you describe more detailed, please? Is the behaviour you are
> experiencing still exactly the same as in the issue description?
> Is your system up-to-date? Which distribution are you using?

It is the same thing and I use Manjaro and my system is up to date.
Comment 45 geisserml 2021-01-22 13:02:39 UTC
(In reply to Toadfield from comment #44)
> It is the same thing and I use Manjaro and my system is up to date.

Then I think you should probably report this upstream in the Manjaro packages bug tracker.
Comment 46 Heu Fui 2021-01-22 16:17:40 UTC
Updated Arch Linux. I've tested it and it's working.

Thank you all.
Comment 47 Jeff Tratt 2021-01-22 17:40:35 UTC
(In reply to Toadfield from comment #41)
> I tried it and it doesn't work for me.

If you tried the kludge I recommended which sets the files to immutable you will need to undo that.

Run the following to make the files editable:
sudo chattr -i ~/.config/kglobalshortcutsrc
sudo chattr -i ~/.config/khotkeysrc

the '-i' will remove the immutable bit so the system can edit these files.