core_test.go RawHistoryFolder

1package core_test
2
3import (
4	"context"
5	"errors"
6	"reflect"
7	"slices"
8	"testing"
9	"time"
10
11	"github.com/bnema/neferwl/internal/adapters/config"
12	"github.com/bnema/neferwl/internal/core"
13	"github.com/bnema/neferwl/internal/ports"
14)
15
16func receive[T any](t *testing.T, ch <-chan T) T {
17	t.Helper()
18	select {
19	case v := <-ch:
20		return v
21	case <-time.After(time.Second):
22		t.Fatal("timed out")
23		var zero T
24		return zero
25	}
26}
27
28// scene receives the next scene set and returns the first output's scene.
29func scene(t *testing.T, ch <-chan []ports.Scene) ports.Scene {
30	t.Helper()
31	return receive(t, ch)[0]
32}
33
34// command receives the next client command, skipping output scale updates
35// and user activity reports.
36func command(t *testing.T, ch <-chan ports.ClientCommand) ports.ClientCommand {
37	t.Helper()
38	for {
39		switch v := receive(t, ch); v.(type) {
40		case nil, ports.SetOutputs, ports.UserActivity:
41		default:
42			return v
43		}
44	}
45}
46
47// modeLanding gives a hand-rolled core test its animation mode: off, or on with
48// a clock the test moves and the page flips it sends. land returns the scene
49// set once every spring has landed (the set itself when none runs, and
50// always with animations off). An on run that never saw a spring would be
51// the off run again, so it fails.
52type modeLanding struct {
53	t       *testing.T
54	clk     *stepClock
55	frames  chan ports.OutputFrame
56	scenes  chan []ports.Scene
57	outputs []string
58	lands   int
59}
60
61// newLanding sets cfg's animations and, when on, the clock of opts and flips of ch.
62func newLanding(t *testing.T, animated bool, cfg *ports.Config, ch *core.Channels, opts *core.Options, outputs ...string) *modeLanding {
63	t.Helper()
64	cfg.Animations.On = animated
65	l := &modeLanding{t: t, scenes: ch.Scenes, outputs: outputs}
66	if animated {
67		l.clk, l.frames = newStepClock(t), make(chan ports.OutputFrame)
68		opts.Clock, ch.Frames = l.clk.clock, l.frames
69		t.Cleanup(func() {
70			if l.lands == 0 {
71				t.Error("no spring ever ran: the animations-on variant checked nothing")
72			}
73		})
74	}
75	return l
76}
77
78func (l *modeLanding) land(set []ports.Scene) []ports.Scene {
79	l.t.Helper()
80	if l.clk == nil {
81		return set
82	}
83	landed, ok := l.clk.settle(l.t, l.frames, l.scenes, l.outputs...)
84	if !ok {
85		return set
86	}
87	l.lands++
88	return landed
89}
90
91// one is land for the first output's scene.
92func (l *modeLanding) one(s ports.Scene) ports.Scene { return l.land([]ports.Scene{s})[0] }
93
94func TestOwner(t *testing.T) { both(t, owner) }
95
96func owner(t *testing.T, animated bool) {
97	cfg := altCmdDefaults()
98	cfg.Border.Width = 0
99	cfg.Layout.Gaps = 8
100	client := make(chan ports.ClientEvent, 128)
101	input := make(chan ports.InputEvent, 32)
102	output := make(chan ports.OutputEvent, 8)
103	reload := make(chan ports.ConfigChanged, 8)
104	commands := make(chan ports.ClientCommand, 256)
105	spawn := make(chan ports.SpawnRequest, 8)
106	scenes := make(chan []ports.Scene, 1)
107	errs := make(chan error, 8)
108	ch := core.Channels{Client: client, Input: input, Output: output, Config: reload, Commands: commands, Spawn: spawn, Scenes: scenes, ConfigErrors: errs}
109	opts := core.Options{}
110	l := newLanding(t, animated, &cfg, &ch, &opts, "OUT-1")
111	c, err := core.New(cfg, ch, opts)
112	if err != nil {
113		t.Fatal(err)
114	}
115	ctx, cancel := context.WithCancel(context.Background())
116	defer cancel()
117	done := make(chan error, 1)
118	go func() { done <- c.Run(ctx) }()
119	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
120	s := scene(t, scenes)
121	if s.OutputWidth != 100 {
122		t.Fatal(s)
123	}
124	client <- ports.WindowMapped{ID: 1}
125	s = l.one(scene(t, scenes))
126	// A single column fills the usable width.
127	if len(s.Windows) != 1 || s.Windows[0].Rect.W != 84 || s.Windows[0].Inset != 0 {
128		t.Fatal(s)
129	}
130	if v := command(t, commands); v != (ports.ConfigureWindow{ID: 1, Width: 84, Height: 64, Activated: true, Output: "OUT-1", Visible: true}) {
131		t.Fatal(v)
132	}
133	command(t, commands)
134	client <- ports.WindowMapped{ID: 2}
135	s = scene(t, scenes)
136	if len(s.Windows) != 2 {
137		t.Fatal(s)
138	}
139	// Commands for focus changes and second mapping.
140	for len(commands) > 0 {
141		<-commands
142	}
143	client <- ports.WindowMapped{ID: 2}
144	scene(t, scenes)
145	if len(commands) != 0 {
146		t.Fatal("duplicate configure")
147	}
148	input <- ports.KeyEvent{Keysym: "Return", Mods: ports.ModAlt, Pressed: true}
149	scene(t, scenes)
150	if v := receive(t, spawn); len(v.Argv) != 1 || v.Argv[0] != "foot" {
151		t.Fatal(v)
152	}
153	input <- ports.KeyEvent{Keysym: "Return", Mods: ports.ModAlt}
154	input <- ports.KeyEvent{Keysym: "x", Pressed: true}
155	if v := command(t, commands); v != (ports.ForwardKey{ID: 2, Key: ports.KeyEvent{Keysym: "x", Pressed: true}}) {
156		t.Fatal(v)
157	}
158	input <- ports.KeyEvent{Keysym: "Q", Mods: ports.ModAlt, Pressed: true}
159	scene(t, scenes)
160	if v := command(t, commands); v != (ports.CloseWindow{ID: 2}) {
161		t.Fatal(v)
162	}
163	client <- ports.WindowUnmapped{ID: 2}
164	scene(t, scenes)
165	for len(commands) > 0 {
166		<-commands
167	}
168	cfg.Layout.Gaps = 4
169	reload <- ports.ConfigChanged{Config: cfg}
170	s = l.one(scene(t, scenes))
171	if s.Windows[0].Rect.W != 92 {
172		t.Fatal(s)
173	}
174	if v := command(t, commands); v != (ports.ConfigureWindow{ID: 1, Width: 92, Height: 72, Activated: true, Output: "OUT-1", Visible: true}) {
175		t.Fatal(v)
176	}
177	cfg.Layout.MaxColumns = 0
178	reload <- ports.ConfigChanged{Config: cfg}
179	receive(t, errs)
180	for i := 0; i < 100; i++ {
181		client <- ports.WindowMapped{ID: ports.WindowID(i + 3)}
182	}
183	input <- ports.KeyEvent{Keysym: "BackSpace", Mods: ports.ModCtrl | ports.ModAlt, Pressed: true}
184	if err := receive(t, done); !errors.Is(err, core.ErrQuit) {
185		t.Fatal(err)
186	}
187}
188func TestCancelAndSceneCapacity(t *testing.T) {
189	cfg := config.Defaults()
190	if _, err := core.New(cfg, core.Channels{Scenes: make(chan []ports.Scene, 2)}, core.Options{}); err == nil {
191		t.Fatal("capacity")
192	}
193	ctx, cancel := context.WithCancel(context.Background())
194	c, err := core.New(cfg, core.Channels{Scenes: make(chan []ports.Scene, 1)}, core.Options{})
195	if err != nil {
196		t.Fatal(err)
197	}
198	done := make(chan error, 1)
199	go func() { done <- c.Run(ctx) }()
200	cancel()
201	if err := receive(t, done); err != nil {
202		t.Fatal(err)
203	}
204}
205
206func TestKeyPressState(t *testing.T) {
207	cfg := config.Defaults()
208	client := make(chan ports.ClientEvent, 8)
209	input := make(chan ports.InputEvent, 8)
210	commands := make(chan ports.ClientCommand, 16)
211	scenes := make(chan []ports.Scene, 1)
212	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Commands: commands, Scenes: scenes}, core.Options{})
213	if err != nil {
214		t.Fatal(err)
215	}
216	ctx, cancel := context.WithCancel(context.Background())
217	done := make(chan error, 1)
218	go func() { done <- c.Run(ctx) }()
219	defer func() { cancel(); receive(t, done) }()
220	client <- ports.WindowMapped{ID: 1}
221	scene(t, scenes)
222	command(t, commands)
223	command(t, commands)
224	press := ports.KeyEvent{Keysym: "Left", Mods: ports.ModSuper, Pressed: true}
225	input <- press
226	scene(t, scenes)
227	input <- ports.KeyEvent{Keysym: "Left", Mods: ports.ModSuper}
228	input <- ports.KeyEvent{Keysym: "Left", Pressed: true}
229	if v := command(t, commands); v != (ports.ForwardKey{ID: 1, Key: ports.KeyEvent{Keysym: "Left", Pressed: true}}) {
230		t.Fatal(v)
231	}
232	input <- ports.KeyEvent{Keysym: "Left"}
233	if v := command(t, commands); v != (ports.ForwardKey{ID: 1, Key: ports.KeyEvent{Keysym: "Left"}}) {
234		t.Fatal(v)
235	}
236	input <- press
237	scene(t, scenes)
238	input <- ports.KeyEvent{Keysym: "Left", Pressed: true}
239	command(t, commands)
240	input <- ports.KeyEvent{Keysym: "Left"}
241	if v := command(t, commands); v != (ports.ForwardKey{ID: 1, Key: ports.KeyEvent{Keysym: "Left"}}) {
242		t.Fatal(v)
243	}
244}
245
246func TestBoundReleaseSwallowed(t *testing.T) {
247	cfg := config.Defaults()
248	input := make(chan ports.InputEvent, 4)
249	client := make(chan ports.ClientEvent, 2)
250	commands := make(chan ports.ClientCommand, 8)
251	scenes := make(chan []ports.Scene, 1)
252	c, err := core.New(cfg, core.Channels{Input: input, Client: client, Commands: commands, Scenes: scenes}, core.Options{})
253	if err != nil {
254		t.Fatal(err)
255	}
256	ctx, cancel := context.WithCancel(context.Background())
257	done := make(chan error, 1)
258	go func() { done <- c.Run(ctx) }()
259	defer func() { cancel(); receive(t, done) }()
260	client <- ports.WindowMapped{ID: 1}
261	scene(t, scenes)
262	command(t, commands)
263	command(t, commands)
264	input <- ports.KeyEvent{Keysym: "Left", Mods: ports.ModSuper, Pressed: true}
265	scene(t, scenes)
266	input <- ports.KeyEvent{Keysym: "Left"}
267	input <- ports.KeyEvent{Keysym: "x", Pressed: true}
268	if v := command(t, commands); v != (ports.ForwardKey{ID: 1, Key: ports.KeyEvent{Keysym: "x", Pressed: true}}) {
269		t.Fatal(v)
270	}
271}
272
273func TestPointerFocusAndGrab(t *testing.T) {
274	cfg := config.Defaults()
275	cfg.Border.Width = 0
276	cfg.Layout.Gaps = 8
277	client := make(chan ports.ClientEvent, 8)
278	input := make(chan ports.InputEvent, 8)
279	output := make(chan ports.OutputEvent, 8)
280	commands := make(chan ports.ClientCommand, 64)
281	scenes := make(chan []ports.Scene, 1)
282	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}, core.Options{})
283	if err != nil {
284		t.Fatal(err)
285	}
286	ctx, cancel := context.WithCancel(context.Background())
287	defer cancel()
288	go c.Run(ctx)
289	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
290	scene(t, scenes)
291	client <- ports.WindowMapped{ID: 1}
292	first := scene(t, scenes).Windows[0].Rect
293	client <- ports.WindowMapped{ID: 2}
294	scene(t, scenes)
295	for len(commands) > 0 {
296		<-commands
297	}
298	input <- ports.PointerMotion{X: float64(first.X + 2), Y: float64(first.Y + 3), Time: 1 * time.Millisecond}
299	if v := command(t, commands); v != (ports.PointerFocus{ID: 1, X: 2, Y: 3}) {
300		t.Fatal(v)
301	}
302	if v := command(t, commands); v != (ports.PointerMotionTo{ID: 1, X: 2, Y: 3, Time: 1 * time.Millisecond}) {
303		t.Fatal(v)
304	}
305	input <- ports.PointerAxis{Vertical: ports.ScrollAxis{Set: true, Value: 15, V120: 120}}
306	if v := command(t, commands); v != (ports.PointerAxisTo{ID: 1, Axis: ports.PointerAxis{Vertical: ports.ScrollAxis{Set: true, Value: 15, V120: 120}}}) {
307		t.Fatal(v)
308	}
309	input <- ports.PointerButton{Button: 0x110, Pressed: true}
310	if v := command(t, commands); v != (ports.PointerButtonTo{ID: 1, Button: 0x110, Pressed: true}) {
311		t.Fatal(v)
312	}
313	scene(t, scenes)
314	found := false
315	for len(commands) > 0 {
316		if v, ok := (<-commands).(ports.FocusWindow); ok && v.ID == 1 {
317			found = true
318		}
319	}
320	if !found {
321		t.Fatal("missing keyboard focus")
322	}
323	input <- ports.PointerMotion{X: 0, Y: 0}
324	if v := command(t, commands); v != (ports.PointerFocus{}) {
325		t.Fatal(v)
326	}
327	// Mid-drag off the window, scroll goes to what is under the pointer:
328	// nothing here, not the grab window that got a leave.
329	input <- ports.PointerAxis{Vertical: ports.ScrollAxis{Set: true, Value: 1}}
330	input <- ports.PointerButton{Button: 0x110}
331	if v := command(t, commands); v != (ports.PointerButtonTo{ID: 1, Button: 0x110}) {
332		t.Fatal(v)
333	}
334}
335
336func TestBorderInset(t *testing.T) { both(t, borderInset) }
337
338func borderInset(t *testing.T, animated bool) {
339	cfg := config.Defaults()
340	cfg.Border.Width = 2
341	client := make(chan ports.ClientEvent, 8)
342	input := make(chan ports.InputEvent, 8)
343	output := make(chan ports.OutputEvent, 8)
344	commands := make(chan ports.ClientCommand, 64)
345	scenes := make(chan []ports.Scene, 1)
346	ch := core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}
347	opts := core.Options{}
348	l := newLanding(t, animated, &cfg, &ch, &opts, "OUT-1")
349	c, err := core.New(cfg, ch, opts)
350	if err != nil {
351		t.Fatal(err)
352	}
353	ctx, cancel := context.WithCancel(context.Background())
354	defer cancel()
355	go c.Run(ctx)
356	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
357	scene(t, scenes)
358	// Alone, the window is borderless and gets the full rect.
359	client <- ports.WindowMapped{ID: 1}
360	r := l.one(scene(t, scenes)).Windows[0].Rect
361	if v := command(t, commands); v != (ports.ConfigureWindow{ID: 1, Width: r.W, Height: r.H, Activated: true, Output: "OUT-1", Visible: true}) {
362		t.Fatalf("%v for outer %v", v, r)
363	}
364	// With a second column, the left window owns the shared separator: its
365	// client is 2px narrower on the right; the right window keeps its rect.
366	client <- ports.WindowMapped{ID: 2}
367	s := l.one(scene(t, scenes))
368	r = s.Windows[1].Rect
369	if s.Windows[0].Inset != ports.SideRight || s.Windows[1].Inset != 0 || len(s.Separators) == 0 {
370		t.Fatal(s)
371	}
372	want := ports.ConfigureWindow{ID: 1, Width: s.Windows[0].Rect.W - 2, Height: r.H, Activated: false, Output: "OUT-1", Visible: true}
373	found := false
374	for len(commands) > 0 {
375		if v := <-commands; v == want {
376			found = true
377		}
378	}
379	if !found {
380		t.Fatalf("no %v for outer %v", want, r)
381	}
382	input <- ports.PointerMotion{X: float64(r.X + 2), Y: float64(r.Y + 5), Time: 1 * time.Millisecond}
383	if v := command(t, commands); v != (ports.PointerFocus{ID: 2, X: 2, Y: 5}) {
384		t.Fatal(v)
385	}
386}
387
388func TestLayerKeyboardFocus(t *testing.T) {
389	cfg := config.Defaults()
390	client := make(chan ports.ClientEvent, 8)
391	input := make(chan ports.InputEvent, 8)
392	output := make(chan ports.OutputEvent, 8)
393	commands := make(chan ports.ClientCommand, 64)
394	scenes := make(chan []ports.Scene, 1)
395	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}, core.Options{})
396	if err != nil {
397		t.Fatal(err)
398	}
399	ctx, cancel := context.WithCancel(context.Background())
400	defer cancel()
401	go c.Run(ctx)
402	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
403	scene(t, scenes)
404	client <- ports.WindowMapped{ID: 1}
405	scene(t, scenes)
406	focusOf := func() ports.WindowID {
407		t.Helper()
408		for {
409			if v, ok := command(t, commands).(ports.FocusWindow); ok {
410				return v.ID
411			}
412		}
413	}
414	if id := focusOf(); id != 1 {
415		t.Fatalf("window focus %d", id)
416	}
417	// An on-demand bar does not steal focus; an exclusive launcher does.
418	launcher := ports.LayerSurface{ID: 7, Layer: ports.LayerOverlay, Width: 40, Height: 20, Keyboard: 1}
419	bar := ports.LayerSurface{ID: 6, Layer: ports.LayerTop, Anchor: ports.AnchorTop | ports.AnchorLeft | ports.AnchorRight, Height: 5, Keyboard: 2}
420	client <- ports.LayerChanged{Layers: []ports.LayerSurface{bar, launcher}}
421	scene(t, scenes)
422	if id := focusOf(); id != 7 {
423		t.Fatalf("layer focus %d", id)
424	}
425	input <- ports.KeyEvent{Keysym: "a", Keycode: 30, Pressed: true}
426	for {
427		if v, ok := command(t, commands).(ports.ForwardKey); ok {
428			if v.ID != 7 {
429				t.Fatalf("key went to %d", v.ID)
430			}
431			break
432		}
433	}
434	client <- ports.LayerChanged{Layers: []ports.LayerSurface{bar}}
435	scene(t, scenes)
436	if id := focusOf(); id != 1 {
437		t.Fatalf("focus not restored: %d", id)
438	}
439}
440
441func TestWorkspaceSwitch(t *testing.T) { workspaceSwitch(t, false) }
442
443// With animations on the scene right after the key shows the slide's start:
444// the test lands it before it asserts.
445func TestWorkspaceSwitchAnimated(t *testing.T) { workspaceSwitch(t, true) }
446
447// settledScene lands the springs an action started on the single output
448// OUT-1 of a rig with a stepClock and returns its scene; animations off:
449// the scene itself.
450func settledScene(t *testing.T, sc *stepClock, frames chan ports.OutputFrame, scenes chan []ports.Scene, s ports.Scene, mustAnimate bool) ports.Scene {
451	t.Helper()
452	if sc == nil {
453		return s
454	}
455	set, ok := sc.settle(t, frames, scenes, "OUT-1")
456	if !ok {
457		if mustAnimate {
458			t.Fatal("the action started no animation: the case checks nothing")
459		}
460		return s
461	}
462	return set[0]
463}
464
465func workspaceSwitch(t *testing.T, animated bool) {
466	cfg := config.Defaults()
467	cfg.Animations.On = animated
468	client := make(chan ports.ClientEvent, 8)
469	input := make(chan ports.InputEvent, 8)
470	output := make(chan ports.OutputEvent, 8)
471	commands := make(chan ports.ClientCommand, 64)
472	scenes := make(chan []ports.Scene, 1)
473	ch := core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}
474	opts := core.Options{}
475	var sc *stepClock
476	frames := make(chan ports.OutputFrame)
477	if animated {
478		sc = newStepClock(t)
479		opts.Clock, ch.Frames = sc.clock, frames
480	}
481	c, err := core.New(cfg, ch, opts)
482	if err != nil {
483		t.Fatal(err)
484	}
485	ctx, cancel := context.WithCancel(context.Background())
486	defer cancel()
487	go c.Run(ctx)
488	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
489	scene(t, scenes)
490	client <- ports.WindowMapped{ID: 1}
491	scene(t, scenes)
492	for len(commands) > 0 {
493		<-commands
494	}
495	// AZERTY: the 2 key prints eacute; the default bind is on its physical key (code 3).
496	input <- ports.KeyEvent{Keysym: "eacute", Base: "eacute", Keycode: 3, Mods: ports.ModSuper, Pressed: true}
497	s := settledScene(t, sc, frames, scenes, scene(t, scenes), animated)
498	if len(s.Windows) != 1 || !s.Windows[0].Hidden {
499		t.Fatal(s)
500	}
501	// Window 1 is deactivated and loses keyboard focus.
502	var sawDeactivate, sawFocus bool
503	for len(commands) > 0 {
504		switch v := (<-commands).(type) {
505		case ports.ConfigureWindow:
506			sawDeactivate = sawDeactivate || (v.ID == 1 && !v.Activated)
507		case ports.FocusWindow:
508			sawFocus = sawFocus || v.ID == 0
509		}
510	}
511	if !sawDeactivate || !sawFocus {
512		t.Fatal(sawDeactivate, sawFocus)
513	}
514	// A new window opens on workspace 2, alone and borderless.
515	client <- ports.WindowMapped{ID: 2}
516	s = settledScene(t, sc, frames, scenes, scene(t, scenes), false)
517	if len(s.Windows) != 2 || s.Windows[1].ID != 2 || s.Windows[1].Hidden || s.Windows[1].Inset != 0 {
518		t.Fatal(s)
519	}
520}
521
522func TestClickAfterWorkspaceSwitch(t *testing.T) { clickAfterWorkspaceSwitch(t, false) }
523
524func TestClickAfterWorkspaceSwitchAnimated(t *testing.T) { clickAfterWorkspaceSwitch(t, true) }
525
526func clickAfterWorkspaceSwitch(t *testing.T, animated bool) {
527	cfg := config.Defaults()
528	cfg.Animations.On = animated
529	client := make(chan ports.ClientEvent, 8)
530	input := make(chan ports.InputEvent, 8)
531	output := make(chan ports.OutputEvent, 8)
532	commands := make(chan ports.ClientCommand, 64)
533	scenes := make(chan []ports.Scene, 1)
534	ch := core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}
535	opts := core.Options{}
536	var sc *stepClock
537	frames := make(chan ports.OutputFrame)
538	if animated {
539		sc = newStepClock(t)
540		opts.Clock, ch.Frames = sc.clock, frames
541	}
542	c, err := core.New(cfg, ch, opts)
543	if err != nil {
544		t.Fatal(err)
545	}
546	ctx, cancel := context.WithCancel(context.Background())
547	defer cancel()
548	go c.Run(ctx)
549	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
550	scene(t, scenes)
551	client <- ports.WindowMapped{ID: 1}
552	scene(t, scenes)
553	input <- ports.PointerMotion{X: 50, Y: 40}
554	for len(commands) < 3 {
555		time.Sleep(time.Millisecond)
556	}
557	for len(commands) > 0 {
558		<-commands
559	}
560	// Cmd+2 hides window 1; the pointer must leave it.
561	input <- ports.KeyEvent{Keysym: "2", Keycode: 3, Mods: ports.ModSuper, Pressed: true}
562	settledScene(t, sc, frames, scenes, scene(t, scenes), animated)
563	var cleared bool
564	for len(commands) > 0 {
565		if v, ok := (<-commands).(ports.PointerFocus); ok && v.ID == 0 {
566			cleared = true
567		}
568	}
569	if !cleared {
570		t.Fatal("pointer focus kept on hidden window")
571	}
572	// A click without moving does not reach window 1 nor switch back.
573	input <- ports.PointerButton{Button: 0x110, Pressed: true}
574	input <- ports.PointerButton{Button: 0x110}
575	client <- ports.WindowMapped{ID: 2}
576	s := settledScene(t, sc, frames, scenes, scene(t, scenes), false)
577	if s.Windows[0].ID != 1 || !s.Windows[0].Hidden || s.Windows[1].Hidden {
578		t.Fatal(s)
579	}
580	for len(commands) > 0 {
581		if v, ok := (<-commands).(ports.PointerButtonTo); ok {
582			t.Fatal(v)
583		}
584	}
585}
586
587func TestShiftReleasedFirst(t *testing.T) {
588	cfg := config.Defaults()
589	input := make(chan ports.InputEvent, 8)
590	client := make(chan ports.ClientEvent, 2)
591	commands := make(chan ports.ClientCommand, 16)
592	scenes := make(chan []ports.Scene, 1)
593	c, err := core.New(cfg, core.Channels{Input: input, Client: client, Commands: commands, Scenes: scenes}, core.Options{})
594	if err != nil {
595		t.Fatal(err)
596	}
597	ctx, cancel := context.WithCancel(context.Background())
598	defer cancel()
599	go c.Run(ctx)
600	client <- ports.WindowMapped{ID: 1}
601	scene(t, scenes)
602	for len(commands) > 0 {
603		<-commands
604	}
605	// US Cmd+Shift+1 prints exclam; the physical key (code 2) matches move-column-to-workspace 1.
606	input <- ports.KeyEvent{Keysym: "exclam", Base: "1", Keycode: 2, Mods: ports.ModSuper | ports.ModShift, Pressed: true}
607	scene(t, scenes)
608	// Shift goes up first, so the release reports "1": still swallowed.
609	input <- ports.KeyEvent{Keysym: "1", Keycode: 2, Mods: ports.ModSuper}
610	input <- ports.KeyEvent{Keysym: "x", Keycode: 45, Pressed: true}
611	if v := command(t, commands); v != (ports.ForwardKey{ID: 1, Key: ports.KeyEvent{Keysym: "x", Keycode: 45, Pressed: true}}) {
612		t.Fatal(v)
613	}
614}
615
616func TestOutputScale(t *testing.T) { both(t, outputScale) }
617
618func outputScale(t *testing.T, animated bool) {
619	cfg := config.Defaults()
620	cfg.Border.Width = 0
621	cfg.Outputs = []ports.OutputConfig{{Name: "DP-2", Scale: 2}}
622	cfg.Binds["Cmd+equal"] = "scale-up"
623	cfg.Binds["Cmd+minus"] = "scale-down"
624	client := make(chan ports.ClientEvent, 8)
625	input := make(chan ports.InputEvent, 8)
626	output := make(chan ports.OutputEvent, 8)
627	reload := make(chan ports.ConfigChanged, 1)
628	commands := make(chan ports.ClientCommand, 64)
629	scenes := make(chan []ports.Scene, 1)
630	ch := core.Channels{Client: client, Input: input, Output: output, Config: reload, Commands: commands, Scenes: scenes}
631	opts := core.Options{}
632	l := newLanding(t, animated, &cfg, &ch, &opts, "DP-2")
633	c, err := core.New(cfg, ch, opts)
634	if err != nil {
635		t.Fatal(err)
636	}
637	ctx, cancel := context.WithCancel(context.Background())
638	defer cancel()
639	go c.Run(ctx)
640	// 5120x2160 at scale 2 is 2560x1080 logical.
641	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "DP-2", Width: 5120, Height: 2160}}
642	s := scene(t, scenes)
643	if s.Scale != 2 || s.OutputWidth != 2560 || s.OutputHeight != 1080 {
644		t.Fatal(s.Scale, s.OutputWidth, s.OutputHeight)
645	}
646	if v := receive(t, commands).(ports.SetOutputs); len(v.Outputs) != 1 || v.Outputs[0].Scale != 2 || v.Outputs[0].Width != 2560 || v.Outputs[0].Height != 1080 || v.Focused != "DP-2" {
647		t.Fatal(v)
648	}
649	client <- ports.WindowMapped{ID: 1}
650	l.one(scene(t, scenes))
651	if v := command(t, commands); v != (ports.ConfigureWindow{ID: 1, Width: 2560, Height: 1080, Activated: true, Output: "DP-2", Visible: true}) {
652		t.Fatal(v)
653	}
654	for len(commands) > 0 {
655		<-commands
656	}
657	// The pointer arrives in global logical pixels.
658	input <- ports.PointerMotion{X: 500, Y: 200}
659	if animated {
660		// The page flips that landed the map's springs re-hit the pointer
661		// (still at the origin, over the window): focus was already sent.
662		if v, ok := command(t, commands).(ports.PointerMotionTo); !ok || v.ID != 1 || v.X != 500 || v.Y != 200 {
663			t.Fatal(v)
664		}
665	} else if v := command(t, commands); v != (ports.PointerFocus{ID: 1, X: 500, Y: 200}) {
666		t.Fatal(v)
667	}
668	// Cmd+- steps down through the clean scales of 5120x2160: 2 → 5/3.
669	input <- ports.KeyEvent{Keysym: "minus", Keycode: 12, Mods: ports.ModSuper, Pressed: true}
670	s = scene(t, scenes)
671	if s.Scale != 5.0/3 || s.OutputWidth != 3072 || s.OutputHeight != 1296 {
672		t.Fatal(s.Scale, s.OutputWidth, s.OutputHeight)
673	}
674	input <- ports.KeyEvent{Keysym: "minus", Keycode: 12, Mods: ports.ModSuper}
675	input <- ports.KeyEvent{Keysym: "equal", Keycode: 13, Mods: ports.ModSuper, Pressed: true}
676	if s = scene(t, scenes); s.Scale != 2 {
677		t.Fatal(s.Scale)
678	}
679	// A reload that keeps the config scale keeps the live one too.
680	input <- ports.KeyEvent{Keysym: "equal", Keycode: 13, Mods: ports.ModSuper}
681	input <- ports.KeyEvent{Keysym: "equal", Keycode: 13, Mods: ports.ModSuper, Pressed: true}
682	if s = scene(t, scenes); s.Scale != 2.5 {
683		t.Fatal(s.Scale)
684	}
685	cfg.Layout.Gaps = 1
686	reload <- ports.ConfigChanged{Config: cfg}
687	if s = scene(t, scenes); s.Scale != 2.5 {
688		t.Fatal(s.Scale)
689	}
690	// Changing the config scale wins.
691	cfg.Outputs = []ports.OutputConfig{{Name: "DP-2", Scale: 1.25}}
692	reload <- ports.ConfigChanged{Config: cfg}
693	if s = scene(t, scenes); s.Scale != 1.25 || s.OutputWidth != 4096 {
694		t.Fatal(s.Scale, s.OutputWidth)
695	}
696}
697
698// A pointer warp moves the cursor on the window under it: input takes the
699// position and the window gets the motion. Other windows cannot warp.
700func TestPointerWarp(t *testing.T) {
701	cfg := config.Defaults()
702	cfg.Border.Width = 0
703	cfg.Layout.Gaps = 0
704	client := make(chan ports.ClientEvent, 8)
705	input := make(chan ports.InputEvent, 8)
706	output := make(chan ports.OutputEvent, 8)
707	commands := make(chan ports.ClientCommand, 64)
708	scenes := make(chan []ports.Scene, 1)
709	constraints := make(chan ports.PointerConstraint, 1)
710	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes, Constraints: constraints}, core.Options{})
711	if err != nil {
712		t.Fatal(err)
713	}
714	ctx, cancel := context.WithCancel(context.Background())
715	defer cancel()
716	go c.Run(ctx)
717	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "A", Width: 100, Height: 80}}
718	scene(t, scenes)
719	client <- ports.WindowMapped{ID: 1}
720	r := receive(t, scenes)[0].Windows[0].Rect
721	input <- ports.PointerMotion{X: 50, Y: 40}
722	for {
723		if _, ok := command(t, commands).(ports.PointerMotionTo); ok {
724			break
725		}
726	}
727	// Another window cannot move the pointer.
728	client <- ports.PointerWarp{ID: 2, X: 5, Y: 5}
729	client <- ports.PointerWarp{ID: 1, X: 10, Y: 20}
730	got := receive(t, constraints)
731	if !got.Warp || got.X != float64(r.X+10) || got.Y != float64(r.Y+20) {
732		t.Fatalf("warp %+v, window %+v", got, r)
733	}
734	for {
735		if v, ok := command(t, commands).(ports.PointerMotionTo); ok {
736			if v.ID != 1 || v.X != 10 || v.Y != 20 || v.DX != 0 || v.DY != 0 {
737				t.Fatalf("motion %+v", v)
738			}
739			break
740		}
741	}
742	// A point outside the window is refused.
743	client <- ports.PointerWarp{ID: 1, X: float64(r.W), Y: 0}
744	client <- ports.PointerWarp{ID: 1, X: 1, Y: 1}
745	if got := receive(t, constraints); got.X != float64(r.X+1) || got.Y != float64(r.Y+1) {
746		t.Fatalf("warp %+v", got)
747	}
748}
749
750func TestPointerConstraint(t *testing.T) { both(t, pointerConstraint) }
751
752func pointerConstraint(t *testing.T, animated bool) {
753	cfg := config.Defaults()
754	cfg.Border.Width = 0
755	cfg.Layout.Gaps = 0
756	client := make(chan ports.ClientEvent, 8)
757	input := make(chan ports.InputEvent, 8)
758	output := make(chan ports.OutputEvent, 8)
759	commands := make(chan ports.ClientCommand, 64)
760	scenes := make(chan []ports.Scene, 1)
761	constraints := make(chan ports.PointerConstraint, 1)
762	ch := core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes, Constraints: constraints}
763	opts := core.Options{}
764	l := newLanding(t, animated, &cfg, &ch, &opts, "A", "B")
765	c, err := core.New(cfg, ch, opts)
766	if err != nil {
767		t.Fatal(err)
768	}
769	ctx, cancel := context.WithCancel(context.Background())
770	defer cancel()
771	go c.Run(ctx)
772	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "A", Width: 100, Height: 80}}
773	scene(t, scenes)
774	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "B", Width: 100, Height: 80}}
775	scene(t, scenes)
776	input <- ports.PointerMotion{X: 150, Y: 40}
777	scene(t, scenes) // the pointer moves the focus to B
778	client <- ports.WindowMapped{ID: 1}
779	r := l.land(receive(t, scenes))[1].Windows[0].Rect
780	// The confine region is window-local and clipped to the window.
781	client <- ports.PointerConstrained{ID: 1, PointerConstraint: ports.PointerConstraint{Mode: ports.ConstraintConfine, Rect: ports.Rect{X: 10, Y: 10, W: 1000, H: 20}}}
782	scene(t, scenes)
783	want := ports.PointerConstraint{Mode: ports.ConstraintConfine, Rect: ports.Rect{X: 100 + r.X + 10, Y: r.Y + 10, W: r.W - 10, H: 20}}
784	// Input gets core's cursor, clamped into the region.
785	if got := receive(t, constraints); got.Mode != want.Mode || got.Rect != want.Rect || got.X != 150 || got.Y != 29 {
786		t.Fatalf("got %+v, want %+v", got, want)
787	}
788	for len(commands) > 0 {
789		<-commands
790	}
791	// Motion is clamped into the region; deltas pass through.
792	input <- ports.PointerMotion{X: 199, Y: 79, DX: 5, DY: 6}
793	for {
794		if v, ok := command(t, commands).(ports.PointerMotionTo); ok {
795			if v.X != float64(want.Rect.X+want.Rect.W-1-100-r.X) || v.Y != float64(want.Rect.Y+want.Rect.H-1-r.Y) || v.DX != 5 || v.DY != 6 {
796				t.Fatalf("motion %+v", v)
797			}
798			break
799		}
800	}
801	// A lock keeps the pointer still.
802	client <- ports.PointerConstrained{ID: 1, PointerConstraint: ports.PointerConstraint{Mode: ports.ConstraintLock}}
803	scene(t, scenes)
804	if got := receive(t, constraints); got.Mode != ports.ConstraintLock {
805		t.Fatalf("lock %+v", got)
806	}
807	for len(commands) > 0 {
808		<-commands
809	}
810	input <- ports.PointerMotion{X: 101, Y: 1, DX: -50}
811	for {
812		if v, ok := command(t, commands).(ports.PointerMotionTo); ok {
813			if v.X != float64(want.Rect.X+want.Rect.W-1-100-r.X) || v.DX != -50 {
814				t.Fatalf("locked motion %+v", v)
815			}
816			break
817		}
818	}
819	client <- ports.PointerConstrained{}
820	scene(t, scenes)
821	if got := receive(t, constraints); got.Mode != ports.ConstraintNone {
822		t.Fatalf("release %+v", got)
823	}
824}
825
826// A click outside a grabbing menu chain closes it, the topmost popup first.
827func TestPopupChainDismissOrder(t *testing.T) {
828	cfg := config.Defaults()
829	cfg.Border.Width = 0
830	client := make(chan ports.ClientEvent, 8)
831	input := make(chan ports.InputEvent, 8)
832	output := make(chan ports.OutputEvent, 8)
833	commands := make(chan ports.ClientCommand, 64)
834	scenes := make(chan []ports.Scene, 1)
835	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}, core.Options{})
836	if err != nil {
837		t.Fatal(err)
838	}
839	ctx, cancel := context.WithCancel(context.Background())
840	defer cancel()
841	go c.Run(ctx)
842	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
843	scene(t, scenes)
844	client <- ports.WindowMapped{ID: 1}
845	scene(t, scenes)
846	pos := ports.Positioner{Width: 10, Height: 10, AnchorRect: ports.Rect{W: 1, H: 1}, Anchor: ports.EdgeBottomRight, Gravity: ports.EdgeBottomRight}
847	for _, v := range []struct{ id, parent ports.WindowID }{{2, 1}, {3, 2}} {
848		client <- ports.PopupRequest{ID: v.id, Parent: v.parent, Positioner: pos, Grab: true}
849		for {
850			if cp, ok := command(t, commands).(ports.ConfigurePopup); ok && cp.ID == v.id {
851				break
852			}
853		}
854		client <- ports.PopupMapped{ID: v.id}
855		scene(t, scenes)
856	}
857	for len(commands) > 0 {
858		<-commands
859	}
860	// The window's far corner is outside both popups.
861	input <- ports.PointerMotion{X: 90, Y: 70}
862	input <- ports.PointerButton{Button: 0x110, Pressed: true}
863	var closed []ports.WindowID
864	for len(closed) < 2 {
865		if v, ok := command(t, commands).(ports.ClosePopup); ok {
866			closed = append(closed, v.ID)
867		}
868	}
869	if closed[0] != 3 || closed[1] != 2 {
870		t.Fatalf("close order %v, want [3 2]", closed)
871	}
872}
873
874// A dialog opened under a fullscreen window stays hidden and out of reach
875// of the pointer until the window leaves fullscreen.
876func TestFloatOverFullscreenHit(t *testing.T) {
877	cfg := config.Defaults()
878	cfg.Border.Width = 0
879	client := make(chan ports.ClientEvent, 8)
880	input := make(chan ports.InputEvent, 8)
881	output := make(chan ports.OutputEvent, 8)
882	commands := make(chan ports.ClientCommand, 64)
883	scenes := make(chan []ports.Scene, 1)
884	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}, core.Options{Clock: steppingClock(t)})
885	if err != nil {
886		t.Fatal(err)
887	}
888	ctx, cancel := context.WithCancel(context.Background())
889	defer cancel()
890	go c.Run(ctx)
891	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
892	scene(t, scenes)
893	client <- ports.WindowMapped{ID: 1}
894	scene(t, scenes)
895	client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: true}
896	scene(t, scenes)
897	client <- ports.WindowMapped{ID: 2, Floating: true, Width: 20, Height: 10}
898	scene(t, scenes)
899	for len(commands) > 0 {
900		<-commands
901	}
902	input <- ports.PointerMotion{X: 50, Y: 40}
903	if v, ok := command(t, commands).(ports.PointerFocus); !ok || v.ID != 1 {
904		t.Fatalf("pointer went to %v, want the fullscreen window", v)
905	}
906	client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: false}
907	scene(t, scenes)
908	for len(commands) > 0 {
909		<-commands
910	}
911	input <- ports.PointerMotion{X: 50, Y: 41}
912	if v, ok := command(t, commands).(ports.PointerFocus); !ok || v.ID != 2 {
913		t.Fatalf("pointer went to %v, want the dialog", v)
914	}
915}
916
917// A dialog of the fullscreen window (a portal dialog parented through
918// xdg-foreign) shows over it and takes the pointer at once.
919func TestDialogOverFullscreenHit(t *testing.T) {
920	cfg := config.Defaults()
921	cfg.Border.Width = 0
922	client := make(chan ports.ClientEvent, 8)
923	input := make(chan ports.InputEvent, 8)
924	output := make(chan ports.OutputEvent, 8)
925	commands := make(chan ports.ClientCommand, 64)
926	scenes := make(chan []ports.Scene, 1)
927	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}, core.Options{Clock: steppingClock(t)})
928	if err != nil {
929		t.Fatal(err)
930	}
931	ctx, cancel := context.WithCancel(context.Background())
932	defer cancel()
933	go c.Run(ctx)
934	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
935	scene(t, scenes)
936	client <- ports.WindowMapped{ID: 1}
937	scene(t, scenes)
938	client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: true}
939	scene(t, scenes)
940	client <- ports.WindowMapped{ID: 2, Floating: true, Width: 20, Height: 10, Parent: 1}
941	s := scene(t, scenes)
942	shown := false
943	for _, w := range s.Windows {
944		if w.ID == 2 {
945			shown = !w.Hidden && w.Rect.W > 0
946		}
947	}
948	if !shown {
949		t.Fatalf("dialog not shown: %+v", s.Windows)
950	}
951	for len(commands) > 0 {
952		<-commands
953	}
954	input <- ports.PointerMotion{X: 50, Y: 40}
955	if v, ok := command(t, commands).(ports.PointerFocus); !ok || v.ID != 2 {
956		t.Fatalf("pointer went to %v, want the dialog", v)
957	}
958}
959
960// A window that asks for fullscreen as it maps (Wine at a remembered
961// monitor size) stays in its column: the windows it opens next are seen.
962// A later request is honoured.
963func TestFullscreenAtMapIgnored(t *testing.T) { both(t, fullscreenAtMapIgnored) }
964
965func fullscreenAtMapIgnored(t *testing.T, animated bool) {
966	cfg := config.Defaults()
967	cfg.Layout.Overflow = "fixed"
968	cfg.Focus.Animation = ports.FocusAnimationOff
969	client := make(chan ports.ClientEvent, 8)
970	output := make(chan ports.OutputEvent, 8)
971	commands := make(chan ports.ClientCommand, 64)
972	scenes := make(chan []ports.Scene, 1)
973	// Core reads the time on its goroutine: the clock is the test's.
974	ch := core.Channels{Client: client, Output: output, Commands: commands, Scenes: scenes}
975	opts := core.Options{}
976	l := newLanding(t, animated, &cfg, &ch, &opts, "OUT-1")
977	clk := l.clk
978	if clk == nil {
979		clk = newStepClock(t)
980		opts.Clock = clk.clock
981	}
982	c, err := core.New(cfg, ch, opts)
983	if err != nil {
984		t.Fatal(err)
985	}
986	ctx, cancel := context.WithCancel(context.Background())
987	defer cancel()
988	go c.Run(ctx)
989	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
990	scene(t, scenes)
991	client <- ports.WindowMapped{ID: 1}
992	scene(t, scenes)
993	client <- ports.WindowMapped{ID: 2}
994	scene(t, scenes)
995	client <- ports.WindowFullscreenRequest{ID: 2, Fullscreen: true}
996	client <- ports.WindowMapped{ID: 3, Floating: true, Width: 20, Height: 10}
997	s := scene(t, scenes)
998	for !slices.ContainsFunc(s.Windows, func(w ports.SceneWindow) bool { return w.ID == 3 }) {
999		s = scene(t, scenes)
1000	}
1001	for _, w := range s.Windows {
1002		if w.Fullscreen || w.Hidden {
1003			t.Fatalf("startup fullscreen applied: %+v", s.Windows)
1004		}
1005	}
1006	// With animations on this lands the maps' springs: the clock moves past
1007	// the grace, as the next line does anyway.
1008	l.one(s)
1009	clk.advance(time.Second)
1010	// Only the focused window may cover the screen (ADR 011).
1011	client <- ports.WindowUnmapped{ID: 3}
1012	scene(t, scenes)
1013	client <- ports.WindowFullscreenRequest{ID: 2, Fullscreen: true}
1014	s = scene(t, scenes)
1015	// Honoured, in place.
1016	if !slices.ContainsFunc(s.Windows, func(w ports.SceneWindow) bool { return w.ID == 2 && w.Fullscreen && !w.Hidden }) {
1017		t.Fatalf("later fullscreen ignored: %+v", s.Windows)
1018	}
1019}
1020
1021// Under fixed overflow, a window opening over a fullscreen game waits
1022// hidden: the game keeps the screen and the keyboard. An activation (a
1023// user action in the new client) leaves fullscreen and shows both tiles;
1024// a focus move back to the game and the bind make it fullscreen again.
1025func TestFixedFullscreenArrivalWaits(t *testing.T) {
1026	r := startMulti(t, func(c *ports.Config) { c.Layout.Overflow = "fixed" }, left)
1027	r.mapWindow(t, 1)
1028	r.key(t, "f", ports.ModAlt|ports.ModShift)
1029	set := r.mapWindow(t, 2)
1030	for len(r.commands) > 0 {
1031		<-r.commands
1032	}
1033	if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{1}) || focused != 1 {
1034		t.Fatal("game disturbed:", got, focused)
1035	}
1036	r.client <- ports.WindowActivate{ID: 2}
1037	set = receive(t, r.scenes)
1038	if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{1, 2}) || focused != 2 {
1039		t.Fatal("after activate:", got, focused)
1040	}
1041	for {
1042		if f, ok := command(t, r.commands).(ports.FocusWindow); ok && f.ID == 2 {
1043			break
1044		}
1045	}
1046	r.key(t, "Left", ports.ModAlt)
1047	set = r.key(t, "f", ports.ModAlt|ports.ModShift)
1048	if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{1}) || focused != 1 {
1049		t.Fatal("game again:", got, focused)
1050	}
1051}
1052
1053// A taskbar's fullscreen request is the user's: it applies at once.
1054func TestExternalFullscreenAtMapApplies(t *testing.T) { both(t, externalFullscreenAtMapApplies) }
1055
1056func externalFullscreenAtMapApplies(t *testing.T, animated bool) {
1057	cfg := config.Defaults()
1058	cfg.Focus.Animation = ports.FocusAnimationOff
1059	client := make(chan ports.ClientEvent, 8)
1060	output := make(chan ports.OutputEvent, 8)
1061	commands := make(chan ports.ClientCommand, 64)
1062	scenes := make(chan []ports.Scene, 1)
1063	ch := core.Channels{Client: client, Output: output, Commands: commands, Scenes: scenes}
1064	opts := core.Options{}
1065	l := newLanding(t, animated, &cfg, &ch, &opts, "OUT-1")
1066	if l.clk == nil {
1067		opts.Clock = newStepClock(t).clock
1068	}
1069	c, err := core.New(cfg, ch, opts)
1070	if err != nil {
1071		t.Fatal(err)
1072	}
1073	ctx, cancel := context.WithCancel(context.Background())
1074	defer cancel()
1075	go c.Run(ctx)
1076	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
1077	scene(t, scenes)
1078	client <- ports.WindowMapped{ID: 1}
1079	l.one(scene(t, scenes))
1080	client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: true, External: true}
1081	s := scene(t, scenes)
1082	if len(s.Windows) != 1 || !s.Windows[0].Fullscreen {
1083		t.Fatalf("taskbar fullscreen ignored: %+v", s.Windows)
1084	}
1085}
1086
1087// Under fixed overflow, a taskbar's fullscreen on an unfocused window is
1088// the user's choice: the window takes the focus and covers the screen.
1089func TestExternalFullscreenFocusesFixed(t *testing.T) {
1090	r := startMulti(t, func(c *ports.Config) { c.Layout.Overflow = "fixed" }, left)
1091	r.mapWindow(t, 1)
1092	r.mapWindow(t, 2)
1093	r.client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: true, External: true}
1094	set := receive(t, r.scenes)
1095	if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{1}) || focused != 1 {
1096		t.Fatal("taskbar fullscreen:", got, focused)
1097	}
1098	// Over another covering window too: it leaves fullscreen.
1099	r.client <- ports.WindowFullscreenRequest{ID: 2, Fullscreen: true, External: true}
1100	set = receive(t, r.scenes)
1101	if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{2}) || focused != 2 {
1102		t.Fatal("taskbar fullscreen over another:", got, focused)
1103	}
1104	// Leaving from the taskbar keeps the focus.
1105	r.client <- ports.WindowFullscreenRequest{ID: 2, External: true}
1106	set = receive(t, r.scenes)
1107	if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{1, 2}) || focused != 2 {
1108		t.Fatal("taskbar leave:", got, focused)
1109	}
1110}
1111
1112// A taskbar fullscreen on a window of a workspace off screen, on another
1113// output, brings it on screen with the focus, as an activation.
1114func TestExternalFullscreenOffScreen(t *testing.T) {
1115	r := startMulti(t, func(c *ports.Config) { c.Layout.Overflow = "fixed" }, left, right)
1116	r.mapWindow(t, 1)
1117	r.key(t, "Next", ports.ModAlt|ports.ModShift) // 1 to workspace 2, not followed
1118	r.key(t, "Right", ports.ModAlt|ports.ModCtrl) // focus DP-2
1119	r.mapWindow(t, 2)
1120	r.client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: true, External: true}
1121	set := receive(t, r.scenes)
1122	found := false
1123	for _, s := range set {
1124		for _, w := range s.Windows {
1125			if w.ID != 1 {
1126				continue
1127			}
1128			found = true
1129			if s.Output != "DP-1" || w.Hidden || !w.Fullscreen || !w.Focused {
1130				t.Fatalf("window 1 on %s: %+v", s.Output, w)
1131			}
1132		}
1133	}
1134	if !found {
1135		t.Fatal("window 1 in no scene")
1136	}
1137}
1138
1139// In the overview, a taskbar fullscreen on a window of another workspace
1140// selects its row: closing the overview lands on it, fullscreen.
1141func TestExternalFullscreenInOverview(t *testing.T) {
1142	r := startMulti(t, func(c *ports.Config) { c.Layout.Overflow = "fixed" }, left)
1143	r.mapWindow(t, 1)
1144	r.key(t, "Next", ports.ModAlt|ports.ModShift) // 1 to workspace 2
1145	r.mapWindow(t, 2)
1146	r.key(t, "o", ports.ModAlt)
1147	r.client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: true, External: true}
1148	receive(t, r.scenes)
1149	set := r.key(t, "o", ports.ModAlt)
1150	if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{1}) || focused != 1 {
1151		t.Fatal("after the overview:", got, focused)
1152	}
1153}
1154
1155// focus-window-down from a fullscreen tile at the bottom of its column
1156// goes to the next workspace and fullscreen stays.
1157func TestFocusWindowDownKeepsFullscreen(t *testing.T) {
1158	both(t, func(t *testing.T, animated bool) {
1159		r := startLanding(t, animated, func(c *ports.Config) { c.Layout.Overflow = "fixed" }, left)
1160		r.mapLanded(t, 1)
1161		r.mapLanded(t, 2)
1162		r.keyLanded(t, "f", ports.ModAlt|ports.ModShift)
1163		set := r.keyLanded(t, "Down", ports.ModAlt)
1164		if got, _ := windowsOf(set, "DP-1"); len(got) != 0 {
1165			t.Fatal("still on the first workspace:", got)
1166		}
1167		set = r.keyLanded(t, "Up", ports.ModAlt)
1168		if got, focused := windowsOf(set, "DP-1"); !reflect.DeepEqual(got, []ports.WindowID{2}) || focused != 2 {
1169			t.Fatal("fullscreen lost:", got, focused)
1170		}
1171	})
1172}
1173
1174// A refused fullscreen request still gets a configure, unchanged: clients
1175// wait for it (xdg-shell).
1176func TestRefusedFullscreenConfigured(t *testing.T) {
1177	r := startMulti(t, func(c *ports.Config) { c.Layout.Overflow = "fixed" }, left)
1178	r.mapWindow(t, 1)
1179	r.mapWindow(t, 2)
1180	for len(r.commands) > 0 {
1181		<-r.commands
1182	}
1183	r.client <- ports.WindowFullscreenRequest{ID: 1, Fullscreen: true}
1184	receive(t, r.scenes)
1185	for len(r.commands) > 0 {
1186		if v, ok := (<-r.commands).(ports.ConfigureWindow); ok && v.ID == 1 {
1187			if v.Fullscreen {
1188				t.Fatalf("refused request applied: %+v", v)
1189			}
1190			return
1191		}
1192	}
1193	t.Fatal("no configure answered the request")
1194}
1195
1196// An activated window on another workspace comes on screen with focus.
1197func TestWindowActivateShowsAndFocuses(t *testing.T) {
1198	cfg := config.Defaults()
1199	client := make(chan ports.ClientEvent, 8)
1200	input := make(chan ports.InputEvent, 8)
1201	output := make(chan ports.OutputEvent, 8)
1202	commands := make(chan ports.ClientCommand, 64)
1203	scenes := make(chan []ports.Scene, 1)
1204	c, err := core.New(cfg, core.Channels{Client: client, Input: input, Output: output, Commands: commands, Scenes: scenes}, core.Options{})
1205	if err != nil {
1206		t.Fatal(err)
1207	}
1208	ctx, cancel := context.WithCancel(context.Background())
1209	defer cancel()
1210	go c.Run(ctx)
1211	output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
1212	scene(t, scenes)
1213	client <- ports.WindowMapped{ID: 1}
1214	scene(t, scenes)
1215	// Window 2 opens on workspace 2, then the user goes back to 1.
1216	input <- ports.KeyEvent{Keysym: "2", Keycode: 3, Mods: ports.ModSuper, Pressed: true}
1217	scene(t, scenes)
1218	client <- ports.WindowMapped{ID: 2}
1219	scene(t, scenes)
1220	input <- ports.KeyEvent{Keysym: "1", Keycode: 2, Mods: ports.ModSuper, Pressed: true}
1221	visible := func(sc ports.Scene) (shown []ports.SceneWindow) {
1222		for _, w := range sc.Windows {
1223			if !w.Hidden {
1224				shown = append(shown, w)
1225			}
1226		}
1227		return shown
1228	}
1229	if v := visible(scene(t, scenes)); len(v) != 1 || v[0].ID != 1 {
1230		t.Fatalf("workspace 1: %+v", v)
1231	}
1232	client <- ports.WindowActivate{ID: 2}
1233	v := visible(scene(t, scenes))
1234	for len(v) != 1 || v[0].ID != 2 {
1235		v = visible(scene(t, scenes))
1236	}
1237	if !v[0].Focused {
1238		t.Fatalf("after activate: %+v", v)
1239	}
1240	for {
1241		if f, ok := command(t, commands).(ports.FocusWindow); ok && f.ID == 2 {
1242			break
1243		}
1244	}
1245
1246}

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. Elsewhere: into the side 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
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
esc
close a dialog, leave a field

Branches 26

Tags 10

↑↓ moveenter openesc close