#117 fix(core): keep focus on a window moved by an output rule

state
merged · a307da7 · merge commit
branch
fix/rule-move-keeps-focus → main
opened
bnema ·
updated

A title rule that moves the focused window to another output (e.g. Steam Big Picture to the virtual tv output) now keeps it focused there via activate(), even on isolated outputs. Skipped while the source overview is open. Unit tests cover placed, isolated, hidden destination workspace, focus on another output and overview open. Not covered headless: needs an XWayland title change; verify by hand with Steam + Sunshine.

CommitSubjectAuthorDateSignatureStatus
b66135afix(core): route rule focus moves through activatebrice GPG Verified
62917e3fix(core): keep focus on a window moved by an output rulebrice GPG Verified

Checks 1

12 files · +144 -332
1/1
M docs/config.md +1 -1
@@ -176,7 +176,7 @@ Outputs are arranged automatically unless `.right-of`, `.left-of`, `.above` or `
176176
177177 ## Window rules
178178
179-Rules place an app's windows when they first open. A rule matches its app ID and, when set, its title. A title rule's output/workspace placement also applies when a later title first matches, at most once per rule per window. This later move never changes focus or view, floating state, or column width. SDR expansion settings follow the current title match.
179+Rules place an app's windows when they first open. A rule matches its app ID and, when set, its title. A title rule's output/workspace placement also applies when a later title first matches, at most once per rule per window. This later move never changes floating state or column width. When the focused window moves, it stays the focused window on the destination output, even an isolated one, and that output becomes focused (not while the source output's overview is open); otherwise focus and view are unchanged. With `output.<name>.input` bindings, input from an unbound device returns focus to the last unbound output. SDR expansion settings follow the current title match.
180180
181181 | Key | Meaning |
182182 |---|---|
@@ -176,7 +176,7 @@ Outputs are arranged automatically unless `.right-of`, `.left-of`, `.above` or `
176 176
177 ## Window rules177 ## Window rules
178 178
179-Rules place an app's windows when they first open. A rule matches its app ID and, when set, its title. A title rule's output/workspace placement also applies when a later title first matches, at most once per rule per window. This later move never changes focus or view, floating state, or column width. SDR expansion settings follow the current title match.179+Rules place an app's windows when they first open. A rule matches its app ID and, when set, its title. A title rule's output/workspace placement also applies when a later title first matches, at most once per rule per window. This later move never changes floating state or column width. When the focused window moves, it stays the focused window on the destination output, even an isolated one, and that output becomes focused (not while the source output's overview is open); otherwise focus and view are unchanged. With `output.<name>.input` bindings, input from an unbound device returns focus to the last unbound output. SDR expansion settings follow the current title match.
180 180
181 | Key | Meaning |181 | Key | Meaning |
182 |---|---|182 |---|---|
D internal/adapters/wayland/content_source.go +0 -84
@@ -1,84 +0,0 @@
1-package wayland
2-
3-import (
4- "time"
5-
6- "github.com/bnema/neferwl/internal/ports"
7-)
8-
9-// mainContent caches the source on the root. Only committed render layouts
10-// participate; pending structural children are not visible content yet.
11-func (s *surface) mainContent() *surface {
12- r := s.root()
13- if r.contentSource == nil {
14- r.contentSource = r.selectContent(r)
15- }
16- return r.contentSource
17-}
18-
19-func contentArea(s *surface) int64 {
20- if !s.has || s.destroyed {
21- return -1
22- }
23- return int64(s.content.LogicalW) * int64(s.content.LogicalH)
24-}
25-
26-// selectContent follows appendTree's paint order. First child wins equal-area
27-// child ties; a full-size child wins a tie with the static root.
28-func (s *surface) selectContent(best *surface) *surface {
29- for _, item := range s.sub.layout {
30- if item.below {
31- best = item.child.selectContent(best)
32- }
33- }
34- if contentArea(s) > contentArea(best) || best == s.root() && s != best && contentArea(s) == contentArea(best) && contentArea(s) >= 0 {
35- best = s
36- }
37- for _, item := range s.sub.layout {
38- if !item.below {
39- best = item.child.selectContent(best)
40- }
41- }
42- return best
43-}
44-
45-func (s *surface) colorManaged() bool {
46- source := s.mainContent()
47- return !s.outputColor().PlainSDR() || source.has && !source.outputColor().PlainSDR()
48-}
49-
50-// mappedColor synchronizes the delta cache with the initial/remap publication.
51-func (s *surface) mappedColor() bool {
52- s.windowColorManaged = s.colorManaged()
53- return s.windowColorManaged
54-}
55-
56-// refreshWindowFacts runs after committed content changes, including detaches.
57-// Only the selected source contributes timings and buffer facts. Switching
58-// sources clears timings so intervals never straddle two independent streams.
59-func (s *surface) refreshWindowFacts(fresh bool) {
60- r := s.root()
61- id := r.windowID()
62- if id == 0 {
63- return
64- }
65- source := r.mainContent()
66- managed := r.colorManaged()
67- if managed != r.windowColorManaged {
68- r.windowColorManaged = managed
69- s.server.emit(ports.WindowColorDescription{ID: id, PlainSDR: !managed})
70- }
71- stats := &s.server.stats
72- if stats.watched != id {
73- return
74- }
75- if stats.source != source {
76- stats.source = source
77- stats.client = frameRing{}
78- stats.lastCommit = time.Time{}
79- }
80- stats.bufferFacts(source.content, source.hold.acquire != nil, source.async)
81- if fresh && s == source {
82- stats.commit(s.server.clock.Now(), source.content, source.hold.acquire != nil, source.async)
83- }
84-}
@@ -1,84 +0,0 @@
1-package wayland
2-
3-import (
4- "time"
5-
6- "github.com/bnema/neferwl/internal/ports"
7-)
8-
9-// mainContent caches the source on the root. Only committed render layouts
10-// participate; pending structural children are not visible content yet.
11-func (s *surface) mainContent() *surface {
12- r := s.root()
13- if r.contentSource == nil {
14- r.contentSource = r.selectContent(r)
15- }
16- return r.contentSource
17-}
18-
19-func contentArea(s *surface) int64 {
20- if !s.has || s.destroyed {
21- return -1
22- }
23- return int64(s.content.LogicalW) * int64(s.content.LogicalH)
24-}
25-
26-// selectContent follows appendTree's paint order. First child wins equal-area
27-// child ties; a full-size child wins a tie with the static root.
28-func (s *surface) selectContent(best *surface) *surface {
29- for _, item := range s.sub.layout {
30- if item.below {
31- best = item.child.selectContent(best)
32- }
33- }
34- if contentArea(s) > contentArea(best) || best == s.root() && s != best && contentArea(s) == contentArea(best) && contentArea(s) >= 0 {
35- best = s
36- }
37- for _, item := range s.sub.layout {
38- if !item.below {
39- best = item.child.selectContent(best)
40- }
41- }
42- return best
43-}
44-
45-func (s *surface) colorManaged() bool {
46- source := s.mainContent()
47- return !s.outputColor().PlainSDR() || source.has && !source.outputColor().PlainSDR()
48-}
49-
50-// mappedColor synchronizes the delta cache with the initial/remap publication.
51-func (s *surface) mappedColor() bool {
52- s.windowColorManaged = s.colorManaged()
53- return s.windowColorManaged
54-}
55-
56-// refreshWindowFacts runs after committed content changes, including detaches.
57-// Only the selected source contributes timings and buffer facts. Switching
58-// sources clears timings so intervals never straddle two independent streams.
59-func (s *surface) refreshWindowFacts(fresh bool) {
60- r := s.root()
61- id := r.windowID()
62- if id == 0 {
63- return
64- }
65- source := r.mainContent()
66- managed := r.colorManaged()
67- if managed != r.windowColorManaged {
68- r.windowColorManaged = managed
69- s.server.emit(ports.WindowColorDescription{ID: id, PlainSDR: !managed})
70- }
71- stats := &s.server.stats
72- if stats.watched != id {
73- return
74- }
75- if stats.source != source {
76- stats.source = source
77- stats.client = frameRing{}
78- stats.lastCommit = time.Time{}
79- }
80- stats.bufferFacts(source.content, source.hold.acquire != nil, source.async)
81- if fresh && s == source {
82- stats.commit(s.server.clock.Now(), source.content, source.hold.acquire != nil, source.async)
83- }
84-}
D internal/adapters/wayland/content_source_test.go +0 -144
@@ -1,144 +0,0 @@
1-package wayland
2-
3-import (
4- "testing"
5- "time"
6-
7- "github.com/bnema/go-wayland-bindings/server/wayland"
8- portsmocks "github.com/bnema/neferwl/internal/mocks/ports"
9- "github.com/bnema/neferwl/internal/ports"
10- "github.com/stretchr/testify/require"
11-)
12-
13-func TestContentSubsurfaceWindowFacts(t *testing.T) {
14- for _, removal := range []string{"revert", "unmap", "destroy", "remap"} {
15- t.Run(removal, func(t *testing.T) {
16- events := make(chan ports.ClientEvent, 32)
17- s, dir, _ := idleClockServerWith(t, Channels{Events: events})
18- c := protocolClient(t, s, dir)
19- w, root, xdg := surfaceMapper(t, c, events)()
20- comp := bindProtocol(t, c, "wl_compositor")
21- subc := bindProtocol(t, c, "wl_subcompositor")
22- child, sub := c.AllocateID(), c.AllocateID()
23- requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, child)
24- registerProtocol(t, c, child)
25- requestProtocol(t, c, subc, wayland.SubcompositorRequestGetSubsurface, sub, child, root)
26- registerProtocol(t, c, sub)
27- requestProtocol(t, c, sub, wayland.SubsurfaceRequestSetDesync)
28- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
29- require.NoError(t, c.Roundtrip())
30- var content *surface
31- s.display.Do(func() {
32- content = s.windows[w.ID].surf().sub.children[0]
33- // Exercise the same captured colour state as the colour protocol sets.
34- content.next.color = SurfaceColor{Set: true, TF: pq, Primaries: bt2020}
35- s.watchStats(w.ID)
36- })
37- now := time.Unix(1, 0)
38- s.clock.(*portsmocks.MockClock).EXPECT().Now().RunAndReturn(func() time.Time { result := now; now = now.Add(20 * time.Millisecond); return result }).Times(3)
39- b := shmBuffer(t, c)
40- for range 3 {
41- requestProtocol(t, c, child, wayland.SurfaceRequestAttach, b, int32(0), int32(0))
42- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
43- // Equal-sized fresh root buffers must not add a second timing stream.
44- if removal == "revert" {
45- requestProtocol(t, c, root, wayland.SurfaceRequestAttach, b, int32(0), int32(0))
46- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
47- }
48- require.NoError(t, c.Roundtrip())
49- }
50- require.Equal(t, ports.WindowColorDescription{ID: w.ID, PlainSDR: false}, clientEvent[ports.WindowColorDescription](t, events))
51- s.display.Do(func() {
52- require.Equal(t, float32(50), s.stats.snapshot().ClientFPS)
53- require.Same(t, content, s.stats.source)
54- require.Equal(t, 1, s.stats.facts.Width)
55- })
56- switch removal {
57- case "remap":
58- s.display.Do(func() { s.watchStats(0) })
59- requestProtocol(t, c, root, wayland.SurfaceRequestAttach, uint32(0), int32(0), int32(0))
60- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
61- require.NoError(t, c.Roundtrip())
62- _ = clientEvent[ports.WindowUnmapped](t, events)
63- serials := make(chan uint32, 8)
64- xp := &configureProxy{serial: serials}
65- xp.SetID(xdg)
66- registerWireProxy(c, xp)
67- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
68- ackAndAttach(t, c, root, xdg, b, serials)
69- again := clientEvent[ports.WindowMapped](t, events)
70- require.True(t, again.Remap)
71- require.True(t, again.ColorDescription)
72- s.display.Do(func() { require.True(t, s.windows[w.ID].surf().windowColorManaged) })
73- return
74- case "revert":
75- s.display.Do(func() { content.next.color = SurfaceColor{} })
76- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
77- case "unmap":
78- requestProtocol(t, c, child, wayland.SurfaceRequestAttach, uint32(0), int32(0), int32(0))
79- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
80- case "destroy":
81- requestProtocol(t, c, child, wayland.SurfaceRequestDestroy)
82- }
83- require.NoError(t, c.Roundtrip())
84- require.Equal(t, ports.WindowColorDescription{ID: w.ID, PlainSDR: true}, clientEvent[ports.WindowColorDescription](t, events))
85- s.display.Do(func() { s.watchStats(0) })
86- })
87- }
88-}
89-
90-func TestContentSourceWaitsForCommittedLayout(t *testing.T) {
91- events := make(chan ports.ClientEvent, 32)
92- s, dir, _ := idleClockServerWith(t, Channels{Events: events})
93- c := protocolClient(t, s, dir)
94- w, root, _ := surfaceMapper(t, c, events)()
95- comp := bindProtocol(t, c, "wl_compositor")
96- subc := bindProtocol(t, c, "wl_subcompositor")
97- child, sub := c.AllocateID(), c.AllocateID()
98- requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, child)
99- registerProtocol(t, c, child)
100- requestProtocol(t, c, subc, wayland.SubcompositorRequestGetSubsurface, sub, child, root)
101- registerProtocol(t, c, sub)
102- requestProtocol(t, c, sub, wayland.SubsurfaceRequestSetDesync)
103- require.NoError(t, c.Roundtrip())
104- var r, ch *surface
105- s.display.Do(func() {
106- r = s.windows[w.ID].surf()
107- ch = r.sub.children[0]
108- ch.next.color = SurfaceColor{Set: true, TF: pq, Primaries: bt2020}
109- })
110- requestProtocol(t, c, child, wayland.SurfaceRequestAttach, shmBufferSized(t, c, 64, 64), int32(0), int32(0))
111- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
112- require.NoError(t, c.Roundtrip())
113- s.display.Do(func() {
114- require.True(t, ch.has)
115- require.Same(t, r, r.mainContent())
116- require.False(t, r.windowColorManaged)
117- })
118- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
119- require.NoError(t, c.Roundtrip())
120- require.Equal(t, ports.WindowColorDescription{ID: w.ID, PlainSDR: false}, clientEvent[ports.WindowColorDescription](t, events))
121- s.display.Do(func() { require.Same(t, ch, r.mainContent()) })
122-}
123-
124-func BenchmarkContentSourceSteadyCommit(b *testing.B) {
125- r := &surface{has: true, server: &Server{}}
126- r.xdg = &xdgSurface{window: &window{id: 1, mapped: true}}
127- for range 100 {
128- ch := &surface{has: true, sub: subState{parent: r}}
129- r.sub.layout = append(r.sub.layout, childLayout{child: ch})
130- }
131- r.refreshWindowFacts(false)
132- b.ReportAllocs()
133- b.ResetTimer()
134- for b.Loop() {
135- r.refreshWindowFacts(false)
136- }
137-}
138-
139-func TestContentSourceSteadyCommitAllocations(t *testing.T) {
140- r := &surface{has: true, server: &Server{}}
141- r.xdg = &xdgSurface{window: &window{id: 1, mapped: true}}
142- r.refreshWindowFacts(false)
143- require.Zero(t, testing.AllocsPerRun(100, func() { r.refreshWindowFacts(false) }))
144-}
@@ -1,144 +0,0 @@
1-package wayland
2-
3-import (
4- "testing"
5- "time"
6-
7- "github.com/bnema/go-wayland-bindings/server/wayland"
8- portsmocks "github.com/bnema/neferwl/internal/mocks/ports"
9- "github.com/bnema/neferwl/internal/ports"
10- "github.com/stretchr/testify/require"
11-)
12-
13-func TestContentSubsurfaceWindowFacts(t *testing.T) {
14- for _, removal := range []string{"revert", "unmap", "destroy", "remap"} {
15- t.Run(removal, func(t *testing.T) {
16- events := make(chan ports.ClientEvent, 32)
17- s, dir, _ := idleClockServerWith(t, Channels{Events: events})
18- c := protocolClient(t, s, dir)
19- w, root, xdg := surfaceMapper(t, c, events)()
20- comp := bindProtocol(t, c, "wl_compositor")
21- subc := bindProtocol(t, c, "wl_subcompositor")
22- child, sub := c.AllocateID(), c.AllocateID()
23- requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, child)
24- registerProtocol(t, c, child)
25- requestProtocol(t, c, subc, wayland.SubcompositorRequestGetSubsurface, sub, child, root)
26- registerProtocol(t, c, sub)
27- requestProtocol(t, c, sub, wayland.SubsurfaceRequestSetDesync)
28- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
29- require.NoError(t, c.Roundtrip())
30- var content *surface
31- s.display.Do(func() {
32- content = s.windows[w.ID].surf().sub.children[0]
33- // Exercise the same captured colour state as the colour protocol sets.
34- content.next.color = SurfaceColor{Set: true, TF: pq, Primaries: bt2020}
35- s.watchStats(w.ID)
36- })
37- now := time.Unix(1, 0)
38- s.clock.(*portsmocks.MockClock).EXPECT().Now().RunAndReturn(func() time.Time { result := now; now = now.Add(20 * time.Millisecond); return result }).Times(3)
39- b := shmBuffer(t, c)
40- for range 3 {
41- requestProtocol(t, c, child, wayland.SurfaceRequestAttach, b, int32(0), int32(0))
42- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
43- // Equal-sized fresh root buffers must not add a second timing stream.
44- if removal == "revert" {
45- requestProtocol(t, c, root, wayland.SurfaceRequestAttach, b, int32(0), int32(0))
46- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
47- }
48- require.NoError(t, c.Roundtrip())
49- }
50- require.Equal(t, ports.WindowColorDescription{ID: w.ID, PlainSDR: false}, clientEvent[ports.WindowColorDescription](t, events))
51- s.display.Do(func() {
52- require.Equal(t, float32(50), s.stats.snapshot().ClientFPS)
53- require.Same(t, content, s.stats.source)
54- require.Equal(t, 1, s.stats.facts.Width)
55- })
56- switch removal {
57- case "remap":
58- s.display.Do(func() { s.watchStats(0) })
59- requestProtocol(t, c, root, wayland.SurfaceRequestAttach, uint32(0), int32(0), int32(0))
60- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
61- require.NoError(t, c.Roundtrip())
62- _ = clientEvent[ports.WindowUnmapped](t, events)
63- serials := make(chan uint32, 8)
64- xp := &configureProxy{serial: serials}
65- xp.SetID(xdg)
66- registerWireProxy(c, xp)
67- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
68- ackAndAttach(t, c, root, xdg, b, serials)
69- again := clientEvent[ports.WindowMapped](t, events)
70- require.True(t, again.Remap)
71- require.True(t, again.ColorDescription)
72- s.display.Do(func() { require.True(t, s.windows[w.ID].surf().windowColorManaged) })
73- return
74- case "revert":
75- s.display.Do(func() { content.next.color = SurfaceColor{} })
76- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
77- case "unmap":
78- requestProtocol(t, c, child, wayland.SurfaceRequestAttach, uint32(0), int32(0), int32(0))
79- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
80- case "destroy":
81- requestProtocol(t, c, child, wayland.SurfaceRequestDestroy)
82- }
83- require.NoError(t, c.Roundtrip())
84- require.Equal(t, ports.WindowColorDescription{ID: w.ID, PlainSDR: true}, clientEvent[ports.WindowColorDescription](t, events))
85- s.display.Do(func() { s.watchStats(0) })
86- })
87- }
88-}
89-
90-func TestContentSourceWaitsForCommittedLayout(t *testing.T) {
91- events := make(chan ports.ClientEvent, 32)
92- s, dir, _ := idleClockServerWith(t, Channels{Events: events})
93- c := protocolClient(t, s, dir)
94- w, root, _ := surfaceMapper(t, c, events)()
95- comp := bindProtocol(t, c, "wl_compositor")
96- subc := bindProtocol(t, c, "wl_subcompositor")
97- child, sub := c.AllocateID(), c.AllocateID()
98- requestProtocol(t, c, comp, wayland.CompositorRequestCreateSurface, child)
99- registerProtocol(t, c, child)
100- requestProtocol(t, c, subc, wayland.SubcompositorRequestGetSubsurface, sub, child, root)
101- registerProtocol(t, c, sub)
102- requestProtocol(t, c, sub, wayland.SubsurfaceRequestSetDesync)
103- require.NoError(t, c.Roundtrip())
104- var r, ch *surface
105- s.display.Do(func() {
106- r = s.windows[w.ID].surf()
107- ch = r.sub.children[0]
108- ch.next.color = SurfaceColor{Set: true, TF: pq, Primaries: bt2020}
109- })
110- requestProtocol(t, c, child, wayland.SurfaceRequestAttach, shmBufferSized(t, c, 64, 64), int32(0), int32(0))
111- requestProtocol(t, c, child, wayland.SurfaceRequestCommit)
112- require.NoError(t, c.Roundtrip())
113- s.display.Do(func() {
114- require.True(t, ch.has)
115- require.Same(t, r, r.mainContent())
116- require.False(t, r.windowColorManaged)
117- })
118- requestProtocol(t, c, root, wayland.SurfaceRequestCommit)
119- require.NoError(t, c.Roundtrip())
120- require.Equal(t, ports.WindowColorDescription{ID: w.ID, PlainSDR: false}, clientEvent[ports.WindowColorDescription](t, events))
121- s.display.Do(func() { require.Same(t, ch, r.mainContent()) })
122-}
123-
124-func BenchmarkContentSourceSteadyCommit(b *testing.B) {
125- r := &surface{has: true, server: &Server{}}
126- r.xdg = &xdgSurface{window: &window{id: 1, mapped: true}}
127- for range 100 {
128- ch := &surface{has: true, sub: subState{parent: r}}
129- r.sub.layout = append(r.sub.layout, childLayout{child: ch})
130- }
131- r.refreshWindowFacts(false)
132- b.ReportAllocs()
133- b.ResetTimer()
134- for b.Loop() {
135- r.refreshWindowFacts(false)
136- }
137-}
138-
139-func TestContentSourceSteadyCommitAllocations(t *testing.T) {
140- r := &surface{has: true, server: &Server{}}
141- r.xdg = &xdgSurface{window: &window{id: 1, mapped: true}}
142- r.refreshWindowFacts(false)
143- require.Zero(t, testing.AllocsPerRun(100, func() { r.refreshWindowFacts(false) }))
144-}
M internal/adapters/wayland/surface.go +15 -15
@@ -57,14 +57,12 @@ type surface struct {
5757 layer *layerSurface
5858 lock *lockSurface
5959 // bufferCommitted is permanent, including commits later discarded by FIFO.
60- bufferCommitted bool
61- server *Server
62- current *wayland.Buffer
63- lastW, lastH int // last logged buffer size
64- role func(bool)
65- destroyed bool
66- contentSource *surface // cached main content; nil when buffering or layout changes
67- windowColorManaged bool // last emitted aggregate root/content colour fact
60+ bufferCommitted bool
61+ server *Server
62+ current *wayland.Buffer
63+ lastW, lastH int // last logged buffer size
64+ role func(bool)
65+ destroyed bool
6866 // hotX, hotY is the click point of a cursor surface (logical).
6967 hotX, hotY int
7068 // on is the output the surface entered; scale is the last scale sent.
@@ -312,7 +310,6 @@ func (s *surface) detach() {
312310 p.sub.pendingLayout = removeLayout(p.sub.pendingLayout, s)
313311 p.sub.layout = removeLayout(p.sub.layout, s)
314312 p.root().treeDirty = true
315- p.root().contentSource = nil
316313 for _, u := range p.queue {
317314 u.layout = removeLayout(u.layout, s)
318315 }
@@ -320,7 +317,6 @@ func (s *surface) detach() {
320317 // Parent updates cannot make a detached child's bound commits visible.
321318 s.dropQueue()
322319 s.flushDesync()
323- p.refreshWindowFacts(false)
324320 p.redraw()
325321 p.emitInput()
326322 s.sendScale()
@@ -438,7 +434,6 @@ func (s *surface) queueAndTick() {
438434 //
439435 //hexcheck:ignore suspicious-business-logic-in-adapter Applies captured Wayland buffer state on the display owner goroutine.
440436 func (s *surface) applyCommit(u *update) {
441- oldHas := s.has
442437 oldW, oldH, oldSource, oldTransform := s.content.LogicalW, s.content.LogicalH, s.content.Source, s.content.Transform
443438 oldColor, oldRepresentation := s.color, s.representation
444439 fresh := u.attached && u.buffer != nil
@@ -475,7 +470,13 @@ func (s *surface) applyCommit(u *update) {
475470 s.root().treeDirty = true
476471 }
477472 s.async = u.async
473+ oldPlain := s.outputColor().PlainSDR()
478474 s.color = u.color
475+ if plain := s.outputColor().PlainSDR(); plain != oldPlain {
476+ if id := s.windowID(); s.root() == s && id != 0 {
477+ s.server.emit(ports.WindowColorDescription{ID: id, PlainSDR: plain})
478+ }
479+ }
479480 s.representation = u.representation
480481 if s.lock != nil && s.commitSkipped {
481482 // A discarded replacement cannot change retained lock geometry, even
@@ -521,6 +522,9 @@ func (s *surface) applyCommit(u *update) {
521522 if !s.validateViewport(c.Width, c.Height) {
522523 return
523524 }
525+ if s.sub.parent == nil && s.server.stats.watched != 0 && s.windowID() == s.server.stats.watched {
526+ s.server.stats.commit(s.server.clock.Now(), c, s.hold.acquire != nil, s.async)
527+ }
524528 c.Transform = s.transform
525529 c.Source, _ = s.source(c.Width, c.Height)
526530 c.LogicalW, c.LogicalH = s.logicalSize(c.Width, c.Height)
@@ -581,10 +585,6 @@ func (s *surface) applyCommit(u *update) {
581585 if s.xdg != nil && s.xdg == u.xdg && u.geometry != s.xdg.geometry {
582586 s.xdg.geometry, geometry = u.geometry, true
583587 }
584- if oldHas != s.has || oldW != s.content.LogicalW || oldH != s.content.LogicalH || moved {
585- s.root().contentSource = nil
586- }
587- s.refreshWindowFacts(fresh)
588588 s.commitConstraint(u.cons, u.region, geometry)
589589 s.emitInput()
590590 if s.kind == roleDragIcon {
@@ -57,14 +57,12 @@ type surface struct {
57 layer *layerSurface57 layer *layerSurface
58 lock *lockSurface58 lock *lockSurface
59 // bufferCommitted is permanent, including commits later discarded by FIFO.59 // bufferCommitted is permanent, including commits later discarded by FIFO.
60- bufferCommitted bool60+ bufferCommitted bool
61- server *Server61+ server *Server
62- current *wayland.Buffer62+ current *wayland.Buffer
63- lastW, lastH int // last logged buffer size63+ lastW, lastH int // last logged buffer size
64- role func(bool)64+ role func(bool)
65- destroyed bool65+ destroyed bool
66- contentSource *surface // cached main content; nil when buffering or layout changes
67- windowColorManaged bool // last emitted aggregate root/content colour fact
68 // hotX, hotY is the click point of a cursor surface (logical).66 // hotX, hotY is the click point of a cursor surface (logical).
69 hotX, hotY int67 hotX, hotY int
70 // on is the output the surface entered; scale is the last scale sent.68 // on is the output the surface entered; scale is the last scale sent.
@@ -312,7 +310,6 @@ func (s *surface) detach() {
312 p.sub.pendingLayout = removeLayout(p.sub.pendingLayout, s)310 p.sub.pendingLayout = removeLayout(p.sub.pendingLayout, s)
313 p.sub.layout = removeLayout(p.sub.layout, s)311 p.sub.layout = removeLayout(p.sub.layout, s)
314 p.root().treeDirty = true312 p.root().treeDirty = true
315- p.root().contentSource = nil
316 for _, u := range p.queue {313 for _, u := range p.queue {
317 u.layout = removeLayout(u.layout, s)314 u.layout = removeLayout(u.layout, s)
318 }315 }
@@ -320,7 +317,6 @@ func (s *surface) detach() {
320 // Parent updates cannot make a detached child's bound commits visible.317 // Parent updates cannot make a detached child's bound commits visible.
321 s.dropQueue()318 s.dropQueue()
322 s.flushDesync()319 s.flushDesync()
323- p.refreshWindowFacts(false)
324 p.redraw()320 p.redraw()
325 p.emitInput()321 p.emitInput()
326 s.sendScale()322 s.sendScale()
@@ -438,7 +434,6 @@ func (s *surface) queueAndTick() {
438 //434 //
439 //hexcheck:ignore suspicious-business-logic-in-adapter Applies captured Wayland buffer state on the display owner goroutine.435 //hexcheck:ignore suspicious-business-logic-in-adapter Applies captured Wayland buffer state on the display owner goroutine.
440 func (s *surface) applyCommit(u *update) {436 func (s *surface) applyCommit(u *update) {
441- oldHas := s.has
442 oldW, oldH, oldSource, oldTransform := s.content.LogicalW, s.content.LogicalH, s.content.Source, s.content.Transform437 oldW, oldH, oldSource, oldTransform := s.content.LogicalW, s.content.LogicalH, s.content.Source, s.content.Transform
443 oldColor, oldRepresentation := s.color, s.representation438 oldColor, oldRepresentation := s.color, s.representation
444 fresh := u.attached && u.buffer != nil439 fresh := u.attached && u.buffer != nil
@@ -475,7 +470,13 @@ func (s *surface) applyCommit(u *update) {
475 s.root().treeDirty = true470 s.root().treeDirty = true
476 }471 }
477 s.async = u.async472 s.async = u.async
473+ oldPlain := s.outputColor().PlainSDR()
478 s.color = u.color474 s.color = u.color
475+ if plain := s.outputColor().PlainSDR(); plain != oldPlain {
476+ if id := s.windowID(); s.root() == s && id != 0 {
477+ s.server.emit(ports.WindowColorDescription{ID: id, PlainSDR: plain})
478+ }
479+ }
479 s.representation = u.representation480 s.representation = u.representation
480 if s.lock != nil && s.commitSkipped {481 if s.lock != nil && s.commitSkipped {
481 // A discarded replacement cannot change retained lock geometry, even482 // A discarded replacement cannot change retained lock geometry, even
@@ -521,6 +522,9 @@ func (s *surface) applyCommit(u *update) {
521 if !s.validateViewport(c.Width, c.Height) {522 if !s.validateViewport(c.Width, c.Height) {
522 return523 return
523 }524 }
525+ if s.sub.parent == nil && s.server.stats.watched != 0 && s.windowID() == s.server.stats.watched {
526+ s.server.stats.commit(s.server.clock.Now(), c, s.hold.acquire != nil, s.async)
527+ }
524 c.Transform = s.transform528 c.Transform = s.transform
525 c.Source, _ = s.source(c.Width, c.Height)529 c.Source, _ = s.source(c.Width, c.Height)
526 c.LogicalW, c.LogicalH = s.logicalSize(c.Width, c.Height)530 c.LogicalW, c.LogicalH = s.logicalSize(c.Width, c.Height)
@@ -581,10 +585,6 @@ func (s *surface) applyCommit(u *update) {
581 if s.xdg != nil && s.xdg == u.xdg && u.geometry != s.xdg.geometry {585 if s.xdg != nil && s.xdg == u.xdg && u.geometry != s.xdg.geometry {
582 s.xdg.geometry, geometry = u.geometry, true586 s.xdg.geometry, geometry = u.geometry, true
583 }587 }
584- if oldHas != s.has || oldW != s.content.LogicalW || oldH != s.content.LogicalH || moved {
585- s.root().contentSource = nil
586- }
587- s.refreshWindowFacts(fresh)
588 s.commitConstraint(u.cons, u.region, geometry)588 s.commitConstraint(u.cons, u.region, geometry)
589 s.emitInput()589 s.emitInput()
590 if s.kind == roleDragIcon {590 if s.kind == roleDragIcon {
M internal/adapters/wayland/winstats.go +3 -5
@@ -105,7 +105,6 @@ type windowStats struct {
105105 gen uint64
106106 timer ports.Timer
107107 client, shown frameRing
108- source *surface
109108 lastCommit time.Time
110109 lastShown time.Duration
111110 lastShownSeq uint64
@@ -113,7 +112,7 @@ type windowStats struct {
113112 scratch [domain.StatsFrames]uint32
114113 }
115114
116-// commit records a fresh main-content buffer and its presentation hints.
115+// commit records a fresh root buffer and its presentation hints.
117116 func (w *windowStats) commit(now time.Time, c domain.SurfaceContent, explicitSync, tearing bool) {
118117 if w.watched == 0 {
119118 return
@@ -172,9 +171,8 @@ func (s *Server) watchStats(id domain.WindowID) {
172171 gen := s.stats.gen + 1
173172 s.stats = windowStats{watched: id, gen: gen}
174173 if id != 0 {
175- source := w.surf().mainContent()
176- s.stats.source = source
177- s.stats.bufferFacts(source.content, source.hold.acquire != nil, source.async)
174+ root := w.surf()
175+ s.stats.bufferFacts(root.content, root.hold.acquire != nil, root.async)
178176 s.armStats()
179177 }
180178 }
@@ -105,7 +105,6 @@ type windowStats struct {
105 gen uint64105 gen uint64
106 timer ports.Timer106 timer ports.Timer
107 client, shown frameRing107 client, shown frameRing
108- source *surface
109 lastCommit time.Time108 lastCommit time.Time
110 lastShown time.Duration109 lastShown time.Duration
111 lastShownSeq uint64110 lastShownSeq uint64
@@ -113,7 +112,7 @@ type windowStats struct {
113 scratch [domain.StatsFrames]uint32112 scratch [domain.StatsFrames]uint32
114 }113 }
115 114
116-// commit records a fresh main-content buffer and its presentation hints.115+// commit records a fresh root buffer and its presentation hints.
117 func (w *windowStats) commit(now time.Time, c domain.SurfaceContent, explicitSync, tearing bool) {116 func (w *windowStats) commit(now time.Time, c domain.SurfaceContent, explicitSync, tearing bool) {
118 if w.watched == 0 {117 if w.watched == 0 {
119 return118 return
@@ -172,9 +171,8 @@ func (s *Server) watchStats(id domain.WindowID) {
172 gen := s.stats.gen + 1171 gen := s.stats.gen + 1
173 s.stats = windowStats{watched: id, gen: gen}172 s.stats = windowStats{watched: id, gen: gen}
174 if id != 0 {173 if id != 0 {
175- source := w.surf().mainContent()174+ root := w.surf()
176- s.stats.source = source175+ s.stats.bufferFacts(root.content, root.hold.acquire != nil, root.async)
177- s.stats.bufferFacts(source.content, source.hold.acquire != nil, source.async)
178 s.armStats()176 s.armStats()
179 }177 }
180 }178 }
M internal/adapters/wayland/x11window.go +1 -1
@@ -351,7 +351,7 @@ func (x *x11Window) tryMap() {
351351 if w.parent != nil && w.parent.mapped {
352352 parent = w.parent.id
353353 }
354- s.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, ColorDescription: surf.mappedColor(), PID: x.info.PID, Xwayland: true, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Positioned: true, Modal: w.modal, Remap: w.gen > 1, HasAt: x.info.HasAt, AtX: x.info.AtX, AtY: x.info.AtY, Fullscreen: x.info.Fullscreen})
354+ s.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, ColorDescription: !surf.outputColor().PlainSDR(), PID: x.info.PID, Xwayland: true, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Positioned: true, Modal: w.modal, Remap: w.gen > 1, HasAt: x.info.HasAt, AtX: x.info.AtX, AtY: x.info.AtY, Fullscreen: x.info.Fullscreen})
355355 s.syncInhibitors()
356356 s.toplevelChanged(w)
357357 s.castInventoryChanged()
@@ -351,7 +351,7 @@ func (x *x11Window) tryMap() {
351 if w.parent != nil && w.parent.mapped {351 if w.parent != nil && w.parent.mapped {
352 parent = w.parent.id352 parent = w.parent.id
353 }353 }
354- s.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, ColorDescription: surf.mappedColor(), PID: x.info.PID, Xwayland: true, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Positioned: true, Modal: w.modal, Remap: w.gen > 1, HasAt: x.info.HasAt, AtX: x.info.AtX, AtY: x.info.AtY, Fullscreen: x.info.Fullscreen})354+ s.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, ColorDescription: !surf.outputColor().PlainSDR(), PID: x.info.PID, Xwayland: true, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Positioned: true, Modal: w.modal, Remap: w.gen > 1, HasAt: x.info.HasAt, AtX: x.info.AtX, AtY: x.info.AtY, Fullscreen: x.info.Fullscreen})
355 s.syncInhibitors()355 s.syncInhibitors()
356 s.toplevelChanged(w)356 s.toplevelChanged(w)
357 s.castInventoryChanged()357 s.castInventoryChanged()
M internal/adapters/wayland/xdg.go +1 -1
@@ -272,7 +272,7 @@ func (x *xdgSurface) GetToplevel(r *xdgshell.Surface, id uint32) {
272272 }
273273 pid := r.Client().PID()
274274 x11 := x.server.x11Client != nil && x.server.x11Client.Owns(pid)
275- x.server.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, Slot: slot, Sandbox: sandbox, ContentType: windowContentType(x.surface.contentKind), ColorDescription: x.surface.mappedColor(), Xwayland: x11, PIDShared: x11, PID: pid, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Modal: w.modal, Remap: w.gen > 1, Fullscreen: w.gen == 1 && w.initialFullscreen})
275+ x.server.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, Slot: slot, Sandbox: sandbox, ContentType: windowContentType(x.surface.contentKind), ColorDescription: !x.surface.outputColor().PlainSDR(), Xwayland: x11, PIDShared: x11, PID: pid, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Modal: w.modal, Remap: w.gen > 1, Fullscreen: w.gen == 1 && w.initialFullscreen})
276276 x.server.syncInhibitors()
277277 x.server.toplevelChanged(w)
278278 x.server.castInventoryChanged()
@@ -272,7 +272,7 @@ func (x *xdgSurface) GetToplevel(r *xdgshell.Surface, id uint32) {
272 }272 }
273 pid := r.Client().PID()273 pid := r.Client().PID()
274 x11 := x.server.x11Client != nil && x.server.x11Client.Owns(pid)274 x11 := x.server.x11Client != nil && x.server.x11Client.Owns(pid)
275- x.server.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, Slot: slot, Sandbox: sandbox, ContentType: windowContentType(x.surface.contentKind), ColorDescription: x.surface.mappedColor(), Xwayland: x11, PIDShared: x11, PID: pid, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Modal: w.modal, Remap: w.gen > 1, Fullscreen: w.gen == 1 && w.initialFullscreen})275+ x.server.emit(ports.WindowMapped{ID: w.id, AppID: w.appID, Title: w.title, Slot: slot, Sandbox: sandbox, ContentType: windowContentType(x.surface.contentKind), ColorDescription: !x.surface.outputColor().PlainSDR(), Xwayland: x11, PIDShared: x11, PID: pid, Floating: w.floating, Width: w.floatW, Height: w.floatH, Parent: parent, Modal: w.modal, Remap: w.gen > 1, Fullscreen: w.gen == 1 && w.initialFullscreen})
276 x.server.syncInhibitors()276 x.server.syncInhibitors()
277 x.server.toplevelChanged(w)277 x.server.toplevelChanged(w)
278 x.server.castInventoryChanged()278 x.server.castInventoryChanged()
M internal/adapters/wayland/xwm/selection_test.go +21 -71
@@ -233,25 +233,7 @@ func TestSelectionXToWaylandINCR(t *testing.T) {
233233 r := ownedRig(t)
234234 const total = 1 << 20
235235 want := pattern(total)
236- src := newMockfdSource(t)
237- var onW func()
238- r.x.lp = newFDLoop(t, r, src, nil, &onW)
239- src.EXPECT().SetWritable(mock.Anything).Return(nil).Maybe()
240- src.EXPECT().Remove().Return().Maybe()
241- f := r.receive(t, 4096)
242- type result struct {
243- data []byte
244- err error
245- }
246- done := make(chan result, 1)
247- finished := make(chan struct{})
248- go func() {
249- defer close(finished)
250- data, err := io.ReadAll(f)
251- done <- result{data, err}
252- }()
253- // Abort first: closing f does not interrupt a blocked read while the XWM holds the write end.
254- t.Cleanup(func() { r.x.selClose(); f.Close(); <-finished })
236+ f := r.receive(t, 1<<20)
255237 _, n := pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == 24 })
256238 r.skip = n
257239 r.p.setProp(r.requestor, r.data, r.p.atom("INCR"), 32, le32(total))
@@ -269,18 +251,11 @@ func TestSelectionXToWaylandINCR(t *testing.T) {
269251 r.p.propertyNotify(r.requestor, r.data, false)
270252 r.waitGet(t)
271253 gets++
272- readUntil(t, r.x, func() bool {
273- for r.x.sel.in[0].state == inWriting {
274- waitSocket(t, r.x.sel.in[0].fd, unix.POLLOUT)
275- onW()
276- }
277- return r.x.sel.in[0].state == inWaitIncr || r.x.sel.in[0].state == inFree
278- })
279254 }
280255 readUntil(t, r.x, func() bool { return r.x.sel.in[0].state == inFree })
281- got := <-done
282- require.NoError(t, got.err)
283- require.True(t, bytes.Equal(want, got.data), "byte-exact, got %d", len(got.data))
256+ got, err := io.ReadAll(f)
257+ require.NoError(t, err)
258+ require.True(t, bytes.Equal(want, got), "byte-exact, got %d", len(got))
284259 require.Equal(t, 1+total/chunk+1, gets, "marker, 16 chunks, empty terminator")
285260 require.NoError(t, r.x.conn.Sync(&r.x.h))
286261 reused, err := r.x.newSelectionRequestor()
@@ -298,18 +273,15 @@ func TestSelectionXToWaylandBackpressure(t *testing.T) {
298273 src.EXPECT().SetWritable(true).Return(nil).Once()
299274 src.EXPECT().SetWritable(false).Return(nil).Once()
300275 src.EXPECT().Remove().Return().Once()
301- f := r.receive(t, 4096) // force backpressure independent of host pipe limits
302- // The kernel rounds the request up to its page size: use the real capacity.
303- piece, err := unix.FcntlInt(f.Fd(), unix.F_GETPIPE_SZ, 0)
304- require.NoError(t, err)
276+ f := r.receive(t, 0) // default 64 KiB pipe
305277 _, n := pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == 24 })
306278 r.skip = n
307- r.p.setProp(r.requestor, r.data, r.p.atom("INCR"), 32, le32(uint32(3*piece)))
279+ r.p.setProp(r.requestor, r.data, r.p.atom("INCR"), 32, le32(3*chunk))
308280 r.p.selectionNotify(r.requestor, r.clip, r.utf8, r.data)
309281 r.waitGet(t)
310- want := pattern(3 * piece)
282+ want := pattern(3 * chunk)
311283 chunkN := func(k int) {
312- r.p.setProp(r.requestor, r.data, r.utf8, 8, want[k*piece:(k+1)*piece])
284+ r.p.setProp(r.requestor, r.data, r.utf8, 8, want[k*chunk:(k+1)*chunk])
313285 r.p.propertyNotify(r.requestor, r.data, false)
314286 }
315287 chunkN(0) // fills the pipe exactly
@@ -327,8 +299,8 @@ func TestSelectionXToWaylandBackpressure(t *testing.T) {
327299 r.x.flush()
328300 require.Equal(t, gets, getProps(r.p, 0, r.requestor), "no GetProperty while a buffer is pending")
329301
330- got := make([]byte, 0, 3*piece)
331- buf := make([]byte, piece)
302+ got := make([]byte, 0, 3*chunk)
303+ buf := make([]byte, chunk)
332304 m, err := f.Read(buf) // the reader wakes: room again
333305 require.NoError(t, err)
334306 got = append(got, buf[:m]...)
@@ -448,20 +420,17 @@ func TestSelectionINCRChunkAllocations(t *testing.T) {
448420 x.onSelectionNotify(&note)
449421 x.onSelDataReply(dataReply(r, r.p.atom("INCR"), le32(1<<20)))
450422 require.Equal(t, inWaitIncr, x.sel.in[0].state)
451- // INCR chunks need not fill the protocol buffer. Keep this hot-path
452- // allocation measurement within one pipe page; full-size chunks and
453- // writable callbacks are exercised by TestSelectionXToWaylandINCR.
454- rep := dataReply(r, r.utf8, pattern(4096))
423+ rep := dataReply(r, r.utf8, pattern(chunk))
455424 var pn xturbo.Event
456425 pn.Kind = xproto.KindPropertyNotify
457426 binary.LittleEndian.PutUint32(pn.Raw[4:], x.sel.in[0].requestor)
458427 binary.LittleEndian.PutUint32(pn.Raw[8:], r.data)
459- sink := make([]byte, 4096)
428+ sink := make([]byte, chunk)
460429 step := func() {
461430 x.onSelProperty(&pn)
462431 rep.Args = [4]uint32{0, x.sel.in[0].gen}
463432 x.onSelDataReply(rep)
464- if m, err := unix.Read(fds[0], sink); err != nil || m != 4096 {
433+ if m, err := unix.Read(fds[0], sink); err != nil || m != chunk {
465434 t.Fatal("read")
466435 }
467436 x.posted = false
@@ -636,30 +605,14 @@ func TestSelectionWaylandToXINCR(t *testing.T) {
636605 require.Equal(t, nXfer, r.x.sel.pool.n)
637606 }
638607
639-// fillOutChunk drives the mock fd loop between pipe-sized writes. A write of
640-// chunk bytes before dispatch would deadlock on hosts with smaller pipes.
641-func fillOutChunk(t *testing.T, r *selRig, w *os.File, onR *func()) {
642- t.Helper()
643- readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outActive })
644- data := pattern(chunk)
645- for off := 0; off < len(data); off += 4096 {
646- n, err := unix.Write(int(w.Fd()), data[off:off+4096])
647- require.NoError(t, err)
648- require.Equal(t, 4096, n)
649- require.NotNil(t, *onR)
650- (*onR)()
651- }
652- require.True(t, r.x.sel.out[0].incr)
653-}
654-
655608 func TestSelectionWaylandToXTimeoutAndClear(t *testing.T) {
656609 r := ownedByWayland(t, "text/plain;charset=utf-8")
657610 src := newMockfdSource(t)
658611 src.EXPECT().Remove().Return().Maybe()
659- var onR func()
660- r.x.lp = newFDLoop(t, r, src, &onR, nil)
612+ r.x.lp = newFDLoop(t, r, src, nil, nil)
661613 w := r.serve(t, r.utf8)
662- fillOutChunk(t, r, w, &onR)
614+ _, err := w.Write(pattern(chunk)) // a full chunk: INCR
615+ require.NoError(t, err)
663616 readUntil(t, r.x, func() bool { return r.x.sel.out[0].incr })
664617 require.Equal(t, r.data, sentNotify(t, r))
665618 require.NotNil(t, r.timer)
@@ -668,18 +621,15 @@ func TestSelectionWaylandToXTimeoutAndClear(t *testing.T) {
668621 r.timer()
669622 }
670623 require.Equal(t, outFree, r.x.sel.out[0].state, "no Deleted for 10 s aborts")
671- _, err := unix.Write(int(w.Fd()), []byte("late"))
672- require.ErrorIs(t, err, unix.EPIPE, "timeout closes the transfer reader")
673624 pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == opDeleteProperty && q.u32(4) == reqWin })
674625
675626 // SelectionClear aborts a running transfer and refuses further requests.
676627 w2 := r.serve(t, r.utf8)
677- fillOutChunk(t, r, w2, &onR)
628+ _, err = w2.Write(pattern(chunk))
629+ require.NoError(t, err)
678630 readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outActive })
679631 r.p.selectionClear(r.x.selWin, r.clip)
680632 readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outFree })
681- _, err = unix.Write(int(w2.Fd()), []byte("late"))
682- require.ErrorIs(t, err, unix.EPIPE, "clear closes the transfer reader")
683633 r.p.selectionRequest(r.x.selWin, reqWin, r.clip, r.utf8, r.data)
684634 require.Equal(t, r.data, sentNotify(t, r), "INCR announcement of the aborted transfer")
685635 require.Zero(t, sentNotify(t, r), "request after the clear is refused")
@@ -690,10 +640,10 @@ func TestSelectionClearAndRace(t *testing.T) {
690640 r := ownedByWayland(t, "text/plain;charset=utf-8")
691641 src := newMockfdSource(t)
692642 src.EXPECT().Remove().Return().Maybe()
693- var onR func()
694- r.x.lp = newFDLoop(t, r, src, &onR, nil)
643+ r.x.lp = newFDLoop(t, r, src, nil, nil)
695644 w := r.serve(t, r.utf8)
696- fillOutChunk(t, r, w, &onR)
645+ _, err := w.Write(pattern(chunk))
646+ require.NoError(t, err)
697647 readUntil(t, r.x, func() bool { return r.x.sel.out[0].incr })
698648 r.x.WaylandSelection(SelClipboard, []string{"text/plain"})
699649 require.Equal(t, outFree, r.x.sel.out[0].state)
@@ -233,25 +233,7 @@ func TestSelectionXToWaylandINCR(t *testing.T) {
233 r := ownedRig(t)233 r := ownedRig(t)
234 const total = 1 << 20234 const total = 1 << 20
235 want := pattern(total)235 want := pattern(total)
236- src := newMockfdSource(t)236+ f := r.receive(t, 1<<20)
237- var onW func()
238- r.x.lp = newFDLoop(t, r, src, nil, &onW)
239- src.EXPECT().SetWritable(mock.Anything).Return(nil).Maybe()
240- src.EXPECT().Remove().Return().Maybe()
241- f := r.receive(t, 4096)
242- type result struct {
243- data []byte
244- err error
245- }
246- done := make(chan result, 1)
247- finished := make(chan struct{})
248- go func() {
249- defer close(finished)
250- data, err := io.ReadAll(f)
251- done <- result{data, err}
252- }()
253- // Abort first: closing f does not interrupt a blocked read while the XWM holds the write end.
254- t.Cleanup(func() { r.x.selClose(); f.Close(); <-finished })
255 _, n := pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == 24 })237 _, n := pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == 24 })
256 r.skip = n238 r.skip = n
257 r.p.setProp(r.requestor, r.data, r.p.atom("INCR"), 32, le32(total))239 r.p.setProp(r.requestor, r.data, r.p.atom("INCR"), 32, le32(total))
@@ -269,18 +251,11 @@ func TestSelectionXToWaylandINCR(t *testing.T) {
269 r.p.propertyNotify(r.requestor, r.data, false)251 r.p.propertyNotify(r.requestor, r.data, false)
270 r.waitGet(t)252 r.waitGet(t)
271 gets++253 gets++
272- readUntil(t, r.x, func() bool {
273- for r.x.sel.in[0].state == inWriting {
274- waitSocket(t, r.x.sel.in[0].fd, unix.POLLOUT)
275- onW()
276- }
277- return r.x.sel.in[0].state == inWaitIncr || r.x.sel.in[0].state == inFree
278- })
279 }254 }
280 readUntil(t, r.x, func() bool { return r.x.sel.in[0].state == inFree })255 readUntil(t, r.x, func() bool { return r.x.sel.in[0].state == inFree })
281- got := <-done256+ got, err := io.ReadAll(f)
282- require.NoError(t, got.err)257+ require.NoError(t, err)
283- require.True(t, bytes.Equal(want, got.data), "byte-exact, got %d", len(got.data))258+ require.True(t, bytes.Equal(want, got), "byte-exact, got %d", len(got))
284 require.Equal(t, 1+total/chunk+1, gets, "marker, 16 chunks, empty terminator")259 require.Equal(t, 1+total/chunk+1, gets, "marker, 16 chunks, empty terminator")
285 require.NoError(t, r.x.conn.Sync(&r.x.h))260 require.NoError(t, r.x.conn.Sync(&r.x.h))
286 reused, err := r.x.newSelectionRequestor()261 reused, err := r.x.newSelectionRequestor()
@@ -298,18 +273,15 @@ func TestSelectionXToWaylandBackpressure(t *testing.T) {
298 src.EXPECT().SetWritable(true).Return(nil).Once()273 src.EXPECT().SetWritable(true).Return(nil).Once()
299 src.EXPECT().SetWritable(false).Return(nil).Once()274 src.EXPECT().SetWritable(false).Return(nil).Once()
300 src.EXPECT().Remove().Return().Once()275 src.EXPECT().Remove().Return().Once()
301- f := r.receive(t, 4096) // force backpressure independent of host pipe limits276+ f := r.receive(t, 0) // default 64 KiB pipe
302- // The kernel rounds the request up to its page size: use the real capacity.
303- piece, err := unix.FcntlInt(f.Fd(), unix.F_GETPIPE_SZ, 0)
304- require.NoError(t, err)
305 _, n := pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == 24 })277 _, n := pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == 24 })
306 r.skip = n278 r.skip = n
307- r.p.setProp(r.requestor, r.data, r.p.atom("INCR"), 32, le32(uint32(3*piece)))279+ r.p.setProp(r.requestor, r.data, r.p.atom("INCR"), 32, le32(3*chunk))
308 r.p.selectionNotify(r.requestor, r.clip, r.utf8, r.data)280 r.p.selectionNotify(r.requestor, r.clip, r.utf8, r.data)
309 r.waitGet(t)281 r.waitGet(t)
310- want := pattern(3 * piece)282+ want := pattern(3 * chunk)
311 chunkN := func(k int) {283 chunkN := func(k int) {
312- r.p.setProp(r.requestor, r.data, r.utf8, 8, want[k*piece:(k+1)*piece])284+ r.p.setProp(r.requestor, r.data, r.utf8, 8, want[k*chunk:(k+1)*chunk])
313 r.p.propertyNotify(r.requestor, r.data, false)285 r.p.propertyNotify(r.requestor, r.data, false)
314 }286 }
315 chunkN(0) // fills the pipe exactly287 chunkN(0) // fills the pipe exactly
@@ -327,8 +299,8 @@ func TestSelectionXToWaylandBackpressure(t *testing.T) {
327 r.x.flush()299 r.x.flush()
328 require.Equal(t, gets, getProps(r.p, 0, r.requestor), "no GetProperty while a buffer is pending")300 require.Equal(t, gets, getProps(r.p, 0, r.requestor), "no GetProperty while a buffer is pending")
329 301
330- got := make([]byte, 0, 3*piece)302+ got := make([]byte, 0, 3*chunk)
331- buf := make([]byte, piece)303+ buf := make([]byte, chunk)
332 m, err := f.Read(buf) // the reader wakes: room again304 m, err := f.Read(buf) // the reader wakes: room again
333 require.NoError(t, err)305 require.NoError(t, err)
334 got = append(got, buf[:m]...)306 got = append(got, buf[:m]...)
@@ -448,20 +420,17 @@ func TestSelectionINCRChunkAllocations(t *testing.T) {
448 x.onSelectionNotify(&note)420 x.onSelectionNotify(&note)
449 x.onSelDataReply(dataReply(r, r.p.atom("INCR"), le32(1<<20)))421 x.onSelDataReply(dataReply(r, r.p.atom("INCR"), le32(1<<20)))
450 require.Equal(t, inWaitIncr, x.sel.in[0].state)422 require.Equal(t, inWaitIncr, x.sel.in[0].state)
451- // INCR chunks need not fill the protocol buffer. Keep this hot-path423+ rep := dataReply(r, r.utf8, pattern(chunk))
452- // allocation measurement within one pipe page; full-size chunks and
453- // writable callbacks are exercised by TestSelectionXToWaylandINCR.
454- rep := dataReply(r, r.utf8, pattern(4096))
455 var pn xturbo.Event424 var pn xturbo.Event
456 pn.Kind = xproto.KindPropertyNotify425 pn.Kind = xproto.KindPropertyNotify
457 binary.LittleEndian.PutUint32(pn.Raw[4:], x.sel.in[0].requestor)426 binary.LittleEndian.PutUint32(pn.Raw[4:], x.sel.in[0].requestor)
458 binary.LittleEndian.PutUint32(pn.Raw[8:], r.data)427 binary.LittleEndian.PutUint32(pn.Raw[8:], r.data)
459- sink := make([]byte, 4096)428+ sink := make([]byte, chunk)
460 step := func() {429 step := func() {
461 x.onSelProperty(&pn)430 x.onSelProperty(&pn)
462 rep.Args = [4]uint32{0, x.sel.in[0].gen}431 rep.Args = [4]uint32{0, x.sel.in[0].gen}
463 x.onSelDataReply(rep)432 x.onSelDataReply(rep)
464- if m, err := unix.Read(fds[0], sink); err != nil || m != 4096 {433+ if m, err := unix.Read(fds[0], sink); err != nil || m != chunk {
465 t.Fatal("read")434 t.Fatal("read")
466 }435 }
467 x.posted = false436 x.posted = false
@@ -636,30 +605,14 @@ func TestSelectionWaylandToXINCR(t *testing.T) {
636 require.Equal(t, nXfer, r.x.sel.pool.n)605 require.Equal(t, nXfer, r.x.sel.pool.n)
637 }606 }
638 607
639-// fillOutChunk drives the mock fd loop between pipe-sized writes. A write of
640-// chunk bytes before dispatch would deadlock on hosts with smaller pipes.
641-func fillOutChunk(t *testing.T, r *selRig, w *os.File, onR *func()) {
642- t.Helper()
643- readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outActive })
644- data := pattern(chunk)
645- for off := 0; off < len(data); off += 4096 {
646- n, err := unix.Write(int(w.Fd()), data[off:off+4096])
647- require.NoError(t, err)
648- require.Equal(t, 4096, n)
649- require.NotNil(t, *onR)
650- (*onR)()
651- }
652- require.True(t, r.x.sel.out[0].incr)
653-}
654-
655 func TestSelectionWaylandToXTimeoutAndClear(t *testing.T) {608 func TestSelectionWaylandToXTimeoutAndClear(t *testing.T) {
656 r := ownedByWayland(t, "text/plain;charset=utf-8")609 r := ownedByWayland(t, "text/plain;charset=utf-8")
657 src := newMockfdSource(t)610 src := newMockfdSource(t)
658 src.EXPECT().Remove().Return().Maybe()611 src.EXPECT().Remove().Return().Maybe()
659- var onR func()612+ r.x.lp = newFDLoop(t, r, src, nil, nil)
660- r.x.lp = newFDLoop(t, r, src, &onR, nil)
661 w := r.serve(t, r.utf8)613 w := r.serve(t, r.utf8)
662- fillOutChunk(t, r, w, &onR)614+ _, err := w.Write(pattern(chunk)) // a full chunk: INCR
615+ require.NoError(t, err)
663 readUntil(t, r.x, func() bool { return r.x.sel.out[0].incr })616 readUntil(t, r.x, func() bool { return r.x.sel.out[0].incr })
664 require.Equal(t, r.data, sentNotify(t, r))617 require.Equal(t, r.data, sentNotify(t, r))
665 require.NotNil(t, r.timer)618 require.NotNil(t, r.timer)
@@ -668,18 +621,15 @@ func TestSelectionWaylandToXTimeoutAndClear(t *testing.T) {
668 r.timer()621 r.timer()
669 }622 }
670 require.Equal(t, outFree, r.x.sel.out[0].state, "no Deleted for 10 s aborts")623 require.Equal(t, outFree, r.x.sel.out[0].state, "no Deleted for 10 s aborts")
671- _, err := unix.Write(int(w.Fd()), []byte("late"))
672- require.ErrorIs(t, err, unix.EPIPE, "timeout closes the transfer reader")
673 pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == opDeleteProperty && q.u32(4) == reqWin })624 pumpReq(t, r.x, r.p, r.skip, func(q xpeerReq) bool { return q.major == opDeleteProperty && q.u32(4) == reqWin })
674 625
675 // SelectionClear aborts a running transfer and refuses further requests.626 // SelectionClear aborts a running transfer and refuses further requests.
676 w2 := r.serve(t, r.utf8)627 w2 := r.serve(t, r.utf8)
677- fillOutChunk(t, r, w2, &onR)628+ _, err = w2.Write(pattern(chunk))
629+ require.NoError(t, err)
678 readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outActive })630 readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outActive })
679 r.p.selectionClear(r.x.selWin, r.clip)631 r.p.selectionClear(r.x.selWin, r.clip)
680 readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outFree })632 readUntil(t, r.x, func() bool { return r.x.sel.out[0].state == outFree })
681- _, err = unix.Write(int(w2.Fd()), []byte("late"))
682- require.ErrorIs(t, err, unix.EPIPE, "clear closes the transfer reader")
683 r.p.selectionRequest(r.x.selWin, reqWin, r.clip, r.utf8, r.data)633 r.p.selectionRequest(r.x.selWin, reqWin, r.clip, r.utf8, r.data)
684 require.Equal(t, r.data, sentNotify(t, r), "INCR announcement of the aborted transfer")634 require.Equal(t, r.data, sentNotify(t, r), "INCR announcement of the aborted transfer")
685 require.Zero(t, sentNotify(t, r), "request after the clear is refused")635 require.Zero(t, sentNotify(t, r), "request after the clear is refused")
@@ -690,10 +640,10 @@ func TestSelectionClearAndRace(t *testing.T) {
690 r := ownedByWayland(t, "text/plain;charset=utf-8")640 r := ownedByWayland(t, "text/plain;charset=utf-8")
691 src := newMockfdSource(t)641 src := newMockfdSource(t)
692 src.EXPECT().Remove().Return().Maybe()642 src.EXPECT().Remove().Return().Maybe()
693- var onR func()643+ r.x.lp = newFDLoop(t, r, src, nil, nil)
694- r.x.lp = newFDLoop(t, r, src, &onR, nil)
695 w := r.serve(t, r.utf8)644 w := r.serve(t, r.utf8)
696- fillOutChunk(t, r, w, &onR)645+ _, err := w.Write(pattern(chunk))
646+ require.NoError(t, err)
697 readUntil(t, r.x, func() bool { return r.x.sel.out[0].incr })647 readUntil(t, r.x, func() bool { return r.x.sel.out[0].incr })
698 r.x.WaylandSelection(SelClipboard, []string{"text/plain"})648 r.x.WaylandSelection(SelClipboard, []string{"text/plain"})
699 require.Equal(t, outFree, r.x.sel.out[0].state)649 require.Equal(t, outFree, r.x.sel.out[0].state)
M internal/core/client.go +3 -1
@@ -78,7 +78,9 @@ func (c *Core) clientEvent(ctx context.Context, ev ports.ClientEvent) (publish,
7878 c.windows.setContentType(v.ID, v.Type)
7979 c.publishState()
8080 case ports.WindowTitle:
81- c.windowTitle(v)
81+ if c.windowTitle(ctx, v) != nil {
82+ return false, true
83+ }
8284 case ports.WindowAppID:
8385 c.windows.setAppID(v.ID, v.AppID)
8486 c.matchWindowExpansion(v.ID)
@@ -78,7 +78,9 @@ func (c *Core) clientEvent(ctx context.Context, ev ports.ClientEvent) (publish,
78 c.windows.setContentType(v.ID, v.Type)78 c.windows.setContentType(v.ID, v.Type)
79 c.publishState()79 c.publishState()
80 case ports.WindowTitle:80 case ports.WindowTitle:
81- c.windowTitle(v)81+ if c.windowTitle(ctx, v) != nil {
82+ return false, true
83+ }
82 case ports.WindowAppID:84 case ports.WindowAppID:
83 c.windows.setAppID(v.ID, v.AppID)85 c.windows.setAppID(v.ID, v.AppID)
84 c.matchWindowExpansion(v.ID)86 c.matchWindowExpansion(v.ID)
M internal/core/rules.go +15 -5
@@ -1,6 +1,7 @@
11 package core
22
33 import (
4+ "context"
45 "fmt"
56 "regexp"
67 "slices"
@@ -209,10 +210,10 @@ func (c *Core) rememberTitleRules(id WindowID) {
209210 }
210211 }
211212
212-func (c *Core) windowTitle(v ports.WindowTitle) {
213+func (c *Core) windowTitle(ctx context.Context, v ports.WindowTitle) error {
213214 rec := c.windows.records[v.ID]
214215 if rec == nil || rec.client.ID == 0 {
215- return
216+ return nil
216217 }
217218 old := rec.client.Title
218219 rec.client.Title = v.Title
@@ -233,19 +234,28 @@ func (c *Core) windowTitle(v ports.WindowTitle) {
233234 }
234235 c.matchWindowExpansion(v.ID)
235236 if !apply {
236- return
237+ return nil
237238 }
238239 fromScreen, from := c.screenOf(v.ID)
239240 if from == nil {
240- return
241+ return nil
241242 }
242243 toScreen, to := c.ruleTarget(eff)
243244 if from == to {
244- return
245+ return nil
245246 }
247+ focused, _ := c.cur().mon.Focused()
248+ // An open overview owns the source output's selection; leave it alone.
249+ held := focused == v.ID && fromScreen == c.cur() && !fromScreen.mon.ov.open
246250 workspacedomain.MoveByRule(from, to, v.ID)
247251 fromScreen.mon.normalize()
248252 toScreen.mon.normalize()
253+ // The focused window stays focused on its new output, even an isolated
254+ // one: the rule moved it, not the user's attention.
255+ if held && to.Has(v.ID) {
256+ return c.activate(ctx, v.ID)
257+ }
258+ return nil
249259 }
250260
251261 func (c *Core) titleHistory(id WindowID) *titleRuleHistory {
@@ -1,6 +1,7 @@
1 package core1 package core
2 2
3 import (3 import (
4+ "context"
4 "fmt"5 "fmt"
5 "regexp"6 "regexp"
6 "slices"7 "slices"
@@ -209,10 +210,10 @@ func (c *Core) rememberTitleRules(id WindowID) {
209 }210 }
210 }211 }
211 212
212-func (c *Core) windowTitle(v ports.WindowTitle) {213+func (c *Core) windowTitle(ctx context.Context, v ports.WindowTitle) error {
213 rec := c.windows.records[v.ID]214 rec := c.windows.records[v.ID]
214 if rec == nil || rec.client.ID == 0 {215 if rec == nil || rec.client.ID == 0 {
215- return216+ return nil
216 }217 }
217 old := rec.client.Title218 old := rec.client.Title
218 rec.client.Title = v.Title219 rec.client.Title = v.Title
@@ -233,19 +234,28 @@ func (c *Core) windowTitle(v ports.WindowTitle) {
233 }234 }
234 c.matchWindowExpansion(v.ID)235 c.matchWindowExpansion(v.ID)
235 if !apply {236 if !apply {
236- return237+ return nil
237 }238 }
238 fromScreen, from := c.screenOf(v.ID)239 fromScreen, from := c.screenOf(v.ID)
239 if from == nil {240 if from == nil {
240- return241+ return nil
241 }242 }
242 toScreen, to := c.ruleTarget(eff)243 toScreen, to := c.ruleTarget(eff)
243 if from == to {244 if from == to {
244- return245+ return nil
245 }246 }
247+ focused, _ := c.cur().mon.Focused()
248+ // An open overview owns the source output's selection; leave it alone.
249+ held := focused == v.ID && fromScreen == c.cur() && !fromScreen.mon.ov.open
246 workspacedomain.MoveByRule(from, to, v.ID)250 workspacedomain.MoveByRule(from, to, v.ID)
247 fromScreen.mon.normalize()251 fromScreen.mon.normalize()
248 toScreen.mon.normalize()252 toScreen.mon.normalize()
253+ // The focused window stays focused on its new output, even an isolated
254+ // one: the rule moved it, not the user's attention.
255+ if held && to.Has(v.ID) {
256+ return c.activate(ctx, v.ID)
257+ }
258+ return nil
249 }259 }
250 260
251 func (c *Core) titleHistory(id WindowID) *titleRuleHistory {261 func (c *Core) titleHistory(id WindowID) *titleRuleHistory {
M internal/core/rules_match_test.go +4 -4
@@ -83,12 +83,12 @@ func TestTitleMatchingAndExpansion(t *testing.T) {
8383 if c.windows.lookup(1).expansionRule != (ruleEffect{}) {
8484 t.Fatal("early title match")
8585 }
86- c.windowTitle(ports.WindowTitle{ID: 1, Title: "BIG PICTURE mode"})
86+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "BIG PICTURE mode"})
8787 eff := c.windows.lookup(1).expansionRule
8888 if eff.sdrExpand != &on || eff.sdrExpandIntensity != &intensity || eff.sdrExpandPeak != &peak || eff.sdrDecode != &decode {
8989 t.Fatal(eff)
9090 }
91- c.windowTitle(ports.WindowTitle{ID: 1, Title: "launcher"})
91+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "launcher"})
9292 if c.windows.lookup(1).expansionRule != (ruleEffect{}) {
9393 t.Fatal("stale expansion match")
9494 }
@@ -104,8 +104,8 @@ func TestMapTimeTitleMatchIsRemembered(t *testing.T) {
104104 t.Fatal(eff)
105105 }
106106 c.rememberTitleRules(1)
107- c.windowTitle(ports.WindowTitle{ID: 1, Title: "loading"})
108- c.windowTitle(ports.WindowTitle{ID: 1, Title: "ready"})
107+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "loading"})
108+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "ready"})
109109 if !c.windows.lookup(1).appliedTitleRules.applied["title"] {
110110 t.Fatal("map match not remembered")
111111 }
@@ -83,12 +83,12 @@ func TestTitleMatchingAndExpansion(t *testing.T) {
83 if c.windows.lookup(1).expansionRule != (ruleEffect{}) {83 if c.windows.lookup(1).expansionRule != (ruleEffect{}) {
84 t.Fatal("early title match")84 t.Fatal("early title match")
85 }85 }
86- c.windowTitle(ports.WindowTitle{ID: 1, Title: "BIG PICTURE mode"})86+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "BIG PICTURE mode"})
87 eff := c.windows.lookup(1).expansionRule87 eff := c.windows.lookup(1).expansionRule
88 if eff.sdrExpand != &on || eff.sdrExpandIntensity != &intensity || eff.sdrExpandPeak != &peak || eff.sdrDecode != &decode {88 if eff.sdrExpand != &on || eff.sdrExpandIntensity != &intensity || eff.sdrExpandPeak != &peak || eff.sdrDecode != &decode {
89 t.Fatal(eff)89 t.Fatal(eff)
90 }90 }
91- c.windowTitle(ports.WindowTitle{ID: 1, Title: "launcher"})91+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "launcher"})
92 if c.windows.lookup(1).expansionRule != (ruleEffect{}) {92 if c.windows.lookup(1).expansionRule != (ruleEffect{}) {
93 t.Fatal("stale expansion match")93 t.Fatal("stale expansion match")
94 }94 }
@@ -104,8 +104,8 @@ func TestMapTimeTitleMatchIsRemembered(t *testing.T) {
104 t.Fatal(eff)104 t.Fatal(eff)
105 }105 }
106 c.rememberTitleRules(1)106 c.rememberTitleRules(1)
107- c.windowTitle(ports.WindowTitle{ID: 1, Title: "loading"})107+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "loading"})
108- c.windowTitle(ports.WindowTitle{ID: 1, Title: "ready"})108+ _ = c.windowTitle(t.Context(), ports.WindowTitle{ID: 1, Title: "ready"})
109 if !c.windows.lookup(1).appliedTitleRules.applied["title"] {109 if !c.windows.lookup(1).appliedTitleRules.applied["title"] {
110 t.Fatal("map match not remembered")110 t.Fatal("map match not remembered")
111 }111 }
M internal/core/rules_test.go +80 -0
@@ -584,3 +584,83 @@ func TestTitleRuleMovesOnceWithoutFocus(t *testing.T) {
584584 }
585585 })
586586 }
587+
588+func drainCommands(ch chan ports.ClientCommand) []ports.ClientCommand {
589+ var out []ports.ClientCommand
590+ for {
591+ select {
592+ case v := <-ch:
593+ if s, ok := v.(ports.SecurityCommand); ok {
594+ v = s.Command
595+ }
596+ out = append(out, v)
597+ default:
598+ return out
599+ }
600+ }
601+}
602+
603+func TestTitleRuleMoveKeepsFocusOfFocusedWindow(t *testing.T) {
604+ tv := domain.OutputInfo{Name: "tv", Virtual: true, Width: 640, Height: 360}
605+ for _, tc := range []struct {
606+ name string
607+ out string
608+ ws string
609+ outs []domain.OutputInfo
610+ setup func(t *testing.T, r *multiRig)
611+ wantOut string
612+ wantFocus domain.WindowID // 0: anything but the moved window
613+ held bool
614+ }{
615+ {name: "placed", out: "DP-2", outs: []domain.OutputInfo{left, right}, wantOut: "DP-2", wantFocus: 1, held: true},
616+ {name: "isolated", out: "tv", outs: []domain.OutputInfo{left, tv}, wantOut: "tv", wantFocus: 1, held: true},
617+ {name: "workspace not current", out: "DP-2", ws: "2", outs: []domain.OutputInfo{left, right}, setup: func(t *testing.T, r *multiRig) {
618+ r.mapApp(t, 3, "side") // fills DP-2's current workspace; a spare follows
619+ }, wantOut: "DP-2", wantFocus: 1, held: true},
620+ {name: "focus on another output", out: "tv", outs: []domain.OutputInfo{left, right, tv}, setup: func(t *testing.T, r *multiRig) {
621+ r.key(t, "Right", domain.ModAlt|domain.ModCtrl)
622+ }, wantOut: "DP-2"},
623+ {name: "overview open", out: "DP-2", outs: []domain.OutputInfo{left, right}, setup: func(t *testing.T, r *multiRig) {
624+ r.key(t, "F12", domain.ModAlt)
625+ }, wantOut: "DP-1"},
626+ } {
627+ t.Run(tc.name, func(t *testing.T) {
628+ synctest.Test(t, func(t *testing.T) {
629+ r := startMulti(t, func(c *domain.Config) {
630+ c.Binds["Alt+F12"] = "toggle-overview"
631+ c.Outputs = []domain.OutputConfig{{Name: "DP-1"}, {Name: "DP-2"}, {Name: "tv", Virtual: true}}
632+ c.Rules = []domain.WindowRule{
633+ winRule("title", "game", func(r *domain.WindowRule) {
634+ r.Title = regexp.MustCompile("(?i)big picture")
635+ r.Output = tc.out
636+ r.Workspace = tc.ws
637+ }),
638+ winRule("side", "side", func(r *domain.WindowRule) { r.Output = "DP-2" }),
639+ }
640+ }, tc.outs...)
641+ r.mapApp(t, 2, "term")
642+ r.client <- ports.WindowMapped{ID: 1, AppID: "game", Title: "launcher", Xwayland: true}
643+ stateAfter(t, r.state, func(st domain.State) bool { return stFocus(st) == 1 && st.Output == "DP-1" })
644+ if tc.setup != nil {
645+ tc.setup(t, r)
646+ }
647+ synctest.Wait()
648+ drainCommands(r.commands)
649+ r.client <- ports.WindowTitle{ID: 1, Title: "Steam Big Picture Mode"}
650+ st := stateAfter(t, r.state, func(st domain.State) bool { w := stWindow(st, 1); return w != nil && w.Output == tc.out })
651+ if st.Output != tc.wantOut || (tc.wantFocus != 0 && stFocus(st) != tc.wantFocus) || (tc.wantFocus == 0 && stFocus(st) == 1) {
652+ t.Fatalf("focus %d on %s", stFocus(st), st.Output)
653+ }
654+ if tc.held && stOutput(st, tc.out).Active != stWindow(st, 1).Workspace {
655+ t.Fatalf("destination workspace not shown: %+v", stOutput(st, tc.out))
656+ }
657+ synctest.Wait()
658+ for _, id := range focusChanges(drainCommands(r.commands)) {
659+ if tc.held && id != 1 || !tc.held && id == 1 {
660+ t.Fatalf("focus sent to %d", id)
661+ }
662+ }
663+ })
664+ })
665+ }
666+}
@@ -584,3 +584,83 @@ func TestTitleRuleMovesOnceWithoutFocus(t *testing.T) {
584 }584 }
585 })585 })
586 }586 }
587+
588+func drainCommands(ch chan ports.ClientCommand) []ports.ClientCommand {
589+ var out []ports.ClientCommand
590+ for {
591+ select {
592+ case v := <-ch:
593+ if s, ok := v.(ports.SecurityCommand); ok {
594+ v = s.Command
595+ }
596+ out = append(out, v)
597+ default:
598+ return out
599+ }
600+ }
601+}
602+
603+func TestTitleRuleMoveKeepsFocusOfFocusedWindow(t *testing.T) {
604+ tv := domain.OutputInfo{Name: "tv", Virtual: true, Width: 640, Height: 360}
605+ for _, tc := range []struct {
606+ name string
607+ out string
608+ ws string
609+ outs []domain.OutputInfo
610+ setup func(t *testing.T, r *multiRig)
611+ wantOut string
612+ wantFocus domain.WindowID // 0: anything but the moved window
613+ held bool
614+ }{
615+ {name: "placed", out: "DP-2", outs: []domain.OutputInfo{left, right}, wantOut: "DP-2", wantFocus: 1, held: true},
616+ {name: "isolated", out: "tv", outs: []domain.OutputInfo{left, tv}, wantOut: "tv", wantFocus: 1, held: true},
617+ {name: "workspace not current", out: "DP-2", ws: "2", outs: []domain.OutputInfo{left, right}, setup: func(t *testing.T, r *multiRig) {
618+ r.mapApp(t, 3, "side") // fills DP-2's current workspace; a spare follows
619+ }, wantOut: "DP-2", wantFocus: 1, held: true},
620+ {name: "focus on another output", out: "tv", outs: []domain.OutputInfo{left, right, tv}, setup: func(t *testing.T, r *multiRig) {
621+ r.key(t, "Right", domain.ModAlt|domain.ModCtrl)
622+ }, wantOut: "DP-2"},
623+ {name: "overview open", out: "DP-2", outs: []domain.OutputInfo{left, right}, setup: func(t *testing.T, r *multiRig) {
624+ r.key(t, "F12", domain.ModAlt)
625+ }, wantOut: "DP-1"},
626+ } {
627+ t.Run(tc.name, func(t *testing.T) {
628+ synctest.Test(t, func(t *testing.T) {
629+ r := startMulti(t, func(c *domain.Config) {
630+ c.Binds["Alt+F12"] = "toggle-overview"
631+ c.Outputs = []domain.OutputConfig{{Name: "DP-1"}, {Name: "DP-2"}, {Name: "tv", Virtual: true}}
632+ c.Rules = []domain.WindowRule{
633+ winRule("title", "game", func(r *domain.WindowRule) {
634+ r.Title = regexp.MustCompile("(?i)big picture")
635+ r.Output = tc.out
636+ r.Workspace = tc.ws
637+ }),
638+ winRule("side", "side", func(r *domain.WindowRule) { r.Output = "DP-2" }),
639+ }
640+ }, tc.outs...)
641+ r.mapApp(t, 2, "term")
642+ r.client <- ports.WindowMapped{ID: 1, AppID: "game", Title: "launcher", Xwayland: true}
643+ stateAfter(t, r.state, func(st domain.State) bool { return stFocus(st) == 1 && st.Output == "DP-1" })
644+ if tc.setup != nil {
645+ tc.setup(t, r)
646+ }
647+ synctest.Wait()
648+ drainCommands(r.commands)
649+ r.client <- ports.WindowTitle{ID: 1, Title: "Steam Big Picture Mode"}
650+ st := stateAfter(t, r.state, func(st domain.State) bool { w := stWindow(st, 1); return w != nil && w.Output == tc.out })
651+ if st.Output != tc.wantOut || (tc.wantFocus != 0 && stFocus(st) != tc.wantFocus) || (tc.wantFocus == 0 && stFocus(st) == 1) {
652+ t.Fatalf("focus %d on %s", stFocus(st), st.Output)
653+ }
654+ if tc.held && stOutput(st, tc.out).Active != stWindow(st, 1).Workspace {
655+ t.Fatalf("destination workspace not shown: %+v", stOutput(st, tc.out))
656+ }
657+ synctest.Wait()
658+ for _, id := range focusChanges(drainCommands(r.commands)) {
659+ if tc.held && id != 1 || !tc.held && id == 1 {
660+ t.Fatalf("focus sent to %d", id)
661+ }
662+ }
663+ })
664+ })
665+ }
666+}

