From 88813833507ba26ef27e454616b286e1cfb22584 Mon Sep 17 00:00:00 2001 From: a Date: Sun, 25 Dec 2022 20:18:39 -0600 Subject: [PATCH] a mess --- Makefile | 5 ++++ cmd/bspc/cli.go | 57 ++++++++++++++++++++++++++++++++++++++++++ cmd/bspc/main.go | 23 +++++++++++++++++ go.mod | 20 +++++++++++++++ go.sum | 27 ++++++++++++++++++++ src/bspc/domains.go | 17 +++++++++++++ src/cmd/cmd.go | 12 +++++++++ src/sock/sock.go | 61 +++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 222 insertions(+) create mode 100644 Makefile create mode 100644 cmd/bspc/cli.go create mode 100644 cmd/bspc/main.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 src/bspc/domains.go create mode 100644 src/cmd/cmd.go create mode 100644 src/sock/sock.go diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..8596972 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +WINDOWSIZE=1024:768 + + +xephyr: + Xephyr -br ac -noreset ${WINDOWSIZE} :1 diff --git a/cmd/bspc/cli.go b/cmd/bspc/cli.go new file mode 100644 index 0000000..cb01b10 --- /dev/null +++ b/cmd/bspc/cli.go @@ -0,0 +1,57 @@ +package main + +import "tuxpa.in/t/wm/src/cmd" + +type Api struct { + Node Node `name:"node" cmd:"node"` + Desktop Desktop `name:"desktop" cmd:"desktop"` +} + +type NodeSel string +type Node struct { + NODE_SEL NodeSel `name:"NODE_SEL" arg:"" default:"focused" optional:"" help:"default is focused"` + Focus NodeFocus `name:"focus" cmd:"focus"` + // Activate NodeSel `name:"activate" cmd:"activate"` + // ToDesktop NodeSel `name:"to-desktop" cmd:"to-desktop"` +} + +type NodeFocus struct { +} + +func (n *NodeFocus) Run(ctx *cmd.Context) error { + panic("not implemented") // TODO: Implement +} + +func (n *Node) Run(ctx *cmd.Context) error { + panic("not implemented") // TODO: Implement +} + +type Desktop struct { + DESKTOP_SEL string `name:"DESKTOP_SEL"` +} + +func (d *Desktop) Run(ctx *cmd.Context) error { + panic("not implemented") // TODO: Implement +} + +type Monitor struct { + MONITOR_SEL string `name:"MONITOR_SEL"` +} + +type Query struct { +} + +type Wm struct { +} + +type Rule struct { +} + +type Config struct { +} + +type Subscribe struct { +} + +type Quit struct { +} diff --git a/cmd/bspc/main.go b/cmd/bspc/main.go new file mode 100644 index 0000000..43fcd98 --- /dev/null +++ b/cmd/bspc/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "fmt" + "os" + + "tuxpa.in/t/wm/src/sock" +) + +func main() { + s, err := sock.Default() + errExit(err) + resp, err := s.Send(os.Args[1:]...) + errExit(err) + fmt.Print(resp) +} + +func errExit(err error) { + if err != nil { + fmt.Printf(err.Error()) + os.Exit(1) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..0739552 --- /dev/null +++ b/go.mod @@ -0,0 +1,20 @@ +module tuxpa.in/t/wm + +go 1.19 + +require github.com/alecthomas/kong v0.7.1 + +require github.com/jezek/xgb v1.1.0 // indirect + +require ( + github.com/google/uuid v1.3.0 // indirect + github.com/mattn/go-isatty v0.0.16 // indirect + github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect + golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect + modernc.org/libc v1.21.2 // indirect + modernc.org/mathutil v1.5.0 // indirect + modernc.org/memory v1.4.0 // indirect + modernc.org/xau v1.0.13 // indirect + modernc.org/xcb v1.0.13 + modernc.org/xdmcp v1.0.14 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..2c79f25 --- /dev/null +++ b/go.sum @@ -0,0 +1,27 @@ +github.com/alecthomas/assert/v2 v2.1.0 h1:tbredtNcQnoSd3QBhQWI7QZ3XHOVkw1Moklp2ojoH/0= +github.com/alecthomas/kong v0.7.1 h1:azoTh0IOfwlAX3qN9sHWTxACE2oV8Bg2gAwBsMwDQY4= +github.com/alecthomas/kong v0.7.1/go.mod h1:n1iCIO2xS46oE8ZfYCNDqdR0b0wZNrXAIAqro/2132U= +github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/jezek/xgb v1.1.0 h1:wnpxJzP1+rkbGclEkmwpVFQWpuE2PUGNUzP8SbfFobk= +github.com/jezek/xgb v1.1.0/go.mod h1:nrhwO0FX/enq75I7Y7G8iN1ubpSGZEiA3v9e9GyRFlk= +github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= +github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 h1:OdAsTTz6OkFY5QxjkYwrChwuRruF69c169dPK26NUlk= +github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab h1:2QkjZIsXupsJbJIdSjjUOgWK3aEtzyuh2mPt3l/CkeU= +golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +modernc.org/libc v1.21.2 h1:V053DgNSpAY+IPrO3XlWqrFKUiQqHyPqG4dsx42Ulck= +modernc.org/libc v1.21.2/go.mod h1:przBsL5RDOZajTVslkugzLBj1evTue36jEomFQOoYuI= +modernc.org/mathutil v1.5.0 h1:rV0Ko/6SfM+8G+yKiyI830l3Wuz1zRutdslNoQ0kfiQ= +modernc.org/mathutil v1.5.0/go.mod h1:mZW8CKdRPY1v87qxC/wUdX5O1qDzXMP5TH3wjfpga6E= +modernc.org/memory v1.4.0 h1:crykUfNSnMAXaOJnnxcSzbUGMqkLWjklJKkBK2nwZwk= +modernc.org/memory v1.4.0/go.mod h1:PkUhL0Mugw21sHPeskwZW4D6VscE/GQJOnIpCnW6pSU= +modernc.org/xau v1.0.13 h1:AEYsSsJFSmkfhSwV6/dx6GoHt02BnZLmMcRT1O8EUOo= +modernc.org/xau v1.0.13/go.mod h1:5ORRqBKlhiUXwoVdM0+ZPy8plvcq0OPOdEgTWyeokhk= +modernc.org/xcb v1.0.13 h1:SIMh1yKsKjkfT/qAxcxSv/W+mRe4RnPzp+XewnD4rS4= +modernc.org/xcb v1.0.13/go.mod h1:M5m1dSVaHvBUf5XUg5Y/b1DZdJs6NK7pYLqsQ+d0swU= +modernc.org/xdmcp v1.0.14 h1:hRCxbYfl75rvOdCmVCPLBRCedClOPjpHiq+tOBzGS3Q= +modernc.org/xdmcp v1.0.14/go.mod h1:TDsH3iMey1HJ3tMCePfTy4dIX6hL/MIVnGREX97nCrE= diff --git a/src/bspc/domains.go b/src/bspc/domains.go new file mode 100644 index 0000000..ac35ae5 --- /dev/null +++ b/src/bspc/domains.go @@ -0,0 +1,17 @@ +package bspc + +import "tuxpa.in/t/wm/src/sock" + +type NODE_SEL string + +type Node struct { + Sel NODE_SEL +} + +func (n *Node) Focus(node NODE_SEL) error { + s, err := sock.Default() + if err != nil { + return err + } + return s.Send("node", "-l") +} diff --git a/src/cmd/cmd.go b/src/cmd/cmd.go new file mode 100644 index 0000000..9239286 --- /dev/null +++ b/src/cmd/cmd.go @@ -0,0 +1,12 @@ +package cmd + +import "context" + +type Context struct { + Debug bool + context.Context +} + +type Cmd interface { + Run(ctx *Context) error +} diff --git a/src/sock/sock.go b/src/sock/sock.go new file mode 100644 index 0000000..1bdd822 --- /dev/null +++ b/src/sock/sock.go @@ -0,0 +1,61 @@ +package sock + +import ( + "fmt" + "io" + "net" + "os" + + "github.com/jezek/xgb" +) + +const SOCKET_PATH_TPL = "/tmp/bspwm%s_%d_%d-socket" + +type Sock struct { + C net.Conn +} + +func (s *Sock) Send(args ...string) (string, error) { + if len(args) == 0 { + return "", s.C.Close() + } + for _, msg := range args { + _, err := s.C.Write([]byte(msg)) + if err != nil { + return "", err + } + _, err = s.C.Write([]byte{0}) + if err != nil { + return "", err + } + } + bts, err := io.ReadAll(s.C) + if err != nil { + return "", err + } + if len(bts) > 0 { + if bts[0] == 7 { + return "", fmt.Errorf(string(bts[1:])) + } + } + return string(bts), nil +} + +func Default() (*Sock, error) { + return New(os.Getenv("BSPWM_SOCKET")) +} +func New(path string) (*Sock, error) { + xc, err := xgb.NewConn() + if err != nil { + return nil, err + } + defer xc.Close() + if path == "" { + path = fmt.Sprintf(SOCKET_PATH_TPL, "", xc.DisplayNumber, xc.DefaultScreen) + } + conn, err := net.Dial("unix", path) + if err != nil { + return nil, err + } + return &Sock{C: conn}, nil +}