diff src/gui_beval.c @ 9624:d63b85fe3dc7 v7.4.2089

commit https://github.com/vim/vim/commit/36edf0685c8b55ee3ce709058d83ada8027fec1e Author: Bram Moolenaar <Bram@vim.org> Date: Thu Jul 21 22:10:12 2016 +0200 patch 7.4.2089 Problem: Color handling of X11 GUIs is too complicated. Solution: Simplify the code. Use RGBA where appropriate. (Kazunobu Kuriyama)
author Christian Brabandt <cb@256bit.org>
date Thu, 21 Jul 2016 22:15:05 +0200
parents 9495e43a800d
children 0c098fb3994c
line wrap: on
line diff
--- a/src/gui_beval.c
+++ b/src/gui_beval.c
@@ -1044,7 +1044,12 @@ set_printable_label_text(GtkLabel *label
 	attrentry_T	*aep;
 	PangoAttribute	*attr;
 	guicolor_T	pixel;
+#if GTK_CHECK_VERSION(3,0,0)
+	GdkRGBA		color = { 0.0, 0.0, 0.0, 1.0 };
+	PangoAttribute  *attr_alpha;
+#else
 	GdkColor	color = { 0, 0, 0, 0 };
+#endif
 
 	/* Look up the RGB values of the SpecialKey foreground color. */
 	aep = syn_gui_attr2entry(hl_attr(HLF_8));
@@ -1052,30 +1057,10 @@ set_printable_label_text(GtkLabel *label
 	if (pixel != INVALCOLOR)
 # if GTK_CHECK_VERSION(3,0,0)
 	{
-	    GdkVisual * const visual = gtk_widget_get_visual(gui.drawarea);
-
-	    if (visual == NULL)
-	    {
-		color.red = 0;
-		color.green = 0;
-		color.blue = 0;
-	    }
-	    else
-	    {
-		guint32 r_mask, g_mask, b_mask;
-		gint r_shift, g_shift, b_shift;
-
-		gdk_visual_get_red_pixel_details(visual, &r_mask, &r_shift,
-						 NULL);
-		gdk_visual_get_green_pixel_details(visual, &g_mask, &g_shift,
-						   NULL);
-		gdk_visual_get_blue_pixel_details(visual, &b_mask, &b_shift,
-						  NULL);
-
-		color.red = ((pixel & r_mask) >> r_shift) / 255.0 * 65535;
-		color.green = ((pixel & g_mask) >> g_shift) / 255.0 * 65535;
-		color.blue = ((pixel & b_mask) >> b_shift) / 255.0 * 65535;
-	    }
+	    color.red = ((pixel & 0xff0000) >> 16) / 255.0;
+	    color.green = ((pixel & 0xff00) >> 8) / 255.0;
+	    color.blue = (pixel & 0xff) / 255.0;
+	    color.alpha = 1.0;
 	}
 # else
 	    gdk_colormap_query_color(gtk_widget_get_colormap(gui.drawarea),
@@ -1124,11 +1109,27 @@ set_printable_label_text(GtkLabel *label
 		    }
 		    if (pixel != INVALCOLOR)
 		    {
+#if GTK_CHECK_VERSION(3,0,0)
+# define DOUBLE2UINT16(val) ((guint16)((val) * 65535 + 0.5))
+			attr = pango_attr_foreground_new(
+				DOUBLE2UINT16(color.red),
+				DOUBLE2UINT16(color.green),
+				DOUBLE2UINT16(color.blue));
+			attr_alpha = pango_attr_foreground_alpha_new(
+				DOUBLE2UINT16(color.alpha));
+# undef DOUBLE2UINT16
+#else
 			attr = pango_attr_foreground_new(
 				color.red, color.green, color.blue);
+#endif
 			attr->start_index = pdest - buf;
 			attr->end_index   = pdest - buf + outlen;
 			pango_attr_list_insert(attr_list, attr);
+#if GTK_CHECK_VERSION(3,0,0)
+			attr_alpha->start_index = pdest - buf;
+			attr_alpha->end_index   = pdest - buf + outlen;
+			pango_attr_list_insert(attr_list, attr_alpha);
+#endif
 		    }
 		    pdest += outlen;
 		    p += charlen;