Add X11 support for Ctrl+Shift+.

This commit is contained in:
Ilya Fedin 2023-11-10 12:13:42 +04:00 committed by John Preston
parent f4b87f2322
commit d047544584

View file

@ -33,7 +33,12 @@
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
#include <WinUser.h> #include <WinUser.h>
#endif // Q_OS_WIN #elif !defined DESKTOP_APP_DISABLE_X11_INTEGRATION // Q_OS_WIN
#include "base/platform/linux/base_linux_xcb_utilities.h"
#include <xcb/xcb_keysyms.h>
#include <xkbcommon/xkbcommon-keysyms.h>
#endif // !Q_OS_WIN && !DESKTOP_APP_DISABLE_X11_INTEGRATION
namespace Ui { namespace Ui {
namespace { namespace {
@ -1008,6 +1013,14 @@ private:
} }
friend class InputField; 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) { void InsertEmojiAtCursor(QTextCursor cursor, EmojiPtr emoji) {
@ -2916,14 +2929,25 @@ bool InputField::handleMarkdownKey(QKeyEvent *e) {
const auto matchesCtrlShiftDot = [&] { const auto matchesCtrlShiftDot = [&] {
// We can't match ctrl+shift+. with QKeySequence because // We can't match ctrl+shift+. with QKeySequence because
// shift+. gives us '>' and ctrl+shift+> is not the same. // 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 #ifdef Q_OS_WIN
return e->modifiers().testFlag(Qt::ControlModifier) return e->modifiers().testFlag(Qt::ControlModifier)
&& e->modifiers().testFlag(Qt::ShiftModifier) && e->modifiers().testFlag(Qt::ShiftModifier)
&& (e->nativeVirtualKey() == VK_OEM_PERIOD); && (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; return false;
#endif // !Q_OS_WIN #endif // !Q_OS_WIN && DESKTOP_APP_DISABLE_X11_INTEGRATION
}; };
if (e == QKeySequence::Bold) { if (e == QKeySequence::Bold) {
toggleSelectionMarkdown(kTagBold); toggleSelectionMarkdown(kTagBold);