This commit is contained in:
a 2023-06-11 09:34:42 -05:00
parent e277164b2a
commit 99f43d3408
1 changed files with 37 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package bsp package bsp
import ( import (
"fmt"
"sync" "sync"
"tuxpa.in/t/wm/src/bsp/cfg" "tuxpa.in/t/wm/src/bsp/cfg"
@ -19,39 +20,66 @@ type Desktop struct {
Name string Name string
Monitor *Monitor Monitor *Monitor
Cfg *cfg.Modifier[Config] Cfg *cfg.Modifier[*Config]
} }
type Monitor struct { type Monitor struct {
Name string Name string
Cfg *cfg.Modifier[Config] Cfg *cfg.Modifier[*Config]
} }
type Node struct { type Node struct {
Name string Name string
Cfg *cfg.Modifier[Config] Cfg *cfg.Modifier[*Config]
} }
func (w *WM) Mutate(fn func() error) { func (w *WM) Mutate(fn func() error) error {
w.mu.Lock() w.mu.Lock()
defer w.mu.Unlock() defer w.mu.Unlock()
if fn != nil { if fn != nil {
fn() return fn()
} }
return nil
} }
func (w *WM) View(fn func() error) { func (w *WM) View(fn func() error) error {
w.mu.RLock() w.mu.RLock()
defer w.mu.RUnlock() defer w.mu.RUnlock()
if fn != nil { if fn != nil {
fn() return fn()
} }
return nil
} }
func (w *WM) AddDesktop(name string) { func (w *WM) AddMonitor(name string) error {
return w.Mutate(func() error {
w.Monitors = append(w.Monitors, &Monitor{
Name: name,
Cfg: cfg.NewModifier(&Config{}),
})
return nil
})
}
func (w *WM) AddDesktop(name string, monitorName string) error {
return w.Mutate(func() error {
var monitor *Monitor
for _, v := range w.Monitors {
if v.Name == monitorName {
monitor = v
}
}
if monitor == nil {
return fmt.Errorf("invalid descriptor found in '%s'", monitor)
}
w.Desktops = append(w.Desktops, &Desktop{
Name: name,
Cfg: cfg.NewModifier(&Config{}),
Monitor: monitor,
})
return nil
})
} }
func NewWM() *WM { func NewWM() *WM {