From a39af5e18a10b2c95f4e65ebf2f027c6ace05fb4 Mon Sep 17 00:00:00 2001 From: DeedleFake Date: Fri, 2 Oct 2026 16:13:25 -0400 Subject: [PATCH] anchor: use wlr.Edges --- .github/workflows/ci.yml | 6 ------ internal/anchor/anchor.go | 30 +++++++++++------------------- internal/anchor/anchor_test.go | 27 ++++++++++++++------------- internal/kawa/layers.go | 4 ++-- internal/kawa/layers_test.go | 32 -------------------------------- 5 files changed, 27 insertions(+), 72 deletions(-) delete mode 100644 internal/kawa/layers_test.go diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ec7e0f8..f986cca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -171,9 +171,3 @@ jobs: env: CGO_ENABLED: '1' run: go test ./... - - # Building these without cgo keeps wlr out of them. - - name: Test pure packages - env: - CGO_ENABLED: '0' - run: go test ./internal/anchor ./internal/bg ./internal/draw ./internal/output ./internal/xflag diff --git a/internal/anchor/anchor.go b/internal/anchor/anchor.go index 7b868db..91aa99b 100644 --- a/internal/anchor/anchor.go +++ b/internal/anchor/anchor.go @@ -1,17 +1,9 @@ // Package anchor places layer surfaces on an output. package anchor -import "deedles.dev/ximage/geom" - -// Edges is a set of edges of an output. Its bits are the same as -// those of the layer shell protocol's anchor enum and of wlr_edges. -type Edges uint8 - -const ( - Top Edges = 1 << iota - Bottom - Left - Right +import ( + "deedles.dev/wlr" + "deedles.dev/ximage/geom" ) // Margins are the distances that a surface keeps from the edges that @@ -23,7 +15,7 @@ type Margins struct { // State is what a layer surface asks for. type State struct { // Anchor is the edges that the surface is anchored to. - Anchor Edges + Anchor wlr.Edges // Width and Height are the surface's desired size. 0 stretches it // between its margins on that axis. Width, Height int @@ -44,12 +36,12 @@ func Place(s State, full, usable geom.Rect[int]) geom.Rect[int] { x0, x1 := placeSpan( bounds.Min.X, bounds.Max.X, s.Width, s.Margin.Left, s.Margin.Right, - s.Anchor&Left != 0, s.Anchor&Right != 0, + s.Anchor&wlr.EdgeLeft != 0, s.Anchor&wlr.EdgeRight != 0, ) y0, y1 := placeSpan( bounds.Min.Y, bounds.Max.Y, s.Height, s.Margin.Top, s.Margin.Bottom, - s.Anchor&Top != 0, s.Anchor&Bottom != 0, + s.Anchor&wlr.EdgeTop != 0, s.Anchor&wlr.EdgeBottom != 0, ) return geom.Rt(x0, y0, x1, y1).Canon() } @@ -73,15 +65,15 @@ func placeSpan(lo, hi, n, before, after int, toLo, toHi bool) (int, int) { // Exclude removes a layer surface's exclusive zone from edge, the edge // of usable that the zone applies to. -func Exclude(usable geom.Rect[int], s State, edge Edges) geom.Rect[int] { +func Exclude(usable geom.Rect[int], s State, edge wlr.Edges) geom.Rect[int] { switch edge { - case Top: + case wlr.EdgeTop: return usable.Pad(s.Zone+s.Margin.Top, 0, 0, 0) - case Bottom: + case wlr.EdgeBottom: return usable.Pad(0, s.Zone+s.Margin.Bottom, 0, 0) - case Left: + case wlr.EdgeLeft: return usable.Pad(0, 0, s.Zone+s.Margin.Left, 0) - case Right: + case wlr.EdgeRight: return usable.Pad(0, 0, 0, s.Zone+s.Margin.Right) default: return usable diff --git a/internal/anchor/anchor_test.go b/internal/anchor/anchor_test.go index c9a2495..637c17a 100644 --- a/internal/anchor/anchor_test.go +++ b/internal/anchor/anchor_test.go @@ -4,6 +4,7 @@ import ( "testing" "deedles.dev/kawa/internal/anchor" + "deedles.dev/wlr" "deedles.dev/ximage/geom" ) @@ -17,27 +18,27 @@ func TestPlace(t *testing.T) { }{ { "stretched wallpaper", - anchor.State{Anchor: anchor.Top | anchor.Bottom | anchor.Left | anchor.Right, Zone: -1}, + anchor.State{Anchor: wlr.EdgeTop | wlr.EdgeBottom | wlr.EdgeLeft | wlr.EdgeRight, Zone: -1}, full, }, { "top panel", - anchor.State{Anchor: anchor.Top | anchor.Left | anchor.Right, Height: 30, Zone: 30}, + anchor.State{Anchor: wlr.EdgeTop | wlr.EdgeLeft | wlr.EdgeRight, Height: 30, Zone: 30}, geom.Rt(0, 25, 1024, 55), }, { "bottom panel with margins", - anchor.State{Anchor: anchor.Bottom | anchor.Left | anchor.Right, Height: 30, Margin: anchor.Margins{Bottom: 5, Left: 10, Right: 20}}, + anchor.State{Anchor: wlr.EdgeBottom | wlr.EdgeLeft | wlr.EdgeRight, Height: 30, Margin: anchor.Margins{Bottom: 5, Left: 10, Right: 20}}, geom.Rt(10, 733, 1004, 763), }, { "left dock", - anchor.State{Anchor: anchor.Left, Width: 64, Height: 400, Margin: anchor.Margins{Left: 4}}, + anchor.State{Anchor: wlr.EdgeLeft, Width: 64, Height: 400, Margin: anchor.Margins{Left: 4}}, geom.Rt(4, 196, 68, 596), }, { "right dock", - anchor.State{Anchor: anchor.Right, Width: 64, Height: 400, Margin: anchor.Margins{Right: 4}}, + anchor.State{Anchor: wlr.EdgeRight, Width: 64, Height: 400, Margin: anchor.Margins{Right: 4}}, geom.Rt(956, 196, 1020, 596), }, { @@ -47,12 +48,12 @@ func TestPlace(t *testing.T) { }, { "anchored to both sides with a size", - anchor.State{Anchor: anchor.Left | anchor.Right, Width: 300, Height: 200}, + anchor.State{Anchor: wlr.EdgeLeft | wlr.EdgeRight, Width: 300, Height: 200}, geom.Rt(362, 296, 662, 496), }, { "margins wider than the area", - anchor.State{Anchor: anchor.Left | anchor.Right, Height: 10, Margin: anchor.Margins{Left: 800, Right: 800}}, + anchor.State{Anchor: wlr.EdgeLeft | wlr.EdgeRight, Height: 10, Margin: anchor.Margins{Left: 800, Right: 800}}, geom.Rt(800, 391, 800, 401), }, } @@ -70,15 +71,15 @@ func TestExclude(t *testing.T) { usable := geom.Rt(0, 25, 1024, 768) state := anchor.State{Zone: 30, Margin: anchor.Margins{Top: 1, Right: 2, Bottom: 3, Left: 4}} tests := []struct { - edge anchor.Edges + edge wlr.Edges want geom.Rect[int] }{ {0, usable}, - {anchor.Top, geom.Rt(0, 56, 1024, 768)}, - {anchor.Bottom, geom.Rt(0, 25, 1024, 735)}, - {anchor.Left, geom.Rt(34, 25, 1024, 768)}, - {anchor.Right, geom.Rt(0, 25, 992, 768)}, - {anchor.Top | anchor.Left, usable}, + {wlr.EdgeTop, geom.Rt(0, 56, 1024, 768)}, + {wlr.EdgeBottom, geom.Rt(0, 25, 1024, 735)}, + {wlr.EdgeLeft, geom.Rt(34, 25, 1024, 768)}, + {wlr.EdgeRight, geom.Rt(0, 25, 992, 768)}, + {wlr.EdgeTop | wlr.EdgeLeft, usable}, } for _, test := range tests { got := anchor.Exclude(usable, state, test.edge) diff --git a/internal/kawa/layers.go b/internal/kawa/layers.go index 75caa06..133bcd8 100644 --- a/internal/kawa/layers.go +++ b/internal/kawa/layers.go @@ -143,7 +143,7 @@ func (server *Server) arrangeLayers(out *Output) { ls.Geo = anchor.Place(state, full, usable) s.Configure(uint32(ls.Geo.Dx()), uint32(ls.Geo.Dy())) if ls.Mapped() { - usable = anchor.Exclude(usable, state, anchor.Edges(s.ExclusiveEdge())) + usable = anchor.Exclude(usable, state, s.ExclusiveEdge()) } } } @@ -160,7 +160,7 @@ func (server *Server) arrangeLayers(out *Output) { func anchorState(state wlr.LayerSurfaceV1State) anchor.State { top, right, bottom, left := state.Margin() return anchor.State{ - Anchor: anchor.Edges(state.Anchor()), + Anchor: wlr.Edges(state.Anchor()), Width: int(state.DesiredWidth()), Height: int(state.DesiredHeight()), Margin: anchor.Margins{Top: int(top), Right: int(right), Bottom: int(bottom), Left: int(left)}, diff --git a/internal/kawa/layers_test.go b/internal/kawa/layers_test.go deleted file mode 100644 index 322cd62..0000000 --- a/internal/kawa/layers_test.go +++ /dev/null @@ -1,32 +0,0 @@ -package kawa - -import ( - "testing" - - "deedles.dev/kawa/internal/anchor" - "deedles.dev/wlr" -) - -func TestAnchorEdges(t *testing.T) { - tests := []struct { - edge anchor.Edges - anchor wlr.LayerSurfaceV1Anchor - wlr wlr.Edges - }{ - {anchor.Top, wlr.LayerSurfaceV1AnchorTop, wlr.EdgeTop}, - {anchor.Bottom, wlr.LayerSurfaceV1AnchorBottom, wlr.EdgeBottom}, - {anchor.Left, wlr.LayerSurfaceV1AnchorLeft, wlr.EdgeLeft}, - {anchor.Right, wlr.LayerSurfaceV1AnchorRight, wlr.EdgeRight}, - } - for _, test := range tests { - if anchor.Edges(test.anchor) != test.edge { - t.Errorf("layer surface anchor %d is not anchor.Edges %d", test.anchor, test.edge) - } - if anchor.Edges(test.wlr) != test.edge { - t.Errorf("wlr.Edges %d is not anchor.Edges %d", test.wlr, test.edge) - } - } - if anchor.Edges(wlr.EdgeNone) != 0 { - t.Errorf("wlr.EdgeNone is %d", wlr.EdgeNone) - } -}