Skip to content

Commit

Permalink
Merge pull request #13657 from acolombier/fix/crash-windows-focus
Browse files Browse the repository at this point in the history
fix: prevent crash when no app windows have the focus
  • Loading branch information
Swiftb0y authored Sep 16, 2024
2 parents 694542d + bd4b989 commit 497121e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,11 @@ void LibraryControl::slotGoToItem(double v) {
// press & release Space (QAbstractButton::clicked() is emitted on release)
QKeyEvent pressSpace = QKeyEvent{QEvent::KeyPress, Qt::Key_Space, Qt::NoModifier};
QKeyEvent releaseSpace = QKeyEvent{QEvent::KeyRelease, Qt::Key_Space, Qt::NoModifier};
QApplication::sendEvent(QApplication::focusWindow(), &pressSpace);
QApplication::sendEvent(QApplication::focusWindow(), &releaseSpace);
auto* pWindow = QApplication::focusWindow();
if (pWindow) {
QApplication::sendEvent(pWindow, &pressSpace);
QApplication::sendEvent(pWindow, &releaseSpace);
}
return;
}
case FocusWidget::ContextMenu:
Expand All @@ -1054,7 +1057,10 @@ void LibraryControl::slotGoToItem(double v) {
// If Unknown is some other 'untrained' or unresponsive widget
// GoToItem is inappropriate and we can't do much about that.
QKeyEvent event = QKeyEvent{QEvent::KeyPress, Qt::Key_Return, Qt::NoModifier};
QApplication::sendEvent(QApplication::focusWindow(), &event);
auto* pWindow = QApplication::focusWindow();
if (pWindow) {
QApplication::sendEvent(pWindow, &event);
}
return;
}
case FocusWidget::Searchbar:
Expand Down

0 comments on commit 497121e

Please sign in to comment.