summaryrefslogtreecommitdiff
path: root/.local/bin/layouttoggle
diff options
context:
space:
mode:
authorBenjamin Chausse <benjamin@chausse.xyz>2025-03-30 01:00:51 -0400
committerBenjamin Chausse <benjamin@chausse.xyz>2025-03-30 01:00:51 -0400
commitf4c4550e327d9090c82a735d39d104d0bedb602d (patch)
treefcfa762512155c132a66d3adbb56067ca2d5d61b /.local/bin/layouttoggle
parent43dbb32d741e11f8e06341f515944ec757d4578f (diff)
Loads of laptop shit
Diffstat (limited to '.local/bin/layouttoggle')
-rwxr-xr-x.local/bin/layouttoggle46
1 files changed, 30 insertions, 16 deletions
diff --git a/.local/bin/layouttoggle b/.local/bin/layouttoggle
index d1ceba5..b64e923 100755
--- a/.local/bin/layouttoggle
+++ b/.local/bin/layouttoggle
@@ -1,20 +1,34 @@
#!/bin/sh
-layout=$(cat "$HOME/.cache/layout")
+cachefile="$HOME/.cache/layout"
-case "$layout" in
-ca)
- setxkbmap -model pc104 -layout us -variant ,,
- echo us >"$HOME/.cache/layout"
- ;;
-us)
- setxkbmap -model pc104 -layout ca -variant ,,
- echo ca >"$HOME/.cache/layout"
- ;;
-*)
- setxkbmap -model pc104 -layout us -variant ,,
- echo us >"$HOME/.cache/layout"
- ;;
-esac
+# Handle manual override first
+if [ -n "$1" ]; then
+ echo "$1" >"$cachefile"
+else
+ # Ensure the cache file exists, or initialize it
+ [ -f "$cachefile" ] || echo "us" >"$cachefile"
+ layout=$(cat "$cachefile")
+
+ case "$layout" in
+ ca)
+ echo us >"$cachefile"
+ ;;
+ us)
+ echo ca >"$cachefile"
+ ;;
+ *)
+ echo us >"$cachefile"
+ ;;
+ esac
+fi
+
+# Apply keyboard layout
+riverctl keyboard-layout -model pc104 "$(cat "$cachefile")"
+
+# Restart the correct block if waybar is running
+waybar_pid=$(pidof waybar)
+if [ -n "$waybar_pid" ]; then
+ kill -38 "$waybar_pid"
+fi
-kill -38 "$(pidof dwmblocks)"