Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layout: add direction parameter to onWindowCreated and friends #3269

Merged
merged 5 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions src/layout/DwindleLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for
PWINDOW->updateWindowDecos();
}

void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow) {
void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direction) {
if (pWindow->m_bIsFloating)
return;

Expand All @@ -238,6 +238,9 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow) {
static auto* const PUSEACTIVE = &g_pConfigManager->getConfigValuePtr("dwindle:use_active_for_splits")->intValue;
static auto* const PDEFAULTSPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:default_split_ratio")->floatValue;

if (direction != DIRECTION_DEFAULT && overrideDirection == DIRECTION_DEFAULT)
vaxerski marked this conversation as resolved.
Show resolved Hide resolved
overrideDirection = direction;

// Populate the node with our window's data
PNODE->workspaceID = pWindow->m_iWorkspaceID;
PNODE->pWindow = pWindow;
Expand Down Expand Up @@ -297,7 +300,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow) {
// last fail-safe to avoid duplicate fullscreens
if ((!OPENINGON || OPENINGON->pWindow == pWindow) && getNodesOnWorkspace(PNODE->workspaceID) > 1) {
for (auto& node : m_lDwindleNodesData) {
if (node.workspaceID == PNODE->workspaceID && node.pWindow != pWindow) {
if (node.workspaceID == PNODE->workspaceID && node.pWindow != nullptr && node.pWindow != pWindow) {
OPENINGON = &node;
break;
}
Expand Down Expand Up @@ -372,7 +375,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow) {
bool verticalOverride = false;

// let user select position -> top, right, bottom, left
if (overrideDirection != OneTimeFocus::NOFOCUS) {
if (overrideDirection != DIRECTION_DEFAULT) {

// this is horizontal
if (overrideDirection % 2 == 0)
Expand All @@ -391,7 +394,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow) {

// whether or not the override persists after opening one window
if (*PERMANENTDIRECTIONOVERRIDE == 0)
overrideDirection = OneTimeFocus::NOFOCUS;
overrideDirection = DIRECTION_DEFAULT;
} else if (*PSMARTSPLIT == 1) {
const auto tl = NEWPARENT->position;
const auto tr = NEWPARENT->position + Vector2D(NEWPARENT->size.x, 0);
Expand Down Expand Up @@ -994,26 +997,26 @@ std::any CHyprDwindleLayout::layoutMessage(SLayoutMessageHeader header, std::str
switch (direction.front()) {
case 'u':
case 't': {
overrideDirection = OneTimeFocus::UP;
overrideDirection = DIRECTION_UP;
break;
}
case 'd':
case 'b': {
overrideDirection = OneTimeFocus::DOWN;
overrideDirection = DIRECTION_DOWN;
break;
}
case 'r': {
overrideDirection = OneTimeFocus::RIGHT;
overrideDirection = DIRECTION_RIGHT;
break;
}
case 'l': {
overrideDirection = OneTimeFocus::LEFT;
overrideDirection = DIRECTION_LEFT;
break;
}
default: {
// any other character resets the focus direction
// needed for the persistent mode
overrideDirection = OneTimeFocus::NOFOCUS;
overrideDirection = DIRECTION_DEFAULT;
break;
}
}
Expand Down
13 changes: 2 additions & 11 deletions src/layout/DwindleLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,6 @@
class CHyprDwindleLayout;
enum eFullscreenMode : uint8_t;

enum OneTimeFocus
{
UP = 0,
RIGHT,
DOWN,
LEFT,
NOFOCUS,
};

struct SDwindleNodeData {
SDwindleNodeData* pParent = nullptr;
bool isNode = false;
Expand Down Expand Up @@ -51,7 +42,7 @@ struct SDwindleNodeData {

class CHyprDwindleLayout : public IHyprLayout {
public:
virtual void onWindowCreatedTiling(CWindow*);
virtual void onWindowCreatedTiling(CWindow*, eDirection direction = DIRECTION_DEFAULT);
virtual void onWindowRemovedTiling(CWindow*);
virtual bool isWindowTiled(CWindow*);
virtual void recalculateMonitor(const int&);
Expand Down Expand Up @@ -90,7 +81,7 @@ class CHyprDwindleLayout : public IHyprLayout {

void toggleSplit(CWindow*);

OneTimeFocus overrideDirection = OneTimeFocus::NOFOCUS;
eDirection overrideDirection = DIRECTION_DEFAULT;

friend struct SDwindleNodeData;
};
4 changes: 2 additions & 2 deletions src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "../defines.hpp"
#include "../Compositor.hpp"

void IHyprLayout::onWindowCreated(CWindow* pWindow) {
void IHyprLayout::onWindowCreated(CWindow* pWindow, eDirection direction) {
if (pWindow->m_bIsFloating) {
onWindowCreatedFloating(pWindow);
} else {
Expand All @@ -18,7 +18,7 @@ void IHyprLayout::onWindowCreated(CWindow* pWindow) {

pWindow->m_vPseudoSize = pWindow->m_vLastFloatingSize;

onWindowCreatedTiling(pWindow);
onWindowCreatedTiling(pWindow, direction);
}
}

Expand Down
15 changes: 11 additions & 4 deletions src/layout/IHyprLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,22 @@ struct SLayoutMessageHeader {

enum eFullscreenMode : uint8_t;

enum eRectCorner
{
enum eRectCorner {
CORNER_NONE = 0,
CORNER_TOPLEFT,
CORNER_TOPRIGHT,
CORNER_BOTTOMRIGHT,
CORNER_BOTTOMLEFT
};

enum eDirection {
DIRECTION_DEFAULT = -1,
DIRECTION_UP = 0,
DIRECTION_RIGHT,
DIRECTION_DOWN,
DIRECTION_LEFT
};

class IHyprLayout {
public:
virtual ~IHyprLayout() = 0;
Expand All @@ -35,8 +42,8 @@ class IHyprLayout {
The layout HAS TO set the goal pos and size (anim mgr will use it)
If !animationinprogress, then the anim mgr will not apply an anim.
*/
virtual void onWindowCreated(CWindow*);
virtual void onWindowCreatedTiling(CWindow*) = 0;
virtual void onWindowCreated(CWindow*, eDirection direction = DIRECTION_DEFAULT);
virtual void onWindowCreatedTiling(CWindow*, eDirection direction = DIRECTION_DEFAULT) = 0;
virtual void onWindowCreatedFloating(CWindow*);

/*
Expand Down
48 changes: 23 additions & 25 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ SMasterNodeData* CHyprMasterLayout::getMasterNodeOnWorkspace(const int& ws) {
return nullptr;
}

void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow) {
void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direction) {
if (pWindow->m_bIsFloating)
return;

Expand Down Expand Up @@ -294,11 +294,11 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) {
}
}

const float totalSize = (orientation == ORIENTATION_TOP || orientation == ORIENTATION_BOTTOM) ? WSSIZE.x : WSSIZE.y;
const float masterAverageSize = totalSize / MASTERS;
const float slaveAverageSize = totalSize / STACKWINDOWS;
float masterAccumulatedSize = 0;
float slaveAccumulatedSize = 0;
const float totalSize = (orientation == ORIENTATION_TOP || orientation == ORIENTATION_BOTTOM) ? WSSIZE.x : WSSIZE.y;
const float masterAverageSize = totalSize / MASTERS;
const float slaveAverageSize = totalSize / STACKWINDOWS;
float masterAccumulatedSize = 0;
float slaveAccumulatedSize = 0;

if (*PSMARTRESIZING) {
// check the total width and height so that later
Expand Down Expand Up @@ -674,13 +674,13 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne
bool centered = orientation == ORIENTATION_CENTER && (*ALWAYSCENTER == 1);
double delta = 0;

const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
const bool DISPLAYRIGHT = STICKS(PWINDOW->m_vPosition.x + PWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
const bool DISPLAYTOP = STICKS(PWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
const bool DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);
const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y);
const bool DISPLAYRIGHT = STICKS(PWINDOW->m_vPosition.x + PWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x);
const bool DISPLAYTOP = STICKS(PWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y);
const bool DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x);

const bool LEFT = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT;
const bool TOP = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT;
const bool LEFT = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT;
const bool TOP = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT;

if (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 && !centered)
return;
Expand Down Expand Up @@ -732,19 +732,18 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne
nodesInSameColumn /= 2;

if (RESIZEDELTA != 0 && nodesInSameColumn > 1) {
const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE);
const auto REVNODEIT = std::find(m_lMasterNodesData.rbegin(), m_lMasterNodesData.rend(), *PNODE);
const auto SIZE = isStackVertical ?
(PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / nodesInSameColumn:
(PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / nodesInSameColumn;
const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE);
const auto REVNODEIT = std::find(m_lMasterNodesData.rbegin(), m_lMasterNodesData.rend(), *PNODE);
const auto SIZE = isStackVertical ? (PMONITOR->vecSize.y - PMONITOR->vecReservedTopLeft.y - PMONITOR->vecReservedBottomRight.y) / nodesInSameColumn :
(PMONITOR->vecSize.x - PMONITOR->vecReservedTopLeft.x - PMONITOR->vecReservedBottomRight.x) / nodesInSameColumn;

const float totalSize = isStackVertical ? WSSIZE.y : WSSIZE.x;
const float minSize = totalSize / nodesInSameColumn * 0.2;
const bool resizePrevNodes = isStackVertical ? (TOP || DISPLAYBOTTOM) && !DISPLAYTOP : (LEFT || DISPLAYRIGHT) && !DISPLAYLEFT;

int nodesLeft = 0;
float sizeLeft = 0;
int nodeCount = 0;
int nodesLeft = 0;
float sizeLeft = 0;
int nodeCount = 0;
// check the sizes of all the nodes to be resized for later calculation
auto checkNodesLeft = [&sizeLeft, &nodesLeft, orientation, isStackVertical, &nodeCount, PNODE](auto it) {
if (it.isMaster != PNODE->isMaster || it.workspaceID != PNODE->workspaceID)
Expand Down Expand Up @@ -773,17 +772,16 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne
PNODE->percSize += resizeDiff / SIZE;

// resize the other nodes
nodeCount = 0;
auto resizeNodesLeft = [maxSizeIncrease, resizeDiff, minSize, orientation, isStackVertical, SIZE, &nodeCount, nodesLeft, PNODE](auto &it) {
nodeCount = 0;
auto resizeNodesLeft = [maxSizeIncrease, resizeDiff, minSize, orientation, isStackVertical, SIZE, &nodeCount, nodesLeft, PNODE](auto& it) {
if (it.isMaster != PNODE->isMaster || it.workspaceID != PNODE->workspaceID)
return;
nodeCount++;
// if center orientation, only resize when on the same side
if (!it.isMaster && orientation == ORIENTATION_CENTER && nodeCount % 2 == 1)
return;
const float size = isStackVertical ? it.size.y : it.size.x;
const float resizeDeltaForEach = maxSizeIncrease != 0 ?
resizeDiff * (size - minSize) / maxSizeIncrease : resizeDiff / nodesLeft;
const float size = isStackVertical ? it.size.y : it.size.x;
const float resizeDeltaForEach = maxSizeIncrease != 0 ? resizeDiff * (size - minSize) / maxSizeIncrease : resizeDiff / nodesLeft;
it.percSize -= resizeDeltaForEach / SIZE;
};
if (resizePrevNodes) {
Expand Down
2 changes: 1 addition & 1 deletion src/layout/MasterLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct SMasterWorkspaceData {

class CHyprMasterLayout : public IHyprLayout {
public:
virtual void onWindowCreatedTiling(CWindow*);
virtual void onWindowCreatedTiling(CWindow*, eDirection direction = DIRECTION_DEFAULT);
virtual void onWindowRemovedTiling(CWindow*);
virtual bool isWindowTiled(CWindow*);
virtual void recalculateMonitor(const int&);
Expand Down
23 changes: 17 additions & 6 deletions src/managers/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1963,17 +1963,28 @@ void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDi
g_pCompositor->warpCursorTo(pWindow->middle());
}

void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow) {
static auto* const BFOCUSREMOVEDWINDOW = &g_pConfigManager->getConfigValuePtr("misc:group_focus_removed_window")->intValue;
const auto PWINDOWPREV = pWindow->getGroupPrevious();
void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir) {
static auto* const BFOCUSREMOVEDWINDOW = &g_pConfigManager->getConfigValuePtr("misc:group_focus_removed_window")->intValue;
const auto PWINDOWPREV = pWindow->getGroupPrevious();
eDirection direction;

switch (dir[0]) {
case 't':
case 'u': direction = DIRECTION_UP; break;
case 'd':
case 'b': direction = DIRECTION_DOWN; break;
case 'l': direction = DIRECTION_LEFT; break;
case 'r': direction = DIRECTION_RIGHT; break;
default: direction = DIRECTION_DEFAULT;
}

g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow);

const auto GROUPSLOCKEDPREV = g_pKeybindManager->m_bGroupsLocked;

g_pKeybindManager->m_bGroupsLocked = true;

g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow);
g_pLayoutManager->getCurrentLayout()->onWindowCreated(pWindow, direction);

g_pKeybindManager->m_bGroupsLocked = GROUPSLOCKEDPREV;

Expand Down Expand Up @@ -2059,13 +2070,13 @@ void CKeybindManager::moveWindowOrGroup(std::string args) {
moveWindowIntoGroup(PWINDOW, PWINDOWINDIR);
} else if (PWINDOWINDIR) {
if (ISWINDOWGROUP && (*BIGNOREGROUPLOCK || !ISWINDOWGROUPLOCKED))
moveWindowOutOfGroup(PWINDOW);
moveWindowOutOfGroup(PWINDOW, args);
else {
g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args);
g_pCompositor->warpCursorTo(PWINDOW->middle());
}
} else if (ISWINDOWGROUP && (*BIGNOREGROUPLOCK || !ISWINDOWGROUPLOCKED)) {
moveWindowOutOfGroup(PWINDOW);
moveWindowOutOfGroup(PWINDOW, args);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/managers/KeybindManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class CKeybindManager {
bool ensureMouseBindState();

static bool tryMoveFocusToMonitor(CMonitor* monitor);
static void moveWindowOutOfGroup(CWindow* pWindow);
static void moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir = "");
static void moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDirection);
static void switchToWindow(CWindow* PWINDOWTOCHANGETO);

Expand Down