88 lines
2.4 KiB
Go
88 lines
2.4 KiB
Go
package niri
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
)
|
|
|
|
type OutputActionRequest struct {
|
|
Output OutputName `json:"output"`
|
|
Action OutputAction `json:"action"`
|
|
}
|
|
|
|
type outputActionResponse struct {
|
|
OutputConfigChanged string `json:"OutputConfigChanged"`
|
|
}
|
|
|
|
type OutputAction struct {
|
|
off Option[bool]
|
|
on Option[bool]
|
|
mode Option[ModeToSet]
|
|
scale Option[ScaleToSet]
|
|
transform Option[OutputTransform]
|
|
position Option[PositionToSet]
|
|
vrr Option[ConfiguredVrr]
|
|
}
|
|
|
|
func OutputActionOff(output string) OutputActionRequest {
|
|
return OutputActionRequest{
|
|
Output: OutputName(output),
|
|
Action: OutputAction{off: OptionOf(true)},
|
|
}
|
|
}
|
|
|
|
func OutputActionOn(output string) OutputActionRequest {
|
|
return OutputActionRequest{
|
|
Output: OutputName(output),
|
|
Action: OutputAction{on: OptionOf(true)},
|
|
}
|
|
}
|
|
|
|
func OutputActionMode(output string, mode ModeToSet) OutputActionRequest {
|
|
return OutputActionRequest{
|
|
Output: OutputName(output),
|
|
Action: OutputAction{mode: OptionOf(mode)},
|
|
}
|
|
}
|
|
|
|
func OutputActionScale(output string, scale ScaleToSet) OutputActionRequest {
|
|
return OutputActionRequest{
|
|
Output: OutputName(output),
|
|
Action: OutputAction{scale: OptionOf(scale)},
|
|
}
|
|
}
|
|
|
|
func OutputActionTransform(output string, transform OutputTransform) OutputActionRequest {
|
|
return OutputActionRequest{
|
|
Output: OutputName(output),
|
|
Action: OutputAction{transform: OptionOf(transform)},
|
|
}
|
|
}
|
|
|
|
func OutputActionVrr(output string, vrr ConfiguredVrr) OutputActionRequest {
|
|
return OutputActionRequest{
|
|
Output: OutputName(output),
|
|
Action: OutputAction{vrr: OptionOf(vrr)},
|
|
}
|
|
}
|
|
|
|
func (m OutputAction) MarshalJSON() ([]byte, error) {
|
|
if m.off != nil {
|
|
return json.Marshal("Off")
|
|
} else if m.on != nil {
|
|
return json.Marshal("On")
|
|
} else if m.mode != nil {
|
|
return json.Marshal(map[string]map[string]ModeToSet{"Mode": {"mode": *m.mode}})
|
|
} else if m.scale != nil {
|
|
return json.Marshal(map[string]map[string]ScaleToSet{"Scale": {"scale": *m.scale}})
|
|
} else if m.transform != nil {
|
|
return json.Marshal(map[string]map[string]OutputTransform{"Transform": {"transform": *m.transform}})
|
|
} else if m.position != nil {
|
|
return json.Marshal(map[string]map[string]PositionToSet{"Position": {"position": *m.position}})
|
|
} else if m.vrr != nil {
|
|
return json.Marshal(map[string]map[string]ConfiguredVrr{"Vrr": {"vrr": *m.vrr}})
|
|
}
|
|
|
|
return nil, errors.New("OutputAction.MarshalJson()")
|
|
}
|