Platform/Unix/X11Mouse: use X11Display::getFocused() to get the coordinates relative to the focused window.
This commit is contained in:
parent
227d58725d
commit
f71cfa86f2
2 changed files with 27 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -29,12 +29,16 @@ protected :
|
|||
|
||||
virtual void update(InputModule *input);
|
||||
|
||||
void updateFocusedWindow();
|
||||
|
||||
protected :
|
||||
::Display* m_disp;
|
||||
::Window m_win;
|
||||
::Window m_win; // Focused window.
|
||||
|
||||
Vector2f m_position;
|
||||
|
||||
Vector2f m_abs_position;
|
||||
|
||||
unsigned int m_btn_state;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue