From cc8eaebd5f0f0bef814fee0fd18d6ce3b2ede558 Mon Sep 17 00:00:00 2001 From: Daniele Fucini Date: Fri, 30 Oct 2026 21:25:57 +0100 Subject: [PATCH] Switch keyboard layout by clicking the xmobar indicator Left-click cycles it -> us -> sk(qwerty), right-click cycles backwards, via a new kbd_cycle.sh that calls setxkbmap like the M-i/M-u/M-s keys. --- .config/xmobar/kbd_cycle.sh | 24 ++++++++++++++++++++++++ .config/xmobar/xmobarrc_hdmi | 2 +- .config/xmobar/xmobarrc_laptop | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100755 .config/xmobar/kbd_cycle.sh diff --git a/.config/xmobar/kbd_cycle.sh b/.config/xmobar/kbd_cycle.sh new file mode 100755 index 0000000..adef34c --- /dev/null +++ b/.config/xmobar/kbd_cycle.sh @@ -0,0 +1,24 @@ +#!/bin/bash +# Cycle keyboard layout it -> us -> sk(qwerty); "prev" cycles backwards. + +current=$(setxkbmap -query | awk '/^layout:/ {split($2, a, ","); print a[1]}') + +if [[ "$1" == "prev" ]]; then + case "$current" in + it) next=sk ;; + us) next=it ;; + *) next=us ;; + esac +else + case "$current" in + it) next=us ;; + us) next=sk ;; + *) next=it ;; + esac +fi + +if [[ "$next" == "sk" ]]; then + setxkbmap -layout sk -variant qwerty +else + setxkbmap -layout "$next" -variant "" +fi diff --git a/.config/xmobar/xmobarrc_hdmi b/.config/xmobar/xmobarrc_hdmi index 6a59b53..08311d2 100644 --- a/.config/xmobar/xmobarrc_hdmi +++ b/.config/xmobar/xmobarrc_hdmi @@ -57,5 +57,5 @@ Config { overrideRedirect = True ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %backup%%updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% " + , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %backup%%updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% " } diff --git a/.config/xmobar/xmobarrc_laptop b/.config/xmobar/xmobarrc_laptop index 3b5cd85..2266b64 100644 --- a/.config/xmobar/xmobarrc_laptop +++ b/.config/xmobar/xmobarrc_laptop @@ -58,5 +58,5 @@ Config { overrideRedirect = True ] , sepChar = "%" , alignSep = "}{" - , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %backup%%updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " + , template = "  | %UnsafeXMonadLog% } %uptime% | %multicpu% %coretemp% | %memory% |  %kbd% { %backup%%updates%%LZIB% · %ens_brief% | %pactl_volume% | %date% %_XMONAD_TRAYPAD% " }