diff --git a/README.md b/README.md index 3b4ebba..6f24861 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,8 @@ A Hyprland overview mode plugin, a new tiling WM workflow. > [!NOTE] -> Sorry guys, because I've been using my own Hyprland branch and the features have been sufficient for me, -> this plugin change started to not work for my Hyprland branch, so I decided to stop it. -> Please fork freely. +> Sorry guys, because I've been using my own Hyprland branch and the features have been sufficient for me. +> If hyprland comes up with features that surprise me, maybe I'll come back, but I don't have time to keep track of his every commit right now, so I decided to stop it temporarily. ### What can it do? - Hycov can tile all of your windows in a single workspace via grid layout. diff --git a/src/OvGridLayout.cpp b/src/OvGridLayout.cpp index 0ad775f..1acac8d 100644 --- a/src/OvGridLayout.cpp +++ b/src/OvGridLayout.cpp @@ -70,7 +70,6 @@ void OvGridLayout::onWindowCreatedTiling(CWindow *pWindow, eDirection direction) pTargetMonitor = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); } - const auto pNode = &m_lOvGridNodesData.emplace_back(); // make a new node in list back const auto pActiveWorkspace = g_pCompositor->getWorkspaceByID(pTargetMonitor->activeWorkspace); @@ -90,7 +89,6 @@ void OvGridLayout::onWindowCreatedTiling(CWindow *pWindow, eDirection direction) pNode->pGroupNextWindow = pWindow->m_sGroupData.pNextWindow; } - pNode->workspaceID = pWindow->m_iWorkspaceID; // encapsulate window objects as node objects to bind more properties pNode->pWindow = pWindow; pNode->workspaceName = pWindowOriWorkspace->m_szName; @@ -136,30 +134,31 @@ void OvGridLayout::onWindowCreatedTiling(CWindow *pWindow, eDirection direction) void OvGridLayout::removeOldLayoutData(CWindow *pWindow) { - switchToLayoutWithoutReleaseData(g_hycov_configLayoutName); - hycov_log(LOG,"remove data of old layout:{}",g_hycov_configLayoutName); + std::string *configLayoutName = &g_hycov_configLayoutName; + switchToLayoutWithoutReleaseData(*configLayoutName); + hycov_log(LOG,"remove data of old layout:{}",*configLayoutName); - if(g_hycov_configLayoutName == "dwindle") { + if(*configLayoutName == "dwindle") { // disable render client of old layout - g_hycov_pHyprDwindleLayout_recalculateMonitor->hook(); - g_hycov_pHyprDwindleLayout_recalculateWindow->hook(); - g_hycov_pSDwindleNodeData_recalcSizePosRecursive->hook(); + g_hycov_pHyprDwindleLayout_recalculateMonitorHook->hook(); + g_hycov_pHyprDwindleLayout_recalculateWindowHook->hook(); + g_hycov_pSDwindleNodeData_recalcSizePosRecursiveHook->hook(); // only remove data,not render anything,becaust still in overview g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); - g_hycov_pSDwindleNodeData_recalcSizePosRecursive->unhook(); - g_hycov_pHyprDwindleLayout_recalculateWindow->unhook(); - g_hycov_pHyprDwindleLayout_recalculateMonitor->unhook(); - } else if(g_hycov_configLayoutName == "master") { - g_hycov_pHyprMasterLayout_recalculateMonitor->hook(); + g_hycov_pSDwindleNodeData_recalcSizePosRecursiveHook->unhook(); + g_hycov_pHyprDwindleLayout_recalculateWindowHook->unhook(); + g_hycov_pHyprDwindleLayout_recalculateMonitorHook->unhook(); + } else if(*configLayoutName == "master") { + g_hycov_pHyprMasterLayout_recalculateMonitorHook->hook(); g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); - g_hycov_pHyprMasterLayout_recalculateMonitor->unhook(); + g_hycov_pHyprMasterLayout_recalculateMonitorHook->unhook(); } else { // may be not support other layout - hycov_log(ERR,"unknow old layout:{}",g_hycov_configLayoutName); + hycov_log(ERR,"unknow old layout:{}",*configLayoutName); g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); } @@ -183,7 +182,6 @@ void OvGridLayout::onWindowRemovedTiling(CWindow *pWindow) if(pNode->isGroupActive && pNode->pGroupPrevWindow && pNode->pGroupPrevWindow != pNode->pWindow) { pNode->pWindow = pNode->pGroupPrevWindow; pNode->pGroupPrevWindow = pNode->pGroupPrevWindow->getGroupPrevious(); - pNode->pGroupNextWindow = pNode->pGroupPrevWindow->m_sGroupData.pNextWindow; pNode->pWindow->m_iWorkspaceID = pNode->workspaceID; applyNodeDataToWindow(pNode); pNode->isInOldLayout = false; @@ -230,6 +228,10 @@ void OvGridLayout::calculateWorkspace(const int &ws) return; } + static const auto *PBORDERSIZE = &g_hycov_bordersize; + static const auto *GAPPO = &g_hycov_overview_gappo; + static const auto *GAPPI = &g_hycov_overview_gappi; + /* m is region that is moniotr, w is region that is monitor but don not contain bar @@ -263,10 +265,10 @@ void OvGridLayout::calculateWorkspace(const int &ws) if (NODECOUNT == 1) { pNode = pTempNodes[0]; - cw = (w_width - 2 * (g_hycov_overview_gappo)) * 0.7; - ch = (w_height - 2 * (g_hycov_overview_gappo)) * 0.8; + cw = (w_width - 2 * (*GAPPO)) * 0.7; + ch = (w_height - 2 * (*GAPPO)) * 0.8; resizeNodeSizePos(pNode, w_x + (int)((m_width - cw) / 2), w_y + (int)((w_height - ch) / 2), - cw - 2 * (g_hycov_bordersize), ch - 2 * (g_hycov_bordersize)); + cw - 2 * (*PBORDERSIZE), ch - 2 * (*PBORDERSIZE)); delete[] pTempNodes; return; } @@ -275,12 +277,12 @@ void OvGridLayout::calculateWorkspace(const int &ws) if (NODECOUNT == 2) { pNode = pTempNodes[0]; - cw = (w_width - 2 * (g_hycov_overview_gappo) - (g_hycov_overview_gappi)) / 2; - ch = (w_height - 2 * (g_hycov_overview_gappo)) * 0.65; - resizeNodeSizePos(pNode, m_x + cw + (g_hycov_overview_gappo) + (g_hycov_overview_gappi), m_y + (m_height - ch) / 2 + (g_hycov_overview_gappo), - cw - 2 * (g_hycov_bordersize), ch - 2 * (g_hycov_bordersize)); - resizeNodeSizePos(pTempNodes[1], m_x + (g_hycov_overview_gappo), m_y + (m_height - ch) / 2 + (g_hycov_overview_gappo), - cw - 2 * (g_hycov_bordersize), ch - 2 * (g_hycov_bordersize)); + cw = (w_width - 2 * (*GAPPO) - (*GAPPI)) / 2; + ch = (w_height - 2 * (*GAPPO)) * 0.65; + resizeNodeSizePos(pNode, m_x + cw + (*GAPPO) + (*GAPPI), m_y + (m_height - ch) / 2 + (*GAPPO), + cw - 2 * (*PBORDERSIZE), ch - 2 * (*PBORDERSIZE)); + resizeNodeSizePos(pTempNodes[1], m_x + (*GAPPO), m_y + (m_height - ch) / 2 + (*GAPPO), + cw - 2 * (*PBORDERSIZE), ch - 2 * (*PBORDERSIZE)); delete[] pTempNodes; return; } @@ -298,24 +300,24 @@ void OvGridLayout::calculateWorkspace(const int &ws) //Calculate the width and height of the layout area based on //the number of rows and columns - ch = (int)((w_height - 2 * (g_hycov_overview_gappo) - (rows - 1) * (g_hycov_overview_gappi)) / rows); - cw = (int)((w_width - 2 * (g_hycov_overview_gappo) - (cols - 1) * (g_hycov_overview_gappi)) / cols); + ch = (int)((w_height - 2 * (*GAPPO) - (rows - 1) * (*GAPPI)) / rows); + cw = (int)((w_width - 2 * (*GAPPO) - (cols - 1) * (*GAPPI)) / cols); //If the nodes do not exactly fill all rows, //the number of Windows in the unfilled rows is overcols = NODECOUNT % cols; if (overcols) - dx = (int)((w_width - overcols * cw - (overcols - 1) * (g_hycov_overview_gappi)) / 2) - (g_hycov_overview_gappo); + dx = (int)((w_width - overcols * cw - (overcols - 1) * (*GAPPI)) / 2) - (*GAPPO); for (i = 0, pNode = pTempNodes[0]; pNode; pNode = pTempNodes[i + 1], i++) { - cx = w_x + (i % cols) * (cw + (g_hycov_overview_gappi)); - cy = w_y + (int)(i / cols) * (ch + (g_hycov_overview_gappi)); + cx = w_x + (i % cols) * (cw + (*GAPPI)); + cy = w_y + (int)(i / cols) * (ch + (*GAPPI)); if (overcols && i >= (NODECOUNT-overcols)) { cx += dx; } - resizeNodeSizePos(pNode, cx + (g_hycov_overview_gappo), cy + (g_hycov_overview_gappo), cw - 2 * (g_hycov_bordersize), ch - 2 * (g_hycov_bordersize)); + resizeNodeSizePos(pNode, cx + (*GAPPO), cy + (*GAPPO), cw - 2 * (*PBORDERSIZE), ch - 2 * (*PBORDERSIZE)); } delete[] pTempNodes; } @@ -343,8 +345,6 @@ void OvGridLayout::applyNodeDataToWindow(SOvGridNodeData *pNode) const auto pWindow = pNode->pWindow; - const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)); - pWindow->updateSpecialRenderData(); // force disable decorate and shadow // pWindow->m_sSpecialRenderData.decorate = false; // pWindow->m_sSpecialRenderData.shadow = false; @@ -352,7 +352,6 @@ void OvGridLayout::applyNodeDataToWindow(SOvGridNodeData *pNode) // force enable bordear and rounding pWindow->m_sSpecialRenderData.border = true; pWindow->m_sSpecialRenderData.rounding = true; - pWindow->m_sSpecialRenderData.borderSize = WORKSPACERULE.borderSize.value_or(-1); pWindow->m_vSize = pNode->size; pWindow->m_vPosition = pNode->position; diff --git a/src/OvGridLayout.hpp b/src/OvGridLayout.hpp index 3333847..9863515 100644 --- a/src/OvGridLayout.hpp +++ b/src/OvGridLayout.hpp @@ -25,7 +25,7 @@ struct SOvGridNodeData bool isGroupActive = false; CWindow* pGroupPrevWindow = nullptr; CWindow* pGroupNextWindow = nullptr; - + int workspaceID = -1; bool operator==(const SOvGridNodeData &rhs) const diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp index adafdef..daf2deb 100644 --- a/src/dispatchers.cpp +++ b/src/dispatchers.cpp @@ -111,7 +111,7 @@ CWindow *direction_select(std::string arg){ auto *pMonitor = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - if (!((isCrossMonitor(arg) && pWindow->m_iWorkspaceID == pMonitor->activeWorkspace ) || pTempClient->m_iWorkspaceID == pWindow->m_iWorkspaceID)) { + if (!((isCrossMonitor(arg) && pWindow->m_iMonitorID != pTempClient->m_iMonitorID && !g_pCompositor->isWorkspaceSpecial(pTempClient->m_iWorkspaceID) && pWindow->m_iWorkspaceID == pMonitor->activeWorkspace ) || pTempClient->m_iWorkspaceID == pWindow->m_iWorkspaceID)) { continue; } @@ -378,6 +378,11 @@ void dispatch_enteroverview(std::string arg) } } + //enter overview layout + // g_pLayoutManager->switchToLayout("ovgrid"); + switchToLayoutWithoutReleaseData("ovgrid"); + g_pLayoutManager->getCurrentLayout()->onEnable(); + //change workspace name to OVERVIEW pActiveMonitor = g_pCompositor->m_pLastMonitor; @@ -386,13 +391,6 @@ void dispatch_enteroverview(std::string arg) workspaceIdBackup = pActiveWorkspace->m_iID; g_pCompositor->renameWorkspace(pActiveMonitor->activeWorkspace,overviewWorksapceName); - - //enter overview layout - // g_pLayoutManager->switchToLayout("ovgrid"); - hycov_log(LOG,"change to layout:ovgrid"); - switchToLayoutWithoutReleaseData("ovgrid"); - g_pLayoutManager->getCurrentLayout()->onEnable(); - //Preserve window focus if(pActiveWindow){ g_pCompositor->focusWindow(pActiveWindow); //restore the focus to before active window @@ -418,7 +416,9 @@ void dispatch_enteroverview(std::string arg) g_hycov_pSpawnHook->hook(); } - g_hycov_pCKeybindManager_changeGroupActive->hook(); + g_hycov_pCKeybindManager_changeGroupActiveHook->hook(); + g_hycov_pCKeybindManager_toggleGroupHook->hook(); + g_hycov_pCKeybindManager_moveOutOfGroupHook->hook(); return; } @@ -433,6 +433,9 @@ void dispatch_leaveoverview(std::string arg) if(pMonitor->specialWorkspaceID != 0) pMonitor->setSpecialWorkspace(nullptr); + // get default layout + std::string *configLayoutName = &g_hycov_configLayoutName; + hycov_log(LOG,"leave overview"); g_hycov_isOverView = false; //mark exiting overview mode @@ -452,12 +455,14 @@ void dispatch_leaveoverview(std::string arg) g_hycov_pSpawnHook->unhook(); } - g_hycov_pCKeybindManager_changeGroupActive->unhook(); + g_hycov_pCKeybindManager_changeGroupActiveHook->unhook(); + g_hycov_pCKeybindManager_toggleGroupHook->unhook(); + g_hycov_pCKeybindManager_moveOutOfGroupHook->unhook(); // if no clients, just exit overview, don't restore client's state if (g_hycov_OvGridLayout->m_lOvGridNodesData.empty()) { - switchToLayoutWithoutReleaseData(g_hycov_configLayoutName); + switchToLayoutWithoutReleaseData(*configLayoutName); recalculateAllMonitor(); g_hycov_OvGridLayout->m_lOvGridNodesData.clear(); g_hycov_isOverViewExiting = false; @@ -512,22 +517,21 @@ void dispatch_leaveoverview(std::string arg) n.isInOldLayout = false; } else { g_pXWaylandManager->setWindowSize(n.pWindow, calcSize); - } + } // restore active window in group if(n.isGroupActive) { n.pWindow->setGroupCurrent(n.pWindow); } - } } //exit overview layout,go back to old layout CWindow *pActiveWindow = g_pCompositor->m_pLastWindow; g_pCompositor->focusWindow(nullptr); - // g_pLayoutManager->switchToLayout(g_hycov_configLayoutName); + // g_pLayoutManager->switchToLayout(*configLayoutName); // g_pLayoutManager->getCurrentLayout()->onDisable(); - switchToLayoutWithoutReleaseData(g_hycov_configLayoutName); + switchToLayoutWithoutReleaseData(*configLayoutName); recalculateAllMonitor(); //Preserve window focus @@ -573,7 +577,6 @@ void dispatch_leaveoverview(std::string arg) hycov_log(LOG,"create tiling window in old layout,window:{},workspace:{},inoldlayout:{}",n.pWindow,n.workspaceID,n.isInOldLayout); g_pLayoutManager->getCurrentLayout()->onWindowCreatedTiling(n.pWindow); } - // restore active window in group if(n.isGroupActive) { n.pWindow->setGroupCurrent(n.pWindow); diff --git a/src/globaleventhook.cpp b/src/globaleventhook.cpp index cb81a14..08ed6ab 100644 --- a/src/globaleventhook.cpp +++ b/src/globaleventhook.cpp @@ -172,7 +172,7 @@ static void hkCInputManager_onMouseButton(void* thisptr, wlr_pointer_button_even break; } } else { - (*(origCInputManager_onMouseButton)g_hycov_pCInputManager_onMouseButton->m_pOriginal)(thisptr, e); + (*(origCInputManager_onMouseButton)g_hycov_pCInputManager_onMouseButtonHook->m_pOriginal)(thisptr, e); } } @@ -288,6 +288,14 @@ void hkSDwindleNodeData_recalcSizePosRecursive(void* thisptr,bool force, bool ho ; } +void hkCKeybindManager_toggleGroup(std::string args) { + ; +} + +void hkCKeybindManager_moveOutOfGroup(std::string args) { + ; +} + void hkCKeybindManager_changeGroupActive(std::string args) { const auto PWINDOW = g_pCompositor->m_pLastWindow; CWindow *pTargetWindow; @@ -310,6 +318,8 @@ void hkCKeybindManager_changeGroupActive(std::string args) { pTargetWindow = pNode->pGroupPrevWindow; } + hycov_log(LOG,"changeGroupActive,pTargetWindow:{}",pTargetWindow); + if(pNode->isInOldLayout) { // if client is taken from the old layout g_hycov_OvGridLayout->removeOldLayoutData(PWINDOW); pNode->isInOldLayout = false; @@ -319,11 +329,12 @@ void hkCKeybindManager_changeGroupActive(std::string args) { pNode->pGroupPrevWindow = pTargetWindow->getGroupPrevious(); pNode->pGroupNextWindow = pTargetWindow->m_sGroupData.pNextWindow; pNode->pWindow->m_iWorkspaceID = pNode->workspaceID; - + PWINDOW->setGroupCurrent(pTargetWindow); g_hycov_OvGridLayout->applyNodeDataToWindow(pNode); } + void registerGlobalEventHook() { g_hycov_isInHotArea = false; @@ -356,18 +367,23 @@ void registerGlobalEventHook() g_hycov_pOnKeyboardKeyHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CInputManager::onKeyboardKey, (void*)&hkOnKeyboardKey); // layotu reculate - g_hycov_pHyprDwindleLayout_recalculateMonitor = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprDwindleLayout::recalculateMonitor, (void*)&hkHyprDwindleLayout_recalculateMonitor); - g_hycov_pHyprMasterLayout_recalculateMonitor = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprMasterLayout::recalculateMonitor, (void*)&hkHyprMasterLayout_recalculateMonitor); - g_hycov_pHyprDwindleLayout_recalculateWindow = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprDwindleLayout::recalculateWindow, (void*)&hkHyprDwindleLayout_recalculateWindow); - g_hycov_pSDwindleNodeData_recalcSizePosRecursive = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&SDwindleNodeData::recalcSizePosRecursive, (void*)&hkSDwindleNodeData_recalcSizePosRecursive); + g_hycov_pHyprDwindleLayout_recalculateMonitorHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprDwindleLayout::recalculateMonitor, (void*)&hkHyprDwindleLayout_recalculateMonitor); + g_hycov_pHyprMasterLayout_recalculateMonitorHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprMasterLayout::recalculateMonitor, (void*)&hkHyprMasterLayout_recalculateMonitor); + g_hycov_pHyprDwindleLayout_recalculateWindowHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CHyprDwindleLayout::recalculateWindow, (void*)&hkHyprDwindleLayout_recalculateWindow); + g_hycov_pSDwindleNodeData_recalcSizePosRecursiveHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&SDwindleNodeData::recalcSizePosRecursive, (void*)&hkSDwindleNodeData_recalcSizePosRecursive); - //mousebutton - g_hycov_pCInputManager_onMouseButton = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CInputManager::onMouseButton, (void*)&hkCInputManager_onMouseButton); - g_hycov_pCInputManager_onMouseButton->hook(); + //mousebutto + g_hycov_pCInputManager_onMouseButtonHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CInputManager::onMouseButton, (void*)&hkCInputManager_onMouseButton); + //changeGroupActive - g_hycov_pCKeybindManager_changeGroupActive = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CKeybindManager::changeGroupActive, (void*)&hkCKeybindManager_changeGroupActive); + g_hycov_pCKeybindManager_changeGroupActiveHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CKeybindManager::changeGroupActive, (void*)&hkCKeybindManager_changeGroupActive); + + //toggleGroup + g_hycov_pCKeybindManager_toggleGroupHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CKeybindManager::toggleGroup, (void*)&hkCKeybindManager_toggleGroup); + //moveOutOfGroup + g_hycov_pCKeybindManager_moveOutOfGroupHook = HyprlandAPI::createFunctionHook(PHANDLE, (void*)&CKeybindManager::moveOutOfGroup, (void*)&hkCKeybindManager_moveOutOfGroup); //create private function hook @@ -389,6 +405,7 @@ void registerGlobalEventHook() //register pEvent hook if(g_hycov_enable_hotarea){ + g_hycov_pCInputManager_onMouseButtonHook->hook(); HyprlandAPI::registerCallbackDynamic(PHANDLE, "mouseMove",[&](void* self, SCallbackInfo& info, std::any data) { mouseMoveHook(self, info, data); }); } diff --git a/src/globals.hpp b/src/globals.hpp index 4a0735b..cfb33b6 100644 --- a/src/globals.hpp +++ b/src/globals.hpp @@ -42,6 +42,7 @@ inline int g_hycov_overview_gappo; inline int g_hycov_overview_gappi; inline std::string g_hycov_configLayoutName; + inline bool g_hycov_isOverViewExiting; inline bool g_hycov_forece_display_all = false; inline bool g_hycov_forece_display_all_in_one_monitor = false; @@ -56,13 +57,14 @@ inline CFunctionHook* g_hycov_pSpawnHook = nullptr; inline CFunctionHook* g_hycov_pStartAnimHook = nullptr; inline CFunctionHook* g_hycov_pFullscreenActiveHook = nullptr; inline CFunctionHook* g_hycov_pOnKeyboardKeyHook = nullptr; -inline CFunctionHook* g_hycov_pHyprDwindleLayout_recalculateMonitor = nullptr; -inline CFunctionHook* g_hycov_pHyprMasterLayout_recalculateMonitor = nullptr; -inline CFunctionHook* g_hycov_pHyprDwindleLayout_recalculateWindow = nullptr; -inline CFunctionHook* g_hycov_pSDwindleNodeData_recalcSizePosRecursive = nullptr; -inline CFunctionHook* g_hycov_pCInputManager_onMouseButton = nullptr; -inline CFunctionHook* g_hycov_pCKeybindManager_changeGroupActive = nullptr; - +inline CFunctionHook* g_hycov_pHyprDwindleLayout_recalculateMonitorHook = nullptr; +inline CFunctionHook* g_hycov_pHyprMasterLayout_recalculateMonitorHook = nullptr; +inline CFunctionHook* g_hycov_pHyprDwindleLayout_recalculateWindowHook = nullptr; +inline CFunctionHook* g_hycov_pSDwindleNodeData_recalcSizePosRecursiveHook = nullptr; +inline CFunctionHook* g_hycov_pCInputManager_onMouseButtonHook = nullptr; +inline CFunctionHook* g_hycov_pCKeybindManager_changeGroupActiveHook = nullptr; +inline CFunctionHook* g_hycov_pCKeybindManager_toggleGroupHook = nullptr; +inline CFunctionHook* g_hycov_pCKeybindManager_moveOutOfGroupHook = nullptr; inline void errorNotif() {