Tablet mode in KDE? (auto-rotate, virtual keyboard)

Wait, what? It has been already a month since I said I had no time that week to try…

What I wanted to do is to check which event triggers the kde touch mode, because that works very reliably, and it should be a libinput event, then hook the toggle of the oscreen keyboard to the same event.

Triggering on the existence of any physical keyboard could be superior, but that’s too complex for me. My idea will not block the virtual keyboard when the laptop is in touch mode but an external keyboard is attached. I’m pretty sure that’ll be an easy fix apart from identifying the correct triggers, but I totally didn’t even attempt it yet.

I just don’t understant how this is not a KDE setting yet, since there is already automatic touch mode and normal mode switching…

EDIT: I think I have the correct libinput trigger to investigate, I’ll try to make and udev rule and post it for y’all to test if it works on my machine

-event13  DEVICE_ADDED                 gpio-keys                         seat0 default group7  cap:S

---

-event13  SWITCH_TOGGLE                +9.013s  switch tablet-mode state 1
 event13  SWITCH_TOGGLE                +14.278s switch tablet-mode state 0


---

Device:                  gpio-keys
Kernel:                  /dev/input/event13
Id:                      host:0001:0001
Group:                   7
Seat:                    seat0, default
Capabilities:            switch
Tap-to-click:            n/a
Tap-and-drag:            n/a
Tap button map:          n/a
Tap drag lock:           n/a
Left-handed:             n/a
Nat.scrolling:           n/a
Middle emulation:        n/a
Calibration:             n/a
Scroll methods:          none
Scroll button:           n/a
Scroll button lock:      n/a
Click methods:           none
Clickfinger button map:  n/a
Disable-w-typing:        n/a
Disable-w-trackpointing: n/a
Accel profiles:          n/a
Rotation:                0.0
Area rectangle:          n/a

Here’s a script that toggles the keyboard on and off automatically:

I spent a while trying to get libinput to notify me about LIBINPUT_SWITCH_TABLET_MODE events, but I wasn’t able to get that to work. Not sure if libinput doesn’t expose that event externally or if I was just doing it wrong.

But KDE happens to have a DBus signal for tablet mode, so the script subscribes to that DBus signal and watches for changes. Then it uses DBus to toggle the keyboard on and off to match. Pretty simple and seems to work for me.

Unfortunately, the DBus objects I’m using are KDE-specific, so this won’t be helpful to people using Gnome or other desktop environments. Somebody on Gnome could try watching dbus-monitor for signals that fire while rotating the hinge. If there are Gnome equivalents then it might be possible to do something similar there.

3 Likes

Thank you so much, this works perfectly! One quick note for other users: I needed to install perl-Net-DBus on Fedora to get it to run properly, but after that and a reboot it’s working. I’m very glad I can stick with KDE now instead of needing to use gnome.

1 Like