layout: add direction parameter to onWindowCreated and friends (#3269)

* feat(layout): add direction parameter to onWindowCreated and friends

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).

* fix: nullptr dereference in dwindle window creation

* refactor: generalized eDirection

* refactor: eliminate DIRECTION_NONE

* Update IHyprLayout.hpp
This commit is contained in:
memchr
2023-09-13 10:13:29 +00:00
committed by GitHub
parent b0d5e4008b
commit 6b1ac659e0
8 changed files with 69 additions and 59 deletions

View File

@@ -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;
@@ -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)
overrideDirection = direction;
// Populate the node with our window's data
PNODE->workspaceID = pWindow->m_iWorkspaceID;
PNODE->pWindow = pWindow;
@@ -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;
}
@@ -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)
@@ -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);
@@ -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;
}
}