summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2017-01-08 16:09:24 +0100
committerDave Davenport <qball@gmpclient.org>2017-01-08 16:09:24 +0100
commitc57e7348d2e34c7eb27fafa73b40602725ea315a (patch)
tree3db8e06a1a46941fcd94244db658d35a73768e5a /source
parent6318e5024b155d5b7383d9352ba56e464f91b3b7 (diff)
Add some better error message. Allow -theme-str option to override part of theme
Diffstat (limited to 'source')
-rw-r--r--source/helper.c21
-rw-r--r--source/rofi.c13
-rw-r--r--source/theme.c21
-rw-r--r--source/widgets/listview.c16
4 files changed, 64 insertions, 7 deletions
diff --git a/source/helper.c b/source/helper.c
index 9f529577..dd26d828 100644
--- a/source/helper.c
+++ b/source/helper.c
@@ -295,6 +295,27 @@ int find_arg_str ( const char * const key, char** val )
return FALSE;
}
+const char ** find_arg_strv ( const char *const key )
+{
+ const char **retv =NULL;
+ int length = 0;
+ for ( int i = 0; i < stored_argc; i++ ) {
+ if ( strcasecmp ( stored_argv[i], key ) == 0 && i < (stored_argc -1 ) ){
+ length++;
+ }
+ }
+ if ( length > 0 ) {
+ retv = g_malloc0((length+1)*sizeof(char*));
+ int index = 0;
+ for ( int i = 0; i < stored_argc; i++ ) {
+ if ( strcasecmp ( stored_argv[i], key ) == 0 && i < (stored_argc -1 ) ){
+ retv[index] = stored_argv[i+1];
+ }
+ }
+ }
+ return retv;
+}
+
int find_arg_int ( const char * const key, int *val )
{
int i = find_arg ( key );
diff --git a/source/rofi.c b/source/rofi.c
index ee57f6da..f10cba4c 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -952,6 +952,19 @@ int main ( int argc, char *argv[] )
rofi_theme_convert_old_theme ( );
}
+ const char ** theme_str = find_arg_strv ( "-theme-str" );
+ if ( theme_str ) {
+ for ( int index = 0; theme_str && theme_str[index]; index++ ){
+ if ( ! rofi_theme_parse_string ( theme_str[index] ) ){
+ fprintf(stderr, "Failed to parse: %s\n", theme_str[index]);
+ exit ( EXIT_FAILURE );
+ }
+ }
+ g_free ( theme_str );
+ }
+
+
+
if ( find_arg ( "-dump-theme" ) >= 0 ){
rofi_theme_print ( rofi_theme );
exit (EXIT_SUCCESS);
diff --git a/source/theme.c b/source/theme.c
index 2680a504..080bb1e5 100644
--- a/source/theme.c
+++ b/source/theme.c
@@ -789,17 +789,34 @@ void rofi_theme_convert_old_theme ( void )
}
}
}
-void rofi_theme_parse_file ( const char *file )
+gboolean rofi_theme_parse_file ( const char *file )
{
char *filename = rofi_expand_path ( file );
yyin = fopen ( filename, "rb");
if ( yyin == NULL ){
fprintf(stderr, "Failed to open file: %s: '%s'\n", filename, strerror ( errno ) );
g_free(filename);
- return;
+ return TRUE;
}
+ extern int str_len;
+ extern const char*input_str;
+ str_len = 0;
+ input_str = NULL;
while ( yyparse() );
yylex_destroy();
g_free(filename);
+ yyin = NULL;
+ return FALSE;
+}
+gboolean rofi_theme_parse_string ( const char *string )
+{
+ extern int str_len;
+ extern const char*input_str;
+ yyin = NULL;
+ input_str = string;
+ str_len = strlen ( string );
+ while ( yyparse () );
+ yylex_destroy();
+ return TRUE;
}
#endif
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index e2e61970..c348ac1f 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -80,6 +80,9 @@ struct _listview
xcb_timestamp_t last_click;
listview_mouse_activated_cb mouse_activated;
void *mouse_activated_data;
+
+
+ char *listview_name;
};
static int listview_get_desired_height ( widget *wid );
@@ -92,6 +95,7 @@ static void listview_free ( widget *wid )
}
g_free ( lv->boxes );
+ g_free( lv->listview_name );
widget_free ( WIDGET ( lv->scrollbar ) );
g_free ( lv );
}
@@ -234,7 +238,7 @@ static void listview_recompute_elements ( listview *lv )
if ( newne > 0 ) {
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
- char *name = g_strjoin (".", lv->widget.name,"element", NULL);
+ char *name = g_strjoin (".", lv->listview_name,"element", NULL);
lv->boxes[i] = textbox_create ( name, flags, NORMAL, "" );
g_free ( name );
}
@@ -351,8 +355,10 @@ static gboolean listview_motion_notify ( widget *wid, xcb_motion_notify_event_t
listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse )
{
listview *lv = g_malloc0 ( sizeof ( listview ) );
-
- widget_init ( WIDGET ( lv ), name );
+ gchar *box = g_strjoin (".", name, "box", NULL );
+ widget_init ( WIDGET ( lv ), box );
+ g_free(box);
+ lv->listview_name = g_strdup ( name );
lv->widget.free = listview_free;
lv->widget.resize = listview_resize;
lv->widget.draw = listview_draw;
@@ -362,7 +368,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->widget.enabled = TRUE;
lv->eh = eh;
- char *n = g_strjoin(".", lv->widget.name,"scrollbar", NULL);
+ char *n = g_strjoin(".", lv->listview_name,"scrollbar", NULL);
lv->scrollbar = scrollbar_create ( n );
// Default position on right.
lv->scrollbar->widget.index = rofi_theme_get_integer_exact ( WIDGET (lv->scrollbar), "index", 1);
@@ -371,7 +377,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->scrollbar->widget.parent = WIDGET ( lv );
// Calculate height of an element.
//
- char *tb_name = g_strjoin (".", lv->widget.name,"element", NULL);
+ char *tb_name = g_strjoin (".", lv->listview_name,"element", NULL);
textbox *tb = textbox_create ( tb_name, 0, NORMAL, "" );
lv->element_height = textbox_get_estimated_height (tb, lv->eh);
g_free(tb_name);