summaryrefslogtreecommitdiff
path: root/qutebrowser/browser/eventfilter.py
diff options
context:
space:
mode:
Diffstat (limited to 'qutebrowser/browser/eventfilter.py')
-rw-r--r--qutebrowser/browser/eventfilter.py51
1 files changed, 32 insertions, 19 deletions
diff --git a/qutebrowser/browser/eventfilter.py b/qutebrowser/browser/eventfilter.py
index a76ccd6d5..1cff11ac4 100644
--- a/qutebrowser/browser/eventfilter.py
+++ b/qutebrowser/browser/eventfilter.py
@@ -1,27 +1,15 @@
-# Copyright 2016-2021 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
+# SPDX-FileCopyrightText: Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
-# This file is part of qutebrowser.
-#
-# qutebrowser is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# qutebrowser is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with qutebrowser. If not, see <https://www.gnu.org/licenses/>.
+# SPDX-License-Identifier: GPL-3.0-or-later
"""Event handling for a browser tab."""
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
+from qutebrowser.utils import log, message, usertypes, qtutils
from qutebrowser.keyinput import modeman
@@ -48,17 +36,42 @@ class ChildEventFilter(QObject):
"""Act on ChildAdded events."""
if event.type() == QEvent.Type.ChildAdded:
child = event.child()
- log.misc.debug("{} got new child {}, installing filter"
- .format(obj, child))
+ if not isinstance(child, QWidget):
+ # Can e.g. happen when dragging text
+ log.misc.debug(f"Ignoring new child {qtutils.qobj_repr(child)}")
+ return False
+
+ log.misc.debug(
+ f"{qtutils.qobj_repr(obj)} got new child {qtutils.qobj_repr(child)}, "
+ "installing filter")
# Additional sanity check, but optional
if self._widget is not None:
assert obj is self._widget
+ # 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 children:
+ log.misc.debug("Focusing new child")
+ child.setFocus()
+
child.installEventFilter(self._filter)
elif event.type() == QEvent.Type.ChildRemoved:
child = event.child()
- log.misc.debug("{}: removed child {}".format(obj, child))
+ log.misc.debug(
+ f"{qtutils.qobj_repr(obj)}: removed child {qtutils.qobj_repr(child)}")
return False