summaryrefslogtreecommitdiff
path: root/src/managers
diff options
context:
space:
mode:
authorMightyPlaza <123664421+MightyPlaza@users.noreply.github.com>2024-07-27 16:46:19 +0000
committerGitHub <noreply@github.com>2024-07-27 17:46:19 +0100
commitad711ef421fea4cfe03661ebebd465d070925437 (patch)
treecd73755f6dde3c48b4d17762f22c82104d6395df /src/managers
parentae638d997d45e6183adafc6942b1b8fcc70f8928 (diff)
input: unify removing currentlyDraggedWindow (#7071)
modified: src/desktop/Window.cpp modified: src/events/Windows.cpp modified: src/layout/IHyprLayout.cpp modified: src/managers/KeybindManager.cpp modified: src/managers/KeybindManager.hpp modified: src/managers/input/InputManager.cpp
Diffstat (limited to 'src/managers')
-rw-r--r--src/managers/KeybindManager.cpp106
-rw-r--r--src/managers/KeybindManager.hpp3
-rw-r--r--src/managers/input/InputManager.cpp2
3 files changed, 46 insertions, 65 deletions
diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp
index 22d9c3d7..038f6401 100644
--- a/src/managers/KeybindManager.cpp
+++ b/src/managers/KeybindManager.cpp
@@ -242,27 +242,14 @@ void CKeybindManager::updateXKBTranslationState() {
}
bool CKeybindManager::ensureMouseBindState() {
- if (!m_bIsMouseBindActive)
+ if (!g_pInputManager->currentlyDraggedWindow)
return false;
if (!g_pInputManager->currentlyDraggedWindow.expired()) {
- PHLWINDOW lastDraggedWindow = g_pInputManager->currentlyDraggedWindow.lock();
-
- m_bIsMouseBindActive = false;
- g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
- g_pInputManager->currentlyDraggedWindow.reset();
- g_pInputManager->dragMode = MBIND_INVALID;
-
- g_pCompositor->updateWorkspaceWindows(lastDraggedWindow->workspaceID());
- g_pCompositor->updateWorkspaceWindowData(lastDraggedWindow->workspaceID());
- g_pLayoutManager->getCurrentLayout()->recalculateMonitor(lastDraggedWindow->m_iMonitorID);
- g_pCompositor->updateAllWindowsAnimatedDecorationValues();
-
+ changeMouseBindMode(MBIND_INVALID);
return true;
}
- m_bIsMouseBindActive = false;
-
return false;
}
@@ -540,10 +527,7 @@ bool CKeybindManager::onMouseEvent(const IPointer::SButtonEvent& e) {
}
void CKeybindManager::resizeWithBorder(const IPointer::SButtonEvent& e) {
- if (e.state == WL_POINTER_BUTTON_STATE_PRESSED)
- mouse("1resizewindow");
- else
- mouse("0resizewindow");
+ changeMouseBindMode(e.state == WL_POINTER_BUTTON_STATE_PRESSED ? MBIND_RESIZE : MBIND_INVALID);
}
void CKeybindManager::onSwitchEvent(const std::string& switchName) {
@@ -971,7 +955,8 @@ static void toggleActiveFloatingCore(std::string args, std::optional<bool> float
return;
// remove drag status
- g_pInputManager->currentlyDraggedWindow.reset();
+ if (!g_pInputManager->currentlyDraggedWindow.expired())
+ g_pKeybindManager->changeMouseBindMode(MBIND_INVALID);
if (PWINDOW->m_sGroupData.pNextWindow.lock() && PWINDOW->m_sGroupData.pNextWindow.lock() != PWINDOW) {
const auto PCURRENT = PWINDOW->getGroupCurrent();
@@ -2365,55 +2350,50 @@ void CKeybindManager::mouse(std::string args) {
const auto ARGS = CVarList(args.substr(1), 2, ' ');
const auto PRESSED = args[0] == '1';
+ if (!PRESSED) {
+ changeMouseBindMode(MBIND_INVALID);
+ return;
+ }
+
if (ARGS[0] == "movewindow") {
- if (PRESSED && g_pInputManager->dragMode == MBIND_INVALID) {
- g_pKeybindManager->m_bIsMouseBindActive = true;
+ changeMouseBindMode(MBIND_MOVE);
+ } else {
+ try {
+ switch (std::stoi(ARGS[1])) {
+ case 1: changeMouseBindMode(MBIND_RESIZE_FORCE_RATIO); break;
+ case 2: changeMouseBindMode(MBIND_RESIZE_BLOCK_RATIO); break;
+ default: changeMouseBindMode(MBIND_RESIZE);
+ }
+ } catch (std::exception& e) { changeMouseBindMode(MBIND_RESIZE); }
+ }
+}
- const auto mouseCoords = g_pInputManager->getMouseCoordsInternal();
- PHLWINDOW pWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
+void CKeybindManager::changeMouseBindMode(const eMouseBindMode MODE) {
+ if (MODE != MBIND_INVALID) {
+ if (!g_pInputManager->currentlyDraggedWindow.expired() || g_pInputManager->dragMode != MBIND_INVALID)
+ return;
- if (pWindow && !pWindow->m_bIsFullscreen)
- pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_START, mouseCoords);
+ const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal();
+ const PHLWINDOW PWINDOW = g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
- if (g_pInputManager->currentlyDraggedWindow.expired())
- g_pInputManager->currentlyDraggedWindow = pWindow;
+ if (!PWINDOW)
+ return;
- g_pInputManager->dragMode = MBIND_MOVE;
- g_pLayoutManager->getCurrentLayout()->onBeginDragWindow();
- } else if (!PRESSED && g_pInputManager->dragMode == MBIND_MOVE) {
- g_pKeybindManager->m_bIsMouseBindActive = false;
+ if (!PWINDOW->m_bIsFullscreen && MODE == MBIND_MOVE)
+ PWINDOW->checkInputOnDecos(INPUT_TYPE_DRAG_START, MOUSECOORDS);
- if (!g_pInputManager->currentlyDraggedWindow.expired()) {
- g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
- g_pInputManager->currentlyDraggedWindow.reset();
- g_pInputManager->dragMode = MBIND_INVALID;
- }
- }
- } else if (ARGS[0] == "resizewindow") {
- if (PRESSED && g_pInputManager->dragMode == MBIND_INVALID) {
- g_pKeybindManager->m_bIsMouseBindActive = true;
-
- g_pInputManager->currentlyDraggedWindow =
- g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
-
- try {
- switch (std::stoi(ARGS[1])) {
- case 1: g_pInputManager->dragMode = MBIND_RESIZE_FORCE_RATIO; break;
- case 2: g_pInputManager->dragMode = MBIND_RESIZE_BLOCK_RATIO; break;
- default: g_pInputManager->dragMode = MBIND_RESIZE;
- }
- } catch (std::exception& e) { g_pInputManager->dragMode = MBIND_RESIZE; }
- g_pLayoutManager->getCurrentLayout()->onBeginDragWindow();
- } else if (!PRESSED &&
- (g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO || g_pInputManager->dragMode == MBIND_RESIZE)) {
- g_pKeybindManager->m_bIsMouseBindActive = false;
-
- if (!g_pInputManager->currentlyDraggedWindow.expired()) {
- g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
- g_pInputManager->currentlyDraggedWindow.reset();
- g_pInputManager->dragMode = MBIND_INVALID;
- }
- }
+ if (g_pInputManager->currentlyDraggedWindow.expired())
+ g_pInputManager->currentlyDraggedWindow = PWINDOW;
+
+ g_pInputManager->dragMode = MODE;
+
+ g_pLayoutManager->getCurrentLayout()->onBeginDragWindow();
+ } else {
+ if (g_pInputManager->currentlyDraggedWindow.expired() || g_pInputManager->dragMode == MBIND_INVALID)
+ return;
+
+ g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
+ g_pInputManager->dragMode = MODE;
}
}
diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp
index 7201df04..26a6345b 100644
--- a/src/managers/KeybindManager.hpp
+++ b/src/managers/KeybindManager.hpp
@@ -105,6 +105,8 @@ class CKeybindManager {
//we also store the keyboard pointer (in the string) to differentiate between different keyboard (layouts)
std::unordered_map<std::string, xkb_keycode_t> m_mKeyToCodeCache;
+ static void changeMouseBindMode(const eMouseBindMode mode);
+
private:
std::deque<SPressedKeyWithMods> m_dPressedKeys;
@@ -116,7 +118,6 @@ class CKeybindManager {
uint32_t m_uLastCode = 0;
uint32_t m_uLastMouseCode = 0;
- bool m_bIsMouseBindActive = false;
std::vector<SKeybind*> m_vPressedSpecialBinds;
int m_iPassPressed = -1; // used for pass
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index 7d2e7a0e..619bfab7 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -1677,7 +1677,7 @@ void CInputManager::releaseAllMouseButtons() {
void CInputManager::setCursorIconOnBorder(PHLWINDOW w) {
// do not override cursor icons set by mouse binds
- if (g_pKeybindManager->m_bIsMouseBindActive) {
+ if (g_pInputManager->currentlyDraggedWindow.expired()) {
m_eBorderIconDirection = BORDERICON_NONE;
return;
}