From b0b3a5af100d6c68a30230c5b5eafd8087703a99 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Mon, 15 Aug 2022 15:59:07 +0200 Subject: [PATCH] added resizewindowpixel and movewindowpixel --- src/Compositor.cpp | 39 +++++++++++ src/Compositor.hpp | 1 + src/managers/KeybindManager.cpp | 114 ++++++++++---------------------- src/managers/KeybindManager.hpp | 2 + 4 files changed, 77 insertions(+), 79 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f8ca7d91..7c6566b7 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1563,4 +1563,43 @@ SLayerSurface* CCompositor::getLayerSurfaceFromSurface(wlr_surface* pSurface) { } return nullptr; +} + +// returns a delta +Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, const Vector2D& relativeTo) { + if (!args.contains(' ')) + return relativeTo; + + std::string x = args.substr(0, args.find_first_of(' ')); + std::string y = args.substr(args.find_first_of(' ') + 1); + + if (x == "exact") { + std::string newX = y.substr(0, y.find_first_of(' ')); + std::string newY = y.substr(y.find_first_of(' ') + 1); + + if (!isNumber(newX) || !isNumber(newY)) { + Debug::log(ERR, "parseWindowVectorArgsRelative: exact args not numbers"); + return relativeTo; + } + + const int X = std::stoi(newX); + const int Y = std::stoi(newY); + + if (X < 0 || Y < 0) { + Debug::log(ERR, "parseWindowVectorArgsRelative: exact args cannot be < 0"); + return relativeTo; + } + + return Vector2D(X, Y); + } + + if (!isNumber(x) || !isNumber(y)) { + Debug::log(ERR, "parseWindowVectorArgsRelative: args not numbers"); + return relativeTo; + } + + const int X = std::stoi(x); + const int Y = std::stoi(y); + + return Vector2D(X + relativeTo.x, Y + relativeTo.y); } \ No newline at end of file diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 95879815..2e8c8dfe 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -158,6 +158,7 @@ public: SLayerSurface* getLayerSurfaceFromWlr(wlr_layer_surface_v1*); SLayerSurface* getLayerSurfaceFromSurface(wlr_surface*); void closeWindow(CWindow*); + Vector2D parseWindowVectorArgsRelative(const std::string&, const Vector2D&); std::string explicitConfigPath; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index ed953ef1..e08be3f1 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -37,6 +37,8 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["layoutmsg"] = layoutmsg; m_mDispatchers["toggleopaque"] = toggleOpaque; m_mDispatchers["dpms"] = dpms; + m_mDispatchers["movewindowpixel"] = moveWindow; + m_mDispatchers["resizewindowpixel"] = resizeWindow; m_tScrollTimer.reset(); } @@ -1138,107 +1140,61 @@ void CKeybindManager::forceRendererReload(std::string args) { } void CKeybindManager::resizeActive(std::string args) { - if (!args.contains(' ')) - return; - - const auto PWINDOW = g_pCompositor->m_pLastWindow; - - // calc the delta if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) - return; // ignore - - std::string x = args.substr(0, args.find_first_of(' ')); - std::string y = args.substr(args.find_first_of(' ') + 1); - - if (x == "exact") { - std::string newX = y.substr(0, y.find_first_of(' ')); - std::string newY = y.substr(y.find_first_of(' ') + 1); - - if (!isNumber(newX) || !isNumber(newY)) { - Debug::log(ERR, "resizeTiledWindow: exact args not numbers"); - return; - } - - const int X = std::stoi(newX); - const int Y = std::stoi(newY); - - if (X < 10 || Y < 10) { - Debug::log(ERR, "resizeTiledWindow: exact args cannot be < 10"); - return; - } - - const int DX = X - PWINDOW->m_vRealSize.goalv().x; - const int DY = Y - PWINDOW->m_vRealSize.goalv().y; - - g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(Vector2D(DX, DY)); - - if (PWINDOW->m_vRealSize.goalv().x > 1 && PWINDOW->m_vRealSize.goalv().y > 1) - PWINDOW->m_bHidden = false; - return; - } - if (!isNumber(x) || !isNumber(y)) { - Debug::log(ERR, "resizeTiledWindow: args not numbers"); - return; - } + const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealSize.goalv()); - const int X = std::stoi(x); - const int Y = std::stoi(y); + g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - g_pCompositor->m_pLastWindow->m_vRealSize.goalv()); - g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(Vector2D(X, Y)); - - if (PWINDOW->m_vRealSize.goalv().x > 1 && PWINDOW->m_vRealSize.goalv().y > 1) - PWINDOW->m_bHidden = false; + if (g_pCompositor->m_pLastWindow->m_vRealSize.goalv().x > 1 && g_pCompositor->m_pLastWindow->m_vRealSize.goalv().y > 1) + g_pCompositor->m_pLastWindow->m_bHidden = false; } void CKeybindManager::moveActive(std::string args) { - if (!args.contains(' ')) + if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) return; - std::string x = args.substr(0, args.find_first_of(' ')); - std::string y = args.substr(args.find_first_of(' ') + 1); + const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealPosition.goalv()); - if (x == "exact") { - std::string newX = y.substr(0, y.find_first_of(' ')); - std::string newY = y.substr(y.find_first_of(' ') + 1); + g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - g_pCompositor->m_pLastWindow->m_vRealPosition.goalv()); +} - if (!isNumber(newX) || !isNumber(newY)) { - Debug::log(ERR, "moveActive: exact args not numbers"); - return; - } +void CKeybindManager::moveWindow(std::string args) { - const int X = std::stoi(newX); - const int Y = std::stoi(newY); + const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1); + const auto MOVECMD = args.substr(0, args.find_first_of(',')); - if (X < 0 || Y < 0) { - Debug::log(ERR, "moveActive: exact args cannot be < 0"); - return; - } - - // calc the delta - if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow)) - return; // ignore - - const auto PWINDOW = g_pCompositor->m_pLastWindow; - - const int DX = X - PWINDOW->m_vRealPosition.goalv().x; - const int DY = Y - PWINDOW->m_vRealPosition.goalv().y; - - g_pLayoutManager->getCurrentLayout()->moveActiveWindow(Vector2D(DX, DY)); + const auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX); + if (!PWINDOW) { + Debug::log(ERR, "moveWindow: no window"); return; } - if (!isNumber(x) || !isNumber(y)) { - Debug::log(ERR, "moveActive: args not numbers"); + const auto POS = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealPosition.goalv()); + + g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - PWINDOW->m_vRealPosition.goalv(), PWINDOW); +} + +void CKeybindManager::resizeWindow(std::string args) { + + const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1); + const auto MOVECMD = args.substr(0, args.find_first_of(',')); + + const auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX); + + if (!PWINDOW) { + Debug::log(ERR, "resizeWindow: no window"); return; } - const int X = std::stoi(x); - const int Y = std::stoi(y); + const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealSize.goalv()); - g_pLayoutManager->getCurrentLayout()->moveActiveWindow(Vector2D(X, Y)); + g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PWINDOW->m_vRealSize.goalv(), PWINDOW); + + if (PWINDOW->m_vRealSize.goalv().x > 1 && PWINDOW->m_vRealSize.goalv().y > 1) + PWINDOW->m_bHidden = false; } void CKeybindManager::circleNext(std::string arg) { diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 4f0d29f9..c8c09df6 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -94,6 +94,8 @@ private: static void forceRendererReload(std::string); static void resizeActive(std::string); static void moveActive(std::string); + static void moveWindow(std::string); + static void resizeWindow(std::string); static void circleNext(std::string); static void focusWindow(std::string); static void setSubmap(std::string);