Skip to content

Commit

Permalink
Merge pull request #38 from asus-linux-drivers/configurable-inactivat…
Browse files Browse the repository at this point in the history
…ion-time
  • Loading branch information
ldrahnik authored Jul 26, 2022
2 parents 41617fa + cf84fbf commit 3e2d32d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ If you find a project useful, do not forget to give project a [![GitHub stars](h
- By default remember the last used level of backlight (even between reboots)
- Smooth change of backlight levels (endless loop with customizable interval, default 1s)
- Customizable slide gesture beginning on top left (default action is calculator with numpad activation and a requirement is end slide after atleast 0.3 of width and height)
- Numpad is automatically disabled due inactivity (default 1 min)
- Disabling Touchpad (e.g. Fn+special key) disables numpad aswell
- Numlock state corresponds to the system numlock state (disabling sys numlock from e.g. external keyboard disables numpad aswell, reflect enabling sys numlock is optional)
- Touchpad physical buttons (left, right and middle) are ignored when is numpad on
Expand Down Expand Up @@ -115,7 +116,8 @@ Example: If you want to set the activation time to 2 seconds and you have chosen

| Option | Required | Default | Description |
| --------------------------- | ------------|---------|-------------------------------------------------------------------|
| **System** | | |
| **System** | | |
| `disable_due_inactivity_time`| | 60 [s] | numpad is automatically disabled when have not received any event for this interval
| `touchpad_disables_numpad`| | `True` | when is touchpad disabled is disabled numpad aswell, valid value is `True` or `False` (e.g. via Fn+special key)<br><br>status is taken from result of `xinput` - to toggle touchpad can be used [this script](https://github.com/ldrahnik/elementary-os-scripts/blob/master/toggle_touchpad.sh)
| `sys_numlock_enables_numpad`| | `False` | obtained via active `LED_NUML` of keyboard device<br><br>enable with `True`, by default numpad reflects only disabling system numlock (then is disabled)
| **Device search** | | | `/proc/bus/input/devices`
Expand Down
36 changes: 34 additions & 2 deletions asus_touchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

percentage_key: libevdev.const = EV_KEY.KEY_5

disable_due_inactivity_time = getattr(model_layout, "disable_due_inactivity_time", 60)
touchpad_disables_numpad = getattr(model_layout, "touchpad_disables_numpad", True)
key_repetitions = getattr(model_layout, "key_repetitions", False)
multitouch = getattr(model_layout, "multitouch", False)
Expand Down Expand Up @@ -367,6 +368,7 @@ def deactivate_numpad():
unsupported_abs_mt_slot: bool = False
top_right_icon_touch_start_time = 0
top_left_icon_touch_start_time = 0
last_event_time = 0
brightness: int = 0

def set_tracking_id(value):
Expand Down Expand Up @@ -669,10 +671,12 @@ def get_system_numlock():
def listen_touchpad_events():
global brightness, d_t, abs_mt_slot_value, abs_mt_slot, abs_mt_slot_numpad_key,\
abs_mt_slot_x_values, abs_mt_slot_y_values, support_for_maximum_abs_mt_slots,\
unsupported_abs_mt_slot, top_right_icon_touch_start_time, touchpad_name
unsupported_abs_mt_slot, top_right_icon_touch_start_time, touchpad_name, last_event_time

for e in d_t.events():

last_event_time = time()

# ignore POINTER_BUTTON when is numpad on
if numlock:
if e.matches(EV_KEY.BTN_LEFT):
Expand Down Expand Up @@ -814,7 +818,7 @@ def check_touchpad_status():
is_touchpad_enabled = is_device_enabled(touchpad_name)

if not is_touchpad_enabled and touchpad_disables_numpad and numlock:
numlock = False
numlock = False
deactivate_numpad()
log.info("Numpad deactivated")

Expand All @@ -833,6 +837,29 @@ def check_touchpad_status_endless_cycle():
sleep(0.5)


def check_numpad_automatical_disable_due_inactivity():
global disable_due_inactivity_time, last_event_time, numlock

while True:
if\
numlock and\
last_event_time != 0 and\
time() > disable_due_inactivity_time + last_event_time:

numlock_lock.acquire()

sys_numlock = get_system_numlock()
if sys_numlock:
send_numlock_key(1)
send_numlock_key(0)
log.info("System numlock deactivated")

numlock = False
deactivate_numpad()
log.info("Numpad deactivated")
numlock_lock.release()
sleep(1)

threads = []
# if keyboard with numlock indicator was found
# thread for listening change of system numlock
Expand All @@ -847,4 +874,9 @@ def check_touchpad_status_endless_cycle():
threads.append(t)
t.start()

if disable_due_inactivity_time > 0:
t = threading.Thread(target=check_numpad_automatical_disable_due_inactivity)
threads.append(t)
t.start()

listen_touchpad_events()

0 comments on commit 3e2d32d

Please sign in to comment.