Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 11 additions & 19 deletions internal/anchor/anchor.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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()
}
Expand All @@ -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
Expand Down
27 changes: 14 additions & 13 deletions internal/anchor/anchor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"deedles.dev/kawa/internal/anchor"
"deedles.dev/wlr"
"deedles.dev/ximage/geom"
)

Expand All @@ -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),
},
{
Expand All @@ -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),
},
}
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions internal/kawa/layers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand All @@ -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)},
Expand Down
32 changes: 0 additions & 32 deletions internal/kawa/layers_test.go

This file was deleted.

Loading