diff options
author | Gatis Paeglis <gatis.paeglis@qt.io> | 2018-11-05 14:26:24 +0100 |
---|---|---|
committer | Gatis Paeglis <gatis.paeglis@qt.io> | 2019-01-04 20:11:52 +0000 |
commit | fe63900dc9891dd355ca1f10d6c7e5fd1516f5d5 (patch) | |
tree | ca2dde2d2e297b629843c7f79098edc9df46826f /src/plugins/platforms/xcb/qxcbconnection.cpp | |
parent | 03039979b5a643f9def38a73e19835bb69384202 (diff) |
xcb: rework focus-in peeker so we can drop PeekFunc API
The API for registering temporary peek function was added ~7 years
ago by 78264f333eb7c262380714ed6517562266f11a03. It was never been
used for anything else. The solution from 78264f333 also did not work
very well on KDE desktop, quoting Martin Flöser:
"In case the keyboard gets grabbed by another process and immediately
ungrabbed the active Qt application window receives a FocusOut and a
FocusIn event. FocusOut on the grab of keyboard, FocusIn on the ungrab.
Qt registers a peek function for checking the FocusIn event, but the
timespan is too short: the new event is not yet queued. This causes
a QEvent::WindowDeactivate being emitted, followed directly by a
QEvent::WindowActivate. This has quite some side effects, for example
rendering flickering in the GUI (switching to inactive/active in short
time frame), hooks on WindowDeactivate being run, etc.
Real world examples for such short keyboard grabs are global shortcut
listener applications like kglobalaccel5. It has e.g. a passive key
grab on the mute key, which is then turned into an active grab when
the key is grabbed. Kglobalaccel5 immediately ungrabs the keyboard
and flushes the connection if it gets a key event, but it of course
causes the sequence of FocusOut and FocusIn events in the active
Qt window."
Reworked the code to use QTimer instead, which is more elegant solution,
because it does not rely on race-conditions, but uses a concreate time
to wait instead. Also the need to write focusInPeeker() caused us to
duplicate event handlers that were present already elsewhere.
Change-Id: I647e52fb2634fdf55a640e19b13265c356f96c95
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io>
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/plugins/platforms/xcb/qxcbconnection.cpp')
-rw-r--r-- | src/plugins/platforms/xcb/qxcbconnection.cpp | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/src/plugins/platforms/xcb/qxcbconnection.cpp b/src/plugins/platforms/xcb/qxcbconnection.cpp index 37ee980924..15ffaaf2e2 100644 --- a/src/plugins/platforms/xcb/qxcbconnection.cpp +++ b/src/plugins/platforms/xcb/qxcbconnection.cpp @@ -131,6 +131,12 @@ QXcbConnection::QXcbConnection(QXcbNativeInterface *nativeInterface, bool canGra if (!m_startupId.isNull()) qunsetenv("DESKTOP_STARTUP_ID"); + m_focusInTimer.setSingleShot(true); + m_focusInTimer.callOnTimeout([]() { + // No FocusIn events for us, proceed with FocusOut normally. + QWindowSystemInterface::handleWindowActivated(nullptr, Qt::ActiveWindowFocusReason); + }); + sync(); } @@ -731,11 +737,6 @@ void QXcbConnection::handleXcbEvent(xcb_generic_event_t *event) m_glIntegration->handleXcbEvent(event, response_type); } -void QXcbConnection::addPeekFunc(PeekFunc f) -{ - m_peekFuncs.append(f); -} - void QXcbConnection::setFocusWindow(QWindow *w) { m_focusWindow = w ? static_cast<QXcbWindow *>(w->handle()) : nullptr; @@ -1015,15 +1016,6 @@ void QXcbConnection::processXcbEvents(QEventLoop::ProcessEventsFlags flags) if (compressEvent(event)) continue; - auto isWaitingFor = [=](PeekFunc peekFunc) { - // These callbacks return true if the event is what they were - // waiting for, remove them from the list in that case. - return peekFunc(this, event); - }; - m_peekFuncs.erase(std::remove_if(m_peekFuncs.begin(), m_peekFuncs.end(), - isWaitingFor), - m_peekFuncs.end()); - handleXcbEvent(event); // The lock-based solution used to free the lock inside this loop, @@ -1032,12 +1024,6 @@ void QXcbConnection::processXcbEvents(QEventLoop::ProcessEventsFlags flags) m_eventQueue->flushBufferedEvents(); } - // Indicate with a null event that the event the callbacks are waiting for - // is not in the queue currently. - for (PeekFunc f : qAsConst(m_peekFuncs)) - f(this, nullptr); - m_peekFuncs.clear(); - xcb_flush(xcb_connection()); } |