package v1 import ( "fmt" "edge-infra.dev/pkg/sds/lib/set" ) // +kubebuilder:validation:Pattern=`^[A-Z]{3}-\d{1,5}$` // // Manufacturer and Product-Code ID, a unique identifier for // the display, i.e. "-". type MPID string func (mpid *MPID) String() string { if mpid == nil { return "" } return string(*mpid) } // DisplayConfig defines the configuration for displays. type DisplayConfig struct { // Maps monitor MPIDs to Display configurations. Displays `json:"displays,omitempty"` // DPMS configuration DPMS *DPMS `json:"dpms,omitempty"` // Layout of the displays as slice, ordered left to right. Layout `json:"layout,omitempty"` } func (displayConfig *DisplayConfig) MPIDs() []MPID { if displayConfig == nil { return []MPID{} } mpids := set.OrderedFromMap(displayConfig.Displays) mpids.Add(displayConfig.Layout...) return mpids.ToSlice() } type Displays map[MPID]Display // Returns the display's MPIDs in sorted order. func (displays Displays) MPIDs() []MPID { if displays == nil { return []MPID{} } mpids := set.OrderedFromMap(displays) return mpids.ToSlice() } // Display configures a display's monitor and input devices. type Display struct { // Primary indicates whether this is the primary display. *Primary `json:"primary,omitempty"` // Orientation of the display, e.g "left" or "inverted". Orientation *Orientation `json:"orientation,omitempty"` // Resolution is the current resolution of the display. *Resolution `json:"resolution,omitempty"` // SupportedResolutions are the valid resolutions the // display can be configured to use. // // It is NOT valid to configure this field in the NodeDisplayConfig // spec. The resolution of the display can be configured // via the Resolution field. SupportedResolutions []Resolution `json:"supportedResolutions,omitempty"` // InputDeviceMappings are the devices the display maps to. InputDeviceMappings []InputDeviceName `json:"inputDeviceMappings,omitempty"` } // Primary indicates whether a display is the primary display. type Primary bool func (display *Display) IsPrimary() bool { if display.Primary == nil { return false } return bool(*display.Primary) } func (display *Display) SetPrimary(primary bool) { display.Primary = (*Primary)(&primary) } // +kubebuilder:validation:Enum=normal;left;right;inverted // // Orientation is the displays orientation, e.g "normal", left", "right" or "inverted". type Orientation string var ( NormalOrientation Orientation = "normal" LeftOrientation Orientation = "left" RightOrientation Orientation = "right" InvertedOrientation Orientation = "inverted" ) func (o *Orientation) String() string { if o == nil { return "" } return string(*o) } // Resolution defines the resolution of a display. type Resolution struct { // +kubebuilder:validation:Minimum=0 // // Width of the display in pixels. Width int `json:"width"` // +kubebuilder:validation:Minimum=0 // // Height of the display in pixels. Height int `json:"height"` } func (res *Resolution) String() string { if res == nil { return "" } return fmt.Sprintf("%dx%d", res.Width, res.Height) } // InputDeviceName is the name of an input device type InputDeviceName string func (name *InputDeviceName) String() string { if name == nil { return "" } return string(*name) } // DPMS describes the DPMS configuration for a display. type DPMS struct { // Enabled indicates whether DPMS is enabled for the node. Enabled *bool `json:"enabled,omitempty"` // +kubebuilder:validation:Minimum=0 // // BlankTime configures the number of seconds of inactivity // before reaching the blank phase of the screen saver. BlankTime *int `json:"blankTime,omitempty"` // +kubebuilder:validation:Minimum=0 // // StandbyTime configures the number of seconds of inactivity // before reaching the standby phase of the DPMS mode. StandbyTime *int `json:"standByTime,omitempty"` // +kubebuilder:validation:Minimum=0 // // SuspendTime configures the number of seconds of inactivity // before reaching the suspend phase of the DPMS mode. SuspendTime *int `json:"suspendTime,omitempty"` // +kubebuilder:validation:Minimum=0 // // OffTime configures the number of seconds of inactivity // before reaching the off phase of the DPMS mode. OffTime *int `json:"offTime,omitempty"` } // Layout describes the physical position of displays as their MPIDs // ordered left to right. type Layout []MPID