wm/src/handler/domains/wm.go

59 lines
991 B
Go
Raw Normal View History

2023-06-11 14:11:36 +00:00
package domains
import (
"fmt"
"tuxpa.in/t/wm/src/copies"
"tuxpa.in/t/wm/src/sock"
)
type Wm struct {
UseNames bool
inject
cmd
}
func (n *Wm) 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
}
}
return nil, nil
}
func (n *Wm) parse(msg *sock.Msg) (bool, error) {
if !msg.HasNext() {
return false, &copies.ErrMissingArguments{}
}
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")
default:
return false, fmt.Errorf(`unknown option: '%s'`, arg)
}
return msg.HasNext(), nil
}