History

Fix functionality sometimes getting stuck if window loses focus

Ryan Huffman committed 8 years ago

Commit 5d448771 parent 83718ca2 files · +15 −7Browse files

Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Application.cpp+14−6
@@ -3705,7 +3705,10 @@ static bool _altPressed{ false }; · 3704 unmodified lines
37053705
37063706 void Application::keyPressEvent(QKeyEvent* event) {
37073707 _altPressed = event->key() == Qt::Key_Alt;
3708− _keysPressed.insert(event->key());
3708+
3709+ if (!event->isAutoRepeat()) {
3710+ _keysPressed.insert(event->key(), *event);
3711+ }
37093712
37103713 _controllerScriptingInterface->emitKeyPressEvent(event); // send events to any registered scripts
37113714 // if one of our scripts have asked to capture this event, then stop processing it
@@ -3916,7 +3919,9 @@ void Application::keyPressEvent(QKeyEvent* event) { · 204 unmodified lines
39163919 }
39173920
39183921 void Application::keyReleaseEvent(QKeyEvent* event) {
3919− _keysPressed.remove(event->key());
3922+ if (!event->isAutoRepeat()) {
3923+ _keysPressed.remove(event->key());
3924+ }
39203925
39213926 #if defined(Q_OS_ANDROID)
39223927 if (event->key() == Qt::Key_Back) {
@@ -3952,11 +3957,14 @@ void Application::focusOutEvent(QFocusEvent* event) { · 29 unmodified lines
39523957 #endif
39533958
39543959 // synthesize events for keys currently pressed, since we may not get their release events
3955− foreach (int key, _keysPressed) {
3956− QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);
3957− keyReleaseEvent(&keyEvent);
3960+ // Because our key event handlers may manipulate _keysPressed, lets swap the keys pressed into a local copy,
3961+ // clearing the existing list.
3962+ QHash<int, QKeyEvent> keysPressed;
3963+ std::swap(keysPressed, _keysPressed);
3964+ for (auto& ev : keysPressed) {
3965+ QKeyEvent synthesizedEvent { QKeyEvent::KeyRelease, ev.key(), Qt::NoModifier, ev.text() };
3966+ keyReleaseEvent(&synthesizedEvent);
39583967 }
3959− _keysPressed.clear();
39603968 }
39613969
39623970 void Application::maybeToggleMenuVisible(QMouseEvent* event) const {

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t