algo/dwindle: use focal point correctly for x-ws moves (#13514)
This commit is contained in:
parent
3b7401b065
commit
75a815fbf2
6 changed files with 40 additions and 28 deletions
|
|
@ -1,5 +1,10 @@
|
||||||
#include "ModeAlgorithm.hpp"
|
#include "ModeAlgorithm.hpp"
|
||||||
|
|
||||||
|
#include "../space/Space.hpp"
|
||||||
|
#include "Algorithm.hpp"
|
||||||
|
#include "../../helpers/Monitor.hpp"
|
||||||
|
#include "../../desktop/view/Window.hpp"
|
||||||
|
|
||||||
using namespace Layout;
|
using namespace Layout;
|
||||||
|
|
||||||
std::expected<void, std::string> IModeAlgorithm::layoutMsg(const std::string_view& sv) {
|
std::expected<void, std::string> IModeAlgorithm::layoutMsg(const std::string_view& sv) {
|
||||||
|
|
@ -9,3 +14,20 @@ std::expected<void, std::string> IModeAlgorithm::layoutMsg(const std::string_vie
|
||||||
std::optional<Vector2D> IModeAlgorithm::predictSizeForNewTarget() {
|
std::optional<Vector2D> IModeAlgorithm::predictSizeForNewTarget() {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::optional<Vector2D> IModeAlgorithm::focalPointForDir(SP<ITarget> t, Math::eDirection dir) {
|
||||||
|
Vector2D focalPoint;
|
||||||
|
|
||||||
|
const auto WINDOWIDEALBB =
|
||||||
|
t->fullscreenMode() != FSMODE_NONE ? m_parent->space()->workspace()->m_monitor->logicalBox() : t->window()->getWindowIdealBoundingBoxIgnoreReserved();
|
||||||
|
|
||||||
|
switch (dir) {
|
||||||
|
case Math::DIRECTION_UP: focalPoint = WINDOWIDEALBB.pos() + Vector2D{WINDOWIDEALBB.size().x / 2.0, -1.0}; break;
|
||||||
|
case Math::DIRECTION_DOWN: focalPoint = WINDOWIDEALBB.pos() + Vector2D{WINDOWIDEALBB.size().x / 2.0, WINDOWIDEALBB.size().y + 1.0}; break;
|
||||||
|
case Math::DIRECTION_LEFT: focalPoint = WINDOWIDEALBB.pos() + Vector2D{-1.0, WINDOWIDEALBB.size().y / 2.0}; break;
|
||||||
|
case Math::DIRECTION_RIGHT: focalPoint = WINDOWIDEALBB.pos() + Vector2D{WINDOWIDEALBB.size().x + 1.0, WINDOWIDEALBB.size().y / 2.0}; break;
|
||||||
|
default: return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
return focalPoint;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,9 @@ namespace Layout {
|
||||||
// optional: predict new window's size
|
// optional: predict new window's size
|
||||||
virtual std::optional<Vector2D> predictSizeForNewTarget();
|
virtual std::optional<Vector2D> predictSizeForNewTarget();
|
||||||
|
|
||||||
|
// Impl'd here: focal point for dir
|
||||||
|
virtual std::optional<Vector2D> focalPointForDir(SP<ITarget> t, Math::eDirection dir);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
IModeAlgorithm() = default;
|
IModeAlgorithm() = default;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -99,11 +99,13 @@ void CDwindleAlgorithm::addTarget(SP<ITarget> target, bool newTarget) {
|
||||||
if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, ACTIVE_MON))
|
if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, ACTIVE_MON))
|
||||||
OPENINGON = getClosestNode(MOUSECOORDS);
|
OPENINGON = getClosestNode(MOUSECOORDS);
|
||||||
|
|
||||||
} else if (*PUSEACTIVE) {
|
} else if (*PUSEACTIVE || m_overrideFocalPoint) {
|
||||||
const auto ACTIVE_WINDOW = Desktop::focusState()->window();
|
const auto ACTIVE_WINDOW = Desktop::focusState()->window();
|
||||||
|
|
||||||
if (!m_overrideFocalPoint && ACTIVE_WINDOW && !ACTIVE_WINDOW->m_isFloating && ACTIVE_WINDOW != target->window() && ACTIVE_WINDOW->m_workspace == PWORKSPACE &&
|
if (m_overrideFocalPoint)
|
||||||
ACTIVE_WINDOW->m_isMapped)
|
OPENINGON = getClosestNode(*m_overrideFocalPoint);
|
||||||
|
else if (!m_overrideFocalPoint && ACTIVE_WINDOW && !ACTIVE_WINDOW->m_isFloating && ACTIVE_WINDOW != target->window() && ACTIVE_WINDOW->m_workspace == PWORKSPACE &&
|
||||||
|
ACTIVE_WINDOW->m_isMapped)
|
||||||
OPENINGON = getNodeFromWindow(ACTIVE_WINDOW);
|
OPENINGON = getNodeFromWindow(ACTIVE_WINDOW);
|
||||||
|
|
||||||
if (!OPENINGON)
|
if (!OPENINGON)
|
||||||
|
|
@ -214,10 +216,7 @@ void CDwindleAlgorithm::addTarget(SP<ITarget> target, bool newTarget) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (*PFORCESPLIT == 0 || !newTarget) {
|
} else if (*PFORCESPLIT == 0 || !newTarget) {
|
||||||
if ((SIDEBYSIDE &&
|
if ((SIDEBYSIDE && MOUSECOORDS.x < NEWPARENT->box.x + (NEWPARENT->box.w / 2.F)) || (!SIDEBYSIDE && MOUSECOORDS.y < NEWPARENT->box.y + (NEWPARENT->box.h / 2.F))) {
|
||||||
VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y + NEWPARENT->box.h)) ||
|
|
||||||
(!SIDEBYSIDE &&
|
|
||||||
VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w, NEWPARENT->box.y + NEWPARENT->box.h / 2.f))) {
|
|
||||||
// we are hovering over the first node, make PNODE first.
|
// we are hovering over the first node, make PNODE first.
|
||||||
NEWPARENT->children[1] = OPENINGON;
|
NEWPARENT->children[1] = OPENINGON;
|
||||||
NEWPARENT->children[0] = PNODE;
|
NEWPARENT->children[0] = PNODE;
|
||||||
|
|
@ -242,11 +241,10 @@ void CDwindleAlgorithm::addTarget(SP<ITarget> target, bool newTarget) {
|
||||||
|
|
||||||
// and update the previous parent if it exists
|
// and update the previous parent if it exists
|
||||||
if (OPENINGON->pParent) {
|
if (OPENINGON->pParent) {
|
||||||
if (OPENINGON->pParent->children[0] == OPENINGON) {
|
if (OPENINGON->pParent->children[0] == OPENINGON)
|
||||||
OPENINGON->pParent->children[0] = NEWPARENT;
|
OPENINGON->pParent->children[0] = NEWPARENT;
|
||||||
} else {
|
else
|
||||||
OPENINGON->pParent->children[1] = NEWPARENT;
|
OPENINGON->pParent->children[1] = NEWPARENT;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the children
|
// Update the children
|
||||||
|
|
@ -557,35 +555,24 @@ void CDwindleAlgorithm::moveTargetInDirection(SP<ITarget> t, Math::eDirection di
|
||||||
if (!PNODE || !t->window())
|
if (!PNODE || !t->window())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Vector2D focalPoint;
|
const auto FOCAL_POINT = focalPointForDir(t, dir);
|
||||||
|
|
||||||
const auto WINDOWIDEALBB =
|
|
||||||
t->fullscreenMode() != FSMODE_NONE ? m_parent->space()->workspace()->m_monitor->logicalBox() : t->window()->getWindowIdealBoundingBoxIgnoreReserved();
|
|
||||||
|
|
||||||
switch (dir) {
|
|
||||||
case Math::DIRECTION_UP: focalPoint = WINDOWIDEALBB.pos() + Vector2D{WINDOWIDEALBB.size().x / 2.0, -1.0}; break;
|
|
||||||
case Math::DIRECTION_DOWN: focalPoint = WINDOWIDEALBB.pos() + Vector2D{WINDOWIDEALBB.size().x / 2.0, WINDOWIDEALBB.size().y + 1.0}; break;
|
|
||||||
case Math::DIRECTION_LEFT: focalPoint = WINDOWIDEALBB.pos() + Vector2D{-1.0, WINDOWIDEALBB.size().y / 2.0}; break;
|
|
||||||
case Math::DIRECTION_RIGHT: focalPoint = WINDOWIDEALBB.pos() + Vector2D{WINDOWIDEALBB.size().x + 1.0, WINDOWIDEALBB.size().y / 2.0}; break;
|
|
||||||
default: return;
|
|
||||||
}
|
|
||||||
|
|
||||||
t->window()->setAnimationsToMove();
|
t->window()->setAnimationsToMove();
|
||||||
|
|
||||||
removeTarget(t);
|
removeTarget(t);
|
||||||
|
|
||||||
const auto PMONITORFOCAL = g_pCompositor->getMonitorFromVector(focalPoint);
|
const auto PMONITORFOCAL = g_pCompositor->getMonitorFromVector(FOCAL_POINT.value_or(t->position().middle()));
|
||||||
|
|
||||||
if (PMONITORFOCAL != m_parent->space()->workspace()->m_monitor) {
|
if (PMONITORFOCAL != m_parent->space()->workspace()->m_monitor) {
|
||||||
// move with a focal point
|
// move with a focal point
|
||||||
|
|
||||||
if (PMONITORFOCAL->m_activeWorkspace)
|
if (PMONITORFOCAL->m_activeWorkspace)
|
||||||
t->assignToSpace(PMONITORFOCAL->m_activeWorkspace->m_space);
|
t->assignToSpace(PMONITORFOCAL->m_activeWorkspace->m_space, FOCAL_POINT);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
movedTarget(t, focalPoint);
|
movedTarget(t, FOCAL_POINT);
|
||||||
|
|
||||||
// restore focus to the previous position
|
// restore focus to the previous position
|
||||||
if (silent) {
|
if (silent) {
|
||||||
|
|
|
||||||
|
|
@ -424,7 +424,7 @@ void CMasterAlgorithm::moveTargetInDirection(SP<ITarget> t, Math::eDirection dir
|
||||||
t->window()->setAnimationsToMove();
|
t->window()->setAnimationsToMove();
|
||||||
|
|
||||||
if (t->window()->m_workspace != targetWs) {
|
if (t->window()->m_workspace != targetWs) {
|
||||||
t->assignToSpace(targetWs->m_space);
|
t->assignToSpace(targetWs->m_space, focalPointForDir(t, dir));
|
||||||
} else if (PWINDOW2) {
|
} else if (PWINDOW2) {
|
||||||
// if same monitor, switch windows
|
// if same monitor, switch windows
|
||||||
g_layoutManager->switchTargets(t, PWINDOW2->layoutTarget());
|
g_layoutManager->switchTargets(t, PWINDOW2->layoutTarget());
|
||||||
|
|
|
||||||
|
|
@ -215,7 +215,7 @@ void CMonocleAlgorithm::moveTargetInDirection(SP<ITarget> t, Math::eDirection di
|
||||||
if (t->window())
|
if (t->window())
|
||||||
t->window()->setAnimationsToMove();
|
t->window()->setAnimationsToMove();
|
||||||
|
|
||||||
t->assignToSpace(TARGETWS->m_space);
|
t->assignToSpace(TARGETWS->m_space, focalPointForDir(t, dir));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -951,7 +951,7 @@ void CScrollingAlgorithm::moveTargetTo(SP<ITarget> t, Math::eDirection dir, bool
|
||||||
// with the original dir
|
// with the original dir
|
||||||
const auto MONINDIR = g_pCompositor->getMonitorInDirection(m_parent->space()->workspace()->m_monitor.lock(), dir);
|
const auto MONINDIR = g_pCompositor->getMonitorInDirection(m_parent->space()->workspace()->m_monitor.lock(), dir);
|
||||||
if (MONINDIR && MONINDIR != m_parent->space()->workspace()->m_monitor && MONINDIR->m_activeWorkspace) {
|
if (MONINDIR && MONINDIR != m_parent->space()->workspace()->m_monitor && MONINDIR->m_activeWorkspace) {
|
||||||
t->assignToSpace(MONINDIR->m_activeWorkspace->m_space);
|
t->assignToSpace(MONINDIR->m_activeWorkspace->m_space, focalPointForDir(t, dir));
|
||||||
|
|
||||||
m_scrollingData->recalculate();
|
m_scrollingData->recalculate();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue