package v2 import ( "regexp" ) var ( dpmsDisabled = false zeroSeconds = 0 ) // Configures the default display configuration to be passed // into displayConfig.GenerateDefaultDisplayConfig(DefaultConfig,inputDevices). type DefaultConfig struct { // The default display configuration that will be applied // to each display. Display Display // Mapping of pre-defined display configurations for displays // we know need additional configuration. Most often this // consists of known input device mappings. KnownDisplays map[MPID]KnownDisplayDefaults // The default DPMS configuration. DPMS *DPMS } type KnownDisplayDefaults struct { InputDevicePatterns []string } // The default display configuration: // - All displays have normal orientation. // - Known display input device mapping regex strings are configured (known device details listed in comments). // - DPMS is disabled. var Defaults = DefaultConfig{ Display: Display{ Orientation: &NormalOrientation, }, KnownDisplays: map[MPID]KnownDisplayDefaults{ "ACR-2199": { // Weida Hi-Tech CoolTouchR System // Weida Hi-Tech CoolTouchR System Mouse InputDevicePatterns: []string{ "Weida Hi-Tech\\s+CoolTouchR System\\s+.*", }, }, "ELO-4098": { // Elo Touch Solutions Elo Touch Solutions Pcap USB Interface InputDevicePatterns: []string{ "Elo Touch Solutions Elo Touch Solutions Pcap USB Interface", }, }, "ELO-5705": { // Atmel Atmel maXTouch Digitizer // Elo TouchSystems, Inc. Elo TouchSystems 2700 IntelliTouch(r) USB InputDevicePatterns: []string{ "Atmel Atmel maXTouch Digitizer", "Elo TouchSystems, Inc\\. Elo TouchSystems 2700.*", }, }, "ELO-5911": { // Elo TouchSystems, Inc. Elo TouchSystems 2700 IntelliTouch(r) USB Touchmonitor Interface InputDevicePatterns: []string{ "Elo TouchSystems, Inc\\. Elo TouchSystems 2700.*", }, }, "ELO-8816": { // Elo Touch 2270L pCAP HID // Elo Touch 2270L pCAP HID Mouse InputDevicePatterns: []string{ "Elo Touch\\s+2270L pCAP HID\\s+.*", }, }, "NCR-22800": { // eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00 // eGalax Inc. eGalaxTouch EXC3160-3079-08.00.00 UNKNOWN InputDevicePatterns: []string{ "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*", }, }, "NCR-22805": { // eGalax Inc. eGalaxTouch EXC3188-0556-04.00.00 InputDevicePatterns: []string{ "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*", }, }, "NCR-22888": { // eGalax Inc. eGalaxTouch EXC3189-2506-09.00.00.00 // eGalax Inc. eGalaxTouch EXC3189-2506-09.00.00.00 Mouse // Advanced Silicon S.A. CoolTouch® System InputDevicePatterns: []string{ "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*", "Advanced Silicon S\\.A\\. CoolTouch® System", }, }, "NCR-22917": { // eGalax Inc. eGalaxTouch EXC3188-0556-04.00.00 InputDevicePatterns: []string{ "eGalax Inc\\. eGalaxTouch EXC[A-Z0-9]{4}-.*", }, }, // CX7ii "NCR-30578": { // eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 // eGalax Inc. eGalaxTouch P80H84 0490 v00_test2 k4.02.146 Mouse // eGalax Inc. eGalaxTouch P81X84 A0U4 v00_T3 k4.26.145 // eGalax Inc. eGalaxTouch P81X84 A0U4 v00_T3 k4.26.145 Mouse // eGalax Inc. eGalaxTouch P81X84 A0RF v00_T1 k4.18.204 // eGalax Inc. eGalaxTouch P81X84 A0RF v00_T1 k4.18.204 Mouse InputDevicePatterns: []string{ "eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*", }, }, "TGC-18464": { // Elo TouchSystems Inc. Elo TouchSystems CarrollTouch 4500U InputDevicePatterns: []string{ "Elo TouchSystems Inc\\. Elo TouchSystems CarrollTouch.*", }, }, "VSC-23866": { // iSolution multitouch // iSolution multitouch Mouse InputDevicePatterns: []string{ "iSolution multitouch.*", }, }, "WNX-22": { // Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse InputDevicePatterns: []string{ "Beijing IRTOUCH SYSTEMS Co\\.,LtD IRTOUCH InfraRed TouchScreen.*", }, }, "WNX-30022": { // eGalax Inc. eGalaxTouch P80H84 0716 v00T3 k03_216 // eGalax Inc. eGalaxTouch P80H84 0716 v00T3 k03_216 Mouse InputDevicePatterns: []string{ "eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*", }, }, "WNX-30028": { // eGalax Inc. eGalaxTouch P80H84 0789 v01 k4.10.139 // eGalax Inc. eGalaxTouch P80H84 0789 v01 k4.10.139 UNKNOWN InputDevicePatterns: []string{ "eGalax Inc\\. eGalaxTouch P8[A-Z0-9]{4} [A-Z0-9]{4}.*", }, }, "WNX-32": { // Beijing IRTOUCH SYSTEMS Co.,LtD IRTOUCH InfraRed TouchScreen Mouse InputDevicePatterns: []string{ "Beijing IRTOUCH SYSTEMS Co\\.,LtD IRTOUCH InfraRed TouchScreen.*", }, }, }, DPMS: &DPMS{ Enabled: &dpmsDisabled, BlankTime: &zeroSeconds, StandbyTime: &zeroSeconds, SuspendTime: &zeroSeconds, OffTime: &zeroSeconds, }, } // Applies the default configuration to the display config. // // Merges the default display with each of the displays in the display config. // // For any display where a display with matching MPID exists in the default // known displays, their configurations are merged together. // // Sets the first display in the layout as the primary display. If there is // no layout, the first display will be primary. // // DPMS is overwritten with the default DPMS configuration. func (a *DisplayConfig) GenerateDefaultDisplayConfig(defaults DefaultConfig, inputDevices []InputDeviceName) (*DisplayConfig, error) { result := a.DeepCopy() if err := applyDefaultDisplay(result, defaults.Display); err != nil { return nil, err } applyKnownDisplays(result, inputDevices, defaults) applyDefaultPrimary(result) result.DPMS = defaults.DPMS return result, nil } func applyDefaultDisplay(displayConfig *DisplayConfig, defaultDisplay Display) error { for dp, display := range displayConfig.Displays { display, err := display.Merge(defaultDisplay) if err != nil { return err } displayConfig.Displays[dp] = *display } return nil } func applyKnownDisplays(displayConfig *DisplayConfig, inputDevices []InputDeviceName, defaults DefaultConfig) { for mpid, defaultDisplay := range defaults.KnownDisplays { regexps := compileRegexStrings(defaultDisplay.InputDevicePatterns) for idx, display := range displayConfig.Displays { if display.MPID != nil && *display.MPID == mpid { display.InputDeviceMappings = matchInputsToDefaultDevicesRegex(inputDevices, regexps) displayConfig.Displays[idx] = display } } } } func compileRegexStrings(regexStrings []string) []*regexp.Regexp { regexps := []*regexp.Regexp{} for _, pattern := range regexStrings { r, _ := regexp.Compile(pattern) regexps = append(regexps, r) } return regexps } func matchInputsToDefaultDevicesRegex(inputDevices []InputDeviceName, defaultDevicesRegexps []*regexp.Regexp) []InputDeviceName { matchedDevices := []InputDeviceName{} for _, r := range defaultDevicesRegexps { for _, inputDevice := range inputDevices { if r.MatchString(string(inputDevice)) { matchedDevices = append(matchedDevices, inputDevice) } } } return matchedDevices } func applyDefaultPrimary(displayConfig *DisplayConfig) { if len(displayConfig.Displays) == 0 { return } primary := displayConfig.Displays[0].DisplayPort if len(displayConfig.Layout) > 0 { primary = displayConfig.Layout[0] } displayConfig.Displays = setPrimaryDisplay(primary, displayConfig.Displays) } func setPrimaryDisplay(primary DisplayPort, displays Displays) Displays { for idx, display := range displays { display.SetPrimary(display.DisplayPort == primary) displays[idx] = display } return displays }