summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Weghorn <m.weghorn@posteo.de>2024-01-23 09:32:07 +0100
committerMichael Stahl <michael.stahl@allotropia.de>2024-01-24 12:15:25 +0100
commit33c646b5044f77de2f1740f6e6b8c951139a96eb (patch)
treefc54b9d1f4c5cb71d012e2e228d39a97e4702f42
parent4d3e10fe4503810f17c60443b84a300a543a44b6 (diff)
tdf#159333 qt a11y: Process shortcuts only once
As described in commit 69e708868f6046cada955a16bca966370ce3218a Author: Michael Weghorn <m.weghorn@posteo.de> Date: Thu Feb 20 08:14:36 2020 +0100 tdf#130794 qt5: Actually, ignore non-spontaneous QEvent::ShortcutOverride and the previous commit 034f56015c1c7a61faede33fb5306f63b5585632 Author: Michael Weghorn <m.weghorn@posteo.de> Date: Mon Feb 17 10:38:15 2020 +0100 tdf#126785 qt5: Ignore external QEvent::ShortcutOverride it refers to, duplicate events of type `QEvent::ShortcutOverride` are received when a11y is active, so those commits introduced ignoring of the non-spontaneous one, and leaving processing for the spontaneous event only, thus preventing duplication of typed text. However, keyboard shortcuts like Ctrl+V were still processed twice: While they're only processed once in `QtWidget::handleEvent` (for the spontaneous event of type `QEvent::ShortcutOverride`), the keyboard shortcut was additionally handled as the shortcut to activate the action that's used for the menu entries, e.g. the "Edit" -> "Paste" menu entry for Ctrl+V (s. class `QtMenu`, where those are set). Accept the non-spontaneous `QEvent::ShortcutOverride` event to prevent that from happening. Quoting the `QEvent::ShortcutOverride` doc [1]: > Key press in child, for overriding shortcut key handling (QKeyEvent). > When a shortcut is about to trigger, ShortcutOverride is sent to the > active window. This allows clients (e.g. widgets) to signal that they > will handle the shortcut themselves, by accepting the event. If the > shortcut override is accepted, the event is delivered as a normal key > press to the focus widget. Otherwise, it triggers the shortcut action, > if one exists. With this commit in place, the shortcut is only processed once, as expected. Potentially, this should ideally be addressed on Qt side in the future, see the discussion in tdf#126785. The duplication happens since this qtbase commit (no longer with a local revert of it): [2] commit 7c532891e0be2cf78c89738e175b3d312d305e4e Date: Tue Apr 17 16:45:09 2018 +0200 Send ShortcutOverride event when receiving a non-spontaneous key press Since 2020, there a pending Qt change by Alexander Volkov suggesting to avoid the duplicate events by filtering them out in `QSpiApplicationAdaptor::eventFilter` on qtbase side: [3] With that change not being merged yet, fix this on LO side for now. [1] https://doc.qt.io/qt-6/qevent.html#Type-enum [2] https://code.qt.io/cgit/qt/qtbase.git/commit/?id=7c532891e0be2cf78c89738e175b3d312d305e4e [3] https://codereview.qt-project.org/c/qt/qtbase/+/295892 Change-Id: I28cb11914ae81284e050bff0deb39d95e8073ce0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162430 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> (cherry picked from commit 6e20e58270c88c8c77f156be75c23c66e1169e44) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162454 Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
-rw-r--r--vcl/qt5/QtWidget.cxx3
1 files changed, 3 insertions, 0 deletions
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx
index 83ada7866f2b..f8fa70886cb2 100644
--- a/vcl/qt5/QtWidget.cxx
+++ b/vcl/qt5/QtWidget.cxx
@@ -641,6 +641,9 @@ bool QtWidget::handleEvent(QtFrame& rFrame, QWidget& rWidget, QEvent* pEvent)
// is called below (s. tdf#122053)
if (!pEvent->spontaneous())
{
+ // accept event so shortcut action (from menu) isn't triggered in addition
+ // to the processing for the spontaneous event further below
+ pEvent->accept();
return false;
}