Skip to content

Commit

Permalink
Update Color Picker
Browse files Browse the repository at this point in the history
Provide a way to pick color in a sandbox (flatpak) and wayland,  also avoid elevated permissions on macOS.

Keep old code as a fallback.
  • Loading branch information
rodlie committed Dec 25, 2024
1 parent 168c7ce commit 9fc0cff
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/core/canvasmouseinteractions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,21 @@ void Canvas::drawPathFinish(const qreal invScale) {

const QColor Canvas::pickPixelColor(const QPoint &pos)
{
// try the "safe" option first
if (QApplication::activeWindow()) {
const auto nPos = QApplication::activeWindow()->mapFromGlobal(pos);
return QApplication::activeWindow()->grab(QRect(QPoint(nPos.x(), nPos.y()),
QSize(1, 1))).toImage().pixel(0, 0);
}

// "insecure" fallback (will not work in a sandbox or wayland)
// will prompt for permissions on macOS
// Windows and X11 don't care
QScreen *screen = QApplication::screenAt(pos);
if (!screen) { return QColor(); }
WId wid = QApplication::desktop()->winId();
QImage img = screen->grabWindow(wid,
pos.x(), pos.y(),
1, 1).toImage();
return QColor(img.pixel(0, 0));
const auto pix = screen->grabWindow(wid, pos.x(), pos.y(), 1, 1);
return QColor(pix.toImage().pixel(0, 0));
}

void Canvas::applyPixelColor(const QColor &color,
Expand Down

0 comments on commit 9fc0cff

Please sign in to comment.