-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
hypr.go
122 lines (110 loc) · 3.1 KB
/
hypr.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package main
import (
"encoding/json"
"fmt"
"net"
)
type workspace struct {
Id int `json:"id"`
Name string `json:"name"`
Monitor string `json:"monitor"`
Windows int `json:"windows"`
Hasfullscreen bool `json:"hasfullscreen"`
Lastwindow string `json:"lastwindow"`
Lastwindowtitle string `json:"lastwindowtitle"`
}
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 struct {
Id int `json:"id"`
Name string `json:"name"`
} `json:"activeWorkspace"`
Reserved []int `json:"reserved"`
Scale float64 `json:"scale"`
Transform int `json:"transform"`
Focused bool `json:"focused"`
DpmsStatus bool `json:"dpmsStatus"`
Vrr bool `json:"vrr"`
}
type client struct {
Address string `json:"address"`
Mapped bool `json:"mapped"`
Hidden bool `json:"hidden"`
At []int `json:"at"`
Size []int `json:"size"`
Workspace struct {
Id int `json:"id"`
Name string `json:"name"`
} `json:"workspace"`
Floating bool `json:"floating"`
Monitor 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 int `json:"fullscreen"`
FullscreenMode int `json:"fullscreenMode"`
FakeFullscreen bool `json:"fakeFullscreen"`
Grouped []interface{} `json:"grouped"`
Swallowing interface{} `json:"swallowing"`
}
func hyprctl(cmd string) ([]byte, error) {
socketFile := fmt.Sprintf("%s/%s/.socket.sock", hyprDir, his)
conn, err := net.Dial("unix", socketFile)
if err != nil {
return nil, err
}
message := []byte(cmd)
_, err = conn.Write(message)
if err != nil {
return nil, err
}
reply := make([]byte, 102400)
n, err := conn.Read(reply)
if err != nil {
return nil, err
}
defer conn.Close()
return reply[:n], nil
}
func listMonitors() error {
reply, err := hyprctl("j/monitors")
if err != nil {
return err
} else {
err = json.Unmarshal([]byte(reply), &monitors)
}
return err
}
func listClients() error {
reply, err := hyprctl("j/clients")
if err != nil {
return err
} else {
err = json.Unmarshal([]byte(reply), &clients)
}
activeClient, _ = getActiveWindow()
return err
}
func getActiveWindow() (*client, error) {
var activeWindow client
reply, err := hyprctl("j/activewindow")
err = json.Unmarshal([]byte(reply), &activeWindow)
if err == nil {
return &activeWindow, nil
}
return nil, err
}