31 lines
484 B
Go
31 lines
484 B
Go
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
|
|
}
|