diff --git a/asus_touchpad.py b/asus_touchpad.py index 77aaf32..60cd793 100755 --- a/asus_touchpad.py +++ b/asus_touchpad.py @@ -13,7 +13,7 @@ from typing import Optional import numpy as np from libevdev import EV_ABS, EV_KEY, EV_LED, EV_MSC, EV_SYN, Device, InputEvent, const, device -from inotify import adapters +from pyinotify import WatchManager, IN_CLOSE_WRITE, IN_IGNORED, IN_MOVED_TO, AsyncNotifier import Xlib.display import Xlib.X import Xlib.XK @@ -864,9 +864,6 @@ def load_all_config_values(): # because inotify (deadlock) sleep(0.1) -inotify_adapters = adapters.Inotify() -inotify_adapters.add_watch(config_file_dir) - def set_tracking_id(value): try: @@ -1638,29 +1635,35 @@ def check_numpad_automatical_disable_due_inactivity(): def check_config_values_changes(): - global inotify_adapters, config_lock - - try: - while not stop_threads: - for event in inotify_adapters.event_gen(yield_nones=False, timeout_s=1): + global config_lock, stop_threads - (_, type_names, path, filename) = event + watch_manager = WatchManager() - if filename != CONFIG_FILE_NAME or path != config_file_dir: - continue + path = os.path.abspath(config_file_dir) + mask = IN_CLOSE_WRITE | IN_IGNORED | IN_MOVED_TO + watch_manager.add_watch(path, mask) - if "IN_CLOSE_WRITE" in type_names or "IN_IGNORED" in type_names or "IN_MOVED_TO" in type_names: + event_notifier = AsyncNotifier(watch_manager) - if not config_lock.locked(): - log.info("check_config_values_changes: detected external change of config file -> loading changes") - # because file might be read so fast that changes will not be there yet - sleep(0.1) - load_all_config_values() - else: - log.info("check_config_values_changes: detected internal change of config file -> do nothing -> would be deadlock") + while not stop_threads: + try: + event_notifier.process_events() + if event_notifier.check_events(): + event_notifier.read_events() + + if not config_lock.locked(): + log.info("check_config_values_changes: detected external change of config file -> loading changes") + # because file might be read so fast that changes will not be there yet + sleep(0.1) + load_all_config_values() + else: + log.info("check_config_values_changes: detected internal change of config file -> do nothing -> would be deadlock") + + except KeyboardInterrupt: + break - except: - pass + event_notifier.stop() + watch_manager.del_watch(path) log.info("check_config_values_changes: inotify watching config file ended") @@ -1711,7 +1714,6 @@ def check_config_values_changes(): # then clean up stop_threads=True - inotify_adapters.remove_watch(config_file_dir) fd_t.close() for thread in threads: thread.join() diff --git a/install.sh b/install.sh index f93e4aa..26913d8 100755 --- a/install.sh +++ b/install.sh @@ -28,7 +28,7 @@ session_id=$(loginctl | grep $SUDO_USER | head -1 | awk '{print $1}') wayland_or_x11=$(loginctl show-session $session_id -p Type --value) if [[ $(apt install 2>/dev/null) ]]; then - echo 'apt is here' && apt -y install ibus libevdev2 i2c-tools python3-dev python3-pip + echo 'apt is here' && apt -y install ibus libevdev2 i2c-tools python3-dev python3-libevdev python3-numpy python3-xlib python3-pyinotify if [ "$wayland_or_x11" = "x11" ]; then apt -y install xinput fi @@ -38,19 +38,25 @@ elif [[ $(pacman -h 2>/dev/null) ]]; then if [ "$wayland_or_x11" = "x11" ]; then pacman --noconfirm --needed -S xorg-xinput fi + + runuser -u $RUN_UNDER_USER -- python3 -m pip install -r requirements.txt + + if [[ $? != 0 ]]; then + echo "pip dependencies via file requirements.txt cannot be loaded correctly." + exit 1 + fi elif [[ $(dnf install 2>/dev/null) ]]; then echo 'dnf is here' && dnf -y install ibus libevdev i2c-tools python3-devel python3-pip if [ "$wayland_or_x11" = "x11" ]; then dnf -y install xinput fi -fi -runuser -u $RUN_UNDER_USER -- python3 -m pip install -r requirements.txt + runuser -u $RUN_UNDER_USER -- python3 -m pip install -r requirements.txt -# Checking if the pip dependencies are successfuly loaded -if [[ $? != 0 ]]; then - echo "pip dependencies via file requirements.txt cannot be loaded correctly." - exit 1 + if [[ $? != 0 ]]; then + echo "pip dependencies via file requirements.txt cannot be loaded correctly." + exit 1 + fi fi modprobe i2c-dev