From 6117c8a98a39cd8bc1ca6b2436b6dab8873053f9 Mon Sep 17 00:00:00 2001 From: hhvn Date: Sat, 18 Nov 2023 14:13:25 +0000 Subject: Draw to an image.RGBA --- bar/bar.go | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'bar/bar.go') diff --git a/bar/bar.go b/bar/bar.go index 560f928..11ac49e 100644 --- a/bar/bar.go +++ b/bar/bar.go @@ -9,7 +9,7 @@ import ( "hhvn.uk/hbspbar/config" "hhvn.uk/hbspbar/common" "hhvn.uk/hbspbar/bspc" - X "hhvn.uk/hbspbar/x" + "hhvn.uk/hbspbar/drw" "github.com/jezek/xgb" "github.com/jezek/xgb/xproto" @@ -27,7 +27,7 @@ var stoploop chan bool type bar struct { Mon *bspc.Monitor w xproto.Window - i *xgraphics.Image + i *image.RGBA drawing sync.Mutex } @@ -36,46 +36,45 @@ func (b *bar) init() error { go b.Mon.TopPadding(config.H) - b.w, err = xproto.NewWindowId(X.X) + b.w, err = xproto.NewWindowId(drw.X) if err != nil { return common.Perror("xproto.NewWindowId", err) } geom := b.Mon.Rectangle - xproto.CreateWindow(X.X, X.Screen.RootDepth, b.w, X.Screen.Root, + xproto.CreateWindow(drw.X, drw.Screen.RootDepth, b.w, drw.Screen.Root, int16(geom.X), int16(geom.Y), uint16(geom.Width), uint16(config.H), 0, - xproto.WindowClassInputOutput, X.Screen.RootVisual, + xproto.WindowClassInputOutput, drw.Screen.RootVisual, xproto.CwBackPixel|xproto.CwEventMask, []uint32{ config.Bg, xproto.EventMaskStructureNotify }) class := icccm.WmClass{"hbspbar", "hbspbar"} - icccm.WmClassSet(X.XU, b.w, &class) + icccm.WmClassSet(drw.XU, b.w, &class) - ewmh.WmWindowTypeSet(X.XU, b.w, []string{"_NET_WM_WINDOW_TYPE_DOCK"}) - ewmh.WmStateSet(X.XU, b.w, []string{"_NET_WM_STATE_STICKY", "_NET_WM_STATE_ABOVE"}) + ewmh.WmWindowTypeSet(drw.XU, b.w, []string{"_NET_WM_WINDOW_TYPE_DOCK"}) + ewmh.WmStateSet(drw.XU, b.w, []string{"_NET_WM_STATE_STICKY", "_NET_WM_STATE_ABOVE"}) - err = xproto.MapWindowChecked(X.X, b.w).Check() + err = xproto.MapWindowChecked(drw.X, b.w).Check() if err != nil { return common.Perror("xproto.MapWindow", err) } - b.reInit() + b.i = image.NewRGBA(b.rect()) return nil } -func (b *bar) reInit() { - X.GraphicReInit(&b.i, image.Rect(0, 0, - int(b.Mon.Rectangle.Width), int(config.H))) +func (b *bar) rect() image.Rectangle { + return image.Rect(0, 0, int(b.Mon.Rectangle.Width), int(config.H)) } func (b *bar) drawText(x int, col uint32, text string) (int, error) { - return X.DrawText(b.i, x, col, text) + return drw.DrawText(b.i, x, col, text) } func (b *bar) drawRect(x, y, w, h int, c uint32, fill bool) { - X.DrawRect(b.i, x, y, w, h, c, fill) + drw.DrawRect(b.i, x, y, w, h, c, fill) } func (b *bar) draw() { @@ -83,7 +82,6 @@ func (b *bar) draw() { var filled bool b.drawing.Lock() - b.reInit() // Dimensions of drawing space cx := 0 @@ -96,7 +94,7 @@ func (b *bar) draw() { // Monitor montext := b.Mon.Name - monw := 6 + X.TextWidth(montext) + 8 + monw := 6 + drw.TextWidth(montext) + 8 if b.Mon.Focused { bg = config.Sel @@ -114,7 +112,7 @@ func (b *bar) draw() { dw := 4 + (4 + boxw + 2 + 3) * ds + 5 for i := 0; i < ds; i++ { - dw += X.TextWidth(b.Mon.Desktops[i].Name) + dw += drw.TextWidth(b.Mon.Desktops[i].Name) } cx += 4 @@ -138,9 +136,11 @@ func (b *bar) draw() { } cx += 5 - b.i.XSurfaceSet(b.w) - b.i.XDraw() - b.i.XPaint(b.w) + xgr := xgraphics.NewConvert(drw.XU, b.i) + + xgr.XSurfaceSet(b.w) + xgr.XDraw() + xgr.XPaint(b.w) b.drawing.Unlock() } @@ -149,7 +149,7 @@ func (b *bar) destroy() { if (b.Mon != nil) { b.Mon.TopPadding(0) } - xproto.DestroyWindow(X.X, b.w) + xproto.DestroyWindow(drw.X, b.w) } type eventwrap struct { @@ -181,7 +181,7 @@ func init() { xstop := make(chan bool, 1) go func() { for { - ev, err := X.X.WaitForEvent() + ev, err := drw.X.WaitForEvent() w := eventwrap{ev, err} select { @@ -229,7 +229,7 @@ func init() { return } if _, ok := bars[id]; ok { break } - if err := create(X.X, X.XU, X.Screen, state.GetMon(id)); err != nil { + if err := create(drw.X, drw.XU, drw.Screen, state.GetMon(id)); err != nil { Handle.Err <- fmt.Errorf("Couldn't create window: %s\n", err) return } -- cgit v1.2.3