From d61e4f9ad75d51f15eac6bced13439899d66a950 Mon Sep 17 00:00:00 2001 From: Jeremy Huang <66577496+thejch@users.noreply.github.com> Date: Tue, 3 Oct 2023 14:16:57 -0700 Subject: master: add option to drag and drop windows at cursor position (#3465) * add option to drag and drop a window at cursor position * use getWindowIdealBoundingBoxIgnoreReserved --- src/config/ConfigManager.cpp | 1 + src/layout/MasterLayout.cpp | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index d639df0c..42611be3 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -188,6 +188,7 @@ void CConfigManager::setDefaultVars() { configValues["master:inherit_fullscreen"].intValue = 1; configValues["master:allow_small_split"].intValue = 0; configValues["master:smart_resizing"].intValue = 1; + configValues["master:drop_at_cursor"].intValue = 1; configValues["animations:enabled"].intValue = 1; diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 624ded2a..6fa168c4 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -132,6 +132,35 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc pWindow->applyGroupRules(); + static auto* const PDROPATCURSOR = &g_pConfigManager->getConfigValuePtr("master:drop_at_cursor")->intValue; + const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->m_iWorkspaceID); + eOrientation orientation = PWORKSPACEDATA->orientation; + const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); + if (*PDROPATCURSOR && g_pInputManager->dragMode == MBIND_MOVE) { + // if dragging window to move, drop it at the cursor position instead of bottom/top of stack + for (auto it = m_lMasterNodesData.begin(); it != m_lMasterNodesData.end(); ++it) { + const wlr_box box = it->pWindow->getWindowIdealBoundingBoxIgnoreReserved(); + if (wlr_box_contains_point(&box, MOUSECOORDS.x, MOUSECOORDS.y)) { // TODO: Deny when not using mouse + switch (orientation) { + case ORIENTATION_LEFT: + case ORIENTATION_RIGHT: + if (MOUSECOORDS.y > it->pWindow->middle().y) + ++it; + break; + case ORIENTATION_TOP: + case ORIENTATION_BOTTOM: + if (MOUSECOORDS.x > it->pWindow->middle().x) + ++it; + break; + case ORIENTATION_CENTER: break; + default: UNREACHABLE(); + } + m_lMasterNodesData.splice(it, m_lMasterNodesData, NODEIT); + break; + } + } + } + if (*PNEWISMASTER || WINDOWSONWORKSPACE == 1 || (!pWindow->m_bFirstMap && OPENINGON->isMaster)) { for (auto& nd : m_lMasterNodesData) { if (nd.isMaster && nd.workspaceID == PNODE->workspaceID) { -- cgit v1.2.3