diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2025-05-27 01:15:11 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-26 19:15:11 +0200 |
| commit | 4c4c9bb324b9e17bddb72c4614b451775521ee24 (patch) | |
| tree | c8d178c85a65025647babf63cb0166c091932350 /src | |
| parent | 292a7456af9465a57a7fe3ee36d113ae661a9ff3 (diff) | |
dwindle: add better automatic window drag and drop direction detection (#9704)
Diffstat (limited to 'src')
| -rw-r--r-- | src/config/ConfigDescriptions.hpp | 6 | ||||
| -rw-r--r-- | src/config/ConfigManager.cpp | 1 | ||||
| -rw-r--r-- | src/layout/IHyprLayout.cpp | 26 |
3 files changed, 32 insertions, 1 deletions
diff --git a/src/config/ConfigDescriptions.hpp b/src/config/ConfigDescriptions.hpp index 8fc6b04b..19c1f74c 100644 --- a/src/config/ConfigDescriptions.hpp +++ b/src/config/ConfigDescriptions.hpp @@ -1757,6 +1757,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = { .type = CONFIG_OPTION_CHOICE, .data = SConfigOptionDescription::SChoiceData{0, "positional,current,opening"}, }, + SConfigOptionDescription{ + .value = "dwindle:precise_move", + .description = "if enabled, bindm movewindow will drop the window more precisely depending on where your mouse is.", + .type = CONFIG_OPTION_BOOL, + .data = SConfigOptionDescription::SBoolData{true}, + }, /* * master: diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f5f0bed3..99b4cf85 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -592,6 +592,7 @@ CConfigManager::CConfigManager() { registerConfigVar("dwindle:split_bias", Hyprlang::INT{0}); registerConfigVar("dwindle:smart_split", Hyprlang::INT{0}); registerConfigVar("dwindle:smart_resizing", Hyprlang::INT{1}); + registerConfigVar("dwindle:precise_move", Hyprlang::INT{0}); registerConfigVar("master:special_scale_factor", {1.f}); registerConfigVar("master:mfact", {0.55f}); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 8d32e44e..93b09c87 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -362,9 +362,33 @@ void IHyprLayout::onEndDragWindow() { } if (DRAGGINGWINDOW->m_draggingTiled) { + static auto PPRECISEMOUSE = CConfigValue<Hyprlang::INT>("dwindle:precise_mouse_move"); DRAGGINGWINDOW->m_isFloating = false; g_pInputManager->refocus(); - changeWindowFloatingMode(DRAGGINGWINDOW); + + if (*PPRECISEMOUSE) { + eDirection direction = DIRECTION_DEFAULT; + + const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); + const PHLWINDOW pReferenceWindow = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING, DRAGGINGWINDOW); + + if (pReferenceWindow && pReferenceWindow != DRAGGINGWINDOW) { + const Vector2D draggedCenter = DRAGGINGWINDOW->m_realPosition->goal() + DRAGGINGWINDOW->m_realSize->goal() / 2.f; + const Vector2D referenceCenter = pReferenceWindow->m_realPosition->goal() + pReferenceWindow->m_realSize->goal() / 2.f; + const float xDiff = draggedCenter.x - referenceCenter.x; + const float yDiff = draggedCenter.y - referenceCenter.y; + + if (fabs(xDiff) > fabs(yDiff)) + direction = xDiff < 0 ? DIRECTION_LEFT : DIRECTION_RIGHT; + else + direction = yDiff < 0 ? DIRECTION_UP : DIRECTION_DOWN; + } + + onWindowRemovedTiling(DRAGGINGWINDOW); + onWindowCreatedTiling(DRAGGINGWINDOW, direction); + } else + changeWindowFloatingMode(DRAGGINGWINDOW); + DRAGGINGWINDOW->m_lastFloatingSize = m_draggingWindowOriginalFloatSize; } |
