diff --git a/README.md b/README.md index 46d94bb..4adcac3 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,33 @@ # kb-layout-caps-led -Switching on and off capslock led according to the keyboard layout +> Switching on and off capslock led according to the keyboard layout + +This project is againts to show your keyboard layout switching with CapsLock LED indicator. + +## Installation + +There are two systemd daemons: one is running from user, the other one as root. + +### User's daemon is against of to determine the current keyboard layout and tell it to root's daemon + +```bash +> systemctl --user enable /%FULL_PATH_TO%/daemons/gnome-kb-layout-watcher.service +``` + +```bash +> systemctl --user start gnome-kb-layout-watcher.service +``` + +### Root's daemon is against of to set up the CapsLock LED indicator according of user's daemon data + +```bash +> sudo cp /%FULL_PATH_TO/daemons/kb-layout-signal-watcher.service /etc/systemd/system/kb-layout-signal-watcher.service +``` + +```bash +> sudo systemctl enable kb-layout-signal-watcher.service +``` + +```bash +> sudo start kb-layout-signal-watcher.service +``` diff --git a/scripts/gnome-kb-layout-watcher.sh b/scripts/gnome-kb-layout-watcher.sh index b9adb08..a674bd1 100644 --- a/scripts/gnome-kb-layout-watcher.sh +++ b/scripts/gnome-kb-layout-watcher.sh @@ -4,14 +4,19 @@ echo $$ > /tmp/gnome-kb-layout-watcher.pid MAIN_KB_LAYOUT=$(gsettings get org.gnome.desktop.input-sources sources | sed -e 's!\[!!g; s!\]!!g; s!), (!,!g; s!(!!; s!)!!g; s! !!g;' | awk -F, '{print $2}' | sed "s/'//g") +LAST_KB_LAYOUT='' + while : do CURRENT_KB_LAYOUT=$(gsettings get org.gnome.desktop.input-sources mru-sources | sed -e 's!\[!!g; s!\]!!g; s!), (!,!g; s!(!!; s!)!!g; s! !!g;' | awk -F, '{print $2}' | sed "s/'//g") - if [[ "$CURRENT_KB_LAYOUT" == "$MAIN_KB_LAYOUT" ]]; then - echo "1" > /tmp/kb-layout - else - echo "0" > /tmp/kb-layout + if ! [[ "$LAST_KB_LAYOUT" == "$CURRENT_KB_LAYOUT" ]]; then + if [[ "$CURRENT_KB_LAYOUT" == "$MAIN_KB_LAYOUT" ]]; then + echo "1" > /tmp/kb-layout + else + echo "0" > /tmp/kb-layout + fi + LAST_KB_LAYOUT="$CURRENT_KB_LAYOUT" fi sleep .1 diff --git a/scripts/kb-layout-signal-watcher.sh b/scripts/kb-layout-signal-watcher.sh index 9f44326..a8b9cbd 100644 --- a/scripts/kb-layout-signal-watcher.sh +++ b/scripts/kb-layout-signal-watcher.sh @@ -6,21 +6,21 @@ CAPS_INPUT=$(ls /sys/class/leds/ | grep caps | head -n 1) echo $CAPS_INPUT -PREVIOUS_KB_LAYOUT="" +LAST_KB_LAYOUT="" while : do CURRENT_KB_LAYOUT=$(cat /tmp/kb-layout) - if ! [[ "$PREVIOUS_KB_LAYOUT" == "$CURRENT_KB_LAYOUT" ]]; then + if ! [[ "$LAST_KB_LAYOUT" == "$CURRENT_KB_LAYOUT" ]]; then if [[ "$CURRENT_KB_LAYOUT" == "1" ]]; then - echo 0 + #echo 0 echo 0 | sudo tee "/sys/class/leds/$CAPS_INPUT/brightness" else - echo 1 + #echo 1 echo 1 | sudo tee "/sys/class/leds/$CAPS_INPUT/brightness" fi - PREVIOUS_KB_LAYOUT="$CURRENT_KB_LAYOUT" + LAST_KB_LAYOUT="$CURRENT_KB_LAYOUT" fi sleep .1