From 9616edbb66a8efbdd2bbc9be18e24aaf38a45b59 Mon Sep 17 00:00:00 2001 From: Elvis Angelaccio Date: Sun, 3 Jun 2018 14:53:55 +0200 Subject: [PATCH] Fix loop of FocusIn events Summary: Commit 43da84eefc7d introduced the risk of entering an endless loop of `FocusIn`/`FocusOut` events sent to two DolphinSearchBox instances when opening a second tab (see D11871). This happens because we deactivate the first tab when we open a new one, but since the `setActive(true)` is delayed with a QTimer, both the old tab and the new one become active and receive their own `FocusIn` event (which starts the loop of focus in/out events). To prevent this issue, we schedule the searchbox activation only if the searchbox is not already active. Test Plan: - Search something in dolphin - Open a new tab after the search ends - Check that dolphin does not eat the CPU Reviewers: #dolphin, anthonyfieroni Subscribers: kfm-devel Tags: #dolphin Differential Revision: https://phabricator.kde.org/D13152 --- src/search/dolphinsearchbox.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/search/dolphinsearchbox.cpp b/src/search/dolphinsearchbox.cpp index 12f0c2138..61f5c2db4 100644 --- a/src/search/dolphinsearchbox.cpp +++ b/src/search/dolphinsearchbox.cpp @@ -231,10 +231,14 @@ bool DolphinSearchBox::eventFilter(QObject* obj, QEvent* event) // #379135: we get the FocusIn event when we close a tab but we don't want to emit // the activated() signal before the removeTab() call in DolphinTabWidget::closeTab() returns. // To avoid this issue, we delay the activation of the search box. - QTimer::singleShot(0, this, [this] { - setActive(true); - setFocus(); - }); + // We also don't want to schedule the activation process if we are already active, + // otherwise we can enter in a loop of FocusIn/FocusOut events with the searchbox of another tab. + if (!isActive()) { + QTimer::singleShot(0, this, [this] { + setActive(true); + setFocus(); + }); + } break; default: