refactor
This commit is contained in:
parent
b1f72fe65f
commit
726c07b87a
30
get_clients.go
Normal file
30
get_clients.go
Normal 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
30
get_workspaces.go
Normal 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
|
||||
}
|
40
monitor.go
40
monitor.go
@ -3,26 +3,26 @@ package hypr
|
||||
import "encoding/json"
|
||||
|
||||
type Monitor struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Make string `json:"make"`
|
||||
Model string `json:"model"`
|
||||
Serial string `json:"serial"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
RefreshRate float64 `json:"refreshRate"`
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
ActiveWorkspace *Workspace `json:"activeWorkspace"`
|
||||
SpecialWorkspace *Workspace `json:"specialWorkspace"`
|
||||
Reserved [4]int `json:"reserved"`
|
||||
Scale float64 `json:"scale"`
|
||||
Transform int `json:"transform"`
|
||||
Focused bool `json:"focused"`
|
||||
DPMSStatus bool `json:"dpmsStatus"`
|
||||
VRR bool `json:"vrr"`
|
||||
ActivelyTearing bool `json:"activelyTearing"`
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
Description string `json:"description"`
|
||||
Make string `json:"make"`
|
||||
Model string `json:"model"`
|
||||
Serial string `json:"serial"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
RefreshRate float64 `json:"refreshRate"`
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
ActiveWorkspace WorkspaceIdent `json:"activeWorkspace"`
|
||||
SpecialWorkspace WorkspaceIdent `json:"specialWorkspace"`
|
||||
Reserved [4]int `json:"reserved"`
|
||||
Scale float64 `json:"scale"`
|
||||
Transform int `json:"transform"`
|
||||
Focused bool `json:"focused"`
|
||||
DPMSStatus bool `json:"dpmsStatus"`
|
||||
VRR bool `json:"vrr"`
|
||||
ActivelyTearing bool `json:"activelyTearing"`
|
||||
}
|
||||
|
||||
func (m Monitor) String() string {
|
||||
|
32
window.go
Normal file
32
window.go
Normal 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)
|
||||
}
|
@ -2,6 +2,11 @@ package hypr
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
type WorkspaceIdent struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type Workspace struct {
|
||||
ID int `json:"id"`
|
||||
Name string `json:"name"`
|
||||
|
Loading…
Reference in New Issue
Block a user