1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-11 13:50:48 -05:00

Parse name in textbox.

This commit is contained in:
QC 2015-09-28 21:41:58 +02:00
parent ca8ff80a5c
commit 29360b20aa
5 changed files with 53 additions and 39 deletions

View file

@ -141,7 +141,7 @@ void textbox_insert ( textbox *tb, int pos, char *str );
* before any of the textbox_ functions is called. * before any of the textbox_ functions is called.
* Clean with textbox_cleanup() * Clean with textbox_cleanup()
*/ */
void textbox_setup ( void ); void textbox_setup ( Display *display );
/** /**
* Cleanup the allocated colors and fonts by textbox_setup(). * Cleanup the allocated colors and fonts by textbox_setup().

View file

@ -1492,7 +1492,7 @@ static int setup ()
if ( pfd >= 0 ) { if ( pfd >= 0 ) {
// Request truecolor visual. // Request truecolor visual.
create_visual_and_colormap ( display ); create_visual_and_colormap ( display );
textbox_setup ( ); textbox_setup ( display );
} }
return pfd; return pfd;
} }

View file

@ -568,27 +568,40 @@ int textbox_keypress ( textbox *tb, XIC xic, XEvent *ev )
/*** /***
* Font setup. * Font setup.
*/ */
static void parse_color ( char *bg, Color *col ) extern Colormap map;
static void parse_color ( Display *display, char *bg, Color *col )
{ {
unsigned int val = 0;
char *endptr = NULL;
if ( bg == NULL ) { if ( bg == NULL ) {
return; return;
} }
if ( strncmp ( bg, "argb:", 5 ) == 0 ) { if ( strncmp ( bg, "argb:", 5 ) == 0 ) {
unsigned int val = strtoul ( &bg[5], NULL, 16 ); val = strtoul ( &bg[5], &endptr, 16 );
col->alpha = ( ( val & 0xFF000000 ) >> 24 ) / 256.0; col->alpha = ( ( val & 0xFF000000 ) >> 24 ) / 256.0;
col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 256.0; col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 256.0;
col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 256.0; col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 256.0;
col->blue = ( ( val & 0x000000FF ) ) / 256.0; col->blue = ( ( val & 0x000000FF ) ) / 256.0;
} }
else { else if ( bg[0] == '#' ) {
unsigned int val = strtoul ( &bg[1], NULL, 16 ); val = strtoul ( &bg[1], &endptr, 16 );
col->alpha = 1; col->alpha = 1;
col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 256.0; col->red = ( ( val & 0x00FF0000 ) >> 16 ) / 256.0;
col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 256.0; col->green = ( ( val & 0x0000FF00 ) >> 8 ) / 256.0;
col->blue = ( ( val & 0x000000FF ) ) / 256.0; col->blue = ( ( val & 0x000000FF ) ) / 256.0;
} }
else {
XColor def, color = { 0, 0, 0, 0, 0, 0 };
Status st = XAllocNamedColor ( display, map, bg, &color, &def );
if ( st != None ) {
col->alpha = 1;
col->red = ( ( def.pixel & 0x00FF0000 ) >> 16 ) / 256.0;
col->green = ( ( def.pixel & 0x0000FF00 ) >> 8 ) / 256.0;
col->blue = ( ( def.pixel & 0x000000FF ) ) / 256.0;
} }
static void textbox_parse_string ( const char *str, RowColor *color ) }
}
static void textbox_parse_string ( Display *display, const char *str, RowColor *color )
{ {
if ( str == NULL ) { if ( str == NULL ) {
return; return;
@ -601,50 +614,50 @@ static void textbox_parse_string ( const char *str, RowColor *color )
switch ( index ) switch ( index )
{ {
case 0: case 0:
parse_color ( g_strstrip ( token ), &( color->bg ) ); parse_color ( display, g_strstrip ( token ), &( color->bg ) );
break; break;
case 1: case 1:
parse_color ( g_strstrip ( token ), &( color->fg ) ); parse_color ( display, g_strstrip ( token ), &( color->fg ) );
break; break;
case 2: case 2:
parse_color ( g_strstrip ( token ), &( color->bgalt ) ); parse_color ( display, g_strstrip ( token ), &( color->bgalt ) );
break; break;
case 3: case 3:
parse_color ( g_strstrip ( token ), &( color->hlbg ) ); parse_color ( display, g_strstrip ( token ), &( color->hlbg ) );
break; break;
case 4: case 4:
parse_color ( g_strstrip ( token ), &( color->hlfg ) ); parse_color ( display, g_strstrip ( token ), &( color->hlfg ) );
break; break;
} }
index++; index++;
} }
g_free ( cstr ); g_free ( cstr );
} }
void textbox_setup ( void ) void textbox_setup ( Display *display )
{ {
if ( config.color_enabled ) { if ( config.color_enabled ) {
textbox_parse_string ( config.color_normal, &( colors[NORMAL] ) ); textbox_parse_string ( display, config.color_normal, &( colors[NORMAL] ) );
textbox_parse_string ( config.color_urgent, &( colors[URGENT] ) ); textbox_parse_string ( display, config.color_urgent, &( colors[URGENT] ) );
textbox_parse_string ( config.color_active, &( colors[ACTIVE] ) ); textbox_parse_string ( display, config.color_active, &( colors[ACTIVE] ) );
} }
else { else {
parse_color ( config.menu_bg, &( colors[NORMAL].bg ) ); parse_color ( display, config.menu_bg, &( colors[NORMAL].bg ) );
parse_color ( config.menu_fg, &( colors[NORMAL].fg ) ); parse_color ( display, config.menu_fg, &( colors[NORMAL].fg ) );
parse_color ( config.menu_bg_alt, &( colors[NORMAL].bgalt ) ); parse_color ( display, config.menu_bg_alt, &( colors[NORMAL].bgalt ) );
parse_color ( config.menu_hlfg, &( colors[NORMAL].hlfg ) ); parse_color ( display, config.menu_hlfg, &( colors[NORMAL].hlfg ) );
parse_color ( config.menu_hlbg, &( colors[NORMAL].hlbg ) ); parse_color ( display, config.menu_hlbg, &( colors[NORMAL].hlbg ) );
parse_color ( config.menu_bg_urgent, &( colors[URGENT].bg ) ); parse_color ( display, config.menu_bg_urgent, &( colors[URGENT].bg ) );
parse_color ( config.menu_fg_urgent, &( colors[URGENT].fg ) ); parse_color ( display, config.menu_fg_urgent, &( colors[URGENT].fg ) );
parse_color ( config.menu_bg_alt, &( colors[URGENT].bgalt ) ); parse_color ( display, config.menu_bg_alt, &( colors[URGENT].bgalt ) );
parse_color ( config.menu_hlfg_urgent, &( colors[URGENT].hlfg ) ); parse_color ( display, config.menu_hlfg_urgent, &( colors[URGENT].hlfg ) );
parse_color ( config.menu_hlbg_urgent, &( colors[URGENT].hlbg ) ); parse_color ( display, config.menu_hlbg_urgent, &( colors[URGENT].hlbg ) );
parse_color ( config.menu_bg_active, &( colors[ACTIVE].bg ) ); parse_color ( display, config.menu_bg_active, &( colors[ACTIVE].bg ) );
parse_color ( config.menu_fg_active, &( colors[ACTIVE].fg ) ); parse_color ( display, config.menu_fg_active, &( colors[ACTIVE].fg ) );
parse_color ( config.menu_bg_alt, &( colors[ACTIVE].bgalt ) ); parse_color ( display, config.menu_bg_alt, &( colors[ACTIVE].bgalt ) );
parse_color ( config.menu_hlfg_active, &( colors[ACTIVE].hlfg ) ); parse_color ( display, config.menu_hlfg_active, &( colors[ACTIVE].hlfg ) );
parse_color ( config.menu_hlbg_active, &( colors[ACTIVE].hlbg ) ); parse_color ( display, config.menu_hlbg_active, &( colors[ACTIVE].hlbg ) );
} }
PangoFontMap *font_map = pango_cairo_font_map_new (); PangoFontMap *font_map = pango_cairo_font_map_new ();
p_context = pango_font_map_create_context ( font_map ); p_context = pango_font_map_create_context ( font_map );

View file

@ -59,6 +59,8 @@ const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
// Mask indicating num-lock. // Mask indicating num-lock.
unsigned int NumlockMask = 0; unsigned int NumlockMask = 0;
extern Colormap map;
// retrieve a property of any type from a window // retrieve a property of any type from a window
int window_get_prop ( Display *display, Window w, Atom prop, Atom *type, int *items, void *buffer, unsigned int bytes ) int window_get_prop ( Display *display, Window w, Atom prop, Atom *type, int *items, void *buffer, unsigned int bytes )
{ {
@ -466,7 +468,6 @@ void x11_setup ( Display *display )
x11_create_frequently_used_atoms ( display ); x11_create_frequently_used_atoms ( display );
} }
extern Colormap map;
extern XVisualInfo vinfo; extern XVisualInfo vinfo;
int truecolor = FALSE; int truecolor = FALSE;
void create_visual_and_colormap ( Display *display ) void create_visual_and_colormap ( Display *display )
@ -504,9 +505,9 @@ unsigned int color_get ( Display *display, const char *const name, const char *
// Special format. // Special format.
if ( strncmp ( name, "argb:", 5 ) == 0 ) { if ( strncmp ( name, "argb:", 5 ) == 0 ) {
color.pixel = strtoul ( &name[5], NULL, 16 ); color.pixel = strtoul ( &name[5], NULL, 16 );
color.red = ( ( color.pixel & 0x00FF0000 ) >> 16 ) * 255; color.red = ( ( color.pixel & 0x00FF0000 ) >> 16 ) * 256;
color.green = ( ( color.pixel & 0x0000FF00 ) >> 8 ) * 255; color.green = ( ( color.pixel & 0x0000FF00 ) >> 8 ) * 256;
color.blue = ( ( color.pixel & 0x000000FF ) ) * 255; color.blue = ( ( color.pixel & 0x000000FF ) ) * 256;
if ( !truecolor ) { if ( !truecolor ) {
// This will drop alpha part. // This will drop alpha part.
Status st = XAllocColor ( display, map, &color ); Status st = XAllocColor ( display, map, &color );

View file

@ -90,7 +90,7 @@ int main ( G_GNUC_UNUSED int argc, G_GNUC_UNUSED char **argv )
cairo_set_operator ( draw, CAIRO_OPERATOR_SOURCE ); cairo_set_operator ( draw, CAIRO_OPERATOR_SOURCE );
// Set alternate row to normal row. // Set alternate row to normal row.
config.menu_bg_alt = config.menu_bg; config.menu_bg_alt = config.menu_bg;
textbox_setup ( ); textbox_setup ( display );
textbox *box = textbox *box =
textbox_create ( TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1, textbox_create ( TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1,
NORMAL, NORMAL,