aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorVaxry <[email protected]>2024-12-15 23:54:05 +0000
committerVaxry <[email protected]>2024-12-15 23:54:14 +0000
commitde3ad245dcbcd42c88e9afc48264bdb8f2356c15 (patch)
treec3c47eaeb05eede32d246cbb53bcaf8031348ca4
parentdb249648776875ce3142141d0d3055e43ce606aa (diff)
downloadHyprland-de3ad245dcbcd42c88e9afc48264bdb8f2356c15.tar.gz
Hyprland-de3ad245dcbcd42c88e9afc48264bdb8f2356c15.zip
input: add warp_back_after_non_mouse_input
adds cursor:warp_back_after_non_mouse_input fixes #8675
-rw-r--r--src/config/ConfigManager.cpp1
-rw-r--r--src/devices/IPointer.hpp3
-rw-r--r--src/devices/Mouse.cpp3
-rw-r--r--src/managers/input/InputManager.cpp25
-rw-r--r--src/managers/input/InputManager.hpp7
5 files changed, 36 insertions, 3 deletions
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index b80fd427..36e73422 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -587,6 +587,7 @@ CConfigManager::CConfigManager() {
m_pConfig->addConfigValue("cursor:hide_on_key_press", Hyprlang::INT{0});
m_pConfig->addConfigValue("cursor:hide_on_touch", Hyprlang::INT{1});
m_pConfig->addConfigValue("cursor:use_cpu_buffer", Hyprlang::INT{0});
+ m_pConfig->addConfigValue("cursor:warp_back_after_non_mouse_input", Hyprlang::INT{0});
m_pConfig->addConfigValue("autogenerated", Hyprlang::INT{0});
diff --git a/src/devices/IPointer.hpp b/src/devices/IPointer.hpp
index 503a690e..ea9cb9f4 100644
--- a/src/devices/IPointer.hpp
+++ b/src/devices/IPointer.hpp
@@ -19,6 +19,7 @@ class IPointer : public IHID {
struct SMotionEvent {
uint32_t timeMs = 0;
Vector2D delta, unaccel;
+ bool mouse = false;
};
struct SMotionAbsoluteEvent {
@@ -31,6 +32,7 @@ class IPointer : public IHID {
uint32_t timeMs = 0;
uint32_t button = 0;
wl_pointer_button_state state = WL_POINTER_BUTTON_STATE_PRESSED;
+ bool mouse = false;
};
struct SAxisEvent {
@@ -40,6 +42,7 @@ class IPointer : public IHID {
wl_pointer_axis_relative_direction relativeDirection = WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL;
double delta = 0.0;
int32_t deltaDiscrete = 0;
+ bool mouse = false;
};
struct SSwipeBeginEvent {
diff --git a/src/devices/Mouse.cpp b/src/devices/Mouse.cpp
index ae89ed92..41652ce4 100644
--- a/src/devices/Mouse.cpp
+++ b/src/devices/Mouse.cpp
@@ -26,6 +26,7 @@ CMouse::CMouse(SP<Aquamarine::IPointer> mouse_) : mouse(mouse_) {
.timeMs = E.timeMs,
.delta = E.delta,
.unaccel = E.unaccel,
+ .mouse = true,
});
});
@@ -46,6 +47,7 @@ CMouse::CMouse(SP<Aquamarine::IPointer> mouse_) : mouse(mouse_) {
.timeMs = E.timeMs,
.button = E.button,
.state = E.pressed ? WL_POINTER_BUTTON_STATE_PRESSED : WL_POINTER_BUTTON_STATE_RELEASED,
+ .mouse = true,
});
});
@@ -59,6 +61,7 @@ CMouse::CMouse(SP<Aquamarine::IPointer> mouse_) : mouse(mouse_) {
.relativeDirection = (wl_pointer_axis_relative_direction)E.direction,
.delta = E.delta,
.deltaDiscrete = E.discrete,
+ .mouse = true,
});
});
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index fdaa6bfa..cccaa43e 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -94,13 +94,19 @@ void CInputManager::onMouseMoved(IPointer::SMotionEvent e) {
PROTO::relativePointer->sendRelativeMotion((uint64_t)e.timeMs * 1000, DELTA, e.unaccel);
+ if (e.mouse)
+ recheckMouseWarpOnMouseInput();
+
g_pPointerManager->move(DELTA);
- mouseMoveUnified(e.timeMs);
+ mouseMoveUnified(e.timeMs, false, e.mouse);
m_tmrLastCursorMovement.reset();
m_bLastInputTouch = false;
+
+ if (e.mouse)
+ m_vLastMousePos = getMouseCoordsInternal();
}
void CInputManager::onMouseWarp(IPointer::SMotionAbsoluteEvent e) {
@@ -138,7 +144,9 @@ void CInputManager::sendMotionEventsToFocused() {
g_pSeatManager->setPointerFocus(g_pCompositor->m_pLastFocus.lock(), LOCAL);
}
-void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
+void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) {
+ m_bLastInputMouse = mouse;
+
if (!g_pCompositor->m_bReadyToProcess || g_pCompositor->m_bIsShuttingDown || g_pCompositor->m_bUnsafeState)
return;
@@ -534,6 +542,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
void CInputManager::onMouseButton(IPointer::SButtonEvent e) {
EMIT_HOOK_EVENT_CANCELLABLE("mouseButton", e);
+ if (e.mouse)
+ recheckMouseWarpOnMouseInput();
+
m_tmrLastCursorMovement.reset();
if (e.state == WL_POINTER_BUTTON_STATE_PRESSED) {
@@ -768,6 +779,9 @@ void CInputManager::onMouseWheel(IPointer::SAxisEvent e) {
const auto EMAP = std::unordered_map<std::string, std::any>{{"event", e}};
EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP);
+ if (e.mouse)
+ recheckMouseWarpOnMouseInput();
+
bool passEvent = g_pKeybindManager->onAxisEvent(e);
if (!passEvent)
@@ -1790,3 +1804,10 @@ void CInputManager::setCursorIconOnBorder(PHLWINDOW w) {
case BORDERICON_DOWN_RIGHT: setCursorImageUntilUnset("bottom_right_corner"); break;
}
}
+
+void CInputManager::recheckMouseWarpOnMouseInput() {
+ static auto PWARPFORNONMOUSE = CConfigValue<Hyprlang::INT>("cursor:warp_back_after_non_mouse_input");
+
+ if (!m_bLastInputMouse && *PWARPFORNONMOUSE)
+ g_pPointerManager->warpTo(m_vLastMousePos);
+}
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index e56aaf6f..bc73d2cc 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -239,7 +239,8 @@ class CInputManager {
uint32_t m_uiCapabilities = 0;
- void mouseMoveUnified(uint32_t, bool refocus = false);
+ void mouseMoveUnified(uint32_t, bool refocus = false, bool mouse = false);
+ void recheckMouseWarpOnMouseInput();
SP<CTabletTool> ensureTabletToolPresent(SP<Aquamarine::ITabletTool>);
@@ -250,6 +251,10 @@ class CInputManager {
PHLLSREF m_pFoundLSToFocus;
PHLWINDOWREF m_pFoundWindowToFocus;
+ // used for warping back after non-mouse input
+ Vector2D m_vLastMousePos = {};
+ bool m_bLastInputMouse = true;
+
// for holding focus on buttons held
bool m_bFocusHeldByButtons = false;
bool m_bRefocusHeldByButtons = false;