summaryrefslogtreecommitdiffstats
path: root/src/widgets/dialogs/qcolordialog.cpp
diff options
context:
space:
mode:
authorHarald Sitter <sitter@kde.org>2022-07-11 14:45:40 +0200
committerHarald Sitter <sitter@kde.org>2022-08-26 13:33:15 +0200
commitb646c7b76c7787cff57bca0fde04d9f58abdfbb8 (patch)
tree68c4a986a69fcaddee8a89023f9f7de1d80c196c /src/widgets/dialogs/qcolordialog.cpp
parentf8409b6e9c7f9a303fc78061182ce06de9bc795e (diff)
add color picking support on wayland using the XDG desktop portal
On wayland applications are not trusted to perform screen grabs by default, it is however possible to let the user specifically pick the color of a pixel using the XDG desktop portal (otherwise used for sandboxing etc.). Try to use this portal on unix systems by default. To support this use case some extra abstraction is necessary as this constitutes a platformservice rather than a platform feature. To that end the QPlatformService has gained a capability system and a pure virtual helper class to facilitate asynchronous color picking. When supported the color picking capability takes precedence over the custom picking code in QColorDialog. Fixes: QTBUG-81538 Change-Id: I4acb3af11d459e9d5ebefe5abbb41e50e3ccf7f0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/widgets/dialogs/qcolordialog.cpp')
-rw-r--r--src/widgets/dialogs/qcolordialog.cpp19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/widgets/dialogs/qcolordialog.cpp b/src/widgets/dialogs/qcolordialog.cpp
index deff2fbf27..e3265278c0 100644
--- a/src/widgets/dialogs/qcolordialog.cpp
+++ b/src/widgets/dialogs/qcolordialog.cpp
@@ -40,6 +40,7 @@
#include "private/qdialog_p.h"
#include <qpa/qplatformintegration.h>
+#include <qpa/qplatformservices.h>
#include <private/qguiapplication_p.h>
#include <algorithm>
@@ -1576,6 +1577,20 @@ void QColorDialogPrivate::_q_newStandard(int r, int c)
void QColorDialogPrivate::_q_pickScreenColor()
{
Q_Q(QColorDialog);
+
+ auto *platformServices = QGuiApplicationPrivate::platformIntegration()->services();
+ if (platformServices->hasCapability(QPlatformServices::Capability::ColorPicking)) {
+ if (auto *colorPicker = platformServices->colorPicker(q->windowHandle())) {
+ q->connect(colorPicker, &QPlatformServiceColorPicker::colorPicked, q,
+ [q, colorPicker](const QColor &color) {
+ colorPicker->deleteLater();
+ q->setCurrentColor(color);
+ });
+ colorPicker->pickColor();
+ return;
+ }
+ }
+
if (!colorPickingEventFilter)
colorPickingEventFilter = new QColorPickingEventFilter(this, q);
q->installEventFilter(colorPickingEventFilter);
@@ -1854,7 +1869,9 @@ void QColorDialogPrivate::retranslateStrings()
bool QColorDialogPrivate::supportsColorPicking() const
{
- return QGuiApplicationPrivate::platformIntegration()->hasCapability(QPlatformIntegration::ScreenWindowGrabbing);
+ const auto integration = QGuiApplicationPrivate::platformIntegration();
+ return integration->hasCapability(QPlatformIntegration::ScreenWindowGrabbing)
+ || integration->services()->hasCapability(QPlatformServices::Capability::ColorPicking);
}
bool QColorDialogPrivate::canBeNativeDialog() const