From 663fba76ae08407f196c1cc1b2c775d52b9fdfc9 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:32:14 +0200 Subject: [PATCH] Added resizeactive --- src/helpers/MiscFunctions.cpp | 2 +- src/layout/DwindleLayout.cpp | 166 ++++++++++++++++++-------------- src/layout/DwindleLayout.hpp | 1 + src/layout/IHyprLayout.hpp | 6 ++ src/managers/KeybindManager.cpp | 21 ++++ src/managers/KeybindManager.hpp | 1 + 6 files changed, 122 insertions(+), 75 deletions(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 2cdadbc8..6f9b465e 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -135,7 +135,7 @@ float getPlusMinusKeywordResult(std::string source, float relative) { } bool isNumber(const std::string& str) { - return std::ranges::all_of(str.begin(), str.end(), [](char c) { return isdigit(c) != 0; }); + return std::ranges::all_of(str.begin(), str.end(), [](char c) { return isdigit(c) != 0 || c == '-'; }); } bool isDirection(const std::string& arg) { diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index e5cbf46c..ce63ace6 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -517,80 +517,7 @@ void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) { g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv()); } else { - // we need to adjust the splitratio - - // get some data about our window - const auto PNODE = getNodeFromWindow(DRAGGINGWINDOW); - const auto PMONITOR = g_pCompositor->getMonitorFromID(DRAGGINGWINDOW->m_iMonitorID); - const bool DISPLAYLEFT = STICKS(DRAGGINGWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x); - const bool DISPLAYRIGHT = STICKS(DRAGGINGWINDOW->m_vPosition.x + DRAGGINGWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x); - const bool DISPLAYTOP = STICKS(DRAGGINGWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y); - const bool DISPLAYBOTTOM = STICKS(DRAGGINGWINDOW->m_vPosition.y + DRAGGINGWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y); - - // construct allowed movement - Vector2D allowedMovement = TICKDELTA; - if (DISPLAYLEFT && DISPLAYRIGHT) - allowedMovement.x = 0; - - if (DISPLAYBOTTOM && DISPLAYTOP) - allowedMovement.y = 0; - - // get the correct containers to apply splitratio to - const auto PPARENT = PNODE->pParent; - - if (!PPARENT) - return; // the only window on a workspace, ignore - - const bool PARENTSIDEBYSIDE = !PPARENT->splitTop; - - // Get the parent's parent - auto PPARENT2 = PPARENT->pParent; - - // No parent means we have only 2 windows, and thus one axis of freedom - if (!PPARENT2) { - if (PARENTSIDEBYSIDE) { - allowedMovement.x *= 2.f / PPARENT->size.x; - PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f); - PPARENT->recalcSizePosRecursive(); - } else { - allowedMovement.y *= 2.f / PPARENT->size.y; - PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f); - PPARENT->recalcSizePosRecursive(); - } - - return; - } - - // Get first parent with other split - while(PPARENT2 && PPARENT2->splitTop == !PARENTSIDEBYSIDE) - PPARENT2 = PPARENT2->pParent; - - // no parent, one axis of freedom - if (!PPARENT2) { - if (PARENTSIDEBYSIDE) { - allowedMovement.x *= 2.f / PPARENT->size.x; - PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f); - PPARENT->recalcSizePosRecursive(); - } else { - allowedMovement.y *= 2.f / PPARENT->size.y; - PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f); - PPARENT->recalcSizePosRecursive(); - } - - return; - } - - // 2 axes of freedom - const auto SIDECONTAINER = PARENTSIDEBYSIDE ? PPARENT : PPARENT2; - const auto TOPCONTAINER = PARENTSIDEBYSIDE ? PPARENT2 : PPARENT; - - allowedMovement.x *= 2.f / SIDECONTAINER->size.x; - allowedMovement.y *= 2.f / TOPCONTAINER->size.y; - - SIDECONTAINER->splitRatio = std::clamp(SIDECONTAINER->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f); - TOPCONTAINER->splitRatio = std::clamp(TOPCONTAINER->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f); - SIDECONTAINER->recalcSizePosRecursive(); - TOPCONTAINER->recalcSizePosRecursive(); + resizeActiveWindow(TICKDELTA, DRAGGINGWINDOW); } } @@ -608,6 +535,97 @@ void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) { g_pHyprRenderer->damageWindow(DRAGGINGWINDOW); } +void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, CWindow* pWindow) { + + const auto PWINDOW = pWindow ? pWindow : g_pCompositor->m_pLastWindow; + + if (!g_pCompositor->windowValidMapped(PWINDOW)) + return; + + const auto PNODE = getNodeFromWindow(PWINDOW); + + if (!PNODE) { + PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goalv() + pixResize); + PWINDOW->m_vRealSize.setValueAndWarp(Vector2D(std::clamp(PWINDOW->m_vRealSize.vec().x, (double)20, (double)999999), std::clamp(PWINDOW->m_vRealSize.vec().y, (double)20, (double)999999))); + + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); + + return; + } + + // get some data about our window + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + const bool DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x); + const bool DISPLAYRIGHT = STICKS(PWINDOW->m_vPosition.x + PWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x); + const bool DISPLAYTOP = STICKS(PWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y); + const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y); + + // construct allowed movement + Vector2D allowedMovement = pixResize; + if (DISPLAYLEFT && DISPLAYRIGHT) + allowedMovement.x = 0; + + if (DISPLAYBOTTOM && DISPLAYTOP) + allowedMovement.y = 0; + + // get the correct containers to apply splitratio to + const auto PPARENT = PNODE->pParent; + + if (!PPARENT) + return; // the only window on a workspace, ignore + + const bool PARENTSIDEBYSIDE = !PPARENT->splitTop; + + // Get the parent's parent + auto PPARENT2 = PPARENT->pParent; + + // No parent means we have only 2 windows, and thus one axis of freedom + if (!PPARENT2) { + if (PARENTSIDEBYSIDE) { + allowedMovement.x *= 2.f / PPARENT->size.x; + PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f); + PPARENT->recalcSizePosRecursive(); + } else { + allowedMovement.y *= 2.f / PPARENT->size.y; + PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f); + PPARENT->recalcSizePosRecursive(); + } + + return; + } + + // Get first parent with other split + while (PPARENT2 && PPARENT2->splitTop == !PARENTSIDEBYSIDE) + PPARENT2 = PPARENT2->pParent; + + // no parent, one axis of freedom + if (!PPARENT2) { + if (PARENTSIDEBYSIDE) { + allowedMovement.x *= 2.f / PPARENT->size.x; + PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f); + PPARENT->recalcSizePosRecursive(); + } else { + allowedMovement.y *= 2.f / PPARENT->size.y; + PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f); + PPARENT->recalcSizePosRecursive(); + } + + return; + } + + // 2 axes of freedom + const auto SIDECONTAINER = PARENTSIDEBYSIDE ? PPARENT : PPARENT2; + const auto TOPCONTAINER = PARENTSIDEBYSIDE ? PPARENT2 : PPARENT; + + allowedMovement.x *= 2.f / SIDECONTAINER->size.x; + allowedMovement.y *= 2.f / TOPCONTAINER->size.y; + + SIDECONTAINER->splitRatio = std::clamp(SIDECONTAINER->splitRatio + allowedMovement.x, (double)0.1f, (double)1.9f); + TOPCONTAINER->splitRatio = std::clamp(TOPCONTAINER->splitRatio + allowedMovement.y, (double)0.1f, (double)1.9f); + SIDECONTAINER->recalcSizePosRecursive(); + TOPCONTAINER->recalcSizePosRecursive(); +} + void CHyprDwindleLayout::onWindowCreatedFloating(CWindow* pWindow) { wlr_box desiredGeometry = {0}; g_pXWaylandManager->getGeometryForWindow(pWindow, &desiredGeometry); diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index 492a52a3..766e9f6a 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -48,6 +48,7 @@ public: virtual void recalculateWindow(CWindow*); virtual void changeWindowFloatingMode(CWindow*); virtual void onBeginDragWindow(); + virtual void resizeActiveWindow(const Vector2D&, CWindow* pWindow = nullptr); virtual void onEndDragWindow(); virtual void onMouseMove(const Vector2D&); virtual void onWindowCreatedFloating(CWindow*); diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index e9cf2a15..8052fe42 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -49,6 +49,12 @@ public: as. */ virtual void onBeginDragWindow() = 0; + /* + Called when a user requests a resize of the current window by a vec + Vector2D holds pixel values + Optional pWindow for a specific window + */ + virtual void resizeActiveWindow(const Vector2D&, CWindow* pWindow = nullptr) = 0; /* Called when a window is ended being dragged (mouse up) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 7d08d358..c3f65b3d 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -25,6 +25,7 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["moveworkspacetomonitor"] = moveWorkspaceToMonitor; m_mDispatchers["togglespecialworkspace"] = toggleSpecialWorkspace; m_mDispatchers["forcerendererreload"] = forceRendererReload; + m_mDispatchers["resizeactive"] = resizeActive; } void CKeybindManager::addKeybind(SKeybind kb) { @@ -764,6 +765,8 @@ void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) { } void CKeybindManager::moveWorkspaceToMonitor(std::string args) { + if (args.find_first_of(' ') == std::string::npos) + return; std::string workspace = args.substr(0, args.find_first_of(' ')); std::string monitor = args.substr(args.find_first_of(' ') + 1); @@ -843,4 +846,22 @@ void CKeybindManager::forceRendererReload(std::string args) { auto rule = g_pConfigManager->getMonitorRuleFor(m.szName); g_pHyprRenderer->applyMonitorRule(&m, &rule, true); } +} + +void CKeybindManager::resizeActive(std::string args) { + if (args.find_first_of(' ') == std::string::npos) + return; + + std::string x = args.substr(0, args.find_first_of(' ')); + std::string y = args.substr(args.find_first_of(' ') + 1); + + if (!isNumber(x) || !isNumber(y)) { + Debug::log(ERR, "resizeTiledWindow: args not numbers"); + return; + } + + const int X = std::stoi(x); + const int Y = std::stoi(y); + + g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(Vector2D(X, Y)); } \ No newline at end of file diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 0cb7c0b5..093197b9 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -55,6 +55,7 @@ private: static void moveWorkspaceToMonitor(std::string); static void toggleSpecialWorkspace(std::string); static void forceRendererReload(std::string); + static void resizeActive(std::string); friend class CCompositor; };