diff options
Diffstat (limited to 'bspc')
| -rw-r--r-- | bspc/bspc.go | 61 |
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 } |