| 1 |
#include "tests.hpp" |
| 2 |
#include "../../shared.hpp" |
| 3 |
#include "../../hyprctlCompat.hpp" |
| 4 |
#include <thread> |
| 5 |
#include <hyprutils/os/Process.hpp> |
| 6 |
#include <hyprutils/memory/WeakPtr.hpp> |
| 7 |
#include <hyprutils/utils/ScopeGuard.hpp> |
| 8 |
#include "../shared.hpp" |
| 9 |
|
| 10 |
using namespace Hyprutils::OS; |
| 11 |
using namespace Hyprutils::Memory; |
| 12 |
using namespace Hyprutils::Utils; |
| 13 |
|
| 14 |
#define UP CUniquePointer |
| 15 |
#define SP CSharedPointer |
| 16 |
|
| 17 |
// TODO: decompose this into multiple test cases |
| 18 |
TEST_CASE(groups) { |
| 19 |
// test on workspace "window" |
| 20 |
NLog::log("{}Dispatching workspace `groups`", Colors::YELLOW); |
| 21 |
getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups' })"); |
| 22 |
|
| 23 |
NLog::log("{}Testing movewindoworgroup from group to group", Colors::YELLOW); |
| 24 |
auto kittyA = Tests::spawnKitty("kittyA"); |
| 25 |
if (!kittyA) { |
| 26 |
FAIL_TEST("Could not spawn kitty"); |
| 27 |
} |
| 28 |
|
| 29 |
// check kitty properties. One kitty should take the entire screen, minus the gaps. |
| 30 |
NLog::log("{}Check kittyA dimensions", Colors::YELLOW); |
| 31 |
{ |
| 32 |
auto str = getFromSocket("/clients"); |
| 33 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 34 |
EXPECT_COUNT_STRING(str, "size: 1876,1036", 1); |
| 35 |
EXPECT_COUNT_STRING(str, "fullscreen: 0", 1); |
| 36 |
} |
| 37 |
|
| 38 |
auto kittyB = Tests::spawnKitty("kittyB"); |
| 39 |
if (!kittyB) { |
| 40 |
FAIL_TEST("Could not spawn kitty"); |
| 41 |
} |
| 42 |
|
| 43 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kittyB' })")); |
| 44 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 45 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kittyA' })")); |
| 46 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 47 |
|
| 48 |
NLog::log("{}Check kittyB dimensions", Colors::YELLOW); |
| 49 |
{ |
| 50 |
auto str = getFromSocket("/activewindow"); |
| 51 |
EXPECT_COUNT_STRING(str, "size: 931,1015", 1); |
| 52 |
EXPECT_COUNT_STRING(str, "fullscreen: 0", 1); |
| 53 |
} |
| 54 |
|
| 55 |
auto kittyC = Tests::spawnKitty("kittyC"); |
| 56 |
if (!kittyC) { |
| 57 |
FAIL_TEST("Could not spawn kitty"); |
| 58 |
} |
| 59 |
|
| 60 |
NLog::log("{}Check kittyC dimensions", Colors::YELLOW); |
| 61 |
{ |
| 62 |
auto str = getFromSocket("/activewindow"); |
| 63 |
EXPECT_COUNT_STRING(str, "size: 931,1015", 1); |
| 64 |
EXPECT_COUNT_STRING(str, "fullscreen: 0", 1); |
| 65 |
} |
| 66 |
|
| 67 |
OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'right', group_aware = true })")); |
| 68 |
NLog::log("{}Check that dimensions remain the same after move", Colors::YELLOW); |
| 69 |
{ |
| 70 |
auto str = getFromSocket("/activewindow"); |
| 71 |
EXPECT_COUNT_STRING(str, "size: 931,1015", 1); |
| 72 |
EXPECT_COUNT_STRING(str, "fullscreen: 0", 1); |
| 73 |
} |
| 74 |
|
| 75 |
// kill all |
| 76 |
NLog::log("{}Kill windows", Colors::YELLOW); |
| 77 |
Tests::killAllWindows(); |
| 78 |
|
| 79 |
NLog::log("{}Spawning kittyProcA", Colors::YELLOW); |
| 80 |
auto kittyProcA = Tests::spawnKitty(); |
| 81 |
if (!kittyProcA) { |
| 82 |
FAIL_TEST("Could not spawn kitty"); |
| 83 |
} |
| 84 |
|
| 85 |
NLog::log("{}Expecting 1 window", Colors::YELLOW); |
| 86 |
ASSERT(Tests::windowCount(), 1); |
| 87 |
|
| 88 |
// check kitty properties. One kitty should take the entire screen, minus the gaps. |
| 89 |
NLog::log("{}Check kitty dimensions", Colors::YELLOW); |
| 90 |
{ |
| 91 |
auto str = getFromSocket("/clients"); |
| 92 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 93 |
EXPECT_COUNT_STRING(str, "size: 1876,1036", 1); |
| 94 |
EXPECT_COUNT_STRING(str, "fullscreen: 0", 1); |
| 95 |
} |
| 96 |
|
| 97 |
// group the kitty |
| 98 |
NLog::log("{}Enable group and groupbar", Colors::YELLOW); |
| 99 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 100 |
OK(getFromSocket("/eval hl.config({ group = { groupbar = { enabled = 1 } } })")); |
| 101 |
|
| 102 |
// check the height of the window now |
| 103 |
NLog::log("{}Recheck kitty dimensions", Colors::YELLOW); |
| 104 |
{ |
| 105 |
auto str = getFromSocket("/clients"); |
| 106 |
EXPECT_CONTAINS(str, "at: 22,43"); |
| 107 |
EXPECT_CONTAINS(str, "size: 1876,1015"); |
| 108 |
} |
| 109 |
|
| 110 |
// disable the groupbar for ease of testing for now |
| 111 |
NLog::log("{}Disable groupbar", Colors::YELLOW); |
| 112 |
OK(getFromSocket("/eval hl.config({ group = { groupbar = { enabled = 0 } } })")); |
| 113 |
|
| 114 |
// check the height of the window now |
| 115 |
NLog::log("{}Recheck kitty dimensions", Colors::YELLOW); |
| 116 |
{ |
| 117 |
auto str = getFromSocket("/clients"); |
| 118 |
EXPECT_CONTAINS(str, "at: 22,22"); |
| 119 |
EXPECT_CONTAINS(str, "size: 1876,1036"); |
| 120 |
} |
| 121 |
|
| 122 |
// kill all |
| 123 |
NLog::log("{}Kill windows", Colors::YELLOW); |
| 124 |
Tests::killAllWindows(); |
| 125 |
|
| 126 |
NLog::log("{}Spawn kitty again", Colors::YELLOW); |
| 127 |
kittyProcA = Tests::spawnKitty(); |
| 128 |
if (!kittyProcA) { |
| 129 |
FAIL_TEST("Could not spawn kitty"); |
| 130 |
} |
| 131 |
|
| 132 |
NLog::log("{}Group kitty", Colors::YELLOW); |
| 133 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 134 |
|
| 135 |
// check the height of the window now |
| 136 |
NLog::log("{}Check kitty dimensions 2", Colors::YELLOW); |
| 137 |
{ |
| 138 |
auto str = getFromSocket("/clients"); |
| 139 |
EXPECT_CONTAINS(str, "at: 22,22"); |
| 140 |
EXPECT_CONTAINS(str, "size: 1876,1036"); |
| 141 |
} |
| 142 |
|
| 143 |
NLog::log("{}Spawn kittyProcB", Colors::YELLOW); |
| 144 |
auto kittyProcB = Tests::spawnKitty(); |
| 145 |
if (!kittyProcB) { |
| 146 |
FAIL_TEST("Could not spawn kitty"); |
| 147 |
} |
| 148 |
|
| 149 |
NLog::log("{}Expecting 2 windows", Colors::YELLOW); |
| 150 |
ASSERT(Tests::windowCount(), 2); |
| 151 |
|
| 152 |
size_t lastActiveKittyIdx = 0; |
| 153 |
|
| 154 |
NLog::log("{}Get last active kitty id", Colors::YELLOW); |
| 155 |
try { |
| 156 |
auto str = getFromSocket("/activewindow"); |
| 157 |
lastActiveKittyIdx = std::stoull(str.substr(7, str.find(" -> ") - 7), nullptr, 16); |
| 158 |
} catch (...) { FAIL_TEST("Could not extract the active window id"); } |
| 159 |
|
| 160 |
// test cycling through |
| 161 |
|
| 162 |
NLog::log("{}Test cycling through grouped windows", Colors::YELLOW); |
| 163 |
OK(getFromSocket("/dispatch hl.dsp.group.next()")); |
| 164 |
|
| 165 |
try { |
| 166 |
auto str = getFromSocket("/activewindow"); |
| 167 |
ASSERT(lastActiveKittyIdx != std::stoull(str.substr(7, str.find(" -> ") - 7), nullptr, 16), true); |
| 168 |
} catch (...) { FAIL_TEST("Could not extract the active window id"); } |
| 169 |
|
| 170 |
getFromSocket("/dispatch hl.dsp.group.next()"); |
| 171 |
|
| 172 |
try { |
| 173 |
auto str = getFromSocket("/activewindow"); |
| 174 |
ASSERT(lastActiveKittyIdx, std::stoull(str.substr(7, str.find(" -> ") - 7), nullptr, 16)); |
| 175 |
} catch (...) { FAIL_TEST("Could not extract the active window id"); } |
| 176 |
|
| 177 |
// test movegroupwindow: focus should follow the moved window |
| 178 |
NLog::log("{}Test movegroupwindow focus follows window", Colors::YELLOW); |
| 179 |
try { |
| 180 |
auto str = getFromSocket("/activewindow"); |
| 181 |
auto activeBeforeMove = std::stoull(str.substr(7, str.find(" -> ") - 7), nullptr, 16); |
| 182 |
OK(getFromSocket("/dispatch hl.dsp.group.move_window({ forward = true })")); |
| 183 |
str = getFromSocket("/activewindow"); |
| 184 |
auto activeAfterMove = std::stoull(str.substr(7, str.find(" -> ") - 7), nullptr, 16); |
| 185 |
EXPECT(activeAfterMove, activeBeforeMove); |
| 186 |
} catch (...) { FAIL_TEST("Could not extract the active window id"); } |
| 187 |
|
| 188 |
// and backwards |
| 189 |
NLog::log("{}Test movegroupwindow backwards", Colors::YELLOW); |
| 190 |
try { |
| 191 |
auto str = getFromSocket("/activewindow"); |
| 192 |
auto activeBeforeMove = std::stoull(str.substr(7, str.find(" -> ") - 7), nullptr, 16); |
| 193 |
OK(getFromSocket("/dispatch hl.dsp.group.move_window({ forward = false })")); |
| 194 |
str = getFromSocket("/activewindow"); |
| 195 |
auto activeAfterMove = std::stoull(str.substr(7, str.find(" -> ") - 7), nullptr, 16); |
| 196 |
EXPECT(activeAfterMove, activeBeforeMove); |
| 197 |
} catch (...) { FAIL_TEST("Could not extract the active window id"); } |
| 198 |
|
| 199 |
NLog::log("{}Disable autogrouping", Colors::YELLOW); |
| 200 |
OK(getFromSocket("/eval hl.config({ group = { auto_group = false } })")); |
| 201 |
OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 2 } })")); |
| 202 |
|
| 203 |
NLog::log("{}Spawn kittyProcC", Colors::YELLOW); |
| 204 |
auto kittyProcC = Tests::spawnKitty(); |
| 205 |
if (!kittyProcC) { |
| 206 |
FAIL_TEST("Could not spawn kitty"); |
| 207 |
} |
| 208 |
|
| 209 |
NLog::log("{}Expecting 3 windows 2", Colors::YELLOW); |
| 210 |
ASSERT(Tests::windowCount(), 3); |
| 211 |
{ |
| 212 |
auto str = getFromSocket("/clients"); |
| 213 |
EXPECT_COUNT_STRING(str, "at: 22,22", 2); |
| 214 |
} |
| 215 |
|
| 216 |
OK(getFromSocket("/eval hl.config({ dwindle = { force_split = 0 } })")); |
| 217 |
OK(getFromSocket("/dispatch hl.dsp.focus({ direction = 'left' })")); |
| 218 |
OK(getFromSocket("/dispatch hl.dsp.group.active({ index = 1 })")); |
| 219 |
OK(getFromSocket("/eval hl.config({ group = { auto_group = true } })")); |
| 220 |
OK(getFromSocket("/eval hl.config({ group = { insert_after_current = false } })")); |
| 221 |
|
| 222 |
NLog::log("{}Spawn kittyProcD", Colors::YELLOW); |
| 223 |
auto kittyProcD = Tests::spawnKitty(); |
| 224 |
if (!kittyProcD) { |
| 225 |
FAIL_TEST("Could not spawn kitty"); |
| 226 |
} |
| 227 |
|
| 228 |
NLog::log("{}Expecting 4 windows", Colors::YELLOW); |
| 229 |
ASSERT(Tests::windowCount(), 4); |
| 230 |
|
| 231 |
OK(getFromSocket("/dispatch hl.dsp.group.active({ index = 3 })")); |
| 232 |
|
| 233 |
{ |
| 234 |
auto str = getFromSocket("/activewindow"); |
| 235 |
EXPECT_CONTAINS(str, std::format("pid: {}", kittyProcD->pid())); |
| 236 |
} |
| 237 |
|
| 238 |
// kill all |
| 239 |
NLog::log("{}Kill windows", Colors::YELLOW); |
| 240 |
Tests::killAllWindows(); |
| 241 |
|
| 242 |
NLog::log("{}Expecting 0 windows", Colors::YELLOW); |
| 243 |
ASSERT(Tests::windowCount(), 0); |
| 244 |
|
| 245 |
// test movewindoworgroup: direction should be respected when extracting from group |
| 246 |
NLog::log("{}Test movewindoworgroup respects direction out of group", Colors::YELLOW); |
| 247 |
OK(getFromSocket("/eval hl.config({ group = { groupbar = { enabled = 0 } } })")); |
| 248 |
{ |
| 249 |
auto kittyE = Tests::spawnKitty(); |
| 250 |
if (!kittyE) { |
| 251 |
FAIL_TEST("Could not spawn kitty"); |
| 252 |
} |
| 253 |
|
| 254 |
// group kitty, and new windows should be auto-grouped |
| 255 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 256 |
|
| 257 |
auto kittyF = Tests::spawnKitty(); |
| 258 |
if (!kittyF) { |
| 259 |
FAIL_TEST("Could not spawn kitty"); |
| 260 |
} |
| 261 |
ASSERT(Tests::windowCount(), 2); |
| 262 |
|
| 263 |
// both windows should be grouped at the same position |
| 264 |
{ |
| 265 |
auto str = getFromSocket("/clients"); |
| 266 |
EXPECT_COUNT_STRING(str, "at: 22,22", 2); |
| 267 |
} |
| 268 |
|
| 269 |
// move active window out of group to the right |
| 270 |
NLog::log("{}Test movewindoworgroup r", Colors::YELLOW); |
| 271 |
OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'right', group_aware = true })")); |
| 272 |
|
| 273 |
// the group should stay at x=22, the extracted window should be to the right |
| 274 |
{ |
| 275 |
auto str = getFromSocket("/clients"); |
| 276 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 277 |
} |
| 278 |
|
| 279 |
// move it back into the group |
| 280 |
OK(getFromSocket("/dispatch hl.dsp.window.move({ into_group = 'left' })")); |
| 281 |
|
| 282 |
// move active window out of group downward |
| 283 |
NLog::log("{}Test movewindoworgroup d", Colors::YELLOW); |
| 284 |
OK(getFromSocket("/dispatch hl.dsp.window.move({ direction = 'down', group_aware = true })")); |
| 285 |
|
| 286 |
// the group should stay at y=22, the extracted window should be below |
| 287 |
{ |
| 288 |
auto str = getFromSocket("/clients"); |
| 289 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 290 |
} |
| 291 |
|
| 292 |
Tests::killAllWindows(); |
| 293 |
ASSERT(Tests::windowCount(), 0); |
| 294 |
} |
| 295 |
|
| 296 |
// test that we can auto-group a new floated window into the focused floated group |
| 297 |
NLog::log("{}Test that we can auto-group a new floated window into the focused floated group.", Colors::GREEN); |
| 298 |
|
| 299 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-floated-A', match = { class = 'kitty_floated_A' } })")); |
| 300 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-floated-A', float = true })")); |
| 301 |
auto kittyFA = Tests::spawnKitty("kitty_floated_A"); |
| 302 |
if (!kittyFA) { |
| 303 |
FAIL_TEST("Could not spawn kitty"); |
| 304 |
} |
| 305 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 306 |
|
| 307 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-floated-B', match = { class = 'kitty_floated_B' } })")); |
| 308 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-floated-B', float = true })")); |
| 309 |
auto kittyFB = Tests::spawnKitty("kitty_floated_B"); |
| 310 |
if (!kittyFB) { |
| 311 |
FAIL_TEST("Could not spawn kitty"); |
| 312 |
} |
| 313 |
ASSERT(Tests::windowCount(), 2); |
| 314 |
|
| 315 |
{ |
| 316 |
auto clients = getFromSocket("/clients"); |
| 317 |
auto classPos = clients.find("class: kitty_floated_B"); |
| 318 |
if (classPos == std::string::npos) { |
| 319 |
FAIL_TEST("Could not find kitty_floated_B in clients output"); |
| 320 |
} else { |
| 321 |
auto entryStart = clients.rfind("Window ", classPos); |
| 322 |
auto entryEnd = clients.find("\n\n", classPos); |
| 323 |
auto windowEntry = clients.substr(entryStart, entryEnd - entryStart); |
| 324 |
EXPECT_CONTAINS(windowEntry, "floating: 1"); |
| 325 |
EXPECT_NOT_CONTAINS(windowEntry, "grouped: 0"); |
| 326 |
} |
| 327 |
} |
| 328 |
|
| 329 |
Tests::killAllWindows(); |
| 330 |
ASSERT(Tests::windowCount(), 0); |
| 331 |
|
| 332 |
// test that we deny a floated window getting auto-grouped into a tiled group. |
| 333 |
NLog::log("{}Test that we deny a floated window getting auto-grouped into a tiled group.", Colors::GREEN); |
| 334 |
|
| 335 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-tiled', match = { class = 'kitty_tiled' } })")); |
| 336 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-tiled', tile = true })")); |
| 337 |
auto kittyProcE = Tests::spawnKitty("kitty_tiled"); |
| 338 |
if (!kittyProcE) { |
| 339 |
FAIL_TEST("Could not spawn kitty"); |
| 340 |
} |
| 341 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 342 |
|
| 343 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-floated', match = { class = 'kitty_floated' } })")); |
| 344 |
OK(getFromSocket("/eval hl.window_rule({ name = 'kitty-floated', float = true })")); |
| 345 |
auto kittyProcF = Tests::spawnKitty("kitty_floated"); |
| 346 |
if (!kittyProcF) { |
| 347 |
FAIL_TEST("Could not spawn kitty"); |
| 348 |
} |
| 349 |
|
| 350 |
ASSERT(Tests::windowCount(), 2); |
| 351 |
|
| 352 |
{ |
| 353 |
auto clients = getFromSocket("/clients"); |
| 354 |
auto classPos = clients.find("class: kitty_floated"); |
| 355 |
if (classPos == std::string::npos) { |
| 356 |
FAIL_TEST("Could not find kitty_floated in clients output"); |
| 357 |
} else { |
| 358 |
auto entryStart = clients.rfind("Window ", classPos); |
| 359 |
auto entryEnd = clients.find("\n\n", classPos); |
| 360 |
auto windowEntry = clients.substr(entryStart, entryEnd - entryStart); |
| 361 |
EXPECT_CONTAINS(windowEntry, "floating: 1"); |
| 362 |
EXPECT_CONTAINS(windowEntry, "grouped: 0"); |
| 363 |
} |
| 364 |
} |
| 365 |
|
| 366 |
Tests::killAllWindows(); |
| 367 |
ASSERT(Tests::windowCount(), 0); |
| 368 |
|
| 369 |
// Tests for grouping/merging logic |
| 370 |
NLog::log("{}Testing locked groups w/ invade", Colors::GREEN); |
| 371 |
|
| 372 |
Tests::killAllWindows(); |
| 373 |
ASSERT(Tests::windowCount(), 0); |
| 374 |
|
| 375 |
// Test normal, unlocked groups |
| 376 |
{ |
| 377 |
auto winA = Tests::spawnKitty("unlocked"); |
| 378 |
if (!winA) { |
| 379 |
FAIL_TEST("Could not spawn unlocked kitty"); |
| 380 |
} |
| 381 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 382 |
|
| 383 |
auto winB = Tests::spawnKitty("top"); |
| 384 |
if (!winB) { |
| 385 |
FAIL_TEST("Could not spawn top kitty"); |
| 386 |
} |
| 387 |
|
| 388 |
// Verify it DID merge into a group |
| 389 |
{ |
| 390 |
auto str = getFromSocket("/clients"); |
| 391 |
EXPECT_COUNT_STRING(str, "at: 22,22", 2); |
| 392 |
} |
| 393 |
} |
| 394 |
|
| 395 |
Tests::killAllWindows(); |
| 396 |
ASSERT(Tests::windowCount(), 0); |
| 397 |
|
| 398 |
// Test locked groups |
| 399 |
{ |
| 400 |
auto lockedWin = Tests::spawnKitty("locked"); |
| 401 |
if (!lockedWin) { |
| 402 |
FAIL_TEST("Could not spawn locked kitty"); |
| 403 |
} |
| 404 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 405 |
OK(getFromSocket(std::format("/dispatch hl.dsp.focus({{ window = 'pid:{}' }})", lockedWin->pid()))); |
| 406 |
OK(getFromSocket("/dispatch hl.dsp.group.lock_active({ action = 'set' })")); |
| 407 |
|
| 408 |
auto winB = Tests::spawnKitty("top"); |
| 409 |
if (!winB) { |
| 410 |
FAIL_TEST("Could not spawn top kitty"); |
| 411 |
} |
| 412 |
|
| 413 |
// Verify it did NOT merge into the locked group |
| 414 |
{ |
| 415 |
auto str = getFromSocket("/clients"); |
| 416 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 417 |
} |
| 418 |
} |
| 419 |
|
| 420 |
Tests::killAllWindows(); |
| 421 |
ASSERT(Tests::windowCount(), 0); |
| 422 |
|
| 423 |
// Test locked groups WITH invade rule |
| 424 |
{ |
| 425 |
OK(getFromSocket("/eval hl.window_rule({ name = 'locked-im', match = { class = '^locked|invade$' } })")); |
| 426 |
OK(getFromSocket("/eval hl.window_rule({ name = 'locked-im', group = 'set always lock invade' })")); |
| 427 |
|
| 428 |
auto lockedWin = Tests::spawnKitty("locked"); |
| 429 |
if (!lockedWin) { |
| 430 |
FAIL_TEST("Could not spawn locked kitty"); |
| 431 |
} |
| 432 |
|
| 433 |
auto invadingWin = Tests::spawnKitty("invade"); |
| 434 |
if (!invadingWin) { |
| 435 |
FAIL_TEST("Could not spawn invading kitty"); |
| 436 |
} |
| 437 |
|
| 438 |
// Verify it DID merge into the locked group |
| 439 |
auto str = getFromSocket("/clients"); |
| 440 |
EXPECT_COUNT_STRING(str, "at: 22,22", 2); |
| 441 |
} |
| 442 |
|
| 443 |
Tests::killAllWindows(); |
| 444 |
ASSERT(Tests::windowCount(), 0); |
| 445 |
|
| 446 |
// Test groupbar middle click close config |
| 447 |
{ |
| 448 |
OK(getFromSocket("/eval hl.config({ group = { auto_group = true, groupbar = { enabled = true, middle_click_close = false } } })")); |
| 449 |
|
| 450 |
auto kittyA = Tests::spawnKitty("kittyA"); |
| 451 |
if (!kittyA) { |
| 452 |
FAIL_TEST("Could not spawn kitty"); |
| 453 |
} |
| 454 |
|
| 455 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 456 |
|
| 457 |
auto kittyB = Tests::spawnKitty("kittyB"); |
| 458 |
if (!kittyB) { |
| 459 |
FAIL_TEST("Could not spawn kitty"); |
| 460 |
} |
| 461 |
|
| 462 |
EXPECT(Tests::windowCount(), 2); |
| 463 |
|
| 464 |
OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 80, y = 32 })")); |
| 465 |
OK(getFromSocket("/eval hl.plugin.test.click(274, 1)")); |
| 466 |
OK(getFromSocket("/eval hl.plugin.test.click(274, 0)")); |
| 467 |
|
| 468 |
std::this_thread::sleep_for(std::chrono::milliseconds(100)); |
| 469 |
EXPECT(Tests::windowCount(), 2); |
| 470 |
|
| 471 |
OK(getFromSocket("/eval hl.config({ group = { groupbar = { middle_click_close = true } } })")); |
| 472 |
OK(getFromSocket("/dispatch hl.dsp.cursor.move({ x = 80, y = 32 })")); |
| 473 |
OK(getFromSocket("/eval hl.plugin.test.click(274, 1)")); |
| 474 |
OK(getFromSocket("/eval hl.plugin.test.click(274, 0)")); |
| 475 |
|
| 476 |
Tests::waitUntilWindowsN(1); |
| 477 |
EXPECT(Tests::windowCount(), 1); |
| 478 |
|
| 479 |
OK(getFromSocket("/eval hl.config({ group = { groupbar = { enabled = 0 } } })")); |
| 480 |
} |
| 481 |
|
| 482 |
Tests::killAllWindows(); |
| 483 |
ASSERT(Tests::windowCount(), 0); |
| 484 |
} |
| 485 |
|
| 486 |
TEST_CASE(groupsNoCrash) { |
| 487 |
auto kittyA = Tests::spawnKitty("kittyA"); |
| 488 |
|
| 489 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 490 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 491 |
|
| 492 |
{ |
| 493 |
auto curr = getFromSocket("/activewindow"); |
| 494 |
EXPECT_CONTAINS(curr, "kittyA"); |
| 495 |
} |
| 496 |
} |
| 497 |
|
| 498 |
TEST_CASE(groupsLuaApi) { |
| 499 |
NLog::log("{}Dispatching workspace `groups-lua-api`", Colors::YELLOW); |
| 500 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-api' })")); |
| 501 |
OK(getFromSocket("/eval hl.config({ group = { auto_group = false, insert_after_current = false, groupbar = { enabled = false } } })")); |
| 502 |
|
| 503 |
auto kittyA = Tests::spawnKitty("luaGroupA"); |
| 504 |
auto kittyB = Tests::spawnKitty("luaGroupB"); |
| 505 |
auto kittyC = Tests::spawnKitty("luaGroupC"); |
| 506 |
auto kittyD = Tests::spawnKitty("luaGroupD"); |
| 507 |
auto kittyE = Tests::spawnKitty("luaGroupE"); |
| 508 |
|
| 509 |
if (!kittyA || !kittyB || !kittyC || !kittyD || !kittyE) |
| 510 |
FAIL_TEST("Could not spawn kitty"); |
| 511 |
|
| 512 |
ASSERT(Tests::windowCount(), 5); |
| 513 |
|
| 514 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:luaGroupA' })")); |
| 515 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 516 |
|
| 517 |
NLog::log("{}Testing Lua group add/remove by object and index", Colors::YELLOW); |
| 518 |
OK(getFromSocket("/eval local a=hl.get_window('class:luaGroupA') local b=hl.get_window('class:luaGroupB') local c=hl.get_window('class:luaGroupC') assert(a and b and c and " |
| 519 |
"a.group) local g=a.group g:add(b) assert(b.group == g) assert(g.size == 2) g:add(c, 1) assert(c.group == g) assert(g.members[1] == c) assert(g.size == 3) " |
| 520 |
"g:remove(1) assert(c.group == nil) assert(g.size == 2) g:remove(b) assert(b.group == nil) assert(g.size == 1)")); |
| 521 |
|
| 522 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:luaGroupD' })")); |
| 523 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 524 |
|
| 525 |
NLog::log("{}Testing Lua group merge with insertion index", Colors::YELLOW); |
| 526 |
OK(getFromSocket("/eval local a=hl.get_window('class:luaGroupA') local d=hl.get_window('class:luaGroupD') local e=hl.get_window('class:luaGroupE') assert(a and d and e and " |
| 527 |
"a.group and d.group) local g=a.group local source=d.group source:add(e) assert(source.size == 2) g:add(d, 1) assert(d.group == g) assert(e.group == g) " |
| 528 |
"assert(g.size == 3) assert(g.members[1] == d) assert(g.members[2] == e) assert(g.members[3] == a)")); |
| 529 |
|
| 530 |
Tests::killAllWindows(); |
| 531 |
ASSERT(Tests::windowCount(), 0); |
| 532 |
} |
| 533 |
|
| 534 |
TEST_CASE(groupsLuaApiInvalidOps) { |
| 535 |
NLog::log("{}Dispatching workspace `groups-lua-invalid`", Colors::YELLOW); |
| 536 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-invalid' })")); |
| 537 |
OK(getFromSocket("/eval hl.config({ group = { auto_group = false, insert_after_current = false, groupbar = { enabled = false } } })")); |
| 538 |
|
| 539 |
auto kittyA = Tests::spawnKitty("luaInvalidA"); |
| 540 |
auto kittyB = Tests::spawnKitty("luaInvalidB"); |
| 541 |
auto kittyC = Tests::spawnKitty("luaInvalidC"); |
| 542 |
|
| 543 |
if (!kittyA || !kittyB || !kittyC) |
| 544 |
FAIL_TEST("Could not spawn kitty"); |
| 545 |
|
| 546 |
ASSERT(Tests::windowCount(), 3); |
| 547 |
|
| 548 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:luaInvalidA' })")); |
| 549 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 550 |
|
| 551 |
OK(getFromSocket( |
| 552 |
"/eval local a=hl.get_window('class:luaInvalidA') local b=hl.get_window('class:luaInvalidB') local c=hl.get_window('class:luaInvalidC') local g=a.group g:add(b) " |
| 553 |
"assert(g.size == 2 and b.group == g and c.group == nil)")); |
| 554 |
|
| 555 |
NOK(getFromSocket("/eval local a=hl.get_window('class:luaInvalidA') local c=hl.get_window('class:luaInvalidC') a.group:add(c, 0)")); |
| 556 |
NOK(getFromSocket("/eval local a=hl.get_window('class:luaInvalidA') local c=hl.get_window('class:luaInvalidC') a.group:add(c, 4)")); |
| 557 |
NOK(getFromSocket("/eval local a=hl.get_window('class:luaInvalidA') a.group:remove(0)")); |
| 558 |
NOK(getFromSocket("/eval local a=hl.get_window('class:luaInvalidA') a.group:remove(3)")); |
| 559 |
NOK(getFromSocket("/eval local a=hl.get_window('class:luaInvalidA') local c=hl.get_window('class:luaInvalidC') a.group:remove(c)")); |
| 560 |
|
| 561 |
OK(getFromSocket("/eval local a=hl.get_window('class:luaInvalidA') local b=hl.get_window('class:luaInvalidB') local c=hl.get_window('class:luaInvalidC') local g=a.group " |
| 562 |
"assert(g.size == 2 and b.group == g and c.group == nil) local first, second = g.members[1], g.members[2] g:add(b, 1) " |
| 563 |
"assert(g.size == 2 and g.members[1] == first and g.members[2] == second)")); |
| 564 |
|
| 565 |
Tests::killAllWindows(); |
| 566 |
ASSERT(Tests::windowCount(), 0); |
| 567 |
} |
| 568 |
|
| 569 |
TEST_CASE(groupsLuaApiCrossWorkspaceMonitor) { |
| 570 |
NLog::log("{}Testing Lua group add across workspaces and monitors", Colors::YELLOW); |
| 571 |
OK(getFromSocket("/eval hl.config({ group = { auto_group = false, insert_after_current = false, groupbar = { enabled = false } } })")); |
| 572 |
|
| 573 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-ws-a' })")); |
| 574 |
auto kittyWorkspaceA = Tests::spawnKitty("luaWorkspaceA"); |
| 575 |
if (!kittyWorkspaceA) |
| 576 |
FAIL_TEST("Could not spawn kitty"); |
| 577 |
|
| 578 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 579 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-ws-b' })")); |
| 580 |
auto kittyWorkspaceB = Tests::spawnKitty("luaWorkspaceB"); |
| 581 |
if (!kittyWorkspaceB) |
| 582 |
FAIL_TEST("Could not spawn kitty"); |
| 583 |
|
| 584 |
OK(getFromSocket("/eval local a=hl.get_window('class:luaWorkspaceA') local b=hl.get_window('class:luaWorkspaceB') assert(a and b and a.group) local g=a.group g:add(b) " |
| 585 |
"assert(b.group == g) assert(b.workspace == a.workspace) assert(b.monitor == a.monitor) assert(g.size == 2)")); |
| 586 |
|
| 587 |
Tests::killAllWindows(); |
| 588 |
ASSERT(Tests::windowCount(), 0); |
| 589 |
|
| 590 |
static const std::string TEST_OUTPUT = "HEADLESS-LUA-GROUP"; |
| 591 |
getFromSocket(std::format("/output remove {}", TEST_OUTPUT)); |
| 592 |
OK(getFromSocket(std::format("/output create headless {}", TEST_OUTPUT))); |
| 593 |
|
| 594 |
CScopeGuard guard = {[&]() { OK(getFromSocket(std::format("/output remove {}", TEST_OUTPUT))); }}; |
| 595 |
|
| 596 |
OK(getFromSocket(std::format("/eval hl.monitor({{ output = '{}', disabled = false, mode = '1920x1080@60', position = '1920x0', scale = '1' }})", TEST_OUTPUT))); |
| 597 |
OK(getFromSocket("/dispatch hl.dsp.focus({ monitor = 'HEADLESS-2' })")); |
| 598 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-monitor-a' })")); |
| 599 |
|
| 600 |
auto kittyMonitorA = Tests::spawnKitty("luaMonitorA"); |
| 601 |
if (!kittyMonitorA) |
| 602 |
FAIL_TEST("Could not spawn kitty"); |
| 603 |
|
| 604 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 605 |
OK(getFromSocket(std::format("/dispatch hl.dsp.focus({{ monitor = '{}' }})", TEST_OUTPUT))); |
| 606 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-monitor-b' })")); |
| 607 |
|
| 608 |
auto kittyMonitorB = Tests::spawnKitty("luaMonitorB"); |
| 609 |
if (!kittyMonitorB) |
| 610 |
FAIL_TEST("Could not spawn kitty"); |
| 611 |
|
| 612 |
OK(getFromSocket("/eval local a=hl.get_window('class:luaMonitorA') local b=hl.get_window('class:luaMonitorB') assert(a and b and a.group) local g=a.group g:add(b) " |
| 613 |
"assert(b.group == g) assert(b.workspace == a.workspace) assert(b.monitor == a.monitor) assert(g.size == 2)")); |
| 614 |
|
| 615 |
Tests::killAllWindows(); |
| 616 |
ASSERT(Tests::windowCount(), 0); |
| 617 |
} |
| 618 |
|
| 619 |
TEST_CASE(groupsLuaApiFullscreen) { |
| 620 |
NLog::log("{}Dispatching workspace `groups-lua-fullscreen`", Colors::YELLOW); |
| 621 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-fullscreen' })")); |
| 622 |
OK(getFromSocket("/eval hl.config({ group = { auto_group = false, insert_after_current = false, groupbar = { enabled = false } } })")); |
| 623 |
|
| 624 |
auto kittyA = Tests::spawnKitty("luaFullscreenGroupA"); |
| 625 |
auto kittyB = Tests::spawnKitty("luaFullscreenSourceB"); |
| 626 |
if (!kittyA || !kittyB) |
| 627 |
FAIL_TEST("Could not spawn kitty"); |
| 628 |
|
| 629 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:luaFullscreenGroupA' })")); |
| 630 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 631 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:luaFullscreenSourceB' })")); |
| 632 |
OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })")); |
| 633 |
|
| 634 |
OK(getFromSocket( |
| 635 |
"/eval local a=hl.get_window('class:luaFullscreenGroupA') local b=hl.get_window('class:luaFullscreenSourceB') assert(a and b and a.group and b.fullscreen == 2) " |
| 636 |
"local g=a.group g:add(b) assert(b.group == g) assert(b.fullscreen == 0) assert(a.fullscreen == 0) assert(g.size == 2)")); |
| 637 |
|
| 638 |
Tests::killAllWindows(); |
| 639 |
ASSERT(Tests::windowCount(), 0); |
| 640 |
|
| 641 |
OK(getFromSocket("/dispatch hl.dsp.focus({ workspace = 'name:groups-lua-fullscreen-target' })")); |
| 642 |
auto kittyC = Tests::spawnKitty("luaFullscreenTargetC"); |
| 643 |
auto kittyD = Tests::spawnKitty("luaFullscreenUnderD"); |
| 644 |
if (!kittyC || !kittyD) |
| 645 |
FAIL_TEST("Could not spawn kitty"); |
| 646 |
|
| 647 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:luaFullscreenTargetC' })")); |
| 648 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 649 |
OK(getFromSocket("/dispatch hl.dsp.window.fullscreen({ mode = 'fullscreen', action = 'set' })")); |
| 650 |
|
| 651 |
OK(getFromSocket("/eval local c=hl.get_window('class:luaFullscreenTargetC') local d=hl.get_window('class:luaFullscreenUnderD') assert(c and d and c.group and c.fullscreen == " |
| 652 |
"2 and d.fullscreen == 0) " |
| 653 |
"local g=c.group g:add(d) assert(d.group == g) assert(d.fullscreen == 2) assert(c.fullscreen == 0) assert(g.size == 2)")); |
| 654 |
|
| 655 |
Tests::killAllWindows(); |
| 656 |
ASSERT(Tests::windowCount(), 0); |
| 657 |
} |
| 658 |
|
| 659 |
TEST_CASE(groups_disable_when_only) { |
| 660 |
ASSERT(Tests::windowCount(), 0); |
| 661 |
|
| 662 |
NLog::log("{}Testing disable_when_only ", Colors::YELLOW); |
| 663 |
auto kittyA = Tests::spawnKitty("kittyA"); |
| 664 |
if (!kittyA) { |
| 665 |
FAIL_TEST("Could not spawn kitty"); |
| 666 |
} |
| 667 |
ASSERT(Tests::windowCount(), 1); |
| 668 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kittyA' })")); |
| 669 |
|
| 670 |
// check kitty properties. One kitty should take the entire screen, minus the gaps. |
| 671 |
NLog::log("{}Check kittyA dimensions", Colors::YELLOW); |
| 672 |
{ |
| 673 |
auto str = getFromSocket("/activewindow"); |
| 674 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 675 |
EXPECT_COUNT_STRING(str, "size: 1876,1036", 1); |
| 676 |
} |
| 677 |
|
| 678 |
OK(getFromSocket("/dispatch hl.dsp.group.toggle()")); |
| 679 |
OK(getFromSocket("/eval hl.config({ group = { groupbar = { disable_when_only = true } } })")); |
| 680 |
|
| 681 |
// check kittyA properties. groupbar should be hidden due to disable_when_only |
| 682 |
NLog::log("{}Check kittyA dimensions", Colors::YELLOW); |
| 683 |
{ |
| 684 |
auto str = getFromSocket("/activewindow"); |
| 685 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 686 |
EXPECT_COUNT_STRING(str, "size: 1876,1036", 1); |
| 687 |
} |
| 688 |
|
| 689 |
auto kittyB = Tests::spawnKitty("kittyB"); |
| 690 |
if (!kittyB) { |
| 691 |
FAIL_TEST("Could not spawn kitty"); |
| 692 |
} |
| 693 |
ASSERT(Tests::windowCount(), 2); |
| 694 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kittyB' })")); |
| 695 |
|
| 696 |
// check kittyB properties. groupbar is visible |
| 697 |
NLog::log("{}Check kittyB dimensions", Colors::YELLOW); |
| 698 |
{ |
| 699 |
auto str = getFromSocket("/activewindow"); |
| 700 |
EXPECT_CONTAINS(str, "at: 22,43"); |
| 701 |
EXPECT_COUNT_STRING(str, "size: 1876,1015", 1); |
| 702 |
} |
| 703 |
|
| 704 |
OK(getFromSocket("/dispatch hl.dsp.window.kill()")); |
| 705 |
Tests::waitUntilWindowsN(1); |
| 706 |
ASSERT(Tests::windowCount(), 1); |
| 707 |
OK(getFromSocket("/dispatch hl.dsp.focus({ window = 'class:kittyA' })")); |
| 708 |
|
| 709 |
// check kittyA properties. groupbar should be hidden due to disable_when_only |
| 710 |
NLog::log("{}Check kittyA dimensions", Colors::YELLOW); |
| 711 |
{ |
| 712 |
auto str = getFromSocket("/activewindow"); |
| 713 |
EXPECT_COUNT_STRING(str, "at: 22,22", 1); |
| 714 |
EXPECT_COUNT_STRING(str, "size: 1876,1036", 1); |
| 715 |
} |
| 716 |
|
| 717 |
OK(getFromSocket("/eval hl.config({ group = { groupbar = { disable_when_only = false } } })")); |
| 718 |
|
| 719 |
// check kittyA properties. groupbar should be visible due to disable_when_only == false |
| 720 |
NLog::log("{}Check kittyA dimensions", Colors::YELLOW); |
| 721 |
{ |
| 722 |
auto str = getFromSocket("/activewindow"); |
| 723 |
EXPECT_COUNT_STRING(str, "at: 22,43", 1); |
| 724 |
EXPECT_COUNT_STRING(str, "size: 1876,1015", 1); |
| 725 |
} |
| 726 |
|
| 727 |
Tests::killAllWindows(); |
| 728 |
ASSERT(Tests::windowCount(), 0); |
| 729 |
} |