From 1fcd0f5cde8b786c03ef48dbe4fbd350606776ea Mon Sep 17 00:00:00 2001 From: milarin Date: Fri, 5 Jan 2024 23:14:56 +0100 Subject: [PATCH] GetActiveWorkspace implemented --- get_workspaces.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/get_workspaces.go b/get_workspaces.go index 00be2dd..8864f17 100644 --- a/get_workspaces.go +++ b/get_workspaces.go @@ -28,3 +28,27 @@ func GetWorkspaces() ([]*Workspace, error) { return workspaces, nil } + +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 +}