qnikst / kbdd

keyboard library for per-window keyboard layout
GNU General Public License v2.0
146 stars 16 forks source link

kbdd randomly switches layouts #44

Closed Hi-Angel closed 7 years ago

Hi-Angel commented 7 years ago

On Archlinux + i3, kbdd for switching windows often either "forgets" to switch layout, or switches to the wrong one (presumably because it "forgot" to switch the layout previously, and remembered the wrong one).

$ kbdd -n
:main Connecting to the Session D-Bus.
:main Regiresting the well-known name (ru.gentoo.KbddService)
:main RequestName returned (null).
:main Creating one MKbddService Object
:main Registering project to D-Bus.
Ready to serve requests
EWMH is supported
Initializing EWHM event listeners

It's the output for kbdd -n just started — unfortunately the problem doesn't trigger output.

UPD: forgot to say: it somehow worked earlier, upgrade broke it. However, the bug seems to be old, because I remember having alike problem earlier either, but it didn't happen that often.

Hi-Angel commented 7 years ago

I tried to debug it, found that at libkbdd.c:255

    if (ev.type == _kbdd._xkbEventType)
        _on_xkbEvent(ev);

the condition should be true on every xkb event. As I understand, layout switch is such an event, but it doesn't trigger the condition.

Idk how to debug further because I'd have to find out what event code the ev.type actually is, but I have no idea what function I have to use, and neither I know X11 or Xkb.

Anyway, I hope that help.

qnikst commented 7 years ago

Oh thanks that is definely a bug during refactoring. I'll try to update soon possibly today if I'll manage to update my environment so I'll be able to test fix.

Hi-Angel commented 7 years ago

@qnikst in a bit more details: on layout changes I saw ev.type of at least 2 different values _(neither matching the _kbdd._xkbEventType)_.

It's not reproducible on start, but it starts happening after switching a bit between windows with different layouts.

qnikst commented 7 years ago

Really quite an interesting because master works for me with EHWM support (EWMH is supported written if kbdd is run in no-deamon mode. Can you check if i3 supports, maybe I've broken something in generic version.

Hi-Angel commented 7 years ago

Can you check if i3 supports

Accordingly to this (probably outdated), some subset. Which part does kbdd uses?

I however just checked it with Awesome WM, and I see the same problem (and I seem to recall that kbdd worked there before). I.e. I set a print of ev.type before the condition, opened 2 windows, and I see that after switching layouts and windows a bit, for pressing the layout hotkey, ev.type most of the time differ from the _kbdd._xkbEventType (sometimes it still matches though). Awesome probably does support EWMH.

HNKNTA commented 7 years ago

I confirm problem with archlinux and awesome. Kbdd worked before.

boris-petrov commented 7 years ago

Same here - Arch and Awesome. Downgrading glib2 to 2.48.2-1 and gtk3 to 3.20.9-1 fixes the issue. But I'll be waiting for a better fix. :)

vladimir-g commented 7 years ago

It happens for me only with --enable-dbus flag.

Looks like something changed in glib main loop, so now it doesn't iterate over X events properly. Sometimes iteration doesn't start when new X event is available, and events are stacked somewhere in the X inner buffer. But inner loop (here) checks only one event at time, so layout change event may be processed after window already switched. Then at some moment kbdd becomes desynchronized with keyboard events completely.

I think that I fixed this in https://github.com/vladimir-g/kbdd/commit/0b92da3dd9b39953c5d275c264f2041da59acfc7, but I didn't test that code on older glib versions and don't know about side effects.

Hi-Angel commented 7 years ago

I think that I fixed this in vladimir-g@0b92da3, but I didn't test that code on older glib versions and don't know about side effects.

Checked on Ubuntu Xenial, libglib2 = 2.48.1-1~ubuntu16.04.1, libdbus-glib = 0.106-1, Awesome WM. Layouts being saved and restored on switch between windows and workspaces, I see nothing unusual.

I think you can probably send a PR.

HNKNTA commented 7 years ago

I can confirm too, it works (archlinux)

qnikst commented 7 years ago

Thanks! I'll check the PR and will merge it tomorrow and bump version.

reinar commented 7 years ago

+1, branch from vladimir-g fixed the issue for me Archlinux/i3