-
Notifications
You must be signed in to change notification settings - Fork 0
/
hyprland.go
50 lines (38 loc) · 915 Bytes
/
hyprland.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
package main
import (
"bufio"
"bytes"
"fmt"
"log"
"os/exec"
"strings"
)
type Hyprland struct{}
func (h Hyprland) Identifier() string {
return "hyprland"
}
func (h Hyprland) Entries() []Entry {
cmd := exec.Command("hyprctl", "clients")
out, err := cmd.Output()
if err != nil {
log.Println(err)
}
entries := []Entry{}
scanner := bufio.NewScanner(bytes.NewReader(out))
for scanner.Scan() {
line := strings.TrimSpace(scanner.Text())
if strings.HasPrefix(scanner.Text(), "Window ") {
entries = append(entries, Entry{})
continue
}
if strings.HasPrefix(line, "title:") {
entries[len(entries)-1].Name = fmt.Sprintf("Window: %s", strings.TrimPrefix(line, "title: "))
continue
}
if strings.HasPrefix(line, "pid:") {
entries[len(entries)-1].Exec = fmt.Sprintf("hyprctl dispatch focuswindow pid:%s", strings.TrimPrefix(line, "pid: "))
continue
}
}
return entries
}