mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-22 20:09:49 +01:00
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
This commit is contained in:
parent
ae638d997d
commit
ad711ef421
6 changed files with 58 additions and 79 deletions
|
@ -477,13 +477,7 @@ void unregisterVar(void* ptr) {
|
|||
|
||||
void CWindow::onUnmap() {
|
||||
static auto PCLOSEONLASTSPECIAL = CConfigValue<Hyprlang::INT>("misc:close_special_on_empty");
|
||||
|
||||
if (g_pCompositor->m_pLastWindow.lock().get() == this)
|
||||
g_pCompositor->m_pLastWindow.reset();
|
||||
if (g_pInputManager->currentlyDraggedWindow.lock().get() == this)
|
||||
g_pInputManager->currentlyDraggedWindow.reset();
|
||||
|
||||
static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking");
|
||||
static auto PINITIALWSTRACKING = CConfigValue<Hyprlang::INT>("misc:initial_workspace_tracking");
|
||||
|
||||
if (!m_szInitialWorkspaceToken.empty()) {
|
||||
const auto TOKEN = g_pTokenManager->getToken(m_szInitialWorkspaceToken);
|
||||
|
|
|
@ -627,6 +627,9 @@ void Events::listener_unmapWindow(void* owner, void* data) {
|
|||
g_pInputManager->releaseAllMouseButtons();
|
||||
}
|
||||
|
||||
if (PWINDOW == g_pInputManager->currentlyDraggedWindow.lock())
|
||||
g_pKeybindManager->changeMouseBindMode(MBIND_INVALID);
|
||||
|
||||
// remove the fullscreen window status from workspace if we closed it
|
||||
const auto PWORKSPACE = PWINDOW->m_pWorkspace;
|
||||
|
||||
|
|
|
@ -187,7 +187,7 @@ void IHyprLayout::onBeginDragWindow() {
|
|||
// Window will be floating. Let's check if it's valid. It should be, but I don't like crashing.
|
||||
if (!validMapped(DRAGGINGWINDOW)) {
|
||||
Debug::log(ERR, "Dragging attempted on an invalid window!");
|
||||
g_pInputManager->currentlyDraggedWindow.reset();
|
||||
g_pKeybindManager->changeMouseBindMode(MBIND_INVALID);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ void IHyprLayout::onBeginDragWindow() {
|
|||
|
||||
if (PWORKSPACE->m_bHasFullscreenWindow && (!DRAGGINGWINDOW->m_bCreatedOverFullscreen || !DRAGGINGWINDOW->m_bIsFloating)) {
|
||||
Debug::log(LOG, "Rejecting drag on a fullscreen workspace. (window under fullscreen)");
|
||||
g_pInputManager->currentlyDraggedWindow.reset();
|
||||
g_pKeybindManager->changeMouseBindMode(MBIND_INVALID);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -288,7 +288,6 @@ void IHyprLayout::onEndDragWindow() {
|
|||
}
|
||||
|
||||
g_pInputManager->unsetCursorImage();
|
||||
|
||||
g_pInputManager->currentlyDraggedWindow.reset();
|
||||
g_pInputManager->m_bWasDraggingWindow = true;
|
||||
|
||||
|
@ -325,12 +324,14 @@ void IHyprLayout::onEndDragWindow() {
|
|||
}
|
||||
|
||||
void IHyprLayout::onMouseMove(const Vector2D& mousePos) {
|
||||
if (g_pInputManager->currentlyDraggedWindow.expired())
|
||||
return;
|
||||
|
||||
const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow.lock();
|
||||
|
||||
// Window invalid or drag begin size 0,0 meaning we rejected it.
|
||||
if (!validMapped(DRAGGINGWINDOW) || m_vBeginDragSizeXY == Vector2D()) {
|
||||
onEndDragWindow();
|
||||
g_pInputManager->currentlyDraggedWindow.reset();
|
||||
if ((!validMapped(DRAGGINGWINDOW) || m_vBeginDragSizeXY == Vector2D())) {
|
||||
g_pKeybindManager->changeMouseBindMode(MBIND_INVALID);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
||||
const auto mouseCoords = g_pInputManager->getMouseCoordsInternal();
|
||||
PHLWINDOW pWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING);
|
||||
|
||||
if (pWindow && !pWindow->m_bIsFullscreen)
|
||||
pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_START, mouseCoords);
|
||||
|
||||
if (g_pInputManager->currentlyDraggedWindow.expired())
|
||||
g_pInputManager->currentlyDraggedWindow = pWindow;
|
||||
|
||||
g_pInputManager->dragMode = MBIND_MOVE;
|
||||
g_pLayoutManager->getCurrentLayout()->onBeginDragWindow();
|
||||
} else if (!PRESSED && g_pInputManager->dragMode == MBIND_MOVE) {
|
||||
g_pKeybindManager->m_bIsMouseBindActive = false;
|
||||
|
||||
if (!g_pInputManager->currentlyDraggedWindow.expired()) {
|
||||
g_pLayoutManager->getCurrentLayout()->onEndDragWindow();
|
||||
g_pInputManager->currentlyDraggedWindow.reset();
|
||||
g_pInputManager->dragMode = MBIND_INVALID;
|
||||
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);
|
||||
}
|
||||
}
|
||||
} else if (ARGS[0] == "resizewindow") {
|
||||
if (PRESSED && g_pInputManager->dragMode == MBIND_INVALID) {
|
||||
g_pKeybindManager->m_bIsMouseBindActive = true;
|
||||
} catch (std::exception& e) { changeMouseBindMode(MBIND_RESIZE); }
|
||||
}
|
||||
}
|
||||
|
||||
g_pInputManager->currentlyDraggedWindow =
|
||||
g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), 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;
|
||||
|
||||
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;
|
||||
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_pLayoutManager->getCurrentLayout()->onEndDragWindow();
|
||||
g_pInputManager->currentlyDraggedWindow.reset();
|
||||
g_pInputManager->dragMode = MBIND_INVALID;
|
||||
}
|
||||
}
|
||||
if (!PWINDOW)
|
||||
return;
|
||||
|
||||
if (!PWINDOW->m_bIsFullscreen && MODE == MBIND_MOVE)
|
||||
PWINDOW->checkInputOnDecos(INPUT_TYPE_DRAG_START, MOUSECOORDS);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue