diff --git a/polybar-scripts/system-keyboard-switch/README.md b/polybar-scripts/system-keyboard-switch/README.md new file mode 100644 index 00000000..1b566c72 --- /dev/null +++ b/polybar-scripts/system-keyboard-switch/README.md @@ -0,0 +1,64 @@ +# Script: system-keyboard-switch + +A shell script that shows the current keyboard layout and change it to another one + +![switch](screenshots/switch_layout.png) + +## Module + +```ini +[module/system-keyboard-switch] +type = custom/script +exec = ~/polybar-scripts/system-keyboard-switch.sh +tail = true +format-prefix = "" +format-prefix-foreground = #00ff00 +format-underline = #ff0000 +click-left = "kill -USR1 $(pgrep --oldest --parent %pid%)" +interval = 3 +``` +## Customization + +By default there is only `fr` or `us` layout. +If you need to switch between other ones just change the script with your needed layouts. + +## Moreover + +I made a special module with script that do the trick. +Alongside with the module `xkeyboard` it looks great in that order of module: `[ ... system-keyboard-menu xkeyboard ... ]` + +![menu-closed](screenshots/menu_layout_closed.png) +![menu-opened](screenshots/menu_layout_opened.png) + +```ini +[module/xkeyboard] +type = internal/xkeyboard +blacklist-0 = num lock + +format-prefix = "" + +label-layout = %layout% + +label-indicator-padding = 2 +label-indicator-margin = 1 + +[module/system-keyboard-menu] +type = custom/menu + +expand-right = true + +format-spacing = 1 + +label-open = " #1 " +label-close = "#2 cancel" +label-separator = | + +menu-0-0 = us +menu-0-0-exec = setxkbmap us -model pc105 +menu-0-1 = fr +menu-0-1-exec = setxkbmap fr -model pc105 + +menu-2-0 = cancel +menu-2-0-exec = #mykeyboard.open.0 + +``` diff --git a/polybar-scripts/system-keyboard-switch/screenshots/menu_layout_closed.png b/polybar-scripts/system-keyboard-switch/screenshots/menu_layout_closed.png new file mode 100644 index 00000000..e41326e0 Binary files /dev/null and b/polybar-scripts/system-keyboard-switch/screenshots/menu_layout_closed.png differ diff --git a/polybar-scripts/system-keyboard-switch/screenshots/menu_layout_opened.png b/polybar-scripts/system-keyboard-switch/screenshots/menu_layout_opened.png new file mode 100644 index 00000000..b4f0ecaa Binary files /dev/null and b/polybar-scripts/system-keyboard-switch/screenshots/menu_layout_opened.png differ diff --git a/polybar-scripts/system-keyboard-switch/screenshots/switch_layout.png b/polybar-scripts/system-keyboard-switch/screenshots/switch_layout.png new file mode 100644 index 00000000..0a4aa169 Binary files /dev/null and b/polybar-scripts/system-keyboard-switch/screenshots/switch_layout.png differ diff --git a/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh b/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh new file mode 100755 index 00000000..1b4d10db --- /dev/null +++ b/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +sleep_pid=0 + +layout=$(setxkbmap -query | grep layout | awk '{print $2}') + +toggle() { + layout=$(setxkbmap -query | grep layout | awk '{print $2}') + if [ "$layout" = "fr" ]; then + layout="us" + elif [ "$layout" = "us" ]; then + layout="fr" + fi + if [ "$sleep_pid" -ne 0 ]; then + kill $sleep_pid >/dev/null 2>&1 + fi +} + +trap "toggle" USR1 + +while true; do + setxkbmap "$layout" -model pc105 + echo " $layout" + sleep 1 & + sleep_pid=$! + wait +done