1
0
Fork 0

Platform/Unix/X11Mouse: use X11Display::getFocused() to get the coordinates relative to the focused window.

This commit is contained in:
Henrik Hautakoski 2020-12-20 16:09:16 +01:00
parent 227d58725d
commit f71cfa86f2
2 changed files with 27 additions and 7 deletions

View file

@ -1,6 +1,7 @@
#include <Spectre/System/Event.h>
#include <Spectre/System/Log.h>
#include "X11Display.h"
#include "X11Mouse.h"
#include "X11SharedDisplay.h"
@ -23,17 +24,17 @@ X11Mouse::~X11Mouse()
void X11Mouse::init()
{
m_disp = XGetDisplay();
updateFocusedWindow();
}
Vector2f X11Mouse::getPosition() const
{
// TODO: Translate to window.
return m_position;
}
Vector2f X11Mouse::getAbsPosition() const
{
return m_position;
return m_abs_position;
}
bool X11Mouse::isButtonDown(Mouse::Button button) const
@ -58,15 +59,30 @@ void X11Mouse::update(InputModule *input)
::Window root, child;
int rx, ry, x = 0, y = 0;
updateFocusedWindow();
// Query position and button state.
XQueryPointer(m_disp, ::XDefaultRootWindow(m_disp),
XQueryPointer(m_disp,
m_win ? m_win : ::XDefaultRootWindow(m_disp),
&root, &child,
&rx, &ry,
&x, &y, &m_btn_state);
// Update position
m_position.x = x;
m_position.y = y;
// Update abs position (relative to root).
m_abs_position.x = rx;
m_abs_position.y = ry;
// Update window position.
if (m_win) {
m_position.x = x;
m_position.y = y;
}
}
void X11Mouse::updateFocusedWindow()
{
X11Display *focus = X11Display::getFocused();
m_win = focus ? (::Window) focus->getHandle() : 0;
}
bool X11Mouse::handleMessage(XEvent* xevent, Event& event)