This commit is contained in:
a 2023-06-11 09:56:54 -05:00
parent 99f43d3408
commit e5f827aed4
5 changed files with 81 additions and 8 deletions

View File

@ -7,6 +7,7 @@ import (
"net"
"os"
"os/signal"
"strconv"
"syscall"
"github.com/jezek/xgbutil"
@ -18,18 +19,19 @@ import (
func main() {
err := _main()
c, err := _main()
if err != nil {
panic(err)
}
os.Exit(c)
}
func _main() error {
func _main() (code int, err error) {
// connect to the x server
log.Printf("connecting to xorg")
x11, err := xgbutil.NewConn()
if err != nil {
return err
return 1, err
}
defer x11.Conn().Close()
@ -38,7 +40,7 @@ func _main() error {
log.Printf("starting bspwm")
ln, err := sock.Server(addr)
if err != nil {
return err
return 1, err
}
defer ln.Close()
@ -67,18 +69,41 @@ func _main() error {
handler.AddDomain[domains.Todo](h, "rule")
handler.AddDomain[domains.Config](h, "config")
handler.AddDomain[domains.Todo](h, "subscribe")
handler.AddDomain[domains.Todo](h, "quit")
handler.AddDomain[domains.Query](h, "query")
handler.AddDomain[domains.Echo](h, "echo")
codeCh := make(chan int, 1)
handler.AddDomain[domains.Todo](h, "quit")
h.AddDomainFunc("quit", func() handler.Domain {
d := &domains.Lambda{
Fn: func(x *bsp.XWM, msg *sock.Msg) ([]byte, error) {
if !msg.HasNext() {
codeCh <- 0
return nil, nil
}
str := msg.Next()
cd, err := strconv.Atoi(str)
if err != nil {
return nil, err
}
codeCh <- cd
return nil, nil
},
}
return d
})
// message listen loop
for {
select {
case m := <-ln.Msg():
h.Run(m)
case cint := <-codeCh:
stop()
return cint, nil
case <-ctx.Done():
log.Println("bspwm shutting down...")
return nil
return 0, nil
}
}
}

View File

@ -114,6 +114,27 @@ func (m *Modifier[T]) setup() {
}
return fmt.Sprintf("%v", fv.Elem()), nil
}
case reflect.Float32, reflect.Float64:
m.setters[k] = func(v string) (err error) {
var val float64
if v != "" {
val, err = strconv.ParseFloat(v, 10)
if err != nil {
return copies.NewInvalidValueErr(k, v)
}
}
if fv.IsNil() {
fv.Set(reflect.New(ft.Type.Elem()))
}
fv.Elem().SetFloat(val)
return nil
}
m.getters[k] = func() (string, error) {
if fv.IsNil() {
return "", nil
}
return fmt.Sprintf("%v", fv.Elem()), nil
}
case reflect.Bool:
m.setters[k] = func(v string) error {
var b bool

View File

@ -71,7 +71,7 @@ func (w *WM) AddDesktop(name string, monitorName string) error {
}
}
if monitor == nil {
return fmt.Errorf("invalid descriptor found in '%s'", monitor)
return fmt.Errorf("invalid descriptor found in '%s'", monitorName)
}
w.Desktops = append(w.Desktops, &Desktop{
Name: name,

View File

@ -0,0 +1,16 @@
package domains
import (
"tuxpa.in/t/wm/src/bsp"
"tuxpa.in/t/wm/src/sock"
)
type Lambda struct {
Fn func(x *bsp.XWM, msg *sock.Msg) ([]byte, error)
inject
}
func (n *Lambda) Run(msg *sock.Msg) ([]byte, error) {
return n.Fn(n.XWM, msg)
}

View File

@ -28,6 +28,17 @@ func AddDomain[T any, PT interface {
}
}
func (h *Handler) AddDomainFunc(name string, fn func() Domain) {
if h.domains == nil {
h.domains = map[string]func() Domain{}
}
h.domains[name] = func() Domain {
d := fn()
d.SetXWM(h.XWM)
return d
}
}
func (h *Handler) Run(msg *sock.Msg) {
resp, err := h.run(msg)
if msg.Err(err) {