This commit is contained in:
a 2023-06-15 10:57:08 -05:00
parent 65162b1651
commit a595d4980c
8 changed files with 166 additions and 30 deletions

3
.gitignore vendored
View File

@ -1,5 +1,8 @@
/bspwm
/bspc
/tspwm
/tspc
*.log
*.sock

View File

@ -20,10 +20,10 @@ all: bspwm bspc
VPATH=src
bspwm: cmd/bspwm src/**/*
go build -o bspwm ./cmd/bspwm
go build -o tspwm ./cmd/bspwm
bspc: cmd/bspc src/**/*
go build -o bspc ./cmd/bspc
go build -o tspc ./cmd/bspc
xephyr:
Xephyr :11 -br -ac -noreset -screen ${WINDOWSIZE}

View File

@ -71,9 +71,9 @@ func _main() (code int, err error) {
XWM: xwm,
}
// install the handlers
handler.AddDomain[domains.Todo](h, "node")
handler.AddDomain[domains.Node](h, "node")
handler.AddDomain[domains.Todo](h, "desktop")
handler.AddDomain[domains.Todo](h, "monitor")
handler.AddDomain[domains.Monitor](h, "monitor")
handler.AddDomain[domains.Wm](h, "wm")
handler.AddDomain[domains.Todo](h, "rule")
handler.AddDomain[domains.Config](h, "config")

View File

