package bsp import ( "context" "github.com/jezek/xgb/xproto" "github.com/jezek/xgbutil" "github.com/jezek/xgbutil/keybind" "github.com/jezek/xgbutil/mousebind" "github.com/jezek/xgbutil/xevent" "tuxpa.in/a/zlog/log" ) type XWM struct { W *WM X *xgbutil.XUtil } func NewXWM(w *WM, x *xgbutil.XUtil) *XWM { xwm := &XWM{ W: w, X: x, } return xwm } func (xwm *XWM) Start(ctx context.Context) error { keybind.Initialize(xwm.X) mousebind.Initialize(xwm.X) captureCombos := []string{ "Mod4-1", "Mod3-1", "Mod2-1", "Mod1-1", } for _, combo := range captureCombos { err := mousebind.ButtonPressFun(func(xu *xgbutil.XUtil, event xevent.ButtonPressEvent) { log.Trace().Str("name", event.String()).Str("mod", combo).Msg("press") }).Connect(xwm.X, xwm.X.RootWin(), combo, false, true) if err != nil { return err } err = mousebind.ButtonReleaseFun(func(xu *xgbutil.XUtil, event xevent.ButtonReleaseEvent) { log.Trace().Str("name", event.String()).Str("mod", combo).Msg("depress") }).Connect(xwm.X, xwm.X.RootWin(), combo, false, true) if err != nil { return err } } tree, err := xproto.QueryTree(xwm.X.Conn(), xwm.X.RootWin()).Reply() if err != nil { return err } for _, v := range tree.Children { if v == xwm.X.Dummy() { continue } attrs, err := xproto.GetWindowAttributes(xwm.X.Conn(), v).Reply() if err != nil { continue } if attrs.MapState == xproto.MapStateUnmapped { continue } log.Trace(). Uint16("class", attrs.Class). Msg("found existing window") log.Println(attrs) } xevent.ConfigureNotifyFun(func(xu *xgbutil.XUtil, event xevent.ConfigureNotifyEvent) { log.Trace().Str("name", event.String()).Msg("notify event") }).Connect(xwm.X, xwm.X.RootWin()) xevent.Main(xwm.X) // for { // err := xwm.run(ctx) // if err != nil { // return err // } // } return nil } func (xwm *XWM) run(ctx context.Context) error { return nil }