Skip to content

About

A flag beside the text cursor, because I kept forgetting the active keyboard layout. Currently supports Niri.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Wayland layout flag

I kept forgetting which keyboard layout was active, so I put a flag beside the text cursor. For Niri on Wayland.

A native input-method-v2 popup lets the compositor place the flag next to text fields in Firefox and other compatible Wayland applications.

Currently supports English (US) and Russian. Other layouts hide the flag. No application patch, browser extension, or terminal shader is required.

Requirements

  • Linux with Niri, including input-method-v2 and text-input-v3 support.
  • Applications that provide their text-input cursor rectangle to the compositor.
  • C compiler, Make, pkg-config, wayland-scanner, libwayland-client, json-c, and Python 3 for tests and installation.
  • A systemd user session for the optional autostart service.

On Arch Linux:

sudo pacman -S --needed base-devel wayland json-c python

Do not run alongside Fcitx, IBus, or another Wayland input-method provider. The helper occupies the seat's input-method slot. Ordinary US/Russian XKB layout switching does not require those frameworks.

Build and try

git clone https://github.com/dolzenko/wayland-layout-flag.git
cd wayland-layout-flag
make test
./.build/wayland-layout-flag

Run from your Niri session, with NIRI_SOCKET, WAYLAND_DISPLAY, and XDG_RUNTIME_DIR set. The default mode runs for 90 seconds and prints popup geometry for diagnosis. Use --daemon to run continuously with lifecycle/error messages only. Ctrl+C or SIGTERM stops either mode.

Install and update

make install

This creates an executable symlink in ~/.local/bin, writes a systemd user unit under $XDG_CONFIG_HOME/systemd/user (default ~/.config/systemd/user), and enables and starts it. Keep the checkout at its installation path. No root access is used for building, installing, or running the helper.

The user service must inherit the Niri session environment. If your session does not already import it, run this from a terminal inside Niri before installing:

systemctl --user import-environment NIRI_SOCKET WAYLAND_DISPLAY XDG_RUNTIME_DIR

Update from the checkout:

git pull --ff-only
make install

Each service start also runs an incremental build, so local source changes are compiled at the next restart. It does not download updates automatically. An existing executable or service belonging to another installation is left untouched; remove that installation first.

systemctl --user status wayland-layout-flag.service
journalctl --user -u wayland-layout-flag.service -n 30
systemctl --user stop wayland-layout-flag.service
systemctl --user start wayland-layout-flag.service

Uninstall from the same checkout:

make uninstall

This stops/disables the service and removes its unit and executable symlink. The checkout remains. If you manually edited the generated unit, review and remove it manually; the uninstaller refuses to delete modified units.

Behavior and limitations

  • The popup is click-through and hides when text input deactivates or the application marks it as password, PIN, hidden, or sensitive content.
  • No keyboard grab, preedit, text insertion, or text deletion requests are used. The protocol can deliver surrounding text; the callback ignores it without storing or logging it. The helper is an ordinary user process, not a sandbox.
  • Firefox may report a position one keypress behind, or leave the position stale after a selection/scroll change until another key event. The helper uses the rectangle it receives rather than estimating the caret position.
  • Only one seat is supported. A runtime lock rejects duplicate copies of this helper before they connect to Wayland; it does not coordinate with other IMs.
  • A tested Niri/Smithay build sent unavailable to the existing IM when a second provider connected. Stop this helper before using another input method. Exit status 2 prevents the service from repeatedly trying to reclaim the seat.
  • This does not provide flags in applications that do not expose text-input geometry. It is not a universal desktop cursor overlay.

Originally tested on Niri 26.04 (v26.04-85-gdd75865f), Firefox Nightly 160.0a1 and GTK 3.24.52. Live checks covered input, textarea, contenteditable, US/RU switching, password/blur hiding, and unchanged typed text. A full logout/login cycle has not been tested. make test runs headlessly and covers layout/color selection, sensitive fields, process locking, and installation/removal. GitHub Actions builds and tests with GCC and Clang; headless CI does not verify popup placement in a live compositor.

Development

make test
make clean
make test CC=clang

The build accepts CC, CFLAGS, CPPFLAGS, LDFLAGS, LDLIBS, and PYTHON overrides. Run make clean when changing compilers or build flags. The protocol bindings and executable are generated under .build/.

License

MIT. The vendored protocol XML retains its original copyright and license notice. It comes from Smithay's wayland-rs protocol collection.

About

A flag beside the text cursor, because I kept forgetting the active keyboard layout. Currently supports Niri.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages