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

feat: auto_group #7883

Merged
merged 23 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6aba6e8
feat: auto_group
Aqa-Ib Sep 22, 2024
e0b4c56
fix: allfloat = false, adding new windows to a floating group
Aqa-Ib Sep 24, 2024
ae5709c
clang-format
Aqa-Ib Sep 24, 2024
1767a16
commentary
Aqa-Ib Sep 24, 2024
8fc44b0
fix: allfloat = false, when the workspace is filled with tiled and fl…
Aqa-Ib Sep 24, 2024
328fe2a
fix: allfloat = true, adding new windows to a tiled group.
Aqa-Ib Sep 24, 2024
b7e18ff
fix: allfloat = false, layout = dwindle. the only one window in the w…
Aqa-Ib Sep 24, 2024
147f293
adhere to naming
Aqa-Ib Sep 24, 2024
ede69bb
fix: a freeze in master layout when toggling a floating group into a
Aqa-Ib Sep 25, 2024
623b04a
fix: toggling a floating group into a tiled group freezes hyprland in…
Aqa-Ib Sep 25, 2024
efb07c2
add: when auto_group = false -> allow the user to manually drag the w…
Aqa-Ib Sep 25, 2024
bbee77f
add consistency
Aqa-Ib Sep 26, 2024
1ad7481
add multi monitor support
Aqa-Ib Sep 26, 2024
31af287
remove repeated check
Aqa-Ib Sep 26, 2024
2fbdb7e
add a missing .lock()
Aqa-Ib Sep 26, 2024
2b0acc0
fix: allfloat=true, togglefloating a tiled group makes it to lose its…
Aqa-Ib Sep 27, 2024
0d06b79
improve consistency
Aqa-Ib Sep 27, 2024
2c2d662
remove unnecessary check as https://github.com/hyprwm/Hyprland/pull/3302
Aqa-Ib Sep 27, 2024
75dc072
fix: XWayland floating windows
Aqa-Ib Sep 28, 2024
7886278
refactor: unify and simplify the code
Aqa-Ib Sep 28, 2024
74a1613
refactor: remove recursiveness
Aqa-Ib Sep 30, 2024
ce8cc09
also add sizes for new floated windows. fixes a bug where the window …
Aqa-Ib Sep 30, 2024
721205c
style: remove curly braces around short else statement
Aqa-Ib Oct 2, 2024
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
6 changes: 6 additions & 0 deletions src/config/ConfigDescriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,12 @@ inline static const std::vector<SConfigOptionDescription> CONFIG_OPTIONS = {
.type = CONFIG_OPTION_GRADIENT,
.data = SConfigOptionDescription::SGradientData{"0x66775500"},
},
SConfigOptionDescription{
.value = "group:auto_group",
.description = "automatically group new windows",
.type = CONFIG_OPTION_BOOL,
.data = SConfigOptionDescription::SBoolData{true},
},

/*
* group:groupbar:
Expand Down
1 change: 1 addition & 0 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1});
m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1});
m_pConfig->addConfigValue("group:merge_groups_on_drag", Hyprlang::INT{1});
m_pConfig->addConfigValue("group:auto_group", Hyprlang::INT{1});
m_pConfig->addConfigValue("group:groupbar:enabled", Hyprlang::INT{1});
m_pConfig->addConfigValue("group:groupbar:font_family", {STRVAL_EMPTY});
m_pConfig->addConfigValue("group:groupbar:font_size", Hyprlang::INT{8});
Expand Down
2 changes: 1 addition & 1 deletion src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
PWINDOW->updateWindowData();

if (PWINDOW->m_bIsFloating) {
g_pLayoutManager->getCurrentLayout()->onWindowCreatedFloating(PWINDOW);
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW);
PWINDOW->m_bCreatedOverFullscreen = true;

// size and move rules
Expand Down
21 changes: 1 addition & 20 deletions src/layout/DwindleLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dir
return;
}

// if it's a group, add the window
if (OPENINGON->pWindow->m_sGroupData.pNextWindow.lock() // target is group
&& pWindow->canBeGroupedInto(OPENINGON->pWindow.lock()) && !m_vOverrideFocalPoint) { // we are not moving window
m_lDwindleNodesData.remove(*PNODE);

static auto USECURRPOS = CConfigValue<Hyprlang::INT>("group:insert_after_current");
(*USECURRPOS ? OPENINGON->pWindow.lock() : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow);

OPENINGON->pWindow->setGroupCurrent(pWindow);
pWindow->applyGroupRules();
pWindow->updateWindowDecos();
recalculateWindow(pWindow);

if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));

return;
}

// If it's not, get the node under our cursor
// get the node under our cursor

m_lDwindleNodesData.push_back(SDwindleNodeData());
const auto NEWPARENT = &m_lDwindleNodesData.back();
Expand Down
69 changes: 56 additions & 13 deletions src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
vaxerski marked this conversation as resolved.
Show resolved Hide resolved
}
}

void IHyprLayout::onWindowRemoved(PHLWINDOW pWindow) {
Expand Down Expand Up @@ -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) {
Aqa-Ib marked this conversation as resolved.
Show resolved Hide resolved
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();

Expand Down
1 change: 1 addition & 0 deletions src/layout/IHyprLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class IHyprLayout {
virtual void onWindowCreated(PHLWINDOW, eDirection direction = DIRECTION_DEFAULT);
virtual void onWindowCreatedTiling(PHLWINDOW, eDirection direction = DIRECTION_DEFAULT) = 0;
virtual void onWindowCreatedFloating(PHLWINDOW);
virtual bool onWindowCreatedAutoGroup(PHLWINDOW);

/*
Return tiled status
Expand Down
20 changes: 0 additions & 20 deletions src/layout/MasterLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,26 +116,6 @@ void CHyprMasterLayout::onWindowCreatedTiling(PHLWINDOW pWindow, eDirection dire
return;
}

// if it's a group, add the window
if (OPENINGON && OPENINGON != PNODE && OPENINGON->pWindow->m_sGroupData.pNextWindow.lock() // target is group
&& pWindow->canBeGroupedInto(OPENINGON->pWindow.lock())) {

m_lMasterNodesData.remove(*PNODE);

static auto USECURRPOS = CConfigValue<Hyprlang::INT>("group:insert_after_current");
(*USECURRPOS ? OPENINGON->pWindow.lock() : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow);

OPENINGON->pWindow->setGroupCurrent(pWindow);
pWindow->applyGroupRules();
pWindow->updateWindowDecos();
recalculateWindow(pWindow);

if (!pWindow->getDecorationByType(DECORATION_GROUPBAR))
pWindow->addWindowDeco(std::make_unique<CHyprGroupBarDecoration>(pWindow));

return;
}

pWindow->applyGroupRules();

static auto PDROPATCURSOR = CConfigValue<Hyprlang::INT>("master:drop_at_cursor");
Expand Down
Loading