From 9160a7ceb3ac9e30973ea65f0908e72c2f476e74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Wed, 17 Feb 2016 13:53:57 +0800 Subject: [PATCH] x11: Premultiply custom cursor image alpha As with Wayland, X11 expects cursor pixels to have the alpha premultiplied, so lets convert the non-premultiplied pixels to premultiplied pixels. Fixes #353. Closes #707. --- src/x11_init.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/x11_init.c b/src/x11_init.c index e4e13729..0125a8b7 100644 --- a/src/x11_init.c +++ b/src/x11_init.c @@ -690,10 +690,12 @@ Cursor _glfwCreateCursorX11(const GLFWimage* image, int xhot, int yhot) for (i = 0; i < image->width * image->height; i++, target++, source += 4) { - *target = (source[3] << 24) | - (source[0] << 16) | - (source[1] << 8) | - source[2]; + unsigned char alpha = source[3]; + + *target = (alpha << 24) | + (_glfwMultiplyAlpha(alpha, source[0]) << 16) | + (_glfwMultiplyAlpha(alpha, source[1]) << 8) | + _glfwMultiplyAlpha(alpha, source[2]); } cursor = XcursorImageLoadCursor(_glfw.x11.display, native);