Platform/Unix/X11Keyboard: only update state and signal key down if we have a focused window.
This commit is contained in:
parent
6c96a3d9a1
commit
080c4f77c3
2 changed files with 21 additions and 3 deletions
|
|
@ -1,6 +1,9 @@
|
|||
|
||||
#include <Spectre/Display/DisplayDescription.h> // FIXME: Weird name clashes with Xlib.h
|
||||
|
||||
#include <string.h>
|
||||
#include "X11Keyboard.h"
|
||||
#include "X11Display.h"
|
||||
#include "X11SharedDisplay.h"
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/keysym.h>
|
||||
|
|
@ -202,7 +205,8 @@ static Keyboard::Key KeySymToKeyboardKey(KeySym key) {
|
|||
}
|
||||
|
||||
X11Keyboard::X11Keyboard() :
|
||||
m_disp(NULL)
|
||||
m_disp(NULL),
|
||||
m_win(0)
|
||||
{
|
||||
memset(m_key_state, 0, sizeof(m_key_state) / sizeof(m_key_state[0]));
|
||||
}
|
||||
|
|
@ -223,6 +227,12 @@ bool X11Keyboard::isKeyDown(Keyboard::Key key)
|
|||
{
|
||||
KeySym sym;
|
||||
|
||||
// Only signal that a button is down
|
||||
// if we have focus on a window.
|
||||
if (!m_win) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch(key) {
|
||||
// Letters
|
||||
case Keyboard::Key::A : sym = XK_a; break;
|
||||
|
|
@ -350,8 +360,15 @@ bool X11Keyboard::handleMessage(XKeyEvent* xkeyevent, Event& event)
|
|||
|
||||
void X11Keyboard::update(InputModule *input)
|
||||
{
|
||||
// Query keyboard state.
|
||||
::XQueryKeymap(m_disp, m_key_state);
|
||||
X11Display *focus = X11Display::getFocused();
|
||||
m_win = focus ? (::Window) focus->getHandle() : 0;
|
||||
|
||||
// If we have focus.
|
||||
if (m_win) {
|
||||
|
||||
// Query keyboard state.
|
||||
::XQueryKeymap(m_disp, m_key_state);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace sp
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ protected :
|
|||
|
||||
private :
|
||||
::Display* m_disp;
|
||||
::Window m_win; // Focused window
|
||||
|
||||
// Cached keyboard state.
|
||||
char m_key_state[32];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue