Bug 351198

Summary: 'Numlock' is not trigger-able
Product: [Frameworks and Libraries] frameworks-kglobalaccel Reporter: Emil Sedgh <emilsedgh>
Component: generalAssignee: Martin Flöser <mgraesslin>
Status: RESOLVED DUPLICATE    
Severity: normal CC: kdelibs-bugs, thomas.luebking
Priority: NOR Flags: thomas.luebking: corner_case+
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:

Description Emil Sedgh 2015-08-11 19:53:24 UTC
On KDE SC 4.x I used to have 'Numlock' as a global shortcut to activate 'Present Windows' desktop effect and it worked just fine.

On KF5/Plasma shell, I can save the Numlock as the shortcut for an action but pressing the button does not trigger the action.

Notes:
1) I first thought it could be a problem with present windows effect, but I tried Numlock for different shortcuts and no action is triggered by numlock.

2) I also thought that 'one-key' shortcuts might have a problem. But I have 'F12' as another global shortcut and it works fine.

3) None of the combinations of Numlock work (ef Ctrl+Numlock)

Reproducible: Always

Steps to Reproduce:
Open 'Global shortcut settings'.
Choose an action (Like 'Activate Present windows on all desktops')
Define shortcut for it as 'Numlock'
Apply the changes
Press 'Numlock'.


Actual Results:  
Nothing happens

Expected Results:  
I expect the 'Present windows' to be triggered.
Comment 1 Thomas Lübking 2015-08-11 20:03:40 UTC
I assume it works with no shortcut (whether for kwin, plasmashell, krunner, ...)?

Stunningly, it works here (numlock is actually a modifier on the X11 level, like meta or alt)
I assme the problem is a keyboard layout change after kglobalaccel was started.

Try to
   pkill kglobalaccel5; sleep 2; kglobalaccel5 &

and whether the numlock shortcut suddenly works afterwards.
Comment 2 Emil Sedgh 2015-08-11 20:14:54 UTC
Oh well, I'm using Caps-Lock as an additional 'Numlock'.
But I assumed that works fine because on 'Set shorctur' dialog when I press the Caps Lock button, it catches 'NumLock'.

So steps to reproduce:

1) Go to system settings -> Input devices -> Keyboard -> Advances tab
2) Under the menu 'Caps lock key behavior' check the 'Mark Caps Lock an additional Num Lock'
3) Open 'Global shortcut settings'.
4) Choose an action (Like 'Activate Present windows on all desktops')
5) Click to define a custom shortcut
6) Press 'Caps lock' (you can see that buttons shows 'Numlock')
7) Apply the changes
8) Press 'Numlock'

(And no, restarting kglobalaccel didn't help)
Comment 3 Thomas Lübking 2015-08-11 20:20:07 UTC
To clarify, you assign SW "numlock" by pressing HW "caps lock" and then the shortcut fails on the HW "numlock" key?
Comment 4 Emil Sedgh 2015-08-11 20:28:55 UTC
Oh I'm sorry Thomas, no.
Step 8 must be 'Press Caps Lock'
Comment 5 Thomas Lübking 2015-08-11 21:49:46 UTC
What happens here is that only one of the keys (caps_lock XOR numlock)
a) acts as numlock (toggling the state)
b) triggers the shortcut
despite both generate a Num_Lock keysym.

It seems to be always the same and -actually- rather caps lock (ie. numlock being dead, but that might depend on the hardware layout or some caching)

How did that act on KDE4? Could you use both keys to toggle the keypad state?
Can you use _one_ of the keys to trigger the shortcut?
Comment 6 Emil Sedgh 2015-08-11 22:00:58 UTC
I don't have an actual Numlock key on my keyboard
(Rather Syslock+Scroll Lock acts as NumLock).

But on KDE4, I could've used Capselock-as-Numlock alone (with no combination).

I also could've used Caps Lock alone.

Im also on #kwin if you need me.
Comment 7 Thomas Lübking 2015-08-11 22:53:22 UTC
I would assume that's because xcb_key_symbols_get_keycode returns a list of keycodes, but kglobalaccel only interprets the first one. I could assume unlike Xlib, where XKeysymToKeycode returns only one value, the keycodes are handled distinct in xcb.

