diff options
author | Florian Bruhin <me@the-compiler.org> | 2023-08-15 14:14:23 +0200 |
---|---|---|
committer | Florian Bruhin <me@the-compiler.org> | 2023-08-15 14:30:14 +0200 |
commit | a6e86629edcffcd30d19fa734f1ace61394169a0 (patch) | |
tree | a8473b42535b0918b0e994877c89cd7e7fafd905 | |
parent | f6d44b927aa97de472001e9699944d12dbee3345 (diff) | |
download | qutebrowser-a6e86629edcffcd30d19fa734f1ace61394169a0.tar.gz qutebrowser-a6e86629edcffcd30d19fa734f1ace61394169a0.zip |
Improve child widget focus workaround
Don't rely on the global QApplication.focusWidget()
See #7820
-rw-r--r-- | qutebrowser/browser/eventfilter.py | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/qutebrowser/browser/eventfilter.py b/qutebrowser/browser/eventfilter.py index b5659dba0..6404608b3 100644 --- a/qutebrowser/browser/eventfilter.py +++ b/qutebrowser/browser/eventfilter.py @@ -6,6 +6,7 @@ from qutebrowser.qt import machinery from qutebrowser.qt.core import QObject, QEvent, Qt, QTimer +from qutebrowser.qt.widgets import QWidget from qutebrowser.config import config from qutebrowser.utils import log, message, usertypes, qtutils, version, utils @@ -44,17 +45,25 @@ class ChildEventFilter(QObject): if self._widget is not None: assert obj is self._widget - # Carry on keyboard focus to the new child - # WORKAROUND for unknown Qt bug losing focus on child change - old_focus_widget = objects.qapp.focusWidget() - if old_focus_widget is not None: - metaobj = old_focus_widget.metaObject() + # WORKAROUND for unknown Qt bug losing focus on child change + # Carry on keyboard focus to the new child if: + # - This is a child event filter on a tab (self._widget is not None) + # - We find an old existing child which is a QQuickWidget and is + # currently focused. + # - We're using QtWebEngine >= 6.4 (older versions are not affected) + children = [ + c for c in self._widget.findChildren( + QWidget, "", Qt.FindChildOption.FindDirectChildrenOnly) + if c is not child and + c.hasFocus() and + c.metaObject() is not None and + c.metaObject().className() == "QQuickWidget" + ] if ( - metaobj is not None and - metaobj.className() == "QQuickWidget" and - old_focus_widget.parent() is obj and + children and objects.backend == usertypes.Backend.QtWebEngine and - version.qtwebengine_versions().webengine >= utils.VersionNumber(6, 2) + version.qtwebengine_versions().webengine >= + utils.VersionNumber(6, 4) ): log.misc.debug("Focusing new child") child.setFocus() |