From b1f72fe65fc40f3041da20ad68b44f1c1d47082e Mon Sep 17 00:00:00 2001 From: milarin Date: Fri, 5 Jan 2024 18:20:29 +0100 Subject: [PATCH] initial commit --- .gitignore | 1 + get_monitors.go | 30 ++++++++++++++++++++++++++++++ go.mod | 3 +++ monitor.go | 31 +++++++++++++++++++++++++++++++ workspace.go | 19 +++++++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 .gitignore create mode 100644 get_monitors.go create mode 100644 go.mod create mode 100644 monitor.go create mode 100644 workspace.go 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) +}