diff options
| author | Loïc Pilette <155224839+LoicPil@users.noreply.github.com> | 2026-02-21 02:17:33 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-20 20:17:33 -0500 |
| commit | ce857ab4f3f37943528cf30f41b33a65906fad6c (patch) | |
| tree | c2f26187ad12a35dff45a460d98313881ccc1d67 /config/hypr | |
| parent | 0e02857355b5f3546cf8a5e083221217d9126dc3 (diff) | |
fix: Tak0-Per-Window-Switch reads kb_layout from UserSettings.conf first (#8)
Diffstat (limited to 'config/hypr')
| -rwxr-xr-x | config/hypr/scripts/Tak0-Per-Window-Switch.sh | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/config/hypr/scripts/Tak0-Per-Window-Switch.sh b/config/hypr/scripts/Tak0-Per-Window-Switch.sh index 6cd0c564..e1f4213d 100755 --- a/config/hypr/scripts/Tak0-Per-Window-Switch.sh +++ b/config/hypr/scripts/Tak0-Per-Window-Switch.sh @@ -1,5 +1,5 @@ ################################################################## -# # +# # # # # TAK_0'S Per-Window-Switch # # # @@ -7,13 +7,14 @@ # # # Just a little script that I made to switch keyboard layouts # # per-window instead of global switching for the more # -# smooth and comfortable workflow. # +# smooth and comfortable workflow. # # # ################################################################## -# This is for changing kb_layouts. Set kb_layouts in +# This is for changing kb_layouts. Set kb_layouts in MAP_FILE="$HOME/.cache/kb_layout_per_window" -CFG_FILE="$HOME/.config/hypr/configs/SystemSettings.conf" +USER_CFG="$HOME/.config/hypr/UserConfigs/UserSettings.conf" +SYS_CFG="$HOME/.config/hypr/configs/SystemSettings.conf" ICON="$HOME/.config/swaync/images/ja.png" SCRIPT_NAME="$(basename "$0")" @@ -21,13 +22,16 @@ SCRIPT_NAME="$(basename "$0")" touch "$MAP_FILE" # Read layouts from config -if ! grep -q 'kb_layout' "$CFG_FILE"; then - echo "Error: cannot find kb_layout in $CFG_FILE" >&2 +if grep -q 'kb_layout' "$USER_CFG" 2>/dev/null; then + CFG_FILE="$USER_CFG" +elif grep -q 'kb_layout' "$SYS_CFG" 2>/dev/null; then + CFG_FILE="$SYS_CFG" +else + echo "Error: cannot find kb_layout in UserSettings.conf nor SystemSettings.conf" >&2 exit 1 fi kb_layouts=($(grep 'kb_layout' "$CFG_FILE" | cut -d '=' -f2 | tr -d '[:space:]' | tr ',' ' ')) count=${#kb_layouts[@]} - # Get current active window ID get_win() { hyprctl activewindow -j | jq -r '.address // .id' @@ -41,8 +45,8 @@ get_keyboards() { # Save window-specific layout save_map() { local W=$1 L=$2 - grep -v "^${W}:" "$MAP_FILE" > "$MAP_FILE.tmp" - echo "${W}:${L}" >> "$MAP_FILE.tmp" + grep -v "^${W}:" "$MAP_FILE" >"$MAP_FILE.tmp" + echo "${W}:${L}" >>"$MAP_FILE.tmp" mv "$MAP_FILE.tmp" "$MAP_FILE" } @@ -74,7 +78,7 @@ cmd_toggle() { break fi done - NEXT=$(( (i+1) % count )) + NEXT=$(((i + 1) % count)) do_switch "$NEXT" save_map "$W" "${kb_layouts[NEXT]}" notify-send -u low -i "$ICON" "kb_layout: ${kb_layouts[NEXT]}" @@ -96,7 +100,10 @@ cmd_restore() { # Listen to focus events and restore window-specific layouts subscribe() { local SOCKET2="$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" - [[ -S "$SOCKET2" ]] || { echo "Error: Hyprland socket not found." >&2; exit 1; } + [[ -S "$SOCKET2" ]] || { + echo "Error: Hyprland socket not found." >&2 + exit 1 + } socat -u UNIX-CONNECT:"$SOCKET2" - | while read -r line; do [[ "$line" =~ ^activewindow ]] && cmd_restore @@ -110,6 +117,9 @@ fi # CLI case "$1" in - toggle|"") cmd_toggle ;; - *) echo "Usage: $SCRIPT_NAME [toggle]" >&2; exit 1 ;; +toggle | "") cmd_toggle ;; +*) + echo "Usage: $SCRIPT_NAME [toggle]" >&2 + exit 1 + ;; esac |
