Skip to content

Commit

Permalink
#104 added gnome gsettings as secondary way except xinput for getting…
Browse files Browse the repository at this point in the history
… status of Touchpad / setting up tab-to-click
  • Loading branch information
ldrahnik committed Mar 17, 2023
1 parent e1eb1d5 commit 55dcfc9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If you find this project useful, do not forget to give it a [![GitHub stars](htt
- Multitouch up to 5 fingers (disabled by default)
- Is implemented protection against multitouching accidentally when is multitouch not enabled (printing NumberPad key and slide gestures from corners are cancelled when is second finger used)
- Driver supports laptop suspend
- Disabling Touchpad (e.g. Fn+special key) disables by default NumberPad as well (can be disabled, this functionality supports atm only `xinput` from `xorg`, no `wayland` support https://github.com/asus-linux-drivers/asus-numberpad-driver/issues/104)
- Disabling Touchpad (e.g. Fn+special key) disables by default NumberPad as well (can be disabled, this functionality supports atm only `xinput` from `xorg` and gnome via `gsettings`)
- Is recognized when is connected external keyboard and automatically is changed [configuration](https://github.com/asus-linux-drivers/asus-numberpad-driver#external-keyboard-configuration)

## Layouts
Expand Down Expand Up @@ -423,10 +423,10 @@ top_left_icon_brightness_func_disabled = 0
| **System** | | |
| `enabled` | | `0` | NumberPad running status (enabled/disabled)
| `disable_due_inactivity_time` | | `60.0` [s] | NumberPad is automatically disabled when have not received any event for this interval<br><br>decimal places allowed
| `touchpad_disables_numpad` | | `1` | when is touchpad disabled is disabled NumberPad aswell, valid value is `1` or `0` (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)
| `touchpad_disables_numpad` | | `1` | when is touchpad disabled is disabled NumberPad 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`, tested can be 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`, secondary is taken result of `xinput` - in this case can be for get this work used [this script](https://github.com/ldrahnik/elementary-os-scripts/blob/master/toggle_touchpad.sh) which has to be binded to Touchpad special key
| `sys_numlock_enables_numpad` | | `0` | obtained via active `LED_NUML` of keyboard device<br><br>enable with `1`, by default NumberPad reflects only disabling system numlock (then is disabled)<br><br>System numlock can be simulated `xdotool key Num_Lock`
| `numpad_disables_sys_numlock` | | `1` | when is set to `1` is every time during inactivation of NumberPad sent `KEY_NUMLOCK`. Is useful do not send NumLock when is to laptop connected external keyboard and goal is only disable NumberPad on laptop but keep NumLock on external keyboard enabled
| `enabled_touchpad_pointer` | | `3` | valid values are `0`, `1`, `2`, `3` <br><br>when is set to `1` touchpad pointer can be used to moving and for clicking and can be clicked pointer buttons left, right and middle when is NumberPad activated, `0` disable this usage and `2` allowes only pointer button clicks, `3` allowes only touchpad pointer moving without clicks
| `enabled_touchpad_pointer` | | `3` | valid values are `0`, `1`, `2`, `3` <br><br>when is set to `1` touchpad pointer can be used to moving and for clicking and can be clicked pointer buttons left, right and middle when is NumberPad activated, `0` disable this usage and `2` allowes only pointer button clicks, `3` allowes only touchpad pointer moving without clicks (touchpad tap-to-click is disabled/enabled using `gnome` via `gsettings` and for `xinput` for `X11` with this order priority)
| **Key layout** | |
| `activation_time` | | `1.0` [seconds] | amount of time you have to touch `top_right_icon` or another spot with key `EV_KEY.KEY_NUMLOCK` for the NumberPad activation/deactivation<br><br>decimal places allowed
| `multitouch` | | `0` | up to quint tap when enabled<br><br>Example 1: can be enabled NumberPad when second finger is touched on touchpad somewhere as well;<br><br>Example 2: brightness can be changed during using NumberPad for calculating)
Expand Down
30 changes: 26 additions & 4 deletions asus_touchpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,19 @@ def isEvent(event):
def is_device_enabled(device_name):
global getting_device_status_failure_count

try:
cmd = ['gsettings', 'get', 'org.gnome.desktop.peripherals.touchpad', 'send-events']
propData = subprocess.check_output(cmd)
propData = propData.decode()
if 'enabled' in propData:
return True
elif 'disabled' in propData:
return False
except:
log.exception('Getting gnome touchpad send-events via gsettings failed')
return True


if getting_device_status_failure_count > 9:
log.debug('Getting Device Enabled via xinput failed more then 9 times so is not try anymore, returned Touchpad enabled')
return True
Expand Down Expand Up @@ -567,6 +580,15 @@ def grab_current_slot():
def set_touchpad_prop_tap_to_click(value):
global touchpad_name

try:
cmd = ['runuser', '-u', os.environ['SUDO_USER'], 'gsettings', 'set', 'org.gnome.desktop.peripherals.touchpad', 'tap-to-click', str(bool(value)).lower()]
log.debug(cmd)
subprocess.check_output(cmd)

return
except (subprocess.CalledProcessError, KeyError) as e:
log.exception('Getting gnome touchpad tap-to-click via gsettings failed')

try:
cmd = ["xinput", "set-prop", touchpad_name, 'libinput Tapping Enabled', str(value)]
log.debug(cmd)
Expand All @@ -578,8 +600,6 @@ def set_touchpad_prop_tap_to_click(value):
def activate_numpad():
global brightness, default_backlight_level, enabled_touchpad_pointer, top_left_icon_brightness_func_disabled

config_set(CONFIG_ENABLED, True)

if enabled_touchpad_pointer == 0 or enabled_touchpad_pointer == 2:
grab()
elif enabled_touchpad_pointer == 3:
Expand All @@ -599,12 +619,12 @@ def activate_numpad():
# TODO: atm do not care what last value is now displayed and which one (nearest higher) should be next (default 0x01 means turn leds on with last used level of brightness)
brightness = -1

config_set(CONFIG_ENABLED, True)


def deactivate_numpad():
global brightness, enabled_touchpad_pointer

config_set(CONFIG_ENABLED, False)

if enabled_touchpad_pointer == 0 or enabled_touchpad_pointer == 2:
ungrab()
elif enabled_touchpad_pointer == 3:
Expand All @@ -613,6 +633,8 @@ def deactivate_numpad():
send_value_to_touchpad_via_i2c("0x00")
brightness = 0

config_set(CONFIG_ENABLED, False)


def get_system_numlock():
global dev_k
Expand Down

0 comments on commit 55dcfc9

Please sign in to comment.