Fixed error in Mouse::Set/GetPosition when the given window was already closed
This commit is contained in:
parent
61adc51d09
commit
73665bd50a
@ -227,6 +227,9 @@ Vector2i InputImpl::GetMousePosition()
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.GetSystemHandle();
|
||||
if (handle)
|
||||
{
|
||||
// we don't care about these but they are required
|
||||
::Window root, child;
|
||||
@ -235,10 +238,15 @@ Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
||||
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
XQueryPointer(global.display, relativeTo.GetSystemHandle(), &root, &child, &gx, &gy, &x, &y, &buttons);
|
||||
XQueryPointer(global.display, handle, &root, &child, &gx, &gy, &x, &y, &buttons);
|
||||
|
||||
return Vector2i(x, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Vector2i();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -252,9 +260,13 @@ 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);
|
||||
WindowHandle handle = relativeTo.GetSystemHandle();
|
||||
if (handle)
|
||||
{
|
||||
XWarpPointer(global.display, None, handle, 0, 0, 0, 0, position.x, position.y);
|
||||
XFlush(global.display);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
@ -177,12 +177,20 @@ Vector2i InputImpl::GetMousePosition()
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
Vector2i InputImpl::GetMousePosition(const Window& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.GetSystemHandle();
|
||||
if (handle)
|
||||
{
|
||||
POINT point;
|
||||
GetCursorPos(&point);
|
||||
ScreenToClient(relativeTo.GetSystemHandle(), &point);
|
||||
ScreenToClient(handle, &point);
|
||||
return Vector2i(point.x, point.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Vector2i();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@ -194,11 +202,15 @@ void InputImpl::SetMousePosition(const Vector2i& position)
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
void InputImpl::SetMousePosition(const Vector2i& position, const Window& relativeTo)
|
||||
{
|
||||
WindowHandle handle = relativeTo.GetSystemHandle();
|
||||
if (handle)
|
||||
{
|
||||
POINT point = {position.x, position.y};
|
||||
ClientToScreen(relativeTo.GetSystemHandle(), &point);
|
||||
ClientToScreen(handle, &point);
|
||||
SetCursorPos(point.x, point.y);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace priv
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user