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

Commit

Permalink
sync from myhycov
Browse files Browse the repository at this point in the history
1.disable togglegroup and moveoutgroup in ov
2.special ws not allow cross focus
3.fix:set pGroupNextWindow err when remove a windwo in group
  • Loading branch information
DreamMaoMao committed Feb 27, 2024
1 parent d2aacdf commit 7d48cff
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 71 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
67 changes: 33 additions & 34 deletions src/OvGridLayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -343,16 +345,13 @@ 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;

// 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;
Expand Down
2 changes: 1 addition & 1 deletion src/OvGridLayout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct SOvGridNodeData
bool isGroupActive = false;
CWindow* pGroupPrevWindow = nullptr;
CWindow* pGroupNextWindow = nullptr;

int workspaceID = -1;

bool operator==(const SOvGridNodeData &rhs) const
Expand Down
35 changes: 19 additions & 16 deletions src/dispatchers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
}
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
37 changes: 27 additions & 10 deletions src/globaleventhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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

Expand All @@ -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); });
}

Expand Down
Loading

0 comments on commit 7d48cff

Please sign in to comment.