Skip to content

Commit ba4e1b0

Browse files
authored
Update 5.5
Now the conclusions leds.txt they do not appear in the root, but in /tmp separate scroll lock key detection, so that the backlight is turned off separately, and not in general the installer was modified so that if there was no applications folder in ~/.local/share/, it could create it and then throw a shortcut to the program
1 parent b327f33 commit ba4e1b0

2 files changed

Lines changed: 64 additions & 22 deletions

File tree

install.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
echo "Stopping worked Wayset, if programm is installed"
3+
echo "Stopping worked Wayset, if program is installed"
44

55
sudo systemctl stop wayset
66

@@ -15,10 +15,11 @@ echo "Install Wayset"
1515

1616
sudo cp wayset /usr/local/bin/wayset
1717
sudo cp -r usr /
18+
mkdir ~/.local/share/applications
1819
cp wayset.desktop ~/.local/share/applications/wayset.desktop
1920

2021
sudo cp wayset.service /etc/systemd/system/wayset.service
21-
sudo chmod 777 /etc/systemd/system/wayset.service
22+
sudo chmod 777 /etc/systemd/system/wayset.service
2223

2324
echo "Start Wayset"
2425

usr/share/wayset/wayset.py

Lines changed: 61 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,117 @@
11
#wayset 3. Created by WebMast from WALM
22
#Wayset 4 update - lock buttons detect
33
#Wayset 5 Update - rewrite keyboard detect
4+
#Wayset 5.5 - logs in /tmp and scroll button from keyboard detect
45

56
import os
67
import keyboard as kek
78
from time import sleep
89
from threading import Thread
910
import sys
11+
import re
1012

1113
scroll_lock = []
12-
enable_led = 1
14+
enab_led_lib = {}
1315
toggle_key = None
1416

1517
def script():
18+
1619
def restart_script():
1720
python = sys.executable
1821
os.execl(python, python, *sys.argv)
1922

2023
try:
21-
os.remove('leds.txt')
24+
os.remove('/tmp/leds.txt')
2225
except:
2326
pass
2427

2528
for i in range(5):
26-
os.system('ls /sys/class/leds/ > leds.txt')
29+
os.system('ls /sys/class/leds/ > /tmp/leds.txt')
2730

28-
with open('leds.txt', 'r', encoding='utf-8') as file:
31+
with open('/tmp/leds.txt', 'r', encoding='utf-8') as file:
2932
lines = [line.strip() for line in file if 'input' in line]
3033

3134
numbers = [item.split('::')[0][5:] for item in lines if 'scrolllock' in item]
3235
scroll_lock.clear()
3336

3437
for number in numbers:
3538
scroll_lock.append(number)
36-
os.remove('leds.txt')
39+
enab_led_lib[number] = 1
40+
os.remove('/tmp/leds.txt')
3741

3842
def proc_detect():
3943

40-
os.system('ls /sys/class/leds/ > leds.txt')
44+
os.system('ls /sys/class/leds/ > /tmp/leds.txt')
4145

42-
with open('leds.txt', 'r', encoding='utf-8') as file:
46+
with open('/tmp/leds.txt', 'r', encoding='utf-8') as file:
4347
lines = [line.strip() for line in file if 'input' in line]
4448

4549
numbers = [item.split('::')[0][5:] for item in lines if 'scrolllock' in item]
4650

4751
if numbers == scroll_lock:
4852
pass
4953
else:
54+
print('wayset restart')
5055
restart_script()
5156

5257
scroll_lock.clear()
5358
for number in numbers:
5459
scroll_lock.append(number)
5560

56-
os.remove('leds.txt')
61+
os.remove('/tmp/leds.txt')
62+
63+
def kbd_detect(e):
64+
e = e.replace('event', '')
65+
try:
66+
with open('/proc/bus/input/devices') as f:
67+
for sec in f.read().split('\n\n'):
68+
if f'event{e}' in sec:
69+
# Пробуем разные паттерны для input
70+
patterns = [
71+
r'/(input\d+)/', # /.../input101/...
72+
r'Sysfs=.*/(input\d+)', # Sysfs=.../input101
73+
r'input/input(\d+)' # input/input101
74+
]
75+
for pattern in patterns:
76+
if m:=re.search(pattern, sec):
77+
input_num = m[1] if len(m.groups()) > 0 else m[0]
78+
if not input_num.startswith('input'):
79+
input_num = f"input{input_num}"
80+
return input_num, f"event{e}"
81+
except:
82+
pass
83+
try:
84+
sysfs_path = f"/sys/class/input/event{e}/device"
85+
if os.path.islink(sysfs_path):
86+
real_path = os.path.realpath(sysfs_path)
87+
for part in real_path.split('/'):
88+
if part.startswith('input'):
89+
return part, f"event{e}"
90+
except:
91+
pass
92+
return None, f"event{e}"
5793

5894
def toggle_led_pown():
5995
for i in scroll_lock:
60-
os.system(f" sh -c 'echo {enable_led} > /sys/class/leds/input{i}::scrolllock/brightness'")
96+
os.system(f" sh -c 'echo {enab_led_lib[i]} > /sys/class/leds/input{i}::scrolllock/brightness'")
6197

6298
def on_key_press(event):
6399
global toggle_key, enable_led
64100
toggle_key = event.name
101+
keytarget = event.device[16:]
65102

66103
if toggle_key == 'scroll lock':
67-
if enable_led == 0:
68-
enable_led = 1
69-
elif enable_led == 1:
70-
enable_led = 0
104+
105+
keytarget = kbd_detect(keytarget)[0][5:]
106+
107+
if keytarget in enab_led_lib:
108+
if enab_led_lib[keytarget] == 1:
109+
enab_led_lib[keytarget] = 0
110+
else:
111+
enab_led_lib[keytarget] = 1
112+
else:
113+
enab_led_lib[keytarget] = 1
114+
71115
if toggle_key == 'num lock':
72116
pass
73117
if toggle_key == 'caps lock':
@@ -77,12 +121,9 @@ def on_key_press(event):
77121
kek.on_press(on_key_press)
78122

79123
while True:
80-
if enable_led == 1:
81-
proc_detect()
82-
toggle_led_pown()
83-
sleep(0.05)
84-
else:
85-
continue
124+
proc_detect()
125+
toggle_led_pown()
126+
sleep(0.05)
86127

87128
print('Wayset. By WALM')
88-
runscript = Thread(target=script).start()
129+
runscript = Thread(target=script).start()

0 commit comments

Comments
 (0)