Files
niri/model_window_layout_change.go

37 lines
795 B
Go

package niri
import (
"encoding/json"
"fmt"
)
type WindowLayoutChange struct {
WindowID WindowID
WindowLayout WindowLayout
}
func (m *WindowLayoutChange) UnmarshalJSON(data []byte) error {
arr := []any{}
if err := json.Unmarshal(data, &arr); err != nil {
return err
}
if len(arr) != 2 {
return fmt.Errorf("expected array of length 2 but got array of length %d", len(arr))
}
if wid, ok := arr[0].(float64); !ok {
return fmt.Errorf("expected array element at index 0 to be of type int")
} else {
m.WindowID = WindowID(wid)
}
if windowLayout, err := reencodeJson[WindowLayout](arr[1]); err != nil {
return fmt.Errorf("expected array element at index 1 to be of type WindowLayout")
} else if windowLayout != nil {
m.WindowLayout = *windowLayout
}
return nil
}