diff options
| author | GrafMonteCarlo <53829166+vailrahmatulin@users.noreply.github.com> | 2024-05-21 18:41:20 +0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-21 18:41:20 +0700 |
| commit | e66c4e6047da7d2b5edaad31439bceb6c4000cbc (patch) | |
| tree | 62a2746dd7ee599ec21480a48cdbecb6eff4cccd /config/hypr/scripts | |
| parent | f9f34c0ff215c8268b2f249c83bd2dbc1f4e4aaf (diff) | |
Update SwitchKeyboardLayout.sh
Changing the keyboard layout for all keyboards connected to the computer.
Diffstat (limited to 'config/hypr/scripts')
| -rwxr-xr-x | config/hypr/scripts/SwitchKeyboardLayout.sh | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/config/hypr/scripts/SwitchKeyboardLayout.sh b/config/hypr/scripts/SwitchKeyboardLayout.sh index 0145e262..cbacd74f 100755 --- a/config/hypr/scripts/SwitchKeyboardLayout.sh +++ b/config/hypr/scripts/SwitchKeyboardLayout.sh @@ -41,5 +41,38 @@ new_layout="${layout_mapping[next_index]}" hyprctl switchxkblayout "at-translated-set-2-keyboard" "$new_layout" echo "$new_layout" > "$layout_f" -# Notification for the new keyboard layout -notify-send -u low -i "$notif" "new KB_Layout: $new_layout" +# Created by T-Crypt + +get_keyboard_names() { + hyprctl devices -j | jq -r '.keyboards[].name' +} + +change_layout() { + local got_error=false + + while read -r name; do + hyprctl switchxkblayout "$name" next + if [[ $? -eq 0 ]]; then + echo "Switched the layout for $name." + else + >&2 echo "Error while switching the layout for $name." + got_error=true + fi + done <<< "$(get_keyboard_names)" + + if [ "$got_error" = true ]; then + >&2 echo "Some errors were found during the process..." + return 1 + fi + + return 0 # All layouts had been cycled successfully +} + +if ! change_layout; then + notify-send -u low -t 2000 'Keyboard layout' 'Error: Layout change failed' + >&2 echo "Layout change failed." + exit 1 +else + # Notification for the new keyboard layout + notify-send -u low -i "$notif" "new KB_Layout: $new_layout" +fi |
