summaryrefslogtreecommitdiff
path: root/bspc
diff options
context:
space:
mode:
authorhhvn <dev@hhvn.uk>2023-08-14 14:04:41 +0100
committerhhvn <dev@hhvn.uk>2023-08-14 14:47:38 +0100
commit79a80fbbf278e0eb743a79e2c0c252817537434f (patch)
tree7704e968ec2071a931140b43f6ec2ea61ed1d527 /bspc
parent0543020038edb5de1162863e7401ea36f8a8584c (diff)
Creating and destroying the windows
Diffstat (limited to 'bspc')
-rw-r--r--bspc/bspc.go61
1 files changed, 44 insertions, 17 deletions
diff --git a/bspc/bspc.go b/bspc/bspc.go
index f3b7ff3..f88d839 100644
--- a/bspc/bspc.go
+++ b/bspc/bspc.go
@@ -1,6 +1,7 @@
package bspc
import (
+ "fmt"
"io"
"bufio"
"strings"
@@ -14,17 +15,48 @@ type State struct {
Monitors []*Monitor
}
+func (s *State) GetMon(id int) (*Monitor) {
+ for _, m := range s.Monitors {
+ if m.ID == id {
+ return m
+ }
+ }
+
+ return nil
+}
+
type Monitor struct {
ID int
Rectangle *Rect
Desktops []*Desktop
}
+func (m *Monitor) TopPadding(px uint) {
+ cmd := exec.Command("bspc", "config",
+ "-m", fmt.Sprintf("%d", m.ID),
+ "top_padding", fmt.Sprintf("%d", px))
+
+ pipe, _ := cmd.StderrPipe()
+ scan := bufio.NewScanner(pipe)
+
+ cmd.Start()
+
+ for scan.Scan() {
+ common.Error("%s\n", scan.Text())
+ }
+
+ if err := scan.Err(); err != nil {
+ common.Perror("scan.Err", err)
+ }
+
+ cmd.Wait()
+}
+
type Rect struct {
- X int
- Y int
- Width int
- Height int
+ X uint
+ Y uint
+ Width uint
+ Height uint
}
type Desktop struct {
@@ -95,25 +127,20 @@ func Subscribe() (*Subscriber, error) {
s.pipe = pipe
s.scanner = bufio.NewScanner(s.pipe)
- go func() {
- for {
- select {
- case <- s.cleanup:
- s.cmd.Wait()
- return
- default:
- if event := s.get(); event != nil {
- s.Event <- event
- }
+ go func() { for {
+ select {
+ default:
+ if event := s.get(); event != nil {
+ s.Event <- event
}
}
- }()
+ }}()
return &s, nil
}
func (s *Subscriber) Close() {
- s.cleanup <- true
+ s.cmd.Process.Kill()
}
func (s *Subscriber) getLine() (string, error) {
@@ -133,7 +160,7 @@ func (s *Subscriber) get() (*Event) {
var err error
for {
line, err = s.getLine()
- if line[0] != 'W' { break }
+ if len(line) > 0 && line[0] != 'W' { break }
}
if line == "" { return nil }