Skip to content

Commit

Permalink
layout: Allow the layout to control how windows are raised in groups (#…
Browse files Browse the repository at this point in the history
…3275)

* Allow the layout to control how windows are raised in groups

Previously windows could only be focused if they weren't hidden or
were part of a group. This shifts the logic for picking the window out
of a group to the layout allowing for alternate group implementations
to function normally.

* Fix doc comment consistency

* Fix tabs in comments
  • Loading branch information
outfoxxed authored Sep 12, 2023
1 parent be19773 commit b0d5e40
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
7 changes: 2 additions & 5 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -829,10 +829,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) {
return;
}

if (pWindow && pWindow->isHidden() && pWindow->m_sGroupData.pNextWindow) {
// grouped, change the current to us
pWindow->setGroupCurrent(pWindow);
}
g_pLayoutManager->getCurrentLayout()->bringWindowToTop(pWindow);

if (!pWindow || !windowValidMapped(pWindow)) {
const auto PLASTWINDOW = m_pLastWindow;
Expand Down Expand Up @@ -2171,7 +2168,7 @@ CWindow* CCompositor::getWindowByRegex(const std::string& regexp) {
}

for (auto& w : g_pCompositor->m_vWindows) {
if (!w->m_bIsMapped || (w->isHidden() && !w->m_sGroupData.pNextWindow))
if (!w->m_bIsMapped || (w->isHidden() && !g_pLayoutManager->getCurrentLayout()->isWindowReachable(w.get())))
continue;

switch (mode) {
Expand Down
12 changes: 11 additions & 1 deletion src/layout/IHyprLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,12 +535,22 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) {
return PWINDOWCANDIDATE;
}

void IHyprLayout::requestFocusForWindow(CWindow* pWindow) {
bool IHyprLayout::isWindowReachable(CWindow* pWindow) {
return pWindow && (!pWindow->isHidden() || pWindow->m_sGroupData.pNextWindow);
}

void IHyprLayout::bringWindowToTop(CWindow* pWindow) {
if (pWindow == nullptr)
return;

if (pWindow->isHidden() && pWindow->m_sGroupData.pNextWindow) {
// grouped, change the current to this window
pWindow->setGroupCurrent(pWindow);
}
}

void IHyprLayout::requestFocusForWindow(CWindow* pWindow) {
bringWindowToTop(pWindow);
g_pCompositor->focusWindow(pWindow);
}

Expand Down
14 changes: 13 additions & 1 deletion src/layout/IHyprLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,22 @@ class IHyprLayout {
*/
virtual void replaceWindowDataWith(CWindow* from, CWindow* to) = 0;

/*
Determines if a window can be focused. If hidden this usually means the window is part of a group.
*/
virtual bool isWindowReachable(CWindow*);

/*
Called before an attempt is made to focus a window.
Brings the window to the top of any groups and ensures it is not hidden.
If the window is unmapped following this call, the focus attempt will fail.
*/
virtual void bringWindowToTop(CWindow*);

/*
Called via the foreign toplevel activation protocol.
Focuses a window, bringing it to the top of its group if applicable.
May be ignored.
May be ignored.
*/
virtual void requestFocusForWindow(CWindow*);

Expand Down

0 comments on commit b0d5e40

Please sign in to comment.