mirror of
https://github.com/hyprwm/Hypr.git
synced 2024-11-22 13:35:57 +01:00
multiple manual navigation fixes
I made this while wearing a suit, elegant code????
This commit is contained in:
parent
0ee0f3ff78
commit
b6fc46714f
2 changed files with 125 additions and 25 deletions
|
@ -1267,8 +1267,11 @@ CWindow* CWindowManager::getNeighborInDir(char dir) {
|
||||||
const auto POSA = CURRENTWINDOW->getPosition();
|
const auto POSA = CURRENTWINDOW->getPosition();
|
||||||
const auto SIZEA = CURRENTWINDOW->getSize();
|
const auto SIZEA = CURRENTWINDOW->getSize();
|
||||||
|
|
||||||
|
auto longestIntersect = -1;
|
||||||
|
CWindow* longestIntersectWindow = nullptr;
|
||||||
|
|
||||||
for (auto& w : windows) {
|
for (auto& w : windows) {
|
||||||
if (w.getDrawable() == CURRENTWINDOW->getDrawable() || w.getWorkspaceID() != CURRENTWINDOW->getWorkspaceID())
|
if (w.getDrawable() == CURRENTWINDOW->getDrawable() || w.getDrawable() < 1 || w.getIsFloating() || !isWorkspaceVisible(w.getWorkspaceID()))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
const auto POSB = w.getPosition();
|
const auto POSB = w.getPosition();
|
||||||
|
@ -1276,26 +1279,49 @@ CWindow* CWindowManager::getNeighborInDir(char dir) {
|
||||||
|
|
||||||
switch (dir) {
|
switch (dir) {
|
||||||
case 'l':
|
case 'l':
|
||||||
if (STICKS(POSA.x, POSB.x + SIZEB.x))
|
if (STICKS(POSA.x, POSB.x + SIZEB.x)) {
|
||||||
return &w;
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
|
||||||
|
if (INTERSECTLEN > longestIntersect) {
|
||||||
|
longestIntersect = INTERSECTLEN;
|
||||||
|
longestIntersectWindow = &w;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
if (STICKS(POSA.x + SIZEA.x, POSB.x))
|
if (STICKS(POSA.x + SIZEA.x, POSB.x)) {
|
||||||
return &w;
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.y + SIZEA.y, POSB.y + SIZEB.y) - std::max(POSA.y, POSB.y));
|
||||||
|
if (INTERSECTLEN > longestIntersect) {
|
||||||
|
longestIntersect = INTERSECTLEN;
|
||||||
|
longestIntersectWindow = &w;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
case 'u':
|
case 'u':
|
||||||
if (STICKS(POSA.y, POSB.y + SIZEB.y))
|
if (STICKS(POSA.y, POSB.y + SIZEB.y)) {
|
||||||
return &w;
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
|
||||||
|
if (INTERSECTLEN > longestIntersect) {
|
||||||
|
longestIntersect = INTERSECTLEN;
|
||||||
|
longestIntersectWindow = &w;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
case 'd':
|
case 'd':
|
||||||
if (STICKS(POSA.y + SIZEA.y, POSB.y))
|
if (STICKS(POSA.y + SIZEA.y, POSB.y)) {
|
||||||
return &w;
|
const auto INTERSECTLEN = std::max((double)0, std::min(POSA.x + SIZEA.x, POSB.x + SIZEB.x) - std::max(POSA.x, POSB.x));
|
||||||
|
if (INTERSECTLEN > longestIntersect) {
|
||||||
|
longestIntersect = INTERSECTLEN;
|
||||||
|
longestIntersectWindow = &w;
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (longestIntersect != -1)
|
||||||
|
return longestIntersectWindow;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1390,6 +1416,49 @@ void CWindowManager::moveActiveWindowTo(char dir) {
|
||||||
CURRENTWINDOW->setDirty(true);
|
CURRENTWINDOW->setDirty(true);
|
||||||
neighbor->setDirty(true);
|
neighbor->setDirty(true);
|
||||||
|
|
||||||
|
// Fix the tree
|
||||||
|
if (CURRENTWINDOW->getParentNodeID() != 0) {
|
||||||
|
const auto PPARENT = getWindowFromDrawable(CURRENTWINDOW->getParentNodeID());
|
||||||
|
if (!PPARENT) {
|
||||||
|
Debug::log(ERR, "No parent node ID despite non-null???");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PPARENT->getChildNodeAID() == CURRENTWINDOW->getDrawable())
|
||||||
|
PPARENT->setChildNodeAID(neighbor->getDrawable());
|
||||||
|
else
|
||||||
|
PPARENT->setChildNodeBID(neighbor->getDrawable());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (neighbor->getParentNodeID() != 0) {
|
||||||
|
const auto PPARENT = getWindowFromDrawable(neighbor->getParentNodeID());
|
||||||
|
if (!PPARENT) {
|
||||||
|
Debug::log(ERR, "No parent node ID despite non-null???");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PPARENT->getChildNodeAID() == neighbor->getDrawable())
|
||||||
|
PPARENT->setChildNodeAID(CURRENTWINDOW->getDrawable());
|
||||||
|
else
|
||||||
|
PPARENT->setChildNodeBID(CURRENTWINDOW->getDrawable());
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto PARENTC = CURRENTWINDOW->getParentNodeID();
|
||||||
|
|
||||||
|
CURRENTWINDOW->setParentNodeID(neighbor->getParentNodeID());
|
||||||
|
neighbor->setParentNodeID(PARENTC);
|
||||||
|
|
||||||
|
// Fix the master layout
|
||||||
|
const auto SMASTER = CURRENTWINDOW->getMaster();
|
||||||
|
const auto SINDEX = CURRENTWINDOW->getMasterChildIndex();
|
||||||
|
|
||||||
|
CURRENTWINDOW->setMasterChildIndex(neighbor->getMasterChildIndex());
|
||||||
|
CURRENTWINDOW->setMaster(neighbor->getMaster());
|
||||||
|
|
||||||
|
neighbor->setMaster(SMASTER);
|
||||||
|
neighbor->setMasterChildIndex(SINDEX);
|
||||||
|
|
||||||
|
|
||||||
// finish by moving the cursor to the new current window
|
// finish by moving the cursor to the new current window
|
||||||
warpCursorTo(CURRENTWINDOW->getPosition() + CURRENTWINDOW->getSize() / 2.f);
|
warpCursorTo(CURRENTWINDOW->getPosition() + CURRENTWINDOW->getSize() / 2.f);
|
||||||
}
|
}
|
||||||
|
@ -1436,8 +1505,11 @@ void CWindowManager::changeWorkspaceByID(int ID) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't change if already opened
|
// Don't change if already opened
|
||||||
if (isWorkspaceVisible(ID))
|
if (isWorkspaceVisible(ID)) {
|
||||||
|
focusOnWorkspace(ID);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// mark old workspace dirty
|
// mark old workspace dirty
|
||||||
setAllWorkspaceWindowsDirtyByID(activeWorkspaces[MONITOR->ID]);
|
setAllWorkspaceWindowsDirtyByID(activeWorkspaces[MONITOR->ID]);
|
||||||
|
@ -1456,21 +1528,7 @@ void CWindowManager::changeWorkspaceByID(int ID) {
|
||||||
|
|
||||||
// if not fullscreen set the focus to any window on that workspace
|
// if not fullscreen set the focus to any window on that workspace
|
||||||
// if fullscreen, set to the fullscreen window
|
// if fullscreen, set to the fullscreen window
|
||||||
const auto PWORKSPACE = getWorkspaceByID(ID);
|
focusOnWorkspace(ID);
|
||||||
if (PWORKSPACE) {
|
|
||||||
if (!PWORKSPACE->getHasFullscreenWindow()) {
|
|
||||||
for (auto& window : windows) {
|
|
||||||
if (window.getWorkspaceID() == ID && window.getDrawable() > 0) {
|
|
||||||
setFocusedWindow(window.getDrawable());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const auto PFULLWINDOW = getFullscreenWindowByWorkspace(ID);
|
|
||||||
if (PFULLWINDOW)
|
|
||||||
setFocusedWindow(PFULLWINDOW->getDrawable());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update bar info
|
// Update bar info
|
||||||
updateBarInfo();
|
updateBarInfo();
|
||||||
|
@ -1496,9 +1554,50 @@ void CWindowManager::changeWorkspaceByID(int ID) {
|
||||||
// Wipe animation
|
// Wipe animation
|
||||||
startWipeAnimOnWorkspace(OLDWORKSPACE, ID);
|
startWipeAnimOnWorkspace(OLDWORKSPACE, ID);
|
||||||
|
|
||||||
|
if (getMonitorFromCursor() && MONITOR->ID != getMonitorFromCursor()->ID)
|
||||||
|
warpCursorTo(MONITOR->vecPosition + MONITOR->vecSize / 2.f);
|
||||||
|
|
||||||
// no need for the new dirty, it's empty
|
// no need for the new dirty, it's empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CWindowManager::focusOnWorkspace(const int& work) {
|
||||||
|
const auto PWORKSPACE = getWorkspaceByID(work);
|
||||||
|
const auto PMONITOR = getMonitorFromWorkspace(work);
|
||||||
|
|
||||||
|
if (!PMONITOR) {
|
||||||
|
Debug::log(ERR, "Orphaned workspace at focusOnWorkspace ???");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PWORKSPACE) {
|
||||||
|
if (!PWORKSPACE->getHasFullscreenWindow()) {
|
||||||
|
bool shouldHopToScreen = true;
|
||||||
|
for (auto& window : windows) {
|
||||||
|
if (window.getWorkspaceID() == work && window.getDrawable() > 0) {
|
||||||
|
setFocusedWindow(window.getDrawable());
|
||||||
|
|
||||||
|
if (getMonitorFromCursor() && getMonitorFromCursor()->ID != PMONITOR->ID)
|
||||||
|
warpCursorTo(window.getPosition() + window.getSize() / 2.f);
|
||||||
|
|
||||||
|
shouldHopToScreen = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldHopToScreen)
|
||||||
|
warpCursorTo(PMONITOR->vecPosition + PMONITOR->vecSize / 2.f);
|
||||||
|
} else {
|
||||||
|
const auto PFULLWINDOW = getFullscreenWindowByWorkspace(work);
|
||||||
|
if (PFULLWINDOW) {
|
||||||
|
setFocusedWindow(PFULLWINDOW->getDrawable());
|
||||||
|
|
||||||
|
if (getMonitorFromCursor() && getMonitorFromCursor()->ID != PMONITOR->ID)
|
||||||
|
warpCursorTo(PFULLWINDOW->getPosition() + PFULLWINDOW->getSize() / 2.f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void CWindowManager::setAllWindowsDirty() {
|
void CWindowManager::setAllWindowsDirty() {
|
||||||
for (auto& window : windows) {
|
for (auto& window : windows) {
|
||||||
window.setDirty(true);
|
window.setDirty(true);
|
||||||
|
|
|
@ -153,6 +153,7 @@ private:
|
||||||
void recalcEntireWorkspace(const int&);
|
void recalcEntireWorkspace(const int&);
|
||||||
void fixMasterWorkspaceOnClosed(CWindow* pWindow);
|
void fixMasterWorkspaceOnClosed(CWindow* pWindow);
|
||||||
void startWipeAnimOnWorkspace(const int&, const int&);
|
void startWipeAnimOnWorkspace(const int&, const int&);
|
||||||
|
void focusOnWorkspace(const int&);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CWindowManager> g_pWindowManager = std::make_unique<CWindowManager>();
|
inline std::unique_ptr<CWindowManager> g_pWindowManager = std::make_unique<CWindowManager>();
|
||||||
|
|
Loading…
Reference in a new issue