minor improvements and readme

master
bvn13 2019-05-05 16:53:13 +03:00
parent 5fe135eaa3
commit f6270f43a5
3 changed files with 45 additions and 10 deletions

View File

@ -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
```

View File

@ -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

View File

@ -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