Skip to content

Instantly share code, notes, and snippets.

@denyago
Created September 8, 2013 10:13
Show Gist options
  • Save denyago/6483569 to your computer and use it in GitHub Desktop.
Save denyago/6483569 to your computer and use it in GitHub Desktop.
Enables Natural Scrolling at Ubuntu like OS X has. Simple script to run on X start.
#!env ruby
# This script enables 'Natural scrolling' as in OS X.
#
# Usage:
# 1. Find your touchpad name by running xinput list
# 2. Run ./natural_scroll.rb 'touchpad name'
#
# Limitations:
# - Tested only on Ubuntu 13.04
# - Assuming scroll up is 4, scroll down is 5
#
# License: MIT
# Author: Denis Yagofarov <[email protected]>
def touchpad_name
@touchpad_name ||= ARGV[0].to_s
end
def input_id
`xinput list | grep "#{touchpad_name}"`.
strip.
match(/id=(\d+)/)[1].
to_i
rescue
0
end
raise 'You must set name of touchpad device. Find one in `xinput list`' if touchpad_name.size == 0
error_command = "notify-send -u critical 'Natural scroll' 'Unable to determine touchpad devise, named \"#{touchpad_name}\"' -i input-tablet"
swap_command = "xinput set-button-map #{input_id} 1 2 3 5 4"
if input_id > 0
`#{swap_command}`
else
`#{error_command}`
exit 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment