31 lines
498 B
Go
31 lines
498 B
Go
|
package hypr
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"os/exec"
|
||
|
)
|
||
|
|
||
|
func GetWorkspaces() ([]*Workspace, error) {
|
||
|
cmd := exec.Command("hyprctl", "-j", "workspaces")
|
||
|
|
||
|
stdout, err := cmd.StdoutPipe()
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
if err := cmd.Start(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
workspaces := make([]*Workspace, 0, 5)
|
||
|
if err := json.NewDecoder(stdout).Decode(&workspaces); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
if err := cmd.Wait(); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
return workspaces, nil
|
||
|
}
|