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>
2023-03-01 14:06:52 +00:00
# include <ranges>
2024-03-03 18:39:20 +00:00
# include "../../config/ConfigValue.hpp"
2024-03-20 01:44:51 +00:00
# include "../../desktop/Window.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"
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-05-05 22:18:10 +01:00
2024-07-21 13:09:54 +02:00
# include <aquamarine/input/Input.hpp>
2024-04-21 01:47:38 +01:00
CInputManager : : CInputManager ( ) {
m_sListeners . setCursorShape = PROTO : : cursorShape - > events . setShape . registerListener ( [ this ] ( std : : any data ) {
if ( ! cursorImageUnlocked ( ) )
return ;
auto event = std : : any_cast < CCursorShapeProtocol : : SSetShapeEvent > ( data ) ;
2024-05-10 18:27:57 +01:00
if ( ! g_pSeatManager - > state . pointerFocusResource )
2024-04-21 15:17:05 +01:00
return ;
2024-05-10 18:27:57 +01:00
if ( wl_resource_get_client ( event . pMgr - > resource ( ) ) ! = g_pSeatManager - > state . pointerFocusResource - > client ( ) )
2024-04-21 01:47:38 +01:00
return ;
Debug : : log ( LOG , " cursorImage request: shape {} -> {} " , ( uint32_t ) event . shape , event . shapeName ) ;
2024-06-08 10:07:59 +02:00
m_sCursorSurfaceInfo . wlSurface - > unassign ( ) ;
2024-04-21 01:47:38 +01:00
m_sCursorSurfaceInfo . vHotspot = { } ;
m_sCursorSurfaceInfo . name = event . shapeName ;
m_sCursorSurfaceInfo . hidden = false ;
m_sCursorSurfaceInfo . inUse = true ;
g_pHyprRenderer - > setCursorFromName ( m_sCursorSurfaceInfo . name ) ;
} ) ;
2024-04-21 16:29:30 +01:00
2024-06-08 23:15:57 +08:00
m_sListeners . newIdleInhibitor = PROTO : : idleInhibit - > events . newIdleInhibitor . registerListener ( [ this ] ( std : : any data ) { this - > newIdleInhibitor ( data ) ; } ) ;
m_sListeners . newVirtualKeyboard = PROTO : : virtualKeyboard - > events . newKeyboard . registerListener ( [ this ] ( std : : any data ) {
this - > newVirtualKeyboard ( std : : any_cast < SP < CVirtualKeyboardV1Resource > > ( data ) ) ;
updateCapabilities ( ) ;
} ) ;
m_sListeners . newVirtualMouse = PROTO : : virtualPointer - > events . newPointer . registerListener ( [ this ] ( std : : any data ) {
this - > newVirtualMouse ( std : : any_cast < SP < CVirtualPointerV1Resource > > ( data ) ) ;
updateCapabilities ( ) ;
} ) ;
m_sListeners . setCursor = g_pSeatManager - > events . setCursor . registerListener ( [ this ] ( std : : any d ) { this - > processMouseRequest ( d ) ; } ) ;
2024-06-08 10:07:59 +02:00
m_sCursorSurfaceInfo . 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 ( ) {
2024-03-02 21:04:55 +00:00
m_vConstraints . clear ( ) ;
2024-05-03 22:34:10 +01:00
m_vKeyboards . clear ( ) ;
m_vPointers . clear ( ) ;
m_vTouches . clear ( ) ;
2024-05-06 02:15:26 +01:00
m_vTablets . clear ( ) ;
m_vTabletTools . clear ( ) ;
m_vTabletPads . clear ( ) ;
2024-04-21 16:29:30 +01:00
m_vIdleInhibitors . clear ( ) ;
2023-11-12 14:03:46 +00:00
m_lSwitches . clear ( ) ;
}
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
2024-05-05 22:18:10 +01:00
const auto DELTA = * PNOACCEL = = 1 ? e . unaccel : e . delta ;
2022-06-06 12:08:33 +02:00
2024-08-17 17:33:16 +01:00
PROTO : : relativePointer - > sendRelativeMotion ( ( uint64_t ) e . timeMs * 1000 , DELTA , e . unaccel ) ;
2022-04-17 21:40:04 +02:00
2024-08-17 17:33:16 +01:00
g_pPointerManager - > move ( DELTA ) ;
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
m_tmrLastCursorMovement . reset ( ) ;
2023-01-17 11:47:39 +01:00
m_bLastInputTouch = false ;
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
m_tmrLastCursorMovement . reset ( ) ;
2023-01-17 11:47:39 +01:00
m_bLastInputTouch = false ;
2022-03-18 23:52:36 +01:00
}
2023-01-31 00:26:15 +00:00
void CInputManager : : simulateMouseMovement ( ) {
timespec now ;
clock_gettime ( CLOCK_MONOTONIC , & now ) ;
m_vLastCursorPosFloored = m_vLastCursorPosFloored - Vector2D ( 1 , 1 ) ; // hack: force the mouseMoveUnified to report without making this a refocus.
mouseMoveUnified ( now . tv_sec * 1000 + now . tv_nsec / 10000000 ) ;
}
2023-09-13 11:33:36 +01:00
void CInputManager : : sendMotionEventsToFocused ( ) {
2024-03-02 21:04:55 +00:00
if ( ! g_pCompositor - > m_pLastFocus | | isConstrained ( ) )
2023-09-13 11:33:36 +01:00
return ;
// todo: this sucks ass
2024-06-08 10:07:59 +02:00
const auto PWINDOW = g_pCompositor - > getWindowFromSurface ( g_pCompositor - > m_pLastFocus . lock ( ) ) ;
const auto PLS = g_pCompositor - > getLayerSurfaceFromSurface ( g_pCompositor - > m_pLastFocus . lock ( ) ) ;
2023-09-13 11:33:36 +01:00
timespec now ;
clock_gettime ( CLOCK_MONOTONIC , & now ) ;
2024-03-02 01:35:17 +01:00
const auto LOCAL = getMouseCoordsInternal ( ) - ( PWINDOW ? PWINDOW - > m_vRealPosition . goal ( ) : ( PLS ? Vector2D { PLS - > geometry . x , PLS - > geometry . y } : Vector2D { } ) ) ;
2023-09-13 11:33:36 +01:00
2024-03-09 18:12:55 +00:00
m_bEmptyFocusCursorSet = false ;
2024-06-08 10:07:59 +02:00
g_pSeatManager - > setPointerFocus ( g_pCompositor - > m_pLastFocus . lock ( ) , LOCAL ) ;
2023-09-13 11:33:36 +01:00
}
2022-04-13 20:19:40 +02:00
void CInputManager : : mouseMoveUnified ( uint32_t time , bool refocus ) {
2024-03-03 18:39:20 +00:00
static auto PFOLLOWMOUSE = CConfigValue < Hyprlang : : INT > ( " input:follow_mouse " ) ;
static auto PMOUSEREFOCUS = CConfigValue < Hyprlang : : INT > ( " input:mouse_refocus " ) ;
static auto PMOUSEDPMS = CConfigValue < Hyprlang : : INT > ( " misc:mouse_move_enables_dpms " ) ;
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-05-09 22:23:01 +01:00
static auto PZOOMFACTOR = CConfigValue < Hyprlang : : FLOAT > ( " cursor:zoom_factor " ) ;
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
2024-06-08 10:07:59 +02:00
m_pFoundSurfaceToFocus . reset ( ) ;
2024-04-30 02:41:27 +01:00
m_pFoundLSToFocus . reset ( ) ;
2024-04-27 12:43:12 +01:00
m_pFoundWindowToFocus . reset ( ) ;
2024-06-08 10:07:59 +02:00
SP < CWLSurfaceResource > foundSurface ;
Vector2D surfaceCoords ;
Vector2D surfacePos = Vector2D ( - 1337 , - 1337 ) ;
PHLWINDOW pFoundWindow ;
PHLLS pFoundLayerSurface ;
2024-06-11 08:11:15 -07:00
SSessionLockSurface * pSessionLock = nullptr ;
2022-10-14 20:46:32 +01:00
2023-09-10 23:44:45 +01:00
if ( ! g_pCompositor - > m_bReadyToProcess | | g_pCompositor - > m_bIsShuttingDown | | g_pCompositor - > m_bUnsafeState )
2022-04-28 17:57:24 +02:00
return ;
2024-03-03 18:39:20 +00:00
if ( ! g_pCompositor - > m_bDPMSStateON & & * PMOUSEDPMS ) {
2022-07-31 15:46:42 +02:00
// enable dpms
g_pKeybindManager - > dpms ( " on " ) ;
}
2022-12-16 17:17:31 +00:00
Vector2D mouseCoords = getMouseCoordsInternal ( ) ;
2022-07-01 17:59:11 +02:00
const auto MOUSECOORDSFLOORED = mouseCoords . floor ( ) ;
2022-07-03 15:51:32 +03:00
if ( MOUSECOORDSFLOORED = = m_vLastCursorPosFloored & & ! refocus )
2022-07-01 17:59:11 +02:00
return ;
2023-10-21 14:52:43 +01:00
EMIT_HOOK_EVENT_CANCELLABLE ( " mouseMove " , MOUSECOORDSFLOORED ) ;
2023-08-13 17:46:16 +02:00
if ( time )
2024-04-29 17:42:07 +01:00
PROTO : : idle - > onActivity ( ) ;
2023-08-13 17:46:16 +02:00
2022-07-01 17:59:11 +02:00
m_vLastCursorPosFloored = MOUSECOORDSFLOORED ;
2022-05-18 14:57:08 +02:00
const auto PMONITOR = g_pCompositor - > getMonitorFromCursor ( ) ;
2023-05-22 05:18:07 -05:00
// this can happen if there are no displays hooked up to Hyprland
if ( PMONITOR = = nullptr )
return ;
2024-03-03 18:39:20 +00:00
if ( * PZOOMFACTOR ! = 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 ( ) ;
2024-07-21 13:09:54 +02:00
if ( ! PMONITOR - > solitaryClient . lock ( ) & & g_pHyprRenderer - > shouldRenderCursor ( ) & & g_pPointerManager - > softwareLockedFor ( PMONITOR - > self . lock ( ) ) & & ! skipFrameSchedule )
g_pCompositor - > scheduleFrameForMonitor ( PMONITOR , Aquamarine : : IOutput : : AQ_SCHEDULE_CURSOR_MOVE ) ;
2023-07-09 00:44:26 +02:00
2024-04-27 12:43:12 +01:00
PHLWINDOW forcedFocus = m_pForcedFocus . lock ( ) ;
2023-07-04 12:05:25 +02:00
if ( ! forcedFocus )
forcedFocus = g_pCompositor - > getForceFocus ( ) ;
if ( forcedFocus ) {
pFoundWindow = forcedFocus ;
2024-03-02 01:35:17 +01:00
surfacePos = pFoundWindow - > m_vRealPosition . value ( ) ;
2024-06-08 10:07:59 +02:00
foundSurface = pFoundWindow - > m_pWLSurface - > resource ( ) ;
2023-05-31 20:59:38 +02:00
}
2023-04-25 21:50:24 +01:00
// constraints
2024-05-10 18:27:57 +01:00
if ( ! g_pSeatManager - > mouse . expired ( ) & & isConstrained ( ) ) {
2024-06-08 10:07:59 +02:00
const auto SURF = CWLSurface : : fromResource ( g_pCompositor - > m_pLastFocus . lock ( ) ) ;
2024-03-02 21:04:55 +00:00
const auto CONSTRAINT = SURF - > constraint ( ) ;
if ( SURF & & CONSTRAINT ) {
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 ( ) ;
2024-03-08 22:51:28 +00:00
const auto CLOSESTLOCAL = ( CLOSEST - ( BOX . has_value ( ) ? BOX - > pos ( ) : Vector2D { } ) ) * ( SURF - > getWindow ( ) ? SURF - > getWindow ( ) - > m_fX11SurfaceScaledBy : 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 ) ;
2024-04-21 19:30:23 +01:00
PROTO : : relativePointer - > sendRelativeMotion ( ( uint64_t ) time * 1000 , { } , { } ) ;
2023-04-25 21:50:24 +01:00
}
2024-03-02 21:04:55 +00:00
return ;
} else
2024-07-22 11:06:11 -05:00
Debug : : log ( ERR , " BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x} " , ( uintptr_t ) SURF . get ( ) , ( uintptr_t ) CONSTRAINT . get ( ) ) ;
2023-04-25 21:50:24 +01: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.
if ( ! PROTO : : data - > dndActive ( ) & & ! m_lCurrentlyHeldButtons . empty ( ) & & g_pCompositor - > m_pLastFocus & & g_pSeatManager - > state . pointerFocus & & ! m_bHardInput ) {
2024-06-08 10:07:59 +02:00
foundSurface = g_pSeatManager - > state . pointerFocus . lock ( ) ;
2024-05-18 21:20:01 +01:00
// IME popups aren't desktop-like elements
// TODO: make them.
CInputPopup * foundPopup = m_sIMERelay . popupFromSurface ( foundSurface ) ;
if ( foundPopup ) {
surfacePos = foundPopup - > globalBox ( ) . pos ( ) ;
2024-04-07 22:15:50 +08:00
m_bFocusHeldByButtons = true ;
m_bRefocusHeldByButtons = refocus ;
} 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 ) {
surfacePos = BOX - > pos ( ) ;
pFoundLayerSurface = HLSurface - > getLayer ( ) ;
pFoundWindow = HLSurface - > getWindow ( ) ;
} 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
2024-05-05 22:18:10 +01:00
if ( PMONITOR & & PMONITOR ! = g_pCompositor - > m_pLastMonitor . get ( ) & & ( * PMOUSEFOCUSMON | | refocus ) & & m_pForcedFocus . expired ( ) )
2022-11-19 16:41:36 +00:00
g_pCompositor - > setActiveMonitor ( PMONITOR ) ;
2022-03-31 17:25:23 +02:00
2023-02-03 11:58:55 +00:00
if ( g_pSessionLockManager - > isSessionLocked ( ) ) {
2024-06-11 08:11:15 -07:00
pSessionLock = PMONITOR ? g_pSessionLockManager - > getSessionLockSurfaceForMonitor ( PMONITOR - > ID ) : nullptr ;
2023-02-03 11:58:55 +00:00
2024-06-11 08:11:15 -07:00
if ( ! pSessionLock )
2023-02-03 11:58:55 +00:00
return ;
2024-06-11 08:11:15 -07:00
foundSurface = pSessionLock - > surface - > surface ( ) ;
2023-02-03 11:58:55 +00:00
surfacePos = PMONITOR - > vecPosition ;
}
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 )
2023-01-22 17:03:25 +01:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLayers [ 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 ) {
2024-03-24 16:08:25 +00:00
auto popup = g_pInputManager - > m_sIMERelay . 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 )
2023-01-22 17:03:25 +01:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_TOP ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-09-19 10:23:13 +01:00
2022-04-25 21:49:45 +02:00
// then, we check if the workspace doesnt have a fullscreen window
2024-04-02 20:32:39 +01:00
const auto PWORKSPACE = PMONITOR - > activeWorkspace ;
2024-07-31 17:55:52 +00:00
if ( PWORKSPACE - > m_bHasFullscreenWindow & & ! foundSurface & & PWORKSPACE - > m_efFullscreenMode = = FSMODE_FULLSCREEN ) {
2022-04-11 19:51:37 +02:00
pFoundWindow = g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) ;
2022-09-05 00:59:13 +02:00
if ( ! pFoundWindow ) {
// what the fuck, somehow happens occasionally??
PWORKSPACE - > m_bHasFullscreenWindow = false ;
return ;
}
2024-02-04 15:40:20 +00:00
const auto PWINDOWIDEAL = g_pCompositor - > vectorToWindowUnified ( mouseCoords , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2023-09-21 23:58:54 +01:00
if ( PWINDOWIDEAL & &
( ( PWINDOWIDEAL - > m_bIsFloating & & PWINDOWIDEAL - > m_bCreatedOverFullscreen ) /* floating over fullscreen */
2024-04-02 20:32:39 +01:00
| | ( PMONITOR - > activeSpecialWorkspace = = PWINDOWIDEAL - > m_pWorkspace ) /* on an open special workspace */ ) )
2023-09-21 23:58:54 +01:00
pFoundWindow = PWINDOWIDEAL ;
2022-10-30 12:28:37 +00:00
if ( ! pFoundWindow - > m_bIsX11 ) {
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 {
2024-06-08 10:07:59 +02:00
foundSurface = pFoundWindow - > m_pWLSurface - > resource ( ) ;
2024-03-02 01:35:17 +01:00
surfacePos = pFoundWindow - > m_vRealPosition . 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 ) {
2024-07-31 17:55:52 +00:00
if ( PWORKSPACE - > m_bHasFullscreenWindow & & PWORKSPACE - > m_efFullscreenMode = = FSMODE_MAXIMIZED ) {
2024-04-03 21:57:12 +01:00
if ( ! foundSurface ) {
if ( PMONITOR - > activeSpecialWorkspace ) {
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 ( ) ) {
pFoundWindow = g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) ;
}
} 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 ) ) {
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM ] , & surfaceCoords ,
& pFoundLayerSurface ) ;
}
2024-04-06 18:59:23 +01:00
if ( ! foundSurface ) {
pFoundWindow = g_pCompositor - > vectorToWindowUnified ( mouseCoords , RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING ) ;
2024-04-03 21:57:12 +01:00
2024-04-06 18:59:23 +01:00
if ( ! ( pFoundWindow & & pFoundWindow - > m_bIsFloating & & pFoundWindow - > m_bCreatedOverFullscreen ) )
pFoundWindow = g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) ;
}
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-02-04 15:40:20 +00:00
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 ) {
if ( ! pFoundWindow - > m_bIsX11 ) {
foundSurface = g_pCompositor - > vectorWindowToSurface ( mouseCoords , pFoundWindow , surfaceCoords ) ;
2024-06-12 18:39:52 +02:00
if ( ! foundSurface ) {
foundSurface = pFoundWindow - > m_pWLSurface - > resource ( ) ;
surfacePos = pFoundWindow - > m_vRealPosition . value ( ) ;
}
2022-04-24 11:41:52 +02:00
} else {
2024-06-08 10:07:59 +02:00
foundSurface = pFoundWindow - > m_pWLSurface - > resource ( ) ;
2024-03-02 01:35:17 +01:00
surfacePos = pFoundWindow - > m_vRealPosition . 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 )
2023-01-22 17:03:25 +01:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-03-20 14:36:55 +01:00
if ( ! foundSurface )
2023-01-22 17:03:25 +01:00
foundSurface =
g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-03-20 14:36:55 +01:00
2024-07-21 13:09:54 +02:00
if ( g_pPointerManager - > softwareLockedFor ( PMONITOR - > self . lock ( ) ) > 0 & & ! skipFrameSchedule )
g_pCompositor - > scheduleFrameForMonitor ( g_pCompositor - > m_pLastMonitor . get ( ) , Aquamarine : : IOutput : : AQ_SCHEDULE_CURSOR_MOVE ) ;
2022-08-28 22:45:05 +02:00
2024-05-11 01:02:57 +01:00
// grabs
if ( g_pSeatManager - > seatGrab & & ! g_pSeatManager - > seatGrab - > accepts ( foundSurface ) ) {
if ( m_bHardInput | | refocus ) {
g_pSeatManager - > setGrab ( nullptr ) ;
return ; // setGrab will refocus
} else {
// we need to grab the last surface.
2024-06-08 10:07:59 +02:00
foundSurface = g_pSeatManager - > 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 ) {
2022-08-28 22:45:05 +02:00
if ( ! m_bEmptyFocusCursorSet ) {
2024-03-03 18:39:20 +00:00
if ( * PRESIZEONBORDER & & * PRESIZECURSORICON & & m_eBorderIconDirection ! = BORDERICON_NONE ) {
2023-12-12 14:55:48 +00:00
m_eBorderIconDirection = BORDERICON_NONE ;
unsetCursorImage ( ) ;
}
2023-12-18 16:06:06 +00:00
// TODO: maybe wrap?
if ( m_ecbClickBehavior = = CLICKMODE_KILL )
setCursorImageOverride ( " crosshair " ) ;
else
setCursorImageOverride ( " left_ptr " ) ;
2022-12-16 17:17:31 +00:00
2022-08-28 22:45:05 +02:00
m_bEmptyFocusCursorSet = true ;
}
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
2024-04-27 12:43:12 +01:00
if ( refocus | | g_pCompositor - > m_pLastWindow . 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 ;
}
2022-08-28 22:45:05 +02:00
m_bEmptyFocusCursorSet = false ;
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
2022-06-22 15:45:56 +02:00
if ( pFoundWindow & & ! pFoundWindow - > m_bIsX11 & & surfacePos ! = Vector2D ( - 1337 , - 1337 ) ) {
// calc for oversized windows... fucking bullshit.
2024-05-10 23:28:33 +01:00
CBox geom = pFoundWindow - > m_pXDGSurface - > 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
}
2023-06-11 21:52:13 +02:00
if ( pFoundWindow & & pFoundWindow - > m_bIsX11 ) // for x11 force scale zero
surfaceLocal = surfaceLocal * pFoundWindow - > m_fX11SurfaceScaledBy ;
2022-08-10 17:46:01 +02:00
bool allowKeyboardRefocus = true ;
2024-01-17 14:43:38 +01:00
if ( ! refocus & & g_pCompositor - > m_pLastFocus ) {
2024-06-08 10:07:59 +02:00
const auto PLS = g_pCompositor - > getLayerSurfaceFromSurface ( g_pCompositor - > m_pLastFocus . lock ( ) ) ;
2022-08-10 17:46:01 +02:00
2024-05-09 21:47:21 +01:00
if ( PLS & & PLS - > layerSurface - > 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 ) {
2022-12-16 17:17:31 +00:00
m_pFoundLSToFocus = pFoundLayerSurface ;
m_pFoundWindowToFocus = pFoundWindow ;
2022-10-14 20:46:32 +01:00
m_pFoundSurfaceToFocus = foundSurface ;
}
2024-05-05 17:16:00 +01:00
if ( currentlyDraggedWindow . lock ( ) & & pFoundWindow ! = currentlyDraggedWindow ) {
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
2023-05-01 15:15:55 +01:00
return ;
}
2024-06-08 10:07:59 +02:00
if ( pFoundWindow & & foundSurface = = pFoundWindow - > m_pWLSurface - > resource ( ) & & ! m_bCursorImageOverridden ) {
2023-10-29 18:09:05 +00:00
const auto BOX = pFoundWindow - > getWindowMainSurfaceBox ( ) ;
if ( ! VECINRECT ( mouseCoords , BOX . x , BOX . y , BOX . x + BOX . width , BOX . y + BOX . height ) )
setCursorImageOverride ( " left_ptr " ) ;
else
restoreCursorIconToApp ( ) ;
}
2024-06-11 08:11:15 -07:00
if ( pSessionLock ! = nullptr )
g_pCompositor - > focusSurface ( foundSurface ) ;
else 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 ) ;
} else if ( m_eBorderIconDirection ! = BORDERICON_NONE ) {
unsetCursorImage ( ) ;
}
2023-02-18 23:35:31 +01:00
}
2023-03-30 00:34:24 +01:00
if ( FOLLOWMOUSE ! = 1 & & ! refocus ) {
2024-04-27 12:43:12 +01:00
if ( pFoundWindow ! = g_pCompositor - > m_pLastWindow . lock ( ) & & g_pCompositor - > m_pLastWindow . lock ( ) & &
2024-05-05 17:16:00 +01:00
( ( pFoundWindow - > m_bIsFloating & & * PFLOATBEHAVIOR = = 2 ) | | ( g_pCompositor - > m_pLastWindow - > m_bIsFloating ! = pFoundWindow - > m_bIsFloating & & * 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
2024-05-10 18:27:57 +01:00
if ( pFoundWindow = = g_pCompositor - > m_pLastWindow )
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
2022-07-19 14:05:12 +02:00
2024-05-05 17:16:00 +01:00
if ( FOLLOWMOUSE ! = 0 | | pFoundWindow = = g_pCompositor - > m_pLastWindow )
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setPointerFocus ( foundSurface , surfaceLocal ) ;
2022-09-25 20:07:48 +02:00
2024-05-15 16:22:45 +01:00
if ( g_pSeatManager - > state . pointerFocus = = foundSurface )
g_pSeatManager - > sendPointerMotion ( time , surfaceLocal ) ;
2022-09-04 18:42:11 +02:00
m_bLastFocusOnLS = 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 {
2024-04-27 12:43:12 +01:00
if ( allowKeyboardRefocus & & ( ( FOLLOWMOUSE ! = 3 & & ( * PMOUSEREFOCUS | | m_pLastMouseFocus . lock ( ) ! = pFoundWindow ) ) | | refocus ) ) {
if ( m_pLastMouseFocus . lock ( ) ! = pFoundWindow | | g_pCompositor - > m_pLastWindow . lock ( ) ! = pFoundWindow | | g_pCompositor - > m_pLastFocus ! = foundSurface | | refocus ) {
2024-02-15 01:24:40 +00:00
m_pLastMouseFocus = pFoundWindow ;
// 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.
2024-04-27 12:43:12 +01:00
if ( m_pLastMouseFocus . lock ( ) ! = pFoundWindow | | g_pCompositor - > m_pLastWindow . lock ( ) ! = pFoundWindow )
2024-02-15 01:24:40 +00:00
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
else
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
m_bLastFocusOnLS = false ;
2022-08-10 17:46:01 +02:00
} else {
2024-03-03 18:39:20 +00:00
if ( * PRESIZEONBORDER & & * PRESIZECURSORICON & & m_eBorderIconDirection ! = BORDERICON_NONE ) {
2023-02-22 00:57:38 +01:00
m_eBorderIconDirection = BORDERICON_NONE ;
unsetCursorImage ( ) ;
}
2024-05-09 21:47:21 +01:00
if ( pFoundLayerSurface & & ( pFoundLayerSurface - > layerSurface - > current . interactivity ! = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE ) & & FOLLOWMOUSE ! = 3 & &
2024-06-11 10:35:30 -07:00
( allowKeyboardRefocus | | pFoundLayerSurface - > layerSurface - > 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 )
m_bLastFocusOnLS = 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-04-29 17:42:07 +01:00
PROTO : : idle - > onActivity ( ) ;
2023-02-28 21:45:57 +00:00
2022-06-24 23:27:02 +02:00
m_tmrLastCursorMovement . reset ( ) ;
2024-05-05 22:18:10 +01:00
if ( e . state = = WL_POINTER_BUTTON_STATE_PRESSED ) {
m_lCurrentlyHeldButtons . push_back ( e . button ) ;
2023-01-11 18:38:54 +01:00
} else {
2024-05-05 22:18:10 +01:00
if ( std : : find_if ( m_lCurrentlyHeldButtons . begin ( ) , m_lCurrentlyHeldButtons . end ( ) , [ & ] ( const auto & other ) { return other = = e . button ; } ) = = m_lCurrentlyHeldButtons . end ( ) )
2023-01-11 18:38:54 +01:00
return ;
2024-05-05 22:18:10 +01:00
std : : erase_if ( m_lCurrentlyHeldButtons , [ & ] ( const auto & other ) { return other = = e . button ; } ) ;
2023-01-11 18:38:54 +01:00
}
2022-06-27 13:42:20 +02:00
switch ( m_ecbClickBehavior ) {
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
2024-05-05 22:18:10 +01:00
if ( m_bFocusHeldByButtons & & m_lCurrentlyHeldButtons . empty ( ) & & e . state = = WL_POINTER_BUTTON_STATE_RELEASED ) {
2023-04-02 13:30:45 +01:00
if ( m_bRefocusHeldByButtons )
refocus ( ) ;
else
simulateMouseMovement ( ) ;
m_bFocusHeldByButtons = false ;
m_bRefocusHeldByButtons = false ;
}
2022-06-27 13:42:20 +02:00
}
2024-05-10 18:27:57 +01:00
void CInputManager : : processMouseRequest ( std : : any E ) {
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
2024-05-10 18:27:57 +01:00
auto e = std : : any_cast < CSeatManager : : SSetCursorEvent > ( E ) ;
2024-02-15 00:46:39 +00:00
2024-07-22 11:06:11 -05:00
Debug : : log ( LOG , " cursorImage request: surface {:x} " , ( uintptr_t ) e . surf . get ( ) ) ;
2024-02-12 20:01:50 +00:00
2024-06-08 10:07:59 +02:00
if ( e . surf ! = m_sCursorSurfaceInfo . wlSurface - > resource ( ) ) {
m_sCursorSurfaceInfo . wlSurface - > unassign ( ) ;
2024-02-12 20:01:50 +00:00
2024-05-10 18:27:57 +01:00
if ( e . surf )
2024-06-08 10:07:59 +02:00
m_sCursorSurfaceInfo . wlSurface - > assign ( e . surf ) ;
2024-05-10 18:27:57 +01:00
}
2023-10-29 18:09:05 +00:00
2024-05-10 18:27:57 +01:00
if ( e . surf ) {
m_sCursorSurfaceInfo . vHotspot = e . hotspot ;
m_sCursorSurfaceInfo . hidden = false ;
} else {
m_sCursorSurfaceInfo . vHotspot = { } ;
m_sCursorSurfaceInfo . hidden = true ;
}
2023-02-28 23:06:46 +00:00
2024-05-10 18:27:57 +01:00
m_sCursorSurfaceInfo . name = " " ;
2023-02-28 23:06:46 +00:00
2024-05-10 18:27:57 +01:00
m_sCursorSurfaceInfo . inUse = true ;
2024-06-08 10:07:59 +02:00
g_pHyprRenderer - > setCursorSurface ( m_sCursorSurfaceInfo . wlSurface , e . hotspot . x , e . hotspot . y ) ;
2023-10-29 18:09:05 +00:00
}
void CInputManager : : restoreCursorIconToApp ( ) {
if ( m_sCursorSurfaceInfo . inUse )
return ;
if ( m_sCursorSurfaceInfo . hidden ) {
g_pHyprRenderer - > setCursorSurface ( nullptr , 0 , 0 ) ;
return ;
}
if ( m_sCursorSurfaceInfo . name . empty ( ) ) {
2024-06-08 10:07:59 +02:00
if ( m_sCursorSurfaceInfo . wlSurface - > exists ( ) )
g_pHyprRenderer - > setCursorSurface ( m_sCursorSurfaceInfo . wlSurface , m_sCursorSurfaceInfo . vHotspot . x , m_sCursorSurfaceInfo . vHotspot . y ) ;
2023-10-29 18:09:05 +00:00
} else {
g_pHyprRenderer - > setCursorFromName ( m_sCursorSurfaceInfo . name ) ;
}
m_sCursorSurfaceInfo . inUse = true ;
}
void CInputManager : : setCursorImageOverride ( const std : : string & name ) {
if ( m_bCursorImageOverridden )
return ;
m_sCursorSurfaceInfo . inUse = false ;
g_pHyprRenderer - > setCursorFromName ( name ) ;
2023-07-24 18:50:17 +02:00
}
bool CInputManager : : cursorImageUnlocked ( ) {
if ( m_ecbClickBehavior = = CLICKMODE_KILL )
return false ;
if ( m_bCursorImageOverridden )
return false ;
return true ;
}
2022-06-27 13:42:20 +02:00
eClickBehaviorMode CInputManager : : getClickMode ( ) {
return m_ecbClickBehavior ;
}
void CInputManager : : setClickMode ( eClickBehaviorMode mode ) {
switch ( mode ) {
case CLICKMODE_DEFAULT :
Debug : : log ( LOG , " SetClickMode: DEFAULT " ) ;
m_ecbClickBehavior = CLICKMODE_DEFAULT ;
2023-09-29 17:51:07 +01:00
g_pHyprRenderer - > setCursorFromName ( " left_ptr " ) ;
2022-06-27 13:42:20 +02:00
break ;
case CLICKMODE_KILL :
Debug : : log ( LOG , " SetClickMode: KILL " ) ;
m_ecbClickBehavior = CLICKMODE_KILL ;
// remove constraints
2022-08-09 20:36:21 +02:00
g_pInputManager - > unconstrainMouse ( ) ;
2022-06-27 13:42:20 +02:00
refocus ( ) ;
// set cursor
2023-09-29 17:51:07 +01:00
g_pHyprRenderer - > setCursorFromName ( " crosshair " ) ;
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
2024-02-10 17:05:28 +00:00
if ( w & & ! m_bLastFocusOnLS & & w - > checkInputOnDecos ( INPUT_TYPE_BUTTON , mouseCoords , e ) )
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
2024-08-30 14:12:23 +02:00
if ( * PRESIZEONBORDER & & ! m_bLastFocusOnLS & & e . state = = WL_POINTER_BUTTON_STATE_PRESSED & & ( ! w | | ! w - > isX11OverrideRedirect ( ) ) ) {
2024-07-31 17:55:52 +00:00
if ( w & & ! w - > isFullscreen ( ) ) {
2024-03-02 01:35:17 +01:00
const CBox real = { w - > m_vRealPosition . value ( ) . x , w - > m_vRealPosition . value ( ) . y , w - > m_vRealSize . value ( ) . x , w - > m_vRealSize . 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 ;
2024-05-10 18:27:57 +01:00
if ( ( g_pSeatManager - > mouse . expired ( ) | | ! isConstrained ( ) ) /* No constraints */
2024-04-27 12:43:12 +01:00
& & ( w & & g_pCompositor - > m_pLastWindow . 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
if ( m_lCurrentlyHeldButtons . size ( ) = = 1 ) {
const auto COPY = m_lCurrentlyHeldButtons ;
m_lCurrentlyHeldButtons . clear ( ) ;
refocus ( ) ;
m_lCurrentlyHeldButtons = COPY ;
} 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
2024-05-25 22:43:51 +02:00
if ( ! g_pSeatManager - > state . pointerFocus )
break ;
2024-06-08 10:07:59 +02:00
auto HLSurf = CWLSurface : : fromResource ( g_pSeatManager - > 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
}
// notify app if we didnt 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
2024-05-05 22:18:10 +01:00
if ( const auto PMON = g_pCompositor - > getMonitorFromVector ( mouseCoords ) ; PMON ! = g_pCompositor - > m_pLastMonitor . get ( ) & & PMON )
2024-02-10 17:39:24 +00:00
g_pCompositor - > setActiveMonitor ( PMON ) ;
2024-05-11 01:02:57 +01:00
if ( g_pSeatManager - > seatGrab & & e . state = = WL_POINTER_BUTTON_STATE_PRESSED ) {
m_bHardInput = true ;
simulateMouseMovement ( ) ;
m_bHardInput = false ;
}
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
m_ecbClickBehavior = CLICKMODE_DEFAULT ;
2022-03-17 16:56:33 +01:00
}
2024-05-05 22:18:10 +01:00
void CInputManager : : onMouseWheel ( IPointer : : SAxisEvent e ) {
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 " ) ;
2022-10-06 22:20:10 +03:00
2024-05-05 22:18:10 +01:00
auto factor = ( * PTOUCHPADSCROLLFACTOR < = 0.f | | e . source = = WL_POINTER_AXIS_SOURCE_FINGER ? * PTOUCHPADSCROLLFACTOR : * PINPUTSCROLLFACTOR ) ;
2022-10-06 22:20:10 +03:00
2024-03-03 18:39:20 +00:00
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 ) ;
bool passEvent = g_pKeybindManager - > onAxisEvent ( e ) ;
2022-06-20 22:47:28 +03:00
2024-04-29 17:42:07 +01:00
PROTO : : idle - > onActivity ( ) ;
2022-06-20 22:47:28 +03:00
2023-12-05 21:16:26 +00:00
if ( ! passEvent )
return ;
2024-01-01 12:02:16 +00:00
if ( ! m_bLastFocusOnLS ) {
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-01-01 12:02:16 +00:00
if ( PWINDOW & & PWINDOW - > checkInputOnDecos ( INPUT_TYPE_AXIS , MOUSECOORDS , e ) )
return ;
2024-04-08 22:35:21 +00:00
if ( PWINDOW & & * POFFWINDOWAXIS ! = 1 ) {
const auto BOX = PWINDOW - > getWindowMainSurfaceBox ( ) ;
if ( ! BOX . containsPoint ( MOUSECOORDS ) & & ! PWINDOW - > hasPopupAt ( MOUSECOORDS ) ) {
if ( * POFFWINDOWAXIS = = 0 )
return ;
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 ) ;
if ( * POFFWINDOWAXIS = = 3 )
2024-05-05 22:18:10 +01:00
g_pCompositor - > warpCursorTo ( { TEMPCURX , TEMPCURY } , true ) ;
2024-04-08 22:35:21 +00:00
2024-05-10 18:27:57 +01:00
g_pSeatManager - > sendPointerMotion ( e . timeMs , Vector2D { TEMPCURX , TEMPCURY } - BOX . pos ( ) ) ;
g_pSeatManager - > sendPointerFrame ( ) ;
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
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 */ ) {
m_ScrollWheelState . accumulatedScroll = 0 ;
// send 1 discrete on first event for responsiveness
discrete = std : : copysign ( 1 , e . deltaDiscrete ) ;
} else
discrete = 0 ;
for ( int ac = m_ScrollWheelState . accumulatedScroll ; ac > = interval ; ac - = interval ) {
discrete + = std : : copysign ( 1 , e . deltaDiscrete ) ;
m_ScrollWheelState . accumulatedScroll - = interval ;
}
m_ScrollWheelState . lastEventSign = std : : signbit ( e . deltaDiscrete ) ;
m_ScrollWheelState . lastEventAxis = e . axis ;
m_ScrollWheelState . lastEventTime = e . timeMs ;
m_ScrollWheelState . accumulatedScroll + = std : : abs ( e . deltaDiscrete ) ;
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
}
2024-07-21 13:09:54 +02:00
void CInputManager : : newKeyboard ( SP < Aquamarine : : IKeyboard > keyboard ) {
const auto PNEWKEYBOARD = m_vKeyboards . 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
2024-07-22 11:06:11 -05:00
Debug : : log ( LOG , " New keyboard created, pointers Hypr: {:x} and AQ: {:x} " , ( uintptr_t ) PNEWKEYBOARD . get ( ) , ( 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 ) {
const auto PNEWKEYBOARD = m_vKeyboards . 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
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " New virtual keyboard created at {:x} " , ( 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-05-06 02:15:26 +01:00
m_vHIDs . push_back ( keeb ) ;
2022-08-05 16:21:08 +02:00
try {
2024-07-21 13:09:54 +02:00
keeb - > hlName = getNameForNewDevice ( keeb - > 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
}
2024-05-03 22:34:10 +01:00
keeb - > events . destroy . registerStaticListener (
[ this ] ( void * owner , std : : any data ) {
auto PKEEB = ( ( IKeyboard * ) owner ) - > self . lock ( ) ;
2024-05-04 00:48:25 +01:00
if ( ! PKEEB )
return ;
2024-05-03 22:34:10 +01:00
destroyKeyboard ( PKEEB ) ;
Debug : : log ( LOG , " Destroyed keyboard {:x} " , ( uintptr_t ) owner ) ;
} ,
keeb . get ( ) ) ;
2022-09-25 20:07:48 +02:00
2024-05-03 22:34:10 +01:00
keeb - > keyboardEvents . key . registerStaticListener (
[ this ] ( void * owner , std : : any data ) {
auto PKEEB = ( ( IKeyboard * ) owner ) - > self . lock ( ) ;
2024-05-09 14:07:21 +01:00
2024-05-03 22:34:10 +01:00
onKeyboardKey ( data , PKEEB ) ;
2022-12-16 17:17:31 +00:00
} ,
2024-05-03 22:34:10 +01:00
keeb . get ( ) ) ;
2022-08-18 17:50:32 +02:00
2024-05-03 22:34:10 +01:00
keeb - > keyboardEvents . modifiers . registerStaticListener (
[ this ] ( void * owner , std : : any data ) {
auto PKEEB = ( ( IKeyboard * ) owner ) - > self . lock ( ) ;
2024-05-09 14:07:21 +01:00
2024-05-03 22:34:10 +01:00
onKeyboardMod ( PKEEB ) ;
} ,
keeb . get ( ) ) ;
2024-05-03 00:54:32 +01:00
2024-05-03 22:34:10 +01:00
keeb - > keyboardEvents . keymap . registerStaticListener (
[ this ] ( void * owner , std : : any data ) {
auto PKEEB = ( ( IKeyboard * ) owner ) - > self . lock ( ) ;
const auto LAYOUT = PKEEB - > getActiveLayout ( ) ;
2022-08-05 16:21:08 +02:00
2024-05-24 20:58:26 +02:00
if ( PKEEB = = g_pSeatManager - > keyboard ) {
2024-05-17 19:28:33 +01:00
g_pSeatManager - > updateActiveKeyboardData ( ) ;
2024-05-24 20:58:26 +02:00
g_pKeybindManager - > m_mKeyToCodeCache . clear ( ) ;
}
2024-05-17 19:28:33 +01:00
2024-05-03 22:34:10 +01:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , PKEEB - > hlName + " , " + LAYOUT } ) ;
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < std : : any > { PKEEB , LAYOUT } ) ) ;
} ,
keeb . get ( ) ) ;
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 ( ) ;
2022-08-05 16:21:08 +02:00
}
2022-03-24 21:05:34 +01:00
void CInputManager : : setKeyboardLayout ( ) {
2024-08-26 17:25:39 +02:00
for ( auto const & k : m_vKeyboards )
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 ) {
auto devname = pKeyboard - > hlName ;
2022-07-28 21:38:30 +02:00
const auto HASCONFIG = g_pConfigManager - > deviceConfigExists ( devname ) ;
2024-05-03 22:34:10 +01:00
Debug : : log ( LOG , " ApplyConfigToKeyboard for \" {} \" , hasconfig: {} " , devname , ( 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
2022-12-20 02:18:47 +00:00
const auto ENABLED = HASCONFIG ? g_pConfigManager - > getDeviceInt ( devname , " enabled " ) : true ;
2022-12-16 17:20:51 +00:00
2024-02-28 00:21:22 +01:00
pKeyboard - > enabled = ENABLED ;
pKeyboard - > resolveBindsBySym = RESOLVEBINDSBYSYM ;
2022-12-16 17:20:51 +00:00
2022-06-28 15:40:14 +02:00
try {
2022-12-16 17:17:31 +00:00
if ( NUMLOCKON = = pKeyboard - > numlockOn & & REPEATDELAY = = pKeyboard - > repeatDelay & & REPEATRATE = = pKeyboard - > repeatRate & & RULES ! = " " & &
RULES = = pKeyboard - > currentRules . rules & & MODEL = = pKeyboard - > currentRules . model & & LAYOUT = = pKeyboard - > currentRules . layout & &
VARIANT = = pKeyboard - > currentRules . variant & & OPTIONS = = pKeyboard - > currentRules . options & & FILEPATH = = pKeyboard - > 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
}
2024-07-21 13:09:54 +02:00
pKeyboard - > repeatRate = std : : max ( 0 , REPEATRATE ) ;
pKeyboard - > repeatDelay = std : : max ( 0 , REPEATDELAY ) ;
2022-12-16 17:17:31 +00:00
pKeyboard - > numlockOn = NUMLOCKON ;
2023-12-11 17:28:22 +01:00
pKeyboard - > xkbFilePath = FILEPATH ;
2022-06-30 21:26:00 +02:00
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
2024-05-03 22:34:10 +01:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , pKeyboard - > hlName + " , " + LAYOUTSTR } ) ;
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < std : : any > { pKeyboard , LAYOUTSTR } ) ) ;
2022-08-18 17:17:33 +02:00
2024-05-03 22:34:10 +01:00
Debug : : log ( LOG , " Set the keyboard layout to {} and variant to {} for keyboard \" {} \" " , pKeyboard - > currentRules . layout , pKeyboard - > currentRules . variant , pKeyboard - > 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 ) {
const auto PMOUSE = m_vPointers . 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
}
2024-07-21 13:09:54 +02:00
void CInputManager : : newMouse ( SP < Aquamarine : : IPointer > mouse ) {
const auto PMOUSE = m_vPointers . emplace_back ( CMouse : : create ( mouse ) ) ;
2022-04-17 21:40:04 +02:00
2024-05-03 22:34:10 +01:00
setupMouse ( PMOUSE ) ;
2024-07-22 11:06:11 -05:00
Debug : : log ( LOG , " New mouse created, pointer AQ: {:x} " , ( uintptr_t ) mouse . get ( ) ) ;
2024-05-03 22:34:10 +01:00
}
void CInputManager : : setupMouse ( SP < IPointer > mauz ) {
2024-05-06 02:15:26 +01:00
m_vHIDs . push_back ( mauz ) ;
2022-06-30 21:26:00 +02:00
try {
2024-07-21 13:09:54 +02:00
mauz - > hlName = getNameForNewDevice ( mauz - > 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 ) ,
libinput_device_config_accel_get_default_speed ( LIBINPUTDEV ) , ( int ) libinput_device_config_accel_get_profile ( LIBINPUTDEV ) ,
( 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
2024-05-03 22:34:10 +01:00
mauz - > connected = true ;
2022-10-27 12:58:10 +01:00
2022-11-04 10:48:42 +00:00
setPointerConfigs ( ) ;
2024-05-03 22:34:10 +01:00
mauz - > events . destroy . registerStaticListener (
[ this ] ( void * mouse , std : : any data ) {
const auto PMOUSE = ( IPointer * ) mouse ;
2024-05-04 00:48:25 +01:00
if ( ! PMOUSE )
return ;
2024-05-03 22:34:10 +01:00
destroyPointer ( PMOUSE - > self . lock ( ) ) ;
} ,
mauz . get ( ) ) ;
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
2022-06-24 23:27:02 +02:00
m_tmrLastCursorMovement . reset ( ) ;
2022-03-18 22:53:27 +01:00
}
2022-10-05 23:21:22 +03:00
void CInputManager : : setPointerConfigs ( ) {
2024-08-26 20:24:30 +02:00
for ( auto const & m : m_vPointers ) {
2024-05-03 22:34:10 +01:00
auto devname = 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 " ) ;
2024-05-03 22:34:10 +01:00
if ( ENABLED & & ! m - > connected ) {
2024-05-05 22:18:10 +01:00
g_pPointerManager - > attachPointer ( m ) ;
2024-05-03 22:34:10 +01:00
m - > connected = true ;
} else if ( ! ENABLED & & m - > connected ) {
2024-05-05 22:18:10 +01:00
g_pPointerManager - > detachPointer ( m ) ;
2024-05-03 22:34:10 +01:00
m - > connected = false ;
2022-10-27 12:58:10 +01:00
}
}
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 " ) ;
2023-02-05 16:17:23 +02:00
if ( TAP_MAP = = " " | | TAP_MAP = = " lrm " )
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 " ) ;
2022-11-24 17:11:21 +00:00
if ( SCROLLMETHOD = = " " ) {
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 ) ;
2023-09-06 19:16:46 +02:00
if ( g_pConfigManager - > getDeviceInt ( devname , " drag_lock " , " input:touchpad:drag_lock " ) = = 0 )
2022-07-19 19:26:53 +02:00
libinput_device_config_tap_set_drag_lock_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_DRAG_LOCK_DISABLED ) ;
else
libinput_device_config_tap_set_drag_lock_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_DRAG_LOCK_ENABLED ) ;
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
}
if ( libinput_device_config_dwt_is_available ( LIBINPUTDEV ) ) {
2023-09-06 19:16:46 +02:00
const auto DWT =
static_cast < 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 ) ;
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
2024-05-03 22:34:10 +01:00
Debug : : log ( LOG , " Applied config to mouse {}, sens {:.2f} " , 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 ) {
std : : erase_if ( g_pInputManager - > m_vHIDs , [ hid ] ( const auto & e ) { return e . expired ( ) | | e = = hid ; } ) ;
g_pInputManager - > updateCapabilities ( ) ;
}
2024-05-03 22:34:10 +01:00
void CInputManager : : destroyKeyboard ( SP < IKeyboard > pKeyboard ) {
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " Keyboard at {:x} removed " , ( uintptr_t ) pKeyboard . get ( ) ) ;
2024-02-28 00:21:22 +01:00
2024-05-03 22:34:10 +01:00
std : : erase_if ( m_vKeyboards , [ pKeyboard ] ( const auto & other ) { return other = = pKeyboard ; } ) ;
2022-06-03 18:59:39 +02:00
2024-05-03 22:34:10 +01:00
if ( m_vKeyboards . size ( ) > 0 ) {
2024-06-12 17:03:04 +02:00
bool found = false ;
2024-08-26 17:25:39 +02:00
for ( auto const & k : m_vKeyboards | 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 ) {
2024-07-21 13:09:54 +02:00
Debug : : log ( LOG , " Pointer at {:x} removed " , ( uintptr_t ) mouse . get ( ) ) ;
2024-05-03 22:34:10 +01:00
std : : erase_if ( m_vPointers , [ mouse ] ( const auto & other ) { return other = = mouse ; } ) ;
2022-04-17 21:40:04 +02:00
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setMouse ( m_vPointers . size ( ) > 0 ? m_vPointers . front ( ) : nullptr ) ;
2022-05-12 12:13:02 +02:00
2024-05-10 18:27:57 +01:00
if ( ! g_pSeatManager - > 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 ) {
Debug : : log ( LOG , " Touch device at {:x} removed " , ( uintptr_t ) touch . get ( ) ) ;
2022-12-16 17:17:31 +00:00
2024-05-03 22:34:10 +01:00
std : : erase_if ( m_vTouches , [ touch ] ( const auto & other ) { return other = = touch ; } ) ;
2024-05-06 02:15:26 +01:00
removeFromHIDs ( touch ) ;
}
void CInputManager : : destroyTablet ( SP < CTablet > tablet ) {
Debug : : log ( LOG , " Tablet device at {:x} removed " , ( uintptr_t ) tablet . get ( ) ) ;
std : : erase_if ( m_vTablets , [ tablet ] ( const auto & other ) { return other = = tablet ; } ) ;
removeFromHIDs ( tablet ) ;
}
void CInputManager : : destroyTabletTool ( SP < CTabletTool > tool ) {
Debug : : log ( LOG , " Tablet tool at {:x} removed " , ( uintptr_t ) tool . get ( ) ) ;
std : : erase_if ( m_vTabletTools , [ tool ] ( const auto & other ) { return other = = tool ; } ) ;
removeFromHIDs ( tool ) ;
}
void CInputManager : : destroyTabletPad ( SP < CTabletPad > pad ) {
Debug : : log ( LOG , " Tablet pad at {:x} removed " , ( uintptr_t ) pad . get ( ) ) ;
std : : erase_if ( m_vTabletPads , [ pad ] ( const auto & other ) { return other = = pad ; } ) ;
removeFromHIDs ( pad ) ;
2022-11-12 13:12:37 +02:00
}
2024-05-15 00:14:43 +09:00
void CInputManager : : updateKeyboardsLeds ( SP < IKeyboard > pKeyboard ) {
if ( ! pKeyboard )
return ;
2024-07-28 19:46:38 +09:00
std : : optional < uint32_t > leds = pKeyboard - > getLEDs ( ) ;
if ( ! leds . has_value ( ) )
return ;
2024-08-26 20:24:30 +02:00
for ( auto const & k : m_vKeyboards ) {
2024-07-28 19:46:38 +09:00
k - > updateLEDs ( leds . value ( ) ) ;
}
2024-05-15 00:14:43 +09:00
}
2024-05-03 22:34:10 +01:00
void CInputManager : : onKeyboardKey ( std : : any event , SP < IKeyboard > pKeyboard ) {
2022-12-16 17:20:51 +00:00
if ( ! pKeyboard - > enabled )
return ;
2024-05-03 22:34:10 +01:00
const bool DISALLOWACTION = pKeyboard - > isVirtual ( ) & & shouldIgnoreVirtualKeyboard ( pKeyboard ) ;
2024-05-01 16:41:17 +01:00
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 ) ;
2024-03-03 18:39:20 +00:00
static auto PDPMS = CConfigValue < Hyprlang : : INT > ( " misc:key_press_enables_dpms " ) ;
if ( * PDPMS & & ! g_pCompositor - > m_bDPMSStateON ) {
2023-03-12 13:46:38 +00:00
// enable dpms
g_pKeybindManager - > dpms ( " on " ) ;
}
2024-05-03 22:34:10 +01:00
bool passEvent = DISALLOWACTION | | g_pKeybindManager - > onKeyEvent ( event , pKeyboard ) ;
auto e = std : : any_cast < IKeyboard : : SKeyEvent > ( event ) ;
2022-03-18 23:06:45 +01:00
2024-04-29 17:42:07 +01:00
PROTO : : idle - > onActivity ( ) ;
2022-03-17 20:55:04 +01:00
2022-07-20 22:45:06 +02:00
if ( passEvent ) {
2024-05-01 16:41:17 +01:00
const auto IME = m_sIMERelay . m_pIME . lock ( ) ;
2022-08-05 16:21:08 +02:00
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-03 22:34:10 +01:00
IME - > sendKey ( e . timeMs , e . keycode , e . state ) ;
2022-08-05 16:21:08 +02:00
} else {
2024-05-10 18:27:57 +01:00
g_pSeatManager - > setKeyboard ( pKeyboard ) ;
g_pSeatManager - > sendKeyboardKey ( e . timeMs , e . keycode , e . 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 ) {
2022-12-16 17:20:51 +00:00
if ( ! pKeyboard - > enabled )
return ;
2024-05-03 22:34:10 +01:00
const bool DISALLOWACTION = pKeyboard - > isVirtual ( ) & & shouldIgnoreVirtualKeyboard ( pKeyboard ) ;
2022-08-05 16:21:08 +02:00
2022-09-04 18:46:28 +02:00
const auto ALLMODS = accumulateModsFromAllKBs ( ) ;
2024-07-21 13:09:54 +02:00
auto MODS = pKeyboard - > modifiersState ;
2022-12-16 17:17:31 +00:00
MODS . depressed = ALLMODS ;
2022-09-04 18:46:28 +02:00
2024-05-01 16:41:17 +01:00
const auto IME = m_sIMERelay . m_pIME . lock ( ) ;
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
2024-07-21 13:09:54 +02:00
if ( pKeyboard - > modifiersState . group ! = pKeyboard - > activeLayout ) {
pKeyboard - > activeLayout = pKeyboard - > 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
2024-05-03 22:34:10 +01:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , pKeyboard - > hlName + " , " + LAYOUT } ) ;
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 ) {
if ( ! pKeyboard - > isVirtual ( ) )
2024-05-03 00:31:48 +01:00
return false ;
2024-05-03 22:34:10 +01:00
CVirtualKeyboard * vk = ( CVirtualKeyboard * ) pKeyboard . get ( ) ;
2024-05-05 17:16:00 +01:00
return ! pKeyboard | | ( ! m_sIMERelay . m_pIME . expired ( ) & & m_sIMERelay . m_pIME - > grabClient ( ) = = vk - > getClient ( ) ) ;
2022-11-07 22:22:13 +00:00
}
2022-03-21 19:28:43 +01:00
void CInputManager : : refocus ( ) {
2022-04-13 20:19:40 +02:00
mouseMoveUnified ( 0 , true ) ;
2022-03-31 17:25:23 +02:00
}
2024-06-11 10:35:30 -07:00
void CInputManager : : refocusLastWindow ( CMonitor * pMonitor ) {
if ( ! pMonitor ) {
refocus ( ) ;
return ;
}
Vector2D surfaceCoords ;
PHLLS pFoundLayerSurface ;
SP < CWLSurfaceResource > foundSurface = nullptr ;
g_pInputManager - > releaseAllMouseButtons ( ) ;
// first try for an exclusive layer
if ( ! m_dExclusiveLSes . empty ( ) )
foundSurface = m_dExclusiveLSes [ m_dExclusiveLSes . size ( ) - 1 ] - > surface - > resource ( ) ;
// then any surfaces above windows on the same monitor
if ( ! foundSurface )
foundSurface = g_pCompositor - > vectorToLayerSurface ( g_pInputManager - > getMouseCoordsInternal ( ) , & pMonitor - > m_aLayerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY ] ,
& surfaceCoords , & pFoundLayerSurface ) ;
if ( ! foundSurface )
foundSurface = g_pCompositor - > vectorToLayerSurface ( g_pInputManager - > getMouseCoordsInternal ( ) , & pMonitor - > m_aLayerSurfaceLayers [ ZWLR_LAYER_SHELL_V1_LAYER_TOP ] ,
& surfaceCoords , & pFoundLayerSurface ) ;
2024-06-11 20:56:35 +00:00
if ( ! foundSurface & & g_pCompositor - > m_pLastWindow . lock ( ) & & g_pCompositor - > isWorkspaceVisibleNotCovered ( g_pCompositor - > m_pLastWindow - > m_pWorkspace ) ) {
2024-06-11 10:35:30 -07:00
// then the last focused window if we're on the same workspace as it
const auto PLASTWINDOW = g_pCompositor - > m_pLastWindow . lock ( ) ;
g_pCompositor - > focusWindow ( PLASTWINDOW ) ;
} else {
// otherwise fall back to a normal refocus.
2024-07-27 17:49:27 +02:00
if ( foundSurface & & ! foundSurface - > hlSurface - > keyboardFocusable ( ) ) {
const auto PLASTWINDOW = g_pCompositor - > m_pLastWindow . lock ( ) ;
g_pCompositor - > focusWindow ( PLASTWINDOW ) ;
}
2024-06-11 10:35:30 -07:00
refocus ( ) ;
}
}
2022-08-09 20:36:21 +02:00
void CInputManager : : unconstrainMouse ( ) {
2024-05-10 18:27:57 +01:00
if ( g_pSeatManager - > mouse . expired ( ) )
2022-08-09 20:36:21 +02:00
return ;
2024-08-26 20:24:30 +02:00
for ( auto const & c : m_vConstraints ) {
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 ( ) {
2024-08-26 20:24:30 +02:00
for ( auto const & c : m_vConstraints ) {
2024-04-26 23:55:41 +01:00
const auto C = c . lock ( ) ;
if ( ! C )
continue ;
2024-06-08 10:07:59 +02:00
if ( ! C - > isActive ( ) | | C - > owner ( ) - > resource ( ) ! = g_pCompositor - > m_pLastFocus )
2024-03-02 21:04:55 +00:00
continue ;
2022-12-10 14:43:46 +00:00
2024-03-02 21:04:55 +00:00
return true ;
2022-12-10 14:43:46 +00:00
}
2023-01-03 13:06:13 +01:00
2024-03-02 21:04:55 +00:00
return false ;
2022-04-17 21:40:04 +02:00
}
2022-06-09 12:46:55 +02:00
2022-12-05 14:28:27 +00:00
void CInputManager : : updateCapabilities ( ) {
uint32_t caps = 0 ;
2024-08-26 20:24:30 +02:00
for ( auto const & h : m_vHIDs ) {
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 ) ;
2022-12-05 14:28:27 +00:00
m_uiCapabilities = caps ;
2022-07-09 23:24:08 +02:00
}
uint32_t CInputManager : : accumulateModsFromAllKBs ( ) {
uint32_t finalMask = 0 ;
2024-08-26 20:24:30 +02:00
for ( auto const & kb : m_vKeyboards ) {
2024-05-03 22:34:10 +01:00
if ( kb - > isVirtual ( ) & & shouldIgnoreVirtualKeyboard ( kb ) )
2022-09-05 11:19:40 +02:00
continue ;
2024-07-21 13:09:54 +02:00
if ( ! kb - > 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 ) {
2024-08-26 20:24:30 +02:00
for ( auto const & k : m_vKeyboards ) {
2024-05-03 22:34:10 +01:00
if ( k - > isVirtual ( ) ! = virt )
2022-08-18 17:50:32 +02:00
continue ;
2024-05-03 22:34:10 +01:00
k - > 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 ) {
const auto PNEWDEV = m_vTouches . emplace_back ( CTouchDevice : : create ( pDevice ) ) ;
2024-05-06 02:15:26 +01:00
m_vHIDs . push_back ( PNEWDEV ) ;
2022-09-21 14:39:25 +01:00
2022-10-07 16:03:52 +02:00
try {
2024-07-21 13:09:54 +02:00
PNEWDEV - > hlName = getNameForNewDevice ( PNEWDEV - > 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
2024-05-03 22:34:10 +01:00
PNEWDEV - > events . destroy . registerStaticListener (
[ this ] ( void * owner , std : : any data ) {
auto PDEV = ( ( ITouch * ) owner ) - > self . lock ( ) ;
2024-05-04 00:48:25 +01:00
if ( ! PDEV )
return ;
2024-05-03 22:34:10 +01:00
destroyTouchDevice ( PDEV ) ;
} ,
PNEWDEV . get ( ) ) ;
2022-09-21 14:39:25 +01:00
2024-05-03 22:34:10 +01:00
Debug : : log ( LOG , " New touch device added at {:x} " , ( 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
2024-05-03 22:34:10 +01:00
const auto ENABLED = g_pConfigManager - > getDeviceInt ( PTOUCHDEV - > 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 ) ;
2024-05-03 22:34:10 +01:00
const int ROTATION = std : : clamp ( g_pConfigManager - > getDeviceInt ( PTOUCHDEV - > hlName , " transform " , " input:touchdevice:transform " ) , 0 , 7 ) ;
Debug : : log ( LOG , " Setting calibration matrix for device {} " , PTOUCHDEV - > hlName ) ;
2023-05-14 13:54:55 +01:00
if ( libinput_device_config_calibration_has_matrix ( LIBINPUTDEV ) )
libinput_device_config_calibration_set_matrix ( LIBINPUTDEV , MATRICES [ ROTATION ] ) ;
2022-10-14 12:38:44 +01:00
2024-05-03 22:34:10 +01:00
auto output = g_pConfigManager - > getDeviceString ( PTOUCHDEV - > 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
}
PTOUCHDEV - > boundOutput = bound ? output : " " ;
const auto PMONITOR = bound ? g_pCompositor - > getMonitorFromName ( output ) : nullptr ;
if ( PMONITOR ) {
2024-05-03 22:34:10 +01:00
Debug : : log ( LOG , " Binding touch device {} to output {} " , PTOUCHDEV - > hlName , PMONITOR - > szName ) ;
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 )
2024-05-03 22:34:10 +01:00
Debug : : log ( ERR , " Failed to bind touch device {} to output '{}': monitor not found " , PTOUCHDEV - > hlName , output ) ;
2022-10-07 16:03:52 +02:00
}
2023-05-24 22:17:33 +02:00
} ;
if ( dev ) {
setConfig ( dev ) ;
return ;
}
2024-08-26 20:24:30 +02:00
for ( auto const & m : m_vTouches ) {
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 ( ) {
2024-08-26 20:24:30 +02:00
for ( auto const & t : m_vTablets ) {
2024-07-21 13:09:54 +02:00
if ( t - > aq ( ) - > getLibinputHandle ( ) ) {
2024-05-06 02:15:26 +01:00
const auto NAME = t - > 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 " ) ;
t - > relativeInput = RELINPUT ;
2023-12-09 04:07:28 +00:00
2024-05-06 02:15:26 +01:00
const int ROTATION = std : : clamp ( g_pConfigManager - > getDeviceInt ( NAME , " transform " , " input:tablet:transform " ) , 0 , 7 ) ;
Debug : : log ( LOG , " Setting calibration matrix for device {} " , NAME ) ;
2023-01-15 20:38:58 +01:00
libinput_device_config_calibration_set_matrix ( LIBINPUTDEV , MATRICES [ ROTATION ] ) ;
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 ) ;
t - > boundOutput = OUTPUT ;
} else
t - > boundOutput = " " ;
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 " ) ;
t - > boundBox = { REGION_POS , REGION_SIZE } ;
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 ) {
2024-07-21 13:09:54 +02:00
t - > activeArea = CBox { ACTIVE_AREA_POS . x / t - > aq ( ) - > physicalSize . x , ACTIVE_AREA_POS . y / t - > aq ( ) - > physicalSize . y ,
( ACTIVE_AREA_POS . x + ACTIVE_AREA_SIZE . x ) / t - > aq ( ) - > physicalSize . x , ( ACTIVE_AREA_POS . y + ACTIVE_AREA_SIZE . y ) / t - > aq ( ) - > physicalSize . 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 ) {
const auto PNEWDEV = & m_lSwitches . emplace_back ( ) ;
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
2024-07-21 13:09:54 +02:00
PNEWDEV - > listeners . destroy = pDevice - > events . destroy . registerListener ( [ this , PNEWDEV ] ( std : : any d ) { destroySwitch ( PNEWDEV ) ; } ) ;
2022-10-04 20:07:21 +01:00
2024-07-21 13:09:54 +02:00
PNEWDEV - > listeners . fire = pDevice - > events . fire . registerListener ( [ PNEWDEV ] ( std : : any d ) {
const auto NAME = PNEWDEV - > pDevice - > getName ( ) ;
const auto E = std : : any_cast < Aquamarine : : ISwitch : : SFireEvent > ( d ) ;
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
2024-07-21 13:09:54 +02:00
if ( E . enable ) {
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 ) {
m_lSwitches . 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 ) ;
2023-10-29 18:09:05 +00:00
m_bCursorImageOverridden = true ;
m_sCursorSurfaceInfo . inUse = false ;
2022-11-15 10:39:05 +00:00
}
void CInputManager : : unsetCursorImage ( ) {
2023-03-30 00:44:25 +02:00
if ( ! m_bCursorImageOverridden )
2022-11-15 10:39:05 +00:00
return ;
2023-03-30 00:44:25 +02:00
m_bCursorImageOverridden = 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
std : : string CInputManager : : deviceNameToInternalString ( std : : string in ) {
std : : replace ( in . begin ( ) , in . end ( ) , ' ' , ' - ' ) ;
2023-08-25 12:17:44 +02:00
std : : replace ( in . begin ( ) , in . end ( ) , ' \n ' , ' - ' ) ;
2022-12-03 15:56:07 +00:00
std : : transform ( in . begin ( ) , in . end ( ) , in . begin ( ) , : : tolower ) ;
return in ;
}
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-05-03 22:34:10 +01:00
while ( std : : find_if ( m_vKeyboards . begin ( ) , m_vKeyboards . end ( ) ,
[ & ] ( const auto & other ) { return other - > hlName = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_vKeyboards . end ( ) )
2022-12-03 20:36:52 +00:00
dupeno + + ;
2024-05-03 22:34:10 +01:00
while ( std : : find_if ( m_vPointers . begin ( ) , m_vPointers . end ( ) ,
[ & ] ( const auto & other ) { return other - > hlName = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_vPointers . end ( ) )
2022-12-03 20:36:52 +00:00
dupeno + + ;
2024-05-03 22:34:10 +01:00
while ( std : : find_if ( m_vTouches . begin ( ) , m_vTouches . end ( ) ,
[ & ] ( const auto & other ) { return other - > hlName = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_vTouches . end ( ) )
2022-12-03 20:36:52 +00:00
dupeno + + ;
2024-05-06 02:15:26 +01:00
while ( std : : find_if ( m_vTabletPads . begin ( ) , m_vTabletPads . end ( ) ,
[ & ] ( const auto & other ) { return other - > hlName = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_vTabletPads . end ( ) )
2022-12-03 20:36:52 +00:00
dupeno + + ;
2024-05-06 02:15:26 +01:00
while ( std : : find_if ( m_vTablets . begin ( ) , m_vTablets . end ( ) ,
[ & ] ( const auto & other ) { return other - > hlName = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_vTablets . end ( ) )
2022-12-03 20:36:52 +00:00
dupeno + + ;
2024-05-06 02:15:26 +01:00
while ( std : : find_if ( m_vTabletTools . begin ( ) , m_vTabletTools . end ( ) ,
[ & ] ( const auto & other ) { return other - > hlName = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_vTabletTools . end ( ) )
2022-12-03 20:36:52 +00:00
dupeno + + ;
return proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ;
}
2022-12-10 14:43:46 +00:00
2023-01-11 18:38:54 +01:00
void CInputManager : : releaseAllMouseButtons ( ) {
const auto buttonsCopy = m_lCurrentlyHeldButtons ;
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 ) {
2024-05-10 18:27:57 +01:00
g_pSeatManager - > sendPointerButton ( 0 , mb , WL_POINTER_BUTTON_STATE_RELEASED ) ;
2023-01-11 18:38:54 +01:00
}
m_lCurrentlyHeldButtons . clear ( ) ;
}
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
2024-07-27 16:46:19 +00:00
if ( g_pInputManager - > currentlyDraggedWindow . expired ( ) ) {
2023-02-18 23:35:31 +01:00
m_eBorderIconDirection = BORDERICON_NONE ;
return ;
}
2024-05-25 22:43:51 +02:00
// ignore X11 OR windows, they shouldn't be touched
2024-08-30 14:12:23 +02:00
if ( w - > m_bIsX11 & & 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 ;
2024-04-27 12:43:12 +01:00
else if ( ! boxFullGrabInput . containsPoint ( mouseCoords ) | | ( ! m_lCurrentlyHeldButtons . empty ( ) & & currentlyDraggedWindow . expired ( ) ) )
2023-10-29 23:37:12 +00:00
direction = BORDERICON_NONE ;
else {
bool onDeco = false ;
2024-08-26 20:24:30 +02:00
for ( auto const & wd : w - > m_dWindowDecorations ) {
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
}
}
}
if ( direction = = m_eBorderIconDirection )
return ;
m_eBorderIconDirection = direction ;
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 ;
}
}