diff --git a/.gitignore b/.gitignore index 46a1a38..2a09b32 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /result /build -/.vscode \ No newline at end of file +/.vscode +/.cache \ No newline at end of file diff --git a/src/GridLayout.cpp b/src/GridLayout.cpp index c548284..5920e07 100644 --- a/src/GridLayout.cpp +++ b/src/GridLayout.cpp @@ -42,6 +42,11 @@ void GridLayout::onWindowCreatedTiling(CWindow *pWindow, eDirection direction) const auto pWindowOriWorkspace = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + if(isFromOnEnable) { + pNode->isInOldLayout = true; + isFromOnEnable = false; + } + pNode->workspaceID = pWindow->m_iWorkspaceID; // encapsulate window objects as node objects to bind more properties pNode->pWindow = pWindow; pNode->workspaceName = pWindowOriWorkspace->m_szName; @@ -82,8 +87,51 @@ void GridLayout::onWindowCreatedTiling(CWindow *pWindow, eDirection direction) recalculateMonitor(pWindow->m_iMonitorID); } +void GridLayout::changeLayout(std::string layout) { + for (size_t i = 0; i < g_pLayoutManager->m_vLayouts.size(); ++i) { + if (g_pLayoutManager->m_vLayouts[i].first == layout) { + if (i == (size_t)g_pLayoutManager->m_iCurrentLayoutID) + return; + g_pLayoutManager->m_iCurrentLayoutID = i; + return; + } + } +} + +void GridLayout::removeOldLayoutData(CWindow *pWindow) { + + std::string *configLayoutName = &HyprlandAPI::getConfigValue(PHANDLE, "general:layout")->strValue; + changeLayout(*configLayoutName); + hycov_log(LOG,"remove data of old layout:{}",*configLayoutName); + + if(*configLayoutName == "dwindle") { + g_pHyprDwindleLayout_recalculateMonitor->hook(); + g_pHyprDwindleLayout_recalculateWindow->hook(); + g_pSDwindleNodeData_recalcSizePosRecursive->hook(); + + g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); + + g_pSDwindleNodeData_recalcSizePosRecursive->unhook(); + g_pHyprDwindleLayout_recalculateWindow->unhook(); + g_pHyprDwindleLayout_recalculateMonitor->unhook(); + } else if(*configLayoutName == "master") { + g_pHyprMasterLayout_recalculateMonitor->hook(); + + g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); + + g_pHyprMasterLayout_recalculateMonitor->unhook(); + } else { + hycov_log(ERR,"unknow old layout:{}",*configLayoutName); + g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); + } + + changeLayout("grid"); +} + void GridLayout::onWindowRemovedTiling(CWindow *pWindow) { + removeOldLayoutData(pWindow); + const auto pNode = getNodeFromWindow(pWindow); SGridNodeData lastNode; @@ -356,8 +404,11 @@ void GridLayout::moveWindowToSourceWorkspace() // it will exec once when change layout enable void GridLayout::onEnable() { + for (auto &w : g_pCompositor->m_vWindows) { + isFromOnEnable = true; + CWindow *pWindow = w.get(); if (pWindow->isHidden() || !pWindow->m_bIsMapped || pWindow->m_bFadingOut || g_pCompositor->isWorkspaceSpecial(pWindow->m_iWorkspaceID)) diff --git a/src/GridLayout.hpp b/src/GridLayout.hpp index 3efce14..4cee1cc 100644 --- a/src/GridLayout.hpp +++ b/src/GridLayout.hpp @@ -20,6 +20,7 @@ struct SGridNodeData bool ovbk_windowIsWithDecorate; bool ovbk_windowIsWithRounding; bool ovbk_windowIsWithShadow; + bool isInOldLayout = false; int workspaceID = -1; @@ -57,5 +58,9 @@ class GridLayout : public IHyprLayout std::list m_lGridNodesData; void moveWindowToSourceWorkspace(); void changeToActivceSourceWorkspace(); + void removeOldLayoutData(CWindow *pWindow); + void changeLayout(std::string layout); + + bool isFromOnEnable = false; private: }; \ No newline at end of file diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp index 4c27e8e..38394f4 100644 --- a/src/dispatchers.cpp +++ b/src/dispatchers.cpp @@ -4,6 +4,28 @@ static const std::string overviewWorksapceName = "OVERVIEW"; static std::string workspaceNameBackup; static int workspaceIdBackup; +void recalculateAllMonitor() { + for (auto &m : g_pCompositor->m_vMonitors) { + CMonitor *pMonitor = m.get(); + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitor->ID); + } +} + +void switchToLayoutWithoutReleaseData(std::string layout) { + for (size_t i = 0; i < g_pLayoutManager->m_vLayouts.size(); ++i) { + if (g_pLayoutManager->m_vLayouts[i].first == layout) { + if (i == (size_t)g_pLayoutManager->m_iCurrentLayoutID) + return; + + // getCurrentLayout()->onDisable(); + g_pLayoutManager->m_iCurrentLayoutID = i; + // getCurrentLayout()->onEnable(); + return; + } + } + hycov_log(ERR, "Unknown layout!"); +} + bool want_auto_fullscren(CWindow *pWindow) { int nodeNumInTargetWorkspace = 1; @@ -309,7 +331,10 @@ void dispatch_enteroverview(std::string arg) } //enter overview layout - g_pLayoutManager->switchToLayout("grid"); + // g_pLayoutManager->switchToLayout("grid"); + switchToLayoutWithoutReleaseData("grid"); + g_pLayoutManager->getCurrentLayout()->onEnable(); + //change workspace name to OVERVIEW pActiveMonitor = g_pCompositor->m_pLastMonitor; @@ -431,7 +456,10 @@ void dispatch_leaveoverview(std::string arg) //exit overview layout,go back to old layout CWindow *pActiveWindow = g_pCompositor->m_pLastWindow; g_pCompositor->focusWindow(nullptr); - g_pLayoutManager->switchToLayout(*configLayoutName); + // g_pLayoutManager->switchToLayout(*configLayoutName); + g_pLayoutManager->getCurrentLayout()->onDisable(); + switchToLayoutWithoutReleaseData(*configLayoutName); + recalculateAllMonitor(); //Preserve window focus if(pActiveWindow){ @@ -456,13 +484,18 @@ void dispatch_leaveoverview(std::string arg) if (!g_pCompositor->m_pLastWindow) { continue; } - + if (n.pWindow != g_pCompositor->m_pLastWindow && n.pWindow->m_iWorkspaceID == g_pCompositor->m_pLastWindow->m_iWorkspaceID) { continue; } g_pCompositor->setWindowFullscreen(n.pWindow, true, n.ovbk_windowFullscreenMode ); } + + // if client not in old layout,create tiling of the client + if (!n.isInOldLayout) { + g_pLayoutManager->getCurrentLayout()->onWindowCreatedTiling(n.pWindow); + } } //clean overview layout node date diff --git a/src/dispatchers.hpp b/src/dispatchers.hpp index 70bdb51..2ced8a1 100644 --- a/src/dispatchers.hpp +++ b/src/dispatchers.hpp @@ -13,6 +13,8 @@ bool isDirection(const std::string& arg); CWindow *direction_select(std::string arg); CWindow *get_circle_next_window (std::string arg); void warpcursor_and_focus_to_window(CWindow *pWindow); +void switchToLayoutWithoutReleaseData(std::string layout); +void recalculateAllMonitor(); void dispatch_circle(std::string arg); void dispatch_focusdir(std::string arg); diff --git a/src/globaleventhook.cpp b/src/globaleventhook.cpp index 31ba3bd..3e69250 100644 --- a/src/globaleventhook.cpp +++ b/src/globaleventhook.cpp @@ -236,6 +236,24 @@ static void hkFullscreenActive(std::string args) { } } +void hkHyprDwindleLayout_recalculateMonitor(void* thisptr,const int& ID) { + ; +} + +void hkHyprMasterLayout_recalculateMonitor(void* thisptr,const int& ID) { + ; +} + +void hkHyprDwindleLayout_recalculateWindow(void* thisptr,CWindow* pWindow) { + ; +} + +void hkSDwindleNodeData_recalcSizePosRecursive(void* thisptr,bool force, bool horizontalOverride, bool verticalOverride) { + ; +} + + + void registerGlobalEventHook() { g_isInHotArea = false; @@ -267,6 +285,13 @@ void registerGlobalEventHook() // hook function of keypress g_pOnKeyboardKeyHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CInputManager::onKeyboardKey, (void*)&hkOnKeyboardKey); + // layotu reculate + g_pHyprDwindleLayout_recalculateMonitor = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprDwindleLayout::recalculateMonitor, (void*)&hkHyprDwindleLayout_recalculateMonitor); + g_pHyprMasterLayout_recalculateMonitor = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprMasterLayout::recalculateMonitor, (void*)&hkHyprMasterLayout_recalculateMonitor); + g_pHyprDwindleLayout_recalculateWindow = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprDwindleLayout::recalculateWindow, (void*)&hkHyprDwindleLayout_recalculateWindow); + g_pSDwindleNodeData_recalcSizePosRecursive = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&SDwindleNodeData::recalcSizePosRecursive, (void*)&hkSDwindleNodeData_recalcSizePosRecursive); + + //create private function hook // hook function of changeworkspace diff --git a/src/globals.hpp b/src/globals.hpp index a5d47a6..da70ca6 100644 --- a/src/globals.hpp +++ b/src/globals.hpp @@ -45,6 +45,10 @@ inline CFunctionHook* g_pSpawnHook = nullptr; inline CFunctionHook* g_pStartAnimHook = nullptr; inline CFunctionHook* g_pFullscreenActiveHook = nullptr; inline CFunctionHook* g_pOnKeyboardKeyHook = nullptr; +inline CFunctionHook* g_pHyprDwindleLayout_recalculateMonitor = nullptr; +inline CFunctionHook* g_pHyprMasterLayout_recalculateMonitor = nullptr; +inline CFunctionHook* g_pHyprDwindleLayout_recalculateWindow = nullptr; +inline CFunctionHook* g_pSDwindleNodeData_recalcSizePosRecursive = nullptr; inline void errorNotif() {