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++

Fix error when opening settings, on some wayland compositors

Luna Lovecraftb8fdf7913b9e
diff --git a/libs/ui/KisPlatformPluginInterfaceFactory.cpp b/libs/ui/KisPlatformPluginInterfaceFactory.cpp
index bf1e7a697e..1b187af799 100644
--- a/libs/ui/KisPlatformPluginInterfaceFactory.cpp
+++ b/libs/ui/KisPlatformPluginInterfaceFactory.cpp
@@ -56,6 +56,10 @@ KisPlatformPluginInterfaceFactory* KisPlatformPluginInterfaceFactory::instance()
KisSurfaceColorManagerInterface* KisPlatformPluginInterfaceFactory::createSurfaceColorManager(QWindow *nativeWindow)
{
+ if (!surfaceColorManagedByOS()) {
+ return nullptr;
+ }
+
KPluginFactory *factory = KoPluginLoader::instance()->loadSinglePlugin(
std::make_pair("X-Krita-PlatformId", QApplication::platformName()),
"Krita/PlatformPlugin");
diff --git a/plugins/platforms/wayland/CMakeLists.txt b/plugins/platforms/wayland/CMakeLists.txt
index 9dbdd5c115..d6c220eda9 100644
--- a/plugins/platforms/wayland/CMakeLists.txt
+++ b/plugins/platforms/wayland/CMakeLists.txt
@@ -38,8 +38,7 @@ set(kritaplatformpluginwayland_LIB_SRCS
KisWaylandKeyboardWatcher.cpp
KisExtendedModifiersMapperWayland.cpp
KritaPlatformPluginWayland.cpp
-
-
+ KisWaylandRegistry.cpp
)
if (KRITA_USE_SURFACE_COLOR_MANAGEMENT_API)
diff --git a/plugins/platforms/wayland/KisWaylandRegistry.cpp b/plugins/platforms/wayland/KisWaylandRegistry.cpp
new file mode 100644
index 0000000000..3e39da90f5
--- /dev/null
+++ b/plugins/platforms/wayland/KisWaylandRegistry.cpp
@@ -0,0 +1,70 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Luna Lovecraft <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#include "KisWaylandRegistry.h"
+#include <qguiapplication.h>
+
+Q_GLOBAL_STATIC(KisWaylandRegistry, s_waylandRegistry)
+
+struct KisWaylandRegistry::Private
+{
+ QHash<uint32_t, std::pair<QString, uint32_t>> globals;
+ bool initialized = false;
+};
+
+KisWaylandRegistry::KisWaylandRegistry()
+ : d(new Private)
+{
+}
+
+KisWaylandRegistry::~KisWaylandRegistry()
+{
+}
+
+void KisWaylandRegistry::registry_global(uint32_t name, const QString &interface, uint32_t version)
+{
+ d->globals.insert(name, std::pair<QString, uint32_t>(interface, version));
+}
+
+bool KisWaylandRegistry::globalExists(const QString& interface)
+{
+ //Check if the interface is explicitly disabled
+ static QStringList interfaceBlacklist = qEnvironmentVariable("QT_WAYLAND_DISABLED_INTERFACES").split(u',');
+
+ if (interfaceBlacklist.contains(interface)) {
+ return false;
+ }
+
+ Q_FOREACH(auto global, d->globals.values()) {
+ if (global.first == interface)
+ return true;
+ }
+
+ return false;
+}
+
+void KisWaylandRegistry::registry_global_remove(uint32_t name)
+{
+ d->globals.remove(name);
+}
+
+KisWaylandRegistry* KisWaylandRegistry::getOrCreate()
+{
+ if (!s_waylandRegistry->d->initialized) {
+ KisWaylandRegistry *registry = s_waylandRegistry;
+ registry->d->initialized = true;
+
+ auto waylandApp = qGuiApp->nativeInterface<QNativeInterface::QWaylandApplication>();
+ auto display = waylandApp->display();
+ auto regisry = ::wl_display_get_registry(display);
+ registry->init(regisry);
+
+ //Wait for the compositor to populate the registry
+ ::wl_display_roundtrip(display);
+ }
+
+ return s_waylandRegistry;
+}
diff --git a/plugins/platforms/wayland/KisWaylandRegistry.h b/plugins/platforms/wayland/KisWaylandRegistry.h
new file mode 100644
index 0000000000..9998e75ffc
--- /dev/null
+++ b/plugins/platforms/wayland/KisWaylandRegistry.h
@@ -0,0 +1,30 @@
+/*
+ * SPDX-FileCopyrightText: 2026 Luna Lovecraft <[email protected]>
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#ifndef _KIS_WAYLAND_REGISTRY_
+#define _KIS_WAYLAND_REGISTRY_
+#include "qwayland-wayland.h"
+#include <qscopedpointer.h>
+
+/// Wayland registry for tracking wayland globals
+class KisWaylandRegistry : QtWayland::wl_registry
+{
+public:
+ static KisWaylandRegistry *getOrCreate();
+ bool globalExists(const QString &interface);
+ KisWaylandRegistry();
+ ~KisWaylandRegistry();
+
+protected:
+ void registry_global(uint32_t name, const QString &interface, uint32_t version) override;
+ void registry_global_remove(uint32_t name) override;
+
+private:
+ struct Private;
+ QScopedPointer<Private> d;
+};
+
+#endif
diff --git a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
index 741fa84da6..f935fa9e6f 100644
--- a/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
+++ b/plugins/platforms/wayland/KritaPlatformPluginWayland.cpp
@@ -4,6 +4,8 @@
* SPDX-License-Identifier: GPL-2.0-or-later
*/
+#include "KisWaylandRegistry.h"
+#include "qwayland-color-management-v1.h"
#include <kpluginfactory.h>
#include <kis_assert.h>
@@ -43,7 +45,8 @@ class KisWaylandSurfaceColorManagementInfo : public KisSurfaceColorManagementInf
public:
using KisSurfaceColorManagementInfo::KisSurfaceColorManagementInfo;
bool surfaceColorManagedByOS() override {
- return true;
+ KisWaylandRegistry* registry = KisWaylandRegistry::getOrCreate();
+ return registry->globalExists(QtWayland::wp_color_manager_v1::interface()->name);
}
QFuture<QString> debugReport() override {