Skip to content

Instantly share code, notes, and snippets.

@brad
Created November 2, 2018 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brad/b29db4a480c7464e44732e46e6c1fe80 to your computer and use it in GitHub Desktop.
Save brad/b29db4a480c7464e44732e46e6c1fe80 to your computer and use it in GitHub Desktop.
Script to find all xinput mice and make them use natural scrolling
#!/bin/sh
# The contents should go in /usr/lib/pm-utils/sleep.d/999natural
case "$1" in
resume)
python /home/brad/bin/natural
esac
#!/usr/bin/python
# The contents of this file should go in /home/brad/bin/natural
"""
Find all input devices and switch them to use natural scrolling
"""
from subprocess import check_output as run
# Get devices that need to be updated
mice = list(map(
lambda mouse: mouse.split('\t')[1].split('=')[1],
filter(
lambda d: d.find('Optical') > -1 or d.find('Touchpad') > -1,
run(['xinput', 'list']).decode('utf8').split('\n')
)
))
# For all mice, loop over the props to find props that need updating
for mouse in mice:
props = run(['xinput', 'list-props', mouse]).decode('utf8').split('\n')
for prop in props[1:-1]:
prop_id = prop.split('(')[1].split(')')[0]
val = prop.split(':')[1]
if prop.find('Natural Scrolling Enabled (') > -1:
# Enable the natural scrolling property
run(['xinput', 'set-prop', mouse, prop_id, '1'])
elif prop.find('Synaptics Scrolling Distance') > -1:
# Negate the scrolling distance
vals = list(map(
lambda p: '-{}'.format(abs(int(p.strip()))),
val.split(','))
)
run(['xinput', 'set-prop', mouse, prop_id, vals[0], vals[1]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment