|
| 1 | +#include "../test.h" |
| 2 | + |
| 3 | +// test that maximized toplevels are automatically unmaximized when new |
| 4 | +// toplevels are added |
| 5 | +// 1. Enable auto-tiling |
| 6 | +// 2. Open two toplevels (A and B) - they should tile side by side |
| 7 | +// 3. Maximize one (A) |
| 8 | +// 4. Open another toplevel (C) |
| 9 | +// Expected: A gets automatically unmaximized, and all three (A, B, C) are tiled |
| 10 | +// together |
| 11 | +int main() { |
| 12 | + DEFAULT(3); |
| 13 | + |
| 14 | + // enable auto-tiling |
| 15 | + AWMSG("b r auto_tile"); |
| 16 | + sleep(1); |
| 17 | + |
| 18 | + // get initial workspace state |
| 19 | + AWMSG_J("w l", workspaces); |
| 20 | + json workspace = *workspaces.begin(); |
| 21 | + ASSERT(workspace["auto_tile"] == true); |
| 22 | + |
| 23 | + // open first toplevel (already opened by DEFAULT(3)) |
| 24 | + sleep(1); |
| 25 | + |
| 26 | + // verify we have 3 toplevels |
| 27 | + AWMSG_J("t l", toplevels); |
| 28 | + ASSERT(toplevels.size() == 3); |
| 29 | + |
| 30 | + // get the toplevels |
| 31 | + auto it = toplevels.begin(); |
| 32 | + json toplevel_a = *it++; |
| 33 | + json toplevel_b = *it++; |
| 34 | + json toplevel_c = *it++; |
| 35 | + |
| 36 | + // verify none are maximized initially |
| 37 | + ASSERT(toplevel_a["maximized"] == false); |
| 38 | + ASSERT(toplevel_b["maximized"] == false); |
| 39 | + ASSERT(toplevel_c["maximized"] == false); |
| 40 | + |
| 41 | + // verify all have reasonable dimensions (should be tiled in a grid) |
| 42 | + // with 3 toplevels in grid mode, they should not take full usable area |
| 43 | + AWMSG_J("o l", outputs); |
| 44 | + json output = *outputs.begin(); |
| 45 | + int usable_width = output["usable"]["width"]; |
| 46 | + int usable_height = output["usable"]["height"]; |
| 47 | + |
| 48 | + // each toplevel should be smaller than full usable area |
| 49 | + ASSERT(toplevel_a["width"] < usable_width); |
| 50 | + ASSERT(toplevel_b["width"] < usable_width); |
| 51 | + ASSERT(toplevel_c["width"] < usable_width); |
| 52 | + |
| 53 | + // focus the first toplevel |
| 54 | + AWMSG("b r previous"); |
| 55 | + AWMSG("b r previous"); |
| 56 | + sleep(1); |
| 57 | + |
| 58 | + // maximize the first toplevel |
| 59 | + AWMSG("b r maximize"); |
| 60 | + sleep(1); |
| 61 | + |
| 62 | + // verify it's maximized and takes full usable area |
| 63 | + AWMSG_J("t l", toplevels_max); |
| 64 | + auto it_max = toplevels_max.begin(); |
| 65 | + json toplevel_a_max = *it_max++; |
| 66 | + json toplevel_b_after = *it_max++; |
| 67 | + json toplevel_c_after = *it_max++; |
| 68 | + |
| 69 | + ASSERT(toplevel_a_max["maximized"] == true); |
| 70 | + ASSERT(toplevel_a_max["width"] == usable_width); |
| 71 | + ASSERT(toplevel_a_max["height"] == usable_height); |
| 72 | + |
| 73 | + // the other two should not be maximized |
| 74 | + ASSERT(toplevel_b_after["maximized"] == false); |
| 75 | + ASSERT(toplevel_c_after["maximized"] == false); |
| 76 | + |
| 77 | + std::cout << "Maximized toplevel verified. Opening new toplevel..." |
| 78 | + << std::endl; |
| 79 | + |
| 80 | + // open a new toplevel |
| 81 | + spawn("foot"); |
| 82 | + sleep(2); |
| 83 | + |
| 84 | + // verify we have 4 toplevels now |
| 85 | + AWMSG_J("t l", toplevels_final); |
| 86 | + ASSERT(toplevels_final.size() == 4); |
| 87 | + |
| 88 | + // get all toplevels |
| 89 | + auto it_final = toplevels_final.begin(); |
| 90 | + json tl0 = *it_final++; |
| 91 | + json tl1 = *it_final++; |
| 92 | + json tl2 = *it_final++; |
| 93 | + json tl3 = *it_final++; |
| 94 | + |
| 95 | + // After adding a new toplevel, the previously maximized one should be |
| 96 | + // auto-unmaximized So all 4 toplevels should be tiled (none maximized) |
| 97 | + int maximized_count = 0; |
| 98 | + |
| 99 | + for (json *tl : {&tl0, &tl1, &tl2, &tl3}) { |
| 100 | + if ((*tl)["maximized"] == true) { |
| 101 | + maximized_count++; |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + // there should be NO maximized toplevels after adding a new one |
| 106 | + ASSERT(maximized_count == 0); |
| 107 | + |
| 108 | + // all 4 toplevels should be tiled (smaller than full usable area) |
| 109 | + for (json *tl : {&tl0, &tl1, &tl2, &tl3}) { |
| 110 | + int width = (*tl)["width"]; |
| 111 | + int height = (*tl)["height"]; |
| 112 | + |
| 113 | + // each tiled window should be smaller than full area |
| 114 | + // (they should be in a grid or similar layout) |
| 115 | + ASSERT(width < usable_width || height < usable_height); |
| 116 | + |
| 117 | + // make sure they're not hidden (width/height should be reasonable) |
| 118 | + ASSERT(width > 0); |
| 119 | + ASSERT(height > 0); |
| 120 | + } |
| 121 | + |
| 122 | + std::cout << "Test passed: Previously maximized toplevel was " |
| 123 | + "auto-unmaximized when new toplevel was added" |
| 124 | + << std::endl; |
| 125 | + |
| 126 | + return 0; |
| 127 | +} |
0 commit comments