mirror of
https://github.com/hyprwm/Hyprland
synced 2024-11-30 01:05:59 +01:00
Added the splitratio dispatcher
This commit is contained in:
parent
418e2d96ae
commit
87b8491294
7 changed files with 95 additions and 26 deletions
|
@ -74,3 +74,41 @@ std::string removeBeginEndSpacesTabs(std::string str) {
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getPlusMinusKeywordResult(std::string source, float relative) {
|
||||||
|
float result = INT_MAX;
|
||||||
|
|
||||||
|
if (source.find_first_of("+") == 0) {
|
||||||
|
try {
|
||||||
|
if (source.find('.') != std::string::npos)
|
||||||
|
result = relative + std::stof(source.substr(1));
|
||||||
|
else
|
||||||
|
result = relative + std::stoi(source.substr(1));
|
||||||
|
} catch (...) {
|
||||||
|
Debug::log(ERR, "Invalid arg \"%s\" in getPlusMinusKeywordResult!", source.c_str());
|
||||||
|
return INT_MAX;
|
||||||
|
}
|
||||||
|
} else if (source.find_first_of("-") == 0) {
|
||||||
|
try {
|
||||||
|
if (source.find('.') != std::string::npos)
|
||||||
|
result = relative - std::stof(source.substr(1));
|
||||||
|
else
|
||||||
|
result = relative - std::stoi(source.substr(1));
|
||||||
|
} catch (...) {
|
||||||
|
Debug::log(ERR, "Invalid arg \"%s\" in getPlusMinusKeywordResult!", source.c_str());
|
||||||
|
return INT_MAX;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
if (source.find('.') != std::string::npos)
|
||||||
|
result = stof(source);
|
||||||
|
else
|
||||||
|
result = stoi(source);
|
||||||
|
} catch (...) {
|
||||||
|
Debug::log(ERR, "Invalid arg \"%s\" in getPlusMinusKeywordResult!", source.c_str());
|
||||||
|
return INT_MAX;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
|
@ -7,3 +7,5 @@ void wlr_signal_emit_safe(struct wl_signal *signal, void *data);
|
||||||
std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string
|
std::string getFormat(const char *fmt, ...); // Basically Debug::log to a string
|
||||||
void scaleBox(wlr_box*, float);
|
void scaleBox(wlr_box*, float);
|
||||||
std::string removeBeginEndSpacesTabs(std::string);
|
std::string removeBeginEndSpacesTabs(std::string);
|
||||||
|
|
||||||
|
float getPlusMinusKeywordResult(std::string in, float relative);
|
|
@ -779,3 +779,16 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) {
|
||||||
// recalc the workspace
|
// recalc the workspace
|
||||||
getMasterNodeOnWorkspace(PNODE->workspaceID)->recalcSizePosRecursive();
|
getMasterNodeOnWorkspace(PNODE->workspaceID)->recalcSizePosRecursive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CHyprDwindleLayout::alterSplitRatioBy(CWindow* pWindow, float ratio) {
|
||||||
|
// window should be valid, insallah
|
||||||
|
|
||||||
|
const auto PNODE = getNodeFromWindow(pWindow);
|
||||||
|
|
||||||
|
if (!PNODE || !PNODE->pParent)
|
||||||
|
return;
|
||||||
|
|
||||||
|
PNODE->pParent->splitRatio = std::clamp(PNODE->pParent->splitRatio + ratio, 0.1f, 1.9f);
|
||||||
|
|
||||||
|
PNODE->pParent->recalcSizePosRecursive();
|
||||||
|
}
|
|
@ -51,7 +51,8 @@ public:
|
||||||
virtual void toggleWindowGroup(CWindow*);
|
virtual void toggleWindowGroup(CWindow*);
|
||||||
virtual void switchGroupWindow(CWindow*);
|
virtual void switchGroupWindow(CWindow*);
|
||||||
virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);
|
virtual SWindowRenderLayoutHints requestRenderHints(CWindow*);
|
||||||
virtual void switchWindows(CWindow*, CWindow*);
|
virtual void switchWindows(CWindow*, CWindow*);
|
||||||
|
virtual void alterSplitRatioBy(CWindow*, float);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -90,4 +90,10 @@ public:
|
||||||
The layout is free to ignore.
|
The layout is free to ignore.
|
||||||
*/
|
*/
|
||||||
virtual void switchWindows(CWindow*, CWindow*) = 0;
|
virtual void switchWindows(CWindow*, CWindow*) = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
Called when the user requests to change the splitratio by X
|
||||||
|
on a window
|
||||||
|
*/
|
||||||
|
virtual void alterSplitRatioBy(CWindow*, float) = 0;
|
||||||
};
|
};
|
|
@ -62,6 +62,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t& modmask, const xkb_keysym_t
|
||||||
else if (k.handler == "movewindow") { moveActiveTo(k.arg); }
|
else if (k.handler == "movewindow") { moveActiveTo(k.arg); }
|
||||||
else if (k.handler == "togglegroup") { toggleGroup(k.arg); }
|
else if (k.handler == "togglegroup") { toggleGroup(k.arg); }
|
||||||
else if (k.handler == "changegroupactive") { changeGroupActive(k.arg); }
|
else if (k.handler == "changegroupactive") { changeGroupActive(k.arg); }
|
||||||
|
else if (k.handler == "splitratio") { alterSplitRatio(k.arg); }
|
||||||
else {
|
else {
|
||||||
Debug::log(ERR, "Inavlid handler in a keybind! (handler %s does not exist)", k.handler.c_str());
|
Debug::log(ERR, "Inavlid handler in a keybind! (handler %s does not exist)", k.handler.c_str());
|
||||||
}
|
}
|
||||||
|
@ -142,29 +143,11 @@ void CKeybindManager::toggleActivePseudo(std::string args) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void CKeybindManager::changeworkspace(std::string args) {
|
void CKeybindManager::changeworkspace(std::string args) {
|
||||||
int workspaceToChangeTo = 0;
|
int workspaceToChangeTo = std::clamp((int)getPlusMinusKeywordResult(args, g_pCompositor->m_pLastMonitor->activeWorkspace), 1, INT_MAX);
|
||||||
|
|
||||||
if (args.find_first_of("+") == 0) {
|
if (workspaceToChangeTo == INT_MAX) {
|
||||||
try {
|
Debug::log(ERR, "Error in changeworkspace, invalid value");
|
||||||
workspaceToChangeTo = g_pCompositor->m_pLastMonitor->activeWorkspace + std::stoi(args.substr(1));
|
return;
|
||||||
} catch (...) {
|
|
||||||
Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if (args.find_first_of("-") == 0) {
|
|
||||||
try {
|
|
||||||
workspaceToChangeTo = std::clamp(g_pCompositor->m_pLastMonitor->activeWorkspace - std::stoi(args.substr(1)), 1, INT_MAX);
|
|
||||||
} catch (...) {
|
|
||||||
Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
try {
|
|
||||||
workspaceToChangeTo = stoi(args);
|
|
||||||
} catch (...) {
|
|
||||||
Debug::log(ERR, "Invalid arg \"%s\" in changeWorkspace!", args.c_str());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if it exists, we warp to it
|
// if it exists, we warp to it
|
||||||
|
@ -359,12 +342,12 @@ void CKeybindManager::moveActiveTo(std::string args) {
|
||||||
|
|
||||||
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
||||||
|
|
||||||
if (!PLASTWINDOW)
|
if (!g_pCompositor->windowValidMapped(PLASTWINDOW))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
const auto PWINDOWTOCHANGETO = g_pCompositor->getWindowInDirection(PLASTWINDOW, arg);
|
||||||
|
|
||||||
if (!PWINDOWTOCHANGETO)
|
if (!g_pCompositor->windowValidMapped(PWINDOWTOCHANGETO))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO);
|
g_pLayoutManager->getCurrentLayout()->switchWindows(PLASTWINDOW, PWINDOWTOCHANGETO);
|
||||||
|
@ -377,3 +360,28 @@ void CKeybindManager::toggleGroup(std::string args) {
|
||||||
void CKeybindManager::changeGroupActive(std::string args) {
|
void CKeybindManager::changeGroupActive(std::string args) {
|
||||||
g_pLayoutManager->getCurrentLayout()->switchGroupWindow(g_pCompositor->m_pLastWindow);
|
g_pLayoutManager->getCurrentLayout()->switchGroupWindow(g_pCompositor->m_pLastWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CKeybindManager::alterSplitRatio(std::string args) {
|
||||||
|
float splitratio = 0;
|
||||||
|
|
||||||
|
if (args == "+" || args == "-") {
|
||||||
|
Debug::log(LOG, "alterSplitRatio: using LEGACY +/-, consider switching to the Hyprland syntax.");
|
||||||
|
splitratio = (args == "+" ? 0.05f : -0.05f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (splitratio == 0) {
|
||||||
|
splitratio = getPlusMinusKeywordResult(args, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (splitratio == INT_MAX) {
|
||||||
|
Debug::log(ERR, "Splitratio invalid in alterSplitRatio!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto PLASTWINDOW = g_pCompositor->m_pLastWindow;
|
||||||
|
|
||||||
|
if (!g_pCompositor->windowValidMapped(PLASTWINDOW))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_pLayoutManager->getCurrentLayout()->alterSplitRatioBy(PLASTWINDOW, splitratio);
|
||||||
|
}
|
|
@ -35,6 +35,7 @@ private:
|
||||||
void moveActiveTo(std::string);
|
void moveActiveTo(std::string);
|
||||||
void toggleGroup(std::string);
|
void toggleGroup(std::string);
|
||||||
void changeGroupActive(std::string);
|
void changeGroupActive(std::string);
|
||||||
|
void alterSplitRatio(std::string);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;
|
inline std::unique_ptr<CKeybindManager> g_pKeybindManager;
|
Loading…
Reference in a new issue