Skip to content

On Screen Keyboard and Auto Rotation

GGEZUS edited this page Sep 23, 2026 · 2 revisions

Two independent helpers: an OSK toggle and an auto-rotate daemon. Take either, both, or neither. Both work on stock niri too: nothing in them depends on the patchset.

# OSK: any touchscreen device, no sensors involved
cp scripts/niri-osk.sh ~/.local/bin/

# auto-rotate: only for devices with an accelerometer
cp scripts/niri-rotate.sh ~/.local/bin/
cp scripts/niri-rotate.service ~/.config/systemd/user/
systemctl --user enable --now niri-rotate.service

Edit OUTPUT/heights at the top of the scripts for your device.

niri-osk.sh (on-screen keyboard)

Toggles wvkbd. On Arch, install the AUR package wvkbd-git, which provides the wvkbd-deskintl binary the script launches; python3 must be installed (it parses the output transform).

The script reads the transform from niri itself, not from sensors: in portrait it doubles the keyboard height, and if you use a two-group xkb layout like "pt,us" it flips the active group on toggle (the OSK is US-labelled; with a single-group layout the flip is a no-op, so a US-only machine needs nothing special).

The two-group layout, if you want it, lives in your input config:

input {
    keyboard {
        xkb {
            layout "pt,us"   // your layout first, us second
        }
    }
}

Off-Arch, build wvkbd from source; extras/wvkbd/ in the repo carries a PKGBUILD variant if you prefer building the package yourself.

The shipped edge-swipe config ties these together: a one-finger swipe up from the bottom edge runs ~/.local/bin/niri-osk.sh (Configuration#touchscreen-edge-swipe).

niri-rotate.sh (auto-rotation)

Follows the accelerometer via iio-sensor-proxy and sets niri msg output <name> transform as the tablet turns; it also resizes a running keyboard. Enable it with the user unit above.

Only useful with a real accelerometer. Check yours with:

monitor-sensor    # after starting iio-sensor-proxy.service

Many touch laptops have none, in which case skip this helper: nothing else depends on it.

2-in-1s: rotation only in tablet mode

On convertibles the helper follows the tablet-mode switch and stays idle while the device is used as a laptop: no rotation happens, and folding the screen back returns the output to the normal orientation. Flipping into tablet mode catches up to the angle the accelerometer already reports. Machines without a switch (plain laptops, pure tablets) are untouched: the gate only engages when a switch is found.

The switch is a sysfs file printing 0 in laptop mode and 1 in tablet mode. ThinkPad Yogas (thinkpad_acpi) and HP convertibles (hp-wmi) are detected automatically; for anything else, find your device's file and export the path (a systemd unit drop-in, environment.d, or editing the script):

NIRI_ROTATE_TABLET_MODE_SYSFS=/sys/devices/platform/your-driver/tablet_mode

Related knobs:

  • NIRI_ROTATE_TABLET_MODE_ONLY=auto (default): gate only when a switch is found. yes insists on the gate and warns if no switch can be read; no disables the gate entirely.
  • NIRI_ROTATE_OUTPUT overrides the output name, same as OUTPUT in the script.

Why a sysfs file and not the input layer or iio-sensor-proxy: reading SW_TABLET_MODE straight from /dev/input needs root or the input group, which a systemd user service does not have, and iio-sensor-proxy has no tablet-mode API at all. Vendor sysfs files are world-readable, so the helper needs no extra privileges.

Clone this wiki locally