diff --git a/get_clients.go b/get_clients.go new file mode 100644 index 0000000..d26cd12 --- /dev/null +++ b/get_clients.go @@ -0,0 +1,30 @@ +package hypr + +import ( + "encoding/json" + "os/exec" +) + +func GetWindows() ([]*Window, error) { + cmd := exec.Command("hyprctl", "-j", "clients") + + stdout, err := cmd.StdoutPipe() + if err != nil { + return nil, err + } + + if err := cmd.Start(); err != nil { + return nil, err + } + + windows := make([]*Window, 0, 5) + if err := json.NewDecoder(stdout).Decode(&windows); err != nil { + return nil, err + } + + if err := cmd.Wait(); err != nil { + return nil, err + } + + return windows, nil +} diff --git a/get_workspaces.go b/get_workspaces.go new file mode 100644 index 0000000..00be2dd --- /dev/null +++ b/get_workspaces.go @@ -0,0 +1,30 @@ +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 +}