-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrackball.rb
141 lines (129 loc) · 4.51 KB
/
trackball.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#!/usr/bin/env ruby
###########################################
## Pick the file you want to write below ##
###########################################
=begin
###########################################
# Puts Small Left Button as Middle #
# Right Left Buttton as Scroll #
###########################################
default_text = <<EOM
Section "InputClass"
Identifier "Marble Mouse"
MatchProduct "Logitech USB Trackball"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
Option "SendCoreEvents" "true"
# Physical buttons come from the mouse as:
# Big: 13
# Small: 8 9
# This makes left small button (8) into the middle,
# and puts scrolling on the right small button (9).
Option "Buttons" "9"
Option "ButtonMapping" "1 8 3 4 5 6 7 2 9"
Option "EmulateWheel" "true"
Option "EmulateWheelButton" "9"
Option "YAxisMapping" "4 5"
Option "XAxisMapping" "6 7"
EndSection
EOM
=end
=begin
####################################################
# Puts Small Left Button as Middle, hold to Scroll #
# Right Left Buttton as Forward #
####################################################
default_text = <<EOM
Section "InputClass"
Identifier "Marble Mouse"
MatchProduct "Logitech USB Trackball"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
# Option "SendCoreEvents" "true"
# Option "Buttons" "8"
Option "ButtonMapping" "1 8 3 4 5 6 7 2 9"
Option "EmulateWheel" "true"
Option "EmulateWheelButton" "8"
Option "YAxisMapping" "4 5"
Option "XAxisMapping" "6 7"
Option "Emulate3Buttons" "true"
EndSection
EOM
=end
=begin
###########################################
# Puts Small Left Button as #
# Right Left Buttton as #
###########################################
default_text = <<EOM
Section "InputClass"
Identifier "Marble Mouse"
MatchProduct "Logitech USB Trackball"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
Option "ButtonMapping" "1 2 3 4 5 6 7 8 9"
Option "EmulateWheel" "true"
Option "EmulateWheelButton" "8"
Option "ZAxisMapping" "4 5"
Option "XAxisMapping" "6 7"
Option "Emulate3Buttons" "true"
EndSection
EOM
=end
default_text = <<EOM
Section "InputClass"
Identifier "Marble Mouse"
MatchProduct "Logitech USB Trackball"
MatchIsPointer "on"
MatchDevicePath "/dev/input/event*"
Driver "evdev"
# Option "SendCoreEvents" "true"
Option "Buttons" "9"
Option "ButtonMapping" "1 8 3 4 5 6 7 2 9"
Option "EmulateWheel" "true"
Option "EmulateWheelButton" "8"
Option "YAxisMapping" "4 5"
Option "XAxisMapping" "6 7"
Option "Emulate3Buttons" "true"
EndSection
EOM
#Finds the configuration directory
xorgconfigdir = `locate xorg.conf.d | grep d$`
xorgconfigdir.chomp!
#Finds the temp directory
require 'tmpdir'
tempdirectory = Dir.tmpdir()
f = File.new((tempdirectory + "/50-marblemouse.conf"), "w")
f.puts default_text
f.close
puts `echo #{xorgconfigdir}`
if FileTest.exists?(xorgconfigdir + "/50-marblemouse.conf")
File.open((xorgconfigdir + "/50-marblemouse.conf"), 'r') do |file|
#btw this block is not iterating (confusing!) only opening & closing the file
if (file.read =~ /Section\s*\"InputClass\"/i)
@dont_append = true
end
end
if @dont_append
puts "Manual Action needed. \nTrackball config file exists with an Input Class already defined. \nOverwrite existing file? WARNING you may loose data! (Y/N)"
overwrite = gets
if (overwrite.to_s =~ /y/i)
puts "Overwriting existing Trackball conf file."
puts `sudo cp #{tempdirectory}/50-marblemouse.conf #{xorgconfigdir}/50-marblemouse.conf`
else
puts "Generated Config file is at #{tempdirectory}/50-marblemouse.conf existing config file is at #{xorgconfigdir}."
end
else
puts "Trackball Conf file exits but doesn't contain Input Class.\nAppending Input Class to config file."
#Change file permisions -- Won't append the file without it.
puts `sudo chmod 666 #{xorgconfigdir + "/50-marblemouse.conf"}`
puts `sudo cat #{tempdirectory + "/50-marblemouse.conf"} >> #{xorgconfigdir + "/50-marblemouse.conf"}`
puts `sudo chmod 644 #{xorgconfigdir + "/50-marblemouse.conf"}`
end
else
puts "Config file doesn't exist. Creating one."
puts `sudo cp #{tempdirectory}/50-marblemouse.conf #{xorgconfigdir}/50-marblemouse.conf`
end