1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -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.
* Clean with textbox_cleanup()
*/
void textbox_setup ( void );
void textbox_setup ( Display *display );
/**
* Cleanup the allocated colors and fonts by textbox_setup().

View file

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

View file

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

View file

@ -54,10 +54,12 @@
( w1 ) ) && OVERLAP ( ( y ), ( h ), ( y1 ), ( h1 ) ) )
#include "x11-helper.h"
Atom netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
Atom netatoms[NUM_NETATOMS];
const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) };
// Mask indicating num-lock.
unsigned int NumlockMask = 0;
unsigned int NumlockMask = 0;
extern Colormap map;
// 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 )
@ -466,7 +468,6 @@ void x11_setup ( Display *display )
x11_create_frequently_used_atoms ( display );
}
extern Colormap map;
extern XVisualInfo vinfo;
int truecolor = FALSE;
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.
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;
color.red = ( ( color.pixel & 0x00FF0000 ) >> 16 ) * 256;
color.green = ( ( color.pixel & 0x0000FF00 ) >> 8 ) * 256;
color.blue = ( ( color.pixel & 0x000000FF ) ) * 256;
if ( !truecolor ) {
// This will drop alpha part.
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 );
// Set alternate row to normal row.
config.menu_bg_alt = config.menu_bg;
textbox_setup ( );
textbox_setup ( display );
textbox *box =
textbox_create ( TB_EDITABLE | TB_AUTOWIDTH | TB_AUTOHEIGHT, 0, 0, -1, -1,
NORMAL,