2022-03-17 15:53:45 +01:00
# include "InputManager.hpp"
# include "../Compositor.hpp"
2022-03-24 15:57:46 +01:00
void CInputManager : : onMouseMoved ( wlr_pointer_motion_event * e ) {
2022-03-17 15:53:45 +01:00
2022-03-19 20:30:21 +01:00
float sensitivity = g_pConfigManager - > getFloat ( " general:sensitivity " ) ;
2022-03-17 15:53:45 +01:00
2022-04-18 13:13:41 +02:00
if ( g_pConfigManager - > getInt ( " general:apply_sens_to_raw " ) = = 1 )
wlr_relative_pointer_manager_v1_send_relative_motion ( g_pCompositor - > m_sWLRRelPointerMgr , g_pCompositor - > m_sSeat . seat , ( uint64_t ) e - > time_msec * 1000 , e - > delta_x * sensitivity , e - > delta_y * sensitivity , e - > unaccel_dx * sensitivity , e - > unaccel_dy * sensitivity ) ;
else
wlr_relative_pointer_manager_v1_send_relative_motion ( g_pCompositor - > m_sWLRRelPointerMgr , g_pCompositor - > m_sSeat . seat , ( uint64_t ) e - > time_msec * 1000 , e - > delta_x , e - > delta_y , e - > unaccel_dx , e - > unaccel_dy ) ;
2022-04-17 21:40:04 +02:00
2022-03-24 15:57:46 +01:00
wlr_cursor_move ( g_pCompositor - > m_sWLRCursor , & e - > pointer - > base , e - > delta_x * sensitivity , e - > delta_y * sensitivity ) ;
2022-03-18 20:42:49 +01:00
2022-03-18 23:52:36 +01:00
mouseMoveUnified ( e - > time_msec ) ;
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-04-13 20:19:40 +02:00
void CInputManager : : mouseMoveUnified ( uint32_t time , bool refocus ) {
2022-03-18 23:52:36 +01:00
2022-04-28 17:57:24 +02:00
if ( ! g_pCompositor - > m_bReadyToProcess )
return ;
2022-05-12 12:13:02 +02:00
if ( ! g_pCompositor - > m_sSeat . mouse ) {
Debug : : log ( ERR , " BUG THIS: Mouse move on mouse nullptr! " ) ;
return ;
}
2022-03-31 17:25:23 +02:00
// update stuff
updateDragIcon ( ) ;
2022-04-13 20:19:40 +02:00
g_pLayoutManager - > getCurrentLayout ( ) - > onMouseMove ( getMouseCoordsInternal ( ) ) ;
2022-04-01 23:31:12 +02:00
2022-03-31 17:25:23 +02:00
// focus
2022-03-20 14:36:55 +01:00
wlr_surface * foundSurface = nullptr ;
Vector2D mouseCoords = getMouseCoordsInternal ( ) ;
2022-03-31 17:25:23 +02:00
2022-03-20 14:36:55 +01:00
const auto PMONITOR = g_pCompositor - > getMonitorFromCursor ( ) ;
2022-04-11 19:51:37 +02:00
if ( PMONITOR & & PMONITOR ! = g_pCompositor - > m_pLastMonitor ) {
2022-03-30 20:16:23 +02:00
g_pCompositor - > m_pLastMonitor = PMONITOR ;
2022-03-31 17:25:23 +02:00
2022-04-11 19:51:37 +02:00
// set active workspace and deactivate all other in wlr
2022-04-28 17:55:25 +02:00
g_pCompositor - > deactivateAllWLRWorkspaces ( g_pCompositor - > getWorkspaceByID ( PMONITOR - > activeWorkspace ) - > m_pWlrHandle ) ;
2022-04-11 19:51:37 +02:00
wlr_ext_workspace_handle_v1_set_active ( g_pCompositor - > getWorkspaceByID ( PMONITOR - > activeWorkspace ) - > m_pWlrHandle , true ) ;
}
2022-03-22 21:59:14 +01:00
Vector2D surfaceCoords ;
2022-03-30 20:16:23 +02:00
Vector2D surfacePos = Vector2D ( - 1337 , - 1337 ) ;
2022-04-02 18:57:09 +02:00
CWindow * pFoundWindow = nullptr ;
2022-03-20 14:36:55 +01:00
2022-04-25 21:49:45 +02:00
// overlay is above fullscreen
if ( ! foundSurface )
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLists [ ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY ] , & surfaceCoords ) ;
// 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-04-18 17:16:01 +02:00
if ( PWORKSPACE - > m_bHasFullscreenWindow & & ! foundSurface ) {
2022-04-11 19:51:37 +02:00
pFoundWindow = g_pCompositor - > getFullscreenWindowOnWorkspace ( PWORKSPACE - > m_iID ) ;
2022-04-02 18:57:09 +02:00
for ( auto w = g_pCompositor - > m_lWindows . rbegin ( ) ; w ! = g_pCompositor - > m_lWindows . rend ( ) ; + + w ) {
2022-04-23 14:16:02 +02:00
wlr_box box = { w - > m_vRealPosition . vec ( ) . x , w - > m_vRealPosition . vec ( ) . y , w - > m_vRealSize . vec ( ) . x , w - > m_vRealSize . vec ( ) . y } ;
2022-04-02 18:57:09 +02:00
if ( w - > m_iWorkspaceID = = pFoundWindow - > m_iWorkspaceID & & w - > m_bIsMapped & & w - > m_bCreatedOverFullscreen & & wlr_box_contains_point ( & box , mouseCoords . x , mouseCoords . y ) ) {
foundSurface = g_pXWaylandManager - > getWindowSurface ( & ( * w ) ) ;
if ( foundSurface )
2022-04-23 14:16:02 +02:00
surfacePos = w - > m_vRealPosition . vec ( ) ;
2022-04-02 18:57:09 +02:00
break ;
2022-03-30 20:16:23 +02:00
}
2022-04-02 18:57:09 +02:00
}
if ( pFoundWindow & & ! foundSurface ) {
if ( pFoundWindow - > m_bIsX11 ) {
foundSurface = g_pXWaylandManager - > getWindowSurface ( pFoundWindow ) ;
if ( foundSurface )
2022-04-23 14:16:02 +02:00
surfacePos = pFoundWindow - > m_vRealPosition . vec ( ) ;
2022-04-02 18:57:09 +02:00
} else {
foundSurface = g_pCompositor - > vectorWindowToSurface ( mouseCoords , pFoundWindow , surfaceCoords ) ;
}
}
2022-03-21 19:18:33 +01:00
}
2022-03-20 14:36:55 +01:00
if ( ! foundSurface )
2022-03-22 21:59:14 +01:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLists [ ZWLR_LAYER_SHELL_V1_LAYER_TOP ] , & surfaceCoords ) ;
2022-03-20 14:36:55 +01:00
// then windows
2022-04-24 11:41:52 +02:00
if ( ! foundSurface ) {
pFoundWindow = g_pCompositor - > vectorToWindowIdeal ( mouseCoords ) ;
if ( pFoundWindow ) {
if ( ! pFoundWindow - > m_bIsX11 ) {
foundSurface = g_pCompositor - > vectorWindowToSurface ( mouseCoords , pFoundWindow , surfaceCoords ) ;
} else {
foundSurface = g_pXWaylandManager - > getWindowSurface ( pFoundWindow ) ;
surfacePos = pFoundWindow - > m_vRealPosition . vec ( ) ;
}
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 )
2022-03-22 21:59:14 +01:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLists [ ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM ] , & surfaceCoords ) ;
2022-03-20 14:36:55 +01:00
if ( ! foundSurface )
2022-03-22 21:59:14 +01:00
foundSurface = g_pCompositor - > vectorToLayerSurface ( mouseCoords , & PMONITOR - > m_aLayerSurfaceLists [ ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND ] , & surfaceCoords ) ;
2022-03-20 14:36:55 +01:00
2022-03-18 23:52:36 +01:00
2022-03-20 14:36:55 +01:00
if ( ! foundSurface ) {
2022-03-18 23:52:36 +01:00
wlr_xcursor_manager_set_cursor_image ( g_pCompositor - > m_sWLRXCursorMgr , " left_ptr " , g_pCompositor - > m_sWLRCursor ) ;
2022-03-22 18:29:13 +01:00
wlr_seat_pointer_clear_focus ( g_pCompositor - > m_sSeat . seat ) ;
2022-03-18 23:52:36 +01:00
return ;
}
if ( time )
2022-03-22 18:29:13 +01:00
wlr_idle_notify_activity ( g_pCompositor - > m_sWLRIdle , g_pCompositor - > m_sSeat . seat ) ;
2022-03-18 23:52:36 +01:00
2022-04-24 17:42:59 +02:00
Vector2D surfaceLocal = surfacePos = = Vector2D ( - 1337 , - 1337 ) ? surfaceCoords : mouseCoords - surfacePos ;
2022-03-18 23:52:36 +01:00
2022-04-13 20:19:40 +02:00
if ( pFoundWindow ) {
if ( g_pConfigManager - > getInt ( " input:follow_mouse " ) = = 0 & & ! refocus ) {
if ( pFoundWindow ! = g_pCompositor - > m_pLastWindow & & g_pCompositor - > windowValidMapped ( g_pCompositor - > m_pLastWindow ) & & ( g_pCompositor - > m_pLastWindow - > m_bIsFloating ! = pFoundWindow - > m_bIsFloating ) ) {
// enter if change floating style
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
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 ; // don't enter any new surfaces
} else {
g_pCompositor - > focusWindow ( pFoundWindow , foundSurface ) ;
}
}
2022-04-02 18:57:09 +02:00
else
g_pCompositor - > focusSurface ( foundSurface ) ;
2022-03-22 21:59:14 +01:00
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-04-17 21:40:04 +02:00
// constraints
// All constraints TODO: multiple mice?
2022-05-12 16:07:14 +02:00
if ( g_pCompositor - > m_sSeat . mouse - > currentConstraint & & pFoundWindow ) { // TODO: make this match the pFoundWindow in SOME way. We don't want to constrain the mouse on another window.
// XWayland windows sometimes issue constraints weirdly.
2022-04-25 13:40:46 +02:00
const auto CONSTRAINTWINDOW = g_pCompositor - > getConstraintWindow ( g_pCompositor - > m_sSeat . mouse ) ;
2022-04-17 21:40:04 +02:00
2022-05-12 12:13:02 +02:00
if ( ! CONSTRAINTWINDOW ) {
g_pCompositor - > m_sSeat . mouse - > currentConstraint = nullptr ;
} else {
2022-05-12 16:07:14 +02:00
// Native Wayland apps know how 2 constrain themselves.
// XWayland, we just have to accept them. Might cause issues, but thats XWayland for ya.
if ( CONSTRAINTWINDOW - > m_bIsX11 | | pFoundWindow = = CONSTRAINTWINDOW ) {
const auto CONSTRAINTPOS = CONSTRAINTWINDOW - > m_bIsX11 ? Vector2D ( CONSTRAINTWINDOW - > m_uSurface . xwayland - > x , CONSTRAINTWINDOW - > m_uSurface . xwayland - > y ) : CONSTRAINTWINDOW - > m_vRealPosition . vec ( ) ;
const auto CONSTRAINTSIZE = CONSTRAINTWINDOW - > m_bIsX11 ? Vector2D ( CONSTRAINTWINDOW - > m_uSurface . xwayland - > width , CONSTRAINTWINDOW - > m_uSurface . xwayland - > height ) : CONSTRAINTWINDOW - > m_vRealSize . vec ( ) ;
if ( VECINRECT ( mouseCoords , CONSTRAINTPOS . x , CONSTRAINTPOS . y , CONSTRAINTPOS . x + CONSTRAINTSIZE . x , CONSTRAINTPOS . y + CONSTRAINTSIZE . y ) ) {
// todo: this is incorrect, but it will work in most cases for now
// i made this cuz i wanna play minecraft lol
Vector2D deltaToMiddle = CONSTRAINTPOS + CONSTRAINTSIZE / 2.f - mouseCoords ;
wlr_cursor_move ( g_pCompositor - > m_sWLRCursor , g_pCompositor - > m_sSeat . mouse - > mouse , deltaToMiddle . x , deltaToMiddle . y ) ;
}
2022-05-12 12:13:02 +02:00
}
2022-04-17 21:40:04 +02:00
}
}
2022-03-18 20:42:49 +01:00
}
2022-03-24 15:57:46 +01:00
void CInputManager : : onMouseButton ( wlr_pointer_button_event * e ) {
2022-03-22 18:29:13 +01:00
wlr_idle_notify_activity ( g_pCompositor - > m_sWLRIdle , g_pCompositor - > m_sSeat . seat ) ;
2022-03-18 20:42:49 +01:00
2022-03-22 18:29:13 +01:00
const auto PKEYBOARD = wlr_seat_get_keyboard ( g_pCompositor - > m_sSeat . seat ) ;
2022-03-20 18:23:16 +01:00
2022-03-18 20:42:49 +01:00
switch ( e - > state ) {
case WLR_BUTTON_PRESSED :
2022-04-18 13:41:48 +02:00
if ( ! g_pCompositor - > m_sSeat . mouse - > currentConstraint )
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
if ( g_pCompositor - > windowValidMapped ( g_pCompositor - > m_pLastWindow ) & & g_pCompositor - > m_pLastWindow - > m_bIsFloating )
g_pCompositor - > moveWindowToTop ( g_pCompositor - > m_pLastWindow ) ;
2022-03-20 18:23:39 +01:00
if ( ( e - > button = = BTN_LEFT | | e - > button = = BTN_RIGHT ) & & wlr_keyboard_get_modifiers ( PKEYBOARD ) = = ( uint32_t ) g_pConfigManager - > getInt ( " general:main_mod_internal " ) ) {
2022-04-03 13:49:21 +02:00
currentlyDraggedWindow = g_pCompositor - > windowFromCursor ( ) ;
2022-03-20 11:14:24 +01:00
dragButton = e - > button ;
g_pLayoutManager - > getCurrentLayout ( ) - > onBeginDragWindow ( ) ;
2022-03-21 19:18:33 +01:00
return ;
2022-03-20 11:14:24 +01:00
}
2022-03-18 20:42:49 +01:00
break ;
case WLR_BUTTON_RELEASED :
2022-04-03 13:49:21 +02:00
if ( currentlyDraggedWindow ) {
g_pLayoutManager - > getCurrentLayout ( ) - > onEndDragWindow ( ) ;
currentlyDraggedWindow = nullptr ;
dragButton = - 1 ;
}
2022-03-18 20:42:49 +01:00
break ;
}
// 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
Debug : : log ( LOG , " Seat notified of button %i (state %i) on surface %x " , e - > button , e - > state , g_pCompositor - > m_pLastFocus ) ;
}
2022-03-17 16:56:33 +01: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-03-18 23:25:26 +01:00
m_lKeyboards . push_back ( SKeyboard ( ) ) ;
2022-03-17 20:55:04 +01:00
2022-03-18 23:25:26 +01:00
const auto PNEWKEYBOARD = & m_lKeyboards . back ( ) ;
2022-03-17 20:55:04 +01:00
PNEWKEYBOARD - > keyboard = keyboard ;
xkb_rule_names rules ;
const auto CONTEXT = xkb_context_new ( XKB_CONTEXT_NO_FLAGS ) ;
const auto KEYMAP = xkb_keymap_new_from_names ( CONTEXT , & rules , XKB_KEYMAP_COMPILE_NO_FLAGS ) ;
2022-04-19 18:51:00 +02:00
const auto REPEATRATE = g_pConfigManager - > getInt ( " input:repeat_rate " ) ;
const auto REPEATDELAY = g_pConfigManager - > getInt ( " input:repeat_delay " ) ;
2022-03-17 20:55:04 +01:00
wlr_keyboard_set_keymap ( keyboard - > keyboard , KEYMAP ) ;
xkb_keymap_unref ( KEYMAP ) ;
xkb_context_unref ( CONTEXT ) ;
2022-04-19 19:14:46 +02:00
wlr_keyboard_set_repeat_info ( keyboard - > keyboard , std : : max ( 0 , REPEATRATE ) , std : : max ( 0 , REPEATDELAY ) ) ;
2022-03-17 20:55:04 +01:00
2022-03-28 22:31:39 +02:00
PNEWKEYBOARD - > hyprListener_keyboardMod . initCallback ( & keyboard - > keyboard - > events . modifiers , & Events : : listener_keyboardMod , PNEWKEYBOARD , " Keyboard " ) ;
PNEWKEYBOARD - > hyprListener_keyboardKey . initCallback ( & keyboard - > keyboard - > events . key , & Events : : listener_keyboardKey , PNEWKEYBOARD , " Keyboard " ) ;
PNEWKEYBOARD - > hyprListener_keyboardDestroy . initCallback ( & keyboard - > events . destroy , & Events : : listener_keyboardDestroy , PNEWKEYBOARD , " Keyboard " ) ;
2022-03-17 20:55:04 +01:00
2022-03-24 15:57:46 +01:00
wlr_seat_set_keyboard ( g_pCompositor - > m_sSeat . seat , keyboard - > keyboard ) ;
2022-03-19 11:27:19 +01:00
Debug : : log ( LOG , " New keyboard created, pointers Hypr: %x and WLR: %x " , PNEWKEYBOARD , keyboard ) ;
2022-03-24 21:05:34 +01:00
setKeyboardLayout ( ) ;
}
void CInputManager : : setKeyboardLayout ( ) {
const auto RULES = g_pConfigManager - > getString ( " input:kb_rules " ) ;
const auto MODEL = g_pConfigManager - > getString ( " input:kb_model " ) ;
const auto LAYOUT = g_pConfigManager - > getString ( " input:kb_layout " ) ;
const auto VARIANT = g_pConfigManager - > getString ( " input:kb_variant " ) ;
const auto OPTIONS = g_pConfigManager - > getString ( " input:kb_options " ) ;
xkb_rule_names rules = {
. rules = RULES . c_str ( ) ,
. model = MODEL . c_str ( ) ,
. layout = LAYOUT . c_str ( ) ,
. variant = VARIANT . c_str ( ) ,
. options = OPTIONS . c_str ( )
} ;
const auto CONTEXT = xkb_context_new ( XKB_CONTEXT_NO_FLAGS ) ;
const auto KEYMAP = xkb_keymap_new_from_names ( CONTEXT , & rules , XKB_KEYMAP_COMPILE_NO_FLAGS ) ;
if ( ! KEYMAP ) {
Debug : : log ( ERR , " Keyboard layout %s with variant %s (rules: %s, model: %s, options: %s) couldn't have been loaded. " , rules . layout , rules . variant , rules . rules , rules . model , rules . options ) ;
xkb_context_unref ( CONTEXT ) ;
return ;
}
// TODO: configure devices one by one
for ( auto & k : m_lKeyboards )
wlr_keyboard_set_keymap ( k . keyboard - > keyboard , KEYMAP ) ;
xkb_keymap_unref ( KEYMAP ) ;
xkb_context_unref ( CONTEXT ) ;
Debug : : log ( LOG , " Set the keyboard layout to %s and variant to %s " , rules . layout , rules . variant ) ;
2022-03-17 20:55:04 +01:00
}
2022-03-18 22:53:27 +01:00
void CInputManager : : newMouse ( wlr_input_device * mouse ) {
2022-04-17 21:40:04 +02:00
m_lMice . emplace_back ( ) ;
const auto PMOUSE = & m_lMice . back ( ) ;
PMOUSE - > mouse = mouse ;
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 ) ;
if ( libinput_device_config_tap_get_finger_count ( LIBINPUTDEV ) ) // this is for tapping (like on a laptop)
libinput_device_config_tap_set_enabled ( LIBINPUTDEV , LIBINPUT_CONFIG_TAP_ENABLED ) ;
if ( libinput_device_config_scroll_has_natural_scroll ( LIBINPUTDEV ) )
2022-05-06 19:34:48 +02:00
libinput_device_config_scroll_set_natural_scroll_enabled ( LIBINPUTDEV , g_pConfigManager - > getInt ( " input:natural_scroll " ) ) ;
2022-04-19 18:50:18 +02:00
if ( libinput_device_config_dwt_is_available ( LIBINPUTDEV ) ) {
const auto DWT = static_cast < enum libinput_config_dwt_state > ( g_pConfigManager - > getInt ( " input:touchpad:disable_while_typing " ) ! = 0 ) ;
libinput_device_config_dwt_set_enabled ( LIBINPUTDEV , DWT ) ;
}
2022-03-18 22:53:27 +01:00
}
2022-05-12 12:13:02 +02:00
PMOUSE - > hyprListener_destroyMouse . initCallback ( & mouse - > events . destroy , & Events : : listener_destroyMouse , PMOUSE , " Mouse " ) ;
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-04-17 21:40:04 +02:00
g_pCompositor - > m_sSeat . mouse = PMOUSE ;
2022-03-19 11:27:19 +01:00
Debug : : log ( LOG , " New mouse created, pointer WLR: %x " , mouse ) ;
2022-03-18 22:53:27 +01: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
m_lKeyboards . remove ( * pKeyboard ) ;
}
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
g_pCompositor - > m_sSeat . mouse - > currentConstraint = nullptr ;
2022-03-18 23:25:26 +01:00
}
2022-03-24 15:57:46 +01:00
void CInputManager : : onKeyboardKey ( wlr_keyboard_key_event * e , SKeyboard * pKeyboard ) {
2022-03-18 23:06:45 +01:00
const auto KEYCODE = e - > keycode + 8 ; // Because to xkbcommon it's +8 from libinput
2022-03-17 20:55:04 +01:00
2022-03-18 23:06:45 +01:00
const xkb_keysym_t * keysyms ;
int syms = xkb_state_key_get_syms ( pKeyboard - > keyboard - > keyboard - > xkb_state , KEYCODE , & keysyms ) ;
const auto MODS = wlr_keyboard_get_modifiers ( pKeyboard - > keyboard - > keyboard ) ;
2022-03-22 18:29:13 +01:00
wlr_idle_notify_activity ( g_pCompositor - > m_sWLRIdle , g_pCompositor - > m_sSeat . seat ) ;
2022-03-17 20:55:04 +01:00
2022-03-19 22:03:40 +01:00
bool found = false ;
2022-03-18 23:06:45 +01:00
if ( e - > state = = WL_KEYBOARD_KEY_STATE_PRESSED ) {
2022-03-22 22:22:59 +01:00
Debug : : log ( LOG , " Pressed key %i, with the MODMASK being %i " , e - > keycode , MODS ) ;
2022-03-19 17:48:18 +01:00
for ( int i = 0 ; i < syms ; + + i )
2022-03-19 22:03:40 +01:00
found = g_pKeybindManager - > handleKeybinds ( MODS , keysyms [ i ] ) | | found ;
2022-03-19 11:27:19 +01:00
} else if ( e - > state = = WL_KEYBOARD_KEY_STATE_RELEASED ) {
2022-03-19 17:48:18 +01:00
// hee hee
2022-03-18 23:06:45 +01:00
}
2022-03-19 22:03:40 +01:00
if ( ! found ) {
2022-03-24 15:57:46 +01:00
wlr_seat_set_keyboard ( g_pCompositor - > m_sSeat . seat , pKeyboard - > keyboard - > keyboard ) ;
2022-03-22 18:29:13 +01:00
wlr_seat_keyboard_notify_key ( g_pCompositor - > m_sSeat . seat , e - > time_msec , e - > keycode , e - > state ) ;
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-03-24 15:57:46 +01:00
wlr_seat_set_keyboard ( g_pCompositor - > m_sSeat . seat , pKeyboard - > keyboard - > keyboard ) ;
2022-03-22 18:29:13 +01:00
wlr_seat_keyboard_notify_modifiers ( g_pCompositor - > m_sSeat . seat , & pKeyboard - > keyboard - > keyboard - > modifiers ) ;
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 ( ) {
if ( ! g_pInputManager - > m_sDrag . dragIcon )
return ;
switch ( g_pInputManager - > m_sDrag . dragIcon - > drag - > grab_type ) {
case WLR_DRAG_GRAB_KEYBOARD :
break ;
case WLR_DRAG_GRAB_KEYBOARD_POINTER :
g_pInputManager - > m_sDrag . pos = g_pInputManager - > getMouseCoordsInternal ( ) ;
break ;
default :
break ;
}
2022-04-17 21:40:04 +02:00
}
void CInputManager : : recheckConstraint ( SMouse * pMouse ) {
if ( ! pMouse - > currentConstraint )
return ;
const auto PREGION = & pMouse - > currentConstraint - > region ;
if ( pMouse - > currentConstraint - > type = = WLR_POINTER_CONSTRAINT_V1_CONFINED ) {
pixman_region32_copy ( & pMouse - > confinedTo , PREGION ) ;
} else {
pixman_region32_clear ( & pMouse - > confinedTo ) ;
}
2022-04-25 13:40:46 +02:00
const auto PWINDOW = g_pCompositor - > getConstraintWindow ( g_pCompositor - > m_sSeat . mouse ) ;
const auto PWINDOWNAME = PWINDOW ? PWINDOW - > m_szTitle : " " ;
Debug : : log ( LOG , " Constraint rechecked: %i, %i to %i, %i for %x (window name: %s) " , PREGION - > extents . x1 , PREGION - > extents . y1 , PREGION - > extents . x2 , PREGION - > extents . y2 , pMouse - > currentConstraint - > surface , PWINDOWNAME . c_str ( ) ) ;
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 PWINDOW = g_pCompositor - > getWindowFromSurface ( constraint - > surface ) ;
const auto MOUSECOORDS = getMouseCoordsInternal ( ) ;
pMouse - > hyprListener_commitConstraint . removeCallback ( ) ;
if ( pMouse - > currentConstraint ) {
if ( ! constraint ) {
// warpe to hint
if ( constraint - > current . committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT ) {
if ( PWINDOW ) {
2022-04-25 13:40:46 +02:00
if ( PWINDOW - > m_bIsX11 ) {
wlr_cursor_warp ( g_pCompositor - > m_sWLRCursor , nullptr ,
constraint - > current . cursor_hint . x + PWINDOW - > m_uSurface . xwayland - > x , PWINDOW - > m_uSurface . xwayland - > y + PWINDOW - > m_vRealPosition . vec ( ) . y ) ;
wlr_seat_pointer_warp ( constraint - > seat , constraint - > current . cursor_hint . x , constraint - > current . cursor_hint . y ) ;
} else {
wlr_cursor_warp ( g_pCompositor - > m_sWLRCursor , nullptr ,
constraint - > current . cursor_hint . x + PWINDOW - > m_vRealPosition . vec ( ) . x , constraint - > current . cursor_hint . y + PWINDOW - > m_vRealPosition . vec ( ) . y ) ;
2022-04-17 21:40:04 +02:00
2022-04-25 13:40:46 +02:00
wlr_seat_pointer_warp ( constraint - > seat , constraint - > current . cursor_hint . x , constraint - > current . cursor_hint . y ) ;
}
2022-04-17 21:40:04 +02:00
}
}
}
wlr_pointer_constraint_v1_send_deactivated ( pMouse - > currentConstraint ) ;
}
pMouse - > currentConstraint = constraint ;
if ( pixman_region32_not_empty ( & constraint - > current . region ) ) {
pixman_region32_intersect ( & constraint - > region , & constraint - > surface - > input_region , & constraint - > current . region ) ;
} else {
pixman_region32_copy ( & constraint - > region , & constraint - > surface - > input_region ) ;
}
// warp to the constraint
recheckConstraint ( pMouse ) ;
wlr_pointer_constraint_v1_send_activated ( pMouse - > currentConstraint ) ;
pMouse - > hyprListener_commitConstraint . initCallback ( & pMouse - > currentConstraint - > surface - > events . commit , & Events : : listener_commitConstraint , pMouse , " Mouse constraint commit " ) ;
Debug : : log ( LOG , " Constrained mouse to %x " , pMouse - > currentConstraint ) ;
}
void Events : : listener_commitConstraint ( void * owner , void * data ) {
//g_pInputManager->recheckConstraint((SMouse*)owner);
}