-
Notifications
You must be signed in to change notification settings - Fork 12
/
wacom_xorg.py
175 lines (157 loc) · 6.41 KB
/
wacom_xorg.py
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Xorg Modification utility
# Tested on Ubuntu Jaunty x86_64
from copy import copy
import os
def SetXorgConfig(value):
CheckXorgConf()
f1 = open("/etc/X11/xorg.conf", 'r')
data = f1.readlines()
f1.close()
if value == 0: # Remove custom configuration
exclusion = [] # Line numbers to exclude
for item in data:
exclusion.append(0)
for i in range(0, len(data)):
line = data[i]
line = line.split("#")[0] # Remove commenting from analysis
if StdParse(line).count("section\"inputdevice\""):
State = 0 # State triggers if it's a wacom configuration
for subline in data[i+1:]:
if StdParse(subline).count("driver\"wacom\""):
State = 1
if StdParse(subline).count("endsection"):
break
# If State = 1, mark all lines until next endsection
if State == 1:
for j in range(i, len(data)):
subline = data[j]
exclusion[j] = 1
if StdParse(subline).count("endsection"):
break
# Remove all entries from serverlayout
if StdParse(line).count("section\"serverlayout\""):
for device in CheckXorgConfig()[1]:
for j in range(i+1, len(data)):
subline = data[j]
if StdParse(subline).count("endsection"):
break
if StdParse(subline).count("inputdevice\""+device+"\""):
exclusion[j] = 1
# Compile the new file
newdata = []
for i in range(0, len(data)):
if exclusion[i] == 0:
newdata.append(data[i])
elif value == 1:
newdata = copy(data)
hasserverlayout = 0
for i in range(0, len(data)):
line = data[i]
line = line.split("#")[0] # Remove commenting from analysis
if StdParse(line).count("section\"serverlayout\""):
hasserverlayout = 1
q = 0
for item in GetSLData():
newdata.insert(i+1+q, item+"\n")
q += 1
break
for item in GetIDData():
newdata.append(item+"\n")
if hasserverlayout == 0:
newdata.append("Section \"ServerLayout\"\n")
newdata.append("Identifier \"Default Layout\"\n")
for item in GetSLData():
newdata.append(item+"\n")
newdata.append("EndSection\n")
# Write the new file to a temporary directory
f1 = open("/tmp/xorg.conf", 'w')
f1.writelines(newdata)
f1.close()
# Backup
os.system("cp /etc/X11/xorg.conf ~/.xorg_wacom_utility_backup")
# Copy
os.system("gksu cp /tmp/xorg.conf /etc/X11/xorg.conf")
def CheckXorgConfig():
# Checks for existance of a section using wacom driver
# Does not check validity of configuration
State = 0 # 0=Unconfigured 1=Configured 2=Broken
Devices = []
CheckXorgConf()
f1 = open("/etc/X11/xorg.conf", 'r')
data = f1.readlines()
f1.close()
for i in range(0,len(data)):
line = data[i]
line = line.split("#")[0] # Remove commenting
if StdParse(line).count("section\"inputdevice\""):
for subline in data[i+1:]:
if StdParse(subline).count("endsection"):
break
if StdParse(subline).count("driver\"wacom\""):
State = 1
if StdParse(subline).count("option\"type\""):
Devices.append(StdParse(subline).split("\"")[-2])
if State == 1: # Check for presence of all listed devices in serverlayout section
for i in range(0, len(data)):
line = data[i]
line = line.split("#")[0] # Remove commenting
if StdParse(line).count("section\"serverlayout\""):
for device in Devices:
Ok = 0
for subline in data[i+1:]:
if StdParse(subline).count("endsection"):
break
if StdParse(subline).count("inputdevice\""+device+"\""):
Ok = 1
if Ok == 0:
State = 2
return State, Devices
def StdParse(line): # Format with no spaces, tabs, and double quotes only
return line.replace(" ","").replace("\t","").replace("\'","\"").replace("\n","").lower()
def CheckXorgConf():
# If xorg.conf doesn't exist, create blank template
# Distros such as Fedora 10 do not come with xorg.conf created
try:
os.stat("/etc/X11/xorg.conf")
except:
newdata = ["Section \"ServerLayout\"\n", "EndSection"]
f1 = open("/tmp/xorg.conf", 'w')
f1.writelines(newdata)
f1.close()
# Copy
os.system("gksu cp /tmp/xorg.conf /etc/X11/xorg.conf")
def GetSLData():
return ["\tInputDevice \"stylus\" \"SendCoreEvents\"",\
"\tInputDevice \"eraser\" \"SendCoreEvents\"",\
"\tInputDevice \"cursor\" \"SendCoreEvents\"\t# For non-LCD tablets only",\
"\tInputDevice \"pad\" \"SendCoreEvents\"\t# For Intuos3/CintiqV5/Graphire4/Bamboo tablets"]
def GetIDData():
data = """Section "InputDevice"
Driver "wacom"
Identifier "stylus"
Option "Device" "/dev/input/wacom" # USB ONLY?
Option "Type" "stylus"
Option "USB" "on" # USB ONLY
EndSection
Section "InputDevice"
Driver "wacom"
Identifier "eraser"
Option "Device" "/dev/input/wacom" # USB ONLY?
Option "Type" "eraser"
Option "USB" "on" # USB ONLY
EndSection
Section "InputDevice"
Driver "wacom"
Identifier "cursor"
Option "Device" "/dev/input/wacom" # USB ONLY?
Option "Type" "cursor"
Option "USB" "on" # USB ONLY
EndSection
Section "InputDevice"
Driver "wacom"
Identifier "pad"
Option "Device" "/dev/input/wacom" # USB ONLY
Option "Type" "pad"
Option "USB" "on" # USB ONLY
EndSection"""
return data.split("\n")