1 package v2
2
3 import (
4 "regexp"
5 )
6
7 var (
8 dpmsDisabled = false
9 zeroSeconds = 0
10 )
11
12
13
14 type DefaultConfig struct {
15
16
17 Display Display
18
19
20
21 KnownDisplays map[MPID]KnownDisplayDefaults
22
23 DPMS *DPMS
24 }
25
26 type KnownDisplayDefaults struct {
27 InputDevicePatterns []string
28 }
29
30
31
32
33
34 var Defaults = DefaultConfig{
35 Display: Display{
36 Orientation: &NormalOrientation,
37 },
38 KnownDisplays: map[MPID]KnownDisplayDefaults{
39 "ACR-2199": {
40
41
42 InputDevicePatterns: []string{
43 "Weida Hi-Tech\\s+CoolTouchR System\\s+.*",
44 },
45 },
46 "ELO-4098": {
47
48 InputDevicePatterns: []string{
49 "Elo Touch Solutions Elo Touch Solutions Pcap USB Interface",
50 },
51 },
52 "ELO-5705": {
53
54
55 InputDevicePatterns: []string{
56 "Atmel Atmel maXTouch Digitizer",
57 "Elo TouchSystems, Inc\\. Elo TouchSystems 2700.*",
58 },
59 },
60 "ELO-5911": {
61
62 InputDevicePatterns: []string{
63 "Elo TouchSystems, Inc\\. Elo TouchSystems 2700.*",
64 },
65 },
66 "ELO-8816": {
67
68
69 InputDevicePatterns: []string{
70 "Elo Touch\\s+2270L pCAP HID\\s+.*",
71 },
72 },
73 "NCR-22800": {
74
75
76 InputDevicePatterns: []string{
77 "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
78 },
79 },
80 "NCR-22805": {
81
82 InputDevicePatterns: []string{
83 "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
84 },
85 },
86 "NCR-22888": {
87
88
89
90 InputDevicePatterns: []string{
91 "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
92 "Advanced Silicon S\\.A\\. CoolTouch® System",
93 },
94 },
95 "NCR-22917": {
96
97 InputDevicePatterns: []string{
98 "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*",
99 },
100 },
101
102 "NCR-30578": {
103
104
105
106
107
108
109 InputDevicePatterns: []string{
110 "eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*",
111 },
112 },
113 "TGC-18464": {
114
115 InputDevicePatterns: []string{
116 "Elo TouchSystems Inc\\. Elo TouchSystems CarrollTouch.*",
117 },
118 },
119 "VSC-23866": {
120
121
122 InputDevicePatterns: []string{
123 "iSolution multitouch.*",
124 },
125 },
126 "WNX-22": {
127
128 InputDevicePatterns: []string{
129 "Beijing IRTOUCH SYSTEMS Co\\.,LtD IRTOUCH InfraRed TouchScreen.*",
130 },
131 },
132 "WNX-30022": {
133
134
135 InputDevicePatterns: []string{
136 "eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*",
137 },
138 },
139 "WNX-30028": {
140
141
142 InputDevicePatterns: []string{
143 "eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*",
144 },
145 },
146 "WNX-32": {
147
148 InputDevicePatterns: []string{
149 "Beijing IRTOUCH SYSTEMS Co\\.,LtD IRTOUCH InfraRed TouchScreen.*",
150 },
151 },
152 },
153 DPMS: &DPMS{
154 Enabled: &dpmsDisabled,
155 BlankTime: &zeroSeconds,
156 StandbyTime: &zeroSeconds,
157 SuspendTime: &zeroSeconds,
158 OffTime: &zeroSeconds,
159 },
160 }
161
162
163
164
165
166
167
168
169
170
171
172
173 func (a *DisplayConfig) GenerateDefaultDisplayConfig(defaults DefaultConfig, inputDevices []InputDeviceName) (*DisplayConfig, error) {
174 result := a.DeepCopy()
175
176 if err := applyDefaultDisplay(result, defaults.Display); err != nil {
177 return nil, err
178 }
179
180 applyKnownDisplays(result, inputDevices, defaults)
181
182 applyDefaultPrimary(result)
183
184 result.DPMS = defaults.DPMS
185
186 return result, nil
187 }
188
189 func applyDefaultDisplay(displayConfig *DisplayConfig, defaultDisplay Display) error {
190 for dp, display := range displayConfig.Displays {
191 display, err := display.Merge(defaultDisplay)
192 if err != nil {
193 return err
194 }
195 displayConfig.Displays[dp] = *display
196 }
197 return nil
198 }
199
200 func applyKnownDisplays(displayConfig *DisplayConfig, inputDevices []InputDeviceName, defaults DefaultConfig) {
201 for mpid, defaultDisplay := range defaults.KnownDisplays {
202 regexps := compileRegexStrings(defaultDisplay.InputDevicePatterns)
203 for idx, display := range displayConfig.Displays {
204 if display.MPID != nil && *display.MPID == mpid {
205 display.InputDeviceMappings = matchInputsToDefaultDevicesRegex(inputDevices, regexps)
206 displayConfig.Displays[idx] = display
207 }
208 }
209 }
210 }
211
212 func compileRegexStrings(regexStrings []string) []*regexp.Regexp {
213 regexps := []*regexp.Regexp{}
214 for _, pattern := range regexStrings {
215 r, _ := regexp.Compile(pattern)
216 regexps = append(regexps, r)
217 }
218 return regexps
219 }
220
221 func matchInputsToDefaultDevicesRegex(inputDevices []InputDeviceName, defaultDevicesRegexps []*regexp.Regexp) []InputDeviceName {
222 matchedDevices := []InputDeviceName{}
223 for _, r := range defaultDevicesRegexps {
224 for _, inputDevice := range inputDevices {
225 if r.MatchString(string(inputDevice)) {
226 matchedDevices = append(matchedDevices, inputDevice)
227 }
228 }
229 }
230 return matchedDevices
231 }
232
233 func applyDefaultPrimary(displayConfig *DisplayConfig) {
234 if len(displayConfig.Displays) == 0 {
235 return
236 }
237
238 primary := displayConfig.Displays[0].DisplayPort
239 if len(displayConfig.Layout) > 0 {
240 primary = displayConfig.Layout[0]
241 }
242
243 displayConfig.Displays = setPrimaryDisplay(primary, displayConfig.Displays)
244 }
245
246 func setPrimaryDisplay(primary DisplayPort, displays Displays) Displays {
247 for idx, display := range displays {
248 display.SetPrimary(display.DisplayPort == primary)
249 displays[idx] = display
250 }
251 return displays
252 }
253
View as plain text