From 673eee78a43678af127c6924a24fe3153cbb9217 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 22 Jan 2015 10:54:28 +0100 Subject: [PATCH] Better handling of non-truecolor colormaps. --- source/rofi.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/rofi.c b/source/rofi.c index 55d96b87..36b3c99b 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -363,6 +363,7 @@ GC gc = NULL; Colormap map = None; XVisualInfo vinfo; +int truecolor = FALSE; static void create_visual_and_colormap () { @@ -370,11 +371,14 @@ static void create_visual_and_colormap () // Try to create TrueColor map if ( XMatchVisualInfo ( display, DefaultScreen ( display ), 32, TrueColor, &vinfo ) ) { // Visual found, lets try to create map. - map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone ); + map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone ); + truecolor = TRUE; } // Failed to create map. // Use the defaults then. if ( map == None ) { + printf ( "fallback\n" ); + truecolor = FALSE; // Two fields we use. vinfo.visual = DefaultVisual ( display, DefaultScreen ( display ) ); vinfo.depth = DefaultDepth ( display, DefaultScreen ( display ) ); @@ -388,10 +392,18 @@ static void create_visual_and_colormap () static unsigned int color_get ( Display *display, const char *const name ) { int screen_id = DefaultScreen ( display ); - XColor color; + XColor color = { 0, }; // Special format. if ( strncmp ( name, "argb:", 5 ) == 0 ) { - return strtoul ( &name[5], NULL, 16 ); + color.pixel = strtoul ( &name[5], NULL, 16 ); + color.red = ( ( color.pixel & 0x00FF0000 ) >> 16 ) * 255; + color.green = ( ( color.pixel & 0x0000FF00 ) >> 8 ) * 255; + color.blue = ( ( color.pixel & 0x000000FF ) ) * 255; + if ( !truecolor ) { + // This will drop alpha part. + return XAllocColor ( display, map, &color ) ? color.pixel : None; + } + return color.pixel; } else { return XAllocNamedColor ( display, map, name, &color, &color ) ? color.pixel : None;