worked copy

This commit is contained in:
bvn13 2019-05-04 02:34:41 +03:00
parent ecf24597cb
commit 5fe135eaa3
9 changed files with 111 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
### emacs ###
*~
\#*\#

View File

@ -1,2 +1,3 @@
# kb-layout-caps-led
Switching on and off capslock led according to the keyboard layout

View File

@ -0,0 +1,24 @@
[Unit]
Description=Gnome-KB-Layout-Watcher
[Service]
Type=simple
Restart=always
RestartSec=1
PIDFile=/tmp/gnome-kb-layout-watcher.pid
WorkingDirectory=/tmp/
#User=bvn13
#Group=bvn13
OOMScoreAdjust=-1000
ExecStart=/bin/bash /home/bvn13/develop/kb-layout-caps-led/scripts/gnome-kb-layout-watcher.sh
ExecStop=kill -0 `cat /tmp/gnome-kb-layout-watcher.pid`
ExecReload=kill -0 `cat /tmp/gnome-kb-layout-watcher.pid` && /bin/bash /home/bvn13/develop/kb-layout-caps-led/scripts/gnome-kb-layout-watcher.sh
TimeoutSec=300
TimeoutStartSec=0
[Install]
WantedBy=default.target

View File

@ -0,0 +1,27 @@
[Unit]
Description=KB-Layout-Signal-Watcher
After=network.target
[Service]
Type=simple
Restart=always
RestartSec=1
PIDFile=/tmp/kb-layout-signal-watcher.pid
WorkingDirectory=/tmp/
User=root
#Group=root
OOMScoreAdjust=-1000
Environment=PATH=/bin/
ExecStart=/bin/bash /home/bvn13/develop/kb-layout-caps-led/scripts/kb-layout-signal-watcher.sh
ExecStop=kill -0 `cat /tmp/kb-layout-signal-watcher.pid`
ExecReload=kill -0 `cat /tmp/kb-layout-signal-watcher.pid` && /bin/bash /home/bvn13/develop/kb-layout-caps-led/scripts/kb-layout-signal-watcher.sh
TimeoutSec=300
TimeoutStartSec=0
[Install]
WantedBy=multi-user.target

3
draft/get-current-layout.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
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"

5
draft/get-main-layout.sh Executable file
View File

@ -0,0 +1,5 @@
#!/bin/bash
#gsettings get org.gnome.desktop.input-sources mru-sources
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"

3
draft/turn-on.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
echo 1 | sudo tee '/sys/class/leds/input3::capslock/brightness'

View File

@ -0,0 +1,18 @@
#!/bin/bash
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")
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
fi
sleep .1
done

View File

@ -0,0 +1,27 @@
#!/bin/bash
echo $$ > /tmp/kb-layout-signal-watcher.pid
CAPS_INPUT=$(ls /sys/class/leds/ | grep caps | head -n 1)
echo $CAPS_INPUT
PREVIOUS_KB_LAYOUT=""
while :
do
CURRENT_KB_LAYOUT=$(cat /tmp/kb-layout)
if ! [[ "$PREVIOUS_KB_LAYOUT" == "$CURRENT_KB_LAYOUT" ]]; then
if [[ "$CURRENT_KB_LAYOUT" == "1" ]]; then
echo 0
echo 0 | sudo tee "/sys/class/leds/$CAPS_INPUT/brightness"
else
echo 1
echo 1 | sudo tee "/sys/class/leds/$CAPS_INPUT/brightness"
fi
PREVIOUS_KB_LAYOUT="$CURRENT_KB_LAYOUT"
fi
sleep .1
done