mirror of
https://github.com/hyprwm/Hyprland
synced 2024-12-23 08:29:50 +01:00
input: add warp_back_after_non_mouse_input
adds cursor:warp_back_after_non_mouse_input fixes #8675
This commit is contained in:
parent
db24964877
commit
de3ad245dc
5 changed files with 36 additions and 3 deletions
|
@ -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});
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue