2024-01-05 18:42:16 +01:00
|
|
|
package hypr
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"os/exec"
|
2024-01-08 12:50:11 +01:00
|
|
|
|
|
|
|
"git.milar.in/milarin/slices"
|
2024-01-05 18:42:16 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2024-01-08 12:50:11 +01:00
|
|
|
windows = slices.Filter(windows, func(w *Window) bool {
|
|
|
|
return w.PID != -1
|
|
|
|
})
|
|
|
|
|
2024-01-05 18:42:16 +01:00
|
|
|
return windows, nil
|
|
|
|
}
|