Skip to content

Commit

Permalink
feat(layout): add direction parameter to onWindowCreated and friends
Browse files Browse the repository at this point in the history
In addition:

- Implement directional moveWindowOutOfGroup for `movewindoworgroup`
  when using dwindle layout. (augmentation of #3006)
- Replace `DWindleLayout::OneTimeFocus` with `IHyprLayout::eDirection`.
- Slight formatting change (clang-format).
  • Loading branch information
memchr committed Sep 12, 2023
1 parent df51c45 commit 83e8043
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 58 deletions.
19 changes: 11 additions & 8 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 != eDirection::NONE)
overrideDirection = direction;

// Populate the node with our window's data
PNODE->workspaceID = pWindow->m_iWorkspaceID;
PNODE->pWindow = pWindow;
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 != eDirection::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 = eDirection::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 = eDirection::UP;
break;
}
case 'd':
case 'b': {
overrideDirection = OneTimeFocus::DOWN;
overrideDirection = eDirection::DOWN;
break;
}
case 'r': {
overrideDirection = OneTimeFocus::RIGHT;
overrideDirection = eDirection::RIGHT;
break;
}
case 'l': {
overrideDirection = OneTimeFocus::LEFT;
overrideDirection = eDirection::LEFT;
break;
}
default: {
// any other character resets the focus direction
// needed for the persistent mode
overrideDirection = OneTimeFocus::NOFOCUS;
overrideDirection = eDirection::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 = NONE);
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 = eDirection::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,8 +15,7 @@ struct SLayoutMessageHeader {

enum eFullscreenMode : uint8_t;

enum eRectCorner
{
enum eRectCorner {
CORNER_NONE = 0,
CORNER_TOPLEFT,
CORNER_TOPRIGHT,
Expand All @@ -30,13 +29,21 @@ class IHyprLayout {
virtual void onEnable() = 0;
virtual void onDisable() = 0;

enum eDirection {
UP = 0,
RIGHT,
DOWN,
LEFT,
DEFAULT,
NONE
};
/*
Called when a window is created (mapped)
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 = NONE);
virtual void onWindowCreatedTiling(CWindow*, eDirection direction = NONE) = 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 = NONE);
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();
IHyprLayout::eDirection direction;

switch (dir[0]) {
case 't':
case 'u': direction = IHyprLayout::eDirection::UP; break;
case 'd':
case 'b': direction = IHyprLayout::eDirection::DOWN; break;
case 'l': direction = IHyprLayout::eDirection::LEFT; break;
case 'r': direction = IHyprLayout::eDirection::RIGHT; break;
default: direction = IHyprLayout::NONE;
}

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

0 comments on commit 83e8043

Please sign in to comment.