...
1 package v1
2
3 import (
4 "fmt"
5
6 "edge-infra.dev/pkg/sds/lib/set"
7 )
8
9
10
11
12
13 type MPID string
14
15 func (mpid *MPID) String() string {
16 if mpid == nil {
17 return ""
18 }
19 return string(*mpid)
20 }
21
22
23 type DisplayConfig struct {
24
25 Displays `json:"displays,omitempty"`
26
27 DPMS *DPMS `json:"dpms,omitempty"`
28
29 Layout `json:"layout,omitempty"`
30 }
31
32 func (displayConfig *DisplayConfig) MPIDs() []MPID {
33 if displayConfig == nil {
34 return []MPID{}
35 }
36 mpids := set.OrderedFromMap(displayConfig.Displays)
37 mpids.Add(displayConfig.Layout...)
38 return mpids.ToSlice()
39 }
40
41 type Displays map[MPID]Display
42
43
44 func (displays Displays) MPIDs() []MPID {
45 if displays == nil {
46 return []MPID{}
47 }
48 mpids := set.OrderedFromMap(displays)
49 return mpids.ToSlice()
50 }
51
52
53 type Display struct {
54
55 *Primary `json:"primary,omitempty"`
56
57 Orientation *Orientation `json:"orientation,omitempty"`
58
59 *Resolution `json:"resolution,omitempty"`
60
61
62
63
64
65
66 SupportedResolutions []Resolution `json:"supportedResolutions,omitempty"`
67
68 InputDeviceMappings []InputDeviceName `json:"inputDeviceMappings,omitempty"`
69 }
70
71
72 type Primary bool
73
74 func (display *Display) IsPrimary() bool {
75 if display.Primary == nil {
76 return false
77 }
78 return bool(*display.Primary)
79 }
80
81 func (display *Display) SetPrimary(primary bool) {
82 display.Primary = (*Primary)(&primary)
83 }
84
85
86
87
88 type Orientation string
89
90 var (
91 NormalOrientation Orientation = "normal"
92 LeftOrientation Orientation = "left"
93 RightOrientation Orientation = "right"
94 InvertedOrientation Orientation = "inverted"
95 )
96
97 func (o *Orientation) String() string {
98 if o == nil {
99 return ""
100 }
101 return string(*o)
102 }
103
104
105 type Resolution struct {
106
107
108
109 Width int `json:"width"`
110
111
112
113 Height int `json:"height"`
114 }
115
116 func (res *Resolution) String() string {
117 if res == nil {
118 return ""
119 }
120 return fmt.Sprintf("%dx%d", res.Width, res.Height)
121 }
122
123
124 type InputDeviceName string
125
126 func (name *InputDeviceName) String() string {
127 if name == nil {
128 return ""
129 }
130 return string(*name)
131 }
132
133
134 type DPMS struct {
135
136 Enabled *bool `json:"enabled,omitempty"`
137
138
139
140
141 BlankTime *int `json:"blankTime,omitempty"`
142
143
144
145
146 StandbyTime *int `json:"standByTime,omitempty"`
147
148
149
150
151 SuspendTime *int `json:"suspendTime,omitempty"`
152
153
154
155
156 OffTime *int `json:"offTime,omitempty"`
157 }
158
159
160
161 type Layout []MPID
162
View as plain text