Fixed error in Mouse::Set/GetPosition when the given window was already closed
This commit is contained in:
parent
61adc51d09
commit
73665bd50a
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user