summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvaxerski <vaxry@vaxry.net>2022-08-15 15:59:07 +0200
committervaxerski <vaxry@vaxry.net>2022-08-15 15:59:07 +0200
commitb0b3a5af100d6c68a30230c5b5eafd8087703a99 (patch)
treec3529c5397aff49773271687d6af421836dbfee3 /src
parentd47bfe6af1d040f5c5feb607cf24ea0947a4c8e8 (diff)
added resizewindowpixel and movewindowpixel
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp39
-rw-r--r--src/Compositor.hpp1
-rw-r--r--src/managers/KeybindManager.cpp108
-rw-r--r--src/managers/KeybindManager.hpp2
4 files changed, 74 insertions, 76 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
+ return;
- std::string x = args.substr(0, args.find_first_of(' '));
- std::string y = args.substr(args.find_first_of(' ') + 1);
+ const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealSize.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()->resizeActiveWindow(SIZ - g_pCompositor->m_pLastWindow->m_vRealSize.goalv());
- if (!isNumber(newX) || !isNumber(newY)) {
- Debug::log(ERR, "resizeTiledWindow: exact args not numbers");
- return;
- }
+ 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;
+}
- const int X = std::stoi(newX);
- const int Y = std::stoi(newY);
+void CKeybindManager::moveActive(std::string args) {
+ if (!g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow))
+ return;
- if (X < 10 || Y < 10) {
- Debug::log(ERR, "resizeTiledWindow: exact args cannot be < 10");
- return;
- }
+ const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealPosition.goalv());
- const int DX = X - PWINDOW->m_vRealSize.goalv().x;
- const int DY = Y - PWINDOW->m_vRealSize.goalv().y;
+ g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - g_pCompositor->m_pLastWindow->m_vRealPosition.goalv());
+}
- g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(Vector2D(DX, DY));
+void CKeybindManager::moveWindow(std::string args) {
- if (PWINDOW->m_vRealSize.goalv().x > 1 && PWINDOW->m_vRealSize.goalv().y > 1)
- PWINDOW->m_bHidden = false;
+ const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1);
+ const auto MOVECMD = args.substr(0, args.find_first_of(','));
- return;
- }
+ const auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX);
- if (!isNumber(x) || !isNumber(y)) {
- Debug::log(ERR, "resizeTiledWindow: args not numbers");
+ if (!PWINDOW) {
+ Debug::log(ERR, "moveWindow: no window");
return;
}
- const int X = std::stoi(x);
- const int Y = std::stoi(y);
+ const auto POS = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealPosition.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;
+ g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - PWINDOW->m_vRealPosition.goalv(), PWINDOW);
}
-void CKeybindManager::moveActive(std::string args) {
- if (!args.contains(' '))
- return;
-
- 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, "moveActive: exact args not numbers");
- return;
- }
-
- const int X = std::stoi(newX);
- const int Y = std::stoi(newY);
+void CKeybindManager::resizeWindow(std::string args) {
- 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;
+ const auto WINDOWREGEX = args.substr(args.find_first_of(',') + 1);
+ const auto MOVECMD = args.substr(0, args.find_first_of(','));
- g_pLayoutManager->getCurrentLayout()->moveActiveWindow(Vector2D(DX, DY));
+ const auto PWINDOW = g_pCompositor->getWindowByRegex(WINDOWREGEX);
+ if (!PWINDOW) {
+ Debug::log(ERR, "resizeWindow: no window");
return;
}
- if (!isNumber(x) || !isNumber(y)) {
- Debug::log(ERR, "moveActive: args not numbers");
- return;
- }
+ const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealSize.goalv());
- const int X = std::stoi(x);
- const int Y = std::stoi(y);
+ g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PWINDOW->m_vRealSize.goalv(), PWINDOW);
- g_pLayoutManager->getCurrentLayout()->moveActiveWindow(Vector2D(X, Y));
+ 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);