2024-01-05 18:42:16 +01:00
|
|
|
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
|
|
|
|
}
|
2024-01-05 23:14:56 +01:00
|
|
|
|
|
|
|
func GetActiveWorkspace() (*Workspace, error) {
|
|
|
|
cmd := exec.Command("hyprctl", "-j", "activeworkspace")
|
|
|
|
|
|
|
|
stdout, err := cmd.StdoutPipe()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cmd.Start(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
workspace := &Workspace{}
|
|
|
|
if err := json.NewDecoder(stdout).Decode(workspace); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := cmd.Wait(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return workspace, nil
|
|
|
|
}
|