From 1357b66091ecd73f097d19d527a23a9ae72a4ff1 Mon Sep 17 00:00:00 2001 From: memchr <118117622+memchr@users.noreply.github.com> Date: Thu, 21 Sep 2023 23:42:00 +0000 Subject: windowrules: add rule `group` to map windows grouped (#3279) * windows: add rule group to map windows grouped * group rule: use `invade` to force open a window in a locked group --- src/Window.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/Window.cpp') diff --git a/src/Window.cpp b/src/Window.cpp index 3df30123..4ee40dff 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -641,6 +641,69 @@ bool CWindow::hasPopupAt(const Vector2D& pos) { return resultSurf; } +void CWindow::applyGroupRules() { + if ((m_eGroupRules & GROUP_SET && m_bFirstMap) || m_eGroupRules & GROUP_SET_ALWAYS) + createGroup(); + + if (m_sGroupData.pNextWindow && ((m_eGroupRules & GROUP_LOCK && m_bFirstMap) || m_eGroupRules & GROUP_LOCK_ALWAYS)) + getGroupHead()->m_sGroupData.locked = true; +} + +void CWindow::createGroup() { + if (m_sGroupData.deny) { + Debug::log(LOG, "createGroup: window:{:x},title:{} is denied as a group, ignored", (uintptr_t)this, this->m_szTitle); + return; + } + if (!m_sGroupData.pNextWindow) { + m_sGroupData.pNextWindow = this; + m_sGroupData.head = true; + m_sGroupData.locked = false; + m_sGroupData.deny = false; + + m_dWindowDecorations.emplace_back(std::make_unique(this)); + updateWindowDecos(); + + g_pLayoutManager->getCurrentLayout()->recalculateWindow(this); + g_pCompositor->updateAllWindowsAnimatedDecorationValues(); + } +} + +void CWindow::destroyGroup() { + if (m_sGroupData.pNextWindow == this) { + if (m_eGroupRules & GROUP_SET_ALWAYS) { + Debug::log(LOG, "destoryGroup: window:{:x},title:{} has rule [group set always], ignored", (uintptr_t)this, this->m_szTitle); + return; + } + m_sGroupData.pNextWindow = nullptr; + updateWindowDecos(); + return; + } + + CWindow* curr = this; + std::vector members; + do { + const auto PLASTWIN = curr; + curr = curr->m_sGroupData.pNextWindow; + PLASTWIN->m_sGroupData.pNextWindow = nullptr; + curr->setHidden(false); + members.push_back(curr); + } while (curr != this); + + for (auto& w : members) { + if (w->m_sGroupData.head) + g_pLayoutManager->getCurrentLayout()->onWindowRemoved(curr); + w->m_sGroupData.head = false; + } + + const bool GROUPSLOCKEDPREV = g_pKeybindManager->m_bGroupsLocked; + g_pKeybindManager->m_bGroupsLocked = true; + for (auto& w : members) { + g_pLayoutManager->getCurrentLayout()->onWindowCreated(w); + w->updateWindowDecos(); + } + g_pKeybindManager->m_bGroupsLocked = GROUPSLOCKEDPREV; +} + CWindow* CWindow::getGroupHead() { CWindow* curr = this; while (!curr->m_sGroupData.head) -- cgit v1.2.3