@ -2,6 +2,7 @@ package domains
import (
"fmt"
"strings"
"tuxpa.in/t/wm/src/bsp"
"tuxpa.in/t/wm/src/copies"
@ -11,6 +12,28 @@ import (
type inject struct {
xwm
}
type monitor_sel struct {
monitorsel string
}
func (n *monitor_sel) tryMonitorSel(msg *sock.Msg) (bool, error) {
// first split the str by .
if !msg.HasNext() {
return false, nil
}
str := msg.Peek()
splt := strings.Split(str, ".")
switch splt[0] {
case "any", "first_ancestor",
"last", "newest", "older", "newer",
"focused", "pointed", "biggest", "smallest":
n.monitorsel = str
return true, nil
}
return false, nil
}
type desktop_sel struct {
desktopsel string
}
@ -51,10 +74,6 @@ type cmd struct {
Command string
}
func (c *cmd) SetCommand(x string) {
c.Command = x
}
func (n *cmd) readCommand(msg *sock.Msg, c string) (bool, error) {
if n.Command == "" {
n.Command = c
@ -63,6 +82,33 @@ func (n *cmd) readCommand(msg *sock.Msg, c string) (bool, error) {
return false, fmt.Errorf("multiple commands given")
}
type commandParser struct {
routes map[string]string
}
func newCommandParser() *commandParser {
return &commandParser{
routes: map[string]string{},
}
}
func (c *commandParser) addDef(name string, aliases ...string) *commandParser {
c.routes["--"+strings.TrimSpace(name)] = name
for _, a := range aliases {
c.routes[strings.TrimSpace(a)] = name
}
return c
}
func (c *commandParser) parse(n *cmd, msg *sock.Msg) (bool, error) {
arg := msg.Next()
cmd, ok := c.routes[arg]
if !ok {
return false, fmt.Errorf(`unknown option: '%s'`, arg)
}
return n.readCommand(msg, cmd)
}
type xwm struct {
XWM *bsp.XWM
}

View File

@ -0,0 +1,72 @@
package domains
import (
"fmt"
"tuxpa.in/t/wm/src/copies"
"tuxpa.in/t/wm/src/sock"
)
type Monitor struct {
UseNames bool
inject
cmd
monitor_sel
}
func (n *Monitor) Run(msg *sock.Msg) ([]byte, error) {
if !msg.HasNext() {
return nil, &copies.ErrMissingArguments{}
}
for {
ok, err := n.parse(msg)
if err != nil {
return nil, err
}
if !ok {
break
}
}
switch n.Command {
default:
return nil, &copies.ErrTODO{
Kind: "command",
Name: n.Command,
}
}
}
func (n *Monitor) parse(msg *sock.Msg) (bool, error) {
if !msg.HasNext() {
return false, &copies.ErrMissingArguments{}
}
ok, err := n.tryMonitorSel(msg)
if err != nil {
return false, err
}
if ok {
msg.Next()
}
arg := msg.Next()
switch arg {
case "--add-desktops", "-a":
return n.readCommand(msg, "add-desktops")
case "--focus", "-f":
return n.readCommand(msg, "focus")
case "--rectangle", "-g":
return n.readCommand(msg, "rectangle")
case "--remove", "-r":
return n.readCommand(msg, "remove")
case "--reorder-desktops", "-o":
return n.readCommand(msg, "reorder-desktops")
case "--reset-desktops", "-d":
return n.readCommand(msg, "reset-desktops")
case "--swap", "-s":
return n.readCommand(msg, "swap")
default:
return false, fmt.Errorf(`unknown option: '%s'`, arg)
}
}

View File

@ -29,7 +29,13 @@ func (n *Node) Run(msg *sock.Msg) ([]byte, error) {
}
}
return nil, nil
switch n.Command {
default:
return nil, &copies.ErrTODO{
Kind: "command",
Name: n.Command,
}
}
}
func (n *Node) parse(msg *sock.Msg) (bool, error) {

View File

@ -60,22 +60,22 @@ func (n *Query) desktops(msg *sock.Msg) ([]byte, error) {
return o.Bytes(), nil
}
var queryParser = newCommandParser().
addDef("desktop", "-d", "--desktops")
func (n *Query) parse(msg *sock.Msg) (bool, error) {
if !msg.HasNext() {
return false, &copies.ErrMissingArguments{}
}
arg := msg.Next()
switch arg {
case "--desktop", "-d":
case "--desktops", "-D":
case "--desktop", "-d", "--desktops", "-D":
return n.readCommand(msg, "desktops")
case "--monitor", "-m":
case "--monitors", "-M":
case "--monitor", "-m", "--monitors", "-M":
return n.readCommand(msg, "monitors")
case "--names":
n.UseNames = true
case "--node", "-n":
case "--nodes", "-N":
case "--node", "-n", "--nodes", "-N":
return n.readCommand(msg, "nodes")
case "--tree", "-T":
return n.readCommand(msg, "tree")

View File

@ -29,7 +29,14 @@ func (n *Wm) Run(msg *sock.Msg) ([]byte, error) {
}
}
return nil, nil
switch n.Command {
default:
return nil, &copies.ErrTODO{
Kind: "command",
Name: n.Command,
}
}
}
func (n *Wm) parse(msg *sock.Msg) (bool, error) {
@ -38,21 +45,23 @@ func (n *Wm) parse(msg *sock.Msg) (bool, error) {
}
arg := msg.Next()
switch arg {
case "--desktop", "-d":
case "--desktops", "-D":
return n.readCommand(msg, "desktops")
case "--monitor", "-m":
case "--monitors", "-M":
return n.readCommand(msg, "monitors")
case "--names":
n.UseNames = true
case "--node", "-n":
case "--nodes", "-N":
return n.readCommand(msg, "nodes")
case "--tree", "-T":
return n.readCommand(msg, "tree")
case "--add-monitor", "-a":
return n.readCommand(msg, "add-monitor")
case "--adopt-orphans", "-o":
return n.readCommand(msg, "adopt-orphans")
case "--dump-state", "-d":
return n.readCommand(msg, "dump-state")
case "--get-status", "-g":
return n.readCommand(msg, "get-status")
case "--load-state", "-l":
return n.readCommand(msg, "load-state")
case "--record-history", "-h":
return n.readCommand(msg, "record-history")
case "--reorder-monitors", "-O":
return n.readCommand(msg, "reorder-monitors")
case "--restart", "-r":
return n.readCommand(msg, "restart")
default:
return false, fmt.Errorf(`unknown option: '%s'`, arg)
}
return msg.HasNext(), nil
}