This commit is contained in:
a 2022-12-25 20:18:39 -06:00
commit 8881383350
8 changed files with 222 additions and 0 deletions

5
Makefile Normal file
View File

@ -0,0 +1,5 @@
WINDOWSIZE=1024:768
xephyr:
Xephyr -br ac -noreset ${WINDOWSIZE} :1

57
cmd/bspc/cli.go Normal file
View File

@ -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 {
}

23
cmd/bspc/main.go Normal file
View File

@ -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)
}
}

20
go.mod Normal file
View File

@ -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
)

27
go.sum Normal file
View File

@ -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=

17
src/bspc/domains.go Normal file
View File

@ -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")
}

12
src/cmd/cmd.go Normal file
View File

@ -0,0 +1,12 @@
package cmd
import "context"
type Context struct {
Debug bool
context.Context
}
type Cmd interface {
Run(ctx *Context) error
}

61
src/sock/sock.go Normal file
View File

@ -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
}