-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesktop.go
43 lines (34 loc) · 804 Bytes
/
desktop.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
package bspc
import (
"bytes"
"fmt"
"os/exec"
)
type Desktop struct {
Name string
Windows []*Window
}
func NewDesktop(name string, monitor *Monitor) *Desktop {
desktop := &Desktop{Name: name}
return desktop
}
func (d *Desktop) Remove() {
exec.Command(d.getSelector(), "--remove").Run()
}
func (d *Desktop) getSelector() string {
return fmt.Sprintf("%s desktop %s", CommandName, d.Name)
}
func (d *Desktop) loadWindows() error {
out, err := exec.Command(CommandName, "query", "--desktop", d.Name, "--windows").Output()
if err != nil {
return err
}
names := bytes.Split(out, []byte("\n"))
// Last entry is blank
windows := make([]*Window, len(names)-1)
for i, name := range names[:len(names)-1] {
windows[i] = &Window{ID: string(name)}
}
d.Windows = windows
return nil
}