hbspbar

[WIP] bspwm status bar
git clone https://hhvn.uk/hbspbar
git clone git://hhvn.uk/hbspbar
Log | Files | Refs

commit e6a5202d0c75bc2ee744a76b73147726e91ee732
parent f63b94d614026e21bf6246440b9bda1f85197fbc
Author: hhvn <dev@hhvn.uk>
Date:   Sat, 27 Jan 2024 16:43:55 +0000

Reorganize bspc/bspc.go

Diffstat:
Mbspc/bspc.go | 106++++++++++++++++++++++++++++++++++++++++----------------------------------------
1 file changed, 53 insertions(+), 53 deletions(-)

diff --git a/bspc/bspc.go b/bspc/bspc.go @@ -85,31 +85,6 @@ var reloadEvents = []string{ "node_swap", "node_transfer" } -var cmdlist []*exec.Cmd -var cmdlock sync.Mutex - -func cmdRegister(c *exec.Cmd) int { - cmdlock.Lock() - defer cmdlock.Unlock() - - for i, v := range cmdlist { - if v == nil { - cmdlist[i] = c - return i - } - } - - cmdlist = append(cmdlist, c) - i := len(cmdlist) - 1 - return i -} - -func cmdDelete(i int) { - cmdlock.Lock() - defer cmdlock.Unlock() - cmdlist[i] = nil -} - func getState() (*State, error) { cmd := exec.Command("bspc", "wm", "-d") @@ -208,6 +183,59 @@ func init() { }}() } +func getLine(s *bufio.Scanner) (string, error) { + if s.Scan() { + return s.Text(), nil + } + + if err := s.Err(); err != nil { + return "", common.Perror("scanner.Err", err) + } + + return "", nil +} + +func get(s *bufio.Scanner) (*event, error) { + var line string + var err error + for { + line, err = getLine(s) + if len(line) > 0 && line[0] != 'W' { break } + } + + if line == "" { return nil, nil } + if err != nil { return nil, err } + + name, tokens, _ := strings.Cut(line, " ") + + return &event{name, strings.Split(tokens, " ")}, nil +} + +var cmdlist []*exec.Cmd +var cmdlock sync.Mutex + +func cmdRegister(c *exec.Cmd) int { + cmdlock.Lock() + defer cmdlock.Unlock() + + for i, v := range cmdlist { + if v == nil { + cmdlist[i] = c + return i + } + } + + cmdlist = append(cmdlist, c) + i := len(cmdlist) - 1 + return i +} + +func cmdDelete(i int) { + cmdlock.Lock() + defer cmdlock.Unlock() + cmdlist[i] = nil +} + func Cmd(args ...string) { cmd := exec.Command("bspc", args...) @@ -238,31 +266,3 @@ func Cleanup() { } } } - -func getLine(s *bufio.Scanner) (string, error) { - if s.Scan() { - return s.Text(), nil - } - - if err := s.Err(); err != nil { - return "", common.Perror("scanner.Err", err) - } - - return "", nil -} - -func get(s *bufio.Scanner) (*event, error) { - var line string - var err error - for { - line, err = getLine(s) - if len(line) > 0 && line[0] != 'W' { break } - } - - if line == "" { return nil, nil } - if err != nil { return nil, err } - - name, tokens, _ := strings.Cut(line, " ") - - return &event{name, strings.Split(tokens, " ")}, nil -}