diff --git a/src/SFML/Window/Linux/InputImpl.cpp b/src/SFML/Window/Linux/InputImpl.cpp index 44ef05aeb..83eb50a19 100644 --- a/src/SFML/Window/Linux/InputImpl.cpp +++ b/src/SFML/Window/Linux/InputImpl.cpp @@ -228,16 +228,24 @@ Vector2i InputImpl::GetMousePosition() //////////////////////////////////////////////////////////// Vector2i InputImpl::GetMousePosition(const Window& relativeTo) { - // we don't care about these but they are required - ::Window root, child; - int gx, gy; - unsigned int buttons; + WindowHandle handle = relativeTo.GetSystemHandle(); + if (handle) + { + // we don't care about these but they are required + ::Window root, child; + int gx, gy; + unsigned int buttons; - int x = 0; - int y = 0; - XQueryPointer(global.display, relativeTo.GetSystemHandle(), &root, &child, &gx, &gy, &x, &y, &buttons); + int x = 0; + int y = 0; + XQueryPointer(global.display, handle, &root, &child, &gx, &gy, &x, &y, &buttons); - return Vector2i(x, y); + return Vector2i(x, y); + } + else + { + return Vector2i(); + } } @@ -252,8 +260,12 @@ void InputImpl::SetMousePosition(const Vector2i& position) //////////////////////////////////////////////////////////// void InputImpl::SetMousePosition(const Vector2i& position, const Window& relativeTo) { - XWarpPointer(global.display, None, relativeTo.GetSystemHandle(), 0, 0, 0, 0, position.x, position.y); - XFlush(global.display); + WindowHandle handle = relativeTo.GetSystemHandle(); + if (handle) + { + XWarpPointer(global.display, None, handle, 0, 0, 0, 0, position.x, position.y); + XFlush(global.display); + } } } // namespace priv diff --git a/src/SFML/Window/Win32/InputImpl.cpp b/src/SFML/Window/Win32/InputImpl.cpp index 2c509173a..8122e581a 100644 --- a/src/SFML/Window/Win32/InputImpl.cpp +++ b/src/SFML/Window/Win32/InputImpl.cpp @@ -178,10 +178,18 @@ Vector2i InputImpl::GetMousePosition() //////////////////////////////////////////////////////////// Vector2i InputImpl::GetMousePosition(const Window& relativeTo) { - POINT point; - GetCursorPos(&point); - ScreenToClient(relativeTo.GetSystemHandle(), &point); - return Vector2i(point.x, point.y); + WindowHandle handle = relativeTo.GetSystemHandle(); + if (handle) + { + POINT point; + GetCursorPos(&point); + ScreenToClient(handle, &point); + return Vector2i(point.x, point.y); + } + else + { + return Vector2i(); + } } @@ -195,9 +203,13 @@ void InputImpl::SetMousePosition(const Vector2i& position) //////////////////////////////////////////////////////////// void InputImpl::SetMousePosition(const Vector2i& position, const Window& relativeTo) { - POINT point = {position.x, position.y}; - ClientToScreen(relativeTo.GetSystemHandle(), &point); - SetCursorPos(point.x, point.y); + WindowHandle handle = relativeTo.GetSystemHandle(); + if (handle) + { + POINT point = {position.x, position.y}; + ClientToScreen(handle, &point); + SetCursorPos(point.x, point.y); + } } } // namespace priv