-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
executable file
·62 lines (52 loc) · 1.12 KB
/
main.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
package main
import (
"encoding/json"
"github.com/labi-le/hyprland-ipc-client/v3"
"log"
"os"
)
type Output struct {
Text string `json:"text"`
Tooltip string `json:"tooltip"`
Class string `json:"class"`
}
func ToStdOut(s any) {
if err := json.NewEncoder(os.Stdout).Encode(s); err != nil {
log.Fatal(err)
}
}
type ed struct {
client.DummyEvHandler
}
func ReadFirstLayout(ipc client.IPC, evDispatcher client.EventHandler) {
devices, err := ipc.Devices()
if err != nil {
log.Fatal(err)
}
for _, device := range devices.Keyboards {
if device.Main {
evDispatcher.ActiveLayout(client.ActiveLayout{
Type: "keyboard",
Name: device.ActiveKeymap,
})
break
}
}
}
func main() {
var (
ipc = client.MustClient(os.Getenv("HYPRLAND_INSTANCE_SIGNATURE"))
evDispatcher = &ed{}
)
ReadFirstLayout(ipc, evDispatcher)
if err := client.Subscribe(ipc, evDispatcher, client.EventActiveLayout); err != nil {
log.Fatal(err)
}
}
func (e *ed) ActiveLayout(layout client.ActiveLayout) {
ToStdOut(Output{
Text: layout.Name,
Tooltip: "Current keyboard layout",
Class: "keyboard-layout",
})
}