summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2021-07-19 15:17:53 +0200
committerMichael Weghorn <m.weghorn@posteo.de>2021-07-21 04:06:02 +0200
commit289ed73a2359f6221ca36c61cf96e4f4b72f61cc (patch)
tree64d40a63f9a5b8f320ace6f8edfcbe3f5d0d60a9
parent83f91ec066614c3c40282913898083d317edd072 (diff)
tdf#143298 Qt5 send SalEvent::KeyModChange events
I originally omitted this in the Qt implementation, as I couldn't find any non-working use case. The implementation got a bit hacky, because Qt doesn't have a non- native way to identify different L/R modifier keys, so we must process the X11/xkb keycode ourself, which obviously won't work on Wayland... but most times this is not relevant, so the default modifier notification may be good enough. P.S. it's basically the same code then X11 and Gtk... Change-Id: I37fbfde4a33a966b6017f3e0c280e2c7ea91e4db Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119235 Tested-by: Jenkins Reviewed-by: Michael Weghorn <m.weghorn@posteo.de> Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de> (cherry picked from commit 862fdb98ca271b60a831cd5420fd16d5f9c1c747) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119191
-rw-r--r--vcl/inc/qt5/Qt5Frame.hxx1
-rw-r--r--vcl/qt5/Qt5Frame.cxx3
-rw-r--r--vcl/qt5/Qt5Widget.cxx81
3 files changed, 85 insertions, 0 deletions
diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index f90936528399..ed82c2a7a8fb 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -102,6 +102,7 @@ class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public SalFrame
#if QT5_USING_X11
ScreenSaverInhibitor m_ScreenSaverInhibitor;
+ ModKeyFlags m_nKeyModifiers;
#endif
LanguageType m_nInputLanguage;
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 6dc54d9408e3..322f293828cd 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -113,6 +113,9 @@ Qt5Frame::Qt5Frame(Qt5Frame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo)
, m_bDefaultPos(true)
, m_bFullScreen(false)
, m_bFullScreenSpanAll(false)
+#if QT5_USING_X11
+ , m_nKeyModifiers(ModKeyFlags::NONE)
+#endif
, m_nInputLanguage(LANGUAGE_DONTKNOW)
{
Qt5Instance* pInst = static_cast<Qt5Instance*>(GetSalData()->m_pInstance);
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index a2bf8fe6472d..2e97132f5e75 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -52,6 +52,11 @@
#include <com/sun/star/accessibility/XAccessibleContext.hpp>
#include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
+#if QT5_USING_X11
+#define XK_MISCELLANY
+#include <X11/keysymdef.h>
+#endif
+
using namespace com::sun::star;
void Qt5Widget::paintEvent(QPaintEvent* pEvent)
@@ -444,6 +449,82 @@ bool Qt5Widget::handleKeyEvent(Qt5Frame& rFrame, const QWidget& rWidget, QKeyEve
return true;
}
+ if (nCode == 0)
+ {
+ sal_uInt16 nModCode = GetKeyModCode(pEvent->modifiers());
+ SalKeyModEvent aModEvt;
+ aModEvt.mbDown = eState == ButtonKeyState::Pressed;
+ aModEvt.mnModKeyCode = ModKeyFlags::NONE;
+
+#if QT5_USING_X11
+ if (QGuiApplication::platformName() == "xcb")
+ {
+ // pressing just the ctrl key leads to a keysym of XK_Control but
+ // the event state does not contain ControlMask. In the release
+ // event it's the other way round: it does contain the Control mask.
+ // The modifier mode therefore has to be adapted manually.
+ ModKeyFlags nExtModMask = ModKeyFlags::NONE;
+ sal_uInt16 nModMask = 0;
+ switch (pEvent->nativeVirtualKey())
+ {
+ case XK_Control_L:
+ nExtModMask = ModKeyFlags::LeftMod1;
+ nModMask = KEY_MOD1;
+ break;
+ case XK_Control_R:
+ nExtModMask = ModKeyFlags::RightMod1;
+ nModMask = KEY_MOD1;
+ break;
+ case XK_Alt_L:
+ nExtModMask = ModKeyFlags::LeftMod2;
+ nModMask = KEY_MOD2;
+ break;
+ case XK_Alt_R:
+ nExtModMask = ModKeyFlags::RightMod2;
+ nModMask = KEY_MOD2;
+ break;
+ case XK_Shift_L:
+ nExtModMask = ModKeyFlags::LeftShift;
+ nModMask = KEY_SHIFT;
+ break;
+ case XK_Shift_R:
+ nExtModMask = ModKeyFlags::RightShift;
+ nModMask = KEY_SHIFT;
+ break;
+ // Map Meta/Super keys to MOD3 modifier on all Unix systems
+ // except macOS
+ case XK_Meta_L:
+ case XK_Super_L:
+ nExtModMask = ModKeyFlags::LeftMod3;
+ nModMask = KEY_MOD3;
+ break;
+ case XK_Meta_R:
+ case XK_Super_R:
+ nExtModMask = ModKeyFlags::RightMod3;
+ nModMask = KEY_MOD3;
+ break;
+ }
+
+ if (eState == ButtonKeyState::Released)
+ {
+ aModEvt.mnModKeyCode = rFrame.m_nKeyModifiers;
+ nModCode &= ~nModMask;
+ rFrame.m_nKeyModifiers &= ~nExtModMask;
+ }
+ else
+ {
+ nModCode |= nModMask;
+ rFrame.m_nKeyModifiers |= nExtModMask;
+ aModEvt.mnModKeyCode = rFrame.m_nKeyModifiers;
+ }
+ }
+#endif
+ aModEvt.mnCode = nModCode;
+
+ rFrame.CallCallback(SalEvent::KeyModChange, &aModEvt);
+ return false;
+ }
+
SalKeyEvent aEvent;
aEvent.mnCharCode = (pEvent->text().isEmpty() ? 0 : pEvent->text().at(0).unicode());
aEvent.mnRepeat = 0;