From 50477a0b99e893da8858fad0e0318b8d4e63b3a5 Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 17 Mar 2017 14:07:11 +0100 Subject: [Keys] Cleanup view a bit. --- source/dialogs/combi.c | 18 +++++++++--------- source/dialogs/drun.c | 6 +++--- source/dialogs/ssh.c | 34 +++++++++++++++++----------------- source/mode.c | 2 +- source/rofi.c | 2 +- source/theme.c | 16 ++++++++-------- source/view.c | 10 +++++----- source/widgets/textbox.c | 16 +++++++--------- source/widgets/widget.c | 16 ++++++++-------- source/xrmoptions.c | 46 +++++++++++++++++++++++++++++++--------------- 10 files changed, 90 insertions(+), 76 deletions(-) (limited to 'source') diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 4da67f31..18d25813 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -204,22 +204,22 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat } for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { - char * str = mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, TRUE ); + char * str = mode_get_display_value ( pd->switchers[i].mode, selected_line - pd->starts[i], state, attr_list, TRUE ); const char *dname = mode_get_display_name ( pd->switchers[i].mode ); - char * retv = g_strdup_printf ( "%s %s", dname, str ); + char * retv = g_strdup_printf ( "%s %s", dname, str ); g_free ( str ); if ( attr_list != NULL ) { - ThemeWidget *wid = rofi_theme_find_widget ( sw->name, NULL, TRUE); - Property *p = rofi_theme_find_property ( wid, P_COLOR, pd->switchers[i].mode->name, TRUE); + ThemeWidget *wid = rofi_theme_find_widget ( sw->name, NULL, TRUE ); + Property *p = rofi_theme_find_property ( wid, P_COLOR, pd->switchers[i].mode->name, TRUE ); if ( p != NULL ) { PangoAttribute *pa = pango_attr_foreground_new ( - p->value.color.red * 65535, - p->value.color.green * 65535, - p->value.color.blue * 65535 ); + p->value.color.red * 65535, + p->value.color.green * 65535, + p->value.color.blue * 65535 ); pa->start_index = PANGO_ATTR_INDEX_FROM_TEXT_BEGINNING; - pa->end_index = strlen(dname); - *attr_list = g_list_append ( *attr_list, pa ); + pa->end_index = strlen ( dname ); + *attr_list = g_list_append ( *attr_list, pa ); } } return retv; diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index ed7e5b51..639b2b39 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -69,7 +69,7 @@ typedef struct /* Generic Name */ char *generic_name; #ifdef GET_CAT_PARSE_TIME - char **categories; + char **categories; #endif GKeyFile *key_file; @@ -273,9 +273,9 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const gchar *gn = g_key_file_get_locale_string ( kf, "Desktop Entry", "GenericName", NULL, NULL ); pd->entry_list[pd->cmd_list_length].generic_name = gn; #ifdef GET_CAT_PARSE_TIME - pd->entry_list[pd->cmd_list_length].categories= g_key_file_get_locale_string_list ( kf, "Desktop Entry", "Categories", NULL, NULL, NULL ); + pd->entry_list[pd->cmd_list_length].categories = g_key_file_get_locale_string_list ( kf, "Desktop Entry", "Categories", NULL, NULL, NULL ); #endif - pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL ); + pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, "Desktop Entry", "Exec", NULL ); // Keep keyfile around. pd->entry_list[pd->cmd_list_length].key_file = kf; diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 0e9bca06..a332dd5f 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -50,12 +50,11 @@ #include "history.h" #include "dialogs/ssh.h" - /** * Log domain for the ssh modi. */ -#define LOG_DOMAIN "Dialogs.Ssh" +#define LOG_DOMAIN "Dialogs.Ssh" /** * Name of the history file where previously choosen hosts are stored. @@ -265,9 +264,9 @@ static char **read_hosts_file ( char ** retv, unsigned int *length ) static void parse_ssh_config_file ( const char *filename, char ***retv, unsigned int *length, unsigned int num_favorites ) { - FILE *fd = fopen ( filename, "r" ); + FILE *fd = fopen ( filename, "r" ); - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Parsing ssh config file: %s" , filename); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Parsing ssh config file: %s", filename ); if ( fd != NULL ) { char *buffer = NULL; size_t buffer_length = 0; @@ -286,22 +285,23 @@ static void parse_ssh_config_file ( const char *filename, char ***retv, unsigned continue; } - if ( g_strcmp0 ( token, "Include") == 0 ) { + if ( g_strcmp0 ( token, "Include" ) == 0 ) { token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ); - g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Found Include: %s" , token); - gchar *path = rofi_expand_path ( token ); + g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Found Include: %s", token ); + gchar *path = rofi_expand_path ( token ); gchar *full_path = NULL; - if ( ! g_path_is_absolute ( path ) ){ + if ( !g_path_is_absolute ( path ) ) { char *dirname = g_path_get_dirname ( filename ); full_path = g_build_filename ( dirname, path, NULL ); - g_free(dirname); - } else { + g_free ( dirname ); + } + else { full_path = g_strdup ( path ); } - glob_t globbuf = {0,}; + glob_t globbuf = { 0, }; - if ( glob ( full_path, 0, NULL, &globbuf ) == 0 ){ - for ( size_t iter = 0; iter < globbuf.gl_pathc; iter++){ + if ( glob ( full_path, 0, NULL, &globbuf ) == 0 ) { + for ( size_t iter = 0; iter < globbuf.gl_pathc; iter++ ) { parse_ssh_config_file ( globbuf.gl_pathv[iter], retv, length, num_favorites ); } } @@ -333,7 +333,7 @@ static void parse_ssh_config_file ( const char *filename, char ***retv, unsigned // given num_favorites is max 25. int found = 0; for ( unsigned int j = 0; j < num_favorites; j++ ) { - if ( !g_ascii_strcasecmp ( token, (*retv)[j] ) ) { + if ( !g_ascii_strcasecmp ( token, ( *retv )[j] ) ) { found = 1; break; } @@ -344,9 +344,9 @@ static void parse_ssh_config_file ( const char *filename, char ***retv, unsigned } // Add this host name to the list. - (*retv) = g_realloc ( (*retv), ( ( *length ) + 2 ) * sizeof ( char* ) ); - (*retv)[( *length )] = g_strdup ( token ); - (*retv)[( *length ) + 1] = NULL; + ( *retv ) = g_realloc ( ( *retv ), ( ( *length ) + 2 ) * sizeof ( char* ) ); + ( *retv )[( *length )] = g_strdup ( token ); + ( *retv )[( *length ) + 1] = NULL; ( *length )++; } } diff --git a/source/mode.c b/source/mode.c index ed15ff1b..c3a1456f 100644 --- a/source/mode.c +++ b/source/mode.c @@ -53,7 +53,7 @@ char * mode_get_completion ( const Mode *mode, unsigned int selected_line ) else { int state; g_assert ( mode->_get_display_value != NULL ); - return mode->_get_display_value ( mode, selected_line, &state,NULL, TRUE ); + return mode->_get_display_value ( mode, selected_line, &state, NULL, TRUE ); } } diff --git a/source/rofi.c b/source/rofi.c index c2e4fc16..67fa5fe6 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -404,7 +404,7 @@ static void cleanup () * Collected modi */ /** List of (possibly uninitialized) modi's */ -Mode ** available_modi = NULL; +Mode ** available_modi = NULL; /** Length of #num_available_modi */ unsigned int num_available_modi = 0; diff --git a/source/theme.c b/source/theme.c index c57778c4..04dba19b 100644 --- a/source/theme.c +++ b/source/theme.c @@ -273,10 +273,10 @@ void yyerror ( YYLTYPE *yylloc, const char *what, const char* s ) g_string_append_printf ( str, "\tParser error: %s\n", esc ); g_free ( esc ); if ( yylloc->filename != NULL ) { - g_string_append_printf ( str, "\tLocation: line %d column %d to line %d column %d.\n"\ - "\tFile '%s'\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column, yylloc->filename); - - }else { + g_string_append_printf ( str, "\tLocation: line %d column %d to line %d column %d.\n" \ + "\tFile '%s'\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column, yylloc->filename ); + } + else { g_string_append_printf ( str, "\tLocation: line %d column %d to line %d column %d\n", yylloc->first_line, yylloc->first_column, yylloc->last_line, yylloc->last_column ); } rofi_add_error_message ( str ); @@ -320,10 +320,10 @@ static ThemeWidget *rofi_theme_find ( ThemeWidget *widget, const char *name, con if ( widget == NULL || name == NULL ) { return widget; } - char *tname = g_strdup(name ); + char *tname = g_strdup ( name ); char *saveptr = NULL; - int found = TRUE; - for (const char *iter = strtok_r (tname, ".", &saveptr); iter != NULL ; iter = strtok_r ( NULL, "." , &saveptr ) ) { + int found = TRUE; + for ( const char *iter = strtok_r ( tname, ".", &saveptr ); iter != NULL; iter = strtok_r ( NULL, ".", &saveptr ) ) { found = FALSE; ThemeWidget *f = rofi_theme_find_single ( widget, iter ); if ( f != widget ) { @@ -567,7 +567,7 @@ gboolean rofi_theme_is_empty ( void ) if ( rofi_theme == NULL ) { return TRUE; } - if ( rofi_theme->properties == NULL && rofi_theme->num_widgets == 0 ) { + if ( rofi_theme->properties == NULL && rofi_theme->num_widgets == 0 ) { return TRUE; } diff --git a/source/view.c b/source/view.c index 63d269b5..8bf0c149 100644 --- a/source/view.c +++ b/source/view.c @@ -879,8 +879,8 @@ static void update_callback ( textbox *t, unsigned int index, void *udata, TextB RofiViewState *state = (RofiViewState *) udata; if ( full ) { GList *add_list = NULL; - int fstate = 0; - char *text = mode_get_display_value ( state->sw, state->line_map[index], &fstate, &add_list, TRUE ); + int fstate = 0; + char *text = mode_get_display_value ( state->sw, state->line_map[index], &fstate, &add_list, TRUE ); type |= fstate; textbox_font ( t, type ); // Move into list view. @@ -898,12 +898,12 @@ static void update_callback ( textbox *t, unsigned int index, void *udata, TextB th = rofi_theme_get_highlight ( WIDGET ( t ), "highlight", th ); helper_token_match_get_pango_attr ( th, state->tokens, textbox_get_visible_text ( t ), list ); } - for ( GList *iter = g_list_first ( add_list ); iter != NULL ; iter = g_list_next(iter) ) { - pango_attr_list_insert ( list, (PangoAttribute *)(iter->data)); + for ( GList *iter = g_list_first ( add_list ); iter != NULL; iter = g_list_next ( iter ) ) { + pango_attr_list_insert ( list, (PangoAttribute *) ( iter->data ) ); } textbox_set_pango_attributes ( t, list ); pango_attr_list_unref ( list ); - g_list_free( add_list); + g_list_free ( add_list ); g_free ( text ); } else { diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 77d7ef28..097748cc 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -330,15 +330,13 @@ static void textbox_free ( widget *wid ) static void textbox_draw ( widget *wid, cairo_t *draw ) { - textbox *tb = (textbox *) wid; - unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; - + textbox *tb = (textbox *) wid; + unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; if ( tb->changed ) { __textbox_update_pango_text ( tb ); } - // Skip the side MARGIN on the X axis. int x = widget_padding_get_left ( WIDGET ( tb ) ) + offset; @@ -360,7 +358,7 @@ static void textbox_draw ( widget *wid, cairo_t *draw ) rofi_theme_get_color ( WIDGET ( tb ), "text", draw ); // draw the cursor if ( tb->flags & TB_EDITABLE && tb->blink ) { - int y = top + ( pango_font_metrics_get_ascent ( tb->metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE; + int y = top + ( pango_font_metrics_get_ascent ( tb->metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE; // We want to place the cursor based on the text shown. const char *text = pango_layout_get_text ( tb->layout ); // Clamp the position, should not be needed, but we are paranoid. @@ -369,10 +367,10 @@ static void textbox_draw ( widget *wid, cairo_t *draw ) // convert to byte location. char *offset = g_utf8_offset_to_pointer ( text, cursor_offset ); pango_layout_get_cursor_pos ( tb->layout, offset - text, &pos, NULL ); - int cursor_x = pos.x / PANGO_SCALE; - int cursor_y = pos.y / PANGO_SCALE; - int cursor_height = pos.height / PANGO_SCALE; - int cursor_width = 2; + int cursor_x = pos.x / PANGO_SCALE; + int cursor_y = pos.y / PANGO_SCALE; + int cursor_height = pos.height / PANGO_SCALE; + int cursor_width = 2; cairo_rectangle ( draw, x + cursor_x, y + cursor_y, cursor_width, cursor_height ); cairo_fill ( draw ); } diff --git a/source/widgets/widget.c b/source/widgets/widget.c index b134c4f5..19a4770e 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -184,11 +184,11 @@ void widget_draw ( widget *widget, cairo_t *d ) cairo_new_path ( d ); rofi_theme_get_color ( widget, "foreground", d ); if ( left > 0 ) { - double offset = ( radius_tl > 0 ) ? floor(top / 2.0) : 0; + double offset = ( radius_tl > 0 ) ? floor ( top / 2.0 ) : 0; cairo_set_line_width ( d, left ); distance_get_linestyle ( widget->border.left, d ); cairo_move_to ( d, margin_left + left / 2.0, margin_top + radius_tl + offset ); - offset = ( radius_bl > 0 ) ? floor(bottom / 2.0) : 0; + offset = ( radius_bl > 0 ) ? floor ( bottom / 2.0 ) : 0; cairo_line_to ( d, margin_left + left / 2.0, widget->h - margin_bottom - radius_bl - offset ); cairo_stroke ( d ); } @@ -216,11 +216,11 @@ void widget_draw ( widget *widget, cairo_t *d ) } } if ( top > 0 ) { - double offset = ( radius_tl > 0 ) ? floor( left / 2.0 ) : 0; + double offset = ( radius_tl > 0 ) ? floor ( left / 2.0 ) : 0; cairo_set_line_width ( d, top ); distance_get_linestyle ( widget->border.top, d ); cairo_move_to ( d, margin_left + radius_tl + offset, margin_top + top / 2.0 ); - offset = ( radius_tr > 0 ) ? floor(right / 2.0) : 0; + offset = ( radius_tr > 0 ) ? floor ( right / 2.0 ) : 0; cairo_line_to ( d, widget->w - margin_right - radius_tr - offset, margin_top + top / 2.0 ); cairo_stroke ( d ); } @@ -247,11 +247,11 @@ void widget_draw ( widget *widget, cairo_t *d ) } } if ( right > 0 ) { - double offset = ( radius_tr > 0 ) ? floor(top / 2.0) : 0; + double offset = ( radius_tr > 0 ) ? floor ( top / 2.0 ) : 0; cairo_set_line_width ( d, right ); distance_get_linestyle ( widget->border.right, d ); cairo_move_to ( d, widget->w - margin_right - right / 2.0, margin_top + radius_tr + offset ); - offset = ( radius_br > 0 ) ?floor( bottom / 2.0) : 0; + offset = ( radius_br > 0 ) ? floor ( bottom / 2.0 ) : 0; cairo_line_to ( d, widget->w - margin_right - right / 2.0, widget->h - margin_bottom - radius_br - offset ); cairo_stroke ( d ); } @@ -278,11 +278,11 @@ void widget_draw ( widget *widget, cairo_t *d ) } } if ( bottom > 0 ) { - double offset = ( radius_bl > 0 ) ? floor( left / 2.0 ) : 0; + double offset = ( radius_bl > 0 ) ? floor ( left / 2.0 ) : 0; cairo_set_line_width ( d, bottom ); distance_get_linestyle ( widget->border.bottom, d ); cairo_move_to ( d, margin_left + radius_bl + offset, widget->h - bottom / 2.0 - margin_bottom ); - offset = ( radius_br > 0 ) ? floor( right / 2.0 ) : 0; + offset = ( radius_br > 0 ) ? floor ( right / 2.0 ) : 0; cairo_line_to ( d, widget->w - margin_right - radius_br - offset, widget->h - bottom / 2.0 - margin_bottom ); cairo_stroke ( d ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 79e379a1..9c017377 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -635,33 +635,34 @@ void config_parse_xresources_theme_dump ( void ) } } -static char * config_parser_return_display_help_entry ( XrmOption *option ) +static char * config_parser_return_display_help_entry ( XrmOption *option, size_t l ) { + int ll = (int) l; switch ( option->type ) { case xrm_Number: - return g_markup_printf_escaped ( " (%u) %s", - option->name, *( option->value.num ), option->comment ); + return g_markup_printf_escaped ( " (%u) %s", + ll, option->name + 3, *( option->value.num ), option->comment ); case xrm_SNumber: - return g_markup_printf_escaped ( " (%d) %s", - option->name, *( option->value.snum ), option->comment ); + return g_markup_printf_escaped ( " (%d) %s", + ll, option->name + 3, *( option->value.snum ), option->comment ); case xrm_String: - return g_markup_printf_escaped ( "%s (%s) %s", - option->name, + return g_markup_printf_escaped ( "%-*s (%s) %s", + ll, option->name + 3, ( *( option->value.str ) != NULL ) ? *( option->value.str ) : "null", option->comment ); case xrm_Boolean: - return g_markup_printf_escaped ( "%s (%s) %s", - option->name, ( *( option->value.num ) == TRUE ) ? "true" : "false", option->comment ); + return g_markup_printf_escaped ( "%-*s (%s) %s", + ll, option->name + 3, ( *( option->value.num ) == TRUE ) ? "true" : "false", option->comment ); case xrm_Char: if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) { - return g_markup_printf_escaped ( "%s (%c) %s", - option->name, *( option->value.charc ), option->comment ); + return g_markup_printf_escaped ( "%-*s (%c) %s", + ll, option->name + 3, *( option->value.charc ), option->comment ); } else { - return g_markup_printf_escaped ( " (\\x%02X) %s", - option->name, *( option->value.charc ), option->comment ); + return g_markup_printf_escaped ( " (\\x%02X) %s", + ll, option->name + 3, *( option->value.charc ), option->comment ); } default: break; @@ -674,6 +675,21 @@ char ** config_parser_return_display_help ( unsigned int *length ) { unsigned int entries = sizeof ( xrmOptions ) / sizeof ( *xrmOptions ); char **retv = NULL; + /** + * Get length of name + */ + size_t max_length = 0; + for ( unsigned int i = 0; i < entries; ++i ) { + size_t l = strlen ( xrmOptions[i].name ); + max_length = MAX ( max_length, l ); + } + for ( unsigned int i = 0; i < num_extra_options; i++ ) { + size_t l = strlen ( extra_options[i].name ); + max_length = MAX ( max_length, l ); + } + /** + * Generate entries + */ for ( unsigned int i = 0; i < entries; ++i ) { if ( ( i + 1 ) < entries ) { if ( xrmOptions[i].value.str == xrmOptions[i + 1].value.str ) { @@ -686,7 +702,7 @@ char ** config_parser_return_display_help ( unsigned int *length ) retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); - retv[( *length )] = config_parser_return_display_help_entry ( &xrmOptions[i] ); + retv[( *length )] = config_parser_return_display_help_entry ( &xrmOptions[i], max_length ); ( *length )++; } for ( unsigned int i = 0; i < num_extra_options; i++ ) { @@ -694,7 +710,7 @@ char ** config_parser_return_display_help ( unsigned int *length ) continue; } retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) ); - retv[( *length )] = config_parser_return_display_help_entry ( &extra_options[i] ); + retv[( *length )] = config_parser_return_display_help_entry ( &extra_options[i], max_length ); ( *length )++; } if ( ( *length ) > 0 ) { -- cgit v1.2.3