From 6b31cc8ef522d3a3199ea672a74eeecbed19ca14 Mon Sep 17 00:00:00 2001 From: milarin Date: Fri, 5 Jan 2024 18:42:16 +0100 Subject: [PATCH] refactor --- get_clients.go | 30 ++++++++++++++++++++++++++++++ get_workspaces.go | 30 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 get_clients.go create mode 100644 get_workspaces.go 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 +}