Created
May 23, 2024 23:03
-
-
Save martinkozle/6f622e36e5686751ef6ef90db33f4c36 to your computer and use it in GitHub Desktop.
Hyprland bind for switching all keyboard layouts, handling inconsistencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Switch keyboard layout (inline) | |
bind = $mainMod, SPACE, exec, switch=$(hyprctl devices -j | jq -r '.keyboards[] | .active_keymap' | uniq -c | [ $(wc -l) -eq 1 ] && echo "next" || echo "0"); for device in $(hyprctl devices -j | jq -r '.keyboards[] | .name'); do hyprctl switchxkblayout $device $switch; done; activeKeymap=$(hyprctl devices -j | jq -r '.keyboards[0] | .active_keymap'); if [ $switch == "0" ]; then resetStr="(reset)"; else resetStr=""; fi; hyprctl notify -1 1500 0 "$activeKeymap $resetStr"; | |
# Switch keyboard layout (shell script) | |
bind = $mainMod, SPACE, exec, ~/somewhere/switch_layout.sh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# switch gets set to "next" if all current active keymaps are the same | |
# if there is more than 1 unique active keymap for any keyboard (like when plugging in a new keyboard), then it gets set to "0" | |
# this will reset all keyboards to the 0th index layout so they become consistent | |
switch=$(hyprctl devices -j | jq -r '.keyboards[] | .active_keymap' | uniq -c | [ $(wc -l) -eq 1 ] && echo "next" || echo "0") | |
# change the layout of every keyboard in hyprland devices | |
for device in $(hyprctl devices -j | jq -r '.keyboards[] | .name') | |
do | |
hyprctl switchxkblayout $device $switch | |
done | |
# get the first keyboard's active keymap | |
activeKeymap=$(hyprctl devices -j | jq -r '.keyboards[0] | .active_keymap') | |
# if switch is "0" then add (reset) to the end of the notification | |
if [ $switch == "0" ] | |
then | |
resetStr="(reset)" | |
else | |
resetStr="" | |
fi | |
# notify which keyboard layout has been changed (tweak the duration to liking) | |
hyprctl notify -1 1500 0 "$activeKeymap $resetStr" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since newer versions of Hyprland,
kb_options = grp:win_space_toggle
seems to be working now. I have changed my bind to only show a notification now when I change the layout.