From 3ee2086f95ca26d7eb43e7cea20784bc79f2bb43 Mon Sep 17 00:00:00 2001 From: Alex Shvartzkop Date: Fri, 22 Sep 2023 05:10:42 +0300 Subject: [PATCH] Don't freak out when can't warp the pointer. --- common/view/wx_view_controls.cpp | 18 ++++++++++++------ libs/kiplatform/gtk/ui.cpp | 13 ++++++++++++- libs/kiplatform/include/kiplatform/ui.h | 3 ++- libs/kiplatform/msw/ui.cpp | 3 ++- libs/kiplatform/osx/ui.mm | 3 ++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/common/view/wx_view_controls.cpp b/common/view/wx_view_controls.cpp index 973bbe0b8c..403219667e 100644 --- a/common/view/wx_view_controls.cpp +++ b/common/view/wx_view_controls.cpp @@ -276,9 +276,11 @@ void WX_VIEW_CONTROLS::onMotion( wxMouseEvent& aEvent ) { if( !justWarped ) { - KIPLATFORM::UI::WarpPointer( m_parentPanel, x + warpX, y + warpY ); - m_dragStartPoint += VECTOR2D( warpX, warpY ); - justWarped = true; + if( KIPLATFORM::UI::WarpPointer( m_parentPanel, x + warpX, y + warpY ) ) + { + m_dragStartPoint += VECTOR2D( warpX, warpY ); + justWarped = true; + } } else justWarped = false; @@ -837,9 +839,13 @@ void WX_VIEW_CONTROLS::CenterOnCursor() if( GetMousePosition( false ) != screenCenter ) { - m_view->SetCenter( GetCursorPosition() ); - m_dragStartPoint = screenCenter; - KIPLATFORM::UI::WarpPointer( m_parentPanel, screenCenter.x, screenCenter.y ); + VECTOR2D newCenter = GetCursorPosition(); + + if( KIPLATFORM::UI::WarpPointer( m_parentPanel, screenCenter.x, screenCenter.y ) ) + { + m_view->SetCenter( newCenter ); + m_dragStartPoint = screenCenter; + } } } diff --git a/libs/kiplatform/gtk/ui.cpp b/libs/kiplatform/gtk/ui.cpp index fc979a6cef..32bdda0223 100644 --- a/libs/kiplatform/gtk/ui.cpp +++ b/libs/kiplatform/gtk/ui.cpp @@ -250,11 +250,12 @@ wxPoint KIPLATFORM::UI::GetMousePosition() #endif -void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) +bool KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) { if( !wxGetEnv( wxT( "WAYLAND_DISPLAY" ), nullptr ) ) { aWindow->WarpPointer( aX, aY ); + return true; } else { @@ -277,7 +278,13 @@ void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) wxLogTrace( traceWayland, wxS( "Set warped from %d %d to %d %d" ), s_warped_from.x, s_warped_from.y, s_warped_to.x, s_warped_to.y ); + + return true; } + + wxLogTrace( traceWayland, wxS( "*** Warp to %d %d failed ***" ), aX, aY ); + + return false; } #endif #ifdef GDK_WINDOWING_X11 @@ -293,9 +300,13 @@ void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) gdk_window_set_cursor( win, blank_cursor ); aWindow->WarpPointer( aX, aY ); gdk_window_set_cursor( win, cur_cursor ); + + return true; } #endif } + + return false; } diff --git a/libs/kiplatform/include/kiplatform/ui.h b/libs/kiplatform/include/kiplatform/ui.h index d9ad50eab6..482fa0a08e 100644 --- a/libs/kiplatform/include/kiplatform/ui.h +++ b/libs/kiplatform/include/kiplatform/ui.h @@ -149,8 +149,9 @@ namespace KIPLATFORM * @param aWindow Window in which to position to mouse cursor * @param aX destination x position * @param aY destination y position + * @return true if the warp was successful */ - void WarpPointer( wxWindow* aWindow, int aX, int aY ); + bool WarpPointer( wxWindow* aWindow, int aX, int aY ); /** * Configures the IME mode of a given control handle diff --git a/libs/kiplatform/msw/ui.cpp b/libs/kiplatform/msw/ui.cpp index b6c4b707c1..de556e16d6 100644 --- a/libs/kiplatform/msw/ui.cpp +++ b/libs/kiplatform/msw/ui.cpp @@ -164,9 +164,10 @@ wxPoint KIPLATFORM::UI::GetMousePosition() } -void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) +bool KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) { aWindow->WarpPointer( aX, aY ); + return true; } diff --git a/libs/kiplatform/osx/ui.mm b/libs/kiplatform/osx/ui.mm index 230d6ad8ad..43f179cf3d 100644 --- a/libs/kiplatform/osx/ui.mm +++ b/libs/kiplatform/osx/ui.mm @@ -172,9 +172,10 @@ wxPoint KIPLATFORM::UI::GetMousePosition() } -void KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) +bool KIPLATFORM::UI::WarpPointer( wxWindow* aWindow, int aX, int aY ) { aWindow->WarpPointer( aX, aY ); + return true; }