mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
x11-helper: Directly store the useful value
Signed-off-by: Quentin Glidic <sardemff7+git@sardemff7.net>
This commit is contained in:
parent
f39f5bb0cb
commit
88ddb7f04e
4 changed files with 25 additions and 29 deletions
|
@ -8,6 +8,7 @@
|
|||
#include <pango/pangocairo.h>
|
||||
#include <cairo.h>
|
||||
#include "widget.h"
|
||||
#include "x11-helper.h"
|
||||
|
||||
/**
|
||||
* @defgroup Textbox Textbox
|
||||
|
@ -16,11 +17,6 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double red, green, blue, alpha;
|
||||
} Color;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Widget widget;
|
||||
|
|
|
@ -151,19 +151,24 @@ void x11_setup ( Display *display );
|
|||
*/
|
||||
void create_visual_and_colormap ( Display *display );
|
||||
|
||||
typedef struct
|
||||
{
|
||||
double red, green, blue, alpha;
|
||||
} Color;
|
||||
|
||||
/**
|
||||
* @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, const char * const defn );
|
||||
Color color_get ( Display *display, const char *const name, const char * const defn );
|
||||
|
||||
void color_background ( Display *display, cairo_t *d );
|
||||
void color_border ( Display *display, cairo_t *d );
|
||||
void color_separator ( Display *display, cairo_t *d );
|
||||
void color_cache_reset ( void );
|
||||
|
||||
void x11_helper_set_cairo_rgba ( cairo_t *d, unsigned int pixel );
|
||||
void x11_helper_set_cairo_rgba ( cairo_t *d, Color col );
|
||||
/*@}*/
|
||||
#endif
|
||||
|
|
|
@ -623,12 +623,7 @@ int textbox_keypress ( textbox *tb, xcb_key_press_event_t *ev, char *pad, int pa
|
|||
*/
|
||||
static void parse_color ( Display *display, char *bg, Color *col )
|
||||
{
|
||||
unsigned int val = 0;
|
||||
val = color_get ( display, bg, "white" );
|
||||
col->alpha = ( ( val & 0xFF000000 ) >> 24 ) / 255.0;
|
||||
col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 255.0;
|
||||
col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 255.0;
|
||||
col->blue = ( ( val & 0x000000FF ) ) / 255.0;
|
||||
*col = color_get ( display, bg, "white" );
|
||||
}
|
||||
static void textbox_parse_string ( Display *display, const char *str, RowColor *color )
|
||||
{
|
||||
|
|
|
@ -600,7 +600,7 @@ void create_visual_and_colormap ( Display *display )
|
|||
}
|
||||
}
|
||||
|
||||
unsigned int color_get ( Display *display, const char *const name, const char * const defn )
|
||||
Color color_get ( Display *display, const char *const name, const char * const defn )
|
||||
{
|
||||
char *copy = g_strdup ( name );
|
||||
char *cname = g_strstrip ( copy );
|
||||
|
@ -637,16 +637,19 @@ unsigned int color_get ( Display *display, const char *const name, const char *
|
|||
}
|
||||
}
|
||||
g_free ( copy );
|
||||
return color.pixel;
|
||||
|
||||
Color ret = {
|
||||
.red = color.red / 65535.0,
|
||||
.green = color.green / 65535.0,
|
||||
.blue = color.blue / 65535.0,
|
||||
.alpha = ( ( color.pixel & 0xFF000000 ) >> 24 ) / 255.0,
|
||||
};
|
||||
return ret;
|
||||
}
|
||||
void x11_helper_set_cairo_rgba ( cairo_t *d, unsigned int pixel )
|
||||
|
||||
void x11_helper_set_cairo_rgba ( cairo_t *d, Color col )
|
||||
{
|
||||
cairo_set_source_rgba ( d,
|
||||
( ( pixel & 0x00FF0000 ) >> 16 ) / 255.0,
|
||||
( ( pixel & 0x0000FF00 ) >> 8 ) / 255.0,
|
||||
( ( pixel & 0x000000FF ) >> 0 ) / 255.0,
|
||||
( ( pixel & 0xFF000000 ) >> 24 ) / 255.0
|
||||
);
|
||||
cairo_set_source_rgba ( d, col.red, col.green, col.blue, col.alpha );
|
||||
}
|
||||
/**
|
||||
* Color cache.
|
||||
|
@ -659,15 +662,12 @@ enum
|
|||
BORDER,
|
||||
SEPARATOR
|
||||
};
|
||||
struct
|
||||
static struct
|
||||
{
|
||||
unsigned int color;
|
||||
Color color;
|
||||
unsigned int set;
|
||||
} color_cache[3] = {
|
||||
{ 0, FALSE },
|
||||
{ 0, FALSE },
|
||||
{ 0, FALSE }
|
||||
};
|
||||
} color_cache[3];
|
||||
|
||||
void color_cache_reset ( void )
|
||||
{
|
||||
color_cache[BACKGROUND].set = FALSE;
|
||||
|
|
Loading…
Reference in a new issue