Comments00 unresolved

    no comments yet.

    Keyboard shortcuts

    Single-key shortcuts are on. ctrl k and esc work whatever this says.

    ctrl k :
    go to a section, branch, tag, file or repository
    ?
    this list
    j k
    move the row cursor down / up
    enter
    open the row under the cursor; on Files, a directory opens or closes in place
    ↑ ↓ ← → home end
    in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
    l h
    on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. On pages with a side panel: into the panel (on a merge request, its files) / back to the content; there j k move between its controls
    g g G
    first / last row
    /
    filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
    b
    switch branch or tag
    g s g f g c g b g m g i g r g a
    tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
    g h
    home
    w
    wide mode: use the whole width of the screen, or not (remembered)
    y
    copy a permalink pinned to the commit; in a file, click a line number to select it, shift-click for a range
    d u x
    diff: split / unified / collapse or expand all
    e E
    diff: the whole file in view / every file, with the lines the hunks hide
    n
    merge request: next note in the diff
    l
    merge request: the list of files (j k move, enter opens, esc back)
    M
    merge request: the merge menu; there 1–3 pick the mode, D deletes the branch, enter merges
    R
    merge request: mark the head read
    esc
    close a dialog, leave a field

    Branches 33

    Tags 15

    ↑↓ moveenter openesc close