diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2024-01-23 09:32:07 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2024-01-29 10:30:25 +0100 |
commit | cef7c012579e3ef43acf3177b454ed70648489db (patch) | |
tree | 736254d87a30f7d835600aa27188e192a1d207e5 /vcl | |
parent | 414d57199480f2768e93f99aa80b1b5d4cbaf8b8 (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 f4cc37c06ae15923df6b15777f2526008c2b4ca6)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162453
Reviewed-by: Michael Stahl <michael.stahl@allotropia.de>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/qt5/QtWidget.cxx | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/vcl/qt5/QtWidget.cxx b/vcl/qt5/QtWidget.cxx index a7c4f32e9243..996a0a7cc9ce 100644 --- a/vcl/qt5/QtWidget.cxx +++ b/vcl/qt5/QtWidget.cxx @@ -697,6 +697,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; } |