diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2026-03-28 23:31:04 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-03-28 15:31:04 +0000 |
| commit | 1c25bcc811664a0dc206f3e4e616b88f5581e83d (patch) | |
| tree | 19c11e42ba7b3170d5d7c1789e412677c5c587f7 | |
| parent | 3103119b7cdda67e1d43588ad07a80465626b3c2 (diff) | |
dispatchers: add moveintoorcreategroup (#13325)
| -rw-r--r-- | hyprtester/src/tests/main/moveintoorcreategroup.cpp | 111 | ||||
| -rw-r--r-- | src/managers/KeybindManager.cpp | 40 | ||||
| -rw-r--r-- | src/managers/KeybindManager.hpp | 1 |
3 files changed, 152 insertions, 0 deletions
diff --git a/hyprtester/src/tests/main/moveintoorcreategroup.cpp b/hyprtester/src/tests/main/moveintoorcreategroup.cpp new file mode 100644 index 00000000..ecb491bc --- /dev/null +++ b/hyprtester/src/tests/main/moveintoorcreategroup.cpp @@ -0,0 +1,111 @@ +#include "tests.hpp" +#include "../../shared.hpp" +#include "../../hyprctlCompat.hpp" +#include <print> +#include <thread> +#include <chrono> +#include <hyprutils/os/Process.hpp> +#include <hyprutils/memory/WeakPtr.hpp> +#include <csignal> +#include <cerrno> +#include "../shared.hpp" + +static int ret = 0; + +using namespace Hyprutils::OS; +using namespace Hyprutils::Memory; + +#define UP CUniquePointer +#define SP CSharedPointer + +static bool test() { + NLog::log("{}Testing moveintoorcreategroup", Colors::GREEN); + + NLog::log("{}Dispatching workspace `moveintoorcreategroup`", Colors::YELLOW); + getFromSocket("/dispatch workspace name:moveintoorcreategroup"); + + OK(getFromSocket("/keyword group:auto_group false")); + + NLog::log("{}Spawning kittyA", Colors::YELLOW); + auto kittyA = Tests::spawnKitty("kitty_A"); + if (!kittyA) { + NLog::log("{}Error: kittyA did not spawn", Colors::RED); + return false; + } + + NLog::log("{}Spawning kittyB", Colors::YELLOW); + auto kittyB = Tests::spawnKitty("kitty_B"); + if (!kittyB) { + NLog::log("{}Error: kittyB did not spawn", Colors::RED); + return false; + } + + NLog::log("{}Expecting 2 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 2); + + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "grouped: 0"); + } + + OK(getFromSocket("/dispatch focuswindow class:kitty_A")); + + NLog::log("{}Move kittyA into group with kittyB (creates group)", Colors::YELLOW); + OK(getFromSocket("/dispatch moveintoorcreategroup r")); + + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "grouped:"); + } + + NLog::log("{}Verify active window is kitty_A (the moved window)", Colors::YELLOW); + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "kitty_A"); + } + + NLog::log("{}Kill windows", Colors::YELLOW); + Tests::killAllWindows(); + + NLog::log("{}Expecting 0 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 0); + + NLog::log("{}Testing moveintoorcreategroup into existing group", Colors::YELLOW); + + NLog::log("{}Spawning kittyC", Colors::YELLOW); + auto kittyC = Tests::spawnKitty("kitty_C"); + NLog::log("{}Spawning kittyD", Colors::YELLOW); + auto kittyD = Tests::spawnKitty("kitty_D"); + NLog::log("{}Spawning kittyE", Colors::YELLOW); + auto kittyE = Tests::spawnKitty("kitty_E"); + + NLog::log("{}Expecting 3 windows", Colors::YELLOW); + EXPECT(Tests::windowCount(), 3); + + OK(getFromSocket("/dispatch focuswindow class:kitty_D")); + OK(getFromSocket("/dispatch togglegroup")); + + OK(getFromSocket("/dispatch focuswindow class:kitty_E")); + + NLog::log("{}Move kittyE into existing group with kittyD", Colors::YELLOW); + OK(getFromSocket("/dispatch moveintoorcreategroup l")); + + { + auto str = getFromSocket("/clients"); + EXPECT_CONTAINS(str, "grouped:"); + } + + NLog::log("{}Verify active window is kitty_E (the moved window)", Colors::YELLOW); + { + auto str = getFromSocket("/activewindow"); + EXPECT_CONTAINS(str, "kitty_E"); + } + + NLog::log("{}Kill windows", Colors::YELLOW); + Tests::killAllWindows(); + OK(getFromSocket("/keyword group:auto_group true")); + + return !ret; +} + +REGISTER_TEST_FN(test) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 4a698c16..10f760a0 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -125,6 +125,7 @@ CKeybindManager::CKeybindManager() { m_dispatchers["lockgroups"] = lockGroups; m_dispatchers["lockactivegroup"] = lockActiveGroup; m_dispatchers["moveintogroup"] = moveIntoGroup; + m_dispatchers["moveintoorcreategroup"] = moveIntoOrCreateGroup; m_dispatchers["moveoutofgroup"] = moveOutOfGroup; m_dispatchers["movewindoworgroup"] = moveWindowOrGroup; m_dispatchers["setignoregrouplock"] = setIgnoreGroupLock; @@ -2690,6 +2691,45 @@ SDispatchResult CKeybindManager::moveIntoGroup(std::string args) { return {}; } +SDispatchResult CKeybindManager::moveIntoOrCreateGroup(std::string args) { + static auto PIGNOREGROUPLOCK = CConfigValue<Hyprlang::INT>("binds:ignore_group_lock"); + + if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_groupsLocked) + return {}; + + Math::eDirection dir = Math::fromChar(args[0]); + if (dir == Math::DIRECTION_DEFAULT) { + Log::logger->log(Log::ERR, "Cannot move into or create group in direction {}, unsupported direction. Supported: l,r,u/t,d/b", args[0]); + return {.success = false, .error = std::format("Cannot move into or create group in direction {}, unsupported direction. Supported: l,r,u/t,d/b", args[0])}; + } + + const auto PWINDOW = Desktop::focusState()->window(); + + if (!PWINDOW) + return {}; + + auto PWINDOWINDIR = g_pCompositor->getWindowInDirection(PWINDOW, dir); + + if (!PWINDOWINDIR) + return {}; + + if (!PWINDOWINDIR->m_group) { + if (PWINDOWINDIR->isFullscreen()) + return {}; + + PWINDOWINDIR->m_group = Desktop::View::CGroup::create({PWINDOWINDIR}); + } + + const auto GROUP = PWINDOWINDIR->m_group; + + if (!*PIGNOREGROUPLOCK && (GROUP->locked() || (PWINDOW->m_group && PWINDOW->m_group->locked()))) + return {}; + + moveWindowIntoGroup(PWINDOW, PWINDOWINDIR); + + return {}; +} + SDispatchResult CKeybindManager::moveOutOfGroup(std::string args) { static auto PIGNOREGROUPLOCK = CConfigValue<Hyprlang::INT>("binds:ignore_group_lock"); diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index eda88a5c..a51f9add 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -232,6 +232,7 @@ class CKeybindManager { static SDispatchResult lockGroups(std::string); static SDispatchResult lockActiveGroup(std::string); static SDispatchResult moveIntoGroup(std::string); + static SDispatchResult moveIntoOrCreateGroup(std::string); static SDispatchResult moveOutOfGroup(std::string); static SDispatchResult moveGroupWindow(std::string); static SDispatchResult moveWindowOrGroup(std::string); |
