Changeset View
Changeset View
Standalone View
Standalone View
applets/colorpicker/plugin/grabwidget.cpp
Show All 23 Lines | |||||
24 | #include <QDBusConnection> | 24 | #include <QDBusConnection> | ||
25 | #include <QDBusMessage> | 25 | #include <QDBusMessage> | ||
26 | #include <QDBusMetaType> | 26 | #include <QDBusMetaType> | ||
27 | #include <QDBusPendingCall> | 27 | #include <QDBusPendingCall> | ||
28 | #include <QDBusPendingCallWatcher> | 28 | #include <QDBusPendingCallWatcher> | ||
29 | #include <QDBusPendingReply> | 29 | #include <QDBusPendingReply> | ||
30 | #include <QApplication> | 30 | #include <QApplication> | ||
31 | #include <QClipboard> | 31 | #include <QClipboard> | ||
32 | #include <QDesktopWidget> | ||||
32 | #include <QEvent> | 33 | #include <QEvent> | ||
33 | #include <QMouseEvent> | 34 | #include <QMouseEvent> | ||
34 | #include <QScreen> | 35 | #include <QScreen> | ||
35 | #include <QWidget> | 36 | #include <QWidget> | ||
36 | 37 | | |||
37 | #include <KWindowSystem> | 38 | #include <KWindowSystem> | ||
38 | 39 | | |||
39 | Q_DECLARE_METATYPE(QColor) | 40 | Q_DECLARE_METATYPE(QColor) | ||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Line(s) | 99 | if (watched == m_grabWidget && event->type() == QEvent::MouseButtonRelease) { | |||
99 | m_grabWidget->removeEventFilter(this); | 100 | m_grabWidget->removeEventFilter(this); | ||
100 | m_grabWidget->hide(); | 101 | m_grabWidget->hide(); | ||
101 | m_grabWidget->releaseMouse(); | 102 | m_grabWidget->releaseMouse(); | ||
102 | 103 | | |||
103 | QMouseEvent *me = static_cast<QMouseEvent *>(event); | 104 | QMouseEvent *me = static_cast<QMouseEvent *>(event); | ||
104 | 105 | | |||
105 | if (me->button() == Qt::LeftButton) { | 106 | if (me->button() == Qt::LeftButton) { | ||
106 | const QPoint pos = me->globalPos(); | 107 | const QPoint pos = me->globalPos(); | ||
107 | 108 | const QDesktopWidget *desktop = QApplication::desktop(); | |||
108 | // the grabbed pixmap will contain all screens, not just the primary one | 109 | const QPixmap pixmap = QGuiApplication::screens().at(desktop->screenNumber())->grabWindow(desktop->winId(), | ||
109 | // originally we traversed all screens looking for where the mouse is | 110 | pos.x(), pos.y(), 1, 1); | ||
110 | // but this isn't neccessarily apparently | 111 | if (!pixmap.isNull()) { | ||
111 | const QPixmap pixmap = qApp->primaryScreen()->grabWindow(0); | 112 | QImage i = pixmap.toImage(); | ||
112 | const QPoint localPos = pos * qApp->devicePixelRatio(); | 113 | QColor color(i.pixel(0, 0)); | ||
113 | 114 | setColor(color); | |||
114 | setColor(QColor(pixmap.toImage().pixel(localPos))); | 115 | } | ||
115 | } | 116 | } | ||
116 | } | 117 | } | ||
117 | 118 | | |||
118 | return QObject::eventFilter(watched, event); | 119 | return QObject::eventFilter(watched, event); | ||
119 | } | 120 | } | ||
120 | 121 | | |||
121 | KWinWaylandGrabber::KWinWaylandGrabber(QObject *parent) | 122 | KWinWaylandGrabber::KWinWaylandGrabber(QObject *parent) | ||
122 | : Grabber(parent) | 123 | : Grabber(parent) | ||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |