Bug 740634 - Color picker crashes when there are multiple monitors

Use Windows API directly to get a screen pixel, works for all kinds of
monitor layouts.
This commit is contained in:
Éric Hoffman
2017-04-06 23:50:26 +02:00
committed by Michael Natterer
parent b7ee733e9f
commit c585c99e80

View File

@ -22,6 +22,11 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#ifdef G_OS_WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#include "libgimpcolor/gimpcolor.h"
#include "gimpwidgetstypes.h"
@ -199,14 +204,41 @@ gimp_pick_button_pick (GdkScreen *screen,
gint y_root,
GimpPickButton *button)
{
GimpRGB rgb;
GimpColorProfile *monitor_profile;
gint monitor;
#ifdef G_OS_WIN32
HDC hdc;
RECT rect;
COLORREF win32_color;
/* For MS Windows, use native GDI functions to get the pixel, as
* cairo does not handle the case where you have multiple monitors
* with a monitor on the left or above the primary monitor. That
* scenario create a cairo primary surface with negative extent,
* which is not handled properly (bug 740634).
*/
hdc = GetDC (HWND_DESKTOP);
GetClipBox (hdc, &rect);
win32_color = GetPixel (hdc, x_root + rect.left, y_root + rect.top);
ReleaseDC (HWND_DESKTOP, hdc);
gimp_rgba_set_uchar (&rgb,
GetRValue (win32_color),
GetGValue (win32_color),
GetBValue (win32_color),
255);
#else
GdkWindow *root_window = gdk_screen_get_root_window (screen);
cairo_surface_t *image;
cairo_t *cr;
guchar *data;
guchar color[3];
GimpRGB rgb;
GimpColorProfile *monitor_profile;
gint monitor;
image = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 1, 1);
@ -224,6 +256,8 @@ gimp_pick_button_pick (GdkScreen *screen,
gimp_rgba_set_uchar (&rgb, color[0], color[1], color[2], 255);
#endif
monitor = gdk_screen_get_monitor_at_point (screen, x_root, y_root);
monitor_profile = gimp_screen_get_color_profile (screen, monitor);