diff --git a/hypr/.config/hypr/hyprland.conf b/hypr/.config/hypr/hyprland.conf index 39f555c..5adffc2 100644 --- a/hypr/.config/hypr/hyprland.conf +++ b/hypr/.config/hypr/hyprland.conf @@ -38,6 +38,7 @@ bind = $Mod, d, exec, $menu bind = $Mod, q, killactive, bind = $Mod SHIFT, q, forcekillactive bind = $Mod, a, exec, audio-sink-switcher.sh +bind = $Mod, m, exec, hyprland-kb-layout-switcher.sh bind = $Mod SHIFT, m, exec, hyprctl switchxkblayout all next ## move focus @@ -162,8 +163,8 @@ bind = $Mod SHIFT, s, exec, slurp | grim -g - "$screenshot_directory/$(date '+%Y input { # keyboard - kb_layout = us, us - kb_variant = basic, intl + kb_layout = us, us, ch + kb_variant = basic, intl, basic # mouse sensitivity = 0.5 diff --git a/scripts/audio-sink-switcher.sh b/scripts/audio-sink-switcher.sh index 43c6db1..c10f9cc 100755 --- a/scripts/audio-sink-switcher.sh +++ b/scripts/audio-sink-switcher.sh @@ -36,10 +36,12 @@ select_audio_sink() { elif $(which fuzzel &>/dev/null); then selection="$(printf "%s\n" "${names[@]//\"/}" | fuzzel --lines ${lines} --dmenu --select-index ${number})" else + notify-send "sink-switcher" "requires either [rofi] or [fuzzel]" return 1 fi if [[ -z "${selection}" ]]; then + notify-send "sink-switcher" "selection failed" return 1 fi @@ -52,7 +54,7 @@ select_audio_sink() { done if [[ -z "${number}" ]]; then - echo "something went wrong.." + notify-send "sink-switcher" "something went wrong.." return 1 fi diff --git a/scripts/hyprland-kb-layout-switcher.sh b/scripts/hyprland-kb-layout-switcher.sh old mode 100644 new mode 100755 index 1aa61e3..ebf2744 --- a/scripts/hyprland-kb-layout-switcher.sh +++ b/scripts/hyprland-kb-layout-switcher.sh @@ -1,6 +1,38 @@ #!/usr/bin/env bash function switch_kb_layout { - layouts="$(hyprctl devices -j | grep -iP '"layout"' -m 1)" - # TODO: + devices="$(hyprctl devices -j)" + languages="$(echo "${devices}" | grep -ioP '(?<="layout": ").*(?=")' -m 1)" + variants="$(echo "${devices}" | grep -ioP '(?<="variant": ").*(?=")' -m 1)" + current="$(echo "${devices}" | grep -ioP '(?<="active_layout_index": ).*(?=,)' -m 1)" + + languages=(${languages}) + variants=(${variants}) + + number=$((${#languages[@]} - 1)) + for n in $(seq 0 $number); do + layouts+=("${languages[$n]//,/} - ${variants[$n]//,/}") + done + + if $(which fuzzel &>/dev/null); then + selection="$(printf "%s\n" "${layouts[@]}" | fuzzel --lines ${#layouts[@]} --dmenu --select-index ${current})" + else + notify-send "layout-switcher" "requires [fuzzel]" + return 1 + fi + + for n in $(seq 0 $number); do + if [[ "${layouts[$n]}" == "${selection}" ]]; then + index=$n + break + fi + done + if [[ -z "${index}" ]]; then + notify-send "layout-switcher" "selection failed" + return 1 + fi + + hyprctl switchxkblayout all "${index}" >/dev/null } + +switch_kb_layout