From 0b9a33228b789ff2c9f07ee85a54bddcb776ee97 Mon Sep 17 00:00:00 2001 From: vaxerski <43317083+vaxerski@users.noreply.github.com> Date: Sun, 3 Apr 2022 13:39:30 +0200 Subject: [PATCH] Added mouse support for movewindow (drag to move) --- src/KeybindManager.cpp | 7 +++++-- src/events/events.cpp | 38 +++++++++++++++++++++++++++++--------- src/window.cpp | 2 +- src/window.hpp | 3 +++ src/windowManager.cpp | 2 +- 5 files changed, 39 insertions(+), 13 deletions(-) diff --git a/src/KeybindManager.cpp b/src/KeybindManager.cpp index d7ca501..068e79d 100644 --- a/src/KeybindManager.cpp +++ b/src/KeybindManager.cpp @@ -175,7 +175,7 @@ void KeybindManager::toggleActiveWindowFullscreen(std::string unusedArg) { g_pWindowManager->toggleWindowFullscrenn(g_pWindowManager->LastWindow); } -void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) { +void KeybindManager::toggleActiveWindowFloating(std::string arg) { if (const auto PWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); PWINDOW) { PWINDOW->setIsFloating(!PWINDOW->getIsFloating()); PWINDOW->setDirty(true); @@ -197,6 +197,7 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) { const auto RESTOREISPSEUDO = PWINDOW->getIsPseudotiled(); const auto RESTOREREALS = PWINDOW->getRealSize(); const auto RESTOREREALP = PWINDOW->getRealPosition(); + const auto RESTOREDRAGT = PWINDOW->getDraggingTiled(); g_pWindowManager->removeWindowFromVectorSafe(PWINDOW->getDrawable()); @@ -215,6 +216,7 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) { PNEWWINDOW->setIsPseudotiled(RESTOREISPSEUDO); PNEWWINDOW->setRealPosition(RESTOREREALP); PNEWWINDOW->setRealSize(RESTOREREALS); + PNEWWINDOW->setDraggingTiled(RESTOREDRAGT); } // EWMH to let everyone know @@ -222,7 +224,8 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) { EWMH::updateWindow(PWINDOW->getDrawable()); - g_pWindowManager->setAllFloatingWindowsTop(); + if (arg != "simple") + g_pWindowManager->setAllFloatingWindowsTop(); } } diff --git a/src/events/events.cpp b/src/events/events.cpp index 028c7f1..c7c71ac 100644 --- a/src/events/events.cpp +++ b/src/events/events.cpp @@ -712,16 +712,26 @@ void Events::eventButtonPress(xcb_generic_event_t* event) { // mouse down! g_pWindowManager->mouseKeyDown = E->detail; + + if (const auto PLASTWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); PLASTWINDOW) { + + PLASTWINDOW->setDraggingTiled(!PLASTWINDOW->getIsFloating()); + + g_pWindowManager->actingOnWindowFloating = PLASTWINDOW->getDrawable(); + g_pWindowManager->mouseLastPos = g_pWindowManager->getCursorPos(); + + if (!PLASTWINDOW->getIsFloating()) { + const auto PDRAWABLE = PLASTWINDOW->getDrawable(); + KeybindManager::toggleActiveWindowFloating(""); + + // refocus + g_pWindowManager->setFocusedWindow(PDRAWABLE); + } + } + xcb_grab_pointer(g_pWindowManager->DisplayConnection, 0, g_pWindowManager->Screen->root, XCB_EVENT_MASK_BUTTON_RELEASE | XCB_EVENT_MASK_BUTTON_MOTION | XCB_EVENT_MASK_POINTER_MOTION_HINT, XCB_GRAB_MODE_ASYNC, XCB_GRAB_MODE_ASYNC, g_pWindowManager->Screen->root, XCB_NONE, XCB_CURRENT_TIME); - - if (const auto PLASTWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->LastWindow); PLASTWINDOW) { - if (PLASTWINDOW->getIsFloating()) { - g_pWindowManager->actingOnWindowFloating = PLASTWINDOW->getDrawable(); - g_pWindowManager->mouseLastPos = g_pWindowManager->getCursorPos(); - } - } } void Events::eventButtonRelease(xcb_generic_event_t* event) { @@ -729,11 +739,21 @@ void Events::eventButtonRelease(xcb_generic_event_t* event) { RETURNIFBAR; + const auto PACTINGWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->actingOnWindowFloating); + // ungrab the mouse ptr xcb_ungrab_pointer(g_pWindowManager->DisplayConnection, XCB_CURRENT_TIME); - const auto PACTINGWINDOW = g_pWindowManager->getWindowFromDrawable(g_pWindowManager->actingOnWindowFloating); - if (PACTINGWINDOW) + + if (PACTINGWINDOW) { PACTINGWINDOW->setDirty(true); + + if (PACTINGWINDOW->getDraggingTiled()) { + g_pWindowManager->LastWindow = PACTINGWINDOW->getDrawable(); + KeybindManager::toggleActiveWindowFloating(""); + } + + } + g_pWindowManager->actingOnWindowFloating = 0; g_pWindowManager->mouseKeyDown = 0; } diff --git a/src/window.cpp b/src/window.cpp index 31ed8c3..06d132d 100644 --- a/src/window.cpp +++ b/src/window.cpp @@ -1,7 +1,7 @@ #include "window.hpp" #include "windowManager.hpp" -CWindow::CWindow() { this->setIsPseudotiled(false); 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() { this->setDraggingTiled(false); this->setIsPseudotiled(false); 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() { diff --git a/src/window.hpp b/src/window.hpp index 6efa376..5e9c41f 100644 --- a/src/window.hpp +++ b/src/window.hpp @@ -112,6 +112,9 @@ public: EXPOSED_MEMBER(IsPseudotiled, bool, b); EXPOSED_MEMBER(PseudoSize, Vector2D, vec); + // For dragging tiled windows + EXPOSED_MEMBER(DraggingTiled, bool, b); + private: }; \ No newline at end of file diff --git a/src/windowManager.cpp b/src/windowManager.cpp index 34fdc35..c8dd548 100644 --- a/src/windowManager.cpp +++ b/src/windowManager.cpp @@ -955,7 +955,7 @@ CWindow* CWindowManager::findWindowAtCursor() { const auto WORKSPACE = activeWorkspaces[getMonitorFromCursor()->ID]; for (auto& window : windows) { - if (window.getWorkspaceID() == WORKSPACE && !window.getIsFloating() && window.getDrawable() > 0) { + if (window.getWorkspaceID() == WORKSPACE && !window.getIsFloating() && window.getDrawable() > 0 && window.getConstructed()) { if (cursorPos.x >= window.getPosition().x && cursorPos.x <= window.getPosition().x + window.getSize().x