summaryrefslogtreecommitdiff
path: root/src/layout/MasterLayout.cpp
diff options
context:
space:
mode:
authorthejch <66577496+thejch@users.noreply.github.com>2023-11-03 10:02:59 -0700
committerGitHub <noreply@github.com>2023-11-03 17:02:59 +0000
commited3d5053b23d2b725cda507cb5fcc9e9a2f35ba9 (patch)
treea9f7b0a18ee494c4c0dc6428fb4be64ce17a4ce2 /src/layout/MasterLayout.cpp
parent93a2ac9de402830d301bdecdbf7aca52f88bd801 (diff)
Master: fix drop_at_cursor when there are only two windows (#3734)
* make drop_at_cursor work when dragging into a one-window workspace * fix drop_at_cursor when new_is_master is enabled
Diffstat (limited to 'src/layout/MasterLayout.cpp')
-rw-r--r--src/layout/MasterLayout.cpp77
1 files changed, 55 insertions, 22 deletions
diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp
index be8da75e..8cc35ee6 100644
--- a/src/layout/MasterLayout.cpp
+++ b/src/layout/MasterLayout.cpp
@@ -133,34 +133,67 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc
const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->m_iWorkspaceID);
eOrientation orientation = PWORKSPACEDATA->orientation;
const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE);
+
+ bool forceDropAsMaster = false;
+ // if dragging window to move, drop it at the cursor position instead of bottom/top of stack
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) {
- if (it->workspaceID != pWindow->m_iWorkspaceID)
- continue;
- 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();
+ if (WINDOWSONWORKSPACE > 2) {
+ for (auto it = m_lMasterNodesData.begin(); it != m_lMasterNodesData.end(); ++it) {
+ if (it->workspaceID != pWindow->m_iWorkspaceID)
+ continue;
+ const wlr_box box = it->pWindow->getWindowIdealBoundingBoxIgnoreReserved();
+ if (wlr_box_contains_point(&box, MOUSECOORDS.x, MOUSECOORDS.y)) {
+ 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;
+ }
+ }
+ } else if (WINDOWSONWORKSPACE == 2) {
+ // when dropping as the second tiled window in the workspace,
+ // make it the master only if the cursor is on the master side of the screen
+ for (auto& nd : m_lMasterNodesData) {
+ if (nd.isMaster && nd.workspaceID == PNODE->workspaceID) {
+ switch (orientation) {
+ case ORIENTATION_LEFT:
+ case ORIENTATION_CENTER:
+ if (MOUSECOORDS.x < nd.pWindow->middle().x)
+ forceDropAsMaster = true;
+ break;
+ case ORIENTATION_RIGHT:
+ if (MOUSECOORDS.x > nd.pWindow->middle().x)
+ forceDropAsMaster = true;
+ break;
+ case ORIENTATION_TOP:
+ if (MOUSECOORDS.y < nd.pWindow->middle().y)
+ forceDropAsMaster = true;
+ break;
+ case ORIENTATION_BOTTOM:
+ if (MOUSECOORDS.y > nd.pWindow->middle().y)
+ forceDropAsMaster = true;
+ break;
+ default: UNREACHABLE();
+ }
+ break;
}
- m_lMasterNodesData.splice(it, m_lMasterNodesData, NODEIT);
- break;
}
}
}
- if (*PNEWISMASTER || WINDOWSONWORKSPACE == 1 || (!pWindow->m_bFirstMap && OPENINGON->isMaster)) {
+ if ((*PNEWISMASTER && g_pInputManager->dragMode != MBIND_MOVE) || WINDOWSONWORKSPACE == 1 || (WINDOWSONWORKSPACE > 2 && !pWindow->m_bFirstMap && OPENINGON->isMaster) ||
+ forceDropAsMaster) {
for (auto& nd : m_lMasterNodesData) {
if (nd.isMaster && nd.workspaceID == PNODE->workspaceID) {
nd.isMaster = false;