This commit is contained in:
milarin 2024-01-05 18:42:16 +01:00
parent b1f72fe65f
commit 726c07b87a
5 changed files with 117 additions and 20 deletions

30
get_clients.go Normal file
View File

@ -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
}

30
get_workspaces.go Normal file
View File

@ -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
}

View File

@ -3,26 +3,26 @@ package hypr
import "encoding/json" import "encoding/json"
type Monitor struct { type Monitor struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"` Description string `json:"description"`
Make string `json:"make"` Make string `json:"make"`
Model string `json:"model"` Model string `json:"model"`
Serial string `json:"serial"` Serial string `json:"serial"`
Width int `json:"width"` Width int `json:"width"`
Height int `json:"height"` Height int `json:"height"`
RefreshRate float64 `json:"refreshRate"` RefreshRate float64 `json:"refreshRate"`
X int `json:"x"` X int `json:"x"`
Y int `json:"y"` Y int `json:"y"`
ActiveWorkspace *Workspace `json:"activeWorkspace"` ActiveWorkspace WorkspaceIdent `json:"activeWorkspace"`
SpecialWorkspace *Workspace `json:"specialWorkspace"` SpecialWorkspace WorkspaceIdent `json:"specialWorkspace"`
Reserved [4]int `json:"reserved"` Reserved [4]int `json:"reserved"`
Scale float64 `json:"scale"` Scale float64 `json:"scale"`
Transform int `json:"transform"` Transform int `json:"transform"`
Focused bool `json:"focused"` Focused bool `json:"focused"`
DPMSStatus bool `json:"dpmsStatus"` DPMSStatus bool `json:"dpmsStatus"`
VRR bool `json:"vrr"` VRR bool `json:"vrr"`
ActivelyTearing bool `json:"activelyTearing"` ActivelyTearing bool `json:"activelyTearing"`
} }
func (m Monitor) String() string { func (m Monitor) String() string {

32
window.go Normal file
View File

@ -0,0 +1,32 @@
package hypr
import "encoding/json"
type Window struct {
Address string `json:"address"`
Mapped bool `json:"mapped"`
Hidden bool `json:"hidden"`
At [2]int `json:"at"`
Size [2]int `json:"size"`
Workspace WorkspaceIdent `json:"workspace"`
Floating bool `json:"floating"`
MonitorID int `json:"monitor"`
Class string `json:"class"`
Title string `json:"title"`
InitialClass string `json:"initialClass"`
InitialTitle string `json:"initialTitle"`
PID int `json:"pid"`
Xwayland bool `json:"xwayland"`
Pinned bool `json:"pinned"`
Fullscreen bool `json:"fullscreen"`
FullscreenMode int `json:"fullscreenMode"`
FakeFullscreen bool `json:"fakeFullscreen"`
Grouped []interface{} `json:"grouped"` // TODO
Swallowing string `json:"swallowing"`
FocusHistoryID int `json:"focusHistoryID"`
}
func (w Window) String() string {
data, _ := json.MarshalIndent(w, "", "\t")
return string(data)
}

View File

@ -2,6 +2,11 @@ package hypr
import "encoding/json" import "encoding/json"
type WorkspaceIdent struct {
ID int `json:"id"`
Name string `json:"name"`
}
type Workspace struct { type Workspace struct {
ID int `json:"id"` ID int `json:"id"`
Name string `json:"name"` Name string `json:"name"`