From e0c571005912c342d8d812b368bc490cb6f28796 Mon Sep 17 00:00:00 2001 From: Virt <41426325+VirtCode@users.noreply.github.com> Date: Fri, 6 Mar 2026 21:11:42 +0100 Subject: layerrules: add dynamically registered rules for plugins (#13331) * layerrules: add dynamically registered rules for plugins * be gone * layerrules: add layer tests with waybar * fix: use kitty layers instead of waybar --- hyprtester/src/tests/shared.cpp | 76 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'hyprtester/src/tests/shared.cpp') diff --git a/hyprtester/src/tests/shared.cpp b/hyprtester/src/tests/shared.cpp index 8cdd648e..f6e2fce9 100644 --- a/hyprtester/src/tests/shared.cpp +++ b/hyprtester/src/tests/shared.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "../shared.hpp" #include "../hyprctlCompat.hpp" @@ -39,6 +40,38 @@ CUniquePointer Tests::spawnKitty(const std::string& class_, const std: return kitty; } +CUniquePointer Tests::spawnLayerKitty(const std::string& namespace_, const std::vector args) { + std::vector programArgs = args; + if (!namespace_.empty()) { + programArgs.insert(programArgs.begin(), "--class"); + programArgs.insert(programArgs.begin() + 1, namespace_); + } + + programArgs.insert(programArgs.begin(), "+kitten"); + programArgs.insert(programArgs.begin() + 1, "panel"); + + CUniquePointer kitty = makeUnique("kitty", programArgs); + kitty->addEnv("WAYLAND_DISPLAY", WLDISPLAY); + kitty->runAsync(); + + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + + // wait while the layer spawns + int counter = 0; + while (processAlive(kitty->pid()) && countOccurrences(getFromSocket("/layers"), std::format("pid: {}", kitty->pid())) == 0) { + counter++; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + if (counter > 50) + return nullptr; + } + + if (!processAlive(kitty->pid())) + return nullptr; + + return kitty; +} + bool Tests::processAlive(pid_t pid) { errno = 0; int ret = kill(pid, 0); @@ -96,6 +129,38 @@ void Tests::waitUntilWindowsN(int n) { } } +int Tests::layerCount() { + return countOccurrences(getFromSocket("/layers"), "namespace: "); +} + +bool Tests::killAllLayers() { + auto str = getFromSocket("/layers"); + auto pos = str.find("pid: "); + while (pos != std::string::npos) { + auto pid = stoi(str.substr(pos + 5, str.find('\n', pos))); + kill(pid, 15); + + // we need to wait for a bit because for some reason otherwise we'll end up + // with layers with pid -1 if they are all removed at the same time + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + pos = str.find("pid: ", pos + 5); + } + + int counter = 0; + while (Tests::layerCount() != 0) { + counter++; + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + + if (counter > 50) { + std::println("{}Timed out waiting for layers to close", Colors::RED); + return false; + } + } + + return true; +} + std::string Tests::execAndGet(const std::string& cmd) { CProcess proc("/bin/sh", {"-c", cmd}); @@ -105,3 +170,14 @@ std::string Tests::execAndGet(const std::string& cmd) { return proc.stdOut(); } + +bool Tests::writeFile(const std::string& name, const std::string& contents) { + std::ofstream of(name, std::ios::trunc); + if (!of.good()) + return false; + + of << contents; + of.close(); + + return true; +} -- cgit v1.2.3