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
3705 3705
3706void Application::keyPressEvent(QKeyEvent* event) {3706void Application::keyPressEvent(QKeyEvent* event) {
3707 _altPressed = event->key() == Qt::Key_Alt;3707 _altPressed = event->key() == Qt::Key_Alt;
3708 _keysPressed.insert(event->key());3708
3709 if (!event->isAutoRepeat()) {
3710 _keysPressed.insert(event->key(), *event);
3711 }
3709 3712
3710 _controllerScriptingInterface->emitKeyPressEvent(event); // send events to any registered scripts3713 _controllerScriptingInterface->emitKeyPressEvent(event); // send events to any registered scripts
3711 // if one of our scripts have asked to capture this event, then stop processing it3714 // 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
3916}3919}
3917 3920
3918void Application::keyReleaseEvent(QKeyEvent* event) {3921void Application::keyReleaseEvent(QKeyEvent* event) {
3919 _keysPressed.remove(event->key());3922 if (!event->isAutoRepeat()) {
3923 _keysPressed.remove(event->key());
3924 }
3920 3925
3921#if defined(Q_OS_ANDROID)3926#if defined(Q_OS_ANDROID)
3922 if (event->key() == Qt::Key_Back) {3927 if (event->key() == Qt::Key_Back) {
@@ -3952,11 +3957,14 @@ void Application::focusOutEvent(QFocusEvent* event) { · 29 unmodified lines
3952#endif3957#endif
3953 3958
3954 // synthesize events for keys currently pressed, since we may not get their release events3959 // synthesize events for keys currently pressed, since we may not get their release events
3955 foreach (int key, _keysPressed) {3960 // Because our key event handlers may manipulate _keysPressed, lets swap the keys pressed into a local copy,
3956 QKeyEvent keyEvent(QEvent::KeyRelease, key, Qt::NoModifier);3961 // clearing the existing list.
3957 keyReleaseEvent(&keyEvent);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);
3958 }3967 }
3959 _keysPressed.clear();
3960}3968}
3961 3969
3962void Application::maybeToggleMenuVisible(QMouseEvent* event) const {3970void 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