capturing windows

This commit is contained in:
a 2023-06-14 22:20:55 -05:00
parent e5f827aed4
commit 9efd1c2290
4 changed files with 92 additions and 3 deletions

View File

@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net"
"os"
"os/signal"
@ -11,6 +10,7 @@ import (
"syscall"
"github.com/jezek/xgbutil"
"tuxpa.in/a/zlog/log"
"tuxpa.in/t/wm/src/bsp"
"tuxpa.in/t/wm/src/handler"
"tuxpa.in/t/wm/src/handler/domains"
@ -57,6 +57,14 @@ func _main() (code int, err error) {
w := bsp.NewWM()
// create a wm-x11 connection
xwm := bsp.NewXWM(w, x11)
go func() {
err := xwm.Start(ctx)
if err != nil {
log.Err(err).Msg("x server shutdown")
stop()
}
}()
// create a handler
h := &handler.Handler{
XWM: xwm,

5
go.mod
View File

@ -10,10 +10,15 @@ require (
github.com/jezek/xgb v1.1.0
github.com/jezek/xgbutil v0.0.0-20230603163917-04188eb39cf0
github.com/stretchr/testify v1.8.4
tuxpa.in/a/zlog v1.61.0
)
require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/zerolog v1.28.0 // indirect
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

17
go.sum
View File

@ -1,12 +1,29 @@
github.com/BurntSushi/freetype-go v0.0.0-20160129220410-b763ddbfe298/go.mod h1:D+QujdIlUNfa0igpNMk6UIvlb6C252URs4yupRUV4lQ=
github.com/BurntSushi/graphics-go v0.0.0-20160129215708-b43f31a4a966/go.mod h1:Mid70uvE93zn9wgF92A/r5ixgnvX8Lh68fxp9KQBaI0=
github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.28.0 h1:MirSo27VyNi7RJYP3078AA1+Cyzd2GB66qy3aUHvsWY=
github.com/rs/zerolog v1.28.0/go.mod h1:NILgTygv/Uej1ra5XxGf82ZFSLk58MFGAUS2o6usyD0=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41 h1:ohgcoMbSofXygzo6AD2I1kz3BFmW1QArPYTtwEM3UXc=
golang.org/x/sys v0.0.0-20220915200043-7b5979e65e41/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
tuxpa.in/a/zlog v1.61.0 h1:7wrS6G4QwpnOmgHRQknrr7IgiMXrfGpekkU0PjM9FhE=
tuxpa.in/a/zlog v1.61.0/go.mod h1:CNpMe8laDHLSypx/DyxfX1S0oyxUydeo3aGTEbtRBhg=

View File

@ -3,7 +3,12 @@ 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 {
@ -20,14 +25,68 @@ func NewXWM(w *WM, x *xgbutil.XUtil) *XWM {
}
func (xwm *XWM) Start(ctx context.Context) error {
for {
err := xwm.run(ctx)
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
}