From d047544584b378cd1445aa0ae982c49147ac6297 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 10 Nov 2023 12:13:42 +0400 Subject: [PATCH] Add X11 support for Ctrl+Shift+. --- ui/widgets/fields/input_field.cpp | 32 +++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/ui/widgets/fields/input_field.cpp b/ui/widgets/fields/input_field.cpp index ae643c0..bd5a6e9 100644 --- a/ui/widgets/fields/input_field.cpp +++ b/ui/widgets/fields/input_field.cpp @@ -33,7 +33,12 @@ #ifdef Q_OS_WIN #include -#endif // Q_OS_WIN +#elif !defined DESKTOP_APP_DISABLE_X11_INTEGRATION // Q_OS_WIN +#include "base/platform/linux/base_linux_xcb_utilities.h" + +#include +#include +#endif // !Q_OS_WIN && !DESKTOP_APP_DISABLE_X11_INTEGRATION namespace Ui { namespace { @@ -1008,6 +1013,14 @@ private: } friend class InputField; +#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION + base::Platform::XCB::ObjectWithConnection< + xcb_key_symbols_t, + xcb_key_symbols_alloc, + xcb_key_symbols_free + > _xcbKeySymbols; +#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION + }; void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji) { @@ -2916,14 +2929,25 @@ bool InputField::handleMarkdownKey(QKeyEvent *e) { const auto matchesCtrlShiftDot = [&] { // We can't match ctrl+shift+. with QKeySequence because // shift+. gives us '>' and ctrl+shift+> is not the same. - // So we check by nativeVirtualKey instead. + // So we check with native code instead. #ifdef Q_OS_WIN return e->modifiers().testFlag(Qt::ControlModifier) && e->modifiers().testFlag(Qt::ShiftModifier) && (e->nativeVirtualKey() == VK_OEM_PERIOD); -#else // Q_OS_WIN +#elif !defined DESKTOP_APP_DISABLE_X11_INTEGRATION // Q_OS_WIN + if (!_inner->_xcbKeySymbols) { + return false; + } + const auto keysym = xcb_key_symbols_get_keysym( + _inner->_xcbKeySymbols.get(), + e->nativeScanCode(), + 0); + return e->modifiers().testFlag(Qt::ControlModifier) + && e->modifiers().testFlag(Qt::ShiftModifier) + && (keysym == XKB_KEY_period); +#else // !Q_OS_WIN && !DESKTOP_APP_DISABLE_X11_INTEGRATION return false; -#endif // !Q_OS_WIN +#endif // !Q_OS_WIN && DESKTOP_APP_DISABLE_X11_INTEGRATION }; if (e == QKeySequence::Bold) { toggleSelectionMarkdown(kTagBold);