Martin, recall https://git.reviewboard.kde.org/r/122454/#review75534 ;-)

dev note:
the returned array is nullptr or terminated by XCB_NO_SYMBOL
Comment 8 Thomas Lübking 2015-08-12 09:53:14 UTC
https://git.reviewboard.kde.org/r/124710/

Notice that you can map caps_lock to other stuff (notably using xmodmap allows for pretty much everything in a rather simple manor)
Freaking around with numlock is generally error prone since you toggle the modifier as well and the modifier combo *does* matter on X11.

While th major toolkits will likely cover that, other handcrafted code may fail to handle certain keyboard input correctly.
Comment 9 Emil Sedgh 2015-08-12 13:35:22 UTC
I applied the patch and tested it,
but it doesn't seem to fix the issue.
Comment 10 Thomas Lübking 2015-08-12 14:33:36 UTC
That would seem to be a problem.

However, there's a trap on installation.
Plugins by default get installed to /usr/lib/plugins/org.kde.kglobalaccel5.platforms but most distro installation have a plugin path of /usr/lib/qt/plugins/org.kde.kglobalaccel5.platforms

=> check whether the updated plugin is loaded (watch make install and compare "strace kglobalaccel5 2>&1 | grep  KF5GlobalAccelPrivateXcb.so")

Since you however luckily can build patches, we can easily add some debug code to see what's failing otherwise.
Comment 11 Emil Sedgh 2015-08-12 14:48:37 UTC
I have KF5/Plasma built from sources using kdesrc-build, so there's no system-wide KDE installed.
So I'm sure this is the used plugin.

However, something funny just happened.
I saw you last comment and found out that there's now a 'kglobalaccel5' binary.

`killall kglobalaccel5`
`kglobalaccel5`

Voila. The caps:num now works as expected :)

I tried a few times. Started Plasma, it was broken. Then I killed kglobalaccel5 and started it manually and caps:num works.

That's with your patch applied. I will now try to undo your patch and see if it still behaves the same when killed and started manually.
Comment 12 Emil Sedgh 2015-08-12 14:53:22 UTC
I removed your patch and tried again.
Even without your patch, killing kglobalaccel5 and starting it again fixes the issue.
Comment 13 Thomas Lübking 2015-08-12 15:14:07 UTC
Errheeemmm... I'll refer to comment #1, push out my chest and say:

    "I told you!"

(Silence, I need that ;-)

Did you fetch kglobalaccel from git (master) or a stable tarball - for the recent commits seem to have patches for keymap change updates?
Comment 14 Emil Sedgh 2015-08-12 15:25:05 UTC
Oh you indeed told me and I promise I tried that. Weird.
Sorry about that man.

Its from git. Last commit:     "Upgrade KF5 version to 5.14.0."
Comment 15 Thomas Lübking 2015-08-20 08:20:11 UTC
No problem. Just helps telling myself that I'm a genius ;-)

So this is rather "just" a defect in catching re-map events then.

*** This bug has been marked as a duplicate of bug 350816 ***
Comment 16 Thomas Lübking 2015-10-05 21:36:15 UTC
Git commit bf71e536bd14e954c44da4ed7af43ef4ee711953 by Thomas Lübking.
Committed on 05/10/2015 at 21:19.
Pushed by luebking into branch 'master'.

Grab all keys for a symbol

Otherwise, if a symbol is represented
by more than one key, only one key
will be an operative shortcut (though
they're both the same symbol)
REVIEW: 124710

M  +63   -58   src/runtime/plugins/xcb/kglobalaccel_x11.cpp

http://commits.kde.org/kglobalaccel/bf71e536bd14e954c44da4ed7af43ef4ee711953
Comment 17 Emil Sedgh 2015-10-05 23:01:46 UTC
Just wanted to thank you, Thomas :)
Comment 18 Thomas Lübking 2015-10-06 07:42:39 UTC
The actual bug (kbd map updates not caught) is not fixed, the patch only improves the situation for multiple mappings.
Comment 19 Emil Sedgh 2016-08-30 17:11:52 UTC
*** Bug 367953 has been marked as a duplicate of this bug. ***