diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 4dffe89eb6..f509c09679 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -248,7 +248,7 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) { if( !justWarped ) { - m_parentPanel->WarpPointer( x + warpX, y + warpY ); + KIPLATFORM::UI::WarpPointer( m_parentPanel, x + warpX, y + warpY ); m_dragStartPoint += VECTOR2D( warpX, warpY ); justWarped = true; } @@ -288,7 +288,7 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) { if( !justWarped ) { - m_parentPanel->WarpPointer( x, y + warpY ); + KIPLATFORM::UI::WarpPointer( m_parentPanel, x, y + warpY ); m_dragStartPoint += VECTOR2D( 0, warpY ); justWarped = true; } @@ -741,17 +741,17 @@ void WX_VIEW_CONTROLS::WarpCursor( const VECTOR2D& aPosition, bool aWorldCoordin if( aWarpView ) { m_view->SetCenter( clampedPosition ); - m_parentPanel->WarpPointer( screenSize.x / 2, screenSize.y / 2 ); + KIPLATFORM::UI::WarpPointer( m_parentPanel, screenSize.x / 2, screenSize.y / 2 ); } } else { - m_parentPanel->WarpPointer( screenPos.x, screenPos.y ); + KIPLATFORM::UI::WarpPointer( m_parentPanel, screenPos.x, screenPos.y ); } } else { - m_parentPanel->WarpPointer( aPosition.x, aPosition.y ); + KIPLATFORM::UI::WarpPointer( m_parentPanel, aPosition.x, aPosition.y ); } refreshMouse(); @@ -766,7 +766,7 @@ void WX_VIEW_CONTROLS::CenterOnCursor() const if( GetMousePosition( false ) != screenCenter ) { m_view->SetCenter( GetCursorPosition() ); - m_parentPanel->WarpPointer( KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) ); + KIPLATFORM::UI::WarpPointer( m_parentPanel, KiROUND( screenSize.x / 2 ), KiROUND( screenSize.y / 2 ) ); } } @@ -877,7 +877,7 @@ void WX_VIEW_CONTROLS::handleCursorCapture( int x, int y ) } if( warp ) - m_parentPanel->WarpPointer( x, y ); + KIPLATFORM::UI::WarpPointer( m_parentPanel, x, y ); } } diff --git a/libs/kiplatform/gtk/ui.cpp b/libs/kiplatform/gtk/ui.cpp index 0cf91ad6d5..f81091546a 100644 --- a/libs/kiplatform/gtk/ui.cpp +++ b/libs/kiplatform/gtk/ui.cpp @@ -26,7 +26,7 @@ #include #include - +#include bool KIPLATFORM::UI::IsDarkTheme() { @@ -81,6 +81,7 @@ bool KIPLATFORM::UI::IsStockCursorOk( wxStockCursor aCursor ) case wxCURSOR_BULLSEYE: case wxCURSOR_HAND: case wxCURSOR_ARROW: + case wxCURSOR_BLANK: return true; default: return false; @@ -134,3 +135,26 @@ void KIPLATFORM::UI::SetOverlayScrolling( const wxWindow* aWindow, bool overlay gtk_scrolled_window_set_overlay_scrolling( GTK_SCROLLED_WINDOW( aWindow->GetHandle() ), overlay ); } + + +void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) +{ + if( !wxGetEnv( wxT( "WAYLAND_DISPLAY" ), nullptr ) ) + { + aWindow->WarpPointer( aX, aY ); + } + else + { + GdkDisplay* disp = gtk_widget_get_display( static_cast( aWindow->GetHandle() ) ); + GdkWindow* win = gdk_display_get_window_at_pointer( disp, nullptr, nullptr ); + GdkCursor* blank_cursor = gdk_cursor_new_for_display( disp, GDK_BLANK_CURSOR ); + GdkCursor* cur_cursor = gdk_window_get_cursor( win ); + + if( cur_cursor ) + g_object_ref( cur_cursor ); + + gdk_window_set_cursor( win, blank_cursor ); + aWindow->WarpPointer( aX, aY ); + gdk_window_set_cursor( win, cur_cursor ); + } +} diff --git a/libs/kiplatform/include/kiplatform/ui.h b/libs/kiplatform/include/kiplatform/ui.h index bf4bd7f79e..c6478f05e7 100644 --- a/libs/kiplatform/include/kiplatform/ui.h +++ b/libs/kiplatform/include/kiplatform/ui.h @@ -116,6 +116,14 @@ namespace KIPLATFORM * Implemented only on GTK. */ void SetOverlayScrolling( const wxWindow* aWindow, bool overlay ); + + /** + * Move the mouse cursor to a specific position relative to the window + * @param aWindow Window in which to position to mouse cursor + * @param aX destination x position + * @param aY destination y position + */ + void WarpPointer( wxWindow* aWindow, int aX, int aY ); } } diff --git a/libs/kiplatform/msw/ui.cpp b/libs/kiplatform/msw/ui.cpp index 7146b79eed..03f2d68b15 100644 --- a/libs/kiplatform/msw/ui.cpp +++ b/libs/kiplatform/msw/ui.cpp @@ -132,3 +132,9 @@ void KIPLATFORM::UI::SetOverlayScrolling( const wxWindow* aWindow, bool overlay { // Not implemented } + + +void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) +{ + aWindow->WarpPointer( aX, aY ); +} diff --git a/libs/kiplatform/osx/ui.mm b/libs/kiplatform/osx/ui.mm index 94c9ae8365..25cf2b9e70 100644 --- a/libs/kiplatform/osx/ui.mm +++ b/libs/kiplatform/osx/ui.mm @@ -132,3 +132,9 @@ void KIPLATFORM::UI::SetOverlayScrolling( const wxWindow* aWindow, bool overlay { // Not implemented } + + +void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) +{ + aWindow->WarpPointer( aX, aY ); +}