UI: Allow eyedropper outside of Blender (X11) #111493

Manually merged
Campbell Barton merged 1 commits from vitorboschi/blender:feature/eyedropper_x11 into main 2023-08-26 09:21:20 +02:00
2 changed files with 37 additions and 2 deletions

View File

@ -1526,6 +1526,36 @@ void GHOST_SystemX11::processEvent(XEvent *xe)
}
}
GHOST_TSuccess GHOST_SystemX11::getPixelAtCursor(float r_color[3]) const
{
XColor c;
int32_t x, y;
if (getCursorPosition(x, y) == GHOST_kFailure) {
return GHOST_kFailure;
}
auto *image = XGetImage(m_display,
XRootWindow(m_display, XDefaultScreen(m_display)),
x,
y,
1,
1,
AllPlanes,
XYPixmap);
if (image == nullptr) {
return GHOST_kFailure;
}
c.pixel = XGetPixel(image, 0, 0);
XFree(image);
XQueryColor(m_display, XDefaultColormap(m_display, XDefaultScreen(m_display)), &c);
/* X11 returns colors in the [0, 65535] range, so we need to scale back to [0, 1] for Blender. */
r_color[0] = c.red / 65535.0f;
r_color[1] = c.green / 65535.0f;
r_color[2] = c.blue / 65535.0f;
return GHOST_kSuccess;
}
GHOST_TSuccess GHOST_SystemX11::getModifierKeys(GHOST_ModifierKeys &keys) const
{
@ -1693,8 +1723,6 @@ GHOST_TCapabilityFlag GHOST_SystemX11::getCapabilities() const
{
return GHOST_TCapabilityFlag(GHOST_CAPABILITY_FLAG_ALL &
~(
/* No support yet for desktop sampling. */
GHOST_kCapabilityDesktopSample |
/* No support yet for image copy/paste. */
GHOST_kCapabilityClipboardImages));
}

View File

@ -154,6 +154,13 @@ class GHOST_SystemX11 : public GHOST_System {
GHOST_TSuccess setCursorPosition(int32_t x, int32_t y) override;
/**
* Get the color of the pixel at the current mouse cursor location
* \param r_color: returned sRGB float colors
* \return Success value (true == successful and supported by platform)
*/
GHOST_TSuccess getPixelAtCursor(float r_color[3]) const override;
/**
* Returns the state of all modifier keys.
* \param keys: The state of all modifier keys (true == pressed).