mirror of
https://github.com/overte-org/overte.git
synced 2025-07-10 22:18:42 +02:00
Fix functionality sometimes getting stuck if window loses focus
This commit is contained in:
parent
83718ca06d
commit
5d44877f56
2 changed files with 15 additions and 7 deletions
|
@ -3705,7 +3705,10 @@ static bool _altPressed{ false };
|
||||||
|
|
||||||
void Application::keyPressEvent(QKeyEvent* event) {
|
void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
_altPressed = event->key() == Qt::Key_Alt;
|
_altPressed = event->key() == Qt::Key_Alt;
|
||||||
_keysPressed.insert(event->key());
|
|
||||||
|
if (!event->isAutoRepeat()) {
|
||||||
|
_keysPressed.insert(event->key(), *event);
|
||||||
|
}
|
||||||
|
|
||||||
_controllerScriptingInterface->emitKeyPressEvent(event); // send events to any registered scripts
|
_controllerScriptingInterface->emitKeyPressEvent(event); // send events to any registered scripts
|
||||||
// if one of our scripts have asked to capture this event, then stop processing it
|
// if one of our scripts have asked to capture this event, then stop processing it
|
||||||
|
@ -3916,7 +3919,9 @@ void Application::keyPressEvent(QKeyEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::keyReleaseEvent(QKeyEvent* event) {
|
void Application::keyReleaseEvent(QKeyEvent* event) {
|
||||||
|
if (!event->isAutoRepeat()) {
|
||||||
_keysPressed.remove(event->key());
|
_keysPressed.remove(event->key());
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(Q_OS_ANDROID)
|
#if defined(Q_OS_ANDROID)
|
||||||
if (event->key() == Qt::Key_Back) {
|
if (event->key() == Qt::Key_Back) {
|
||||||
|
@ -3952,11 +3957,14 @@ void Application::focusOutEvent(QFocusEvent* event) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// synthesize events for keys currently pressed, since we may not get their release events
|
// synthesize events for keys currently pressed, since we may not get their release events
|
||||||
foreach (int key, _keysPressed) {
|
// Because our key event handlers may manipulate _keysPressed, lets swap the keys pressed into a local copy,
|
||||||
QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);
|
// clearing the existing list.
|
||||||
keyReleaseEvent(&keyEvent);
|
QHash<int, QKeyEvent> keysPressed;
|
||||||
|
std::swap(keysPressed, _keysPressed);
|
||||||
|
for (auto& ev : keysPressed) {
|
||||||
|
QKeyEvent synthesizedEvent { QKeyEvent::KeyRelease, ev.key(), Qt::NoModifier, ev.text() };
|
||||||
|
keyReleaseEvent(&synthesizedEvent);
|
||||||
}
|
}
|
||||||
_keysPressed.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Application::maybeToggleMenuVisible(QMouseEvent* event) const {
|
void Application::maybeToggleMenuVisible(QMouseEvent* event) const {
|
||||||
|
|
|
@ -621,7 +621,7 @@ private:
|
||||||
float _mirrorYawOffset;
|
float _mirrorYawOffset;
|
||||||
float _raiseMirror;
|
float _raiseMirror;
|
||||||
|
|
||||||
QSet<int> _keysPressed;
|
QHash<int, QKeyEvent> _keysPressed;
|
||||||
|
|
||||||
bool _enableProcessOctreeThread;
|
bool _enableProcessOctreeThread;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue