Bug 356220

Summary: Keyboard layout not being switched using a keyboard shortcut
Product: [Unmaintained] telepathy Reporter: Ondřej Kučera <ondrej.kucera>
Component: text-uiAssignee: Telepathy Bugs <kde-telepathy-bugs>
Status: RESOLVED FIXED    
Severity: normal CC: eugene.shalygin+bugzilla.kde, mklapetek
Priority: NOR    
Version: 15.08.2   
Target Milestone: Future   
Platform: Arch Linux   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:

Description Ondřej Kučera 2015-12-03 02:07:52 UTC
I'm using two keyboard layouts (English and Czech) and a custom global shortcut (Meta+K) for switching. When I'm in the chat window, the Czech layout is activated (for example) and I press Meta+K, Plasma shows me an "OSD image" of keyboard being switched to English but that in fact doesn't happen.
When I use the icon in the system tray instead of the keyboard shortcut, everything works as expected.

Reproducible: Always

Steps to Reproduce:
1. Configure two keyboard layouts.
2. Open the chat window.
3. Press a keyboard shortcut for layout switching (Ctrl+Alt+K by default, IIRC).

Actual Results:  
The layout isn't switched.

Expected Results:  
The layout should be switched.
Comment 1 Martin Klapetek 2015-12-07 19:25:10 UTC
Thanks for the report

Is this happening only in ktp-text-ui? Or also in other applications?
Comment 2 Ondřej Kučera 2015-12-07 20:18:07 UTC
Only there. It works properly in all other applications that I use.
Comment 3 Martin Klapetek 2015-12-07 20:23:11 UTC
Ok, it's probably due to the layout-per-tab handling the text-ui uses.

I'll have a look.
Comment 4 Martin Klapetek 2015-12-07 20:30:27 UTC
Are you able to test patches btw?
Comment 5 Martin Klapetek 2015-12-07 20:32:36 UTC
Actually, what would be easier, please install bustle, run bustle, open some chat, switch the keyboard layout, stop bustle, save the log and attach it here. You can also email it directly if you're concerned about your data (it may contain your account and the chat contact).
Comment 6 Martin Klapetek 2015-12-07 21:29:05 UTC
Ok, after inspecting the bustle log and the code, I think I see the problem.

In app/chat-window.cpp, the restoreKeyboardLayout(..) is called on various occasions, this in turn calls the setLayout on the keyboard switching interface. I guess it's called with the old layout from somewhere.

I'll investigate more properly later tonight.

Oh and btw, for testing patches, you'd need to recompile only ktp-text-ui, should be really simple :)
Comment 7 Martin Klapetek 2015-12-09 03:47:37 UTC
Ok I understand now what's going on. It's...unexpected.

So. If you use "save layout per tab", the layout is set everytime
you switch to the window (make it an active window). Now when
you press the key combo to change layout, the OSD popups up
and that takes the focus away from ktp-text-ui, even if for a split
of a second. After that, the text-ui is switched back to, ie. made
an active window. At this point, text-ui is setting the "old" layout
back (because the updated layout didn't make it to it yet).

And that makes it look like it's blocking the change.
Comment 8 Martin Klapetek 2015-12-10 20:49:15 UTC
Some updates.

I made a patch yesterday [1] fixing this problem. I've added
Martin G to the review which prompted him to look for the
root cause of the bug (described in previous comment) and
it will likely get fixed elsewhere, but for the time being the
exact cause of the WindowDeactivate/WindowActivate events
is still unknown.

[1] - https://git.reviewboard.kde.org/r/126287/
Comment 9 Martin Klapetek 2015-12-10 20:54:45 UTC
*** Bug 333742 has been marked as a duplicate of this bug. ***
Comment 10 Ondřej Kučera 2016-01-30 17:16:38 UTC
It works properly now in 15.12.1.