klavaro

Crates.ioklavaro
lib.rsklavaro
version1.0.2
sourcesrc
created_at2022-03-28 06:50:31.324284
updated_at2024-09-16 21:12:37.737802
descriptionPrint your current xkb_layout in Sway.
homepage
repositoryhttps://github.com/Fierthraix/klavaro
max_upload_size
id557648
size43,479
(Fierthraix)

documentation

README

klavaro

Save the current keyboard layout (xkb_active_layout) to a file on Sway. Useful with i3status.

$ klavaro --help
Print the current xkb_layout in sway.
The default output file is `/tmp/.xkb_lingvo'
USAGE:
    klavaro [OUTPUT_FILE]

Instalation

Local

Install to $HOME/.cargo/bin/klavaro

cargo install klavaro

Global

Install to /usr/local/bin/klavaro

sudo -E cargo install --root /usr/local klavaro

i3status

Your current Sway keyboard layout can be printed in i3status thusly:

~/.i3status.conf
order += "read_file keyboard"

read_file keyboard {
        path = "/tmp/.xkb_lingvo"
        color_good = "#FFFFFF"
}

However, the klavaro program must already be running, which can be accomplished via systemd user service as below.

SystemD User Service

Since sway is a user process, a systemd user service must be used in order to get the SWAYSOCK successfully.

This is the service file needed:

/etc/systemd/user/klavaro.service
[Unit]
Description=klavaro

[Service]
Type=simple
ExecStart=/usr/local/bin/klavaro
Restart=always
RestartSec=1s

[Install]
WantedBy=multi-user.target

Then the service can be started:

systemctl --user enable klavaro # Schedule klavaro on startup.
systemctl --user start klavaro  # Start klavaro immediately.

swaymsg

This is basically equivalent to (but muuch more efficient than)

swaymsg -r -t subscribe -m '["input"]' \
   | jq '.input.xkb_active_layout_name'

and saving the result to a file.

Commit count: 7

cargo fmt