Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Extract X11-related code for modifiers fetching into a plugin
Dmitry Kazakovffc244f2d7bd
diff --git a/libs/koplugin/KoPluginLoader.cpp b/libs/koplugin/KoPluginLoader.cppindex 7ce1c65a4e..77b7cd2706 100644--- a/libs/koplugin/KoPluginLoader.cpp+++ b/libs/koplugin/KoPluginLoader.cpp@@ -148,3 +148,50 @@ void KoPluginLoader::load(const QString & serviceType, const QString & versionStconfigGroup.writeEntry(config.blacklist, blacklist);}}++KPluginFactory* KoPluginLoader::loadSinglePlugin(const std::vector<std::pair<QString, QString>> &predicates, const QString &serviceType)+{+ QList<KoJsonTrader::Plugin> offers = KoJsonTrader::instance()->query(serviceType, QString());++ offers.erase(std::remove_if(offers.begin(),+ offers.end(),+ [&](const KoJsonTrader::Plugin &plugin) {+ QJsonObject json = plugin.metaData().value("MetaData").toObject();+ Q_FOREACH(const auto &predicate, predicates) {+ if (json.value(predicate.first).toString() != predicate.second) {+ return true;+ }+ }+ return false;+ }),+ offers.end());++ auto versionFromPlugin = [] (const KoJsonTrader::Plugin &plugin) {+ QJsonObject json = plugin.metaData().value("MetaData").toObject();+ QVariant version = json.value("X-Krita-Version");+ return version.toString().toInt();+ };++ auto versionCompareLess = [&] (const KoJsonTrader::Plugin &lhs, const KoJsonTrader::Plugin &rhs) {+ return versionFromPlugin(lhs) < versionFromPlugin(rhs);+ };++ auto it = std::max_element(offers.begin(), offers.end(), versionCompareLess);++ if (it != offers.end()) {+ KPluginFactory *factory = qobject_cast<KPluginFactory *>(it->instance());+ return factory;+ }++ return nullptr;+}++KPluginFactory* KoPluginLoader::loadSinglePlugin(const std::pair<QString, QString> &predicates, const QString & serviceType)+{+ return loadSinglePlugin(std::vector<std::pair<QString, QString>>{predicates}, serviceType);+}++KPluginFactory* KoPluginLoader::loadSinglePlugin(const QString &id, const QString &serviceType)+{+ return loadSinglePlugin({"Id", id}, serviceType);+}\ No newline at end of filediff --git a/libs/koplugin/KoPluginLoader.h b/libs/koplugin/KoPluginLoader.hindex d48d1bdf21..ed7acc4215 100644--- a/libs/koplugin/KoPluginLoader.h+++ b/libs/koplugin/KoPluginLoader.h@@ -12,6 +12,8 @@#include "kritaplugin_export.h"+class KPluginFactory;+#ifndef Q_MOC_RUN/*** The pluginloader singleton is responsible for loading the plugins@@ -103,6 +105,10 @@ public:*/void load(const QString & serviceType, const QString & versionString = QString(), const PluginsConfig &config = PluginsConfig(), QObject* owner = 0, bool cache = true);+ KPluginFactory* loadSinglePlugin(const std::vector<std::pair<QString, QString>> &predicates, const QString & serviceType);+ KPluginFactory* loadSinglePlugin(const std::pair<QString, QString> &predicates, const QString & serviceType);+ KPluginFactory* loadSinglePlugin(const QString &id, const QString & serviceType);+public:/// DO NOT USE! Use instance() instead// TODO: turn KoPluginLoader into namespace and do not expose object at alldiff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txtindex 50bed9f070..f882d2f731 100644--- a/libs/ui/CMakeLists.txt+++ b/libs/ui/CMakeLists.txt@@ -331,6 +331,7 @@ set(kritaui_LIB_SRCSinput/kis_input_manager.cppinput/kis_input_manager_p.cppinput/kis_extended_modifiers_mapper.cpp+ input/KisExtendedModifiersMapperPluginInterface.cppinput/kis_abstract_input_action.cppinput/kis_tool_invocation_action.cppinput/kis_pan_action.cpp@@ -712,11 +713,6 @@ if (ANDROID)target_link_libraries(kritaui PRIVATE Qt${QT_MAJOR_VERSION}::AndroidExtras)endif()-if (NOT WIN32 AND NOT APPLE AND NOT ANDROID AND NOT HAIKU)- target_link_libraries(kritaui PRIVATE ${X11_X11_LIB}- ${X11_Xinput_LIB})-endif()-if (HAIKU)target_link_libraries(kritaui PRIVATE network expat iconv intl)endif()@@ -740,15 +736,6 @@ if (HAVE_WAYLAND)target_link_libraries(kritaui PRIVATE kritawayland)endif()-# Add VSync disable workaround-if(NOT WIN32 AND NOT APPLE AND NOT ANDROID AND NOT HAIKU AND QT_MAJOR_VERSION STREQUAL "5")- target_link_libraries(kritaui PRIVATE ${CMAKE_DL_LIBS} Qt${QT_MAJOR_VERSION}::X11Extras)-endif()--if (X11_FOUND AND (QT_MAJOR_VERSION STREQUAL "5"))- target_link_libraries(kritaui PRIVATE Qt${QT_MAJOR_VERSION}::X11Extras ${X11_LIBRARIES})-endif()-target_include_directories(kritauiPUBLIC$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/canvas>diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cppindex f575161437..1446646e62 100644--- a/libs/ui/KisApplication.cpp+++ b/libs/ui/KisApplication.cpp@@ -120,6 +120,9 @@#if HAVE_WAYLAND#include <KisWaylandKeyboardWatcher.h>#endif /* HAVE_WAYLAND */+#include <kpluginfactory.h>+#include <input/KisExtendedModifiersMapperPluginInterface.h>+namespace {const QTime appStartTime(QTime::currentTime());@@ -174,6 +177,7 @@ public:#if HAVE_WAYLANDQScopedPointer<KisWaylandKeyboardWatcher> waylandKeyboardWatcher;#endif /* HAVE_WAYLAND */+ QScopedPointer<KisExtendedModifiersMapperPluginInterface> extendedModifiersPluginInterface;};class KisApplication::ResetStarting@@ -258,6 +262,19 @@ KisApplication::KisApplication(const QString &key, int &argc, char **argv)qDebug() << "Style override disabled, using" << style()->objectName();}+ /**+ * Load platform plugin for modifiers fetching+ */+ {+ KPluginFactory *factory = KoPluginLoader::instance()->loadSinglePlugin(+ std::make_pair("X-Krita-PlatformId", QGuiApplication::platformName()),+ "Krita/PlatformPlugin");++ if (factory) {+ d->extendedModifiersPluginInterface.reset(factory->create<KisExtendedModifiersMapperPluginInterface>());+ }+ }+// store the style nameqApp->setProperty(currentUnderlyingStyleNameProperty, style()->objectName());KisSynchronizedConnectionBase::registerSynchronizedEventBarrier(std::bind(&KisApplication::processPostponedSynchronizationEvents, this));@@ -1209,3 +1226,8 @@ KisWaylandKeyboardWatcher *KisApplication::waylandKeyboardWatcher()return d->waylandKeyboardWatcher.data();}#endif /* HAVE_WAYLAND */++KisExtendedModifiersMapperPluginInterface* KisApplication::extendedModifiersPluginInterface()+{+ return d->extendedModifiersPluginInterface.data();+}diff --git a/libs/ui/KisApplication.h b/libs/ui/KisApplication.hindex 90455bbe53..c23f5eb4af 100644--- a/libs/ui/KisApplication.h+++ b/libs/ui/KisApplication.h@@ -19,6 +19,7 @@ class KisApplicationPrivate;class QWidget;class KisApplicationArguments;class KisAutoSaveRecoveryDialog;+class KisExtendedModifiersMapperPluginInterface;#if HAVE_WAYLANDclass KisWaylandKeyboardWatcher;@@ -102,6 +103,7 @@ public:KisWaylandKeyboardWatcher *waylandKeyboardWatcher();#endif+ KisExtendedModifiersMapperPluginInterface* extendedModifiersPluginInterface();public Q_SLOTS:diff --git a/libs/ui/input/KisExtendedModifiersMapperPluginInterface.cpp b/libs/ui/input/KisExtendedModifiersMapperPluginInterface.cppnew file mode 100644index 0000000000..001535eaa1--- /dev/null+++ b/libs/ui/input/KisExtendedModifiersMapperPluginInterface.cpp@@ -0,0 +1,11 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include "KisExtendedModifiersMapperPluginInterface.h"++KisExtendedModifiersMapperPluginInterface::~KisExtendedModifiersMapperPluginInterface()+{+}\ No newline at end of filediff --git a/libs/ui/input/KisExtendedModifiersMapperPluginInterface.h b/libs/ui/input/KisExtendedModifiersMapperPluginInterface.hnew file mode 100644index 0000000000..7153ff93d9--- /dev/null+++ b/libs/ui/input/KisExtendedModifiersMapperPluginInterface.h@@ -0,0 +1,28 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#ifndef __KIS_EXTENDED_MODIFIERS_MAPPER_PLUGIN_INTERFACE_H+#define __KIS_EXTENDED_MODIFIERS_MAPPER_PLUGIN_INTERFACE_H++#include <kritaui_export.h>+#include <Qt>+#include <QObject>+#include <QVector>+++class KRITAUI_EXPORT KisExtendedModifiersMapperPluginInterface : public QObject+{+ Q_OBJECT+public:+ typedef QVector<Qt::Key> ExtendedModifiers;++ using QObject::QObject;++ virtual ~KisExtendedModifiersMapperPluginInterface();+ virtual ExtendedModifiers queryExtendedModifiers() = 0;+};++#endif /* __KIS_EXTENDED_MODIFIERS_MAPPER_PLUGIN_INTERFACE_H */\ No newline at end of filediff --git a/libs/ui/input/kis_extended_modifiers_mapper.cpp b/libs/ui/input/kis_extended_modifiers_mapper.cppindex d78b89cd86..3a29e31a25 100644--- a/libs/ui/input/kis_extended_modifiers_mapper.cpp+++ b/libs/ui/input/kis_extended_modifiers_mapper.cpp@@ -5,10 +5,13 @@*/#include "kis_extended_modifiers_mapper.h"+#include "KisExtendedModifiersMapperPluginInterface.h"-#include <QApplication>+#include <KisApplication.h>#include <QKeyEvent>+#include <krita_container_utils.h>+#include <config-wayland.h>#ifdef Q_OS_MACOS@@ -66,118 +69,14 @@ QVector<Qt::Key> queryPressedKeysWin()#if HAVE_WAYLAND-#include <KisApplication.h>#include <KisWaylandKeyboardWatcher.h>#endif /* HAVE_WAYLAND */-#ifdef HAVE_X11-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))-#include <QX11Info>-#else-#include <QGuiApplication>-#endif--#include <X11/X.h>-#include <X11/Xlib.h>-#include <X11/keysym.h>-#include <krita_container_utils.h>-#include <X11/XKBlib.h>--struct KeyMapping {- KeyMapping() {}- KeyMapping(KeySym sym, Qt::Key key) : x11KeySym(sym), qtKey(key) {}- KeySym x11KeySym {0};- Qt::Key qtKey {Qt::Key_unknown};-};--#endif /* HAVE_X11 */-struct KisExtendedModifiersMapper::Private{- Private();--#ifdef HAVE_X11-- QVector<KeyMapping> mapping;- char keysState[32];- int minKeyCode = 0;- int maxKeyCode = 0;-- bool checkKeyCodePressedX11(KeyCode key);-#endif /* HAVE_X11 */};-#ifdef HAVE_X11--KisExtendedModifiersMapper::Private::Private()-{- if (QGuiApplication::platformName() == QLatin1String("xcb")) {-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- XDisplayKeycodes(QX11Info::display(), &minKeyCode, &maxKeyCode);- XQueryKeymap(QX11Info::display(), keysState);-#else- XDisplayKeycodes(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(),- &minKeyCode, &maxKeyCode);- XQueryKeymap(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), keysState);-#endif-- mapping.append(KeyMapping(XK_Shift_L, Qt::Key_Shift));- mapping.append(KeyMapping(XK_Shift_R, Qt::Key_Shift));-- mapping.append(KeyMapping(XK_Control_L, Qt::Key_Control));- mapping.append(KeyMapping(XK_Control_R, Qt::Key_Control));-- mapping.append(KeyMapping(XK_Meta_L, Qt::Key_Alt));- mapping.append(KeyMapping(XK_Meta_R, Qt::Key_Alt));- mapping.append(KeyMapping(XK_Mode_switch, Qt::Key_AltGr));- mapping.append(KeyMapping(XK_ISO_Level3_Shift, Qt::Key_AltGr));-- mapping.append(KeyMapping(XK_Alt_L, Qt::Key_Alt));- mapping.append(KeyMapping(XK_Alt_R, Qt::Key_Alt));-- mapping.append(KeyMapping(XK_Super_L, Qt::Key_Meta));- mapping.append(KeyMapping(XK_Super_R, Qt::Key_Meta));-- mapping.append(KeyMapping(XK_Hyper_L, Qt::Key_Hyper_L));- mapping.append(KeyMapping(XK_Hyper_R, Qt::Key_Hyper_R));--- mapping.append(KeyMapping(XK_space, Qt::Key_Space));-- for (int qtKey = Qt::Key_0, x11Sym = XK_0;- qtKey <= Qt::Key_9;- qtKey++, x11Sym++) {-- mapping.append(KeyMapping(x11Sym, Qt::Key(qtKey)));- }-- for (int qtKey = Qt::Key_A, x11Sym = XK_a;- qtKey <= Qt::Key_Z;- qtKey++, x11Sym++) {-- mapping.append(KeyMapping(x11Sym, Qt::Key(qtKey)));- }- }-}--bool KisExtendedModifiersMapper::Private::checkKeyCodePressedX11(KeyCode key)-{- int byte = key / 8;- char mask = 1 << (key % 8);-- return keysState[byte] & mask;-}--#else /* HAVE_X11 */--KisExtendedModifiersMapper::Private::Private()-{-}--#endif /* HAVE_X11 */--KisExtendedModifiersMapper::KisExtendedModifiersMapper(): m_d(new Private){@@ -198,57 +97,14 @@ void KisExtendedModifiersMapper::setLocalMonitor(bool activate, KisShortcutMatchKisExtendedModifiersMapper::ExtendedModifiersKisExtendedModifiersMapper::queryExtendedModifiers(){- auto qtModifiersToQtKeys = [] (Qt::KeyboardModifiers standardModifiers) {- ExtendedModifiers modifiers;-- if (standardModifiers & Qt::ShiftModifier) {- modifiers << Qt::Key_Shift;- }-- if (standardModifiers & Qt::ControlModifier) {- modifiers << Qt::Key_Control;- }-- if (standardModifiers & Qt::AltModifier) {- modifiers << Qt::Key_Alt;- }-- if (standardModifiers & Qt::MetaModifier) {- modifiers << Qt::Key_Meta;- }-- return modifiers;- };-- ExtendedModifiers modifiers;--#if defined HAVE_X11-- if (QGuiApplication::platformName() == QLatin1String("xcb")) {- for (int keyCode = m_d->minKeyCode; keyCode <= m_d->maxKeyCode; keyCode++) {- if (m_d->checkKeyCodePressedX11(keyCode)) {-#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))- KeySym sym = XkbKeycodeToKeysym(QX11Info::display(), keyCode,-#else- KeySym sym = XkbKeycodeToKeysym(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), keyCode,-#endif- 0, 0);- Q_FOREACH (const KeyMapping &map, m_d->mapping) {- if (map.x11KeySym == sym) {- modifiers << map.qtKey;- break;- }- }- }- }+ KisExtendedModifiersMapperPluginInterface *plugin =+ static_cast<KisApplication*>(qApp)->extendedModifiersPluginInterface();- // in X11 some keys may have multiple keysyms,- // (Alt Key == XK_Meta_{L,R}, XK_Meta_{L,R})- KritaUtils::makeContainerUnique(modifiers);- return modifiers;+ if (plugin) {+ return plugin->queryExtendedModifiers();}-#endif /* HAVE_X11 */+ ExtendedModifiers modifiers;#if HAVE_WAYLAND@@ -296,3 +152,26 @@ Qt::Key KisExtendedModifiersMapper::workaroundShiftAltMetaHell(const QKeyEvent *return key;}++KisExtendedModifiersMapper::ExtendedModifiers KisExtendedModifiersMapper::qtModifiersToQtKeys(Qt::KeyboardModifiers standardModifiers)+{+ ExtendedModifiers modifiers;++ if (standardModifiers & Qt::ShiftModifier) {+ modifiers << Qt::Key_Shift;+ }++ if (standardModifiers & Qt::ControlModifier) {+ modifiers << Qt::Key_Control;+ }++ if (standardModifiers & Qt::AltModifier) {+ modifiers << Qt::Key_Alt;+ }++ if (standardModifiers & Qt::MetaModifier) {+ modifiers << Qt::Key_Meta;+ }++ return modifiers;+};\ No newline at end of filediff --git a/libs/ui/input/kis_extended_modifiers_mapper.h b/libs/ui/input/kis_extended_modifiers_mapper.hindex 877e813923..a801ca3054 100644--- a/libs/ui/input/kis_extended_modifiers_mapper.h+++ b/libs/ui/input/kis_extended_modifiers_mapper.h@@ -37,6 +37,7 @@ public:Qt::KeyboardModifiers queryStandardModifiers();static Qt::Key workaroundShiftAltMetaHell(const QKeyEvent *keyEvent);+ static ExtendedModifiers qtModifiersToQtKeys(Qt::KeyboardModifiers standardModifiers);#ifdef Q_OS_MACOSstatic void setLocalMonitor(bool activate, KisShortcutMatcher *matcher = 0);diff --git a/libs/widgets/CMakeLists.txt b/libs/widgets/CMakeLists.txtindex f1986da116..ca13d12765 100644--- a/libs/widgets/CMakeLists.txt+++ b/libs/widgets/CMakeLists.txt@@ -113,10 +113,6 @@ target_link_libraries(kritawidgetsKF${KF_MAJOR}::Completion)-if(X11_FOUND AND QT_MAJOR_VERSION STREQUAL "5")- target_link_libraries(kritawidgets Qt${QT_MAJOR_VERSION}::X11Extras ${X11_LIBRARIES})-endif()-set_target_properties(kritawidgets PROPERTIESVERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION})diff --git a/plugins/CMakeLists.txt b/plugins/CMakeLists.txtindex 6483999114..f438759e96 100644--- a/plugins/CMakeLists.txt+++ b/plugins/CMakeLists.txt@@ -14,3 +14,5 @@ add_subdirectory( qt )if ((HAVE_PYQT5 OR HAVE_PYQT6) AND HAVE_SIP AND HAVE_PYTHONLIBS)add_subdirectory( python )endif()++add_subdirectory( platforms )diff --git a/plugins/platforms/CMakeLists.txt b/plugins/platforms/CMakeLists.txtnew file mode 100644index 0000000000..e6b539eacb--- /dev/null+++ b/plugins/platforms/CMakeLists.txt@@ -0,0 +1,3 @@+if (HAVE_X11)+ add_subdirectory( xcb )+endif()diff --git a/plugins/platforms/xcb/CMakeLists.txt b/plugins/platforms/xcb/CMakeLists.txtnew file mode 100644index 0000000000..15a547e802--- /dev/null+++ b/plugins/platforms/xcb/CMakeLists.txt@@ -0,0 +1,19 @@+project( kritaplatformpluginxcb )++set ( kritaplatformpluginxcb_SRCS+ KritaPlatformPluginXcb.cpp+ KisExtendedModifiersMapperX11.cpp+)++kis_add_library(kritaplatformpluginxcb MODULE ${kritaplatformpluginxcb_SRCS})++target_link_libraries(kritaplatformpluginxcb PRIVATE kritaglobal kritaui)++if (QT_MAJOR_VERSION STREQUAL "5")+ target_link_libraries(kritaplatformpluginxcb PRIVATE Qt${QT_MAJOR_VERSION}::X11Extras)+endif()++target_link_libraries(kritaplatformpluginxcb PRIVATE ${X11_X11_LIB})++install(TARGETS kritaplatformpluginxcb DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})+diff --git a/plugins/platforms/xcb/KisExtendedModifiersMapperX11.cpp b/plugins/platforms/xcb/KisExtendedModifiersMapperX11.cppnew file mode 100644index 0000000000..48a815f213--- /dev/null+++ b/plugins/platforms/xcb/KisExtendedModifiersMapperX11.cpp@@ -0,0 +1,173 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include "KisExtendedModifiersMapperX11.h"++#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))+#include <QX11Info>+#else+#include <QGuiApplication>+#endif++#include <X11/X.h>+#include <X11/XKBlib.h>+#include <X11/Xlib.h>+#include <X11/keysym.h>+#include <krita_container_utils.h>++struct KeyMapping {+ KeySym x11KeySym {0};+ Qt::Key qtKey {Qt::Key_unknown};+};++static const KeyMapping s_mapping[] = {+ {XK_Shift_L, Qt::Key_Shift},+ {XK_Shift_R, Qt::Key_Shift},++ {XK_Control_L, Qt::Key_Control},+ {XK_Control_R, Qt::Key_Control},++ {XK_Meta_L, Qt::Key_Alt},+ {XK_Meta_R, Qt::Key_Alt},+ {XK_Mode_switch, Qt::Key_AltGr},+ {XK_ISO_Level3_Shift, Qt::Key_AltGr},++ {XK_Alt_L, Qt::Key_Alt},+ {XK_Alt_R, Qt::Key_Alt},++ {XK_Super_L, Qt::Key_Meta},+ {XK_Super_R, Qt::Key_Meta},++ {XK_Hyper_L, Qt::Key_Hyper_L},+ {XK_Hyper_R, Qt::Key_Hyper_R},++ {XK_space, Qt::Key_Space},++ {XK_0, Qt::Key_0},+ {XK_1, Qt::Key_1},+ {XK_2, Qt::Key_2},+ {XK_3, Qt::Key_3},+ {XK_4, Qt::Key_4},+ {XK_5, Qt::Key_5},+ {XK_6, Qt::Key_6},+ {XK_7, Qt::Key_7},+ {XK_8, Qt::Key_8},+ {XK_9, Qt::Key_9},++ {XK_a, Qt::Key_A},+ {XK_b, Qt::Key_B},+ {XK_c, Qt::Key_C},+ {XK_d, Qt::Key_D},+ {XK_e, Qt::Key_E},+ {XK_f, Qt::Key_F},+ {XK_g, Qt::Key_G},+ {XK_h, Qt::Key_H},+ {XK_i, Qt::Key_I},+ {XK_j, Qt::Key_J},+ {XK_k, Qt::Key_K},+ {XK_l, Qt::Key_L},+ {XK_m, Qt::Key_M},+ {XK_n, Qt::Key_N},+ {XK_o, Qt::Key_O},+ {XK_p, Qt::Key_P},+ {XK_q, Qt::Key_Q},+ {XK_r, Qt::Key_R},+ {XK_s, Qt::Key_S},+ {XK_t, Qt::Key_T},+ {XK_u, Qt::Key_U},+ {XK_v, Qt::Key_V},+ {XK_w, Qt::Key_W},+ {XK_x, Qt::Key_X},+ {XK_y, Qt::Key_Y},+ {XK_z, Qt::Key_Z},++ {XK_A, Qt::Key_A},+ {XK_B, Qt::Key_B},+ {XK_C, Qt::Key_C},+ {XK_D, Qt::Key_D},+ {XK_E, Qt::Key_E},+ {XK_F, Qt::Key_F},+ {XK_G, Qt::Key_G},+ {XK_H, Qt::Key_H},+ {XK_I, Qt::Key_I},+ {XK_J, Qt::Key_J},+ {XK_K, Qt::Key_K},+ {XK_L, Qt::Key_L},+ {XK_M, Qt::Key_M},+ {XK_N, Qt::Key_N},+ {XK_O, Qt::Key_O},+ {XK_P, Qt::Key_P},+ {XK_Q, Qt::Key_Q},+ {XK_R, Qt::Key_R},+ {XK_S, Qt::Key_S},+ {XK_T, Qt::Key_T},+ {XK_U, Qt::Key_U},+ {XK_V, Qt::Key_V},+ {XK_W, Qt::Key_W},+ {XK_X, Qt::Key_X},+ {XK_Y, Qt::Key_Y},+ {XK_Z, Qt::Key_Z}+};++KisExtendedModifiersMapperX11::KisExtendedModifiersMapperX11(QObject *parent, const QVariantList &)+ : KisExtendedModifiersMapperPluginInterface(parent)+{+}++KisExtendedModifiersMapperX11::~KisExtendedModifiersMapperX11() = default;++KisExtendedModifiersMapperPluginInterface::ExtendedModifiers KisExtendedModifiersMapperX11::queryExtendedModifiers()+{+ KisExtendedModifiersMapperPluginInterface::ExtendedModifiers modifiers;++ char keysState[32];+ int minKeyCode = 0;+ int maxKeyCode = 0;++#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))+ XDisplayKeycodes(QX11Info::display(), &minKeyCode, &maxKeyCode);+ XQueryKeymap(QX11Info::display(), keysState);+#else+ XDisplayKeycodes(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(),+ &minKeyCode,+ &maxKeyCode);+ XQueryKeymap(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(), keysState);+#endif+++ auto checkKeyCodePressedX11 = [&keysState] (KeyCode key) -> bool {+ int byte = key / 8;+ char mask = 1 << (key % 8);+ return keysState[byte] & mask;+ };++ for (int keyCode = minKeyCode; keyCode <= maxKeyCode; keyCode++) {+ if (checkKeyCodePressedX11(keyCode)) {+#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))+ KeySym sym = XkbKeycodeToKeysym(QX11Info::display(),+ keyCode,+#else+ KeySym sym = XkbKeycodeToKeysym(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display(),+ keyCode,+#endif+ 0,+ 0);+ for (size_t i = 0; i < sizeof(s_mapping); i++) {+ const KeyMapping &map = s_mapping[i];+ if (map.x11KeySym == sym) {+ modifiers << map.qtKey;+ break;+ }+ }+ }+ }++ // in X11 some keys may have multiple keysyms,+ // (Alt Key == XK_Meta_{L,R}, XK_Meta_{L,R})+ KritaUtils::makeContainerUnique(modifiers);+ return modifiers;+}+diff --git a/plugins/platforms/xcb/KisExtendedModifiersMapperX11.h b/plugins/platforms/xcb/KisExtendedModifiersMapperX11.hnew file mode 100644index 0000000000..2567e61955--- /dev/null+++ b/plugins/platforms/xcb/KisExtendedModifiersMapperX11.h@@ -0,0 +1,19 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include <input/KisExtendedModifiersMapperPluginInterface.h>++#include <QObject>++class KisExtendedModifiersMapperX11+ : public KisExtendedModifiersMapperPluginInterface+{+public:+ KisExtendedModifiersMapperX11(QObject *parent, const QVariantList &);+ ~KisExtendedModifiersMapperX11() override;++ ExtendedModifiers queryExtendedModifiers() override;+};\ No newline at end of filediff --git a/plugins/platforms/xcb/KritaPlatformPluginXcb.cpp b/plugins/platforms/xcb/KritaPlatformPluginXcb.cppnew file mode 100644index 0000000000..0f3e1b70b7--- /dev/null+++ b/plugins/platforms/xcb/KritaPlatformPluginXcb.cpp@@ -0,0 +1,13 @@+/*+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */++#include <kpluginfactory.h>++#include "KisExtendedModifiersMapperX11.h"++K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginXcbFactory, "kritaplatformxcb.json", registerPlugin<KisExtendedModifiersMapperX11>();)++#include <KritaPlatformPluginXcb.moc>diff --git a/plugins/platforms/xcb/kritaplatformxcb.json b/plugins/platforms/xcb/kritaplatformxcb.jsonnew file mode 100644index 0000000000..52d3b7760f--- /dev/null+++ b/plugins/platforms/xcb/kritaplatformxcb.json@@ -0,0 +1,11 @@+{+ "Id": "kritaplatformxcb",+ "Type": "Service",+ "X-KDE-Library": "kritaplatformxcb",+ "X-KDE-PluginInfo-Name": "Krita Platform Plugin for X11/XCB",+ "X-KDE-ServiceTypes": [+ "Krita/PlatformPlugin"+ ],+ "X-Krita-Version": "28",+ "X-Krita-PlatformId": "xcb"+}