2022-03-17 15:53:45 +01:00
# include "InputManager.hpp"
2022-06-09 12:46:55 +02:00
# include "../../Compositor.hpp"
2023-01-08 16:35:24 +01:00
# include "wlr/types/wlr_switch.h"
2023-03-01 15:06:52 +01:00
# include <ranges>
2022-03-17 15:53:45 +01:00
2023-11-12 15:03:46 +01:00
CInputManager : : ~ CInputManager ( ) {
m_lConstraints . clear ( ) ;
m_lKeyboards . clear ( ) ;
m_lMice . clear ( ) ;
m_lTablets . clear ( ) ;
m_lTabletTools . clear ( ) ;
m_lTabletPads . clear ( ) ;
m_lIdleInhibitors . clear ( ) ;
m_lTouchDevices . clear ( ) ;
m_lSwitches . clear ( ) ;
}
2022-03-24 15:57:46 +01:00
void CInputManager : : onMouseMoved ( wlr_pointer_motion_event * e ) {
2022-12-16 18:17:31 +01:00
static auto * const PSENS = & g_pConfigManager - > getConfigValuePtr ( " general:sensitivity " ) - > floatValue ;
static auto * const PNOACCEL = & g_pConfigManager - > getConfigValuePtr ( " input:force_no_accel " ) - > intValue ;
2022-09-03 19:35:17 +02:00
static auto * const PSENSTORAW = & g_pConfigManager - > getConfigValuePtr ( " general:apply_sens_to_raw " ) - > intValue ;
2022-03-17 15:53:45 +01:00
2022-12-16 18:17:31 +01:00
const auto DELTA = * PNOACCEL = = 1 ? Vector2D ( e - > unaccel_dx , e - > unaccel_dy ) : Vector2D ( e - > delta_x , e - > delta_y ) ;
2022-06-06 12:08:33 +02:00
2022-09-03 19:35:17 +02:00
if ( * PSENSTORAW = = 1 )
2022-12-16 18:17:31 +01:00
wlr_relative_pointer_manager_v1_send_relative_motion ( g_pCompositor - > m_sWLRRelPointerMgr , g_pCompositor - > m_sSeat . seat , ( uint64_t ) e - > time_msec * 1000 , DELTA . x * * PSENS ,
DELTA . y * * PSENS , e - > unaccel_dx * * PSENS , e - > unaccel_dy * * PSENS ) ;
2022-04-18 13:13:41 +02:00
else
2022-12-16 18:17:31 +01:00
wlr_relative_pointer_manager_v1_send_relative_motion ( g_pCompositor - > m_sWLRRelPointerMgr , g_pCompositor - > m_sSeat . seat , ( uint64_t ) e - > time_msec * 1000 , DELTA . x , DELTA . y ,
e - > unaccel_dx , e - > unaccel_dy ) ;
2022-04-17 21:40:04 +02:00
2022-09-03 19:35:17 +02:00
wlr_cursor_move ( g_pCompositor - > m_sWLRCursor , & e - > pointer - > base , DELTA . x * * PSENS , DELTA . y * * PSENS ) ;
2022-03-18 20:42:49 +01:00
2022-03-18 23:52:36 +01:00
mouseMoveUnified ( e - > time_msec ) ;
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
}
2022-03-24 15:57:46 +01:00
void CInputManager : : onMouseWarp ( wlr_pointer_motion_absolute_event * e ) {
wlr_cursor_warp_absolute ( g_pCompositor - > m_sWLRCursor , & e - > pointer - > base , e - > x , e - > y ) ;
2022-03-18 20:42:49 +01:00
2022-03-18 23:52:36 +01:00
mouseMoveUnified ( e - > time_msec ) ;
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 01:26:15 +01: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 12:33:36 +02:00
void CInputManager : : sendMotionEventsToFocused ( ) {
if ( ! g_pCompositor - > m_pLastFocus )
return ;
// todo: this sucks ass
const auto PWINDOW = g_pCompositor - > getWindowFromSurface ( g_pCompositor - > m_pLastFocus ) ;
const auto PLS = g_pCompositor - > getLayerSurfaceFromSurface ( g_pCompositor - > m_pLastFocus ) ;
timespec now ;
clock_gettime ( CLOCK_MONOTONIC , & now ) ;
const auto LOCAL = getMouseCoordsInternal ( ) - ( PWINDOW ? PWINDOW - > m_vRealPosition . goalv ( ) : ( PLS ? Vector2D { PLS - > geometry . x , PLS - > geometry . y } : Vector2D { } ) ) ;
wlr_seat_pointer_notify_enter ( g_pCompositor - > m_sSeat . seat , g_pCompositor - > m_pLastFocus , LOCAL . x , LOCAL . y ) ;
wlr_seat_pointer_notify_motion ( g_pCompositor - > m_sSeat . seat , now . tv_sec * 1000 + now . tv_nsec / 10000000 , LOCAL . x , LOCAL . y ) ;
}
2022-04-13 20:19:40 +02:00
void CInputManager : : mouseMoveUnified ( uint32_t time , bool refocus ) {
2023-02-18 23:35:31 +01:00
static auto * const PFOLLOWMOUSE = & g_pConfigManager - > getConfigValuePtr ( " input:follow_mouse " ) - > intValue ;
2023-04-25 17:00:34 +02:00
static auto * const PMOUSEREFOCUS = & g_pConfigManager - > getConfigValuePtr ( " input:mouse_refocus " ) - > intValue ;
2023-02-18 23:35:31 +01:00
static auto * const PMOUSEDPMS = & g_pConfigManager - > getConfigValuePtr ( " misc:mouse_move_enables_dpms " ) - > intValue ;
static auto * const PFOLLOWONDND = & g_pConfigManager - > getConfigValuePtr ( " misc:always_follow_on_dnd " ) - > intValue ;
static auto * const PFLOATBEHAVIOR = & g_pConfigManager - > getConfigValuePtr ( " input:float_switch_override_focus " ) - > intValue ;
static auto * const PMOUSEFOCUSMON = & g_pConfigManager - > getConfigValuePtr ( " misc:mouse_move_focuses_monitor " ) - > intValue ;
static auto * const PRESIZEONBORDER = & g_pConfigManager - > getConfigValuePtr ( " general:resize_on_border " ) - > intValue ;
static auto * const PRESIZECURSORICON = & g_pConfigManager - > getConfigValuePtr ( " general:hover_icon_on_border " ) - > intValue ;
2023-04-16 15:48:38 +02:00
static auto * const PZOOMFACTOR = & g_pConfigManager - > getConfigValuePtr ( " misc:cursor_zoom_factor " ) - > floatValue ;
2022-12-16 18:17:31 +01:00
2023-03-30 01:34:24 +02:00
const auto FOLLOWMOUSE = * PFOLLOWONDND & & m_sDrag . drag ? 1 : * PFOLLOWMOUSE ;
2022-12-16 18:17:31 +01:00
m_pFoundSurfaceToFocus = nullptr ;
m_pFoundLSToFocus = nullptr ;
m_pFoundWindowToFocus = nullptr ;
wlr_surface * foundSurface = nullptr ;
Vector2D surfaceCoords ;
Vector2D surfacePos = Vector2D ( - 1337 , - 1337 ) ;
CWindow * pFoundWindow = nullptr ;
2022-11-04 12:09:34 +01:00
SLayerSurface * pFoundLayerSurface = nullptr ;
2022-10-14 21:46:32 +02:00
2023-09-11 00:44:45 +02:00
if ( ! g_pCompositor - > m_bReadyToProcess | | g_pCompositor - > m_bIsShuttingDown | | g_pCompositor - > m_bUnsafeState )
2022-04-28 17:57:24 +02:00
return ;
2022-07-31 15:46:42 +02:00
if ( ! g_pCompositor - > m_bDPMSStateON & & * PMOUSEDPMS ) {
// enable dpms
g_pKeybindManager - > dpms ( " on " ) ;
}
2022-12-16 18:17:31 +01:00
Vector2D mouseCoords = getMouseCoordsInternal ( ) ;
2022-07-01 17:59:11 +02:00
const auto MOUSECOORDSFLOORED = mouseCoords . floor ( ) ;
2022-07-03 14:51:32 +02:00
if ( MOUSECOORDSFLOORED = = m_vLastCursorPosFloored & & ! refocus )
2022-07-01 17:59:11 +02:00
return ;
2023-10-21 15:52:43 +02:00
EMIT_HOOK_EVENT_CANCELLABLE ( " mouseMove " , MOUSECOORDSFLOORED ) ;
2023-08-13 17:46:16 +02:00
if ( time )
g_pCompositor - > notifyIdleActivity ( ) ;
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 12:18:07 +02:00
// this can happen if there are no displays hooked up to Hyprland
if ( PMONITOR = = nullptr )
return ;
2023-04-16 15:48:38 +02:00
if ( * PZOOMFACTOR ! = 1.f )
g_pHyprRenderer - > damageMonitor ( PMONITOR ) ;
2023-11-10 19:49:15 +01:00
if ( ! PMONITOR - > solitaryClient & & g_pHyprRenderer - > shouldRenderCursor ( ) & & PMONITOR - > output - > software_cursor_locks > 0 )
2023-09-28 22:48:33 +02:00
g_pCompositor - > scheduleFrameForMonitor ( PMONITOR ) ;
2023-07-09 00:44:26 +02:00
2023-07-04 12:05:25 +02:00
CWindow * forcedFocus = m_pForcedFocus ;
if ( ! forcedFocus )
forcedFocus = g_pCompositor - > getForceFocus ( ) ;
if ( forcedFocus ) {
pFoundWindow = forcedFocus ;
2023-05-31 20:59:38 +02:00
surfacePos = pFoundWindow - > m_vRealPosition . vec ( ) ;
2023-07-04 12:05:25 +02:00
foundSurface = pFoundWindow - > m_pWLSurface . wlr ( ) ;
2023-05-31 20:59:38 +02:00
}
2023-04-25 22:50:24 +02:00
// constraints
// All constraints TODO: multiple mice?
if ( g_pCompositor - > m_sSeat . mouse & & g_pCompositor - > m_sSeat . mouse - > currentConstraint & & ! g_pCompositor - > m_sSeat . exclusiveClient & & ! g_pSessionLockManager - > isSessionLocked ( ) ) {
// XWayland windows sometimes issue constraints weirdly.
// TODO: We probably should search their parent. wlr_xwayland_surface->parent
const auto CONSTRAINTWINDOW = g_pCompositor - > getConstraintWindow ( g_pCompositor - > m_sSeat . mouse ) ;
const auto PCONSTRAINT = constraintFromWlr ( g_pCompositor - > m_sSeat . mouse - > currentConstraint ) ;
if ( ! CONSTRAINTWINDOW | | ! PCONSTRAINT ) {
unconstrainMouse ( ) ;
} else {
// Native Wayland apps know how 2 constrain themselves.
// XWayland, we just have to accept them. Might cause issues, but thats XWayland for ya.
2023-09-20 17:47:05 +02:00
const auto CONSTRAINTPOS = PCONSTRAINT - > getLogicConstraintPos ( ) ;
const auto CONSTRAINTSIZE = PCONSTRAINT - > getLogicConstraintSize ( ) ;
2023-04-25 22:50:24 +02:00
if ( g_pCompositor - > m_sSeat . mouse - > currentConstraint - > type = = WLR_POINTER_CONSTRAINT_V1_LOCKED ) {
// we just snap the cursor to where it should be.
2023-09-20 17:47:05 +02:00
if ( PCONSTRAINT - > hintSet )
wlr_cursor_warp_closest ( g_pCompositor - > m_sWLRCursor , g_pCompositor - > m_sSeat . mouse - > mouse , CONSTRAINTPOS . x + PCONSTRAINT - > positionHint . x ,
CONSTRAINTPOS . y + PCONSTRAINT - > positionHint . y ) ;
2023-04-25 22:50:24 +02:00
return ; // don't process anything else, the cursor is locked. The surface should not receive any further events.
// these are usually FPS games. They will use the relative motion.
} else {
// we restrict the cursor to the confined region
2023-09-20 17:47:05 +02:00
const auto REGION = PCONSTRAINT - > getLogicCoordsRegion ( ) ;
if ( ! REGION . containsPoint ( mouseCoords ) ) {
2023-04-25 22:50:24 +02:00
if ( g_pCompositor - > m_sSeat . mouse - > constraintActive ) {
2023-09-20 17:47:05 +02:00
const auto CLOSEST = REGION . closestPoint ( mouseCoords ) ;
2023-09-04 17:34:19 +02:00
wlr_cursor_warp_closest ( g_pCompositor - > m_sWLRCursor , NULL , CLOSEST . x , CLOSEST . y ) ;
2023-04-25 22:50:24 +02:00
mouseCoords = getMouseCoordsInternal ( ) ;
}
} else {
if ( ( ! CONSTRAINTWINDOW - > m_bIsX11 & & PMONITOR & & CONSTRAINTWINDOW - > m_iWorkspaceID = = PMONITOR - > activeWorkspace ) | | ( CONSTRAINTWINDOW - > m_bIsX11 ) ) {
g_pCompositor - > m_sSeat . mouse - > constraintActive = true ;
}
}
}
if ( CONSTRAINTWINDOW - > m_bIsX11 ) {
foundSurface = CONSTRAINTWINDOW - > m_pWLSurface . wlr ( ) ;
surfacePos = CONSTRAINTWINDOW - > m_vRealPosition . vec ( ) ;
} else {
g_pCompositor - > vectorWindowToSurface ( mouseCoords , CONSTRAINTWINDOW , surfaceCoords ) ;
}
pFoundWindow = CONSTRAINTWINDOW ;
}
}
2022-03-31 17:25:23 +02:00
// update stuff
updateDragIcon ( ) ;
2023-10-26 19:54:07 +02:00
if ( ! m_sDrag . drag & & ! m_lCurrentlyHeldButtons . empty ( ) & & g_pCompositor - > m_pLastFocus & & m_pLastMouseSurface ) {
2023-04-02 14:30:45 +02:00
if ( m_bLastFocusOnLS ) {
2023-09-23 18:20:39 +02:00
foundSurface = m_pLastMouseSurface ;
2023-04-02 14:30:45 +02:00
pFoundLayerSurface = g_pCompositor - > getLayerSurfaceFromSurface ( foundSurface ) ;
if ( pFoundLayerSurface ) {
surfacePos = g_pCompositor - > getLayerSurfaceFromSurface ( foundSurface ) - > position ;
m_bFocusHeldByButtons = true ;
m_bRefocusHeldByButtons = refocus ;
} else {
// ?
foundSurface = nullptr ;
pFoundLayerSurface = nullptr ;
}
} else if ( g_pCompositor - > m_pLastWindow ) {
2023-09-23 02:21:59 +02:00
foundSurface = m_pLastMouseSurface ;
2023-04-02 14:42:57 +02:00
pFoundWindow = g_pCompositor - > m_pLastWindow ;
2023-04-02 14:30:45 +02:00
2023-09-23 02:21:59 +02:00
surfaceCoords = g_pCompositor - > vectorToSurfaceLocal ( mouseCoords , pFoundWindow , foundSurface ) ;
2023-04-02 14:30:45 +02:00
m_bFocusHeldByButtons = true ;
m_bRefocusHeldByButtons = refocus ;
}
}
2022-04-13 20:19:40 +02:00
g_pLayoutManager - > getCurrentLayout ( ) - > onMouseMove ( getMouseCoordsInternal ( ) ) ;
2022-04-01 23:31:12 +02:00
2023-09-01 17:10:03 +02:00
if ( PMONITOR & & PMONITOR ! = g_pCompositor - > m_pLastMonitor & & ( * PMOUSEFOCUSMON | | refocus ) )
2022-11-19 17:41:36 +01:00
g_pCompositor - > setActiveMonitor ( PMONITOR ) ;
2022-03-31 17:25:23 +02:00
2023-02-03 12:58:55 +01:00
if ( g_pSessionLockManager - > isSessionLocked ( ) ) {
const auto PSLS = PMONITOR ? g_pSessionLockManager - > getSessionLockSurfaceForMonitor ( PMONITOR - > ID ) : nullptr ;
if ( ! PSLS )
return ;
foundSurface = PSLS - > pWlrLockSurface - > surface ;
surfacePos = PMONITOR - > vecPosition ;
}
2023-04-25 22:50:24 +02:00
// overlay is 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
2022-09-19 11:23:13 +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_TOP ] , & surfaceCoords , & pFoundLayerSurface ) ;
2022-09-19 11:23:13 +02:00
2022-04-25 21:49:45 +02:00
// then, we check if the workspace doesnt have a fullscreen window
2022-03-21 19:18:33 +01:00
const auto PWORKSPACE = g_pCompositor - > getWorkspaceByID ( PMONITOR - > activeWorkspace ) ;
2022-05-31 14:01:00 +02:00
if ( PWORKSPACE - > m_bHasFullscreenWindow & & ! foundSurface & & PWORKSPACE - > m_efFullscreenMode = = FULLSCREEN_FULL ) {
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 ;
}
2023-09-22 00:58:54 +02:00
const auto PWINDOWIDEAL = g_pCompositor - > vectorToWindowIdeal ( mouseCoords ) ;
if ( PWINDOWIDEAL & &
( ( PWINDOWIDEAL - > m_bIsFloating & & PWINDOWIDEAL - > m_bCreatedOverFullscreen ) /* floating over fullscreen */
| | ( PMONITOR - > specialWorkspaceID = = PWINDOWIDEAL - > m_iWorkspaceID ) /* on an open special workspace */ ) )
pFoundWindow = PWINDOWIDEAL ;
2022-10-30 13:28:37 +01:00
if ( ! pFoundWindow - > m_bIsX11 ) {
foundSurface = g_pCompositor - > vectorWindowToSurface ( mouseCoords , pFoundWindow , surfaceCoords ) ;
2022-12-16 18:17:31 +01:00
surfacePos = Vector2D ( - 1337 , - 1337 ) ;
2022-10-30 13:28:37 +01:00
} else {
2023-03-20 16:00:58 +01:00
foundSurface = pFoundWindow - > m_pWLSurface . wlr ( ) ;
2022-12-16 18:17:31 +01:00
surfacePos = pFoundWindow - > m_vRealPosition . vec ( ) ;
2022-10-30 13:28:37 +01: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 ) {
2022-07-06 14:58:46 +02:00
if ( PWORKSPACE - > m_bHasFullscreenWindow & & PWORKSPACE - > m_efFullscreenMode = = FULLSCREEN_MAXIMIZED ) {
2022-11-27 23:42:22 +01:00
if ( PMONITOR - > specialWorkspaceID ) {
2022-07-06 14:58:46 +02:00
pFoundWindow = g_pCompositor - > vectorToWindowIdeal ( mouseCoords ) ;
2022-11-27 23:42:22 +01:00
if ( pFoundWindow & & ! g_pCompositor - > isWorkspaceSpecial ( pFoundWindow - > m_iWorkspaceID ) ) {
2022-07-06 14:58:46 +02:00
pFoundWindow = g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) ;
}
} else {
2022-07-13 18:33:36 +02:00
pFoundWindow = g_pCompositor - > vectorToWindowIdeal ( mouseCoords ) ;
if ( ! ( pFoundWindow & & pFoundWindow - > m_bIsFloating & & pFoundWindow - > m_bCreatedOverFullscreen ) )
pFoundWindow = g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) ;
2022-07-06 14:58:46 +02:00
}
2022-08-19 17:25:07 +02:00
} else {
2022-06-29 14:44:24 +02:00
pFoundWindow = g_pCompositor - > vectorToWindowIdeal ( mouseCoords ) ;
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 ) ;
} else {
2023-03-20 16:00:58 +01:00
foundSurface = pFoundWindow - > m_pWLSurface . wlr ( ) ;
2022-12-16 18:17:31 +01:00
surfacePos = pFoundWindow - > m_vRealPosition . vec ( ) ;
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
2022-08-28 22:45:05 +02:00
g_pCompositor - > scheduleFrameForMonitor ( g_pCompositor - > m_pLastMonitor ) ;
2022-03-20 14:36:55 +01:00
if ( ! foundSurface ) {
2022-08-28 22:45:05 +02:00
if ( ! m_bEmptyFocusCursorSet ) {
2023-02-22 00:57:38 +01:00
m_eBorderIconDirection = BORDERICON_NONE ;
2023-01-26 11:39:06 +01:00
if ( g_pHyprRenderer - > m_bHasARenderedCursor ) {
// TODO: maybe wrap?
if ( m_ecbClickBehavior = = CLICKMODE_KILL )
2023-10-29 19:09:05 +01:00
setCursorImageOverride ( " crosshair " ) ;
2023-01-26 11:39:06 +01:00
else
2023-10-29 19:09:05 +01:00
setCursorImageOverride ( " left_ptr " ) ;
2023-01-26 11:39:06 +01:00
}
2022-12-16 18:17:31 +01:00
2022-08-28 22:45:05 +02:00
m_bEmptyFocusCursorSet = true ;
}
2022-03-18 23:52:36 +01:00
2022-03-22 18:29:13 +01:00
wlr_seat_pointer_clear_focus ( g_pCompositor - > m_sSeat . seat ) ;
2023-10-26 19:54:07 +02:00
m_pLastMouseSurface = nullptr ;
2022-03-18 23:52:36 +01:00
2023-10-06 02:11:47 +02:00
if ( refocus | | ! g_pCompositor - > m_pLastWindow ) // 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.
wlr_box geom ;
wlr_xdg_surface_get_geometry ( pFoundWindow - > m_uSurface . xdg , & geom ) ;
surfaceLocal = mouseCoords - surfacePos + Vector2D ( geom . x , geom . y ) ;
}
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 ;
2023-10-23 00:32:37 +02:00
if ( ! refocus & & g_pCompositor - > m_pLastFocus ) {
2022-08-10 17:46:01 +02:00
const auto PLS = g_pCompositor - > getLayerSurfaceFromSurface ( g_pCompositor - > m_pLastFocus ) ;
2023-10-23 00:32:37 +02:00
if ( PLS & & PLS - > layerSurface - > current . keyboard_interactive = = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE )
2022-08-10 17:46:01 +02:00
allowKeyboardRefocus = false ;
}
2022-10-14 21:46:32 +02:00
// set the values for use
if ( refocus ) {
2022-12-16 18:17:31 +01:00
m_pFoundLSToFocus = pFoundLayerSurface ;
m_pFoundWindowToFocus = pFoundWindow ;
2022-10-14 21:46:32 +02:00
m_pFoundSurfaceToFocus = foundSurface ;
}
2023-05-01 16:15:55 +02:00
if ( currentlyDraggedWindow & & pFoundWindow ! = currentlyDraggedWindow ) {
wlr_seat_pointer_notify_enter ( g_pCompositor - > m_sSeat . seat , foundSurface , surfaceLocal . x , surfaceLocal . y ) ;
wlr_seat_pointer_notify_motion ( g_pCompositor - > m_sSeat . seat , time , surfaceLocal . x , surfaceLocal . y ) ;
return ;
}
2023-10-29 19:09:05 +01:00
if ( pFoundWindow & & foundSurface = = pFoundWindow - > m_pWLSurface . wlr ( ) & & ! m_bCursorImageOverridden ) {
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 ( ) ;
}
2022-04-13 20:19:40 +02:00
if ( pFoundWindow ) {
2023-02-22 00:57:38 +01:00
// change cursor icon if hovering over border
2023-04-21 14:36:55 +02:00
if ( * PRESIZEONBORDER & & * PRESIZECURSORICON ) {
if ( ! pFoundWindow - > m_bIsFullscreen & & ! pFoundWindow - > hasPopupAt ( mouseCoords ) ) {
setCursorIconOnBorder ( pFoundWindow ) ;
} else if ( m_eBorderIconDirection ! = BORDERICON_NONE ) {
unsetCursorImage ( ) ;
}
2023-02-18 23:35:31 +01:00
}
2023-03-30 01:34:24 +02:00
if ( FOLLOWMOUSE ! = 1 & & ! refocus ) {
2022-12-16 18:17:31 +01:00
if ( pFoundWindow ! = g_pCompositor - > m_pLastWindow & & g_pCompositor - > m_pLastWindow & &
( ( 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 01:34:24 +02:00
if ( FOLLOWMOUSE ! = 3 & & allowKeyboardRefocus )
2022-08-01 18:42:11 +02:00
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
2023-09-23 02:21:59 +02:00
m_pLastMouseSurface = foundSurface ;
2022-04-13 20:19:40 +02:00
wlr_seat_pointer_notify_enter ( g_pCompositor - > m_sSeat . seat , foundSurface , surfaceLocal . x , surfaceLocal . y ) ;
2023-03-30 01:34:24 +02:00
} else if ( FOLLOWMOUSE = = 2 | | FOLLOWMOUSE = = 3 ) {
2023-09-23 02:21:59 +02:00
m_pLastMouseSurface = foundSurface ;
2022-06-12 02:14:22 +02:00
wlr_seat_pointer_notify_enter ( g_pCompositor - > m_sSeat . seat , foundSurface , surfaceLocal . x , surfaceLocal . y ) ;
}
2022-07-19 14:05:12 +02:00
2022-09-04 18:42:11 +02:00
if ( pFoundWindow = = g_pCompositor - > m_pLastWindow ) {
2023-10-26 23:21:13 +02:00
m_pLastMouseSurface = foundSurface ;
wlr_seat_pointer_notify_enter ( g_pCompositor - > m_sSeat . seat , foundSurface , surfaceLocal . x , surfaceLocal . y ) ;
2022-07-19 14:05:12 +02:00
}
2023-03-30 01:34:24 +02:00
if ( FOLLOWMOUSE ! = 0 | | pFoundWindow = = g_pCompositor - > m_pLastWindow )
2022-09-18 13:35:05 +02:00
wlr_seat_pointer_notify_motion ( g_pCompositor - > m_sSeat . seat , time , surfaceLocal . x , surfaceLocal . y ) ;
2022-09-25 20:07:48 +02:00
2022-09-04 18:42:11 +02:00
m_bLastFocusOnLS = false ;
2022-12-16 18:17:31 +01:00
return ; // don't enter any new surfaces
2022-04-13 20:19:40 +02:00
} else {
2023-04-25 17:00:34 +02:00
if ( ( ( FOLLOWMOUSE ! = 3 & & allowKeyboardRefocus ) & & ( * PMOUSEREFOCUS | | m_pLastMouseFocus ! = pFoundWindow ) ) | | refocus ) {
m_pLastMouseFocus = pFoundWindow ;
2022-08-01 18:42:11 +02:00
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
2023-04-25 17:00:34 +02: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 {
2023-02-22 00:57:38 +01:00
if ( * PRESIZEONBORDER & & * PRESIZECURSORICON & & m_eBorderIconDirection ! = BORDERICON_NONE ) {
m_eBorderIconDirection = BORDERICON_NONE ;
unsetCursorImage ( ) ;
}
2023-04-09 20:53:31 +02:00
if ( pFoundLayerSurface & &
2023-10-23 00:32:37 +02:00
( pFoundLayerSurface - > layerSurface - > current . keyboard_interactive ! = ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE | |
( pFoundLayerSurface - > layer > = ZWLR_LAYER_SHELL_V1_LAYER_TOP & & ! g_pCompositor - > m_pLastWindow ) ) & &
2023-03-30 01:34:24 +02:00
FOLLOWMOUSE ! = 3 & & allowKeyboardRefocus ) {
2022-08-10 17:46:01 +02:00
g_pCompositor - > focusSurface ( foundSurface ) ;
2022-08-19 17:29:16 +02:00
}
2022-12-10 16:15:40 +01:00
if ( pFoundLayerSurface )
m_bLastFocusOnLS = true ;
2022-08-10 17:46:01 +02:00
}
2022-03-22 21:59:14 +01:00
2023-09-23 02:21:59 +02:00
m_pLastMouseSurface = foundSurface ;
2022-04-05 18:29:58 +02:00
wlr_seat_pointer_notify_enter ( g_pCompositor - > m_sSeat . seat , foundSurface , surfaceLocal . x , surfaceLocal . y ) ;
wlr_seat_pointer_notify_motion ( g_pCompositor - > m_sSeat . seat , time , surfaceLocal . x , surfaceLocal . y ) ;
2022-03-18 20:42:49 +01:00
}
2022-03-24 15:57:46 +01:00
void CInputManager : : onMouseButton ( wlr_pointer_button_event * e ) {
2023-10-21 15:52:43 +02:00
EMIT_HOOK_EVENT_CANCELLABLE ( " mouseButton " , e ) ;
2022-03-18 20:42:49 +01:00
2023-10-21 15:52:43 +02:00
g_pCompositor - > notifyIdleActivity ( ) ;
2023-02-28 22:45:57 +01:00
2022-06-24 23:27:02 +02:00
m_tmrLastCursorMovement . reset ( ) ;
2023-01-11 18:38:54 +01:00
if ( e - > state = = WLR_BUTTON_PRESSED ) {
m_lCurrentlyHeldButtons . push_back ( e - > button ) ;
} else {
if ( std : : find_if ( m_lCurrentlyHeldButtons . begin ( ) , m_lCurrentlyHeldButtons . end ( ) , [ & ] ( const auto & other ) { return other = = e - > button ; } ) = = m_lCurrentlyHeldButtons . end ( ) )
return ;
std : : erase_if ( m_lCurrentlyHeldButtons , [ & ] ( const auto & other ) { return other = = e - > button ; } ) ;
}
2022-06-27 13:42:20 +02:00
switch ( m_ecbClickBehavior ) {
2022-12-16 18:17:31 +01: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 14:30:45 +02:00
if ( m_bFocusHeldByButtons & & m_lCurrentlyHeldButtons . empty ( ) & & e - > state = = WLR_BUTTON_RELEASED ) {
if ( m_bRefocusHeldByButtons )
refocus ( ) ;
else
simulateMouseMovement ( ) ;
m_bFocusHeldByButtons = false ;
m_bRefocusHeldByButtons = false ;
}
2022-06-27 13:42:20 +02:00
}
void CInputManager : : processMouseRequest ( wlr_seat_pointer_request_set_cursor_event * e ) {
2023-07-24 18:50:17 +02:00
if ( ! e - > surface )
2022-06-27 13:42:20 +02:00
g_pHyprRenderer - > m_bWindowRequestedCursorHide = true ;
2023-07-24 18:50:17 +02:00
else
2022-06-27 13:42:20 +02:00
g_pHyprRenderer - > m_bWindowRequestedCursorHide = false ;
2023-09-29 18:51:07 +02:00
if ( ! cursorImageUnlocked ( ) | | ! g_pHyprRenderer - > m_bHasARenderedCursor )
2022-11-15 11:39:05 +01:00
return ;
2022-06-27 13:42:20 +02:00
2023-10-29 19:09:05 +01:00
if ( e - > seat_client = = g_pCompositor - > m_sSeat . seat - > pointer_state . focused_client ) {
m_sCursorSurfaceInfo . wlSurface . unassign ( ) ;
if ( e - > surface ) {
m_sCursorSurfaceInfo . wlSurface . assign ( e - > surface ) ;
m_sCursorSurfaceInfo . vHotspot = { e - > hotspot_x , e - > hotspot_y } ;
m_sCursorSurfaceInfo . hidden = false ;
} else {
m_sCursorSurfaceInfo . vHotspot = { } ;
m_sCursorSurfaceInfo . hidden = true ;
}
2023-03-01 00:06:46 +01:00
2023-10-29 19:09:05 +01:00
m_sCursorSurfaceInfo . name = " " ;
2023-03-01 00:06:46 +01:00
2023-10-29 19:09:05 +01:00
m_sCursorSurfaceInfo . inUse = true ;
2023-09-29 18:51:07 +02:00
g_pHyprRenderer - > setCursorSurface ( e - > surface , e - > hotspot_x , e - > hotspot_y ) ;
2023-10-29 19:09:05 +01:00
}
2022-06-27 13:42:20 +02:00
}
2023-07-24 18:50:17 +02:00
void CInputManager : : processMouseRequest ( wlr_cursor_shape_manager_v1_request_set_shape_event * e ) {
2023-09-29 18:51:07 +02:00
if ( ! g_pHyprRenderer - > m_bHasARenderedCursor | | ! cursorImageUnlocked ( ) )
2023-07-24 18:50:17 +02:00
return ;
2023-10-29 19:09:05 +01:00
if ( e - > seat_client = = g_pCompositor - > m_sSeat . seat - > pointer_state . focused_client ) {
m_sCursorSurfaceInfo . wlSurface . unassign ( ) ;
m_sCursorSurfaceInfo . vHotspot = { } ;
m_sCursorSurfaceInfo . name = wlr_cursor_shape_v1_name ( e - > shape ) ;
m_sCursorSurfaceInfo . hidden = false ;
m_sCursorSurfaceInfo . inUse = true ;
g_pHyprRenderer - > setCursorFromName ( m_sCursorSurfaceInfo . name ) ;
}
}
void CInputManager : : restoreCursorIconToApp ( ) {
if ( m_sCursorSurfaceInfo . inUse )
return ;
if ( m_sCursorSurfaceInfo . hidden ) {
g_pHyprRenderer - > setCursorSurface ( nullptr , 0 , 0 ) ;
return ;
}
if ( m_sCursorSurfaceInfo . name . empty ( ) ) {
if ( m_sCursorSurfaceInfo . wlSurface . exists ( ) )
g_pHyprRenderer - > setCursorSurface ( m_sCursorSurfaceInfo . wlSurface . wlr ( ) , m_sCursorSurfaceInfo . vHotspot . x , m_sCursorSurfaceInfo . vHotspot . y ) ;
} 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 ( ) {
2023-09-29 18:51:07 +02:00
if ( ! g_pHyprRenderer - > m_bHasARenderedCursor )
2023-07-24 18:50:17 +02:00
return false ;
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 18:51:07 +02: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 18:51:07 +02:00
g_pHyprRenderer - > setCursorFromName ( " crosshair " ) ;
2022-06-27 13:42:20 +02:00
break ;
2022-12-16 18:17:31 +01:00
default : break ;
2022-09-25 20:07:48 +02:00
}
2022-06-27 13:42:20 +02:00
}
void CInputManager : : processMouseDownNormal ( wlr_pointer_button_event * e ) {
2022-12-16 18:17:31 +01:00
2022-07-26 14:50:21 +02:00
// notify the keybind manager
2023-02-18 23:35:31 +01:00
static auto * const PPASSMOUSE = & g_pConfigManager - > getConfigValuePtr ( " binds:pass_mouse_when_bound " ) - > intValue ;
const auto PASS = g_pKeybindManager - > onMouseEvent ( e ) ;
static auto * const PFOLLOWMOUSE = & g_pConfigManager - > getConfigValuePtr ( " input:follow_mouse " ) - > intValue ;
static auto * const PRESIZEONBORDER = & g_pConfigManager - > getConfigValuePtr ( " general:resize_on_border " ) - > intValue ;
2022-07-26 14:50:21 +02:00
if ( ! PASS & & ! * PPASSMOUSE )
return ;
2023-08-30 17:39:22 +02:00
const auto mouseCoords = g_pInputManager - > getMouseCoordsInternal ( ) ;
const auto w = g_pCompositor - > vectorToWindowIdeal ( mouseCoords ) ;
2023-10-29 21:14:47 +01:00
if ( w & & ! w - > m_bIsFullscreen & & ! w - > hasPopupAt ( mouseCoords ) ) {
for ( auto & wd : w - > m_dWindowDecorations ) {
2023-11-04 14:10:52 +01:00
if ( ! ( wd - > getDecorationFlags ( ) & DECORATION_ALLOWS_MOUSE_INPUT ) )
2023-10-29 21:14:47 +01:00
continue ;
2023-11-11 15:37:17 +01:00
if ( g_pDecorationPositioner - > getWindowDecorationBox ( wd . get ( ) ) . containsPoint ( mouseCoords ) ) {
2023-10-29 21:14:47 +01:00
wd - > onMouseButtonOnDeco ( mouseCoords , e ) ;
return ;
2023-08-30 17:39:22 +02:00
}
}
}
2023-02-18 23:35:31 +01:00
// clicking on border triggers resize
// TODO detect click on LS properly
if ( * PRESIZEONBORDER & & ! m_bLastFocusOnLS ) {
if ( w & & ! w - > m_bIsFullscreen ) {
2023-11-04 18:03:05 +01:00
const CBox real = { w - > m_vRealPosition . vec ( ) . x , w - > m_vRealPosition . vec ( ) . y , w - > m_vRealSize . vec ( ) . x , w - > m_vRealSize . vec ( ) . y } ;
if ( ( ! 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 ;
}
}
}
2022-03-18 20:42:49 +01:00
switch ( e - > state ) {
case WLR_BUTTON_PRESSED :
2022-11-08 21:28:41 +01:00
if ( * PFOLLOWMOUSE = = 3 ) // don't refocus on full loose
break ;
2023-09-23 02:21:59 +02:00
if ( ( ! g_pCompositor - > m_sSeat . mouse | | ! g_pCompositor - > m_sSeat . mouse - > currentConstraint ) /* No constraints */
2023-09-23 14:30:53 +02:00
& & ( w & & g_pCompositor - > m_pLastWindow ! = w ) /* window should change */ ) {
2023-04-04 00:09:44 +02: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
2022-10-14 21:46:32 +02:00
if ( g_pCompositor - > m_pLastWindow & & g_pCompositor - > m_pLastWindow - > m_bIsFloating )
2023-09-21 23:18:26 +02:00
g_pCompositor - > changeWindowZOrder ( g_pCompositor - > m_pLastWindow , true ) ;
2022-04-04 16:28:43 +02:00
2022-03-18 20:42:49 +01:00
break ;
2022-12-16 18:17:31 +01:00
case WLR_BUTTON_RELEASED : break ;
2022-03-18 20:42:49 +01:00
}
// notify app if we didnt handle it
2022-03-22 21:59:14 +01:00
if ( g_pCompositor - > doesSeatAcceptInput ( g_pCompositor - > m_pLastFocus ) ) {
2022-03-22 18:29:13 +01:00
wlr_seat_pointer_notify_button ( g_pCompositor - > m_sSeat . seat , e - > time_msec , e - > button , e - > state ) ;
2022-03-22 21:59:14 +01:00
}
2022-06-27 13:42:20 +02:00
}
void CInputManager : : processMouseDownKill ( wlr_pointer_button_event * e ) {
switch ( e - > state ) {
case WLR_BUTTON_PRESSED : {
2022-12-29 11:52:46 +01:00
const auto PWINDOW = g_pCompositor - > vectorToWindowIdeal ( getMouseCoordsInternal ( ) ) ;
2022-06-27 13:42:20 +02:00
2022-10-14 21:46:32 +02: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 ;
}
2022-12-16 18:17:31 +01:00
case WLR_BUTTON_RELEASED : break ;
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
}
2022-06-20 21:47:28 +02:00
void CInputManager : : onMouseWheel ( wlr_pointer_axis_event * e ) {
2023-08-30 17:39:22 +02:00
static auto * const PSCROLLFACTOR = & g_pConfigManager - > getConfigValuePtr ( " input:touchpad:scroll_factor " ) - > floatValue ;
2023-10-10 18:42:45 +02:00
static auto * const PGROUPBARSCROLLING = & g_pConfigManager - > getConfigValuePtr ( " group:groupbar:scrolling " ) - > intValue ;
2022-10-06 21:20:10 +02:00
2022-12-16 18:17:31 +01:00
auto factor = ( * PSCROLLFACTOR < = 0.f | | e - > source ! = WLR_AXIS_SOURCE_FINGER ? 1.f : * PSCROLLFACTOR ) ;
2022-10-06 21:20:10 +02:00
2022-12-16 18:17:31 +01:00
bool passEvent = g_pKeybindManager - > onAxisEvent ( e ) ;
2022-06-20 21:47:28 +02:00
2023-07-13 18:05:34 +02:00
g_pCompositor - > notifyIdleActivity ( ) ;
2022-06-20 21:47:28 +02:00
2023-08-30 17:39:22 +02:00
const auto MOUSECOORDS = g_pInputManager - > getMouseCoordsInternal ( ) ;
const auto pWindow = g_pCompositor - > vectorToWindowIdeal ( MOUSECOORDS ) ;
if ( * PGROUPBARSCROLLING & & pWindow & & ! pWindow - > m_bIsFullscreen & & ! pWindow - > hasPopupAt ( MOUSECOORDS ) & & pWindow - > m_sGroupData . pNextWindow ) {
2023-11-11 15:37:17 +01:00
const CBox box = g_pDecorationPositioner - > getWindowDecorationBox ( pWindow - > getDecorationByType ( DECORATION_GROUPBAR ) ) ;
2023-11-04 18:03:05 +01:00
if ( box . containsPoint ( MOUSECOORDS ) ) {
2023-08-30 17:39:22 +02:00
if ( e - > delta > 0 )
pWindow - > setGroupCurrent ( pWindow - > m_sGroupData . pNextWindow ) ;
else
pWindow - > setGroupCurrent ( pWindow - > getGroupPrevious ( ) ) ;
return ;
}
}
2023-07-25 11:49:31 +02:00
if ( passEvent )
2022-12-16 18:17:31 +01:00
wlr_seat_pointer_notify_axis ( g_pCompositor - > m_sSeat . seat , e - > time_msec , e - > orientation , factor * e - > delta , std : : round ( factor * e - > delta_discrete ) , e - > source ) ;
2022-06-20 21:47:28 +02:00
}
2022-03-17 19:03:15 +01:00
Vector2D CInputManager : : getMouseCoordsInternal ( ) {
2022-03-19 20:30:21 +01:00
return Vector2D ( g_pCompositor - > m_sWLRCursor - > x , g_pCompositor - > m_sWLRCursor - > y ) ;
2022-03-17 20:55:04 +01:00
}
void CInputManager : : newKeyboard ( wlr_input_device * keyboard ) {
2022-06-28 15:40:14 +02:00
const auto PNEWKEYBOARD = & m_lKeyboards . emplace_back ( ) ;
2022-03-17 20:55:04 +01:00
PNEWKEYBOARD - > keyboard = keyboard ;
2022-06-30 21:26:00 +02:00
try {
2022-12-03 21:36:52 +01:00
PNEWKEYBOARD - > name = getNameForNewDevice ( keyboard - > name ) ;
2022-06-30 21:26:00 +02:00
} catch ( std : : exception & e ) {
2022-12-16 18:17:31 +01:00
Debug : : log ( ERR , " Keyboard had no name??? " ) ; // logic error
2022-06-30 21:26:00 +02:00
}
2022-03-17 20:55:04 +01:00
2022-07-11 23:09:35 +02:00
PNEWKEYBOARD - > hyprListener_keyboardMod . initCallback ( & wlr_keyboard_from_input_device ( keyboard ) - > events . modifiers , & Events : : listener_keyboardMod , PNEWKEYBOARD , " Keyboard " ) ;
PNEWKEYBOARD - > hyprListener_keyboardKey . initCallback ( & wlr_keyboard_from_input_device ( keyboard ) - > events . key , & Events : : listener_keyboardKey , PNEWKEYBOARD , " Keyboard " ) ;
2022-03-28 22:31:39 +02:00
PNEWKEYBOARD - > hyprListener_keyboardDestroy . initCallback ( & keyboard - > events . destroy , & Events : : listener_keyboardDestroy , PNEWKEYBOARD , " Keyboard " ) ;
2022-03-17 20:55:04 +01:00
2022-12-16 18:17:31 +01:00
PNEWKEYBOARD - > hyprListener_keyboardKeymap . initCallback (
& wlr_keyboard_from_input_device ( keyboard ) - > events . keymap ,
[ & ] ( void * owner , void * data ) {
const auto PKEYBOARD = ( SKeyboard * ) owner ;
2023-02-19 21:54:53 +01:00
const auto LAYOUT = getActiveLayoutForKeyboard ( PKEYBOARD ) ;
2022-09-25 20:07:48 +02:00
2023-07-06 15:23:11 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , PKEYBOARD - > name + " , " + LAYOUT } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < void * > { PKEYBOARD , ( void * ) & LAYOUT } ) ) ;
2022-12-16 18:17:31 +01:00
} ,
PNEWKEYBOARD , " Keyboard " ) ;
2022-08-18 17:17:33 +02:00
2022-08-18 17:50:32 +02:00
disableAllKeyboards ( false ) ;
2022-09-25 20:07:48 +02:00
2022-06-03 18:59:39 +02:00
m_pActiveKeyboard = PNEWKEYBOARD ;
2022-08-18 17:17:33 +02:00
PNEWKEYBOARD - > active = true ;
2022-06-25 11:50:09 +02:00
applyConfigToKeyboard ( PNEWKEYBOARD ) ;
2022-06-03 19:15:39 +02:00
2022-07-11 23:09:35 +02:00
wlr_seat_set_keyboard ( g_pCompositor - > m_sSeat . seat , wlr_keyboard_from_input_device ( keyboard ) ) ;
2022-03-19 11:27:19 +01:00
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " New keyboard created, pointers Hypr: {:x} and WLR: {:x} " , ( uintptr_t ) PNEWKEYBOARD , ( uintptr_t ) keyboard ) ;
2022-03-24 21:05:34 +01:00
}
2022-08-05 16:21:08 +02:00
void CInputManager : : newVirtualKeyboard ( wlr_input_device * keyboard ) {
const auto PNEWKEYBOARD = & m_lKeyboards . emplace_back ( ) ;
2022-12-16 18:17:31 +01:00
PNEWKEYBOARD - > keyboard = keyboard ;
2022-08-05 16:21:08 +02:00
PNEWKEYBOARD - > isVirtual = true ;
try {
2022-12-03 21:36:52 +01:00
PNEWKEYBOARD - > name = getNameForNewDevice ( keyboard - > name ) ;
2022-08-05 16:21:08 +02:00
} catch ( std : : exception & e ) {
2022-12-16 18:17:31 +01:00
Debug : : log ( ERR , " Keyboard had no name??? " ) ; // logic error
2022-08-05 16:21:08 +02:00
}
PNEWKEYBOARD - > hyprListener_keyboardMod . initCallback ( & wlr_keyboard_from_input_device ( keyboard ) - > events . modifiers , & Events : : listener_keyboardMod , PNEWKEYBOARD , " Keyboard " ) ;
PNEWKEYBOARD - > hyprListener_keyboardKey . initCallback ( & wlr_keyboard_from_input_device ( keyboard ) - > events . key , & Events : : listener_keyboardKey , PNEWKEYBOARD , " Keyboard " ) ;
PNEWKEYBOARD - > hyprListener_keyboardDestroy . initCallback ( & keyboard - > events . destroy , & Events : : listener_keyboardDestroy , PNEWKEYBOARD , " Keyboard " ) ;
2022-12-16 18:17:31 +01:00
PNEWKEYBOARD - > hyprListener_keyboardKeymap . initCallback (
& wlr_keyboard_from_input_device ( keyboard ) - > events . keymap ,
[ & ] ( void * owner , void * data ) {
const auto PKEYBOARD = ( SKeyboard * ) owner ;
2023-02-19 21:54:53 +01:00
const auto LAYOUT = getActiveLayoutForKeyboard ( PKEYBOARD ) ;
2022-09-25 20:07:48 +02:00
2023-07-06 15:23:11 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , PKEYBOARD - > name + " , " + LAYOUT } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < void * > { PKEYBOARD , ( void * ) & LAYOUT } ) ) ;
2022-12-16 18:17:31 +01:00
} ,
PNEWKEYBOARD , " Keyboard " ) ;
2022-08-18 17:50:32 +02:00
disableAllKeyboards ( true ) ;
2022-08-05 16:21:08 +02:00
m_pActiveKeyboard = PNEWKEYBOARD ;
2022-08-18 17:17:33 +02:00
PNEWKEYBOARD - > active = true ;
2022-08-05 16:21:08 +02:00
applyConfigToKeyboard ( PNEWKEYBOARD ) ;
wlr_seat_set_keyboard ( g_pCompositor - > m_sSeat . seat , wlr_keyboard_from_input_device ( keyboard ) ) ;
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " New virtual keyboard created, pointers Hypr: {:x} and WLR: {:x} " , ( uintptr_t ) PNEWKEYBOARD , ( uintptr_t ) keyboard ) ;
2022-08-05 16:21:08 +02:00
}
2022-03-24 21:05:34 +01:00
void CInputManager : : setKeyboardLayout ( ) {
2022-06-23 15:48:31 +02:00
for ( auto & k : m_lKeyboards )
applyConfigToKeyboard ( & k ) ;
2022-08-21 16:43:18 +02:00
g_pKeybindManager - > updateXKBTranslationState ( ) ;
2022-06-23 15:48:31 +02:00
}
void CInputManager : : applyConfigToKeyboard ( SKeyboard * pKeyboard ) {
2022-12-16 18:17:31 +01:00
auto devname = pKeyboard - > name ;
2022-07-28 21:38:30 +02:00
const auto HASCONFIG = g_pConfigManager - > deviceConfigExists ( devname ) ;
2023-09-06 21:45:37 +02:00
Debug : : log ( LOG , " ApplyConfigToKeyboard for \" {} \" , hasconfig: {} " , pKeyboard - > name , ( int ) HASCONFIG ) ;
2022-03-24 21:05:34 +01:00
2022-06-23 15:48:31 +02:00
ASSERT ( pKeyboard ) ;
2022-03-24 21:05:34 +01:00
2022-07-11 23:09:35 +02:00
if ( ! wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) )
2022-07-03 22:54:47 +02:00
return ;
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
2023-09-06 19:16:46 +02:00
const auto NUMLOCKON = g_pConfigManager - > getDeviceInt ( devname , " numlock_by_default " , " input:numlock_by_default " ) ;
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 03:18:47 +01:00
const auto ENABLED = HASCONFIG ? g_pConfigManager - > getDeviceInt ( devname , " enabled " ) : true ;
2022-12-16 18:20:51 +01:00
pKeyboard - > enabled = ENABLED ;
2022-06-28 15:40:14 +02:00
try {
2022-12-16 18:17:31 +01: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
}
2022-07-11 23:09:35 +02:00
wlr_keyboard_set_repeat_info ( wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) , std : : max ( 0 , REPEATRATE ) , std : : max ( 0 , REPEATDELAY ) ) ;
2022-06-30 21:26:00 +02:00
pKeyboard - > repeatDelay = REPEATDELAY ;
2022-12-16 18:17:31 +01:00
pKeyboard - > repeatRate = REPEATRATE ;
pKeyboard - > numlockOn = NUMLOCKON ;
2022-08-19 20:01:51 +02:00
pKeyboard - > xkbFilePath = FILEPATH . c_str ( ) ;
2022-06-30 21:26:00 +02:00
2022-12-16 18:17:31 +01:00
xkb_rule_names rules = { . rules = RULES . c_str ( ) , . model = MODEL . c_str ( ) , . layout = LAYOUT . c_str ( ) , . variant = VARIANT . c_str ( ) , . options = OPTIONS . c_str ( ) } ;
2022-03-24 21:05:34 +01:00
2022-12-16 18:17:31 +01:00
pKeyboard - > currentRules . rules = RULES ;
pKeyboard - > currentRules . model = MODEL ;
2022-07-08 12:27:05 +02:00
pKeyboard - > currentRules . variant = VARIANT ;
pKeyboard - > currentRules . options = OPTIONS ;
2022-12-16 18:17:31 +01:00
pKeyboard - > currentRules . layout = LAYOUT ;
2022-06-25 11:50:09 +02:00
2022-03-24 21:05:34 +01:00
const auto CONTEXT = xkb_context_new ( XKB_CONTEXT_NO_FLAGS ) ;
2022-06-23 18:52:05 +02:00
if ( ! CONTEXT ) {
Debug : : log ( ERR , " applyConfigToKeyboard: CONTEXT null?? " ) ;
2022-03-24 21:05:34 +01:00
return ;
}
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " Attempting to create a keymap for layout {} with variant {} (rules: {}, model: {}, options: {}) " , rules . layout , rules . variant , rules . rules , rules . model ,
2022-12-16 18:17:31 +01:00
rules . options ) ;
2022-06-25 11:50:09 +02:00
2022-12-16 18:17:31 +01:00
xkb_keymap * KEYMAP = NULL ;
2022-08-19 20:01:51 +02:00
if ( ! FILEPATH . empty ( ) ) {
2022-12-16 18:17:31 +01:00
auto path = absolutePath ( FILEPATH , g_pConfigManager - > configCurrentPath ) ;
2022-08-19 20:01:51 +02:00
2023-08-25 17:21:55 +02:00
if ( FILE * const KEYMAPFILE = fopen ( path . c_str ( ) , " r " ) ; ! KEYMAPFILE )
Debug : : log ( ERR , " Cannot open input:kb_file= file for reading " ) ;
2023-08-07 19:34:15 +02:00
else {
2023-08-30 13:42:17 +02:00
KEYMAP = xkb_keymap_new_from_file ( CONTEXT , KEYMAPFILE , XKB_KEYMAP_FORMAT_TEXT_V1 , XKB_KEYMAP_COMPILE_NO_FLAGS ) ;
2023-08-07 19:34:15 +02:00
fclose ( KEYMAPFILE ) ;
}
2022-09-25 20:07:48 +02:00
}
2022-08-19 20:01:51 +02:00
2023-07-25 11:49:31 +02:00
if ( ! KEYMAP )
2022-12-16 18:17:31 +01:00
KEYMAP = xkb_keymap_new_from_names ( CONTEXT , & rules , XKB_KEYMAP_COMPILE_NO_FLAGS ) ;
2022-06-02 20:31:47 +02:00
2022-03-24 21:05:34 +01:00
if ( ! KEYMAP ) {
2022-12-16 18:17:31 +01:00
g_pConfigManager - > addParseError ( " Invalid keyboard layout passed. ( rules: " + RULES + " , model: " + MODEL + " , variant: " + VARIANT + " , options: " + OPTIONS +
" , layout: " + LAYOUT + " ) " ) ;
2022-08-09 18:13:13 +02:00
2023-09-06 12:51:36 +02:00
Debug : : log ( ERR , " Keyboard layout {} with variant {} (rules: {}, model: {}, options: {}) couldn't have been loaded. " , rules . layout , rules . variant , rules . rules , rules . model ,
2022-12-16 18:17:31 +01:00
rules . options ) ;
2022-06-25 11:50:09 +02:00
memset ( & rules , 0 , sizeof ( rules ) ) ;
2022-12-16 18:17:31 +01:00
pKeyboard - > currentRules . rules = " " ;
pKeyboard - > currentRules . model = " " ;
2022-07-08 12:27:05 +02:00
pKeyboard - > currentRules . variant = " " ;
pKeyboard - > currentRules . options = " " ;
2022-12-16 18:17:31 +01:00
pKeyboard - > currentRules . layout = " " ;
2022-06-25 11:50:09 +02:00
KEYMAP = xkb_keymap_new_from_names ( CONTEXT , & rules , XKB_KEYMAP_COMPILE_NO_FLAGS ) ;
2022-06-03 18:59:39 +02:00
}
2022-06-02 19:47:11 +02:00
2022-07-11 23:09:35 +02:00
wlr_keyboard_set_keymap ( wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) , KEYMAP ) ;
2022-06-02 19:47:11 +02:00
2022-06-03 18:59:39 +02:00
wlr_keyboard_modifiers wlrMods = { 0 } ;
2022-06-02 19:47:11 +02:00
2022-06-30 21:26:00 +02:00
if ( NUMLOCKON = = 1 ) {
2022-06-03 18:59:39 +02:00
// lock numlock
const auto IDX = xkb_map_mod_get_index ( KEYMAP , XKB_MOD_NAME_NUM ) ;
if ( IDX ! = XKB_MOD_INVALID )
wlrMods . locked | = ( uint32_t ) 1 < < IDX ;
}
2023-07-25 11:49:31 +02:00
if ( wlrMods . locked ! = 0 )
2022-07-11 23:09:35 +02:00
wlr_keyboard_notify_modifiers ( wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) , 0 , 0 , wlrMods . locked , 0 ) ;
2022-06-02 19:47:11 +02:00
2022-03-24 21:05:34 +01:00
xkb_keymap_unref ( KEYMAP ) ;
xkb_context_unref ( CONTEXT ) ;
2023-02-19 21:54:53 +01:00
const auto LAYOUTSTR = getActiveLayoutForKeyboard ( pKeyboard ) ;
2023-07-06 15:23:11 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , pKeyboard - > name + " , " + LAYOUTSTR } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < void * > { pKeyboard , ( void * ) & LAYOUTSTR } ) ) ;
2022-08-18 17:17:33 +02:00
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " Set the keyboard layout to {} and variant to {} for keyboard \" {} \" " , rules . layout , rules . variant , pKeyboard - > keyboard - > name ) ;
2022-09-25 20:07:48 +02:00
}
2022-03-17 20:55:04 +01:00
2022-07-11 20:23:16 +02:00
void CInputManager : : newMouse ( wlr_input_device * mouse , bool virt ) {
2022-04-17 21:40:04 +02:00
m_lMice . emplace_back ( ) ;
const auto PMOUSE = & m_lMice . back ( ) ;
PMOUSE - > mouse = mouse ;
2022-12-16 18:17:31 +01:00
PMOUSE - > virt = virt ;
2022-06-30 21:26:00 +02:00
try {
2022-12-03 21:36:52 +01:00
PMOUSE - > name = getNameForNewDevice ( mouse - > name ) ;
2022-12-16 18:17:31 +01:00
} catch ( std : : exception & e ) {
2022-06-30 21:26:00 +02:00
Debug : : log ( ERR , " Mouse had no name??? " ) ; // logic error
}
2022-03-18 22:53:27 +01:00
if ( wlr_input_device_is_libinput ( mouse ) ) {
const auto LIBINPUTDEV = ( libinput_device * ) wlr_libinput_get_device_handle ( mouse ) ;
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
}
wlr_cursor_attach_input_device ( g_pCompositor - > m_sWLRCursor , mouse ) ;
2022-03-19 11:27:19 +01:00
2022-10-27 13:58:10 +02:00
PMOUSE - > connected = true ;
2022-11-04 11:48:42 +01:00
setPointerConfigs ( ) ;
PMOUSE - > hyprListener_destroyMouse . initCallback ( & mouse - > events . destroy , & Events : : listener_destroyMouse , PMOUSE , " Mouse " ) ;
2022-04-17 21:40:04 +02:00
g_pCompositor - > m_sSeat . mouse = PMOUSE ;
2022-06-24 23:27:02 +02:00
m_tmrLastCursorMovement . reset ( ) ;
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " New mouse created, pointer WLR: {:x} " , ( uintptr_t ) mouse ) ;
2022-03-18 22:53:27 +01:00
}
2022-10-05 22:21:22 +02:00
void CInputManager : : setPointerConfigs ( ) {
2022-07-19 19:26:53 +02:00
for ( auto & m : m_lMice ) {
2022-10-05 22:21:22 +02:00
const auto PPOINTER = & m ;
2022-07-19 19:26:53 +02:00
2022-12-16 18:17:31 +01:00
auto devname = PPOINTER - > name ;
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 13:58:10 +02:00
if ( HASCONFIG ) {
const auto ENABLED = g_pConfigManager - > getDeviceInt ( devname , " enabled " ) ;
if ( ENABLED & & ! m . connected ) {
wlr_cursor_attach_input_device ( g_pCompositor - > m_sWLRCursor , m . mouse ) ;
m . connected = true ;
} else if ( ! ENABLED & & m . connected ) {
wlr_cursor_detach_input_device ( g_pCompositor - > m_sWLRCursor , m . mouse ) ;
m . connected = false ;
}
}
2022-07-19 19:26:53 +02:00
if ( wlr_input_device_is_libinput ( m . mouse ) ) {
const auto LIBINPUTDEV = ( libinput_device * ) wlr_libinput_get_device_handle ( m . mouse ) ;
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 22:46:41 +02:00
libinput_device_config_left_handed_set ( LIBINPUTDEV , 0 ) ;
else
libinput_device_config_left_handed_set ( LIBINPUTDEV , 1 ) ;
2022-12-16 18:17:31 +01: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 15:17:23 +01: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 15:17:23 +01: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 18:11:21 +01:00
if ( SCROLLMETHOD = = " " ) {
2022-10-05 22:21:22 +02: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 13:05:26 +01: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 18:17:31 +01:00
if ( libinput_device_config_tap_get_finger_count ( LIBINPUTDEV ) ) // this is for tapping (like on a laptop)
2023-09-06 19:16:46 +02:00
if ( g_pConfigManager - > getDeviceInt ( devname , " tap-to-click " , " input:touchpad:tap-to-click " ) = = 1 )
2022-07-19 19:26:53 +02:00
libinput_device_config_tap_set_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_TAP_ENABLED ) ;
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 " ) ;
2022-10-05 22:21:22 +02:00
2022-11-24 18:11:21 +01:00
if ( ACCELPROFILE = = " " ) {
2022-10-05 22:21:22 +02: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-05-05 17:06:13 +02:00
CVarList args = { ACCELPROFILE , 0 , ' ' } ;
try {
double step = std : : stod ( args [ 1 ] ) ;
std : : vector < double > points ;
for ( size_t i = 2 ; i < args . size ( ) ; + + i )
points . push_back ( std : : stod ( args [ i ] ) ) ;
const auto CONFIG = libinput_config_accel_create ( LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM ) ;
libinput_config_accel_set_points ( CONFIG , LIBINPUT_ACCEL_TYPE_MOTION , step , points . size ( ) , points . data ( ) ) ;
libinput_device_config_accel_set_profile ( LIBINPUTDEV , LIBINPUT_CONFIG_ACCEL_PROFILE_CUSTOM ) ;
libinput_config_accel_destroy ( CONFIG ) ;
} catch ( std : : exception & e ) { Debug : : log ( ERR , " Invalid values in custom accel profile " ) ; }
2022-10-05 22:21:22 +02:00
} else {
Debug : : log ( WARN , " Unknown acceleration profile, falling back to default " ) ;
2022-11-22 00:26:18 +01:00
}
2023-09-06 19:16:46 +02:00
const auto SCROLLBUTTON = g_pConfigManager - > getDeviceInt ( devname , " scroll_button " , " input:scroll_button " ) ;
2022-11-22 00:26:18 +01:00
libinput_device_config_scroll_set_button ( LIBINPUTDEV , SCROLLBUTTON = = 0 ? libinput_device_config_scroll_get_default_button ( LIBINPUTDEV ) : SCROLLBUTTON ) ;
2022-10-05 22:21:22 +02: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 14:54:48 +02: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 14:54:48 +02:00
2023-09-06 21:45:37 +02:00
Debug : : log ( LOG , " Applied config to mouse {}, sens {:.2f} " , m . name , LIBINPUTSENS ) ;
2022-07-19 19:26:53 +02:00
}
}
}
2022-03-18 23:25:26 +01:00
void CInputManager : : destroyKeyboard ( SKeyboard * pKeyboard ) {
2022-03-28 22:31:39 +02:00
pKeyboard - > hyprListener_keyboardDestroy . removeCallback ( ) ;
pKeyboard - > hyprListener_keyboardMod . removeCallback ( ) ;
pKeyboard - > hyprListener_keyboardKey . removeCallback ( ) ;
2022-03-18 23:25:26 +01:00
2022-06-03 18:59:39 +02:00
if ( pKeyboard - > active ) {
m_lKeyboards . remove ( * pKeyboard ) ;
if ( m_lKeyboards . size ( ) > 0 ) {
2022-12-16 18:17:31 +01:00
m_pActiveKeyboard = & m_lKeyboards . back ( ) ;
2022-06-03 18:59:39 +02:00
m_pActiveKeyboard - > active = true ;
} else {
m_pActiveKeyboard = nullptr ;
}
2023-01-02 12:08:00 +01:00
} else
m_lKeyboards . remove ( * pKeyboard ) ;
2022-03-18 23:25:26 +01:00
}
void CInputManager : : destroyMouse ( wlr_input_device * mouse ) {
2022-04-17 21:40:04 +02:00
for ( auto & m : m_lMice ) {
if ( m . mouse = = mouse ) {
m_lMice . remove ( m ) ;
2022-05-12 12:13:02 +02:00
break ;
2022-04-17 21:40:04 +02:00
}
}
g_pCompositor - > m_sSeat . mouse = m_lMice . size ( ) > 0 ? & m_lMice . front ( ) : nullptr ;
2022-05-12 12:13:02 +02:00
2022-05-18 14:57:08 +02:00
if ( g_pCompositor - > m_sSeat . mouse )
2022-08-09 20:36:21 +02:00
unconstrainMouse ( ) ;
2022-03-18 23:25:26 +01:00
}
2022-12-16 18:17:31 +01:00
void CInputManager : : updateKeyboardsLeds ( wlr_input_device * pKeyboard ) {
2022-11-12 12:12:37 +01:00
auto keyboard = wlr_keyboard_from_input_device ( pKeyboard ) ;
2022-12-16 18:17:31 +01:00
2022-11-12 12:12:37 +01:00
if ( keyboard - > xkb_state = = NULL ) {
2022-12-16 18:17:31 +01:00
return ;
}
uint32_t leds = 0 ;
for ( uint32_t i = 0 ; i < WLR_LED_COUNT ; + + i ) {
2023-07-25 11:49:31 +02:00
if ( xkb_state_led_index_is_active ( keyboard - > xkb_state , keyboard - > led_indexes [ i ] ) )
2022-12-16 18:17:31 +01:00
leds | = ( 1 < < i ) ;
}
2022-11-12 12:12:37 +01:00
for ( auto & kb : m_lKeyboards ) {
if ( ( kb . isVirtual & & shouldIgnoreVirtualKeyboard ( & kb ) ) | | kb . keyboard = = pKeyboard )
continue ;
wlr_keyboard_led_update ( wlr_keyboard_from_input_device ( kb . keyboard ) , leds ) ;
}
}
2022-03-24 15:57:46 +01:00
void CInputManager : : onKeyboardKey ( wlr_keyboard_key_event * e , SKeyboard * pKeyboard ) {
2022-12-16 18:20:51 +01:00
if ( ! pKeyboard - > enabled )
return ;
2023-03-16 01:30:07 +01:00
static auto * const PDPMS = & g_pConfigManager - > getConfigValuePtr ( " misc:key_press_enables_dpms " ) - > intValue ;
2023-03-16 16:29:48 +01:00
if ( * PDPMS & & ! g_pCompositor - > m_bDPMSStateON ) {
2023-03-12 14:46:38 +01:00
// enable dpms
g_pKeybindManager - > dpms ( " on " ) ;
}
2022-07-20 22:45:06 +02:00
bool passEvent = g_pKeybindManager - > onKeyEvent ( e , pKeyboard ) ;
2022-03-18 23:06:45 +01:00
2023-07-13 18:05:34 +02:00
g_pCompositor - > notifyIdleActivity ( ) ;
2022-03-17 20:55:04 +01:00
2022-07-20 22:45:06 +02:00
if ( passEvent ) {
2022-08-05 16:21:08 +02:00
const auto PIMEGRAB = m_sIMERelay . getIMEKeyboardGrab ( pKeyboard ) ;
if ( PIMEGRAB & & PIMEGRAB - > pWlrKbGrab & & PIMEGRAB - > pWlrKbGrab - > input_method ) {
wlr_input_method_keyboard_grab_v2_set_keyboard ( PIMEGRAB - > pWlrKbGrab , wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) ) ;
wlr_input_method_keyboard_grab_v2_send_key ( PIMEGRAB - > pWlrKbGrab , e - > time_msec , e - > keycode , e - > state ) ;
} else {
wlr_seat_set_keyboard ( g_pCompositor - > m_sSeat . seat , wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) ) ;
wlr_seat_keyboard_notify_key ( g_pCompositor - > m_sSeat . seat , e - > time_msec , e - > keycode , e - > state ) ;
}
2022-11-12 12:12:37 +01:00
updateKeyboardsLeds ( pKeyboard - > keyboard ) ;
2022-03-19 22:03:40 +01:00
}
2022-03-18 23:06:45 +01:00
}
2022-03-17 20:55:04 +01:00
2022-03-18 23:06:45 +01:00
void CInputManager : : onKeyboardMod ( void * data , SKeyboard * pKeyboard ) {
2022-12-16 18:20:51 +01:00
if ( ! pKeyboard - > enabled )
return ;
2022-08-05 16:21:08 +02:00
const auto PIMEGRAB = m_sIMERelay . getIMEKeyboardGrab ( pKeyboard ) ;
2022-09-04 18:46:28 +02:00
const auto ALLMODS = accumulateModsFromAllKBs ( ) ;
2022-12-16 18:17:31 +01:00
auto MODS = wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) - > modifiers ;
MODS . depressed = ALLMODS ;
2022-09-04 18:46:28 +02:00
2022-08-05 16:21:08 +02:00
if ( PIMEGRAB & & PIMEGRAB - > pWlrKbGrab & & PIMEGRAB - > pWlrKbGrab - > input_method ) {
wlr_input_method_keyboard_grab_v2_set_keyboard ( PIMEGRAB - > pWlrKbGrab , wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) ) ;
2022-09-04 18:46:28 +02:00
wlr_input_method_keyboard_grab_v2_send_modifiers ( PIMEGRAB - > pWlrKbGrab , & MODS ) ;
2022-08-05 16:21:08 +02:00
} else {
wlr_seat_set_keyboard ( g_pCompositor - > m_sSeat . seat , wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) ) ;
2022-09-04 18:46:28 +02:00
wlr_seat_keyboard_notify_modifiers ( g_pCompositor - > m_sSeat . seat , & MODS ) ;
2022-08-05 16:21:08 +02:00
}
2022-08-18 17:17:33 +02:00
2022-11-12 12:12:37 +01:00
updateKeyboardsLeds ( pKeyboard - > keyboard ) ;
2022-08-18 17:17:33 +02:00
const auto PWLRKB = wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) ;
if ( PWLRKB - > modifiers . group ! = pKeyboard - > activeLayout ) {
2022-12-16 18:17:31 +01:00
pKeyboard - > activeLayout = PWLRKB - > modifiers . group ;
2022-08-18 17:17:33 +02:00
2023-02-19 21:54:53 +01:00
const auto LAYOUT = getActiveLayoutForKeyboard ( pKeyboard ) ;
2023-07-06 15:23:11 +02:00
g_pEventManager - > postEvent ( SHyprIPCEvent { " activelayout " , pKeyboard - > name + " , " + LAYOUT } ) ;
2023-02-19 21:54:53 +01:00
EMIT_HOOK_EVENT ( " activeLayout " , ( std : : vector < void * > { pKeyboard , ( void * ) & LAYOUT } ) ) ;
2022-12-16 18:17:31 +01:00
}
2022-03-21 19:28:43 +01:00
}
2022-11-07 23:22:13 +01:00
bool CInputManager : : shouldIgnoreVirtualKeyboard ( SKeyboard * pKeyboard ) {
2022-12-16 18:17:31 +01:00
return ! pKeyboard | |
( m_sIMERelay . m_pKeyboardGrab & &
wl_resource_get_client ( m_sIMERelay . m_pKeyboardGrab - > pWlrKbGrab - > resource ) = = wl_resource_get_client ( wlr_input_device_get_virtual_keyboard ( pKeyboard - > keyboard ) - > resource ) ) ;
2022-11-07 23:22:13 +01: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
}
void CInputManager : : updateDragIcon ( ) {
2022-08-06 22:26:32 +02:00
if ( ! m_sDrag . dragIcon )
2022-03-31 17:25:23 +02:00
return ;
2022-08-06 22:26:32 +02:00
switch ( m_sDrag . dragIcon - > drag - > grab_type ) {
2022-12-16 18:17:31 +01:00
case WLR_DRAG_GRAB_KEYBOARD : break ;
2022-06-29 14:15:08 +02:00
case WLR_DRAG_GRAB_KEYBOARD_POINTER : {
2023-11-04 18:03:05 +01:00
CBox box = { m_sDrag . pos . x - 2 , m_sDrag . pos . y - 2 , m_sDrag . dragIcon - > surface - > current . width + 4 , m_sDrag . dragIcon - > surface - > current . height + 4 } ;
2022-06-29 14:15:08 +02:00
g_pHyprRenderer - > damageBox ( & box ) ;
2022-08-06 22:26:32 +02:00
m_sDrag . pos = getMouseCoordsInternal ( ) ;
2022-03-31 17:25:23 +02:00
break ;
2022-06-29 14:15:08 +02:00
}
2022-12-16 18:17:31 +01:00
default : break ;
2022-03-31 17:25:23 +02:00
}
2022-04-17 21:40:04 +02:00
}
void CInputManager : : recheckConstraint ( SMouse * pMouse ) {
if ( ! pMouse - > currentConstraint )
return ;
const auto PREGION = & pMouse - > currentConstraint - > region ;
2023-07-25 11:49:31 +02:00
if ( pMouse - > currentConstraint - > type = = WLR_POINTER_CONSTRAINT_V1_CONFINED )
2023-07-19 20:09:49 +02:00
pMouse - > confinedTo . set ( PREGION ) ;
2023-07-25 11:49:31 +02:00
else
2023-07-19 20:09:49 +02:00
pMouse - > confinedTo . clear ( ) ;
2022-04-17 21:40:04 +02:00
}
void CInputManager : : constrainMouse ( SMouse * pMouse , wlr_pointer_constraint_v1 * constraint ) {
if ( pMouse - > currentConstraint = = constraint )
return ;
const auto MOUSECOORDS = getMouseCoordsInternal ( ) ;
2023-09-28 21:02:00 +02:00
const auto PCONSTRAINT = constraintFromWlr ( constraint ) ;
2022-04-17 21:40:04 +02:00
pMouse - > hyprListener_commitConstraint . removeCallback ( ) ;
2023-09-28 21:02:00 +02:00
if ( pMouse - > currentConstraint )
wlr_pointer_constraint_v1_send_deactivated ( pMouse - > currentConstraint ) ;
2023-09-15 22:01:54 +02:00
2023-09-28 21:02:00 +02:00
if ( const auto PWINDOW = g_pCompositor - > getWindowFromSurface ( constraint - > surface ) ; PWINDOW ) {
const auto RELATIVETO = PWINDOW - > m_bIsX11 ?
( PWINDOW - > m_bIsMapped ? PWINDOW - > m_vRealPosition . goalv ( ) :
g_pXWaylandManager - > xwaylandToWaylandCoords ( { PWINDOW - > m_uSurface . xwayland - > x , PWINDOW - > m_uSurface . xwayland - > y } ) ) :
PWINDOW - > m_vRealPosition . goalv ( ) ;
2022-09-25 20:07:48 +02:00
2023-10-26 03:05:10 +02:00
PCONSTRAINT - > cursorPosOnActivate = ( MOUSECOORDS - RELATIVETO ) * PWINDOW - > m_fX11SurfaceScaledBy ;
2023-09-28 21:02:00 +02:00
}
if ( constraint - > current . committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT ) {
PCONSTRAINT - > hintSet = true ;
PCONSTRAINT - > positionHint = { constraint - > current . cursor_hint . x , constraint - > current . cursor_hint . y } ;
2022-04-17 21:40:04 +02:00
}
2023-09-28 21:02:00 +02:00
if ( constraint - > current . committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT & & constraint - > type = = WLR_POINTER_CONSTRAINT_V1_LOCKED )
warpMouseToConstraintMiddle ( PCONSTRAINT ) ;
2022-04-17 21:40:04 +02:00
pMouse - > currentConstraint = constraint ;
2022-12-16 18:17:31 +01:00
pMouse - > constraintActive = true ;
2022-04-17 21:40:04 +02:00
2023-07-25 11:49:31 +02:00
if ( pixman_region32_not_empty ( & constraint - > current . region ) )
2022-04-17 21:40:04 +02:00
pixman_region32_intersect ( & constraint - > region , & constraint - > surface - > input_region , & constraint - > current . region ) ;
2023-07-25 11:49:31 +02:00
else
2022-04-17 21:40:04 +02:00
pixman_region32_copy ( & constraint - > region , & constraint - > surface - > input_region ) ;
// warp to the constraint
recheckConstraint ( pMouse ) ;
2023-09-28 21:02:00 +02:00
PCONSTRAINT - > active = true ;
2023-08-30 17:23:35 +02:00
2022-04-17 21:40:04 +02:00
wlr_pointer_constraint_v1_send_activated ( pMouse - > currentConstraint ) ;
pMouse - > hyprListener_commitConstraint . initCallback ( & pMouse - > currentConstraint - > surface - > events . commit , & Events : : listener_commitConstraint , pMouse , " Mouse constraint commit " ) ;
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " Constrained mouse to {:x} " , ( uintptr_t ) pMouse - > currentConstraint ) ;
2022-04-17 21:40:04 +02:00
}
2023-08-18 22:40:23 +02:00
void CInputManager : : warpMouseToConstraintMiddle ( SConstraint * pConstraint ) {
if ( ! pConstraint )
return ;
const auto PWINDOW = g_pCompositor - > getWindowFromSurface ( pConstraint - > constraint - > surface ) ;
if ( PWINDOW ) {
2023-09-28 21:02:00 +02:00
const auto RELATIVETO = pConstraint - > getLogicConstraintPos ( ) ;
2023-08-18 22:40:23 +02:00
const auto HINTSCALE = PWINDOW - > m_fX11SurfaceScaledBy ;
2023-09-28 21:02:00 +02:00
auto HINT = pConstraint - > hintSet ? pConstraint - > positionHint : pConstraint - > cursorPosOnActivate ;
2023-09-04 17:34:19 +02:00
2023-09-28 21:02:00 +02:00
if ( HINT = = Vector2D { - 1 , - 1 } )
HINT = pConstraint - > getLogicConstraintSize ( ) / 2.f ;
if ( HINT ! = Vector2D { - 1 , - 1 } ) {
wlr_cursor_warp ( g_pCompositor - > m_sWLRCursor , nullptr , RELATIVETO . x + HINT . x / HINTSCALE , RELATIVETO . y + HINT . y / HINTSCALE ) ;
wlr_seat_pointer_warp ( pConstraint - > constraint - > seat , pConstraint - > constraint - > current . cursor_hint . x , pConstraint - > constraint - > current . cursor_hint . y ) ;
2023-09-04 17:34:19 +02:00
}
2023-08-18 22:40:23 +02:00
}
}
2022-08-09 20:36:21 +02:00
void CInputManager : : unconstrainMouse ( ) {
2023-02-28 20:02:30 +01:00
if ( ! g_pCompositor - > m_sSeat . mouse | | ! g_pCompositor - > m_sSeat . mouse - > currentConstraint )
2022-08-09 20:36:21 +02:00
return ;
const auto CONSTRAINTWINDOW = g_pCompositor - > getConstraintWindow ( g_pCompositor - > m_sSeat . mouse ) ;
2023-07-25 11:49:31 +02:00
if ( CONSTRAINTWINDOW )
2023-03-20 16:00:58 +01:00
g_pXWaylandManager - > activateSurface ( CONSTRAINTWINDOW - > m_pWLSurface . wlr ( ) , false ) ;
2022-08-09 20:36:21 +02:00
wlr_pointer_constraint_v1_send_deactivated ( g_pCompositor - > m_sSeat . mouse - > currentConstraint ) ;
2023-08-30 13:42:17 +02:00
const auto PCONSTRAINT = constraintFromWlr ( g_pCompositor - > m_sSeat . mouse - > currentConstraint ) ;
2023-09-17 17:46:04 +02:00
if ( PCONSTRAINT )
PCONSTRAINT - > active = false ;
2023-08-30 13:42:17 +02:00
2022-08-09 20:36:21 +02:00
g_pCompositor - > m_sSeat . mouse - > constraintActive = false ;
// TODO: its better to somehow detect the workspace...
g_pCompositor - > m_sSeat . mouse - > currentConstraint = nullptr ;
g_pCompositor - > m_sSeat . mouse - > hyprListener_commitConstraint . removeCallback ( ) ;
}
2022-04-17 21:40:04 +02:00
void Events : : listener_commitConstraint ( void * owner , void * data ) {
2022-12-10 15:43:46 +01:00
const auto PMOUSE = ( SMouse * ) owner ;
if ( PMOUSE - > currentConstraint - > current . committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT ) {
const auto PCONSTRAINT = g_pInputManager - > constraintFromWlr ( PMOUSE - > currentConstraint ) ;
2022-12-16 18:17:31 +01:00
if ( PCONSTRAINT ) { // should never be null but who knows
2022-12-10 15:43:46 +01:00
PCONSTRAINT - > positionHint = Vector2D ( PMOUSE - > currentConstraint - > current . cursor_hint . x , PMOUSE - > currentConstraint - > current . cursor_hint . y ) ;
2022-12-16 18:17:31 +01:00
PCONSTRAINT - > hintSet = true ;
2022-12-10 15:43:46 +01:00
}
}
2023-01-03 13:06:13 +01:00
if ( PMOUSE - > currentConstraint - > current . committed & WLR_POINTER_CONSTRAINT_V1_STATE_REGION ) {
2023-07-25 11:49:31 +02:00
if ( pixman_region32_not_empty ( & PMOUSE - > currentConstraint - > current . region ) )
2023-01-03 13:06:13 +01:00
pixman_region32_intersect ( & PMOUSE - > currentConstraint - > region , & PMOUSE - > currentConstraint - > surface - > input_region , & PMOUSE - > currentConstraint - > current . region ) ;
2023-07-25 11:49:31 +02:00
else
2023-01-03 13:06:13 +01:00
pixman_region32_copy ( & PMOUSE - > currentConstraint - > region , & PMOUSE - > currentConstraint - > surface - > input_region ) ;
g_pInputManager - > recheckConstraint ( PMOUSE ) ;
}
2022-04-17 21:40:04 +02:00
}
2022-06-09 12:46:55 +02:00
2022-12-05 15:28:27 +01:00
void CInputManager : : updateCapabilities ( ) {
uint32_t caps = 0 ;
if ( ! m_lKeyboards . empty ( ) )
caps | = WL_SEAT_CAPABILITY_KEYBOARD ;
if ( ! m_lMice . empty ( ) )
caps | = WL_SEAT_CAPABILITY_POINTER ;
if ( ! m_lTouchDevices . empty ( ) )
caps | = WL_SEAT_CAPABILITY_TOUCH ;
if ( ! m_lTabletTools . empty ( ) )
caps | = WL_SEAT_CAPABILITY_POINTER ;
wlr_seat_set_capabilities ( g_pCompositor - > m_sSeat . seat , caps ) ;
m_uiCapabilities = caps ;
2022-07-09 23:24:08 +02:00
}
uint32_t CInputManager : : accumulateModsFromAllKBs ( ) {
uint32_t finalMask = 0 ;
for ( auto & kb : m_lKeyboards ) {
2022-11-07 23:22:13 +01:00
if ( kb . isVirtual & & shouldIgnoreVirtualKeyboard ( & kb ) )
2022-09-05 11:19:40 +02:00
continue ;
2022-12-16 18:20:51 +01:00
if ( ! kb . enabled )
continue ;
2022-07-11 23:09:35 +02:00
finalMask | = wlr_keyboard_get_modifiers ( wlr_keyboard_from_input_device ( kb . keyboard ) ) ;
2022-07-09 23:24:08 +02:00
}
return finalMask ;
2022-07-12 13:11:54 +02:00
}
2022-08-16 16:10:20 +02:00
std : : string CInputManager : : getActiveLayoutForKeyboard ( SKeyboard * pKeyboard ) {
2022-12-16 18:17:31 +01:00
const auto WLRKB = wlr_keyboard_from_input_device ( pKeyboard - > keyboard ) ;
const auto KEYMAP = WLRKB - > keymap ;
const auto STATE = WLRKB - > xkb_state ;
2022-08-16 16:10:20 +02:00
const auto LAYOUTSNUM = xkb_keymap_num_layouts ( KEYMAP ) ;
2022-08-16 16:15:43 +02:00
for ( uint32_t i = 0 ; i < LAYOUTSNUM ; + + i ) {
2022-08-16 16:10:20 +02:00
if ( xkb_state_layout_index_is_active ( STATE , i , XKB_STATE_LAYOUT_EFFECTIVE ) ) {
const auto LAYOUTNAME = xkb_keymap_layout_get_name ( KEYMAP , i ) ;
2022-09-25 20:07:48 +02:00
if ( LAYOUTNAME )
2022-08-16 16:10:20 +02:00
return std : : string ( LAYOUTNAME ) ;
return " error " ;
}
}
return " none " ;
}
2022-08-18 17:50:32 +02:00
void CInputManager : : disableAllKeyboards ( bool virt ) {
for ( auto & k : m_lKeyboards ) {
if ( k . isVirtual ! = virt )
continue ;
k . active = false ;
}
2022-08-19 20:01:51 +02:00
}
2022-09-21 15:39:25 +02:00
void CInputManager : : newTouchDevice ( wlr_input_device * pDevice ) {
2022-12-16 18:17:31 +01:00
const auto PNEWDEV = & m_lTouchDevices . emplace_back ( ) ;
2022-09-21 15:39:25 +02:00
PNEWDEV - > pWlrDevice = pDevice ;
2022-10-07 16:03:52 +02:00
try {
2022-12-03 21:36:52 +01:00
PNEWDEV - > name = getNameForNewDevice ( pDevice - > name ) ;
2022-12-16 18:17:31 +01: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 ) ;
2022-09-21 15:39:25 +02:00
wlr_cursor_attach_input_device ( g_pCompositor - > m_sWLRCursor , pDevice ) ;
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " New touch device added at {:x} " , ( uintptr_t ) PNEWDEV ) ;
2022-09-21 15:39:25 +02:00
2022-12-16 18:17:31 +01:00
PNEWDEV - > hyprListener_destroy . initCallback (
& pDevice - > events . destroy , [ & ] ( void * owner , void * data ) { destroyTouchDevice ( ( STouchDevice * ) data ) ; } , PNEWDEV , " TouchDevice " ) ;
2022-09-21 15:39:25 +02:00
}
2023-05-24 22:17:33 +02:00
void CInputManager : : setTouchDeviceConfigs ( STouchDevice * dev ) {
2022-10-07 16:03:52 +02:00
2023-05-24 22:17:33 +02:00
auto setConfig = [ & ] ( STouchDevice * const PTOUCHDEV ) - > void {
if ( wlr_input_device_is_libinput ( PTOUCHDEV - > pWlrDevice ) ) {
const auto LIBINPUTDEV = ( libinput_device * ) wlr_libinput_get_device_handle ( PTOUCHDEV - > pWlrDevice ) ;
2022-10-07 16:03:52 +02:00
2023-09-06 19:16:46 +02:00
const int ROTATION = std : : clamp ( g_pConfigManager - > getDeviceInt ( PTOUCHDEV - > name , " transform " , " input:touchdevice:transform " ) , 0 , 7 ) ;
2023-05-14 14:54:55 +02:00
if ( libinput_device_config_calibration_has_matrix ( LIBINPUTDEV ) )
libinput_device_config_calibration_set_matrix ( LIBINPUTDEV , MATRICES [ ROTATION ] ) ;
2022-10-14 13:38:44 +02:00
2023-09-06 19:16:46 +02:00
const auto OUTPUT = g_pConfigManager - > getDeviceString ( PTOUCHDEV - > name , " output " , " input:touchdevice:output " ) ;
2022-10-14 13:38:44 +02:00
if ( ! OUTPUT . empty ( ) & & OUTPUT ! = STRVAL_EMPTY )
PTOUCHDEV - > boundOutput = OUTPUT ;
else
PTOUCHDEV - > boundOutput = " " ;
2022-10-07 16:03:52 +02:00
}
2023-05-24 22:17:33 +02:00
} ;
if ( dev ) {
setConfig ( dev ) ;
return ;
}
for ( auto & m : m_lTouchDevices ) {
const auto PTOUCHDEV = & m ;
setConfig ( PTOUCHDEV ) ;
2022-10-07 16:03:52 +02:00
}
}
2022-12-21 16:11:39 +01:00
void CInputManager : : setTabletConfigs ( ) {
for ( auto & t : m_lTablets ) {
2023-01-15 20:38:58 +01:00
if ( wlr_input_device_is_libinput ( t . wlrDevice ) ) {
const auto LIBINPUTDEV = ( libinput_device * ) wlr_libinput_get_device_handle ( t . wlrDevice ) ;
2022-12-21 16:11:39 +01:00
2023-09-06 19:16:46 +02:00
const int ROTATION = std : : clamp ( g_pConfigManager - > getDeviceInt ( t . name , " transform " , " input:tablet:transform " ) , 0 , 7 ) ;
2023-09-06 21:45:37 +02:00
Debug : : log ( LOG , " Setting calibration matrix for device {} " , t . name ) ;
2023-01-15 20:38:58 +01:00
libinput_device_config_calibration_set_matrix ( LIBINPUTDEV , MATRICES [ ROTATION ] ) ;
2023-09-06 19:16:46 +02:00
const auto OUTPUT = g_pConfigManager - > getDeviceString ( t . name , " output " , " input:tablet:output " ) ;
2023-01-15 20:38:58 +01:00
const auto PMONITOR = g_pCompositor - > getMonitorFromString ( OUTPUT ) ;
if ( ! OUTPUT . empty ( ) & & OUTPUT ! = STRVAL_EMPTY & & PMONITOR ) {
2022-12-21 16:11:39 +01:00
wlr_cursor_map_input_to_output ( g_pCompositor - > m_sWLRCursor , t . wlrDevice , PMONITOR - > output ) ;
wlr_cursor_map_input_to_region ( g_pCompositor - > m_sWLRCursor , t . wlrDevice , nullptr ) ;
}
2023-09-27 20:49:30 +02:00
const auto REGION_POS = g_pConfigManager - > getDeviceVec ( t . name , " region_position " , " input:tablet:region_position " ) ;
const auto REGION_SIZE = g_pConfigManager - > getDeviceVec ( t . name , " region_size " , " input:tablet:region_size " ) ;
2023-11-04 18:03:05 +01:00
auto regionBox = CBox { REGION_POS . x , REGION_POS . y , REGION_SIZE . x , REGION_SIZE . y } ;
if ( ! regionBox . empty ( ) )
wlr_cursor_map_input_to_region ( g_pCompositor - > m_sWLRCursor , t . wlrDevice , regionBox . pWlr ( ) ) ;
2022-12-21 16:11:39 +01:00
}
}
}
2022-09-21 15:39:25 +02:00
void CInputManager : : destroyTouchDevice ( STouchDevice * pDevice ) {
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " Touch device at {:x} removed " , ( uintptr_t ) pDevice ) ;
2022-09-21 15:39:25 +02:00
m_lTouchDevices . remove ( * pDevice ) ;
}
2022-10-04 21:07:21 +02:00
void CInputManager : : newSwitch ( wlr_input_device * pDevice ) {
2022-12-16 18:17:31 +01:00
const auto PNEWDEV = & m_lSwitches . emplace_back ( ) ;
2022-10-04 21:07:21 +02:00
PNEWDEV - > pWlrDevice = pDevice ;
2023-09-06 12:51:36 +02:00
Debug : : log ( LOG , " New switch with name \" {} \" added " , pDevice - > name ) ;
2022-10-04 21:07:21 +02:00
2022-12-16 18:17:31 +01:00
PNEWDEV - > hyprListener_destroy . initCallback (
& pDevice - > events . destroy , [ & ] ( void * owner , void * data ) { destroySwitch ( ( SSwitchDevice * ) owner ) ; } , PNEWDEV , " SwitchDevice " ) ;
2022-10-04 21:07:21 +02:00
const auto PSWITCH = wlr_switch_from_input_device ( pDevice ) ;
2022-12-16 18:17:31 +01:00
PNEWDEV - > hyprListener_toggle . initCallback (
& PSWITCH - > events . toggle ,
[ & ] ( void * owner , void * data ) {
const auto PDEVICE = ( SSwitchDevice * ) owner ;
const auto NAME = std : : string ( PDEVICE - > pWlrDevice - > name ) ;
2023-03-16 17:30:22 +01:00
const auto E = ( wlr_switch_toggle_event * ) data ;
if ( PDEVICE - > status ! = - 1 & & PDEVICE - > status = = E - > switch_state )
return ;
2022-10-04 21:07:21 +02:00
2023-09-06 21:45:37 +02:00
Debug : : log ( LOG , " Switch {} fired, triggering binds. " , NAME ) ;
2022-10-04 21:07:21 +02:00
2022-12-16 18:17:31 +01:00
g_pKeybindManager - > onSwitchEvent ( NAME ) ;
2023-01-08 16:35:24 +01:00
2023-03-16 17:30:22 +01:00
switch ( E - > switch_state ) {
2023-01-08 16:35:24 +01:00
case WLR_SWITCH_STATE_ON :
2023-09-06 21:45:37 +02:00
Debug : : log ( LOG , " Switch {} turn on, triggering binds. " , NAME ) ;
2023-01-08 16:35:24 +01:00
g_pKeybindManager - > onSwitchOnEvent ( NAME ) ;
break ;
case WLR_SWITCH_STATE_OFF :
2023-09-06 21:45:37 +02:00
Debug : : log ( LOG , " Switch {} turn off, triggering binds. " , NAME ) ;
2023-01-08 16:35:24 +01:00
g_pKeybindManager - > onSwitchOffEvent ( NAME ) ;
break ;
}
2023-03-16 17:30:22 +01:00
PDEVICE - > status = E - > switch_state ;
2022-12-16 18:17:31 +01:00
} ,
PNEWDEV , " SwitchDevice " ) ;
2022-10-04 21:07:21 +02:00
}
void CInputManager : : destroySwitch ( SSwitchDevice * pDevice ) {
m_lSwitches . remove ( * pDevice ) ;
2022-10-05 04:25:26 +02:00
}
2022-11-15 11:39:05 +01:00
void CInputManager : : setCursorImageUntilUnset ( std : : string name ) {
2023-09-29 18:51:07 +02:00
g_pHyprRenderer - > setCursorFromName ( name . c_str ( ) ) ;
2023-10-29 19:09:05 +01:00
m_bCursorImageOverridden = true ;
m_sCursorSurfaceInfo . inUse = false ;
2022-11-15 11:39:05 +01:00
}
void CInputManager : : unsetCursorImage ( ) {
2023-03-30 00:44:25 +02:00
if ( ! m_bCursorImageOverridden )
2022-11-15 11:39:05 +01:00
return ;
2023-03-30 00:44:25 +02:00
m_bCursorImageOverridden = false ;
2023-10-29 19:09:05 +01:00
restoreCursorIconToApp ( ) ;
2022-11-15 11:39:05 +01:00
}
2022-12-03 16:56:07 +01: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 16:56:07 +01:00
std : : transform ( in . begin ( ) , in . end ( ) , in . begin ( ) , : : tolower ) ;
return in ;
}
2022-12-03 21:36:52 +01:00
std : : string CInputManager : : getNameForNewDevice ( std : : string internalName ) {
auto proposedNewName = deviceNameToInternalString ( internalName ) ;
2022-12-16 18:17:31 +01:00
int dupeno = 0 ;
2022-12-03 21:36:52 +01:00
2022-12-16 18:17:31 +01:00
while ( std : : find_if ( m_lKeyboards . begin ( ) , m_lKeyboards . end ( ) ,
[ & ] ( const SKeyboard & other ) { return other . name = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_lKeyboards . end ( ) )
2022-12-03 21:36:52 +01:00
dupeno + + ;
2022-12-16 18:17:31 +01:00
while ( std : : find_if ( m_lMice . begin ( ) , m_lMice . end ( ) , [ & ] ( const SMouse & other ) { return other . name = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! =
m_lMice . end ( ) )
2022-12-03 21:36:52 +01:00
dupeno + + ;
2022-12-16 18:17:31 +01:00
while ( std : : find_if ( m_lTouchDevices . begin ( ) , m_lTouchDevices . end ( ) ,
[ & ] ( const STouchDevice & other ) { return other . name = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_lTouchDevices . end ( ) )
2022-12-03 21:36:52 +01:00
dupeno + + ;
2022-12-16 18:17:31 +01:00
while ( std : : find_if ( m_lTabletPads . begin ( ) , m_lTabletPads . end ( ) ,
[ & ] ( const STabletPad & other ) { return other . name = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_lTabletPads . end ( ) )
2022-12-03 21:36:52 +01:00
dupeno + + ;
2022-12-16 18:17:31 +01:00
while ( std : : find_if ( m_lTablets . begin ( ) , m_lTablets . end ( ) ,
[ & ] ( const STablet & other ) { return other . name = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_lTablets . end ( ) )
2022-12-03 21:36:52 +01:00
dupeno + + ;
2022-12-16 18:17:31 +01:00
while ( std : : find_if ( m_lTabletTools . begin ( ) , m_lTabletTools . end ( ) ,
[ & ] ( const STabletTool & other ) { return other . name = = proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ; } ) ! = m_lTabletTools . end ( ) )
2022-12-03 21:36:52 +01:00
dupeno + + ;
return proposedNewName + ( dupeno = = 0 ? " " : ( " - " + std : : to_string ( dupeno ) ) ) ;
}
2022-12-10 15:43:46 +01:00
SConstraint * CInputManager : : constraintFromWlr ( wlr_pointer_constraint_v1 * constraint ) {
for ( auto & c : m_lConstraints ) {
if ( c . constraint = = constraint )
return & c ;
}
return nullptr ;
}
2023-01-11 18:38:54 +01:00
void CInputManager : : releaseAllMouseButtons ( ) {
const auto buttonsCopy = m_lCurrentlyHeldButtons ;
if ( g_pInputManager - > m_sDrag . drag )
return ;
for ( auto & mb : buttonsCopy ) {
wlr_seat_pointer_notify_button ( g_pCompositor - > m_sSeat . seat , 0 , mb , WLR_BUTTON_RELEASED ) ;
}
m_lCurrentlyHeldButtons . clear ( ) ;
}
2023-02-18 23:35:31 +01:00
void CInputManager : : setCursorIconOnBorder ( CWindow * w ) {
// do not override cursor icons set by mouse binds
if ( g_pKeybindManager - > m_bIsMouseBindActive ) {
m_eBorderIconDirection = BORDERICON_NONE ;
return ;
}
2023-04-04 00:15:33 +02:00
static auto * const PROUNDING = & g_pConfigManager - > getConfigValuePtr ( " decoration:rounding " ) - > intValue ;
static const auto * PEXTENDBORDERGRAB = & g_pConfigManager - > getConfigValuePtr ( " general:extend_border_grab_area " ) - > intValue ;
2023-08-17 10:13:19 +02:00
const int BORDERSIZE = w - > getRealBorderSize ( ) ;
2023-02-18 23:35:31 +01:00
// give a small leeway (10 px) for corner icon
2023-08-17 10:13:19 +02:00
const auto CORNER = * PROUNDING + BORDERSIZE + 10 ;
2023-04-04 00:15:33 +02:00
const auto mouseCoords = getMouseCoordsInternal ( ) ;
2023-11-04 18:03:05 +01:00
CBox box = w - > getWindowMainSurfaceBox ( ) ;
2023-04-04 00:15:33 +02:00
eBorderIconDirection direction = BORDERICON_NONE ;
2023-11-04 18:03:05 +01:00
CBox boxFullGrabInput = { box . x - * PEXTENDBORDERGRAB - BORDERSIZE , box . y - * PEXTENDBORDERGRAB - BORDERSIZE , box . width + 2 * ( * PEXTENDBORDERGRAB + BORDERSIZE ) ,
box . height + 2 * ( * PEXTENDBORDERGRAB + BORDERSIZE ) } ;
2023-04-04 00:15:33 +02:00
2023-10-30 00:37:12 +01:00
if ( w - > hasPopupAt ( mouseCoords ) )
2023-04-04 00:15:33 +02:00
direction = BORDERICON_NONE ;
2023-11-04 18:03:05 +01:00
else if ( ! boxFullGrabInput . containsPoint ( mouseCoords ) | | ( ! m_lCurrentlyHeldButtons . empty ( ) & & ! currentlyDraggedWindow ) )
2023-10-30 00:37:12 +01:00
direction = BORDERICON_NONE ;
else {
bool onDeco = false ;
2023-11-04 14:10:52 +01:00
for ( auto & wd : w - > m_dWindowDecorations ) {
if ( ! ( wd - > getDecorationFlags ( ) & DECORATION_ALLOWS_MOUSE_INPUT ) )
2023-10-30 00:37:12 +01:00
continue ;
2023-11-11 15:37:17 +01:00
if ( g_pDecorationPositioner - > getWindowDecorationBox ( wd . get ( ) ) . containsPoint ( mouseCoords ) ) {
2023-10-30 00:37:12 +01:00
onDeco = true ;
break ;
}
}
if ( onDeco )
2023-02-18 23:35:31 +01:00
direction = BORDERICON_NONE ;
2023-10-30 00:37:12 +01:00
else {
2023-11-04 18:03:05 +01:00
if ( box . containsPoint ( mouseCoords ) ) {
2023-10-30 00:37:12 +01: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-30 00:37:12 +01: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 ;
}
}