Browse Source

Platform: don't leak XApplication modifiers into buttons and vice versa.

Couldn't discover this without having them actually printed in the test.
pull/651/head
Vladimír Vondruš 2 years ago
parent
commit
e19dab0a65
  1. 6
      src/Magnum/Platform/AbstractXApplication.cpp
  2. 18
      src/Magnum/Platform/AbstractXApplication.h

6
src/Magnum/Platform/AbstractXApplication.cpp

@ -169,18 +169,18 @@ bool AbstractXApplication::mainLoopIteration() {
/* Key/mouse events */ /* Key/mouse events */
case KeyPress: case KeyPress:
case KeyRelease: { case KeyRelease: {
KeyEvent e(static_cast<KeyEvent::Key>(XLookupKeysym(&event.xkey, 0)), static_cast<InputEvent::Modifier>(event.xkey.state), {event.xkey.x, event.xkey.y}); KeyEvent e(static_cast<KeyEvent::Key>(XLookupKeysym(&event.xkey, 0)), event.xkey.state, {event.xkey.x, event.xkey.y});
event.type == KeyPress ? keyPressEvent(e) : keyReleaseEvent(e); event.type == KeyPress ? keyPressEvent(e) : keyReleaseEvent(e);
} break; } break;
case ButtonPress: case ButtonPress:
case ButtonRelease: { case ButtonRelease: {
MouseEvent e(static_cast<MouseEvent::Button>(event.xbutton.button), static_cast<InputEvent::Modifier>(event.xkey.state), {event.xbutton.x, event.xbutton.y}); MouseEvent e(static_cast<MouseEvent::Button>(event.xbutton.button), event.xkey.state, {event.xbutton.x, event.xbutton.y});
event.type == ButtonPress ? mousePressEvent(e) : mouseReleaseEvent(e); event.type == ButtonPress ? mousePressEvent(e) : mouseReleaseEvent(e);
} break; } break;
/* Mouse move events */ /* Mouse move events */
case MotionNotify: { case MotionNotify: {
MouseMoveEvent e(static_cast<InputEvent::Modifier>(event.xmotion.state), {event.xmotion.x, event.xmotion.y}); MouseMoveEvent e(event.xmotion.state, {event.xmotion.x, event.xmotion.y});
mouseMoveEvent(e); mouseMoveEvent(e);
} break; } break;
} }

18
src/Magnum/Platform/AbstractXApplication.h

@ -643,20 +643,24 @@ class AbstractXApplication::InputEvent {
bool isAccepted() const { return _accepted; } bool isAccepted() const { return _accepted; }
/** @brief Modifiers */ /** @brief Modifiers */
Modifiers modifiers() const { return _modifiers; } Modifiers modifiers() const {
return Modifiers(_modifiers & (ShiftMask|ControlMask|Mod1Mask|Mod5Mask|LockMask|Mod2Mask));
}
/** @brief Mouse buttons */ /** @brief Mouse buttons */
Buttons buttons() const { return Button(static_cast<unsigned int>(_modifiers)); } Buttons buttons() const {
return Buttons(_modifiers & (Button1Mask|Button2Mask|Button3Mask));
}
#ifndef DOXYGEN_GENERATING_OUTPUT #ifndef DOXYGEN_GENERATING_OUTPUT
protected: protected:
explicit InputEvent(Modifiers modifiers): _modifiers(modifiers), _accepted(false) {} explicit InputEvent(unsigned int modifiers): _modifiers(modifiers), _accepted(false) {}
~InputEvent() = default; ~InputEvent() = default;
#endif #endif
private: private:
Modifiers _modifiers; unsigned int _modifiers;
bool _accepted; bool _accepted;
}; };
@ -1014,7 +1018,7 @@ class AbstractXApplication::KeyEvent: public AbstractXApplication::InputEvent {
Vector2i position() const { return _position; } Vector2i position() const { return _position; }
private: private:
explicit KeyEvent(Key key, Modifiers modifiers, const Vector2i& position): InputEvent(modifiers), _key(key), _position(position) {} explicit KeyEvent(Key key, unsigned int modifiers, const Vector2i& position): InputEvent(modifiers), _key(key), _position(position) {}
const Key _key; const Key _key;
const Vector2i _position; const Vector2i _position;
@ -1049,7 +1053,7 @@ class AbstractXApplication::MouseEvent: public AbstractXApplication::InputEvent
Vector2i position() const { return _position; } Vector2i position() const { return _position; }
private: private:
explicit MouseEvent(Button button, Modifiers modifiers, const Vector2i& position): InputEvent(modifiers), _button(button), _position(position) {} explicit MouseEvent(Button button, unsigned int modifiers, const Vector2i& position): InputEvent(modifiers), _button(button), _position(position) {}
const Button _button; const Button _button;
const Vector2i _position; const Vector2i _position;
@ -1068,7 +1072,7 @@ class AbstractXApplication::MouseMoveEvent: public AbstractXApplication::InputEv
Vector2i position() const { return _position; } Vector2i position() const { return _position; }
private: private:
explicit MouseMoveEvent(Modifiers modifiers, const Vector2i& position): InputEvent(modifiers), _position(position) {} explicit MouseMoveEvent(unsigned int modifiers, const Vector2i& position): InputEvent(modifiers), _position(position) {}
const Vector2i _position; const Vector2i _position;
}; };

Loading…
Cancel
Save