From 53584c7ec589b0f58452f779d58d48400a9ef3b4 Mon Sep 17 00:00:00 2001 From: Florentin Soubrand Date: Fri, 17 Dec 2021 18:15:38 +0100 Subject: [PATCH 1/3] Add a keyboard switch script plus a little combination of two modules to change layout Signed-off-by: Florentin Soubrand --- .../system-keyboard-switch/README.md | 67 +++++++++++++++++++ .../system-keyboard-switch.sh | 27 ++++++++ 2 files changed, 94 insertions(+) create mode 100644 polybar-scripts/system-keyboard-switch/README.md create mode 100755 polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh diff --git a/polybar-scripts/system-keyboard-switch/README.md b/polybar-scripts/system-keyboard-switch/README.md new file mode 100644 index 00000000..9d6a165c --- /dev/null +++ b/polybar-scripts/system-keyboard-switch/README.md @@ -0,0 +1,67 @@ +# Script: system-keyboard-switch + +A shell script that shows the current keyboard layout and change it to another one + + +## 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 ... ]` + +```ini +[module/xkeyboard] +type = internal/xkeyboard +blacklist-0 = num lock + +format-prefix = "" +format-prefix-foreground = ${colors.foreground-alt} + +label-layout = %layout% +label-layout-underline = ${colors.secondary} + +label-indicator-padding = 2 +label-indicator-margin = 1 +label-indicator-background = ${colors.secondary} +label-indicator-underline = ${colors.secondary} + +[module/system-keyboard-menu] +type = custom/menu + +expand-right = true + +format-spacing = 1 + +label-open = "  " +label-open-foreground = #00ff00 +label-close =  cancel +label-close-foreground = #00ff00 +label-separator = | +label-separator-foreground = ${colors.foreground-alt} + +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/system-keyboard-switch.sh b/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh new file mode 100755 index 00000000..69db4b50 --- /dev/null +++ b/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh @@ -0,0 +1,27 @@ +#! /usr/bin/env bash + +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 From 335f7fa64113cc8fbd19060e0e21afabb0c58310 Mon Sep 17 00:00:00 2001 From: Florentin Soubrand Date: Fri, 17 Dec 2021 18:27:06 +0100 Subject: [PATCH 2/3] Add details and screenshots Signed-off-by: Florentin Soubrand --- polybar-scripts/system-keyboard-switch/README.md | 15 ++++++--------- .../screenshots/menu_layout_closed.png | Bin 0 -> 302 bytes .../screenshots/menu_layout_opened.png | Bin 0 -> 543 bytes .../screenshots/switch_layout.png | Bin 0 -> 350 bytes 4 files changed, 6 insertions(+), 9 deletions(-) create mode 100644 polybar-scripts/system-keyboard-switch/screenshots/menu_layout_closed.png create mode 100644 polybar-scripts/system-keyboard-switch/screenshots/menu_layout_opened.png create mode 100644 polybar-scripts/system-keyboard-switch/screenshots/switch_layout.png diff --git a/polybar-scripts/system-keyboard-switch/README.md b/polybar-scripts/system-keyboard-switch/README.md index 9d6a165c..1b566c72 100644 --- a/polybar-scripts/system-keyboard-switch/README.md +++ b/polybar-scripts/system-keyboard-switch/README.md @@ -2,6 +2,7 @@ A shell script that shows the current keyboard layout and change it to another one +![switch](screenshots/switch_layout.png) ## Module @@ -26,21 +27,20 @@ If you need to switch between other ones just change the script with your needed 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 = "" -format-prefix-foreground = ${colors.foreground-alt} label-layout = %layout% -label-layout-underline = ${colors.secondary} label-indicator-padding = 2 label-indicator-margin = 1 -label-indicator-background = ${colors.secondary} -label-indicator-underline = ${colors.secondary} [module/system-keyboard-menu] type = custom/menu @@ -49,12 +49,9 @@ expand-right = true format-spacing = 1 -label-open = "  " -label-open-foreground = #00ff00 -label-close =  cancel -label-close-foreground = #00ff00 +label-open = " #1 " +label-close = "#2 cancel" label-separator = | -label-separator-foreground = ${colors.foreground-alt} menu-0-0 = us menu-0-0-exec = setxkbmap us -model pc105 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 0000000000000000000000000000000000000000..e41326e06e9b96fda40e42be27e0418810f04433 GIT binary patch literal 302 zcmeAS@N?(olHy`uVBq!ia0vp^PCzWf!2~3uHvO{zQk(@Ik;M!Qd`Cc-ajG_-G*Iw? zr;B4qMC;q>v0R501X_GwCJS}&e&N{b)_*Vi3*Ro*y$u*4C``E*y!D>Zc2IA06qRHh;^9D;M)3E=a8XYdSM>-HrLPfAsS`e|{lv zhpzpX7EVX@b;SpGC+2!YF1p`))>rL+KnHOBmwtcV yIO}h6<-}~M!eoi#)oRA_7*TD*VyT%KI~At#_j-2f&*j^ zk-9XA1Azc3`M)O`1t+q99Gk+``9c81@U-^^z~ceYfN07U&DZs_sC5%^5YY@>J9O>d zyI6(3Yx=Iq#|{xaC$X|SRed?6X!@>ssbBN4qY*`8#-OUvVS#`AqM4@{=`Qd1(6wfI z7@a?RR|~P8QS+yn?Grx7Q}%OPdiJ_Y>?Av$vTX zOxCJtZV?THc1qNb==RAQr;0a*^_r)mM)Odx{+rTJh!Omy6YxdatRle3PjfOF7ItXNLVXkh+Ww zgc5Ffwzs1>$bU~@OBf$vfmo1fKr|2yhz6no(H!J^8sO#U_akcl`}upyG-MhO4WCYL z_almklp?tv4?=Y&8_ h1BVfuKt!$+{s0di0R3KhjvN30002ovPDHLkV1mBY_X9;1gKx>MKa4(yJfg5iRjQ%*Gbz$D}(Xo^(@}q%QfqkNLcXO6rm@UVWvN zqMJFZwphge_7*)1VpAIP Date: Fri, 17 Dec 2021 18:28:30 +0100 Subject: [PATCH 3/3] Remove colors and icons Signed-off-by: Florentin Soubrand --- .../system-keyboard-switch/system-keyboard-switch.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh b/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh index 69db4b50..1b4d10db 100755 --- a/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh +++ b/polybar-scripts/system-keyboard-switch/system-keyboard-switch.sh @@ -1,4 +1,4 @@ -#! /usr/bin/env bash +#!/bin/sh sleep_pid=0