1package core
2
3import (
4 "context"
5 "testing"
6
7 "github.com/bnema/neferwl/internal/ports"
8)
9
10// A neighbor workspace is visible only as an overview preview; its real
11// placement on the output is hidden. Its last configure must not be resized.
12func TestOverviewNeighborPreviewKeepsHiddenConfigureSize(t *testing.T) {
13 cfg := ports.Config{}
14 cfg.Keyboard.CmdKey = "super"
15 cfg.Layout.MaxColumns = 3
16 commands := make(chan ports.ClientCommand, 256)
17 scenes := make(chan []ports.Scene, 1)
18 c, err := New(cfg, Channels{Commands: commands, Scenes: scenes})
19 if err != nil {
20 t.Fatal(err)
21 }
22 c.addScreen(ports.OutputInfo{Name: "OUT-1", Width: 600, Height: 400})
23 m := c.cur().mon
24 m.AddWindow(1)
25 m.Focus(1)
26 m.AddWindow(2)
27 ctx := context.Background()
28 publish := func() []ports.ConfigureWindow {
29 t.Helper()
30 if err := c.publish(ctx); err != nil {
31 t.Fatal(err)
32 }
33 <-scenes
34 var sent []ports.ConfigureWindow
35 for len(commands) > 0 {
36 if v, ok := (<-commands).(ports.ConfigureWindow); ok {
37 sent = append(sent, v)
38 }
39 }
40 return sent
41 }
42 publish() // establish a sized configure while workspace 2 is on screen
43 before := c.configures.sent[2]
44 if before.Width == 0 || before.Height == 0 {
45 t.Fatalf("missing prior size: %+v", before)
46 }
47 m.Focus(0)
48 publish() // the workspace is hidden on the output
49 if c.configures.sent[2].Visible {
50 t.Fatal("neighbor was not hidden before overview")
51 }
52 m.ToggleOverview()
53 preview := previewOf(t, m.Layout(), 2)
54 if preview.Hidden || preview.Preview <= 0 {
55 t.Fatalf("neighbor not shown as preview: %+v", preview)
56 }
57 for _, v := range publish() {
58 if v.ID == 2 && (v.Width != before.Width || v.Height != before.Height) {
59 t.Fatalf("hidden neighbor resized from %+v to %+v", before, v)
60 }
61 }
62 got := c.configures.sent[2]
63 if got.Width != before.Width || got.Height != before.Height {
64 t.Fatalf("neighbor size from %+v to %+v", before, got)
65 }
66}
67
68func TestOverviewConfigureUsesRealLayoutAfterMaximize(t *testing.T) {
69 cfg := ports.Config{}
70 cfg.Keyboard.CmdKey = "super"
71 cfg.Layout.Overflow = "fixed"
72 cfg.Layout.MaxColumns = 3
73 commands := make(chan ports.ClientCommand, 256)
74 scenes := make(chan []ports.Scene, 1)
75 c, err := New(cfg, Channels{Commands: commands, Scenes: scenes})
76 if err != nil {
77 t.Fatal(err)
78 }
79 c.addScreen(ports.OutputInfo{Name: "OUT-1", Width: 600, Height: 400})
80 m := c.cur().mon
81 for id := WindowID(1); id <= 3; id++ {
82 m.AddWindow(id)
83 }
84 ctx := context.Background()
85 publish := func() []ports.ConfigureWindow {
86 t.Helper()
87 if err := c.publish(ctx); err != nil {
88 t.Fatal(err)
89 }
90 <-scenes
91 var out []ports.ConfigureWindow
92 for len(commands) > 0 {
93 if v, ok := (<-commands).(ports.ConfigureWindow); ok {
94 out = append(out, v)
95 }
96 }
97 return out
98 }
99 publish()
100 before := c.configures.sent[3]
101 m.ToggleOverview()
102 publish()
103 m.Current().ToggleFullWidth() // a real workspace mutation, not an overview bind
104 real := previewOf(t, m.Current().Layout(), 3)
105 expected := c.clientRect(real)
106 ps := m.Layout()
107 preview := previewOf(t, ps, 3)
108 if preview.Preview == 0 || expected.W <= before.Width {
109 t.Fatalf("setup before %+v expected %+v preview %+v", before, expected, preview)
110 }
111 got := publish()
112 found := false
113 for _, v := range got {
114 if v.ID == 3 {
115 found = true
116 if v.Width != expected.W || v.Height != expected.H {
117 t.Fatalf("preview sized configure %+v want %dx%d", v, expected.W, expected.H)
118 }
119 }
120 }
121 if !found {
122 t.Fatalf("no immediate resize while overview open; configures %v", got)
123 }
124}