commit b1f72fe65fc40f3041da20ad68b44f1c1d47082e Author: milarin Date: Fri Jan 5 18:20:29 2024 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b97602b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*_test.go \ No newline at end of file diff --git a/get_monitors.go b/get_monitors.go new file mode 100644 index 0000000..43c81f8 --- /dev/null +++ b/get_monitors.go @@ -0,0 +1,30 @@ +package hypr + +import ( + "encoding/json" + "os/exec" +) + +func GetMonitors() ([]*Monitor, error) { + cmd := exec.Command("hyprctl", "-j", "monitors") + + stdout, err := cmd.StdoutPipe() + if err != nil { + return nil, err + } + + if err := cmd.Start(); err != nil { + return nil, err + } + + monitors := make([]*Monitor, 0, 5) + if err := json.NewDecoder(stdout).Decode(&monitors); err != nil { + return nil, err + } + + if err := cmd.Wait(); err != nil { + return nil, err + } + + return monitors, nil +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..5900e77 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.milar.in/milarin/hypr + +go 1.21.5 diff --git a/monitor.go b/monitor.go new file mode 100644 index 0000000..d9d645f --- /dev/null +++ b/monitor.go @@ -0,0 +1,31 @@ +package hypr + +import "encoding/json" + +type Monitor struct { + ID int `json:"id"` + Name string `json:"name"` + Description string `json:"description"` + Make string `json:"make"` + Model string `json:"model"` + Serial string `json:"serial"` + Width int `json:"width"` + Height int `json:"height"` + RefreshRate float64 `json:"refreshRate"` + X int `json:"x"` + Y int `json:"y"` + ActiveWorkspace *Workspace `json:"activeWorkspace"` + SpecialWorkspace *Workspace `json:"specialWorkspace"` + Reserved [4]int `json:"reserved"` + Scale float64 `json:"scale"` + Transform int `json:"transform"` + Focused bool `json:"focused"` + DPMSStatus bool `json:"dpmsStatus"` + VRR bool `json:"vrr"` + ActivelyTearing bool `json:"activelyTearing"` +} + +func (m Monitor) String() string { + data, _ := json.MarshalIndent(m, "", "\t") + return string(data) +} diff --git a/workspace.go b/workspace.go new file mode 100644 index 0000000..25c1f7b --- /dev/null +++ b/workspace.go @@ -0,0 +1,19 @@ +package hypr + +import "encoding/json" + +type Workspace struct { + ID int `json:"id"` + Name string `json:"name"` + Monitor string `json:"monitor"` + MonitorID int `json:"monitorID"` + Windows int `json:"windows"` + HasFullscreen bool `json:"hasfullscreen"` + LastWindow string `json:"lastwindow"` + LastWindowTitle string `json:"lastwindowtitle"` +} + +func (w Workspace) String() string { + data, _ := json.MarshalIndent(w, "", "\t") + return string(data) +}