aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorvaxerski <[email protected]>2022-06-06 19:32:14 +0200
committervaxerski <[email protected]>2022-06-06 19:32:14 +0200
commit663fba76ae08407f196c1cc1b2c775d52b9fdfc9 (patch)
tree5d7e9235567f03cc9692af48fa62a854025b9c9d
parentd73e05cc681cb7227d69d67c32e735b2705743a6 (diff)
downloadHyprland-663fba76ae08407f196c1cc1b2c775d52b9fdfc9.tar.gz
Hyprland-663fba76ae08407f196c1cc1b2c775d52b9fdfc9.zip
Added resizeactive
-rw-r--r--src/helpers/MiscFunctions.cpp2
-rw-r--r--src/layout/DwindleLayout.cpp156
-rw-r--r--src/layout/DwindleLayout.hpp1
-rw-r--r--src/layout/IHyprLayout.hpp6
-rw-r--r--src/managers/KeybindManager.cpp21
-rw-r--r--src/managers/KeybindManager.hpp1
6 files changed, 117 insertions, 70 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,95 +517,113 @@ void CHyprDwindleLayout::onMouseMove(const Vector2D& mousePos) {
g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv());
} else {
- // we need to adjust the splitratio
+ resizeActiveWindow(TICKDELTA, DRAGGINGWINDOW);
+ }
+ }
- // 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);
+ // get middle point
+ Vector2D middle = DRAGGINGWINDOW->m_vRealPosition.vec() + DRAGGINGWINDOW->m_vRealSize.vec() / 2.f;
- // construct allowed movement
- Vector2D allowedMovement = TICKDELTA;
- if (DISPLAYLEFT && DISPLAYRIGHT)
- allowedMovement.x = 0;
+ // and check its monitor
+ const auto PMONITOR = g_pCompositor->getMonitorFromVector(middle);
- if (DISPLAYBOTTOM && DISPLAYTOP)
- allowedMovement.y = 0;
+ if (PMONITOR) {
+ DRAGGINGWINDOW->m_iMonitorID = PMONITOR->ID;
+ DRAGGINGWINDOW->m_iWorkspaceID = PMONITOR->activeWorkspace;
+ }
- // get the correct containers to apply splitratio to
- const auto PPARENT = PNODE->pParent;
+ g_pHyprRenderer->damageWindow(DRAGGINGWINDOW);
+}
- if (!PPARENT)
- return; // the only window on a workspace, ignore
+void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, CWindow* pWindow) {
- const bool PARENTSIDEBYSIDE = !PPARENT->splitTop;
+ const auto PWINDOW = pWindow ? pWindow : g_pCompositor->m_pLastWindow;
- // Get the parent's parent
- auto PPARENT2 = PPARENT->pParent;
+ if (!g_pCompositor->windowValidMapped(PWINDOW))
+ return;
- // 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();
- }
+ const auto PNODE = getNodeFromWindow(PWINDOW);
- return;
- }
+ 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)));
- // 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;
- }
+ 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);
- // 2 axes of freedom
- const auto SIDECONTAINER = PARENTSIDEBYSIDE ? PPARENT : PPARENT2;
- const auto TOPCONTAINER = PARENTSIDEBYSIDE ? PPARENT2 : PPARENT;
+ // construct allowed movement
+ Vector2D allowedMovement = pixResize;
+ if (DISPLAYLEFT && DISPLAYRIGHT)
+ allowedMovement.x = 0;
- allowedMovement.x *= 2.f / SIDECONTAINER->size.x;
- allowedMovement.y *= 2.f / TOPCONTAINER->size.y;
+ if (DISPLAYBOTTOM && DISPLAYTOP)
+ allowedMovement.y = 0;
- 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();
+ // 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 middle point
- Vector2D middle = DRAGGINGWINDOW->m_vRealPosition.vec() + DRAGGINGWINDOW->m_vRealSize.vec() / 2.f;
+ // Get first parent with other split
+ while (PPARENT2 && PPARENT2->splitTop == !PARENTSIDEBYSIDE)
+ PPARENT2 = PPARENT2->pParent;
- // and check its monitor
- const auto PMONITOR = g_pCompositor->getMonitorFromVector(middle);
+ // 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();
+ }
- if (PMONITOR) {
- DRAGGINGWINDOW->m_iMonitorID = PMONITOR->ID;
- DRAGGINGWINDOW->m_iWorkspaceID = PMONITOR->activeWorkspace;
+ return;
}
- g_pHyprRenderer->damageWindow(DRAGGINGWINDOW);
+ // 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) {
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
@@ -50,6 +50,12 @@ public:
*/
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;
};