1package core
2
3import (
4 "context"
5 "testing"
6
7 "github.com/bnema/neferwl/internal/ports"
8)
9
10func TestCoreCoveringFloatSceneAndHit(t *testing.T) {
11 cfg := ports.Config{}
12 cfg.Keyboard.CmdKey = "super"
13 cfg.Layout.MaxColumns = 2
14 cfg.Border.Width = 2
15 cfg.Floating.Dim = 0.3
16 scenes := make(chan []ports.Scene, 1)
17 commands := make(chan ports.ClientCommand, 128)
18 c, err := New(cfg, Channels{Scenes: scenes, Commands: commands})
19 if err != nil {
20 t.Fatal(err)
21 }
22 c.cur().info = ports.OutputInfo{Name: "OUT", Width: 100, Height: 80}
23 m := c.cur().mon
24 m.SetOutput(100, 80)
25 w := m.Current()
26 w.AddWindow(1)
27 w.AddFloating(2, 100, 80)
28 ctx := context.Background()
29 check := func(dim float64, ids ...WindowID) {
30 t.Helper()
31 if err := c.publish(ctx); err != nil {
32 t.Fatal(err)
33 }
34 s := (<-scenes)[0]
35 if s.Dim != dim {
36 t.Fatalf("dim %v, want %v", s.Dim, dim)
37 }
38 if len(s.Windows) != len(ids) {
39 t.Fatalf("scene %+v", s.Windows)
40 }
41 for i, id := range ids {
42 if s.Windows[i].ID != id {
43 t.Fatalf("scene %+v, want %v", s.Windows, ids)
44 }
45 }
46 }
47 check(0.3, 1, 2)
48 w.FocusID(1)
49 check(0, 2, 1)
50 if !w.Layout()[0].Below {
51 t.Fatal("float not below")
52 }
53 if id, _, _ := c.hit(50, 40); id != 1 {
54 t.Fatalf("hit %d, want tile", id)
55 }
56 w.AddFloating(3, 12, 10)
57 check(0.3, 2, 1, 3)
58 if id, _, _ := c.hit(50, 40); id != 3 {
59 t.Fatalf("hit %d, want dialog", id)
60 }
61 w.FocusID(2)
62 check(0.3, 1, 2, 3)
63 m.ToggleOverview()
64 if err := c.publish(ctx); err != nil {
65 t.Fatal(err)
66 }
67 if s := (<-scenes)[0]; s.Dim != 0.3 || !s.DimBehind {
68 t.Fatalf("overview dim %v behind %v", s.Dim, s.DimBehind)
69 }
70}
71
72// The overview darkens the wallpaper behind its previews, tiles only too.
73func TestCoreOverviewDimsBehind(t *testing.T) {
74 cfg := ports.Config{}
75 cfg.Keyboard.CmdKey = "super"
76 cfg.Layout.MaxColumns = 2
77 cfg.Floating.Dim = 0.3
78 scenes := make(chan []ports.Scene, 1)
79 c, err := New(cfg, Channels{Scenes: scenes, Commands: make(chan ports.ClientCommand, 128)})
80 if err != nil {
81 t.Fatal(err)
82 }
83 c.cur().info = ports.OutputInfo{Name: "OUT", Width: 100, Height: 80}
84 m := c.cur().mon
85 m.SetOutput(100, 80)
86 m.Current().AddWindow(1)
87 ctx := context.Background()
88 for _, tc := range []struct {
89 dim float64
90 behind bool
91 }{{0, false}, {0.3, true}, {0, false}} {
92 if err := c.publish(ctx); err != nil {
93 t.Fatal(err)
94 }
95 if s := (<-scenes)[0]; s.Dim != tc.dim || s.DimBehind != tc.behind {
96 t.Fatalf("dim %v behind %v, want %v %v", s.Dim, s.DimBehind, tc.dim, tc.behind)
97 }
98 m.ToggleOverview()
99 }
100}