From 84a832181b8fbd5e16d303b2277e83d451f83538 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Wed, 9 Mar 2022 12:13:47 +0100 Subject: [PATCH] Added splitratio --- example/hypr.conf | 3 +++ src/KeybindManager.cpp | 4 ++++ src/KeybindManager.hpp | 1 + src/config/ConfigManager.cpp | 1 + src/window.cpp | 13 ++++++++----- src/window.hpp | 3 +++ src/windowManager.cpp | 37 +++++++++++++++++++++++++++++++++++- src/windowManager.hpp | 2 ++ 8 files changed, 58 insertions(+), 6 deletions(-) diff --git a/example/hypr.conf b/example/hypr.conf index 2500f6c..93d857a 100644 --- a/example/hypr.conf +++ b/example/hypr.conf @@ -110,3 +110,6 @@ bind=SUPERSHIFT,8,movetoworkspace,8 bind=SUPERSHIFT,9,movetoworkspace,9 bind=SUPER,SPACE,togglefloating, + +bind=SUPER,equals,splitratio,+ +bind=SUPER,minus,splitratio,- diff --git a/src/KeybindManager.cpp b/src/KeybindManager.cpp index 6ba09dc..5011f68 100644 --- a/src/KeybindManager.cpp +++ b/src/KeybindManager.cpp @@ -212,3 +212,7 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) { g_pWindowManager->setAllFloatingWindowsTop(); } } + +void KeybindManager::changeSplitRatio(std::string args) { + g_pWindowManager->changeSplitRatioCurrent(args[0]); +} \ No newline at end of file diff --git a/src/KeybindManager.hpp b/src/KeybindManager.hpp index 08834c0..b518f9e 100644 --- a/src/KeybindManager.hpp +++ b/src/KeybindManager.hpp @@ -27,4 +27,5 @@ namespace KeybindManager { void toggleActiveWindowFullscreen(std::string args); void toggleActiveWindowFloating(std::string args); void movetoworkspace(std::string args); + void changeSplitRatio(std::string args); }; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index c4040e4..bc886e6 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -124,6 +124,7 @@ void handleBind(const std::string& command, const std::string& value) { if (HANDLER == "workspace") dispatcher = KeybindManager::changeworkspace; if (HANDLER == "lastworkspace") dispatcher = KeybindManager::changetolastworkspace; if (HANDLER == "togglefloating") dispatcher = KeybindManager::toggleActiveWindowFloating; + if (HANDLER == "splitratio") dispatcher = KeybindManager::changeSplitRatio; if (dispatcher && KEY != 0) KeybindManager::keybinds.push_back(Keybind(KeybindManager::modToMask(MOD), KEY, COMMAND, dispatcher)); diff --git a/src/window.cpp b/src/window.cpp index 319be54..c8fe9b0 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,7 +1,7 @@ #include "window.hpp" #include "windowManager.hpp" -CWindow::CWindow() { this->setDockHidden(false); this->setRealBorderColor(0); this->setEffectiveBorderColor(0); this->setFirstOpen(true); this->setConstructed(false); this->setTransient(false); this->setLastUpdatePosition(Vector2D(0,0)); this->setLastUpdateSize(Vector2D(0,0)); this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); } +CWindow::CWindow() { this->setSplitRatio(1); this->setDockHidden(false); this->setRealBorderColor(0); this->setEffectiveBorderColor(0); this->setFirstOpen(true); this->setConstructed(false); this->setTransient(false); this->setLastUpdatePosition(Vector2D(0,0)); this->setLastUpdateSize(Vector2D(0,0)); this->setDock(false); this->setUnderFullscreen(false); this->setIsSleeping(true); this->setFirstAnimFrame(true); this->setIsAnimated(false); this->setDead(false); this->setMasterChildIndex(0); this->setMaster(false); this->setCanKill(false); this->setImmovable(false); this->setNoInterventions(false); this->setDirty(true); this->setFullscreen(false); this->setIsFloating(false); this->setParentNodeID(0); this->setChildNodeAID(0); this->setChildNodeBID(0); this->setName(""); } CWindow::~CWindow() { } void CWindow::generateNodeID() { @@ -28,11 +28,14 @@ void CWindow::setDirtyRecursive(bool val) { void CWindow::recalcSizePosRecursive() { if (m_iChildNodeAID != 0) { const auto HORIZONTAL = m_vecSize.x > m_vecSize.y; + + const auto REVERSESPLITRATIO = 2.f - m_fSplitRatio; + g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setPosition(m_vecPosition); - g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setPosition(m_vecPosition + (HORIZONTAL ? Vector2D(m_vecSize.x / 2.f, 0) : Vector2D(0, m_vecSize.y / 2.f))); - - g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2))); - g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2))); + g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setPosition(m_vecPosition + (HORIZONTAL ? Vector2D(m_vecSize.x / 2.f * m_fSplitRatio, 0) : Vector2D(0, m_vecSize.y / 2.f * m_fSplitRatio))); + + g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 / m_fSplitRatio : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2 / m_fSplitRatio))); + g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setSize(Vector2D(m_vecSize.x / (HORIZONTAL ? 2 / REVERSESPLITRATIO : 1), m_vecSize.y / (HORIZONTAL ? 1 : 2 / REVERSESPLITRATIO))); g_pWindowManager->getWindowFromDrawable(m_iChildNodeAID)->setDirty(true); g_pWindowManager->getWindowFromDrawable(m_iChildNodeBID)->setDirty(true); diff --git a/src/window.hpp b/src/window.hpp index b8b2c46..8a9b982 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -59,6 +59,9 @@ public: EXPOSED_MEMBER(IsFloating, bool, b); EXPOSED_MEMBER(Drawable, int64_t, i); // int64_t because it's my internal ID system too. + // For splitting ratios + EXPOSED_MEMBER(SplitRatio, float, f); + // Fullscreen EXPOSED_MEMBER(Fullscreen, bool, b); diff --git a/src/windowManager.cpp b/src/windowManager.cpp index e65a27d..75a95d2 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -1113,7 +1113,7 @@ void CWindowManager::recalcEntireWorkspace(const int& workspace) { // get the master on the workspace CWindow* pMasterWindow = nullptr; for (auto& w : windows) { - if (w.getWorkspaceID() == workspace && w.getParentNodeID() == 0) { + if (w.getWorkspaceID() == workspace && w.getParentNodeID() == 0 && !w.getIsFloating() && !w.getDock()) { pMasterWindow = &w; break; } @@ -2425,4 +2425,39 @@ SMonitor* CWindowManager::getMonitorFromCoord(const Vector2D coord) { } return nullptr; +} + +void CWindowManager::changeSplitRatioCurrent(const char& dir) { + + const auto CURRENT = getWindowFromDrawable(LastWindow); + + if (!CURRENT) { + Debug::log(LOG, "Cannot change split ratio when lastwindow NULL."); + return; + } + + const auto PARENT = getWindowFromDrawable(CURRENT->getParentNodeID()); + + if (!PARENT) { + Debug::log(LOG, "Cannot change split ratio when parent NULL."); + return; + } + + switch(dir) { + case '+': + PARENT->setSplitRatio(PARENT->getSplitRatio() + 0.05f); + break; + case '-': + PARENT->setSplitRatio(PARENT->getSplitRatio() - 0.05f); + break; + default: + Debug::log(ERR, "changeSplitRatioCurrent called with an invalid dir!"); + return; + } + + PARENT->setSplitRatio(std::clamp(PARENT->getSplitRatio(), 0.1f, 1.9f)); + + Debug::log(LOG, "Changed SplitRatio of " + std::to_string(PARENT->getDrawable()) + " to " + std::to_string(PARENT->getSplitRatio()) + " (" + dir + ")" ); + + recalcEntireWorkspace(CURRENT->getWorkspaceID()); } \ No newline at end of file diff --git a/src/windowManager.hpp b/src/windowManager.hpp index d1444dc..f8c04ff 100644 --- a/src/windowManager.hpp +++ b/src/windowManager.hpp @@ -144,6 +144,8 @@ public: bool shouldBeManaged(const int&); + void changeSplitRatioCurrent(const char& dir); + private: // Internal WM functions that don't have to be exposed