2022-03-17 15:53:45 +01:00
# include "InputManager.hpp"
2022-06-09 12:46:55 +02:00
# include "../../Compositor.hpp"
2024-07-21 13:09:54 +02:00
# include <aquamarine/output/Output.hpp>
2024-06-03 16:47:02 -04:00
# include <cstdint>
2025-04-25 16:38:31 +02:00
# include <hyprutils/math/Vector2D.hpp>
2023-03-01 14:06:52 +00:00
# include <ranges>
2025-10-20 13:22:50 +02:00
# include <algorithm>
2024-03-03 18:39:20 +00:00
# include "../../config/ConfigValue.hpp"
2025-04-15 23:00:40 +00:00
# include "../../config/ConfigManager.hpp"
2024-03-20 01:44:51 +00:00
# include "../../desktop/Window.hpp"
2025-01-17 15:21:35 +00:00
# include "../../desktop/LayerSurface.hpp"
2024-04-21 01:47:38 +01:00
# include "../../protocols/CursorShape.hpp"
2024-04-21 16:29:30 +01:00
# include "../../protocols/IdleInhibit.hpp"
2024-04-21 19:30:23 +01:00
# include "../../protocols/RelativePointer.hpp"
2024-04-26 23:55:41 +01:00
# include "../../protocols/PointerConstraints.hpp"
2025-08-28 11:20:29 +02:00
# include "../../protocols/PointerGestures.hpp"
2024-04-29 17:42:07 +01:00
# include "../../protocols/IdleNotify.hpp"
2024-04-30 16:32:05 +01:00
# include "../../protocols/SessionLock.hpp"
2024-05-01 16:41:17 +01:00
# include "../../protocols/InputMethodV2.hpp"
2024-05-03 00:31:48 +01:00
# include "../../protocols/VirtualKeyboard.hpp"
2024-05-03 01:27:59 +01:00
# include "../../protocols/VirtualPointer.hpp"
2024-05-09 21:47:21 +01:00
# include "../../protocols/LayerShell.hpp"
2024-05-10 18:27:57 +01:00
# include "../../protocols/core/Seat.hpp"
2024-05-11 17:13:20 +01:00
# include "../../protocols/core/DataDevice.hpp"
2024-07-27 17:49:27 +02:00
# include "../../protocols/core/Compositor.hpp"
2024-05-10 23:28:33 +01:00
# include "../../protocols/XDGShell.hpp"
2024-04-21 01:47:38 +01:00
2024-05-03 22:34:10 +01:00
# include "../../devices/Mouse.hpp"
# include "../../devices/VirtualPointer.hpp"
# include "../../devices/Keyboard.hpp"
# include "../../devices/VirtualKeyboard.hpp"
# include "../../devices/TouchDevice.hpp"
2024-05-05 22:18:10 +01:00
# include "../../managers/PointerManager.hpp"
2024-05-10 18:27:57 +01:00
# include "../../managers/SeatManager.hpp"
2024-09-09 20:29:00 +00:00
# include "../../managers/KeybindManager.hpp"
2025-01-17 15:21:35 +00:00
# include "../../render/Renderer.hpp"
# include "../../managers/HookSystemManager.hpp"
# include "../../managers/EventManager.hpp"
# include "../../managers/LayoutManager.hpp"
2025-05-18 18:13:20 +01:00
# include "../../managers/permissions/DynamicPermissionManager.hpp"
2024-05-05 22:18:10 +01:00
2025-04-16 01:37:48 +01:00
# include "../../helpers/time/Time.hpp"
2025-08-04 16:29:39 -03:00
# include "../../helpers/MiscFunctions.hpp"
2025-04-16 01:37:48 +01:00
2025-08-28 11:20:29 +02:00
# include "trackpad/TrackpadGestures.hpp"
2024-07-21 13:09:54 +02:00
# include <aquamarine/input/Input.hpp>
2024-04-21 01:47:38 +01:00
CInputManager : : CInputManager ( ) {
2025-07-08 09:56:40 -07:00
m_listeners . setCursorShape = PROTO : : cursorShape - > m_events . setShape . listen ( [ this ] ( const CCursorShapeProtocol : : SSetShapeEvent & event ) {
2024-04-21 01:47:38 +01:00
if ( ! cursorImageUnlocked ( ) )
return ;
2025-05-02 17:07:20 +02:00
if ( ! g_pSeatManager - > m_state . pointerFocusResource )
2024-04-21 15:17:05 +01:00
return ;
2025-05-02 17:07:20 +02:00
if ( wl_resource_get_client ( event . pMgr - > resource ( ) ) ! = g_pSeatManager - > m_state . pointerFocusResource - > client ( ) )
2024-04-21 01:47:38 +01:00
return ;
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " cursorImage request: shape {} -> {} " , sc < uint32_t > ( event . shape ) , event . shapeName ) ;
2024-04-21 01:47:38 +01:00
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . wlSurface - > unassign ( ) ;
m_cursorSurfaceInfo . vHotspot = { } ;
m_cursorSurfaceInfo . name = event . shapeName ;
m_cursorSurfaceInfo . hidden = false ;
2024-04-21 01:47:38 +01:00
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . inUse = true ;
g_pHyprRenderer - > setCursorFromName ( m_cursorSurfaceInfo . name ) ;
2024-04-21 01:47:38 +01:00
} ) ;
2024-04-21 16:29:30 +01:00
2025-07-08 09:56:40 -07:00
m_listeners . newIdleInhibitor = PROTO : : idleInhibit - > m_events . newIdleInhibitor . listen ( [ this ] ( const auto & data ) { this - > newIdleInhibitor ( data ) ; } ) ;
m_listeners . newVirtualKeyboard = PROTO : : virtualKeyboard - > m_events . newKeyboard . listen ( [ this ] ( const auto & keyboard ) {
this - > newVirtualKeyboard ( keyboard ) ;
2024-06-08 23:15:57 +08:00
updateCapabilities ( ) ;
} ) ;
2025-07-08 09:56:40 -07:00
m_listeners . newVirtualMouse = PROTO : : virtualPointer - > m_events . newPointer . listen ( [ this ] ( const auto & mouse ) {
this - > newVirtualMouse ( mouse ) ;
2024-06-08 23:15:57 +08:00
updateCapabilities ( ) ;
} ) ;
2025-07-08 09:56:40 -07:00
m_listeners . setCursor = g_pSeatManager - > m_events . setCursor . listen ( [ this ] ( const auto & event ) { this - > processMouseRequest ( event ) ; } ) ;
2024-06-08 10:07:59 +02:00
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . wlSurface = CWLSurface : : create ( ) ;
2024-04-21 01:47:38 +01:00
}
2022-03-17 15:53:45 +01:00
2023-11-12 14:03:46 +00:00
CInputManager : : ~ CInputManager ( ) {
2025-05-01 23:57:11 +02:00
m_constraints . clear ( ) ;
m_keyboards . clear ( ) ;
m_pointers . clear ( ) ;
m_touches . clear ( ) ;
m_tablets . clear ( ) ;
m_tabletTools . clear ( ) ;
m_tabletPads . clear ( ) ;
m_idleInhibitors . clear ( ) ;
m_switches . clear ( ) ;
2023-11-12 14:03:46 +00:00
}
2024-05-05 22:18:10 +01:00
void CInputManager : : onMouseMoved ( IPointer : : SMotionEvent e ) {
2024-08-17 17:33:16 +01:00
static auto PNOACCEL = CConfigValue < Hyprlang : : INT > ( " input:force_no_accel " ) ;
2022-03-17 15:53:45 +01:00
2025-03-03 15:56:01 -05:00
Vector2D delta = e . delta ;
Vector2D unaccel = e . unaccel ;
2025-03-06 11:33:01 -05:00
if ( e . device ) {
2025-04-29 19:51:07 +02:00
if ( e . device - > m_isTouchpad ) {
if ( e . device - > m_flipX ) {
2025-03-06 11:33:01 -05:00
delta . x = - delta . x ;
unaccel . x = - unaccel . x ;
}
2025-04-29 19:51:07 +02:00
if ( e . device - > m_flipY ) {
2025-03-06 11:33:01 -05:00
delta . y = - delta . y ;
unaccel . y = - unaccel . y ;
}
2025-03-03 15:56:01 -05:00
}
}
const auto DELTA = * PNOACCEL = = 1 ? unaccel : delta ;
2022-06-06 12:08:33 +02:00
2025-05-02 17:07:20 +02:00
if ( g_pSeatManager - > m_isPointerFrameSkipped )
2025-08-14 19:44:56 +05:00
g_pPointerManager - > storeMovement ( e . timeMs , DELTA , unaccel ) ;
2024-10-12 03:29:51 +03:00
else
2025-08-14 19:44:56 +05:00
g_pPointerManager - > setStoredMovement ( e . timeMs , DELTA , unaccel ) ;
2024-10-12 03:29:51 +03:00
2025-08-14 19:44:56 +05:00
PROTO : : relativePointer - > sendRelativeMotion ( sc < uint64_t > ( e . timeMs ) * 1000 , DELTA , unaccel ) ;
2022-04-17 21:40:04 +02:00
2024-12-15 23:54:05 +00:00
if ( e . mouse )
recheckMouseWarpOnMouseInput ( ) ;
2024-08-17 17:33:16 +01:00
g_pPointerManager - > move ( DELTA ) ;
2022-03-18 20:42:49 +01:00
2024-12-15 23:54:05 +00:00
mouseMoveUnified ( e . timeMs , false , e . mouse ) ;
2022-06-24 23:27:02 +02:00
2025-05-01 23:57:11 +02:00
m_lastCursorMovement . reset ( ) ;
2023-01-17 11:47:39 +01:00
2025-05-01 23:57:11 +02:00
m_lastInputTouch = false ;
2024-12-15 23:54:05 +00:00
if ( e . mouse )
2025-05-01 23:57:11 +02:00
m_lastMousePos = getMouseCoordsInternal ( ) ;
2022-03-17 16:56:33 +01:00
}
2024-05-05 22:18:10 +01:00
void CInputManager : : onMouseWarp ( IPointer : : SMotionAbsoluteEvent e ) {
g_pPointerManager - > warpAbsolute ( e . absolute , e . device ) ;
2022-03-18 20:42:49 +01:00
2024-05-05 22:18:10 +01:00
mouseMoveUnified ( e . timeMs ) ;
2022-06-24 23:27:02 +02:00
2025-05-01 23:57:11 +02:00
m_lastCursorMovement . reset ( ) ;
2023-01-17 11:47:39 +01:00
2025-05-01 23:57:11 +02:00
m_lastInputTouch = false ;
2022-03-18 23:52:36 +01:00
}
2023-01-31 00:26:15 +00:00
void CInputManager : : simulateMouseMovement ( ) {
2025-05-01 23:57:11 +02:00
m_lastCursorPosFloored = m_lastCursorPosFloored - Vector2D ( 1 , 1 ) ; // hack: force the mouseMoveUnified to report without making this a refocus.
2025-04-16 01:37:48 +01:00
mouseMoveUnified ( Time : : millis ( Time : : steadyNow ( ) ) ) ;
2023-01-31 00:26:15 +00:00
}
2023-09-13 11:33:36 +01:00
void CInputManager : : sendMotionEventsToFocused ( ) {
2025-04-22 15:23:29 +02:00
if ( ! g_pCompositor - > m_lastFocus | | isConstrained ( ) )
2023-09-13 11:33:36 +01:00
return ;
// todo: this sucks ass
2025-04-22 15:23:29 +02:00
const auto PWINDOW = g_pCompositor - > getWindowFromSurface ( g_pCompositor - > m_lastFocus . lock ( ) ) ;
const auto PLS = g_pCompositor - > getLayerSurfaceFromSurface ( g_pCompositor - > m_lastFocus . lock ( ) ) ;
2023-09-13 11:33:36 +01:00
2025-04-28 22:25:22 +02:00
const auto LOCAL = getMouseCoordsInternal ( ) - ( PWINDOW ? PWINDOW - > m_realPosition - > goal ( ) : ( PLS ? Vector2D { PLS - > m_geometry . x , PLS - > m_geometry . y } : Vector2D { } ) ) ;
2023-09-13 11:33:36 +01:00
2025-05-01 23:57:11 +02:00
m_emptyFocusCursorSet = false ;
2024-03-09 18:12:55 +00:00
2025-04-22 15:23:29 +02:00
g_pSeatManager - > setPointerFocus ( g_pCompositor - > m_lastFocus . lock ( ) , LOCAL ) ;
2023-09-13 11:33:36 +01:00
}
2025-08-20 13:01:31 +02:00
void CInputManager : : mouseMoveUnified ( uint32_t time , bool refocus , bool mouse , std : : optional < Vector2D > overridePos ) {
2025-05-01 23:57:11 +02:00
m_lastInputMouse = mouse ;
2024-12-15 23:54:05 +00:00
2025-04-22 15:23:29 +02:00
if ( ! g_pCompositor - > m_readyToProcess | | g_pCompositor - > m_isShuttingDown | | g_pCompositor - > m_unsafeState )
2024-10-27 18:51:26 +01:00
return ;
2025-08-20 13:01:31 +02:00
Vector2D const mouseCoords = overridePos . value_or ( getMouseCoordsInternal ( ) ) ;
2024-10-27 18:51:26 +01:00
auto const MOUSECOORDSFLOORED = mouseCoords . floor ( ) ;
2025-05-01 23:57:11 +02:00
if ( MOUSECOORDSFLOORED = = m_lastCursorPosFloored & & ! refocus )
2024-10-27 18:51:26 +01:00
return ;
2025-02-17 04:03:27 +02:00
static auto PFOLLOWMOUSE = CConfigValue < Hyprlang : : INT > ( " input:follow_mouse " ) ;
static auto PFOLLOWMOUSETHRESHOLD = CConfigValue < Hyprlang : : FLOAT > ( " input:follow_mouse_threshold " ) ;
static auto PMOUSEREFOCUS = CConfigValue < Hyprlang : : INT > ( " input:mouse_refocus " ) ;
static auto PFOLLOWONDND = CConfigValue < Hyprlang : : INT > ( " misc:always_follow_on_dnd " ) ;
static auto PFLOATBEHAVIOR = CConfigValue < Hyprlang : : INT > ( " input:float_switch_override_focus " ) ;
static auto PMOUSEFOCUSMON = CConfigValue < Hyprlang : : INT > ( " misc:mouse_move_focuses_monitor " ) ;
static auto PRESIZEONBORDER = CConfigValue < Hyprlang : : INT > ( " general:resize_on_border " ) ;
static auto PRESIZECURSORICON = CConfigValue < Hyprlang : : INT > ( " general:hover_icon_on_border " ) ;
2024-03-03 18:39:20 +00:00
2024-05-11 17:13:20 +01:00
const auto FOLLOWMOUSE = * PFOLLOWONDND & & PROTO : : data - > dndActive ( ) ? 1 : * PFOLLOWMOUSE ;
2023-03-30 00:34:24 +01:00
2025-05-01 23:57:11 +02:00
if ( FOLLOWMOUSE = = 1 & & m_lastCursorMovement . getSeconds ( ) < 0.5 )
m_mousePosDelta + = MOUSECOORDSFLOORED . distance ( m_lastCursorPosFloored ) ;
2025-02-17 04:03:27 +02:00
else
2025-05-01 23:57:11 +02:00
m_mousePosDelta = 0 ;
2025-02-17 04:03:27 +02:00
2025-05-01 23:57:11 +02:00
m_foundSurfaceToFocus . reset ( ) ;
m_foundLSToFocus . reset ( ) ;
m_foundWindowToFocus . reset ( ) ;
2024-06-08 10:07:59 +02:00
SP < CWLSurfaceResource > foundSurface ;
Vector2D surfaceCoords ;
Vector2D surfacePos = Vector2D ( - 1337 , - 1337 ) ;
PHLWINDOW pFoundWindow ;
PHLLS pFoundLayerSurface ;
2022-10-14 20:46:32 +01:00
2023-10-21 14:52:43 +01:00
EMIT_HOOK_EVENT_CANCELLABLE ( " mouseMove " , MOUSECOORDSFLOORED ) ;
2025-05-01 23:57:11 +02:00
m_lastCursorPosFloored = MOUSECOORDSFLOORED ;
2022-07-01 17:59:11 +02:00
2025-04-22 15:23:29 +02:00
const auto PMONITOR = isLocked ( ) & & g_pCompositor - > m_lastMonitor ? g_pCompositor - > m_lastMonitor . lock ( ) : g_pCompositor - > getMonitorFromCursor ( ) ;
2022-05-18 14:57:08 +02:00
2023-05-22 05:18:07 -05:00
// this can happen if there are no displays hooked up to Hyprland
if ( PMONITOR = = nullptr )
return ;
2025-07-01 11:33:48 +02:00
if ( PMONITOR - > m_cursorZoom - > value ( ) ! = 1.f )
2023-04-16 14:48:38 +01:00
g_pHyprRenderer - > damageMonitor ( PMONITOR ) ;
2024-06-14 14:45:32 +03:00
bool skipFrameSchedule = PMONITOR - > shouldSkipScheduleFrameOnMouseEvent ( ) ;
2025-04-30 23:45:20 +02:00
if ( ! PMONITOR - > m_solitaryClient . lock ( ) & & g_pHyprRenderer - > shouldRenderCursor ( ) & & g_pPointerManager - > softwareLockedFor ( PMONITOR - > m_self . lock ( ) ) & & ! skipFrameSchedule )
2024-07-21 13:09:54 +02:00
g_pCompositor - > scheduleFrameForMonitor ( PMONITOR , Aquamarine : : IOutput : : AQ_SCHEDULE_CURSOR_MOVE ) ;
2023-07-09 00:44:26 +02:00
2023-04-25 21:50:24 +01:00
// constraints
2025-05-02 17:07:20 +02:00
if ( ! g_pSeatManager - > m_mouse . expired ( ) & & isConstrained ( ) ) {
2025-04-22 15:23:29 +02:00
const auto SURF = CWLSurface : : fromResource ( g_pCompositor - > m_lastFocus . lock ( ) ) ;
2024-10-12 03:29:51 +03:00
const auto CONSTRAINT = SURF ? SURF - > constraint ( ) : nullptr ;
2024-03-02 21:04:55 +00:00
2024-10-12 03:29:51 +03:00
if ( CONSTRAINT ) {
2024-03-02 21:04:55 +00:00
if ( CONSTRAINT - > isLocked ( ) ) {
const auto HINT = CONSTRAINT - > logicPositionHint ( ) ;
2024-05-05 22:18:10 +01:00
g_pCompositor - > warpCursorTo ( HINT , true ) ;
2023-04-25 21:50:24 +01:00
} else {
2024-03-02 21:04:55 +00:00
const auto RG = CONSTRAINT - > logicConstraintRegion ( ) ;
const auto CLOSEST = RG . closestPoint ( mouseCoords ) ;
const auto BOX = SURF - > getSurfaceBoxGlobal ( ) ;
2025-04-28 22:25:22 +02:00
const auto CLOSESTLOCAL = ( CLOSEST - ( BOX . has_value ( ) ? BOX - > pos ( ) : Vector2D { } ) ) * ( SURF - > getWindow ( ) ? SURF - > getWindow ( ) - > m_X11SurfaceScaledBy : 1.0 ) ;
2023-04-25 21:50:24 +01:00
2024-05-05 22:18:10 +01:00
g_pCompositor - > warpCursorTo ( CLOSEST , true ) ;
2024-05-10 18:27:57 +01:00
g_pSeatManager - > sendPointerMotion ( time , CLOSESTLOCAL ) ;
2025-08-14 19:44:56 +05:00
PROTO : : relativePointer - > sendRelativeMotion ( sc < uint64_t > ( time ) * 1000 , { } , { } ) ;
2023-04-25 21:50:24 +01:00
}
2024-03-02 21:04:55 +00:00
return ;
} else
2025-08-14 19:44:56 +05:00
Debug : : log ( ERR , " BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x} " , rc < uintptr_t > ( SURF . get ( ) ) , rc < uintptr_t > ( CONSTRAINT . get ( ) ) ) ;
2023-04-25 21:50:24 +01:00
}
2025-05-01 23:57:11 +02:00
if ( PMONITOR ! = g_pCompositor - > m_lastMonitor & & ( * PMOUSEFOCUSMON | | refocus ) & & m_forcedFocus . expired ( ) )
2024-09-04 15:59:00 +00:00
g_pCompositor - > setActiveMonitor ( PMONITOR ) ;
2025-05-18 19:34:14 +02:00
// check for windows that have focus priority like our permission popups
pFoundWindow = g_pCompositor - > vectorToWindowUnified ( mouseCoords , FOCUS_PRIORITY ) ;
if ( pFoundWindow )
foundSurface = g_pCompositor - > vectorWindowToSurface ( mouseCoords , pFoundWindow , surfaceCoords ) ;
if ( ! foundSurface & & g_pSessionLockManager - > isSessionLocked ( ) ) {
2025-04-25 16:38:31 +02:00
// set keyboard focus on session lock surface regardless of layers
2025-04-30 23:45:20 +02:00
const auto PSESSIONLOCKSURFACE = g_pSessionLockManager - > getSessionLockSurfaceForMonitor ( PMONITOR - > m_id ) ;
2025-04-25 16:38:31 +02:00
const auto foundLockSurface = PSESSIONLOCKSURFACE ? PSESSIONLOCKSURFACE - > surface - > surface ( ) : nullptr ;
g_pCompositor - > focusSurface ( foundLockSurface ) ;
// search for interactable abovelock surfaces for pointer focus, or use session lock surface if not found
2025-04-30 23:45:20 +02:00
for ( auto & lsl : PMONITOR - > m_layerSurfaceLayers | std : : views : : reverse ) {
2025-04-25 16:38:31 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & lsl , & surfaceCoords , & pFoundLayerSurface , true ) ;
if ( foundSurface )
break ;
}
if ( ! foundSurface ) {
2025-04-30 23:45:20 +02:00
surfaceCoords = mouseCoords - PMONITOR - > m_position ;
2025-04-25 16:38:31 +02:00
foundSurface = foundLockSurface ;
}
2024-09-04 15:59:00 +00:00
2025-05-03 16:07:02 +02:00
if ( refocus ) {
m_foundLSToFocus = pFoundLayerSurface ;
m_foundWindowToFocus = pFoundWindow ;
m_foundSurfaceToFocus = foundSurface ;
}
2025-04-25 16:38:31 +02:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceCoords ) ;
g_pSeatManager - > sendPointerMotion ( time , surfaceCoords ) ;
2024-09-04 15:59:00 +00:00
return ;
}
2025-05-01 23:57:11 +02:00
PHLWINDOW forcedFocus = m_forcedFocus . lock ( ) ;
2024-09-04 15:59:00 +00:00
if ( ! forcedFocus )
forcedFocus = g_pCompositor - > getForceFocus ( ) ;
2025-05-18 19:34:14 +02:00
if ( forcedFocus & & ! foundSurface ) {
2024-09-04 15:59:00 +00:00
pFoundWindow = forcedFocus ;
2025-04-28 22:25:22 +02:00
surfacePos = pFoundWindow - > m_realPosition - > value ( ) ;
foundSurface = pFoundWindow - > m_wlSurface - > resource ( ) ;
2024-09-04 15:59:00 +00:00
}
2024-05-11 17:13:20 +01:00
// if we are holding a pointer button,
// and we're not dnd-ing, don't refocus. Keep focus on last surface.
2025-05-03 16:02:49 +02:00
if ( ! PROTO : : data - > dndActive ( ) & & ! m_currentlyHeldButtons . empty ( ) & & g_pCompositor - > m_lastFocus & & g_pCompositor - > m_lastFocus - > m_mapped & &
g_pSeatManager - > m_state . pointerFocus & & ! m_hardInput ) {
2025-05-17 19:43:12 +02:00
foundSurface = g_pSeatManager - > m_state . pointerFocus . lock ( ) ;
2024-05-18 21:20:01 +01:00
// IME popups aren't desktop-like elements
// TODO: make them.
2025-05-01 23:57:11 +02:00
CInputPopup * foundPopup = m_relay . popupFromSurface ( foundSurface ) ;
2024-05-18 21:20:01 +01:00
if ( foundPopup ) {
2025-05-01 23:57:11 +02:00
surfacePos = foundPopup - > globalBox ( ) . pos ( ) ;
m_focusHeldByButtons = true ;
m_refocusHeldByButtons = refocus ;
2024-04-07 22:15:50 +08:00
} else {
2024-06-08 10:07:59 +02:00
auto HLSurface = CWLSurface : : fromResource ( foundSurface ) ;
2024-05-18 21:20:01 +01:00
if ( HLSurface ) {
const auto BOX = HLSurface - > getSurfaceBoxGlobal ( ) ;
if ( BOX ) {
2025-03-14 20:22:39 -04:00
const auto PWINDOW = HLSurface - > getWindow ( ) ;
2024-05-18 21:20:01 +01:00
surfacePos = BOX - > pos ( ) ;
pFoundLayerSurface = HLSurface - > getLayer ( ) ;
2025-06-19 04:48:51 +08:00
if ( ! pFoundLayerSurface )
pFoundWindow = ! PWINDOW | | PWINDOW - > isHidden ( ) ? g_pCompositor - > m_lastWindow . lock ( ) : PWINDOW ;
2024-05-18 21:20:01 +01:00
} else // reset foundSurface, find one normally
foundSurface = nullptr ;
} else // reset foundSurface, find one normally
foundSurface = nullptr ;
2023-04-02 13:30:45 +01:00
}
}
2022-04-13 20:19:40 +02:00
g_pLayoutManager - > getCurrentLayout ( ) - > onMouseMove ( getMouseCoordsInternal ( ) ) ;
2022-04-01 23:31:12 +02:00
2025-04-07 20:52:11 +02:00
// forced above all
2025-05-01 23:57:11 +02:00
if ( ! g_pInputManager - > m_exclusiveLSes . empty ( ) ) {
2025-04-07 20:52:11 +02:00
if ( ! foundSurface )
2025-05-01 23:57:11 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & g_pInputManager - > m_exclusiveLSes , & surfaceCoords , & pFoundLayerSurface ) ;
2025-04-07 20:52:11 +02:00
if ( ! foundSurface ) {
2025-05-01 23:57:11 +02:00
foundSurface = ( * g_pInputManager - > m_exclusiveLSes . begin ( ) ) - > m_surface - > resource ( ) ;
surfacePos = ( * g_pInputManager - > m_exclusiveLSes . begin ( ) ) - > m_realPosition - > goal ( ) ;
2025-04-07 20:52:11 +02:00
}
}
2024-03-25 16:20:30 +00:00
if ( ! foundSurface )
foundSurface = g_pCompositor - > vectorToLayerPopupSurface ( mouseCoords , PMONITOR , & surfaceCoords , & pFoundLayerSurface ) ;
2023-11-25 22:27:57 +08:00
// overlays are above fullscreen
2022-04-25 21:49:45 +02:00
if ( ! foundSurface )
2025-04-30 23:45:20 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_layerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-04-25 21:49:45 +02:00
2023-11-25 22:27:57 +08:00
// also IME popups
if ( ! foundSurface ) {
2025-05-01 23:57:11 +02:00
auto popup = g_pInputManager - > m_relay . popupFromCoords ( mouseCoords ) ;
2023-11-25 22:27:57 +08:00
if ( popup ) {
2024-06-08 10:07:59 +02:00
foundSurface = popup - > getSurface ( ) ;
2024-03-24 16:08:25 +00:00
surfacePos = popup - > globalBox ( ) . pos ( ) ;
2023-11-25 22:27:57 +08:00
}
}
// also top layers
2022-09-19 10:23:13 +01:00
if ( ! foundSurface )
2025-04-30 23:45:20 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_layerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_TOP ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-09-19 10:23:13 +01:00
2025-07-25 15:19:23 +00:00
// then, we check if the workspace doesn't have a fullscreen window
2025-06-11 17:09:39 +02:00
const auto PWORKSPACE = PMONITOR - > m_activeSpecialWorkspace ? PMONITOR - > m_activeSpecialWorkspace : PMONITOR - > m_activeWorkspace ;
2024-10-31 00:20:32 +01:00
const auto PWINDOWIDEAL = g_pCompositor - > vectorToWindowUnified ( mouseCoords , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2025-04-25 02:37:12 +02:00
if ( PWORKSPACE - > m_hasFullscreenWindow & & ! foundSurface & & PWORKSPACE - > m_fullscreenMode = = FSMODE_FULLSCREEN ) {
2024-11-22 16:01:02 +00:00
pFoundWindow = PWORKSPACE - > getFullscreenWindow ( ) ;
2022-09-05 00:59:13 +02:00
if ( ! pFoundWindow ) {
// what the fuck, somehow happens occasionally??
2025-04-25 02:37:12 +02:00
PWORKSPACE - > m_hasFullscreenWindow = false ;
2022-09-05 00:59:13 +02:00
return ;
}
2023-09-21 23:58:54 +01:00
if ( PWINDOWIDEAL & &
2025-05-08 14:59:51 -04:00
( ( PWINDOWIDEAL - > m_isFloating & & ( PWINDOWIDEAL - > m_createdOverFullscreen | | PWINDOWIDEAL - > m_pinned ) ) /* floating over fullscreen or pinned */
2025-04-30 23:45:20 +02:00
| | ( PMONITOR - > m_activeSpecialWorkspace = = PWINDOWIDEAL - > m_workspace ) /* on an open special workspace */ ) )
2023-09-21 23:58:54 +01:00
pFoundWindow = PWINDOWIDEAL ;
2022-10-30 12:28:37 +00:00
2025-04-28 22:25:22 +02:00
if ( ! pFoundWindow - > m_isX11 ) {
2022-10-30 12:28:37 +00:00
foundSurface = g_pCompositor - > vectorWindowToSurface ( mouseCoords , pFoundWindow , surfaceCoords ) ;
2022-12-16 17:17:31 +00:00
surfacePos = Vector2D ( - 1337 , - 1337 ) ;
2022-10-30 12:28:37 +00:00
} else {
2025-04-28 22:25:22 +02:00
foundSurface = pFoundWindow - > m_wlSurface - > resource ( ) ;
surfacePos = pFoundWindow - > m_realPosition - > value ( ) ;
2022-10-30 12:28:37 +00:00
}
2022-03-21 19:18:33 +01:00
}
2022-03-20 14:36:55 +01:00
// then windows
2022-04-24 11:41:52 +02:00
if ( ! foundSurface ) {
2025-04-25 02:37:12 +02:00
if ( PWORKSPACE - > m_hasFullscreenWindow & & PWORKSPACE - > m_fullscreenMode = = FSMODE_MAXIMIZED ) {
2024-04-03 21:57:12 +01:00
if ( ! foundSurface ) {
2025-04-30 23:45:20 +02:00
if ( PMONITOR - > m_activeSpecialWorkspace ) {
2024-10-31 00:20:32 +01:00
if ( pFoundWindow ! = PWINDOWIDEAL )
pFoundWindow = g_pCompositor - > vectorToWindowUnified ( mouseCoords , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2022-07-13 18:33:36 +02:00
2024-04-03 21:57:12 +01:00
if ( pFoundWindow & & ! pFoundWindow - > onSpecialWorkspace ( ) ) {
2024-11-22 16:01:02 +00:00
pFoundWindow = PWORKSPACE - > getFullscreenWindow ( ) ;
2024-04-03 21:57:12 +01:00
}
} else {
2024-04-06 15:18:58 +01:00
// if we have a maximized window, allow focusing on a bar or something if in reserved area.
if ( g_pCompositor - > isPointOnReservedArea ( mouseCoords , PMONITOR ) ) {
2025-04-30 23:45:20 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_layerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM ] , & surfaceCoords ,
2024-04-06 15:18:58 +01:00
& pFoundLayerSurface ) ;
}
2024-04-06 18:59:23 +01:00
if ( ! foundSurface ) {
2024-10-31 00:20:32 +01:00
if ( pFoundWindow ! = PWINDOWIDEAL )
pFoundWindow = g_pCompositor - > vectorToWindowUnified ( mouseCoords , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2024-04-03 21:57:12 +01:00
2025-05-08 14:59:51 -04:00
if ( ! ( pFoundWindow & & ( pFoundWindow - > m_isFloating & & ( pFoundWindow - > m_createdOverFullscreen | | pFoundWindow - > m_pinned ) ) ) )
2024-11-22 16:01:02 +00:00
pFoundWindow = PWORKSPACE - > getFullscreenWindow ( ) ;
2024-04-06 18:59:23 +01:00
}
2024-04-03 21:57:12 +01:00
}
2022-07-06 14:58:46 +02:00
}
2024-04-03 21:57:12 +01:00
2022-08-19 17:25:07 +02:00
} else {
2024-10-31 00:20:32 +01:00
if ( pFoundWindow ! = PWINDOWIDEAL )
pFoundWindow = g_pCompositor - > vectorToWindowUnified ( mouseCoords , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2022-08-19 17:25:07 +02:00
}
2022-04-24 11:41:52 +02:00
if ( pFoundWindow ) {
2025-04-28 22:25:22 +02:00
if ( ! pFoundWindow - > m_isX11 ) {
2022-04-24 11:41:52 +02:00
foundSurface = g_pCompositor - > vectorWindowToSurface ( mouseCoords , pFoundWindow , surfaceCoords ) ;
2024-06-12 18:39:52 +02:00
if ( ! foundSurface ) {
2025-04-28 22:25:22 +02:00
foundSurface = pFoundWindow - > m_wlSurface - > resource ( ) ;
surfacePos = pFoundWindow - > m_realPosition - > value ( ) ;
2024-06-12 18:39:52 +02:00
}
2022-04-24 11:41:52 +02:00
} else {
2025-04-28 22:25:22 +02:00
foundSurface = pFoundWindow - > m_wlSurface - > resource ( ) ;
surfacePos = pFoundWindow - > m_realPosition - > value ( ) ;
2022-04-24 11:41:52 +02:00
}
2022-04-02 13:02:16 +02:00
}
2022-03-20 14:36:55 +01:00
}
2022-04-02 18:57:09 +02:00
2022-03-20 14:36:55 +01:00
// then surfaces below
if ( ! foundSurface )
2025-04-30 23:45:20 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_layerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-03-20 14:36:55 +01:00
if ( ! foundSurface )
2025-04-30 23:45:20 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_layerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-03-20 14:36:55 +01:00
2025-04-30 23:45:20 +02:00
if ( g_pPointerManager - > softwareLockedFor ( PMONITOR - > m_self . lock ( ) ) > 0 & & ! skipFrameSchedule )
2025-04-22 15:23:29 +02:00
g_pCompositor - > scheduleFrameForMonitor ( g_pCompositor - > m_lastMonitor . lock ( ) , Aquamarine : : IOutput : : AQ_SCHEDULE_CURSOR_MOVE ) ;
2022-08-28 22:45:05 +02:00
2024-12-14 16:19:56 +01:00
// FIXME: This will be disabled during DnD operations because we do not exactly follow the spec
// xdg-popup grabs should be keyboard-only, while they are absolute in our case...
2025-05-02 17:07:20 +02:00
if ( g_pSeatManager - > m_seatGrab & & ! g_pSeatManager - > m_seatGrab - > accepts ( foundSurface ) & & ! PROTO : : data - > dndActive ( ) ) {
2025-05-01 23:57:11 +02:00
if ( m_hardInput | | refocus ) {
2024-05-11 01:02:57 +01:00
g_pSeatManager - > setGrab ( nullptr ) ;
return ; // setGrab will refocus
} else {
// we need to grab the last surface.
2025-05-02 17:07:20 +02:00
foundSurface = g_pSeatManager - > m_state . pointerFocus . lock ( ) ;
2024-05-11 01:02:57 +01:00
2024-06-08 10:07:59 +02:00
auto HLSurface = CWLSurface : : fromResource ( foundSurface ) ;
2024-05-11 01:02:57 +01:00
if ( HLSurface ) {
const auto BOX = HLSurface - > getSurfaceBoxGlobal ( ) ;
if ( BOX . has_value ( ) )
surfacePos = BOX - > pos ( ) ;
}
}
}
2022-03-20 14:36:55 +01:00
if ( ! foundSurface ) {
2025-05-01 23:57:11 +02:00
if ( ! m_emptyFocusCursorSet ) {
if ( * PRESIZEONBORDER & & * PRESIZECURSORICON & & m_borderIconDirection ! = BORDERICON_NONE ) {
m_borderIconDirection = BORDERICON_NONE ;
2023-12-12 14:55:48 +00:00
unsetCursorImage ( ) ;
}
2023-12-18 16:06:06 +00:00
// TODO: maybe wrap?
2025-05-01 23:57:11 +02:00
if ( m_clickBehavior = = CLICKMODE_KILL )
2023-12-18 16:06:06 +00:00
setCursorImageOverride ( " crosshair " ) ;
else
setCursorImageOverride ( " left_ptr " ) ;
2022-12-16 17:17:31 +00:00
2025-05-01 23:57:11 +02:00
m_emptyFocusCursorSet = true ;
2022-08-28 22:45:05 +02:00
}
2022-03-18 23:52:36 +01:00
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( nullptr , { } ) ;
2022-03-18 23:52:36 +01:00
2025-04-22 15:23:29 +02:00
if ( refocus | | g_pCompositor - > m_lastWindow . expired ( ) ) // if we are forcing a refocus, and we don't find a surface, clear the kb focus too!
2022-08-08 20:21:11 +02:00
g_pCompositor - > focusWindow ( nullptr ) ;
2022-07-07 21:47:59 +02:00
2022-03-18 23:52:36 +01:00
return ;
}
2025-05-01 23:57:11 +02:00
m_emptyFocusCursorSet = false ;
2022-08-28 22:45:05 +02:00
2022-04-24 17:42:59 +02:00
Vector2D surfaceLocal = surfacePos = = Vector2D ( - 1337 , - 1337 ) ? surfaceCoords : mouseCoords - surfacePos ;
2022-03-18 23:52:36 +01:00
2025-04-28 22:25:22 +02:00
if ( pFoundWindow & & ! pFoundWindow - > m_isX11 & & surfacePos ! = Vector2D ( - 1337 , - 1337 ) ) {
2022-06-22 15:45:56 +02:00
// calc for oversized windows... fucking bullshit.
2025-05-04 23:39:00 +02:00
CBox geom = pFoundWindow - > m_xdgSurface - > m_current . geometry ;
2022-06-22 15:45:56 +02:00
2024-05-10 23:28:33 +01:00
surfaceLocal = mouseCoords - surfacePos + geom . pos ( ) ;
2022-06-22 15:45:56 +02:00
}
2025-04-28 22:25:22 +02:00
if ( pFoundWindow & & pFoundWindow - > m_isX11 ) // for x11 force scale zero
surfaceLocal = surfaceLocal * pFoundWindow - > m_X11SurfaceScaledBy ;
2023-06-11 21:52:13 +02:00
2022-08-10 17:46:01 +02:00
bool allowKeyboardRefocus = true ;
2025-04-22 15:23:29 +02:00
if ( ! refocus & & g_pCompositor - > m_lastFocus ) {
const auto PLS = g_pCompositor - > getLayerSurfaceFromSurface ( g_pCompositor - > m_lastFocus . lock ( ) ) ;
2022-08-10 17:46:01 +02:00
2025-05-04 00:13:29 +02:00
if ( PLS & & PLS - > m_layerSurface - > m_current . interactivity = = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE )
2022-08-10 17:46:01 +02:00
allowKeyboardRefocus = false ;
}
2022-10-14 20:46:32 +01:00
// set the values for use
if ( refocus ) {
2025-05-01 23:57:11 +02:00
m_foundLSToFocus = pFoundLayerSurface ;
m_foundWindowToFocus = pFoundWindow ;
m_foundSurfaceToFocus = foundSurface ;
2022-10-14 20:46:32 +01:00
}
2025-05-01 23:57:11 +02:00
if ( m_currentlyDraggedWindow . lock ( ) & & pFoundWindow ! = m_currentlyDraggedWindow ) {
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
2023-05-01 15:15:55 +01:00
return ;
}
2025-05-01 23:57:11 +02:00
if ( pFoundWindow & & foundSurface = = pFoundWindow - > m_wlSurface - > resource ( ) & & ! m_cursorImageOverridden ) {
2023-10-29 18:09:05 +00:00
const auto BOX = pFoundWindow - > getWindowMainSurfaceBox ( ) ;
2025-05-03 21:54:15 +05:00
if ( VECNOTINRECT ( mouseCoords , BOX . x , BOX . y , BOX . x + BOX . width , BOX . y + BOX . height ) )
2023-10-29 18:09:05 +00:00
setCursorImageOverride ( " left_ptr " ) ;
else
restoreCursorIconToApp ( ) ;
}
2024-09-04 15:59:00 +00:00
if ( pFoundWindow ) {
2023-02-22 00:57:38 +01:00
// change cursor icon if hovering over border
2024-03-03 18:39:20 +00:00
if ( * PRESIZEONBORDER & & * PRESIZECURSORICON ) {
2024-07-31 17:55:52 +00:00
if ( ! pFoundWindow - > isFullscreen ( ) & & ! pFoundWindow - > hasPopupAt ( mouseCoords ) ) {
2023-04-21 12:36:55 +00:00
setCursorIconOnBorder ( pFoundWindow ) ;
2025-05-01 23:57:11 +02:00
} else if ( m_borderIconDirection ! = BORDERICON_NONE ) {
2023-04-21 12:36:55 +00:00
unsetCursorImage ( ) ;
}
2023-02-18 23:35:31 +01:00
}
2023-03-30 00:34:24 +01:00
if ( FOLLOWMOUSE ! = 1 & & ! refocus ) {
2025-04-22 15:23:29 +02:00
if ( pFoundWindow ! = g_pCompositor - > m_lastWindow . lock ( ) & & g_pCompositor - > m_lastWindow . lock ( ) & &
2025-04-28 22:25:22 +02:00
( ( pFoundWindow - > m_isFloating & & * PFLOATBEHAVIOR = = 2 ) | | ( g_pCompositor - > m_lastWindow - > m_isFloating ! = pFoundWindow - > m_isFloating & & * PFLOATBEHAVIOR ! = 0 ) ) ) {
2022-04-13 20:19:40 +02:00
// enter if change floating style
2023-03-30 00:34:24 +01:00
if ( FOLLOWMOUSE ! = 3 & & allowKeyboardRefocus )
2022-08-01 18:42:11 +02:00
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
} else if ( FOLLOWMOUSE = = 2 | | FOLLOWMOUSE = = 3 )
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
2022-07-19 14:05:12 +02:00
2025-04-22 15:23:29 +02:00
if ( pFoundWindow = = g_pCompositor - > m_lastWindow )
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
2022-07-19 14:05:12 +02:00
2025-04-22 15:23:29 +02:00
if ( FOLLOWMOUSE ! = 0 | | pFoundWindow = = g_pCompositor - > m_lastWindow )
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
2022-09-25 20:07:48 +02:00
2025-05-02 17:07:20 +02:00
if ( g_pSeatManager - > m_state . pointerFocus = = foundSurface )
2024-05-15 16:22:45 +01:00
g_pSeatManager - > sendPointerMotion ( time , surfaceLocal ) ;
2025-05-01 23:57:11 +02:00
m_lastFocusOnLS = false ;
2022-12-16 17:17:31 +00:00
return ; // don't enter any new surfaces
2022-04-13 20:19:40 +02:00
} else {
2025-05-01 23:57:11 +02:00
if ( allowKeyboardRefocus & & ( ( FOLLOWMOUSE ! = 3 & & ( * PMOUSEREFOCUS | | m_lastMouseFocus . lock ( ) ! = pFoundWindow ) ) | | refocus ) ) {
if ( m_lastMouseFocus . lock ( ) ! = pFoundWindow | | g_pCompositor - > m_lastWindow . lock ( ) ! = pFoundWindow | | g_pCompositor - > m_lastFocus ! = foundSurface | | refocus ) {
m_lastMouseFocus = pFoundWindow ;
2024-02-15 01:24:40 +00:00
// TODO: this looks wrong. When over a popup, it constantly is switching.
// Temp fix until that's figured out. Otherwise spams windowrule lookups and other shit.
2025-05-01 23:57:11 +02:00
if ( m_lastMouseFocus . lock ( ) ! = pFoundWindow | | g_pCompositor - > m_lastWindow . lock ( ) ! = pFoundWindow ) {
if ( m_mousePosDelta > * PFOLLOWMOUSETHRESHOLD | | refocus ) {
2025-04-28 22:25:22 +02:00
const bool hasNoFollowMouse = pFoundWindow & & pFoundWindow - > m_windowData . noFollowMouse . valueOrDefault ( ) ;
2025-04-21 14:48:27 -04:00
if ( refocus | | ! hasNoFollowMouse )
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
}
2025-02-17 04:03:27 +02:00
} else
2024-02-15 01:24:40 +00:00
g_pCompositor - > focusSurface ( foundSurface , pFoundWindow ) ;
}
2023-04-25 15:00:34 +00:00
}
2022-04-13 20:19:40 +02:00
}
2022-09-04 18:42:11 +02:00
2025-05-02 17:07:20 +02:00
if ( g_pSeatManager - > m_state . keyboardFocus = = nullptr )
2024-09-05 17:03:12 -07:00
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
2025-05-01 23:57:11 +02:00
m_lastFocusOnLS = false ;
2022-08-10 17:46:01 +02:00
} else {
2025-05-01 23:57:11 +02:00
if ( * PRESIZEONBORDER & & * PRESIZECURSORICON & & m_borderIconDirection ! = BORDERICON_NONE ) {
m_borderIconDirection = BORDERICON_NONE ;
2023-02-22 00:57:38 +01:00
unsetCursorImage ( ) ;
}
2025-05-04 00:13:29 +02:00
if ( pFoundLayerSurface & & ( pFoundLayerSurface - > m_layerSurface - > m_current . interactivity ! = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE ) & & FOLLOWMOUSE ! = 3 & &
( allowKeyboardRefocus | | pFoundLayerSurface - > m_layerSurface - > m_current . interactivity = = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE ) ) {
2022-08-10 17:46:01 +02:00
g_pCompositor - > focusSurface ( foundSurface ) ;
2022-08-19 17:29:16 +02:00
}
2022-12-10 15:15:40 +00:00
if ( pFoundLayerSurface )
2025-05-01 23:57:11 +02:00
m_lastFocusOnLS = true ;
2022-08-10 17:46:01 +02:00
}
2022-03-22 21:59:14 +01:00
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
g_pSeatManager - > sendPointerMotion ( time , surfaceLocal ) ;
2022-03-18 20:42:49 +01:00
}
2024-05-05 22:18:10 +01:00
void CInputManager : : onMouseButton ( IPointer : : SButtonEvent e ) {
2023-10-21 14:52:43 +01:00
EMIT_HOOK_EVENT_CANCELLABLE ( " mouseButton " , e ) ;
2022-03-18 20:42:49 +01:00
2024-12-15 23:54:05 +00:00
if ( e . mouse )
recheckMouseWarpOnMouseInput ( ) ;
2025-05-01 23:57:11 +02:00
m_lastCursorMovement . reset ( ) ;
2022-06-24 23:27:02 +02:00
2024-05-05 22:18:10 +01:00
if ( e . state = = WL_POINTER_BUTTON_STATE_PRESSED ) {
2025-05-01 23:57:11 +02:00
m_currentlyHeldButtons . push_back ( e . button ) ;
2023-01-11 18:38:54 +01:00
} else {
2025-05-30 18:25:59 +05:00
if ( std : : ranges : : find_if ( m_currentlyHeldButtons , [ & ] ( const auto & other ) { return other = = e . button ; } ) = = m_currentlyHeldButtons . end ( ) )
2023-01-11 18:38:54 +01:00
return ;
2025-05-01 23:57:11 +02:00
std : : erase_if ( m_currentlyHeldButtons , [ & ] ( const auto & other ) { return other = = e . button ; } ) ;
2023-01-11 18:38:54 +01:00
}
2025-05-01 23:57:11 +02:00
switch ( m_clickBehavior ) {
2022-12-16 17:17:31 +00:00
case CLICKMODE_DEFAULT : processMouseDownNormal ( e ) ; break ;
case CLICKMODE_KILL : processMouseDownKill ( e ) ; break ;
default : break ;
2022-06-27 13:42:20 +02:00
}
2023-04-02 13:30:45 +01:00
2025-05-01 23:57:11 +02:00
if ( m_focusHeldByButtons & & m_currentlyHeldButtons . empty ( ) & & e . state = = WL_POINTER_BUTTON_STATE_RELEASED ) {
if ( m_refocusHeldByButtons )
2023-04-02 13:30:45 +01:00
refocus ( ) ;
else
simulateMouseMovement ( ) ;
2025-05-01 23:57:11 +02:00
m_focusHeldByButtons = false ;
m_refocusHeldByButtons = false ;
2023-04-02 13:30:45 +01:00
}
2022-06-27 13:42:20 +02:00
}
2025-07-08 09:56:40 -07:00
void CInputManager : : processMouseRequest ( const CSeatManager : : SSetCursorEvent & event ) {
2023-12-18 16:06:06 +00:00
if ( ! cursorImageUnlocked ( ) )
2022-11-15 10:39:05 +00:00
return ;
2022-06-27 13:42:20 +02:00
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " cursorImage request: surface {:x} " , rc < uintptr_t > ( event . surf . get ( ) ) ) ;
2024-02-12 20:01:50 +00:00
2025-07-08 09:56:40 -07:00
if ( event . surf ! = m_cursorSurfaceInfo . wlSurface - > resource ( ) ) {
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . wlSurface - > unassign ( ) ;
2024-02-12 20:01:50 +00:00
2025-07-08 09:56:40 -07:00
if ( event . surf )
m_cursorSurfaceInfo . wlSurface - > assign ( event . surf ) ;
2024-05-10 18:27:57 +01:00
}
2023-10-29 18:09:05 +00:00
2025-07-08 09:56:40 -07:00
if ( event . surf ) {
m_cursorSurfaceInfo . vHotspot = event . hotspot ;
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . hidden = false ;
2024-05-10 18:27:57 +01:00
} else {
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . vHotspot = { } ;
m_cursorSurfaceInfo . hidden = true ;
2024-05-10 18:27:57 +01:00
}
2023-02-28 23:06:46 +00:00
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . name = " " ;
2023-02-28 23:06:46 +00:00
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . inUse = true ;
2025-07-08 09:56:40 -07:00
g_pHyprRenderer - > setCursorSurface ( m_cursorSurfaceInfo . wlSurface , event . hotspot . x , event . hotspot . y ) ;
2023-10-29 18:09:05 +00:00
}
void CInputManager : : restoreCursorIconToApp ( ) {
2025-05-01 23:57:11 +02:00
if ( m_cursorSurfaceInfo . inUse )
2023-10-29 18:09:05 +00:00
return ;
2025-05-01 23:57:11 +02:00
if ( m_cursorSurfaceInfo . hidden ) {
2023-10-29 18:09:05 +00:00
g_pHyprRenderer - > setCursorSurface ( nullptr , 0 , 0 ) ;
return ;
}
2025-05-01 23:57:11 +02:00
if ( m_cursorSurfaceInfo . name . empty ( ) ) {
if ( m_cursorSurfaceInfo . wlSurface - > exists ( ) )
g_pHyprRenderer - > setCursorSurface ( m_cursorSurfaceInfo . wlSurface , m_cursorSurfaceInfo . vHotspot . x , m_cursorSurfaceInfo . vHotspot . y ) ;
2023-10-29 18:09:05 +00:00
} else {
2025-05-01 23:57:11 +02:00
g_pHyprRenderer - > setCursorFromName ( m_cursorSurfaceInfo . name ) ;
2023-10-29 18:09:05 +00:00
}
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . inUse = true ;
2023-10-29 18:09:05 +00:00
}
void CInputManager : : setCursorImageOverride ( const std : : string & name ) {
2025-05-01 23:57:11 +02:00
if ( m_cursorImageOverridden )
2023-10-29 18:09:05 +00:00
return ;
2025-05-01 23:57:11 +02:00
m_cursorSurfaceInfo . inUse = false ;
2023-10-29 18:09:05 +00:00
g_pHyprRenderer - > setCursorFromName ( name ) ;
2023-07-24 18:50:17 +02:00
}
bool CInputManager : : cursorImageUnlocked ( ) {
2025-05-01 23:57:11 +02:00
if ( m_clickBehavior = = CLICKMODE_KILL )
2023-07-24 18:50:17 +02:00
return false ;
2025-05-01 23:57:11 +02:00
if ( m_cursorImageOverridden )
2023-07-24 18:50:17 +02:00
return false ;
return true ;
}
2022-06-27 13:42:20 +02:00
eClickBehaviorMode CInputManager : : getClickMode ( ) {
2025-05-01 23:57:11 +02:00
return m_clickBehavior ;
2022-06-27 13:42:20 +02:00
}
void CInputManager : : setClickMode ( eClickBehaviorMode mode ) {
switch ( mode ) {
case CLICKMODE_DEFAULT :
Debug : : log ( LOG , " SetClickMode: DEFAULT " ) ;
2025-05-01 23:57:11 +02:00
m_clickBehavior = CLICKMODE_DEFAULT ;
2025-10-20 13:22:50 +02:00
g_pHyprRenderer - > setCursorFromName ( " left_ptr " , true ) ;
2022-06-27 13:42:20 +02:00
break ;
case CLICKMODE_KILL :
Debug : : log ( LOG , " SetClickMode: KILL " ) ;
2025-05-01 23:57:11 +02:00
m_clickBehavior = CLICKMODE_KILL ;
2022-06-27 13:42:20 +02:00
// remove constraints
2022-08-09 20:36:21 +02:00
g_pInputManager - > unconstrainMouse ( ) ;
2022-06-27 13:42:20 +02:00
refocus ( ) ;
// set cursor
2025-10-20 13:22:50 +02:00
g_pHyprRenderer - > setCursorFromName ( " crosshair " , true ) ;
2022-06-27 13:42:20 +02:00
break ;
2022-12-16 17:17:31 +00:00
default : break ;
2022-09-25 20:07:48 +02:00
}
2022-06-27 13:42:20 +02:00
}
2024-05-05 22:18:10 +01:00
void CInputManager : : processMouseDownNormal ( const IPointer : : SButtonEvent & e ) {
2022-12-16 17:17:31 +00:00
2022-07-26 14:50:21 +02:00
// notify the keybind manager
2024-03-03 18:39:20 +00:00
static auto PPASSMOUSE = CConfigValue < Hyprlang : : INT > ( " binds:pass_mouse_when_bound " ) ;
const auto PASS = g_pKeybindManager - > onMouseEvent ( e ) ;
static auto PFOLLOWMOUSE = CConfigValue < Hyprlang : : INT > ( " input:follow_mouse " ) ;
static auto PRESIZEONBORDER = CConfigValue < Hyprlang : : INT > ( " general:resize_on_border " ) ;
static auto PBORDERSIZE = CConfigValue < Hyprlang : : INT > ( " general:border_size " ) ;
static auto PBORDERGRABEXTEND = CConfigValue < Hyprlang : : INT > ( " general:extend_border_grab_area " ) ;
const auto BORDER_GRAB_AREA = * PRESIZEONBORDER ? * PBORDERSIZE + * PBORDERGRABEXTEND : 0 ;
if ( ! PASS & & ! * PPASSMOUSE )
2022-07-26 14:50:21 +02:00
return ;
2023-08-30 15:39:22 +00:00
const auto mouseCoords = g_pInputManager - > getMouseCoordsInternal ( ) ;
2024-02-04 15:40:20 +00:00
const auto w = g_pCompositor - > vectorToWindowUnified ( mouseCoords , ALLOW_FLOATING | RESERVED_EXTENTS | INPUT_EXTENTS ) ;
2023-08-30 15:39:22 +00:00
2025-06-22 12:49:13 +02:00
if ( w & & ! m_lastFocusOnLS & & ! g_pSessionLockManager - > isSessionLocked ( ) & & w - > checkInputOnDecos ( INPUT_TYPE_BUTTON , mouseCoords , e ) )
2024-02-10 17:05:28 +00:00
return ;
2023-08-30 15:39:22 +00:00
2023-02-18 23:35:31 +01:00
// clicking on border triggers resize
// TODO detect click on LS properly
2025-06-22 12:49:13 +02:00
if ( * PRESIZEONBORDER & & ! g_pSessionLockManager - > isSessionLocked ( ) & & ! m_lastFocusOnLS & & e . state = = WL_POINTER_BUTTON_STATE_PRESSED & & ( ! w | | ! w - > isX11OverrideRedirect ( ) ) ) {
2024-07-31 17:55:52 +00:00
if ( w & & ! w - > isFullscreen ( ) ) {
2025-04-28 22:25:22 +02:00
const CBox real = { w - > m_realPosition - > value ( ) . x , w - > m_realPosition - > value ( ) . y , w - > m_realSize - > value ( ) . x , w - > m_realSize - > value ( ) . y } ;
2023-11-30 20:12:08 -05:00
const CBox grab = { real . x - BORDER_GRAB_AREA , real . y - BORDER_GRAB_AREA , real . width + 2 * BORDER_GRAB_AREA , real . height + 2 * BORDER_GRAB_AREA } ;
2023-12-28 22:54:41 +00:00
2023-11-30 20:12:08 -05:00
if ( ( grab . containsPoint ( mouseCoords ) & & ( ! real . containsPoint ( mouseCoords ) | | w - > isInCurvedCorner ( mouseCoords . x , mouseCoords . y ) ) ) & & ! w - > hasPopupAt ( mouseCoords ) ) {
2023-02-18 23:35:31 +01:00
g_pKeybindManager - > resizeWithBorder ( e ) ;
return ;
}
}
}
2024-05-05 22:18:10 +01:00
switch ( e . state ) {
2024-05-25 22:43:51 +02:00
case WL_POINTER_BUTTON_STATE_PRESSED : {
2024-03-03 18:39:20 +00:00
if ( * PFOLLOWMOUSE = = 3 ) // don't refocus on full loose
2022-11-08 20:28:41 +00:00
break ;
2025-05-02 17:07:20 +02:00
if ( ( g_pSeatManager - > m_mouse . expired ( ) | | ! isConstrained ( ) ) /* No constraints */
2025-04-22 15:23:29 +02:00
& & ( w & & g_pCompositor - > m_lastWindow . lock ( ) ! = w ) /* window should change */ ) {
2023-04-03 23:09:44 +01:00
// a bit hacky
// if we only pressed one button, allow us to refocus. m_lCurrentlyHeldButtons.size() > 0 will stick the focus
2025-05-01 23:57:11 +02:00
if ( m_currentlyHeldButtons . size ( ) = = 1 ) {
const auto COPY = m_currentlyHeldButtons ;
m_currentlyHeldButtons . clear ( ) ;
2023-04-03 23:09:44 +01:00
refocus ( ) ;
2025-05-01 23:57:11 +02:00
m_currentlyHeldButtons = COPY ;
2023-04-03 23:09:44 +01:00
} else
refocus ( ) ;
}
2022-04-02 13:02:16 +02:00
2022-04-04 16:28:43 +02:00
// if clicked on a floating window make it top
2025-05-02 17:07:20 +02:00
if ( ! g_pSeatManager - > m_state . pointerFocus )
2024-05-25 22:43:51 +02:00
break ;
2025-05-02 17:07:20 +02:00
auto HLSurf = CWLSurface : : fromResource ( g_pSeatManager - > m_state . pointerFocus . lock ( ) ) ;
2024-05-25 22:43:51 +02:00
if ( HLSurf & & HLSurf - > getWindow ( ) )
g_pCompositor - > changeWindowZOrder ( HLSurf - > getWindow ( ) , true ) ;
2022-04-04 16:28:43 +02:00
2022-03-18 20:42:49 +01:00
break ;
2024-05-25 22:43:51 +02:00
}
2024-04-06 17:07:21 -07:00
case WL_POINTER_BUTTON_STATE_RELEASED : break ;
2022-03-18 20:42:49 +01:00
}
2025-07-25 15:19:23 +00:00
// notify app if we didn't handle it
2024-05-10 18:27:57 +01:00
g_pSeatManager - > sendPointerButton ( e . timeMs , e . button , e . state ) ;
2024-02-10 17:39:24 +00:00
2025-04-22 15:23:29 +02:00
if ( const auto PMON = g_pCompositor - > getMonitorFromVector ( mouseCoords ) ; PMON ! = g_pCompositor - > m_lastMonitor & & PMON )
2024-02-10 17:39:24 +00:00
g_pCompositor - > setActiveMonitor ( PMON ) ;
2024-05-11 01:02:57 +01:00
2025-05-02 17:07:20 +02:00
if ( g_pSeatManager - > m_seatGrab & & e . state = = WL_POINTER_BUTTON_STATE_PRESSED ) {
2025-05-01 23:57:11 +02:00
m_hardInput = true ;
2024-05-11 01:02:57 +01:00
simulateMouseMovement ( ) ;
2025-05-01 23:57:11 +02:00
m_hardInput = false ;
2024-05-11 01:02:57 +01:00
}
2022-06-27 13:42:20 +02:00
}
2024-05-05 22:18:10 +01:00
void CInputManager : : processMouseDownKill ( const IPointer : : SButtonEvent & e ) {
switch ( e . state ) {
2024-04-06 17:07:21 -07:00
case WL_POINTER_BUTTON_STATE_PRESSED : {
2024-02-04 15:40:20 +00:00
const auto PWINDOW = g_pCompositor - > vectorToWindowUnified ( getMouseCoordsInternal ( ) , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2022-06-27 13:42:20 +02:00
2022-10-14 20:46:32 +01:00
if ( ! PWINDOW ) {
2022-06-27 13:42:20 +02:00
Debug : : log ( ERR , " Cannot kill invalid window! " ) ;
break ;
}
// kill the mf
kill ( PWINDOW - > getPID ( ) , SIGKILL ) ;
break ;
}
2024-04-06 17:07:21 -07:00
case WL_POINTER_BUTTON_STATE_RELEASED : break ;
2022-12-16 17:17:31 +00:00
default : break ;
2022-06-27 13:42:20 +02:00
}
// reset click behavior mode
2025-05-01 23:57:11 +02:00
m_clickBehavior = CLICKMODE_DEFAULT ;
2022-03-17 16:56:33 +01:00
}
2025-09-02 13:16:43 +02:00
void CInputManager : : onMouseWheel ( IPointer : : SAxisEvent e , SP < IPointer > pointer ) {
2024-04-08 22:35:21 +00:00
static auto POFFWINDOWAXIS = CConfigValue < Hyprlang : : INT > ( " input:off_window_axis_events " ) ;
2024-03-05 14:18:53 -05:00
static auto PINPUTSCROLLFACTOR = CConfigValue < Hyprlang : : FLOAT > ( " input:scroll_factor " ) ;
static auto PTOUCHPADSCROLLFACTOR = CConfigValue < Hyprlang : : FLOAT > ( " input:touchpad:scroll_factor " ) ;
2024-07-18 15:57:08 -04:00
static auto PEMULATEDISCRETE = CConfigValue < Hyprlang : : INT > ( " input:emulate_discrete_scroll " ) ;
2024-11-08 18:25:37 +01:00
static auto PFOLLOWMOUSE = CConfigValue < Hyprlang : : INT > ( " input:follow_mouse " ) ;
2022-10-06 22:20:10 +03:00
2024-12-06 01:16:58 -05:00
const bool ISTOUCHPADSCROLL = * PTOUCHPADSCROLLFACTOR < = 0.f | | e . source = = WL_POINTER_AXIS_SOURCE_FINGER ;
auto factor = ISTOUCHPADSCROLL ? * PTOUCHPADSCROLLFACTOR : * PINPUTSCROLLFACTOR ;
2022-10-06 22:20:10 +03:00
2025-09-02 13:16:43 +02:00
if ( pointer & & pointer - > m_scrollFactor . has_value ( ) )
factor = * pointer - > m_scrollFactor ;
const auto EMAP = std : : unordered_map < std : : string , std : : any > { { " event " , e } } ;
2023-11-30 18:44:58 +00:00
EMIT_HOOK_EVENT_CANCELLABLE ( " mouseAxis " , EMAP ) ;
2024-12-15 23:54:05 +00:00
if ( e . mouse )
recheckMouseWarpOnMouseInput ( ) ;
2023-11-30 18:44:58 +00:00
bool passEvent = g_pKeybindManager - > onAxisEvent ( e ) ;
2022-06-20 22:47:28 +03:00
2023-12-05 21:16:26 +00:00
if ( ! passEvent )
return ;
2025-05-01 23:57:11 +02:00
if ( ! m_lastFocusOnLS ) {
2024-01-01 12:02:16 +00:00
const auto MOUSECOORDS = g_pInputManager - > getMouseCoordsInternal ( ) ;
2024-02-04 15:40:20 +00:00
const auto PWINDOW = g_pCompositor - > vectorToWindowUnified ( MOUSECOORDS , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2023-08-30 15:39:22 +00:00
2024-11-08 18:25:37 +01:00
if ( PWINDOW ) {
if ( PWINDOW - > checkInputOnDecos ( INPUT_TYPE_AXIS , MOUSECOORDS , e ) )
return ;
if ( * POFFWINDOWAXIS ! = 1 ) {
const auto BOX = PWINDOW - > getWindowMainSurfaceBox ( ) ;
2024-04-08 22:35:21 +00:00
2024-11-08 18:25:37 +01:00
if ( ! BOX . containsPoint ( MOUSECOORDS ) & & ! PWINDOW - > hasPopupAt ( MOUSECOORDS ) ) {
if ( * POFFWINDOWAXIS = = 0 )
return ;
2024-04-08 22:35:21 +00:00
2024-11-08 18:25:37 +01:00
const auto TEMPCURX = std : : clamp ( MOUSECOORDS . x , BOX . x , BOX . x + BOX . w - 1 ) ;
const auto TEMPCURY = std : : clamp ( MOUSECOORDS . y , BOX . y , BOX . y + BOX . h - 1 ) ;
2024-04-08 22:35:21 +00:00
2024-11-08 18:25:37 +01:00
if ( * POFFWINDOWAXIS = = 3 )
g_pCompositor - > warpCursorTo ( { TEMPCURX , TEMPCURY } , true ) ;
g_pSeatManager - > sendPointerMotion ( e . timeMs , Vector2D { TEMPCURX , TEMPCURY } - BOX . pos ( ) ) ;
g_pSeatManager - > sendPointerFrame ( ) ;
}
}
2024-04-08 22:35:21 +00:00
2025-05-02 17:07:20 +02:00
if ( g_pSeatManager - > m_state . pointerFocus ) {
const auto PCURRWINDOW = g_pCompositor - > getWindowFromSurface ( g_pSeatManager - > m_state . pointerFocus . lock ( ) ) ;
2024-04-08 22:35:21 +00:00
2024-11-08 18:25:37 +01:00
if ( * PFOLLOWMOUSE = = 1 & & PCURRWINDOW & & PWINDOW ! = PCURRWINDOW )
simulateMouseMovement ( ) ;
2024-04-08 22:35:21 +00:00
}
2025-09-02 13:16:43 +02:00
if ( ! ISTOUCHPADSCROLL & & PWINDOW - > isScrollMouseOverridden ( ) )
factor = PWINDOW - > getScrollMouse ( ) ;
else if ( ISTOUCHPADSCROLL & & PWINDOW - > isScrollTouchpadOverridden ( ) )
factor = PWINDOW - > getScrollTouchpad ( ) ;
2024-04-08 22:35:21 +00:00
}
2024-01-01 12:02:16 +00:00
}
2024-07-18 15:57:08 -04:00
double discrete = ( e . deltaDiscrete ! = 0 ) ? ( factor * e . deltaDiscrete / std : : abs ( e . deltaDiscrete ) ) : 0 ;
double delta = e . delta * factor ;
if ( e . source = = 0 ) {
// if an application supports v120, it should ignore discrete anyways
if ( ( * PEMULATEDISCRETE > = 1 & & std : : abs ( e . deltaDiscrete ) ! = 120 ) | | * PEMULATEDISCRETE > = 2 ) {
const int interval = factor ! = 0 ? std : : round ( 120 * ( 1 / factor ) ) : 120 ;
// reset the accumulator when timeout is reached or direction/axis has changed
2025-05-01 23:57:11 +02:00
if ( std : : signbit ( e . deltaDiscrete ) ! = m_scrollWheelState . lastEventSign | | e . axis ! = m_scrollWheelState . lastEventAxis | |
e . timeMs - m_scrollWheelState . lastEventTime > 500 /* 500ms taken from libinput default timeout */ ) {
2024-07-18 15:57:08 -04:00
2025-05-01 23:57:11 +02:00
m_scrollWheelState . accumulatedScroll = 0 ;
2024-07-18 15:57:08 -04:00
// send 1 discrete on first event for responsiveness
discrete = std : : copysign ( 1 , e . deltaDiscrete ) ;
} else
discrete = 0 ;
2025-05-01 23:57:11 +02:00
for ( int ac = m_scrollWheelState . accumulatedScroll ; ac > = interval ; ac - = interval ) {
2024-07-18 15:57:08 -04:00
discrete + = std : : copysign ( 1 , e . deltaDiscrete ) ;
2025-05-01 23:57:11 +02:00
m_scrollWheelState . accumulatedScroll - = interval ;
2024-07-18 15:57:08 -04:00
}
2025-05-01 23:57:11 +02:00
m_scrollWheelState . lastEventSign = std : : signbit ( e . deltaDiscrete ) ;
m_scrollWheelState . lastEventAxis = e . axis ;
m_scrollWheelState . lastEventTime = e . timeMs ;
m_scrollWheelState . accumulatedScroll + = std : : abs ( e . deltaDiscrete ) ;
2024-07-18 15:57:08 -04:00
delta = 15.0 * discrete * factor ;
}
}
int32_t value120 = std : : round ( factor * e . deltaDiscrete ) ;
int32_t deltaDiscrete = std : : abs ( discrete ) ! = 0 & & std : : abs ( discrete ) < 1 ? std : : copysign ( 1 , discrete ) : std : : round ( discrete ) ;
g_pSeatManager - > sendPointerAxis ( e . timeMs , e . axis , delta , deltaDiscrete , value120 , e . source , WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL ) ;
2022-06-20 22:47:28 +03:00
}
2022-03-17 19:03:15 +01:00
Vector2D CInputManager : : getMouseCoordsInternal ( ) {
2024-05-05 22:18:10 +01:00
return g_pPointerManager - > position ( ) ;
2022-03-17 20:55:04 +01:00
}
2025-08-04 16:29:39 -03:00
void CInputManager : : newKeyboard ( SP < IKeyboard > keeb ) {
const auto PNEWKEYBOARD = m_keyboards . emplace_back ( keeb ) ;
setupKeyboard ( PNEWKEYBOARD ) ;
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " New keyboard created, pointers Hypr: {:x} " , rc < uintptr_t > ( PNEWKEYBOARD . get ( ) ) ) ;
2025-08-04 16:29:39 -03:00
}
2024-07-21 13:09:54 +02:00
void CInputManager : : newKeyboard ( SP < Aquamarine : : IKeyboard > keyboard ) {
2025-05-01 23:57:11 +02:00
const auto PNEWKEYBOARD = m_keyboards . emplace_back ( CKeyboard : : create ( keyboard ) ) ;
2022-09-25 20:07:48 +02:00
2024-05-03 22:34:10 +01:00
setupKeyboard ( PNEWKEYBOARD ) ;
2022-09-25 20:07:48 +02:00
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " New keyboard created, pointers Hypr: {:x} and AQ: {:x} " , rc < uintptr_t > ( PNEWKEYBOARD . get ( ) ) , rc < uintptr_t > ( keyboard . get ( ) ) ) ;
2024-05-03 22:34:10 +01:00
}
2022-08-18 17:17:33 +02:00
2024-05-03 22:34:10 +01:00
void CInputManager : : newVirtualKeyboard ( SP < CVirtualKeyboardV1Resource > keyboard ) {
2025-05-01 23:57:11 +02:00
const auto PNEWKEYBOARD = m_keyboards . emplace_back ( CVirtualKeyboard : : create ( keyboard ) ) ;
2022-06-03 19:15:39 +02:00
2024-05-03 22:34:10 +01:00
setupKeyboard ( PNEWKEYBOARD ) ;
2022-03-19 11:27:19 +01:00
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " New virtual keyboard created at {:x} " , rc < uintptr_t > ( PNEWKEYBOARD . get ( ) ) ) ;
2022-03-24 21:05:34 +01:00
}
2024-05-03 22:34:10 +01:00
void CInputManager : : setupKeyboard ( SP < IKeyboard > keeb ) {
2024-09-09 20:29:00 +00:00
static auto PDPMS = CConfigValue < Hyprlang : : INT > ( " misc:key_press_enables_dpms " ) ;
2025-05-01 23:57:11 +02:00
m_hids . emplace_back ( keeb ) ;
2024-05-06 02:15:26 +01:00
2022-08-05 16:21:08 +02:00
try {
2025-04-29 19:51:07 +02:00
keeb - > m_hlName = getNameForNewDevice ( keeb - > m_deviceName ) ;
2022-08-05 16:21:08 +02:00
} catch ( std : : exception & e ) {
2022-12-16 17:17:31 +00:00
Debug : : log ( ERR , " Keyboard had no name??? " ) ; // logic error
2022-08-05 16:21:08 +02:00
}
2025-07-08 09:56:40 -07:00
keeb - > m_events . destroy . listenStatic ( [ this , keeb = keeb . get ( ) ] {
auto PKEEB = keeb - > m_self . lock ( ) ;
2024-05-04 00:48:25 +01:00
2025-07-08 09:56:40 -07:00
if ( ! PKEEB )
return ;
2024-05-04 00:48:25 +01:00
2025-07-08 09:56:40 -07:00
destroyKeyboard ( PKEEB ) ;
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " Destroyed keyboard {:x} " , rc < uintptr_t > ( keeb ) ) ;
2025-07-08 09:56:40 -07:00
} ) ;
2022-09-25 20:07:48 +02:00
2025-07-08 09:56:40 -07:00
keeb - > m_keyboardEvents . key . listenStatic ( [ this , keeb = keeb . get ( ) ] ( const IKeyboard : : SKeyEvent & event ) {
auto PKEEB = keeb - > m_self . lock ( ) ;
2024-05-09 14:07:21 +01:00
2025-07-08 09:56:40 -07:00
onKeyboardKey ( event , PKEEB ) ;
2024-09-05 23:58:57 +00:00
2025-07-08 09:56:40 -07:00
if ( PKEEB - > m_enabled )
PROTO : : idle - > onActivity ( ) ;
2024-09-09 20:29:00 +00:00
2025-07-08 09:56:40 -07:00
if ( PKEEB - > m_enabled & & * PDPMS & & ! g_pCompositor - > m_dpmsStateOn )
g_pKeybindManager - > dpms ( " on " ) ;
} ) ;
2022-08-18 17:50:32 +02:00
2025-07-08 09:56:40 -07:00
keeb - > m_keyboardEvents . modifiers . listenStatic ( [ this , keeb = keeb . get ( ) ] {
auto PKEEB = keeb - > m_self . lock ( ) ;
2024-05-09 14:07:21 +01:00
2025-07-08 09:56:40 -07:00
onKeyboardMod ( PKEEB ) ;
2024-09-05 23:58:57 +00:00
2025-07-08 09:56:40 -07:00
if ( PKEEB - > m_enabled )
PROTO : : idle - > onActivity ( ) ;
2024-09-09 20:29:00 +00:00
2025-07-08 09:56:40 -07:00
if ( PKEEB - > m_enabled & & * PDPMS & & ! g_pCompositor - > m_dpmsStateOn )
g_pKeybindManager - > dpms ( " on " ) ;
} ) ;
2024-05-03 00:54:32 +01:00
2025-07-08 09:56:40 -07:00
keeb - > m_keyboardEvents . keymap . listenStatic ( [ keeb = keeb . get ( ) ] {
auto PKEEB = keeb - > m_self . lock ( ) ;
const auto LAYOUT = PKEEB - > getActiveLayout ( ) ;
2022-08-05 16:21:08 +02:00
2025-07-08 09:56:40 -07:00
if ( PKEEB = = g_pSeatManager - > m_keyboard ) {
g_pSeatManager - > updateActiveKeyboardData ( ) ;
g_pKeybindManager - > m_keyToCodeCache . clear ( ) ;
}
2024-05-17 19:28:33 +01:00
2025-07-08 09:56:40 -07:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , PKEEB - > m_hlName + " , " + LAYOUT } ) ;
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < std : : any > { PKEEB , LAYOUT } ) ) ;
} ) ;
2024-05-03 22:34:10 +01:00
disableAllKeyboards ( false ) ;
2022-08-05 16:21:08 +02:00
2024-05-03 22:34:10 +01:00
applyConfigToKeyboard ( keeb ) ;
2022-08-05 16:21:08 +02:00
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setKeyboard ( keeb ) ;
2024-08-07 02:44:20 -05:00
keeb - > updateLEDs ( ) ;
2025-09-10 10:22:45 +00:00
// in case m_lastFocus was set without a keyboard
if ( m_keyboards . size ( ) = = 1 & & g_pCompositor - > m_lastFocus )
g_pSeatManager - > setKeyboardFocus ( g_pCompositor - > m_lastFocus . lock ( ) ) ;
2022-08-05 16:21:08 +02:00
}
2022-03-24 21:05:34 +01:00
void CInputManager : : setKeyboardLayout ( ) {
2025-05-01 23:57:11 +02:00
for ( auto const & k : m_keyboards )
2024-05-03 22:34:10 +01:00
applyConfigToKeyboard ( k ) ;
2022-08-21 16:43:18 +02:00
g_pKeybindManager - > updateXKBTranslationState ( ) ;
2022-06-23 15:48:31 +02:00
}
2024-05-03 22:34:10 +01:00
void CInputManager : : applyConfigToKeyboard ( SP < IKeyboard > pKeyboard ) {
2025-04-29 19:51:07 +02:00
auto devname = pKeyboard - > m_hlName ;
2022-07-28 21:38:30 +02:00
const auto HASCONFIG = g_pConfigManager - > deviceConfigExists ( devname ) ;
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " ApplyConfigToKeyboard for \" {} \" , hasconfig: {} " , devname , sc < int > ( HASCONFIG ) ) ;
2022-07-03 22:54:47 +02:00
2023-09-06 19:16:46 +02:00
const auto REPEATRATE = g_pConfigManager - > getDeviceInt ( devname , " repeat_rate " , " input:repeat_rate " ) ;
const auto REPEATDELAY = g_pConfigManager - > getDeviceInt ( devname , " repeat_delay " , " input:repeat_delay " ) ;
2022-03-24 21:05:34 +01:00
2024-02-28 00:21:22 +01:00
const auto NUMLOCKON = g_pConfigManager - > getDeviceInt ( devname , " numlock_by_default " , " input:numlock_by_default " ) ;
const auto RESOLVEBINDSBYSYM = g_pConfigManager - > getDeviceInt ( devname , " resolve_binds_by_sym " , " input:resolve_binds_by_sym " ) ;
2022-06-30 21:26:00 +02:00
2023-09-06 19:16:46 +02:00
const auto FILEPATH = g_pConfigManager - > getDeviceString ( devname , " kb_file " , " input:kb_file " ) ;
const auto RULES = g_pConfigManager - > getDeviceString ( devname , " kb_rules " , " input:kb_rules " ) ;
const auto MODEL = g_pConfigManager - > getDeviceString ( devname , " kb_model " , " input:kb_model " ) ;
const auto LAYOUT = g_pConfigManager - > getDeviceString ( devname , " kb_layout " , " input:kb_layout " ) ;
const auto VARIANT = g_pConfigManager - > getDeviceString ( devname , " kb_variant " , " input:kb_variant " ) ;
const auto OPTIONS = g_pConfigManager - > getDeviceString ( devname , " kb_options " , " input:kb_options " ) ;
2022-03-24 21:05:34 +01:00
2025-04-16 20:19:10 -04:00
const auto ENABLED = HASCONFIG ? g_pConfigManager - > getDeviceInt ( devname , " enabled " ) : true ;
const auto ALLOWBINDS = HASCONFIG ? g_pConfigManager - > getDeviceInt ( devname , " keybinds " ) : true ;
2022-12-16 17:20:51 +00:00
2025-04-29 19:51:07 +02:00
pKeyboard - > m_enabled = ENABLED ;
pKeyboard - > m_resolveBindsBySym = RESOLVEBINDSBYSYM ;
pKeyboard - > m_allowBinds = ALLOWBINDS ;
2022-12-16 17:20:51 +00:00
2025-05-18 18:13:20 +01:00
const auto PERM = g_pDynamicPermissionManager - > clientPermissionModeWithString ( - 1 , pKeyboard - > m_hlName , PERMISSION_TYPE_KEYBOARD ) ;
if ( PERM = = PERMISSION_RULE_ALLOW_MODE_PENDING ) {
const auto PROMISE = g_pDynamicPermissionManager - > promiseFor ( - 1 , pKeyboard - > m_hlName , PERMISSION_TYPE_KEYBOARD ) ;
if ( ! PROMISE )
Debug : : log ( ERR , " BUG THIS: No promise for client permission for keyboard " ) ;
else {
PROMISE - > then ( [ k = WP < IKeyboard > { pKeyboard } ] ( SP < CPromiseResult < eDynamicPermissionAllowMode > > r ) {
if ( r - > hasError ( ) ) {
Debug : : log ( ERR , " BUG THIS: No permission returned for keyboard " ) ;
return ;
}
if ( ! k )
return ;
k - > m_allowed = r - > result ( ) = = PERMISSION_RULE_ALLOW_MODE_ALLOW ;
} ) ;
}
} else
pKeyboard - > m_allowed = PERM = = PERMISSION_RULE_ALLOW_MODE_ALLOW ;
2022-06-28 15:40:14 +02:00
try {
2025-07-29 17:25:27 +02:00
if ( NUMLOCKON = = pKeyboard - > m_numlockOn & & REPEATDELAY = = pKeyboard - > m_repeatDelay & & REPEATRATE = = pKeyboard - > m_repeatRate & & RULES = = pKeyboard - > m_currentRules . rules & &
MODEL = = pKeyboard - > m_currentRules . model & & LAYOUT = = pKeyboard - > m_currentRules . layout & & VARIANT = = pKeyboard - > m_currentRules . variant & &
OPTIONS = = pKeyboard - > m_currentRules . options & & FILEPATH = = pKeyboard - > m_xkbFilePath ) {
2022-06-28 15:40:14 +02:00
Debug : : log ( LOG , " Not applying config to keyboard, it did not change. " ) ;
return ;
}
} catch ( std : : exception & e ) {
// can be libc errors for null std::string
// we can ignore those and just apply
2022-06-25 11:50:09 +02:00
}
2025-04-29 19:51:07 +02:00
pKeyboard - > m_repeatRate = std : : max ( 0 , REPEATRATE ) ;
pKeyboard - > m_repeatDelay = std : : max ( 0 , REPEATDELAY ) ;
pKeyboard - > m_numlockOn = NUMLOCKON ;
pKeyboard - > m_xkbFilePath = FILEPATH ;
2024-07-21 13:09:54 +02:00
pKeyboard - > setKeymap ( IKeyboard : : SStringRuleNames { LAYOUT , MODEL , VARIANT , OPTIONS , RULES } ) ;
2022-03-24 21:05:34 +01:00
2024-05-03 22:34:10 +01:00
const auto LAYOUTSTR = pKeyboard - > getActiveLayout ( ) ;
2023-02-19 20:54:53 +00:00
2025-04-29 19:51:07 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , pKeyboard - > m_hlName + " , " + LAYOUTSTR } ) ;
2024-05-03 22:34:10 +01:00
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < std : : any > { pKeyboard , LAYOUTSTR } ) ) ;
2022-08-18 17:17:33 +02:00
2025-04-29 19:51:07 +02:00
Debug : : log ( LOG , " Set the keyboard layout to {} and variant to {} for keyboard \" {} \" " , pKeyboard - > m_currentRules . layout , pKeyboard - > m_currentRules . variant ,
pKeyboard - > m_hlName ) ;
2022-09-25 20:07:48 +02:00
}
2022-03-17 20:55:04 +01:00
2024-05-03 22:34:10 +01:00
void CInputManager : : newVirtualMouse ( SP < CVirtualPointerV1Resource > mouse ) {
2025-05-01 23:57:11 +02:00
const auto PMOUSE = m_pointers . emplace_back ( CVirtualPointer : : create ( mouse ) ) ;
2024-05-03 01:27:59 +01:00
2024-05-03 22:34:10 +01:00
setupMouse ( PMOUSE ) ;
2024-05-03 01:27:59 +01:00
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " New virtual mouse created " ) ;
2024-05-03 01:27:59 +01:00
}
2025-09-02 13:16:43 +02:00
void CInputManager : : newMouse ( SP < IPointer > mouse ) {
m_pointers . emplace_back ( mouse ) ;
setupMouse ( mouse ) ;
Debug : : log ( LOG , " New mouse created, pointer Hypr: {:x} " , rc < uintptr_t > ( mouse . get ( ) ) ) ;
}
2024-07-21 13:09:54 +02:00
void CInputManager : : newMouse ( SP < Aquamarine : : IPointer > mouse ) {
2025-05-01 23:57:11 +02:00
const auto PMOUSE = m_pointers . emplace_back ( CMouse : : create ( mouse ) ) ;
2022-04-17 21:40:04 +02:00
2024-05-03 22:34:10 +01:00
setupMouse ( PMOUSE ) ;
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " New mouse created, pointer AQ: {:x} " , rc < uintptr_t > ( mouse . get ( ) ) ) ;
2024-05-03 22:34:10 +01:00
}
void CInputManager : : setupMouse ( SP < IPointer > mauz ) {
2025-05-01 23:57:11 +02:00
m_hids . emplace_back ( mauz ) ;
2024-05-06 02:15:26 +01:00
2022-06-30 21:26:00 +02:00
try {
2025-04-29 19:51:07 +02:00
mauz - > m_hlName = getNameForNewDevice ( mauz - > m_deviceName ) ;
2022-12-16 17:17:31 +00:00
} catch ( std : : exception & e ) {
2022-06-30 21:26:00 +02:00
Debug : : log ( ERR , " Mouse had no name??? " ) ; // logic error
}
2024-07-21 13:09:54 +02:00
if ( mauz - > aq ( ) & & mauz - > aq ( ) - > getLibinputHandle ( ) ) {
const auto LIBINPUTDEV = mauz - > aq ( ) - > getLibinputHandle ( ) ;
2022-03-18 22:53:27 +01:00
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " New mouse has libinput sens {:.2f} ({:.2f}) with accel profile {} ({}) " , libinput_device_config_accel_get_speed ( LIBINPUTDEV ) ,
2025-08-14 19:44:56 +05:00
libinput_device_config_accel_get_default_speed ( LIBINPUTDEV ) , sc < int > ( libinput_device_config_accel_get_profile ( LIBINPUTDEV ) ) ,
sc < int > ( libinput_device_config_accel_get_default_profile ( LIBINPUTDEV ) ) ) ;
2022-03-18 22:53:27 +01:00
}
2024-05-05 22:18:10 +01:00
g_pPointerManager - > attachPointer ( mauz ) ;
2022-03-19 11:27:19 +01:00
2025-04-29 19:51:07 +02:00
mauz - > m_connected = true ;
2022-10-27 12:58:10 +01:00
2022-11-04 10:48:42 +00:00
setPointerConfigs ( ) ;
2025-07-08 09:56:40 -07:00
mauz - > m_events . destroy . listenStatic ( [ this , PMOUSE = mauz . get ( ) ] { destroyPointer ( PMOUSE - > m_self . lock ( ) ) ; } ) ;
2022-11-04 10:48:42 +00:00
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setMouse ( mauz ) ;
2022-04-17 21:40:04 +02:00
2025-05-01 23:57:11 +02:00
m_lastCursorMovement . reset ( ) ;
2022-03-18 22:53:27 +01:00
}
2022-10-05 23:21:22 +03:00
void CInputManager : : setPointerConfigs ( ) {
2025-05-01 23:57:11 +02:00
for ( auto const & m : m_pointers ) {
2025-04-29 19:51:07 +02:00
auto devname = m - > m_hlName ;
2022-07-28 21:38:30 +02:00
const auto HASCONFIG = g_pConfigManager - > deviceConfigExists ( devname ) ;
2022-07-19 19:26:53 +02:00
2022-10-27 12:58:10 +01:00
if ( HASCONFIG ) {
const auto ENABLED = g_pConfigManager - > getDeviceInt ( devname , " enabled " ) ;
2025-04-29 19:51:07 +02:00
if ( ENABLED & & ! m - > m_connected ) {
2024-05-05 22:18:10 +01:00
g_pPointerManager - > attachPointer ( m ) ;
2025-04-29 19:51:07 +02:00
m - > m_connected = true ;
} else if ( ! ENABLED & & m - > m_connected ) {
2024-05-05 22:18:10 +01:00
g_pPointerManager - > detachPointer ( m ) ;
2025-04-29 19:51:07 +02:00
m - > m_connected = false ;
2022-10-27 12:58:10 +01:00
}
}
2025-09-02 13:16:43 +02:00
if ( g_pConfigManager - > deviceConfigExplicitlySet ( devname , " scroll_factor " ) )
m - > m_scrollFactor = std : : clamp ( g_pConfigManager - > getDeviceFloat ( devname , " scroll_factor " , " input:scroll_factor " ) , 0.F , 100.F ) ;
else
m - > m_scrollFactor = std : : nullopt ;
2024-07-21 13:09:54 +02:00
if ( m - > aq ( ) & & m - > aq ( ) - > getLibinputHandle ( ) ) {
const auto LIBINPUTDEV = m - > aq ( ) - > getLibinputHandle ( ) ;
2022-07-19 19:26:53 +02:00
2023-07-06 16:26:38 +02:00
double touchw = 0 , touchh = 0 ;
const auto ISTOUCHPAD = libinput_device_has_capability ( LIBINPUTDEV , LIBINPUT_DEVICE_CAP_POINTER ) & &
libinput_device_get_size ( LIBINPUTDEV , & touchw , & touchh ) = = 0 ; // pointer with size is a touchpad
2023-09-06 19:16:46 +02:00
if ( g_pConfigManager - > getDeviceInt ( devname , " clickfinger_behavior " , " input:touchpad:clickfinger_behavior " ) = = 0 ) // toggle software buttons or clickfinger
2022-07-19 19:26:53 +02:00
libinput_device_config_click_set_method ( LIBINPUTDEV , LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS ) ;
else
libinput_device_config_click_set_method ( LIBINPUTDEV , LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER ) ;
2023-09-06 19:16:46 +02:00
if ( g_pConfigManager - > getDeviceInt ( devname , " left_handed " , " input:left_handed " ) = = 0 )
2022-10-04 21:46:41 +01:00
libinput_device_config_left_handed_set ( LIBINPUTDEV , 0 ) ;
else
libinput_device_config_left_handed_set ( LIBINPUTDEV , 1 ) ;
2022-12-16 17:17:31 +00:00
if ( libinput_device_config_middle_emulation_is_available ( LIBINPUTDEV ) ) { // middleclick on r+l mouse button pressed
2023-09-06 19:16:46 +02:00
if ( g_pConfigManager - > getDeviceInt ( devname , " middle_button_emulation " , " input:touchpad:middle_button_emulation " ) = = 1 )
2022-07-19 19:26:53 +02:00
libinput_device_config_middle_emulation_set_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED ) ;
else
libinput_device_config_middle_emulation_set_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED ) ;
2023-02-05 16:17:23 +02:00
2023-09-06 19:16:46 +02:00
const auto TAP_MAP = g_pConfigManager - > getDeviceString ( devname , " tap_button_map " , " input:touchpad:tap_button_map " ) ;
2025-05-31 23:49:50 +05:00
if ( TAP_MAP . empty ( ) | | TAP_MAP = = " lrm " )
2023-02-05 16:17:23 +02:00
libinput_device_config_tap_set_button_map ( LIBINPUTDEV , LIBINPUT_CONFIG_TAP_MAP_LRM ) ;
else if ( TAP_MAP = = " lmr " )
libinput_device_config_tap_set_button_map ( LIBINPUTDEV , LIBINPUT_CONFIG_TAP_MAP_LMR ) ;
else
Debug : : log ( WARN , " Tap button mapping unknown " ) ;
2022-07-19 19:26:53 +02:00
}
2023-09-06 19:16:46 +02:00
const auto SCROLLMETHOD = g_pConfigManager - > getDeviceString ( devname , " scroll_method " , " input:scroll_method " ) ;
2025-05-31 23:49:50 +05:00
if ( SCROLLMETHOD . empty ( ) ) {
2022-10-05 23:21:22 +03:00
libinput_device_config_scroll_set_method ( LIBINPUTDEV , libinput_device_config_scroll_get_default_method ( LIBINPUTDEV ) ) ;
} else if ( SCROLLMETHOD = = " no_scroll " ) {
libinput_device_config_scroll_set_method ( LIBINPUTDEV , LIBINPUT_CONFIG_SCROLL_NO_SCROLL ) ;
} else if ( SCROLLMETHOD = = " 2fg " ) {
libinput_device_config_scroll_set_method ( LIBINPUTDEV , LIBINPUT_CONFIG_SCROLL_2FG ) ;
} else if ( SCROLLMETHOD = = " edge " ) {
libinput_device_config_scroll_set_method ( LIBINPUTDEV , LIBINPUT_CONFIG_SCROLL_EDGE ) ;
} else if ( SCROLLMETHOD = = " on_button_down " ) {
libinput_device_config_scroll_set_method ( LIBINPUTDEV , LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN ) ;
} else {
Debug : : log ( WARN , " Scroll method unknown " ) ;
}
2023-09-06 19:16:46 +02:00
if ( g_pConfigManager - > getDeviceInt ( devname , " tap-and-drag " , " input:touchpad:tap-and-drag " ) = = 0 )
2022-12-22 23:05:26 +11:00
libinput_device_config_tap_set_drag_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_DRAG_DISABLED ) ;
else
libinput_device_config_tap_set_drag_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_DRAG_ENABLED ) ;
2025-06-15 11:45:06 +02:00
const auto TAP_DRAG_LOCK = g_pConfigManager - > getDeviceInt ( devname , " drag_lock " , " input:touchpad:drag_lock " ) ;
if ( TAP_DRAG_LOCK > = 0 & & TAP_DRAG_LOCK < = 2 ) {
2025-08-14 19:44:56 +05:00
libinput_device_config_tap_set_drag_lock_enabled ( LIBINPUTDEV , sc < libinput_config_drag_lock_state > ( TAP_DRAG_LOCK ) ) ;
2025-06-15 11:45:06 +02:00
}
2022-07-19 19:26:53 +02:00
2022-12-16 17:17:31 +00:00
if ( libinput_device_config_tap_get_finger_count ( LIBINPUTDEV ) ) // this is for tapping (like on a laptop)
2024-08-18 10:14:42 +03:00
libinput_device_config_tap_set_enabled ( LIBINPUTDEV ,
g_pConfigManager - > getDeviceInt ( devname , " tap-to-click " , " input:touchpad:tap-to-click " ) = = 1 ? LIBINPUT_CONFIG_TAP_ENABLED :
LIBINPUT_CONFIG_TAP_DISABLED ) ;
2022-07-19 19:26:53 +02:00
if ( libinput_device_config_scroll_has_natural_scroll ( LIBINPUTDEV ) ) {
2023-07-06 16:26:38 +02:00
if ( ISTOUCHPAD )
2023-09-06 16:14:18 +02:00
libinput_device_config_scroll_set_natural_scroll_enabled ( LIBINPUTDEV ,
2023-09-06 19:16:46 +02:00
g_pConfigManager - > getDeviceInt ( devname , " natural_scroll " , " input:touchpad:natural_scroll " ) ) ;
2022-07-19 19:26:53 +02:00
else
2023-09-06 19:16:46 +02:00
libinput_device_config_scroll_set_natural_scroll_enabled ( LIBINPUTDEV , g_pConfigManager - > getDeviceInt ( devname , " natural_scroll " , " input:natural_scroll " ) ) ;
2022-07-19 19:26:53 +02:00
}
2025-06-06 16:47:15 +02:00
if ( libinput_device_config_3fg_drag_get_finger_count ( LIBINPUTDEV ) > = 3 ) {
2025-08-14 19:44:56 +05:00
const auto DRAG_3FG_STATE = sc < libinput_config_3fg_drag_state > ( g_pConfigManager - > getDeviceInt ( devname , " drag_3fg " , " input:touchpad:drag_3fg " ) ) ;
2025-06-06 16:47:15 +02:00
libinput_device_config_3fg_drag_set_enabled ( LIBINPUTDEV , DRAG_3FG_STATE ) ;
}
2022-07-19 19:26:53 +02:00
if ( libinput_device_config_dwt_is_available ( LIBINPUTDEV ) ) {
2025-08-14 19:44:56 +05:00
const auto DWT = sc < enum libinput_config_dwt_state > ( g_pConfigManager - > getDeviceInt ( devname , " disable_while_typing " , " input:touchpad:disable_while_typing " ) ! = 0 ) ;
2022-07-19 19:26:53 +02:00
libinput_device_config_dwt_set_enabled ( LIBINPUTDEV , DWT ) ;
}
2023-09-06 19:16:46 +02:00
const auto LIBINPUTSENS = std : : clamp ( g_pConfigManager - > getDeviceFloat ( devname , " sensitivity " , " input:sensitivity " ) , - 1.f , 1.f ) ;
2022-07-19 19:26:53 +02:00
libinput_device_config_accel_set_speed ( LIBINPUTDEV , LIBINPUTSENS ) ;
2025-10-10 17:05:51 +02:00
if ( libinput_device_config_rotation_is_available ( LIBINPUTDEV ) ) {
const auto ROTATION = std : : clamp ( g_pConfigManager - > getDeviceInt ( devname , " rotation " , " input:rotation " ) , 0 , 359 ) ;
libinput_device_config_rotation_set_angle ( LIBINPUTDEV , ROTATION ) ;
}
2025-04-29 19:51:07 +02:00
m - > m_flipX = g_pConfigManager - > getDeviceInt ( devname , " flip_x " , " input:touchpad:flip_x " ) ! = 0 ;
m - > m_flipY = g_pConfigManager - > getDeviceInt ( devname , " flip_y " , " input:touchpad:flip_y " ) ! = 0 ;
2025-03-03 15:56:01 -05:00
2023-09-06 19:16:46 +02:00
const auto ACCELPROFILE = g_pConfigManager - > getDeviceString ( devname , " accel_profile " , " input:accel_profile " ) ;
2023-12-10 18:30:08 +02:00
const auto SCROLLPOINTS = g_pConfigManager - > getDeviceString ( devname , " scroll_points " , " input:scroll_points " ) ;
2022-10-05 23:21:22 +03:00
2023-12-10 18:30:08 +02:00
if ( ACCELPROFILE . empty ( ) ) {
2022-10-05 23:21:22 +03:00
libinput_device_config_accel_set_profile ( LIBINPUTDEV , libinput_device_config_accel_get_default_profile ( LIBINPUTDEV ) ) ;
} else if ( ACCELPROFILE = = " adaptive " ) {
libinput_device_config_accel_set_profile ( LIBINPUTDEV , LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE ) ;
} else if ( ACCELPROFILE = = " flat " ) {
libinput_device_config_accel_set_profile ( LIBINPUTDEV , LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT ) ;
2023-10-15 20:07:23 +02:00
} else if ( ACCELPROFILE . starts_with ( " custom " ) ) {
2023-12-10 18:30:08 +02:00
CVarList accelValues = { ACCELPROFILE , 0 , ' ' } ;
2023-05-05 16:06:13 +01:00
try {
2023-12-10 18:30:08 +02:00
double accelStep = std : : stod ( accelValues [ 1 ] ) ;
std : : vector < double > accelPoints ;
for ( size_t i = 2 ; i < accelValues . size ( ) ; + + i ) {
accelPoints . push_back ( std : : stod ( accelValues [ i ] ) ) ;
}
2023-05-05 16:06:13 +01:00
const auto CONFIG = libinput_config_accel_create ( LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM ) ;
2023-12-10 18:30:08 +02:00
if ( ! SCROLLPOINTS . empty ( ) ) {
CVarList scrollValues = { SCROLLPOINTS , 0 , ' ' } ;
try {
double scrollStep = std : : stod ( scrollValues [ 0 ] ) ;
std : : vector < double > scrollPoints ;
for ( size_t i = 1 ; i < scrollValues . size ( ) ; + + i ) {
scrollPoints . push_back ( std : : stod ( scrollValues [ i ] ) ) ;
}
libinput_config_accel_set_points ( CONFIG , LIBINPUT_ACCEL_TYPE_SCROLL , scrollStep , scrollPoints . size ( ) , scrollPoints . data ( ) ) ;
} catch ( std : : exception & e ) { Debug : : log ( ERR , " Invalid values in scroll_points " ) ; }
}
libinput_config_accel_set_points ( CONFIG , LIBINPUT_ACCEL_TYPE_MOTION , accelStep , accelPoints . size ( ) , accelPoints . data ( ) ) ;
2023-11-25 20:09:21 +05:30
libinput_device_config_accel_apply ( LIBINPUTDEV , CONFIG ) ;
2023-05-05 16:06:13 +01:00
libinput_config_accel_destroy ( CONFIG ) ;
} catch ( std : : exception & e ) { Debug : : log ( ERR , " Invalid values in custom accel profile " ) ; }
2022-10-05 23:21:22 +03:00
} else {
Debug : : log ( WARN , " Unknown acceleration profile, falling back to default " ) ;
2022-11-21 23:26:18 +00:00
}
2023-09-06 19:16:46 +02:00
const auto SCROLLBUTTON = g_pConfigManager - > getDeviceInt ( devname , " scroll_button " , " input:scroll_button " ) ;
2022-11-21 23:26:18 +00:00
libinput_device_config_scroll_set_button ( LIBINPUTDEV , SCROLLBUTTON = = 0 ? libinput_device_config_scroll_get_default_button ( LIBINPUTDEV ) : SCROLLBUTTON ) ;
2022-10-05 23:21:22 +03:00
2023-09-06 19:16:46 +02:00
const auto SCROLLBUTTONLOCK = g_pConfigManager - > getDeviceInt ( devname , " scroll_button_lock " , " input:scroll_button_lock " ) ;
2023-09-06 21:54:48 +09:00
2023-09-06 16:14:18 +02:00
libinput_device_config_scroll_set_button_lock ( LIBINPUTDEV ,
SCROLLBUTTONLOCK = = 0 ? LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED : LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED ) ;
2023-09-06 21:54:48 +09:00
2025-04-29 19:51:07 +02:00
Debug : : log ( LOG , " Applied config to mouse {}, sens {:.2f} " , m - > m_hlName , LIBINPUTSENS ) ;
2022-07-19 19:26:53 +02:00
}
}
}
2024-05-06 02:15:26 +01:00
static void removeFromHIDs ( WP < IHID > hid ) {
2025-05-01 23:57:11 +02:00
std : : erase_if ( g_pInputManager - > m_hids , [ hid ] ( const auto & e ) { return e . expired ( ) | | e = = hid ; } ) ;
2024-05-06 02:15:26 +01:00
g_pInputManager - > updateCapabilities ( ) ;
}
2024-05-03 22:34:10 +01:00
void CInputManager : : destroyKeyboard ( SP < IKeyboard > pKeyboard ) {
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " Keyboard at {:x} removed " , rc < uintptr_t > ( pKeyboard . get ( ) ) ) ;
2024-02-28 00:21:22 +01:00
2025-05-01 23:57:11 +02:00
std : : erase_if ( m_keyboards , [ pKeyboard ] ( const auto & other ) { return other = = pKeyboard ; } ) ;
2022-06-03 18:59:39 +02:00
2025-05-31 23:49:50 +05:00
if ( ! m_keyboards . empty ( ) ) {
2024-06-12 17:03:04 +02:00
bool found = false ;
2025-05-01 23:57:11 +02:00
for ( auto const & k : m_keyboards | std : : views : : reverse ) {
2024-07-21 13:09:54 +02:00
if ( ! k )
2024-06-12 17:03:04 +02:00
continue ;
g_pSeatManager - > setKeyboard ( k ) ;
found = true ;
break ;
}
if ( ! found )
g_pSeatManager - > setKeyboard ( nullptr ) ;
} else
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setKeyboard ( nullptr ) ;
2024-05-06 02:15:26 +01:00
removeFromHIDs ( pKeyboard ) ;
2022-03-18 23:25:26 +01:00
}
2024-05-03 22:34:10 +01:00
void CInputManager : : destroyPointer ( SP < IPointer > mouse ) {
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " Pointer at {:x} removed " , rc < uintptr_t > ( mouse . get ( ) ) ) ;
2024-07-21 13:09:54 +02:00
2025-05-01 23:57:11 +02:00
std : : erase_if ( m_pointers , [ mouse ] ( const auto & other ) { return other = = mouse ; } ) ;
2022-04-17 21:40:04 +02:00
2025-05-31 23:49:50 +05:00
g_pSeatManager - > setMouse ( ! m_pointers . empty ( ) ? m_pointers . front ( ) : nullptr ) ;
2022-05-12 12:13:02 +02:00
2025-05-02 17:07:20 +02:00
if ( ! g_pSeatManager - > m_mouse . expired ( ) )
2022-08-09 20:36:21 +02:00
unconstrainMouse ( ) ;
2024-05-06 02:15:26 +01:00
removeFromHIDs ( mouse ) ;
2022-03-18 23:25:26 +01:00
}
2024-05-03 22:34:10 +01:00
void CInputManager : : destroyTouchDevice ( SP < ITouch > touch ) {
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " Touch device at {:x} removed " , rc < uintptr_t > ( touch . get ( ) ) ) ;
2022-12-16 17:17:31 +00:00
2025-05-01 23:57:11 +02:00
std : : erase_if ( m_touches , [ touch ] ( const auto & other ) { return other = = touch ; } ) ;
2024-05-06 02:15:26 +01:00
removeFromHIDs ( touch ) ;
}
void CInputManager : : destroyTablet ( SP < CTablet > tablet ) {
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " Tablet device at {:x} removed " , rc < uintptr_t > ( tablet . get ( ) ) ) ;
2024-05-06 02:15:26 +01:00
2025-05-01 23:57:11 +02:00
std : : erase_if ( m_tablets , [ tablet ] ( const auto & other ) { return other = = tablet ; } ) ;
2024-05-06 02:15:26 +01:00
removeFromHIDs ( tablet ) ;
}
void CInputManager : : destroyTabletTool ( SP < CTabletTool > tool ) {
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " Tablet tool at {:x} removed " , rc < uintptr_t > ( tool . get ( ) ) ) ;
2024-05-06 02:15:26 +01:00
2025-05-01 23:57:11 +02:00
std : : erase_if ( m_tabletTools , [ tool ] ( const auto & other ) { return other = = tool ; } ) ;
2024-05-06 02:15:26 +01:00
removeFromHIDs ( tool ) ;
}
void CInputManager : : destroyTabletPad ( SP < CTabletPad > pad ) {
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " Tablet pad at {:x} removed " , rc < uintptr_t > ( pad . get ( ) ) ) ;
2024-05-06 02:15:26 +01:00
2025-05-01 23:57:11 +02:00
std : : erase_if ( m_tabletPads , [ pad ] ( const auto & other ) { return other = = pad ; } ) ;
2024-05-06 02:15:26 +01:00
removeFromHIDs ( pad ) ;
2022-11-12 13:12:37 +02:00
}
2024-05-15 00:14:43 +09:00
void CInputManager : : updateKeyboardsLeds ( SP < IKeyboard > pKeyboard ) {
2025-05-14 17:48:17 +01:00
if ( ! pKeyboard | | pKeyboard - > isVirtual ( ) )
2024-05-15 00:14:43 +09:00
return ;
2024-07-28 19:46:38 +09:00
std : : optional < uint32_t > leds = pKeyboard - > getLEDs ( ) ;
if ( ! leds . has_value ( ) )
return ;
2025-05-01 23:57:11 +02:00
for ( auto const & k : m_keyboards ) {
2024-07-28 19:46:38 +09:00
k - > updateLEDs ( leds . value ( ) ) ;
}
2024-05-15 00:14:43 +09:00
}
2025-07-08 09:56:40 -07:00
void CInputManager : : onKeyboardKey ( const IKeyboard : : SKeyEvent & event , SP < IKeyboard > pKeyboard ) {
2025-05-18 18:13:20 +01:00
if ( ! pKeyboard - > m_enabled | | ! pKeyboard - > m_allowed )
2022-12-16 17:20:51 +00:00
return ;
2024-05-03 22:34:10 +01:00
const bool DISALLOWACTION = pKeyboard - > isVirtual ( ) & & shouldIgnoreVirtualKeyboard ( pKeyboard ) ;
2024-05-01 16:41:17 +01:00
2025-08-04 16:29:39 -03:00
const auto IME = m_relay . m_inputMethod . lock ( ) ;
const bool HASIME = IME & & IME - > hasGrab ( ) ;
const bool USEIME = HASIME & & ! DISALLOWACTION ;
2024-05-03 22:34:10 +01:00
const auto EMAP = std : : unordered_map < std : : string , std : : any > { { " keyboard " , pKeyboard } , { " event " , event } } ;
2023-11-30 18:44:58 +00:00
EMIT_HOOK_EVENT_CANCELLABLE ( " keyPress " , EMAP ) ;
2025-08-04 16:29:39 -03:00
bool passEvent = DISALLOWACTION ;
2024-05-03 22:34:10 +01:00
2025-08-04 16:29:39 -03:00
if ( ! DISALLOWACTION )
passEvent = g_pKeybindManager - > onKeyEvent ( event , pKeyboard ) ;
2022-08-05 16:21:08 +02:00
2025-08-04 16:29:39 -03:00
if ( passEvent ) {
if ( USEIME ) {
2024-07-21 13:09:54 +02:00
IME - > setKeyboard ( pKeyboard ) ;
2025-07-08 09:56:40 -07:00
IME - > sendKey ( event . timeMs , event . keycode , event . state ) ;
2022-08-05 16:21:08 +02:00
} else {
2025-08-04 16:29:39 -03:00
const auto PRESSED = shareKeyFromAllKBs ( event . keycode , event . state = = WL_KEYBOARD_KEY_STATE_PRESSED ) ;
const auto CONTAINS = std : : ranges : : contains ( m_pressed , event . keycode ) ;
if ( CONTAINS & & PRESSED )
return ;
if ( ! CONTAINS & & ! PRESSED )
return ;
if ( CONTAINS )
std : : erase ( m_pressed , event . keycode ) ;
else
m_pressed . emplace_back ( event . keycode ) ;
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setKeyboard ( pKeyboard ) ;
2025-07-08 09:56:40 -07:00
g_pSeatManager - > sendKeyboardKey ( event . timeMs , event . keycode , event . state ) ;
2022-08-05 16:21:08 +02:00
}
2022-11-12 13:12:37 +02:00
2024-05-15 00:14:43 +09:00
updateKeyboardsLeds ( pKeyboard ) ;
2022-03-19 22:03:40 +01:00
}
2022-03-18 23:06:45 +01:00
}
2022-03-17 20:55:04 +01:00
2024-05-03 22:34:10 +01:00
void CInputManager : : onKeyboardMod ( SP < IKeyboard > pKeyboard ) {
2025-04-29 19:51:07 +02:00
if ( ! pKeyboard - > m_enabled )
2022-12-16 17:20:51 +00:00
return ;
2024-05-03 22:34:10 +01:00
const bool DISALLOWACTION = pKeyboard - > isVirtual ( ) & & shouldIgnoreVirtualKeyboard ( pKeyboard ) ;
2022-08-05 16:21:08 +02:00
2025-08-04 16:29:39 -03:00
auto MODS = pKeyboard - > m_modifiersState ;
const auto ALLMODS = shareModsFromAllKBs ( MODS . depressed ) ;
MODS . depressed = ALLMODS ;
2025-09-20 12:57:39 -03:00
m_lastMods = MODS . depressed ;
2022-09-04 18:46:28 +02:00
2025-05-01 23:57:11 +02:00
const auto IME = m_relay . m_inputMethod . lock ( ) ;
2024-05-01 16:41:17 +01:00
if ( IME & & IME - > hasGrab ( ) & & ! DISALLOWACTION ) {
2024-07-21 13:09:54 +02:00
IME - > setKeyboard ( pKeyboard ) ;
2024-05-01 16:41:17 +01:00
IME - > sendMods ( MODS . depressed , MODS . latched , MODS . locked , MODS . group ) ;
2022-08-05 16:21:08 +02:00
} else {
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setKeyboard ( pKeyboard ) ;
g_pSeatManager - > sendKeyboardMods ( MODS . depressed , MODS . latched , MODS . locked , MODS . group ) ;
2022-08-05 16:21:08 +02:00
}
2022-08-18 17:17:33 +02:00
2024-05-15 00:14:43 +09:00
updateKeyboardsLeds ( pKeyboard ) ;
2022-08-18 17:17:33 +02:00
2025-04-29 19:51:07 +02:00
if ( pKeyboard - > m_modifiersState . group ! = pKeyboard - > m_activeLayout ) {
pKeyboard - > m_activeLayout = pKeyboard - > m_modifiersState . group ;
2022-08-18 17:17:33 +02:00
2024-05-03 22:34:10 +01:00
const auto LAYOUT = pKeyboard - > getActiveLayout ( ) ;
2023-02-19 20:54:53 +00:00
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " LAYOUT CHANGED TO {} GROUP {} " , LAYOUT , MODS . group ) ;
2024-03-02 01:46:16 +00:00
2025-04-29 19:51:07 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , pKeyboard - > m_hlName + " , " + LAYOUT } ) ;
2024-05-03 22:34:10 +01:00
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < std : : any > { pKeyboard , LAYOUT } ) ) ;
2022-12-16 17:17:31 +00:00
}
2022-03-21 19:28:43 +01:00
}
2024-05-03 22:34:10 +01:00
bool CInputManager : : shouldIgnoreVirtualKeyboard ( SP < IKeyboard > pKeyboard ) {
2025-09-20 12:57:39 -03:00
if ( ! pKeyboard )
return true ;
2024-05-03 22:34:10 +01:00
if ( ! pKeyboard - > isVirtual ( ) )
2024-05-03 00:31:48 +01:00
return false ;
2025-09-20 12:57:39 -03:00
const auto CLIENT = pKeyboard - > getClient ( ) ;
const auto DISALLOWACTION = CLIENT & & ! m_relay . m_inputMethod . expired ( ) & & m_relay . m_inputMethod - > grabClient ( ) = = CLIENT ;
if ( DISALLOWACTION )
pKeyboard - > setShareStatesAuto ( false ) ;
2024-05-03 22:34:10 +01:00
2025-09-20 12:57:39 -03:00
return DISALLOWACTION ;
2022-11-07 22:22:13 +00:00
}
2025-08-20 13:01:31 +02:00
void CInputManager : : refocus ( std : : optional < Vector2D > overridePos ) {
mouseMoveUnified ( 0 , true , false , overridePos ) ;
2022-03-31 17:25:23 +02:00
}
2025-04-07 20:52:11 +02:00
bool CInputManager : : refocusLastWindow ( PHLMONITOR pMonitor ) {
2025-05-01 23:57:11 +02:00
if ( ! m_exclusiveLSes . empty ( ) ) {
2025-04-07 20:52:11 +02:00
Debug : : log ( LOG , " CInputManager::refocusLastWindow: ignoring, exclusive LS present. " ) ;
return false ;
}
2024-06-11 10:35:30 -07:00
if ( ! pMonitor ) {
refocus ( ) ;
2025-04-07 20:52:11 +02:00
return true ;
2024-06-11 10:35:30 -07:00
}
Vector2D surfaceCoords ;
PHLLS pFoundLayerSurface ;
SP < CWLSurfaceResource > foundSurface = nullptr ;
g_pInputManager - > releaseAllMouseButtons ( ) ;
// then any surfaces above windows on the same monitor
2024-11-09 02:25:54 +00:00
if ( ! foundSurface ) {
2025-04-30 23:45:20 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( g_pInputManager - > getMouseCoordsInternal ( ) , & pMonitor - > m_layerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY ] ,
2024-06-11 10:35:30 -07:00
& surfaceCoords , & pFoundLayerSurface ) ;
2025-04-24 20:49:49 +02:00
if ( pFoundLayerSurface & & pFoundLayerSurface - > m_interactivity = = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND )
2024-11-09 02:25:54 +00:00
foundSurface = nullptr ;
}
2024-06-11 10:35:30 -07:00
2024-11-09 02:25:54 +00:00
if ( ! foundSurface ) {
2025-04-30 23:45:20 +02:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( g_pInputManager - > getMouseCoordsInternal ( ) , & pMonitor - > m_layerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_TOP ] ,
2024-06-11 10:35:30 -07:00
& surfaceCoords , & pFoundLayerSurface ) ;
2025-04-24 20:49:49 +02:00
if ( pFoundLayerSurface & & pFoundLayerSurface - > m_interactivity = = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND )
2024-11-09 02:25:54 +00:00
foundSurface = nullptr ;
}
2024-06-11 10:35:30 -07:00
2025-04-28 22:25:22 +02:00
if ( ! foundSurface & & g_pCompositor - > m_lastWindow . lock ( ) & & g_pCompositor - > m_lastWindow - > m_workspace & & g_pCompositor - > m_lastWindow - > m_workspace - > isVisibleNotCovered ( ) ) {
2024-06-11 10:35:30 -07:00
// then the last focused window if we're on the same workspace as it
2025-04-22 15:23:29 +02:00
const auto PLASTWINDOW = g_pCompositor - > m_lastWindow . lock ( ) ;
2024-06-11 10:35:30 -07:00
g_pCompositor - > focusWindow ( PLASTWINDOW ) ;
} else {
// otherwise fall back to a normal refocus.
2024-07-27 17:49:27 +02:00
2025-05-03 16:02:49 +02:00
if ( foundSurface & & ! foundSurface - > m_hlSurface - > keyboardFocusable ( ) ) {
2025-04-22 15:23:29 +02:00
const auto PLASTWINDOW = g_pCompositor - > m_lastWindow . lock ( ) ;
2024-07-27 17:49:27 +02:00
g_pCompositor - > focusWindow ( PLASTWINDOW ) ;
}
2024-06-11 10:35:30 -07:00
refocus ( ) ;
}
2025-04-07 20:52:11 +02:00
return true ;
2024-06-11 10:35:30 -07:00
}
2022-08-09 20:36:21 +02:00
void CInputManager : : unconstrainMouse ( ) {
2025-05-02 17:07:20 +02:00
if ( g_pSeatManager - > m_mouse . expired ( ) )
2022-08-09 20:36:21 +02:00
return ;
2025-05-01 23:57:11 +02:00
for ( auto const & c : m_constraints ) {
2024-04-26 23:55:41 +01:00
const auto C = c . lock ( ) ;
if ( ! C )
continue ;
if ( ! C - > isActive ( ) )
2024-03-02 21:04:55 +00:00
continue ;
2022-08-09 20:36:21 +02:00
2024-04-26 23:55:41 +01:00
C - > deactivate ( ) ;
2024-03-02 21:04:55 +00:00
}
2022-08-09 20:36:21 +02:00
}
2024-03-02 21:04:55 +00:00
bool CInputManager : : isConstrained ( ) {
2025-05-30 18:25:59 +05:00
return std : : ranges : : any_of ( m_constraints , [ ] ( auto const & c ) {
2024-10-27 18:51:26 +01:00
const auto constraint = c . lock ( ) ;
2025-04-22 15:23:29 +02:00
return constraint & & constraint - > isActive ( ) & & constraint - > owner ( ) - > resource ( ) = = g_pCompositor - > m_lastFocus ;
2024-10-27 18:51:26 +01:00
} ) ;
2022-04-17 21:40:04 +02:00
}
2022-06-09 12:46:55 +02:00
2024-10-12 03:29:51 +03:00
bool CInputManager : : isLocked ( ) {
if ( ! isConstrained ( ) )
return false ;
2025-04-22 15:23:29 +02:00
const auto SURF = CWLSurface : : fromResource ( g_pCompositor - > m_lastFocus . lock ( ) ) ;
2024-10-12 03:29:51 +03:00
const auto CONSTRAINT = SURF ? SURF - > constraint ( ) : nullptr ;
return CONSTRAINT & & CONSTRAINT - > isLocked ( ) ;
}
2022-12-05 14:28:27 +00:00
void CInputManager : : updateCapabilities ( ) {
uint32_t caps = 0 ;
2025-05-01 23:57:11 +02:00
for ( auto const & h : m_hids ) {
2024-05-06 02:15:26 +01:00
if ( h . expired ( ) )
continue ;
2024-06-29 00:23:02 +02:00
caps | = h - > getCapabilities ( ) ;
2024-05-06 02:15:26 +01:00
}
2022-12-05 14:28:27 +00:00
2024-05-10 18:27:57 +01:00
g_pSeatManager - > updateCapabilities ( caps ) ;
2025-05-01 23:57:11 +02:00
m_capabilities = caps ;
2022-07-09 23:24:08 +02:00
}
2025-08-04 16:29:39 -03:00
const std : : vector < uint32_t > & CInputManager : : getKeysFromAllKBs ( ) {
return m_pressed ;
}
uint32_t CInputManager : : getModsFromAllKBs ( ) {
return m_lastMods ;
}
bool CInputManager : : shareKeyFromAllKBs ( uint32_t key , bool pressed ) {
bool finalState = pressed ;
2022-07-09 23:24:08 +02:00
2025-08-04 16:29:39 -03:00
if ( finalState )
return finalState ;
2022-07-09 23:24:08 +02:00
2025-05-01 23:57:11 +02:00
for ( auto const & kb : m_keyboards ) {
2025-08-04 16:29:39 -03:00
if ( ! kb - > shareStates ( ) )
continue ;
if ( kb - > isVirtual ( ) & & shouldIgnoreVirtualKeyboard ( kb ) )
continue ;
if ( ! kb - > m_enabled )
continue ;
const bool PRESSED = kb - > getPressed ( key ) ;
if ( PRESSED )
return PRESSED ;
}
return finalState ;
}
uint32_t CInputManager : : shareModsFromAllKBs ( uint32_t depressed ) {
uint32_t finalMask = depressed ;
for ( auto const & kb : m_keyboards ) {
if ( ! kb - > shareStates ( ) )
continue ;
2024-05-03 22:34:10 +01:00
if ( kb - > isVirtual ( ) & & shouldIgnoreVirtualKeyboard ( kb ) )
2022-09-05 11:19:40 +02:00
continue ;
2025-04-29 19:51:07 +02:00
if ( ! kb - > m_enabled )
2022-12-16 17:20:51 +00:00
continue ;
2024-07-21 13:09:54 +02:00
finalMask | = kb - > getModifiers ( ) ;
2022-07-09 23:24:08 +02:00
}
return finalMask ;
2022-07-12 19:11:54 +08:00
}
2022-08-16 16:10:20 +02:00
2022-08-18 17:50:32 +02:00
void CInputManager : : disableAllKeyboards ( bool virt ) {
2025-05-01 23:57:11 +02:00
for ( auto const & k : m_keyboards ) {
2024-05-03 22:34:10 +01:00
if ( k - > isVirtual ( ) ! = virt )
2022-08-18 17:50:32 +02:00
continue ;
2025-04-29 19:51:07 +02:00
k - > m_active = false ;
2022-08-18 17:50:32 +02:00
}
2022-08-19 21:01:51 +03:00
}
2022-09-21 14:39:25 +01:00
2024-07-21 13:09:54 +02:00
void CInputManager : : newTouchDevice ( SP < Aquamarine : : ITouch > pDevice ) {
2025-05-01 23:57:11 +02:00
const auto PNEWDEV = m_touches . emplace_back ( CTouchDevice : : create ( pDevice ) ) ;
m_hids . emplace_back ( PNEWDEV ) ;
2022-09-21 14:39:25 +01:00
2022-10-07 16:03:52 +02:00
try {
2025-04-29 19:51:07 +02:00
PNEWDEV - > m_hlName = getNameForNewDevice ( PNEWDEV - > m_deviceName ) ;
2022-12-16 17:17:31 +00:00
} catch ( std : : exception & e ) {
2022-10-07 16:03:52 +02:00
Debug : : log ( ERR , " Touch Device had no name??? " ) ; // logic error
}
2023-05-24 22:17:33 +02:00
setTouchDeviceConfigs ( PNEWDEV ) ;
2024-05-05 22:18:10 +01:00
g_pPointerManager - > attachTouch ( PNEWDEV ) ;
2022-09-21 14:39:25 +01:00
2025-07-08 09:56:40 -07:00
PNEWDEV - > m_events . destroy . listenStatic ( [ this , dev = PNEWDEV . get ( ) ] {
auto PDEV = dev - > m_self . lock ( ) ;
2024-05-04 00:48:25 +01:00
2025-07-08 09:56:40 -07:00
if ( ! PDEV )
return ;
2024-05-04 00:48:25 +01:00
2025-07-08 09:56:40 -07:00
destroyTouchDevice ( PDEV ) ;
} ) ;
2022-09-21 14:39:25 +01:00
2025-08-14 19:44:56 +05:00
Debug : : log ( LOG , " New touch device added at {:x} " , rc < uintptr_t > ( PNEWDEV . get ( ) ) ) ;
2022-09-21 14:39:25 +01:00
}
2024-05-03 22:34:10 +01:00
void CInputManager : : setTouchDeviceConfigs ( SP < ITouch > dev ) {
2024-07-21 16:45:40 +02:00
auto setConfig = [ ] ( SP < ITouch > PTOUCHDEV ) - > void {
if ( PTOUCHDEV - > aq ( ) & & PTOUCHDEV - > aq ( ) - > getLibinputHandle ( ) ) {
const auto LIBINPUTDEV = PTOUCHDEV - > aq ( ) - > getLibinputHandle ( ) ;
2022-10-07 16:03:52 +02:00
2025-04-29 19:51:07 +02:00
const auto ENABLED = g_pConfigManager - > getDeviceInt ( PTOUCHDEV - > m_hlName , " enabled " , " input:touchdevice:enabled " ) ;
2024-01-23 19:15:01 -05:00
const auto mode = ENABLED ? LIBINPUT_CONFIG_SEND_EVENTS_ENABLED : LIBINPUT_CONFIG_SEND_EVENTS_DISABLED ;
if ( libinput_device_config_send_events_get_mode ( LIBINPUTDEV ) ! = mode )
libinput_device_config_send_events_set_mode ( LIBINPUTDEV , mode ) ;
2025-03-06 14:24:36 +03:00
if ( libinput_device_config_calibration_has_matrix ( LIBINPUTDEV ) ) {
2025-04-29 19:51:07 +02:00
Debug : : log ( LOG , " Setting calibration matrix for device {} " , PTOUCHDEV - > m_hlName ) ;
2025-03-06 14:24:36 +03:00
// default value of transform being -1 means it's unset.
2025-04-29 19:51:07 +02:00
const int ROTATION = std : : clamp ( g_pConfigManager - > getDeviceInt ( PTOUCHDEV - > m_hlName , " transform " , " input:touchdevice:transform " ) , - 1 , 7 ) ;
2025-03-06 14:24:36 +03:00
if ( ROTATION > - 1 )
libinput_device_config_calibration_set_matrix ( LIBINPUTDEV , MATRICES [ ROTATION ] ) ;
}
2022-10-14 12:38:44 +01:00
2025-04-29 19:51:07 +02:00
auto output = g_pConfigManager - > getDeviceString ( PTOUCHDEV - > m_hlName , " output " , " input:touchdevice:output " ) ;
2024-02-27 23:11:59 +01:00
bool bound = ! output . empty ( ) & & output ! = STRVAL_EMPTY ;
const bool AUTODETECT = output = = " [[Auto]] " ;
if ( ! bound & & AUTODETECT ) {
2024-07-21 13:09:54 +02:00
// FIXME:
// const auto DEFAULTOUTPUT = PTOUCHDEV->wlr()->output_name;
// if (DEFAULTOUTPUT) {
// output = DEFAULTOUTPUT;
// bound = true;
// }
2024-02-27 23:11:59 +01:00
}
2025-04-29 19:51:07 +02:00
PTOUCHDEV - > m_boundOutput = bound ? output : " " ;
const auto PMONITOR = bound ? g_pCompositor - > getMonitorFromName ( output ) : nullptr ;
2024-02-27 23:11:59 +01:00
if ( PMONITOR ) {
2025-04-30 23:45:20 +02:00
Debug : : log ( LOG , " Binding touch device {} to output {} " , PTOUCHDEV - > m_hlName , PMONITOR - > m_name ) ;
2024-05-05 22:18:10 +01:00
// wlr_cursor_map_input_to_output(g_pCompositor->m_sWLRCursor, &PTOUCHDEV->wlr()->base, PMONITOR->output);
2024-02-27 23:11:59 +01:00
} else if ( bound )
2025-04-29 19:51:07 +02:00
Debug : : log ( ERR , " Failed to bind touch device {} to output '{}': monitor not found " , PTOUCHDEV - > m_hlName , output ) ;
2022-10-07 16:03:52 +02:00
}
2023-05-24 22:17:33 +02:00
} ;
if ( dev ) {
setConfig ( dev ) ;
return ;
}
2025-05-01 23:57:11 +02:00
for ( auto const & m : m_touches ) {
2024-05-03 22:34:10 +01:00
setConfig ( m ) ;
2022-10-07 16:03:52 +02:00
}
}
2022-12-21 15:11:39 +00:00
void CInputManager : : setTabletConfigs ( ) {
2025-05-01 23:57:11 +02:00
for ( auto const & t : m_tablets ) {
2024-07-21 13:09:54 +02:00
if ( t - > aq ( ) - > getLibinputHandle ( ) ) {
2025-04-29 19:51:07 +02:00
const auto NAME = t - > m_hlName ;
2024-07-21 13:09:54 +02:00
const auto LIBINPUTDEV = t - > aq ( ) - > getLibinputHandle ( ) ;
2022-12-21 15:11:39 +00:00
2024-05-06 02:15:26 +01:00
const auto RELINPUT = g_pConfigManager - > getDeviceInt ( NAME , " relative_input " , " input:tablet:relative_input " ) ;
2025-04-29 19:51:07 +02:00
t - > m_relativeInput = RELINPUT ;
2023-12-09 04:07:28 +00:00
2025-03-06 14:24:36 +03:00
const int ROTATION = std : : clamp ( g_pConfigManager - > getDeviceInt ( NAME , " transform " , " input:tablet:transform " ) , - 1 , 7 ) ;
2024-05-06 02:15:26 +01:00
Debug : : log ( LOG , " Setting calibration matrix for device {} " , NAME ) ;
2025-03-06 14:24:36 +03:00
if ( ROTATION > - 1 )
libinput_device_config_calibration_set_matrix ( LIBINPUTDEV , MATRICES [ ROTATION ] ) ;
2023-01-15 20:38:58 +01:00
2024-05-06 02:15:26 +01:00
if ( g_pConfigManager - > getDeviceInt ( NAME , " left_handed " , " input:tablet:left_handed " ) = = 0 )
2024-03-20 07:00:43 +03:00
libinput_device_config_left_handed_set ( LIBINPUTDEV , 0 ) ;
else
libinput_device_config_left_handed_set ( LIBINPUTDEV , 1 ) ;
2024-05-06 02:15:26 +01:00
const auto OUTPUT = g_pConfigManager - > getDeviceString ( NAME , " output " , " input:tablet:output " ) ;
if ( OUTPUT ! = STRVAL_EMPTY ) {
Debug : : log ( LOG , " Binding tablet {} to output {} " , NAME , OUTPUT ) ;
2025-04-29 19:51:07 +02:00
t - > m_boundOutput = OUTPUT ;
2024-05-06 02:15:26 +01:00
} else
2025-04-29 19:51:07 +02:00
t - > m_boundOutput = " " ;
2024-05-06 02:15:26 +01:00
const auto REGION_POS = g_pConfigManager - > getDeviceVec ( NAME , " region_position " , " input:tablet:region_position " ) ;
const auto REGION_SIZE = g_pConfigManager - > getDeviceVec ( NAME , " region_size " , " input:tablet:region_size " ) ;
2025-04-29 19:51:07 +02:00
t - > m_boundBox = { REGION_POS , REGION_SIZE } ;
2024-05-06 02:15:26 +01:00
2024-11-11 13:45:33 +00:00
const auto ABSOLUTE_REGION_POS = g_pConfigManager - > getDeviceInt ( NAME , " absolute_region_position " , " input:tablet:absolute_region_position " ) ;
2025-04-29 19:51:07 +02:00
t - > m_absolutePos = ABSOLUTE_REGION_POS ;
2024-11-11 13:45:33 +00:00
2024-05-06 02:15:26 +01:00
const auto ACTIVE_AREA_SIZE = g_pConfigManager - > getDeviceVec ( NAME , " active_area_size " , " input:tablet:active_area_size " ) ;
const auto ACTIVE_AREA_POS = g_pConfigManager - > getDeviceVec ( NAME , " active_area_position " , " input:tablet:active_area_position " ) ;
2024-03-23 23:31:03 +03:00
if ( ACTIVE_AREA_SIZE . x ! = 0 | | ACTIVE_AREA_SIZE . y ! = 0 ) {
2025-09-13 01:11:30 +02:00
// Rotations with an odd index (90 and 270 degrees, and their flipped variants) swap the X and Y axes.
// Use swapped dimensions when the axes are rotated, otherwise keep the original ones.
const Vector2D effectivePhysicalSize = ( ROTATION % 2 ) ? Vector2D { t - > aq ( ) - > physicalSize . y , t - > aq ( ) - > physicalSize . x } : t - > aq ( ) - > physicalSize ;
// Scale the active area coordinates into normalized space (0– 1) using the effective dimensions.
t - > m_activeArea = CBox { ACTIVE_AREA_POS . x / effectivePhysicalSize . x , ACTIVE_AREA_POS . y / effectivePhysicalSize . y ,
( ACTIVE_AREA_POS . x + ACTIVE_AREA_SIZE . x ) / effectivePhysicalSize . x , ( ACTIVE_AREA_POS . y + ACTIVE_AREA_SIZE . y ) / effectivePhysicalSize . y } ;
2024-03-23 23:31:03 +03:00
}
2022-12-21 15:11:39 +00:00
}
}
}
2024-07-21 13:09:54 +02:00
void CInputManager : : newSwitch ( SP < Aquamarine : : ISwitch > pDevice ) {
2025-05-01 23:57:11 +02:00
const auto PNEWDEV = & m_switches . emplace_back ( ) ;
2024-07-21 13:09:54 +02:00
PNEWDEV - > pDevice = pDevice ;
2022-10-04 20:07:21 +01:00
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " New switch with name \" {} \" added " , pDevice - > getName ( ) ) ;
2022-10-04 20:07:21 +01:00
2025-07-08 09:56:40 -07:00
PNEWDEV - > listeners . destroy = pDevice - > events . destroy . listen ( [ this , PNEWDEV ] { destroySwitch ( PNEWDEV ) ; } ) ;
2022-10-04 20:07:21 +01:00
2025-07-08 09:56:40 -07:00
PNEWDEV - > listeners . fire = pDevice - > events . fire . listen ( [ PNEWDEV ] ( const Aquamarine : : ISwitch : : SFireEvent & event ) {
2024-07-21 13:09:54 +02:00
const auto NAME = PNEWDEV - > pDevice - > getName ( ) ;
2023-03-16 16:30:22 +00:00
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " Switch {} fired, triggering binds. " , NAME ) ;
2022-10-04 20:07:21 +01:00
2024-07-21 13:09:54 +02:00
g_pKeybindManager - > onSwitchEvent ( NAME ) ;
2023-01-08 23:35:24 +08:00
2025-07-08 09:56:40 -07:00
if ( event . enable ) {
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " Switch {} turn on, triggering binds. " , NAME ) ;
g_pKeybindManager - > onSwitchOnEvent ( NAME ) ;
} else {
Debug : : log ( LOG , " Switch {} turn off, triggering binds. " , NAME ) ;
g_pKeybindManager - > onSwitchOffEvent ( NAME ) ;
}
} ) ;
2022-10-04 20:07:21 +01:00
}
void CInputManager : : destroySwitch ( SSwitchDevice * pDevice ) {
2025-05-01 23:57:11 +02:00
m_switches . remove ( * pDevice ) ;
2022-10-05 04:25:26 +02:00
}
2022-11-15 10:39:05 +00:00
void CInputManager : : setCursorImageUntilUnset ( std : : string name ) {
2023-12-11 17:28:22 +01:00
g_pHyprRenderer - > setCursorFromName ( name ) ;
2025-05-01 23:57:11 +02:00
m_cursorImageOverridden = true ;
m_cursorSurfaceInfo . inUse = false ;
2022-11-15 10:39:05 +00:00
}
void CInputManager : : unsetCursorImage ( ) {
2025-05-01 23:57:11 +02:00
if ( ! m_cursorImageOverridden )
2022-11-15 10:39:05 +00:00
return ;
2025-05-01 23:57:11 +02:00
m_cursorImageOverridden = false ;
2023-10-29 18:09:05 +00:00
restoreCursorIconToApp ( ) ;
2022-11-15 10:39:05 +00:00
}
2022-12-03 15:56:07 +00:00
2022-12-03 20:36:52 +00:00
std : : string CInputManager : : getNameForNewDevice ( std : : string internalName ) {
auto proposedNewName = deviceNameToInternalString ( internalName ) ;
2022-12-16 17:17:31 +00:00
int dupeno = 0 ;
2022-12-03 20:36:52 +00:00
2024-11-09 01:53:01 +00:00
auto makeNewName = [ & ] ( ) { return ( proposedNewName . empty ( ) ? " unknown-device " : proposedNewName ) + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ;
2022-12-03 20:36:52 +00:00
2025-05-30 18:25:59 +05:00
while ( std : : ranges : : find_if ( m_hids , [ & ] ( const auto & other ) { return other - > m_hlName = = makeNewName ( ) ; } ) ! = m_hids . end ( ) )
2022-12-03 20:36:52 +00:00
dupeno + + ;
2024-11-09 01:53:01 +00:00
return makeNewName ( ) ;
2022-12-03 20:36:52 +00:00
}
2022-12-10 14:43:46 +00:00
2023-01-11 18:38:54 +01:00
void CInputManager : : releaseAllMouseButtons ( ) {
2025-05-01 23:57:11 +02:00
const auto buttonsCopy = m_currentlyHeldButtons ;
2023-01-11 18:38:54 +01:00
2024-05-11 17:13:20 +01:00
if ( PROTO : : data - > dndActive ( ) )
2023-01-11 18:38:54 +01:00
return ;
2024-08-26 17:25:39 +02:00
for ( auto const & mb : buttonsCopy ) {
2025-04-16 01:37:48 +01:00
g_pSeatManager - > sendPointerButton ( Time : : millis ( Time : : steadyNow ( ) ) , mb , WL_POINTER_BUTTON_STATE_RELEASED ) ;
2023-01-11 18:38:54 +01:00
}
2025-05-01 23:57:11 +02:00
m_currentlyHeldButtons . clear ( ) ;
2023-01-11 18:38:54 +01:00
}
2023-02-18 23:35:31 +01:00
2024-04-27 12:43:12 +01:00
void CInputManager : : setCursorIconOnBorder ( PHLWINDOW w ) {
2023-02-18 23:35:31 +01:00
// do not override cursor icons set by mouse binds
2025-05-01 23:57:11 +02:00
if ( g_pInputManager - > m_currentlyDraggedWindow . expired ( ) ) {
m_borderIconDirection = BORDERICON_NONE ;
2023-02-18 23:35:31 +01:00
return ;
}
2024-05-25 22:43:51 +02:00
// ignore X11 OR windows, they shouldn't be touched
2025-04-28 22:25:22 +02:00
if ( w - > m_isX11 & & w - > isX11OverrideRedirect ( ) )
2024-05-25 22:43:51 +02:00
return ;
2024-03-03 18:39:20 +00:00
static auto PEXTENDBORDERGRAB = CConfigValue < Hyprlang : : INT > ( " general:extend_border_grab_area " ) ;
const int BORDERSIZE = w - > getRealBorderSize ( ) ;
const int ROUNDING = w - > rounding ( ) ;
2023-08-17 08:13:19 +00:00
2023-02-18 23:35:31 +01:00
// give a small leeway (10 px) for corner icon
2024-02-18 15:00:34 +00:00
const auto CORNER = ROUNDING + BORDERSIZE + 10 ;
2023-04-03 23:15:33 +01:00
const auto mouseCoords = getMouseCoordsInternal ( ) ;
2023-11-04 17:03:05 +00:00
CBox box = w - > getWindowMainSurfaceBox ( ) ;
2023-04-03 23:15:33 +01:00
eBorderIconDirection direction = BORDERICON_NONE ;
2024-03-03 18:39:20 +00:00
CBox boxFullGrabInput = { box . x - * PEXTENDBORDERGRAB - BORDERSIZE , box . y - * PEXTENDBORDERGRAB - BORDERSIZE , box . width + 2 * ( * PEXTENDBORDERGRAB + BORDERSIZE ) ,
box . height + 2 * ( * PEXTENDBORDERGRAB + BORDERSIZE ) } ;
2023-04-03 23:15:33 +01:00
2023-10-29 23:37:12 +00:00
if ( w - > hasPopupAt ( mouseCoords ) )
2023-04-03 23:15:33 +01:00
direction = BORDERICON_NONE ;
2025-05-01 23:57:11 +02:00
else if ( ! boxFullGrabInput . containsPoint ( mouseCoords ) | | ( ! m_currentlyHeldButtons . empty ( ) & & m_currentlyDraggedWindow . expired ( ) ) )
2023-10-29 23:37:12 +00:00
direction = BORDERICON_NONE ;
else {
bool onDeco = false ;
2025-04-28 22:25:22 +02:00
for ( auto const & wd : w - > m_windowDecorations ) {
2023-11-04 13:10:52 +00:00
if ( ! ( wd - > getDecorationFlags ( ) & DECORATION_ALLOWS_MOUSE_INPUT ) )
2023-10-29 23:37:12 +00:00
continue ;
2023-11-11 14:37:17 +00:00
if ( g_pDecorationPositioner - > getWindowDecorationBox ( wd . get ( ) ) . containsPoint ( mouseCoords ) ) {
2023-10-29 23:37:12 +00:00
onDeco = true ;
break ;
}
}
if ( onDeco )
2023-02-18 23:35:31 +01:00
direction = BORDERICON_NONE ;
2023-10-29 23:37:12 +00:00
else {
2023-11-04 17:03:05 +00:00
if ( box . containsPoint ( mouseCoords ) ) {
2023-10-29 23:37:12 +00:00
if ( ! w - > isInCurvedCorner ( mouseCoords . x , mouseCoords . y ) ) {
direction = BORDERICON_NONE ;
} else {
if ( mouseCoords . y < box . y + CORNER ) {
if ( mouseCoords . x < box . x + CORNER )
direction = BORDERICON_UP_LEFT ;
else
direction = BORDERICON_UP_RIGHT ;
} else {
if ( mouseCoords . x < box . x + CORNER )
direction = BORDERICON_DOWN_LEFT ;
else
direction = BORDERICON_DOWN_RIGHT ;
}
}
2023-02-18 23:35:31 +01:00
} else {
2023-10-29 23:37:12 +00:00
if ( mouseCoords . y < box . y + CORNER ) {
if ( mouseCoords . x < box . x + CORNER )
direction = BORDERICON_UP_LEFT ;
else if ( mouseCoords . x > box . x + box . width - CORNER )
direction = BORDERICON_UP_RIGHT ;
else
direction = BORDERICON_UP ;
} else if ( mouseCoords . y > box . y + box . height - CORNER ) {
if ( mouseCoords . x < box . x + CORNER )
direction = BORDERICON_DOWN_LEFT ;
else if ( mouseCoords . x > box . x + box . width - CORNER )
direction = BORDERICON_DOWN_RIGHT ;
else
direction = BORDERICON_DOWN ;
} else {
if ( mouseCoords . x < box . x + CORNER )
direction = BORDERICON_LEFT ;
else if ( mouseCoords . x > box . x + box . width - CORNER )
direction = BORDERICON_RIGHT ;
}
2023-02-18 23:35:31 +01:00
}
}
}
2025-05-01 23:57:11 +02:00
if ( direction = = m_borderIconDirection )
2023-02-18 23:35:31 +01:00
return ;
2025-05-01 23:57:11 +02:00
m_borderIconDirection = direction ;
2023-02-18 23:35:31 +01:00
switch ( direction ) {
case BORDERICON_NONE : unsetCursorImage ( ) ; break ;
case BORDERICON_UP : setCursorImageUntilUnset ( " top_side " ) ; break ;
case BORDERICON_DOWN : setCursorImageUntilUnset ( " bottom_side " ) ; break ;
case BORDERICON_LEFT : setCursorImageUntilUnset ( " left_side " ) ; break ;
case BORDERICON_RIGHT : setCursorImageUntilUnset ( " right_side " ) ; break ;
case BORDERICON_UP_LEFT : setCursorImageUntilUnset ( " top_left_corner " ) ; break ;
case BORDERICON_DOWN_LEFT : setCursorImageUntilUnset ( " bottom_left_corner " ) ; break ;
case BORDERICON_UP_RIGHT : setCursorImageUntilUnset ( " top_right_corner " ) ; break ;
case BORDERICON_DOWN_RIGHT : setCursorImageUntilUnset ( " bottom_right_corner " ) ; break ;
}
}
2024-12-15 23:54:05 +00:00
void CInputManager : : recheckMouseWarpOnMouseInput ( ) {
static auto PWARPFORNONMOUSE = CConfigValue < Hyprlang : : INT > ( " cursor:warp_back_after_non_mouse_input " ) ;
2025-05-01 23:57:11 +02:00
if ( ! m_lastInputMouse & & * PWARPFORNONMOUSE )
g_pPointerManager - > warpTo ( m_lastMousePos ) ;
2024-12-15 23:54:05 +00:00
}
2025-08-28 11:20:29 +02:00
void CInputManager : : onSwipeBegin ( IPointer : : SSwipeBeginEvent e ) {
EMIT_HOOK_EVENT_CANCELLABLE ( " swipeBegin " , e ) ;
g_pTrackpadGestures - > gestureBegin ( e ) ;
PROTO : : pointerGestures - > swipeBegin ( e . timeMs , e . fingers ) ;
}
void CInputManager : : onSwipeUpdate ( IPointer : : SSwipeUpdateEvent e ) {
EMIT_HOOK_EVENT_CANCELLABLE ( " swipeUpdate " , e ) ;
g_pTrackpadGestures - > gestureUpdate ( e ) ;
PROTO : : pointerGestures - > swipeUpdate ( e . timeMs , e . delta ) ;
}
void CInputManager : : onSwipeEnd ( IPointer : : SSwipeEndEvent e ) {
EMIT_HOOK_EVENT_CANCELLABLE ( " swipeEnd " , e ) ;
g_pTrackpadGestures - > gestureEnd ( e ) ;
PROTO : : pointerGestures - > swipeEnd ( e . timeMs , e . cancelled ) ;
}
void CInputManager : : onPinchBegin ( IPointer : : SPinchBeginEvent e ) {
EMIT_HOOK_EVENT_CANCELLABLE ( " pinchBegin " , e ) ;
g_pTrackpadGestures - > gestureBegin ( e ) ;
PROTO : : pointerGestures - > pinchBegin ( e . timeMs , e . fingers ) ;
}
void CInputManager : : onPinchUpdate ( IPointer : : SPinchUpdateEvent e ) {
EMIT_HOOK_EVENT_CANCELLABLE ( " pinchUpdate " , e ) ;
g_pTrackpadGestures - > gestureUpdate ( e ) ;
PROTO : : pointerGestures - > pinchUpdate ( e . timeMs , e . delta , e . scale , e . rotation ) ;
}
void CInputManager : : onPinchEnd ( IPointer : : SPinchEndEvent e ) {
EMIT_HOOK_EVENT_CANCELLABLE ( " pinchEnd " , e ) ;
g_pTrackpadGestures - > gestureEnd ( e ) ;
PROTO : : pointerGestures - > pinchEnd ( e . timeMs , e . cancelled ) ;
}