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

Get current layout from workspace instead of g_pLayoutManager #6544

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 14 additions & 12 deletions src/Compositor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,8 @@ void CCompositor::focusWindow(PHLWINDOW pWindow, SP<CWLSurfaceResource> pSurface
if (pWindow && pWindow->m_bIsX11 && pWindow->m_iX11Type == 2 && !pWindow->m_pXWaylandSurface->wantsFocus())
return;

g_pLayoutManager->getCurrentLayout()->bringWindowToTop(pWindow);
if (pWindow)
pWindow->m_pWorkspace->getCurrentLayout()->bringWindowToTop(pWindow);

if (!pWindow || !validMapped(pWindow)) {

Expand All @@ -898,7 +899,8 @@ void CCompositor::focusWindow(PHLWINDOW pWindow, SP<CWLSurfaceResource> pSurface

EMIT_HOOK_EVENT("activeWindow", (PHLWINDOW) nullptr);

g_pLayoutManager->getCurrentLayout()->onWindowFocusChange(nullptr);
if (m_pLastMonitor)
m_pLastMonitor->activeWorkspace->getCurrentLayout()->onWindowFocusChange(nullptr);

m_pLastFocus.reset();

Expand Down Expand Up @@ -971,7 +973,7 @@ void CCompositor::focusWindow(PHLWINDOW pWindow, SP<CWLSurfaceResource> pSurface

EMIT_HOOK_EVENT("activeWindow", pWindow);

g_pLayoutManager->getCurrentLayout()->onWindowFocusChange(pWindow);
pWindow->m_pWorkspace->getCurrentLayout()->onWindowFocusChange(pWindow);

g_pInputManager->recheckIdleInhibitorStatus();

Expand Down Expand Up @@ -1764,7 +1766,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(PHLWINDOW pWindow) {
};

// border
const auto RENDERDATA = g_pLayoutManager->getCurrentLayout()->requestRenderHints(pWindow);
const auto RENDERDATA = pWindow->m_pWorkspace->getCurrentLayout()->requestRenderHints(pWindow);
if (RENDERDATA.isBorderGradient)
setBorderColor(*RENDERDATA.borderGradient);
else {
Expand Down Expand Up @@ -1905,8 +1907,8 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB)
PWORKSPACEA->rememberPrevWorkspace(PWORKSPACEB);
PWORKSPACEB->rememberPrevWorkspace(PWORKSPACEA);

g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitorA->ID);
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitorB->ID);
PWORKSPACEA->getCurrentLayout()->recalculateMonitor(pMonitorB->ID);
PWORKSPACEB->getCurrentLayout()->recalculateMonitor(pMonitorA->ID);

updateFullscreenFadeOnWorkspace(PWORKSPACEB);
updateFullscreenFadeOnWorkspace(PWORKSPACEA);
Expand Down Expand Up @@ -2090,7 +2092,7 @@ void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, CMonitor* pMon

setActiveMonitor(pMonitor);
pMonitor->activeWorkspace = pWorkspace;
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitor->ID);
pWorkspace->getCurrentLayout()->recalculateMonitor(pMonitor->ID);

pWorkspace->startAnim(true, true, true);
pWorkspace->m_bVisible = true;
Expand All @@ -2103,7 +2105,7 @@ void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, CMonitor* pMon

// finalize
if (POLDMON) {
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID);
POLDMON->activeWorkspace->getCurrentLayout()->recalculateMonitor(POLDMON->ID);
updateFullscreenFadeOnWorkspace(POLDMON->activeWorkspace);
updateSuspendedStates();
}
Expand Down Expand Up @@ -2187,7 +2189,7 @@ void CCompositor::setWindowFullscreen(PHLWINDOW pWindow, bool on, eFullscreenMod
return;
}

g_pLayoutManager->getCurrentLayout()->fullscreenRequestForWindow(pWindow, MODE, on);
PWORKSPACE->getCurrentLayout()->fullscreenRequestForWindow(pWindow, MODE, on);

g_pXWaylandManager->setWindowFullscreen(pWindow, pWindow->shouldSendFullscreenState());

Expand Down Expand Up @@ -2304,7 +2306,7 @@ PHLWINDOW CCompositor::getWindowByRegex(const std::string& regexp) {
}

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

switch (mode) {
Expand Down Expand Up @@ -2546,10 +2548,10 @@ void CCompositor::moveWindowToWorkspaceSafe(PHLWINDOW pWindow, PHLWORKSPACE pWor
setWindowFullscreen(pWindow, false, FULLSCREEN_FULL);

if (!pWindow->m_bIsFloating) {
g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow);
pWindow->m_pWorkspace->getCurrentLayout()->onWindowRemovedTiling(pWindow);
pWindow->moveToWorkspace(pWorkspace);
pWindow->m_iMonitorID = pWorkspace->m_iMonitorID;
g_pLayoutManager->getCurrentLayout()->onWindowCreatedTiling(pWindow);
pWindow->m_pWorkspace->getCurrentLayout()->onWindowCreatedTiling(pWindow);
} else {
const auto PWINDOWMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID);
const auto POSTOMON = pWindow->m_vRealPosition.goal() - PWINDOWMONITOR->vecPosition;
Expand Down
4 changes: 2 additions & 2 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) {
}

for (auto& m : g_pCompositor->m_vMonitors)
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
m->activeWorkspace->getCurrentLayout()->recalculateMonitor(m->ID);

// Update the keyboard layout to the cfg'd one if this is not the first launch
if (!isFirstLaunch) {
Expand Down Expand Up @@ -909,7 +909,7 @@ std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::
// invalidate layouts if they changed
if (COMMAND == "monitor" || COMMAND.contains("gaps_") || COMMAND.starts_with("dwindle:") || COMMAND.starts_with("master:")) {
for (auto& m : g_pCompositor->m_vMonitors)
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
m->activeWorkspace->getCurrentLayout()->recalculateMonitor(m->ID);
}

// Update window border colors
Expand Down
6 changes: 3 additions & 3 deletions src/debug/HyprCtl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) {
if (COMMAND.contains("decoration:") || COMMAND.contains("border") || COMMAND == "workspace" || COMMAND.contains("zoom_factor") || COMMAND == "source") {
for (auto& m : g_pCompositor->m_vMonitors) {
g_pHyprRenderer->damageMonitor(m.get());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
m->activeWorkspace->getCurrentLayout()->recalculateMonitor(m->ID);
}
}

Expand Down Expand Up @@ -1296,7 +1296,7 @@ std::string dispatchSetProp(eHyprCtlOutputFormat format, std::string request) {
}

for (auto& m : g_pCompositor->m_vMonitors)
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
m->activeWorkspace->getCurrentLayout()->recalculateMonitor(m->ID);

return "ok";
}
Expand Down Expand Up @@ -1722,7 +1722,7 @@ std::string CHyprCtl::getReply(std::string request) {

for (auto& m : g_pCompositor->m_vMonitors) {
g_pHyprRenderer->damageMonitor(m.get());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID);
m->activeWorkspace->getCurrentLayout()->recalculateMonitor(m->ID);
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/desktop/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ void CWindow::addWindowDeco(std::unique_ptr<IHyprWindowDecoration> deco) {
m_dWindowDecorations.emplace_back(std::move(deco));
g_pDecorationPositioner->forceRecalcFor(m_pSelf.lock());
updateWindowDecos();
g_pLayoutManager->getCurrentLayout()->recalculateWindow(m_pSelf.lock());
m_pWorkspace->getCurrentLayout()->recalculateWindow(m_pSelf.lock());
}

void CWindow::removeWindowDeco(IHyprWindowDecoration* deco) {
m_vDecosToRemove.push_back(deco);
g_pDecorationPositioner->forceRecalcFor(m_pSelf.lock());
updateWindowDecos();
g_pLayoutManager->getCurrentLayout()->recalculateWindow(m_pSelf.lock());
m_pWorkspace->getCurrentLayout()->recalculateWindow(m_pSelf.lock());
}

void CWindow::uncacheWindowDecos() {
Expand Down Expand Up @@ -412,11 +412,11 @@ void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) {

g_pCompositor->updateWorkspaceWindows(OLDWORKSPACE->m_iID);
g_pCompositor->updateWorkspaceSpecialRenderData(OLDWORKSPACE->m_iID);
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(OLDWORKSPACE->m_iMonitorID);
OLDWORKSPACE->getCurrentLayout()->recalculateMonitor(OLDWORKSPACE->m_iMonitorID);

g_pCompositor->updateWorkspaceWindows(workspaceID());
g_pCompositor->updateWorkspaceSpecialRenderData(workspaceID());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
m_pWorkspace->getCurrentLayout()->recalculateMonitor(m_iMonitorID);

g_pCompositor->updateAllWindowsAnimatedDecorationValues();

Expand Down Expand Up @@ -523,7 +523,7 @@ void CWindow::onUnmap() {

g_pCompositor->updateWorkspaceWindows(workspaceID());
g_pCompositor->updateWorkspaceSpecialRenderData(workspaceID());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
m_pWorkspace->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
g_pCompositor->updateAllWindowsAnimatedDecorationValues();

m_pWorkspace.reset();
Expand Down Expand Up @@ -819,7 +819,7 @@ void CWindow::updateDynamicRules() {

EMIT_HOOK_EVENT("windowUpdateRules", m_pSelf.lock());

g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
m_pWorkspace->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
}

// check if the point is "hidden" under a rounded corner of the window
Expand Down Expand Up @@ -886,7 +886,7 @@ void CWindow::createGroup() {

g_pCompositor->updateWorkspaceWindows(workspaceID());
g_pCompositor->updateWorkspaceSpecialRenderData(workspaceID());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
m_pWorkspace->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
g_pCompositor->updateAllWindowsAnimatedDecorationValues();

g_pEventManager->postEvent(SHyprIPCEvent{"togglegroup", std::format("1,{:x}", (uintptr_t)this)});
Expand All @@ -904,7 +904,7 @@ void CWindow::destroyGroup() {
updateWindowDecos();
g_pCompositor->updateWorkspaceWindows(workspaceID());
g_pCompositor->updateWorkspaceSpecialRenderData(workspaceID());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
m_pWorkspace->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
g_pCompositor->updateAllWindowsAnimatedDecorationValues();

g_pEventManager->postEvent(SHyprIPCEvent{"togglegroup", std::format("0,{:x}", (uintptr_t)this)});
Expand All @@ -926,21 +926,21 @@ void CWindow::destroyGroup() {

for (auto& w : members) {
if (w->m_sGroupData.head)
g_pLayoutManager->getCurrentLayout()->onWindowRemoved(curr);
m_pWorkspace->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);
m_pWorkspace->getCurrentLayout()->onWindowCreated(w);
w->updateWindowDecos();
}
g_pKeybindManager->m_bGroupsLocked = GROUPSLOCKEDPREV;

g_pCompositor->updateWorkspaceWindows(workspaceID());
g_pCompositor->updateWorkspaceSpecialRenderData(workspaceID());
g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
m_pWorkspace->getCurrentLayout()->recalculateMonitor(m_iMonitorID);
g_pCompositor->updateAllWindowsAnimatedDecorationValues();

if (!addresses.empty())
Expand Down Expand Up @@ -1028,7 +1028,7 @@ void CWindow::setGroupCurrent(PHLWINDOW pWindow) {
PCURRENT->setHidden(true);
pWindow->setHidden(false); // can remove m_pLastWindow

g_pLayoutManager->getCurrentLayout()->replaceWindowDataWith(PCURRENT, pWindow);
m_pWorkspace->getCurrentLayout()->replaceWindowDataWith(PCURRENT, pWindow);

if (PCURRENT->m_bIsFloating) {
pWindow->m_vRealPosition.setValueAndWarp(PWINDOWPOS);
Expand Down
5 changes: 5 additions & 0 deletions src/desktop/Workspace.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Workspace.hpp"
#include "../Compositor.hpp"
#include "../config/ConfigValue.hpp"
#include "managers/LayoutManager.hpp"

#include <hyprutils/string/String.hpp>
using namespace Hyprutils::String;
Expand Down Expand Up @@ -508,3 +509,7 @@ void CWorkspace::markInert() {
bool CWorkspace::inert() {
return m_bInert;
}

IHyprLayout* CWorkspace::getCurrentLayout() {
return g_pLayoutManager->getCurrentGlobalLayout();
}
21 changes: 12 additions & 9 deletions src/desktop/Workspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <string>
#include "../defines.hpp"
#include "DesktopTypes.hpp"
#include "../layout/IHyprLayout.hpp"

enum eFullscreenMode : int8_t {
FULLSCREEN_INVALID = -1,
Expand Down Expand Up @@ -63,21 +64,23 @@ class CWorkspace {
bool m_bPersistent = false;

// Inert: destroyed and invalid. If this is true, release the ptr you have.
bool inert();
bool inert();

void startAnim(bool in, bool left, bool instant = false);
void setActive(bool on);
void startAnim(bool in, bool left, bool instant = false);
void setActive(bool on);

void moveToMonitor(const int&);
void moveToMonitor(const int&);

PHLWINDOW getLastFocusedWindow();
void rememberPrevWorkspace(const PHLWORKSPACE& prevWorkspace);
PHLWINDOW getLastFocusedWindow();
void rememberPrevWorkspace(const PHLWORKSPACE& prevWorkspace);

std::string getConfigName();
std::string getConfigName();

bool matchesStaticSelector(const std::string& selector);
bool matchesStaticSelector(const std::string& selector);

void markInert();
void markInert();

IHyprLayout* getCurrentLayout();

private:
void init(PHLWORKSPACE self);
Expand Down
20 changes: 10 additions & 10 deletions src/events/Windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
PWINDOW->updateSpecialRenderData();

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

// size and move rules
Expand Down Expand Up @@ -450,7 +450,7 @@ void Events::listener_mapWindow(void* owner, void* data) {

g_pCompositor->changeWindowZOrder(PWINDOW, true);
} else {
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW);
PWINDOW->m_pWorkspace->getCurrentLayout()->onWindowCreated(PWINDOW);

// Set the pseudo size here too so that it doesnt end up being 0x0
PWINDOW->m_vPseudoSize = PWINDOW->m_vRealSize.goal() - Vector2D(10, 10);
Expand Down Expand Up @@ -532,11 +532,11 @@ void Events::listener_mapWindow(void* owner, void* data) {
// swallow
PWINDOW->m_pSwallowed = SWALLOWER;

g_pLayoutManager->getCurrentLayout()->onWindowRemoved(SWALLOWER);
SWALLOWER->m_pWorkspace->getCurrentLayout()->onWindowRemoved(SWALLOWER);

SWALLOWER->setHidden(true);

g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PWINDOW->m_iMonitorID);
PWINDOW->m_pWorkspace->getCurrentLayout()->recalculateMonitor(PWINDOW->m_iMonitorID);
}
}

Expand All @@ -551,7 +551,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
// apply data from default decos. Borders, shadows.
g_pDecorationPositioner->forceRecalcFor(PWINDOW);
PWINDOW->updateWindowDecos();
g_pLayoutManager->getCurrentLayout()->recalculateWindow(PWINDOW);
PWINDOW->m_pWorkspace->getCurrentLayout()->recalculateWindow(PWINDOW);

// do animations
g_pAnimationManager->onWindowPostCreateClose(PWINDOW, false);
Expand Down Expand Up @@ -614,7 +614,7 @@ void Events::listener_unmapWindow(void* owner, void* data) {
// swallowing
if (valid(PWINDOW->m_pSwallowed)) {
PWINDOW->m_pSwallowed->setHidden(false);
g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW->m_pSwallowed.lock());
PWINDOW->m_pWorkspace->getCurrentLayout()->onWindowCreated(PWINDOW->m_pSwallowed.lock());
PWINDOW->m_pSwallowed.reset();
}

Expand All @@ -634,14 +634,14 @@ void Events::listener_unmapWindow(void* owner, void* data) {
if (PWORKSPACE->m_bHasFullscreenWindow && PWINDOW->m_bIsFullscreen)
PWORKSPACE->m_bHasFullscreenWindow = false;

g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
PWORKSPACE->getCurrentLayout()->onWindowRemoved(PWINDOW);

// do this after onWindowRemoved because otherwise it'll think the window is invalid
PWINDOW->m_bIsMapped = false;

// refocus on a new window if needed
if (wasLastWindow) {
const auto PWINDOWCANDIDATE = g_pLayoutManager->getCurrentLayout()->getNextWindowCandidate(PWINDOW);
const auto PWINDOWCANDIDATE = PWORKSPACE->getCurrentLayout()->getNextWindowCandidate(PWINDOW);

Debug::log(LOG, "On closed window, new focused candidate is {}", PWINDOWCANDIDATE);

Expand Down Expand Up @@ -690,7 +690,7 @@ void Events::listener_commitWindow(void* owner, void* data) {
PHLWINDOW PWINDOW = ((CWindow*)owner)->m_pSelf.lock();

if (!PWINDOW->m_bIsX11 && PWINDOW->m_pXDGSurface->initialCommit) {
Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(PWINDOW);
Vector2D predSize = PWINDOW->m_pWorkspace->getCurrentLayout()->predictSizeForNewWindow(PWINDOW);

Debug::log(LOG, "Layout predicts size {} for {}", predSize, PWINDOW);

Expand Down Expand Up @@ -775,7 +775,7 @@ void Events::listener_destroyWindow(void* owner, void* data) {

PWINDOW->listeners = {};

g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW);
PWINDOW->m_pWorkspace->getCurrentLayout()->onWindowRemoved(PWINDOW);

PWINDOW->m_bReadyToDelete = true;

Expand Down
Loading
Loading