Skip to content

armgit / krita

Public Imported from GitHub
0

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 Wayland keyboard state detection code into a plugin as well

Dmitry Kazakov01e40b05f6a9
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 47d1b43526..a3e69f017f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -540,10 +540,9 @@ endif()
set(HAVE_WAYLAND FALSE)
if (TARGET Qt::WaylandClient)
- message(STATUS "Found Qt::WaylandClient, enabling kritawayland library")
+ message(STATUS "Found Qt::WaylandClient, enabling kritawayland platform")
set(HAVE_WAYLAND TRUE)
endif()
-configure_file(config-wayland.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-wayland.h)
#
# Check for the presence of custom patches in Qt
diff --git a/config-wayland.h.cmake b/config-wayland.h.cmake
deleted file mode 100644
index e6830040cd..0000000000
--- a/config-wayland.h.cmake
+++ /dev/null
@@ -1 +0,0 @@
-#cmakedefine01 HAVE_WAYLAND
diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt
index d4cecaf949..aa7af642ea 100644
--- a/libs/CMakeLists.txt
+++ b/libs/CMakeLists.txt
@@ -23,6 +23,3 @@ add_subdirectory( metadata )
add_subdirectory( resourcewidgets )
add_subdirectory( psd )
add_subdirectory( multiarch )
-if (HAVE_WAYLAND)
- add_subdirectory( wayland )
-endif()
diff --git a/libs/ui/CMakeLists.txt b/libs/ui/CMakeLists.txt
index f882d2f731..8e50d31cb5 100644
--- a/libs/ui/CMakeLists.txt
+++ b/libs/ui/CMakeLists.txt
@@ -732,10 +732,6 @@ if(OpenEXR_FOUND)
target_link_libraries(kritaui PUBLIC ${LINK_OPENEXR_LIB})
endif()
-if (HAVE_WAYLAND)
- target_link_libraries(kritaui PRIVATE kritawayland)
-endif()
-
target_include_directories(kritaui
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/canvas>
diff --git a/libs/ui/KisApplication.cpp b/libs/ui/KisApplication.cpp
index 1446646e62..af01303855 100644
--- a/libs/ui/KisApplication.cpp
+++ b/libs/ui/KisApplication.cpp
@@ -117,9 +117,6 @@
#include <config-seexpr.h>
#include <config-safe-asserts.h>
-#if HAVE_WAYLAND
-#include <KisWaylandKeyboardWatcher.h>
-#endif /* HAVE_WAYLAND */
#include <kpluginfactory.h>
#include <input/KisExtendedModifiersMapperPluginInterface.h>
@@ -174,9 +171,6 @@ public:
bool batchRun {false};
QVector<QByteArray> earlyRemoteArguments;
QVector<QString> earlyFileOpenEvents;
-#if HAVE_WAYLAND
- QScopedPointer<KisWaylandKeyboardWatcher> waylandKeyboardWatcher;
-#endif /* HAVE_WAYLAND */
QScopedPointer<KisExtendedModifiersMapperPluginInterface> extendedModifiersPluginInterface;
};
@@ -278,12 +272,6 @@ KisApplication::KisApplication(const QString &key, int &argc, char **argv)
// store the style name
qApp->setProperty(currentUnderlyingStyleNameProperty, style()->objectName());
KisSynchronizedConnectionBase::registerSynchronizedEventBarrier(std::bind(&KisApplication::processPostponedSynchronizationEvents, this));
-
-#if HAVE_WAYLAND
- if (QGuiApplication::platformName() == QLatin1String("wayland")) {
- d->waylandKeyboardWatcher.reset(new KisWaylandKeyboardWatcher());
- }
-#endif /* HAVE_WAYLAND */
}
#if defined(Q_OS_WIN) && defined(ENV32BIT)
@@ -1220,13 +1208,6 @@ void KisApplication::askResetConfig()
}
}
-#if HAVE_WAYLAND
-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.h
index c23f5eb4af..020b7a9c4f 100644
--- a/libs/ui/KisApplication.h
+++ b/libs/ui/KisApplication.h
@@ -12,8 +12,6 @@
#include <qtsingleapplication/qtsingleapplication.h>
#include "kritaui_export.h"
-#include <config-wayland.h>
-
class KisMainWindow;
class KisApplicationPrivate;
class QWidget;
@@ -21,10 +19,6 @@ class KisApplicationArguments;
class KisAutoSaveRecoveryDialog;
class KisExtendedModifiersMapperPluginInterface;
-#if HAVE_WAYLAND
-class KisWaylandKeyboardWatcher;
-#endif
-
#include <KisImportExportManager.h>
/**
@@ -99,10 +93,6 @@ public:
static void verifyMetatypeRegistration();
-#if HAVE_WAYLAND
- KisWaylandKeyboardWatcher *waylandKeyboardWatcher();
-#endif
-
KisExtendedModifiersMapperPluginInterface* extendedModifiersPluginInterface();
public Q_SLOTS:
diff --git a/libs/ui/input/kis_extended_modifiers_mapper.cpp b/libs/ui/input/kis_extended_modifiers_mapper.cpp
index 3a29e31a25..392535c989 100644
--- a/libs/ui/input/kis_extended_modifiers_mapper.cpp
+++ b/libs/ui/input/kis_extended_modifiers_mapper.cpp
@@ -12,8 +12,6 @@
#include <krita_container_utils.h>
-#include <config-wayland.h>
-
#ifdef Q_OS_MACOS
#include "kis_extended_modifiers_mapper_osx.h"
@@ -67,12 +65,6 @@ QVector<Qt::Key> queryPressedKeysWin()
#endif /* Q_OS_WIN */
-#if HAVE_WAYLAND
-
-#include <KisWaylandKeyboardWatcher.h>
-
-#endif /* HAVE_WAYLAND */
-
struct KisExtendedModifiersMapper::Private
{
};
@@ -106,24 +98,6 @@ KisExtendedModifiersMapper::queryExtendedModifiers()
ExtendedModifiers modifiers;
-#if HAVE_WAYLAND
-
- if (QGuiApplication::platformName() == QLatin1String("wayland")) {
- KisWaylandKeyboardWatcher *watcher =
- static_cast<KisApplication*>(qApp)->waylandKeyboardWatcher();
-
- if (watcher->hasKeyboardFocus()) {
- modifiers = watcher->pressedKeys();
- KritaUtils::makeContainerUnique(modifiers);
- } else {
- modifiers = qtModifiersToQtKeys(watcher->modifiers());
- }
-
- return modifiers;
- }
-
-#endif /* HAVE_WAYLAND */
-
#if defined Q_OS_WIN
modifiers = queryPressedKeysWin();
#elif defined Q_OS_MACOS
diff --git a/plugins/platforms/CMakeLists.txt b/plugins/platforms/CMakeLists.txt
index e6b539eacb..0e7b055c9f 100644
--- a/plugins/platforms/CMakeLists.txt
+++ b/plugins/platforms/CMakeLists.txt
@@ -1,3 +1,7 @@
if (HAVE_X11)
add_subdirectory( xcb )
endif()
+
+if (HAVE_WAYLAND)
+ add_subdirectory( wayland )
+endif()
diff --git a/libs/wayland/CMakeLists.txt b/plugins/platforms/wayland/CMakeLists.txt
similarity index 68%
rename from libs/wayland/CMakeLists.txt
rename to plugins/platforms/wayland/CMakeLists.txt
index 8d9614f353..0c10db5e9c 100644
--- a/libs/wayland/CMakeLists.txt
+++ b/plugins/platforms/wayland/CMakeLists.txt
@@ -1,7 +1,9 @@
if (NOT QT_MAJOR_VERSION STREQUAL "6")
- message(FATAL_ERROR "kritawayland library is supported with Qt6 only")
+ message(FATAL_ERROR "kritaplatformpluginwayland library is supported with Qt6 only")
endif()
+project( kritaplatformpluginwayland )
+
##
## Check for the presence of custom Wayland patches in Qt
##
@@ -29,16 +31,18 @@ unset(CMAKE_REQUIRED_LIBRARIES)
configure_file(config-qt-wayland-patches-present.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-qt-wayland-patches-present.h)
##
-## Define the kritawayland library
+## Define the kritaplatformpluginwayland library
##
-set(kritawayland_LIB_SRCS
+set(kritaplatformpluginwayland_LIB_SRCS
KisWaylandKeyboardWatcher.cpp
+ KisExtendedModifiersMapperWayland.cpp
+ KritaPlatformPluginWayland.cpp
)
-kis_add_library(kritawayland SHARED ${kritawayland_LIB_SRCS})
+kis_add_library(kritaplatformpluginwayland MODULE ${kritaplatformpluginwayland_LIB_SRCS})
-qt6_generate_wayland_protocol_client_sources(kritawayland
+qt6_generate_wayland_protocol_client_sources(kritaplatformpluginwayland
FILES
"${CMAKE_CURRENT_SOURCE_DIR}/protocols/wayland.xml"
)
@@ -50,19 +54,14 @@ set_source_files_properties(
"${Qt6WaylandGlobalPrivate_INCLUDE_DIRS};${Qt6WaylandClient_PRIVATE_INCLUDE_DIRS};${Qt6Gui_PRIVATE_INCLUDE_DIRS}"
)
-target_link_libraries(kritawayland
+target_link_libraries(kritaplatformpluginwayland
PRIVATE
Qt::Gui
Qt::GuiPrivate
Qt::WaylandClient
kritaglobal
+ kritaui
)
-generate_export_header(kritawayland BASE_NAME kritawayland)
-
-set_target_properties(kritawayland PROPERTIES
- VERSION ${GENERIC_KRITA_LIB_VERSION} SOVERSION ${GENERIC_KRITA_LIB_SOVERSION}
-)
-
-install(TARGETS kritawayland ${INSTALL_TARGETS_DEFAULT_ARGS} )
+install(TARGETS kritaplatformpluginwayland DESTINATION ${KRITA_PLUGIN_INSTALL_DIR})
diff --git a/plugins/platforms/wayland/KisExtendedModifiersMapperWayland.cpp b/plugins/platforms/wayland/KisExtendedModifiersMapperWayland.cpp
new file mode 100644
index 0000000000..380dce698f
--- /dev/null
+++ b/plugins/platforms/wayland/KisExtendedModifiersMapperWayland.cpp
@@ -0,0 +1,27 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "KisExtendedModifiersMapperWayland.h"
+
+#include <input/kis_extended_modifiers_mapper.h>
+#include <krita_container_utils.h>
+
+KisExtendedModifiersMapperWayland::KisExtendedModifiersMapperWayland(QObject *parent, const QVariantList &)
+ : KisExtendedModifiersMapperPluginInterface(parent)
+{
+}
+
+KisExtendedModifiersMapperWayland::ExtendedModifiers KisExtendedModifiersMapperWayland::queryExtendedModifiers() {
+ ExtendedModifiers modifiers;
+ if (m_watcher.hasKeyboardFocus()) {
+ modifiers = m_watcher.pressedKeys();
+ KritaUtils::makeContainerUnique(modifiers);
+ } else {
+ modifiers = KisExtendedModifiersMapper::qtModifiersToQtKeys(m_watcher.modifiers());
+ }
+
+ return modifiers;
+}
\ No newline at end of file
diff --git a/plugins/platforms/wayland/KisExtendedModifiersMapperWayland.h b/plugins/platforms/wayland/KisExtendedModifiersMapperWayland.h
new file mode 100644
index 0000000000..2db407dc3f
--- /dev/null
+++ b/plugins/platforms/wayland/KisExtendedModifiersMapperWayland.h
@@ -0,0 +1,23 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef KIS_EXTENDED_MODIFIERS_MAPPER_WAYLAND_H
+#define KIS_EXTENDED_MODIFIERS_MAPPER_WAYLAND_H
+
+#include <input/KisExtendedModifiersMapperPluginInterface.h>
+#include <KisWaylandKeyboardWatcher.h>
+
+class KisExtendedModifiersMapperWayland : public KisExtendedModifiersMapperPluginInterface
+{
+public:
+ KisExtendedModifiersMapperWayland(QObject *parent, const QVariantList &);
+ ExtendedModifiers queryExtendedModifiers() override;
+
+private:
+ KisWaylandKeyboardWatcher m_watcher;
+};
+
+#endif // KIS_EXTENDED_MODIFIERS_MAPPER_WAYLAND_H
\ No newline at end of file
diff --git a/libs/wayland/KisWaylandKeyboardWatcher.cpp b/plugins/platforms/wayland/KisWaylandKeyboardWatcher.cpp
similarity index 100%
rename from libs/wayland/KisWaylandKeyboardWatcher.cpp
rename to plugins/platforms/wayland/KisWaylandKeyboardWatcher.cpp
diff --git a/libs/wayland/KisWaylandKeyboardWatcher.h b/plugins/platforms/wayland/KisWaylandKeyboardWatcher.h
similarity index 80%
rename from libs/wayland/KisWaylandKeyboardWatcher.h
rename to plugins/platforms/wayland/KisWaylandKeyboardWatcher.h
index 557d98b149..ea594176bf 100644
--- a/libs/wayland/KisWaylandKeyboardWatcher.h
+++ b/plugins/platforms/wayland/KisWaylandKeyboardWatcher.h
@@ -7,12 +7,10 @@
#ifndef KISWAYLANDKEYBOARDWATCHER_H
#define KISWAYLANDKEYBOARDWATCHER_H
-#include <kritawayland_export.h>
-
#include <memory>
#include <QList>
-class KRITAWAYLAND_EXPORT KisWaylandKeyboardWatcher
+class KisWaylandKeyboardWatcher
{
public:
KisWaylandKeyboardWatcher();
diff --git a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
new file mode 100644
index 0000000000..bfc00670cb
--- /dev/null
+++ b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
@@ -0,0 +1,13 @@
+/*
+ * SPDX-FileCopyrightText: 2025 Dmitry Kazakov <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include <kpluginfactory.h>
+
+#include <KisExtendedModifiersMapperWayland.h>
+
+K_PLUGIN_FACTORY_WITH_JSON(KritaPlatformPluginWaylandFactory, "kritaplatformwayland.json", registerPlugin<KisExtendedModifiersMapperWayland>();)
+
+#include <KritaPlatformPluginWayland.moc>
diff --git a/libs/wayland/config-qt-wayland-patches-present.h.cmake b/plugins/platforms/wayland/config-qt-wayland-patches-present.h.cmake
similarity index 100%
rename from libs/wayland/config-qt-wayland-patches-present.h.cmake
rename to plugins/platforms/wayland/config-qt-wayland-patches-present.h.cmake
diff --git a/plugins/platforms/wayland/kritaplatformwayland.json b/plugins/platforms/wayland/kritaplatformwayland.json
new file mode 100644
index 0000000000..6bb827c980
--- /dev/null
+++ b/plugins/platforms/wayland/kritaplatformwayland.json
@@ -0,0 +1,11 @@
+{
+ "Id": "kritaplatformwayland",
+ "Type": "Service",
+ "X-KDE-Library": "kritaplatformwayland",
+ "X-KDE-PluginInfo-Name": "Krita Platform Plugin for Wayland",
+ "X-KDE-ServiceTypes": [
+ "Krita/PlatformPlugin"
+ ],
+ "X-Krita-Version": "28",
+ "X-Krita-PlatformId": "wayland"
+}
diff --git a/libs/wayland/protocols/wayland.xml b/plugins/platforms/wayland/protocols/wayland.xml
similarity index 100%
rename from libs/wayland/protocols/wayland.xml
rename to plugins/platforms/wayland/protocols/wayland.xml