Skip to content

Commit

Permalink
Added mouse support for movewindow (drag to move)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaxerski committed Apr 3, 2022
1 parent 894a9b0 commit 0b9a332
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/KeybindManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());

Expand All @@ -215,14 +216,16 @@ void KeybindManager::toggleActiveWindowFloating(std::string unusedArg) {
PNEWWINDOW->setIsPseudotiled(RESTOREISPSEUDO);
PNEWWINDOW->setRealPosition(RESTOREREALP);
PNEWWINDOW->setRealSize(RESTOREREALS);
PNEWWINDOW->setDraggingTiled(RESTOREDRAGT);
}

// EWMH to let everyone know
EWMH::updateClientList();

EWMH::updateWindow(PWINDOW->getDrawable());

g_pWindowManager->setAllFloatingWindowsTop();
if (arg != "simple")
g_pWindowManager->setAllFloatingWindowsTop();
}
}

Expand Down
36 changes: 28 additions & 8 deletions src/events/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,28 +712,48 @@ void Events::eventButtonPress(xcb_generic_event_t* event) {

// mouse down!
g_pWindowManager->mouseKeyDown = E->detail;
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();

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

void Events::eventButtonRelease(xcb_generic_event_t* event) {
const auto E = reinterpret_cast<xcb_button_release_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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/window.cpp
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
3 changes: 3 additions & 0 deletions src/window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class CWindow {
EXPOSED_MEMBER(IsPseudotiled, bool, b);
EXPOSED_MEMBER(PseudoSize, Vector2D, vec);

// For dragging tiled windows
EXPOSED_MEMBER(DraggingTiled, bool, b);

private:

};
2 changes: 1 addition & 1 deletion src/windowManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0b9a332

Please sign in to comment.