summaryrefslogtreecommitdiff
path: root/src/layout/IHyprLayout.cpp
diff options
context:
space:
mode:
authorAqa-Ib <victorcana@gmx.com>2024-10-02 11:22:19 +0200
committerGitHub <noreply@github.com>2024-10-02 10:22:19 +0100
commite2426942e5716a742ea353d2a1de7d7760fbbb41 (patch)
tree046d532f7d0090e9614b66aae34388117b850f3a /src/layout/IHyprLayout.cpp
parent5c6c300abfea2539ffad9bcbf857325eec5ab765 (diff)
layout: add auto_group to control default grouping (#7883)
Diffstat (limited to 'src/layout/IHyprLayout.cpp')
-rw-r--r--src/layout/IHyprLayout.cpp69
1 files changed, 56 insertions, 13 deletions
diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp
index c5a5373c..0fb78d02 100644
--- a/src/layout/IHyprLayout.cpp
+++ b/src/layout/IHyprLayout.cpp
@@ -9,23 +9,25 @@
#include "../xwayland/XSurface.hpp"
void IHyprLayout::onWindowCreated(PHLWINDOW pWindow, eDirection direction) {
- if (pWindow->m_bIsFloating) {
- onWindowCreatedFloating(pWindow);
- } else {
- CBox desiredGeometry = {};
- g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry);
+ CBox desiredGeometry = {};
+ g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry);
- if (desiredGeometry.width <= 5 || desiredGeometry.height <= 5) {
- const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
- pWindow->m_vLastFloatingSize = PMONITOR->vecSize / 2.f;
- } else {
- pWindow->m_vLastFloatingSize = Vector2D(desiredGeometry.width, desiredGeometry.height);
- }
+ if (desiredGeometry.width <= 5 || desiredGeometry.height <= 5) {
+ const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
+ pWindow->m_vLastFloatingSize = PMONITOR->vecSize / 2.f;
+ } else
+ pWindow->m_vLastFloatingSize = Vector2D(desiredGeometry.width, desiredGeometry.height);
+
+ pWindow->m_vPseudoSize = pWindow->m_vLastFloatingSize;
- pWindow->m_vPseudoSize = pWindow->m_vLastFloatingSize;
+ bool autoGrouped = IHyprLayout::onWindowCreatedAutoGroup(pWindow);
+ if (autoGrouped)
+ return;
+ if (pWindow->m_bIsFloating)
+ onWindowCreatedFloating(pWindow);
+ else
onWindowCreatedTiling(pWindow, direction);
- }
}
void IHyprLayout::onWindowRemoved(PHLWINDOW pWindow) {
@@ -178,6 +180,47 @@ void IHyprLayout::onWindowCreatedFloating(PHLWINDOW pWindow) {
}
}
+bool IHyprLayout::onWindowCreatedAutoGroup(PHLWINDOW pWindow) {
+ static auto AUTOGROUP = CConfigValue<Hyprlang::INT>("group:auto_group");
+ if ((*AUTOGROUP || g_pInputManager->m_bWasDraggingWindow) // check if auto_group is enabled, or, if the user is manually dragging the window into the group.
+ && g_pCompositor->m_pLastWindow.lock() // check if a focused window exists.
+ && g_pCompositor->m_pLastWindow != pWindow // fixes a freeze when activating togglefloat to transform a floating group into a tiled group.
+ && g_pCompositor->m_pLastWindow->m_pWorkspace ==
+ pWindow
+ ->m_pWorkspace // fix for multimonitor: when there is a focused group in monitor 1 and monitor 2 is empty, this enables adding the first window of monitor 2 when using the mouse to focus it.
+ && g_pCompositor->m_pLastWindow->m_sGroupData.pNextWindow.lock() // check if the focused window is a group
+ && pWindow->canBeGroupedInto(g_pCompositor->m_pLastWindow.lock()) // check if the new window can be grouped into the focused group
+ && !g_pXWaylandManager->shouldBeFloated(pWindow)) { // don't group XWayland windows that should be floated.
+
+ switch (pWindow->m_bIsFloating) {
+ case false:
+ if (g_pCompositor->m_pLastWindow->m_bIsFloating)
+ pWindow->m_bIsFloating = true;
+ break;
+
+ case true:
+ if (!g_pCompositor->m_pLastWindow->m_bIsFloating)
+ pWindow->m_bIsFloating = false;
+ break;
+ }
+
+ static auto USECURRPOS = CConfigValue<Hyprlang::INT>("group:insert_after_current");
+ (*USECURRPOS ? g_pCompositor->m_pLastWindow : g_pCompositor->m_pLastWindow->getGroupTail())->insertWindowToGroup(pWindow);
+
+ g_pCompositor->m_pLastWindow->setGroupCurrent(pWindow);
+ pWindow->applyGroupRules();
+ pWindow->updateWindowDecos();
+ recalculateWindow(pWindow);
+
+ if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
+ pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));
+
+ return true;
+ }
+
+ return false;
+}
+
void IHyprLayout::onBeginDragWindow() {
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow.lock();