Skip to content
This repository has been archived by the owner on Jul 9, 2024. It is now read-only.

Commit

Permalink
optimize:remeber pos and siez of tiled window
Browse files Browse the repository at this point in the history
  • Loading branch information
DreamMaoMao committed Jan 3, 2024
1 parent 1ce8dcd commit 2154b91
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 3 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/result
/build
/.vscode
/.vscode
/.cache
51 changes: 51 additions & 0 deletions src/GridLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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))
Expand Down
5 changes: 5 additions & 0 deletions src/GridLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct SGridNodeData
bool ovbk_windowIsWithDecorate;
bool ovbk_windowIsWithRounding;
bool ovbk_windowIsWithShadow;
bool isInOldLayout = false;

int workspaceID = -1;

Expand Down Expand Up @@ -57,5 +58,9 @@ class GridLayout : public IHyprLayout
std::list<SGridNodeData> m_lGridNodesData;
void moveWindowToSourceWorkspace();
void changeToActivceSourceWorkspace();
void removeOldLayoutData(CWindow *pWindow);
void changeLayout(std::string layout);

bool isFromOnEnable = false;
private:
};
37 changes: 35 additions & 2 deletions src/dispatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -463,6 +491,11 @@ void dispatch_leaveoverview(std::string arg)
}
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
Expand Down
2 changes: 2 additions & 0 deletions src/dispatchers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 25 additions & 0 deletions src/globaleventhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down

0 comments on commit 2154b91

Please sign in to comment.