Added mouse support for movewindow (drag to move)

This commit is contained in:
vaxerski 2022-04-03 13:39:30 +02:00
parent 894a9b0e3e
commit 0b9a33228b
5 changed files with 39 additions and 13 deletions

View file

@ -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,6 +224,7 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) {
EWMH::updateWindow(PWINDOW->getDrawable());
if (arg != "simple")
g_pWindowManager->setAllFloatingWindowsTop();
}
}

View file

@ -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;
}

View file

@ -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() {

View file

@ -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:
};

View file

@ -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