Skip to content

Commit

Permalink
#199 added toggling tap-to-click using qdbus for kde (credits @sleddev)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldrahnik committed Sep 15, 2024
1 parent f6d761d commit f817e1d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ keyboard shortcuts - for example in [my toggling script](https://github.com/asus
- NumberPad is automatically disabled due to inactivity (default 1 min, maximum value is around 2 minutes and is limited by hardware, more in [#143](https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/143))
- NumberPad cooperation with system NumLock is configurable (activation/deactivation of NumberPad may also enable/disable system NumLock and vice versa)
- Activation of NumberPad with a configurable distance beyond which the movement of a pressed key is considered as a pointer movement rather than a key specification
- Activation of NumberPad disables pointer taps (*this functionality presently supports only `xinput` from `xorg` and `gnome` via `gsettings`* - can be configured)
- Activation of NumberPad disables pointer taps (has to be set )
- Protection against accidental multitouching (when a second finger is simultaneously used)
- Protection against sending a NumberPad key when a pointer button (left, right, middle) is clicked (configuration value set to `press_key_when_is_done_untouch=1`)
- Disabling the Touchpad (e.g. Fn+special key) disables by default the NumberPad as well (*this functionality presently supports only `xinput` from `xorg` and `gnome` via `gsettings`* - can be disabled)
Expand Down Expand Up @@ -496,7 +496,7 @@ idle_enabled = 0
| `touchpad_disables_numpad` | | `1` | when Touchpad is disabled is NumberPad is disabled aswell, valid value is `1` or `0` (e.g. via Fn+special key)<br><br>status is being attempted for the first time from `gsettings get org.gnome.desktop.peripherals.touchpad send-events`, can be tested via direct change `gsettings set org.gnome.desktop.peripherals.touchpad send-events 'enabled'` or simulation of Touchpad toggling via CLI `xdotool key XF86TouchpadToggle` or `xdotool key XF86TouchpadOn` and `xdotool key XF86TouchpadOff`, secondly the result of `xinput` is taken - in this case [this script](https://github.com/ldrahnik/elementary-os-scripts/blob/master/toggle_touchpad.sh) which has to be bound to a specific Touchpad key
| `sys_numlock_enables_numpad` | | `1` | NumLock status obtained via active `LED_NUML` of keyboard device (by default NumberPad is enabled or disabled when the system NumLock is toggled)<br><br>System NumLock can be simulated `xdotool key Num_Lock`<br><br>`sys_numlock_enables_numpad` to be set to `1` automatically even when is in config file value is `0` (overwritten) in cases when no position key `EV_KEY.KEY_NUMLOCK` has been defined in the key layout and top right icon is not defined (size values `top_right_icon_width` and `top_right_icon_height`)
| `numpad_disables_sys_numlock` | | `1` | when is set to `1` at each inactivation of NumberPad `EV_KEY.KEY_NUMLOCK` is sent. This is useful to not send NumLock when a laptop is connected to an external keyboard and one wants to disable NumberPad on laptop keeping NumLock on the external keyboard enabled
| `enabled_touchpad_pointer` | | `3` | valid values are `0`, `1`, `2`, `3` <br><br>when set to `1` the touchpad pointer can be used for moving and for clicking the left, right and middle pointer buttons when NumberPad is activated, `0` disables this usage and `2` allowes only pointer button clicks, `3` allowes only touchpad pointer movements without clicks (touchpad tap-to-click is disabled/enabled using `gnome` via `gsettings` and for `xinput` for `X11` with this order priority)
| `enabled_touchpad_pointer` | | `3` | valid values are `0`, `1`, `2`, `3` <br><br>when set to `1` the touchpad pointer can be used for moving and for clicking the left, right and middle pointer buttons when NumberPad is activated, `0` disables this usage and `2` allowes only pointer button clicks, `3` allowes only touchpad pointer movements without clicks (touchpad tap-to-click is disabled/enabled using `gsettings` on `gnome`, `qdbus` on `kde` and using `xinput` for `X11` with this order priority)
| `press_key_when_is_done_untouch` | | `1` | valid values are `0`, `1` <br><br>when set to `1` the touchpad sends keys when the finger is released (e.g. allows moving with the pointer and allows canceling sending when is the finger before untouch moved outside of the grid spot for touched character or moved inside the grid spot more than is defined by `distance_to_move_only_pointer`)
| **Key layout** | |
| `activation_time` | | `1.0` [seconds] | amount of time you have to hold `top_right_icon` or another predefined key `EV_KEY.KEY_NUMLOCK` for NumberPad activation/deactivation<br><br>decimal numbers allowed
Expand Down
36 changes: 32 additions & 4 deletions numberpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,9 @@ def load_keymap_listener_x11():
gsettings_failure_count = 0
gsettings_max_failure_count = 3

qdbus_failure_count = 0
qdbus_max_failure_count = 3

getting_device_via_xinput_status_failure_count = 0
getting_device_via_xinput_status_max_failure_count = 3

Expand Down Expand Up @@ -706,6 +709,31 @@ def gsettingsGet(path, name):
log.debug('Gsettings failed more then: \"%s\" so is not try anymore', gsettings_max_failure_count)


def qdbusSet(value):
global qdbus_failure_count, qdbus_max_failure_count, touchpad

if qdbus_failure_count < qdbus_max_failure_count:
try:
cmd = [
'qdbus',
'org.kde.KWin',
f'/org/kde/KWin/InputDevice/event{touchpad}',
'org.kde.KWin.InputDevice.tapToClick',
str(value)
]
subprocess.call(cmd)
except:
log.exception('qdbus set failed')
qdbus_failure_count+=1
else:
log.debug('Qdbus failed more then: \"%s\" so is not try anymore', qdbus_max_failure_count)

subprocess.call(cmd)


def qdbusSetTouchpadTapToClick(value):
qdbusSet(value)

def gsettingsGetTouchpadSendEvents():
return gsettingsGet('org.gnome.desktop.peripherals.touchpad', 'send-events').decode().rstrip()

Expand Down Expand Up @@ -1164,13 +1192,13 @@ def grab_current_slot():


def set_touchpad_prop_tap_to_click(value):
global touchpad_name, gsettings_failure_count, gsettings_max_failure_count, getting_device_via_xinput_status_failure_count, getting_device_via_xinput_status_max_failure_count, getting_device_via_synclient_status_failure_count, getting_device_via_synclient_status_max_failure_count
global touchpad_name, gsettings_failure_count, gsettings_max_failure_count, qdbus_max_failure_count, qdbus_failure_count, getting_device_via_xinput_status_failure_count, getting_device_via_xinput_status_max_failure_count, getting_device_via_synclient_status_failure_count, getting_device_via_synclient_status_max_failure_count

# 1. priority - gsettings
# 1. priority - gsettings (gnome) or qdbus (kde)
if gsettings_failure_count < gsettings_max_failure_count:
gsettingsSetTouchpadTapToClick(value)
# why is return commented? and is always run also xinput below? Because on KDE is allowed set up without any error but nothing happens
# return
if qdbus_failure_count < qdbus_max_failure_count:
qdbusSetTouchpadTapToClick(value)

# 2. priority - xinput
if getting_device_via_xinput_status_failure_count > getting_device_via_xinput_status_max_failure_count:
Expand Down

0 comments on commit f817e1d

Please sign in to comment.