From b6652a022114b3c5982523637d30551d16f31553 Mon Sep 17 00:00:00 2001 From: QC Date: Sat, 14 Feb 2015 19:42:04 +0100 Subject: [PATCH] Small move --- include/x11-helper.h | 17 +++++++++++++ source/rofi.c | 59 +++----------------------------------------- source/x11-helper.c | 45 +++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 56 deletions(-) diff --git a/include/x11-helper.h b/include/x11-helper.h index d0361a7a..dae16772 100644 --- a/include/x11-helper.h +++ b/include/x11-helper.h @@ -115,4 +115,21 @@ void x11_set_window_opacity ( Display *display, Window box, unsigned int opacity * * Cache */ void x11_setup ( Display *display ); + +/** + * @param display Connection to the X server. + * + * This function tries to create a 32bit TrueColor colormap. + * If this fails, it falls back to the default for the connected display. + */ +void create_visual_and_colormap ( Display *display ); + + +/** + * @param display Connection to the X server. + * @param name String representing the color. + * + * Allocate a pixel value for an X named color + */ +unsigned int color_get ( Display *display, const char *const name ); #endif diff --git a/source/rofi.c b/source/rofi.c index c2625536..226c062c 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -44,11 +44,11 @@ #include #include -#include "helper.h" -#include "x11-helper.h" #include "rofi.h" -#include "xrmoptions.h" +#include "helper.h" #include "textbox.h" +#include "x11-helper.h" +#include "xrmoptions.h" // Switchers. #include "dialogs/run-dialog.h" #include "dialogs/ssh-dialog.h" @@ -130,59 +130,6 @@ Window main_window = None; GC gc = NULL; Colormap map = None; XVisualInfo vinfo; -int truecolor = FALSE; - -/** - * @param display Connection to the X server. - * - * This function tries to create a 32bit TrueColor colormap. - * If this fails, it falls back to the default for the connected display. - */ -static void create_visual_and_colormap ( Display *display ) -{ - int screen = DefaultScreen ( display ); - // Try to create TrueColor map - if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) { - // Visual found, lets try to create map. - map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone ); - truecolor = TRUE; - } - // Failed to create map. - // Use the defaults then. - if ( map == None ) { - truecolor = FALSE; - // Two fields we use. - vinfo.visual = DefaultVisual ( display, screen ); - vinfo.depth = DefaultDepth ( display, screen ); - map = DefaultColormap ( display, screen ); - } -} - -/** - * @param display Connection to the X server. - * @param name String representing the color. - * - * Allocate a pixel value for an X named color - */ -static unsigned int color_get ( Display *display, const char *const name ) -{ - XColor color = { 0, 0, 0, 0, 0, 0 }; - // Special format. - if ( strncmp ( name, "argb:", 5 ) == 0 ) { - 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; - } -} /** * @param display Connection to the X server. diff --git a/source/x11-helper.c b/source/x11-helper.c index 3af847b7..a187810e 100644 --- a/source/x11-helper.c +++ b/source/x11-helper.c @@ -407,3 +407,48 @@ void x11_setup ( Display *display ) x11_figure_out_numlock_mask ( display ); x11_create_frequently_used_atoms ( display ); } + + + +extern Colormap map; +extern XVisualInfo vinfo; +int truecolor = FALSE; +void create_visual_and_colormap ( Display *display ) +{ + int screen = DefaultScreen ( display ); + // Try to create TrueColor map + if ( XMatchVisualInfo ( display, screen, 32, TrueColor, &vinfo ) ) { + // Visual found, lets try to create map. + map = XCreateColormap ( display, DefaultRootWindow ( display ), vinfo.visual, AllocNone ); + truecolor = TRUE; + } + // Failed to create map. + // Use the defaults then. + if ( map == None ) { + truecolor = FALSE; + // Two fields we use. + vinfo.visual = DefaultVisual ( display, screen ); + vinfo.depth = DefaultDepth ( display, screen ); + map = DefaultColormap ( display, screen ); + } +} + +unsigned int color_get ( Display *display, const char *const name ) +{ + XColor color = { 0, 0, 0, 0, 0, 0 }; + // Special format. + if ( strncmp ( name, "argb:", 5 ) == 0 ) { + 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; + } +}