fullscreen_left_core_test.go RawHistoryFolder
1package core
2
3import (
4 "context"
5 "testing"
6 "time"
7
8 "github.com/bnema/neferwl/internal/ports"
9)
10
11// Through core, scroll overflow: an app whose fullscreen the user left by
12// activating another window cannot cover it again by asking at once; once
13// activated again, it may ask and is honoured.
14func TestCoreLeftFullscreenLatch(t *testing.T) {
15 client := make(chan ports.ClientEvent)
16 output := make(chan ports.OutputEvent)
17 commands := make(chan ports.ClientCommand, 64)
18 scenes := make(chan []ports.Scene, 1)
19 cfg := ports.Config{}
20 cfg.Keyboard.CmdKey = "super"
21 cfg.Layout.MaxColumns = 2
22 c, err := New(cfg, Channels{Client: client, Output: output, Commands: commands, Scenes: scenes, Clock: laterClock(t)})
23 if err != nil {
24 t.Fatal(err)
25 }
26 ctx, cancel := context.WithCancel(context.Background())
27 defer cancel()
28 done := make(chan struct{})
29 go func() { defer close(done); _ = c.Run(ctx) }()
30 go func() {
31 for range commands {
32 }
33 }()
34 full := func() ports.WindowID {
35 t.Helper()
36 select {
37 case s := <-scenes:
38 for _, w := range s[0].Windows {
39 if w.Fullscreen && !w.Hidden {
40 return w.ID
41 }
42 }
43 return 0
44 case <-time.After(time.Second):
45 t.Fatal("scene timeout")
46 return 0
47 }
48 }
49 output <- ports.OutputAdded{Info: ports.OutputInfo{Name: "OUT-1", Width: 100, Height: 80}}
50 full()
51 client <- ports.WindowMapped{ID: 1}
52 full()
53 client <- ports.WindowMapped{ID: 2}
54 full()
55 client <- ports.WindowFullscreenRequest{ID: 2, Fullscreen: true}
56 if id := full(); id != 2 {
57 t.Fatalf("fullscreen %d, want 2", id)
58 }
59 client <- ports.WindowActivate{ID: 1}
60 if id := full(); id != 0 {
61 t.Fatalf("after activation: fullscreen %d", id)
62 }
63 client <- ports.WindowFullscreenRequest{ID: 2, Fullscreen: true}
64 if id := full(); id != 0 {
65 t.Fatalf("re-request covered: fullscreen %d", id)
66 }
67 client <- ports.WindowActivate{ID: 2}
68 full()
69 client <- ports.WindowActivate{ID: 1}
70 full()
71 // The latch settled when 2 had the focus: scroll overflow honours an
72 // unfocused window's request again.
73 client <- ports.WindowFullscreenRequest{ID: 2, Fullscreen: true}
74 if id := full(); id != 2 {
75 t.Fatalf("after refocus: fullscreen %d, want 2", id)
76 }
77 cancel()
78 <-done
79 close(commands)
80}