initial commit

This commit is contained in:
milarin 2024-01-05 18:20:29 +01:00
commit b1f72fe65f
5 changed files with 84 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*_test.go

30
get_monitors.go Normal file
View File

@ -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
}

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module git.milar.in/milarin/hypr
go 1.21.5

31
monitor.go Normal file
View File

@ -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)
}

19
workspace.go Normal file
View File

@ -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)
}