hyprwm / Hyprland

Hyprland is an independent, highly customizable, dynamic tiling Wayland compositor that doesn't sacrifice on its looks.
https://hyprland.org
BSD 3-Clause "New" or "Revised" License
21.09k stars 882 forks source link

Ability to switch (not redefine!) keyboard layout via `hyprctl` (like `xkb_switch_layout` in sway) #1163

Closed MahouShoujoMivutilde closed 1 year ago

MahouShoujoMivutilde commented 1 year ago

In sway you can

swaymsg input type:keyboard xkb_switch_layout <next|prev|index>

From the man page:

    input <identifier> xkb_switch_layout <index>|next|prev
    Changes the active keyboard layout to counting from zero or to next or previous layout on the list. If there is no next or previous layout, this command hops to the other end of the list.
    This can be used when multiple layouts are configured with xkb_layout. A list of layouts you can switch between can be obtained with swaymsg -t get_inputs.

https://man.archlinux.org/man/sway-input.5.en

Use case

Described here https://github.com/hyprwm/Hyprland/discussions/915, also would help with scripting https://github.com/hyprwm/Hyprland/issues/1162

Basically, switching layouts with grp: toggles is very fast, while redefining them via

hyprctl keyword device:*DEVICE*:kb_layout *layout_you_want*

is quite a bit slower (like ~1ms? vs 40ms slower)

while xkb_switch_layout is like calling grp toggle from cli in terms of latency.

vaxerski commented 1 year ago

done in 79adba557eccff5d19f300f3d04b1f3f67aee407

https://wiki.hyprland.org/Configuring/Using-hyprctl/

hyprctl setxkblayout [keyboard] [cmd] where just like in sway cmd is next prev or id

MahouShoujoMivutilde commented 1 year ago

Thanks!

MahouShoujoMivutilde commented 1 year ago

Hey, it's actually hyprctl switchxkblayout ...

❯ hyprctl switchxkblayout logitech-usb-keyboard next
ok

~ 
❯ hyprctl switchxkblayout logitech-usb-keyboard next
ok

~ 
❯ hyprctl --help                                    
usage: hyprctl [(opt)flags] [command] [(opt)args]

commands:
    monitors
    workspaces
    clients
    activewindow
    layers
    devices
    dispatch
    keyword
    version
    kill
    splash
    hyprpaper
    reload
    setcursor
    getoption
    cursorpos

flags:
    -j -> output in JSON
    --batch -> execute a batch of commands, separated by ';'

~ 
❯ hyprctl --help | grep switch

~ 
❯ hyprctl version             
Hyprland, built from branch main at commit 79adba557eccff5d19f300f3d04b1f3f67aee407dirty (added hyprctl switchxkblayout).
flags: (if any)

It works fine, but it's missing from hyprctl --help.

vaxerski commented 1 year ago

fixed