From 879ef824f7b57d0707f63387869ec505b6c5122c Mon Sep 17 00:00:00 2001 From: jchtt Date: Sun, 10 May 2020 19:11:06 -0400 Subject: [PATCH 1/7] Added combi mode format options --- config/config.c | 5 ++++ include/settings.h | 5 ++++ source/dialogs/combi.c | 45 ++++++++++++++++++++++++++++++++--- source/xrmoptions.c | 8 +++++++ test/run_combi_mode_format.sh | 6 +++++ 5 files changed, 66 insertions(+), 3 deletions(-) create mode 100755 test/run_combi_mode_format.sh diff --git a/config/config.c b/config/config.c index 62adab5dc..c21ced7b4 100644 --- a/config/config.c +++ b/config/config.c @@ -155,6 +155,11 @@ Settings config = { .plugin_path = PLUGIN_PATH, .max_history_size = 25, .combi_hide_mode_prefix = FALSE, + /** Combi format display */ + .combi_display_format = "{mode} {element}", + .combi_no_linebreak_modi = "", + .combi_no_linebreak_str = " ", + .markup_combi = FALSE, .matching_negate_char = '-', diff --git a/include/settings.h b/include/settings.h index b1f35e33d..75e941a32 100644 --- a/include/settings.h +++ b/include/settings.h @@ -184,6 +184,11 @@ typedef struct /** Maximum history length per mode. */ unsigned int max_history_size; gboolean combi_hide_mode_prefix; + /** Combi mode show */ + char * combi_display_format; + char * combi_no_linebreak_modi; + char * combi_no_linebreak_str; + gboolean markup_combi; char matching_negate_char; diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 691afce9f..0037fea2c 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -39,6 +39,7 @@ #include #include "mode-private.h" #include +#include "widgets/textbox.h" /** * Combi Mode @@ -47,6 +48,7 @@ typedef struct { Mode *mode; gboolean disable; + gboolean print_newline; } CombiMode; typedef struct @@ -69,6 +71,10 @@ static void combi_mode_parse_switchers ( Mode *sw ) char *switcher_str = g_strdup ( config.combi_modi ); const char * const sep = ",#"; // Split token on ','. This modifies switcher_str. + + GHashTable *ht; + ht = g_hash_table_new ( g_str_hash, g_str_equal ); + for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { // Resize and add entry. @@ -78,14 +84,19 @@ static void combi_mode_parse_switchers ( Mode *sw ) Mode *mode = rofi_collect_modi_search ( token ); if ( mode ) { pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers++].mode = mode; + pd->switchers[pd->num_switchers].mode = mode; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ } else { // If not build in, use custom switchers. Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers++].mode = sw; + pd->switchers[pd->num_switchers].mode = sw; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); } else { // Report error, don't continue. @@ -94,8 +105,21 @@ static void combi_mode_parse_switchers ( Mode *sw ) } } } + + savept = NULL; + for ( char *token = strtok_r ( config.combi_no_linebreak_modi, sep, &savept ); token != NULL; + token = strtok_r ( NULL, sep, &savept ) ) { + CombiMode *mode = g_hash_table_lookup ( ht, token ); + if ( mode != NULL ) { + mode->print_newline = FALSE; + } + else { + g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); + } + } // Free string that was modified by strtok_r g_free ( switcher_str ); + g_hash_table_destroy( ht ); } static int combi_mode_init ( Mode *sw ) @@ -184,7 +208,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned return mretv & MENU_LOWER_MASK; } + unsigned offset = 0; for ( unsigned i = 0; i < pd->num_switchers; i++ ) { + if ( pd->switchers[i].disable ) { + offset += pd->lengths[i]; + } if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[i] ); @@ -208,6 +236,9 @@ static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigne static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); + if (config.markup_combi) { + *state |= MARKUP; + } if ( !get_entry ) { for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { @@ -223,8 +254,16 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat char * str = retv = 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 ); if ( !config.combi_hide_mode_prefix ) { - retv = g_strdup_printf ( "%s %s", dname, str ); + char *dname_markup = g_markup_escape_text ( dname, -1 ); + char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str); + retv = helper_string_replace_if_exists( config.combi_display_format, + "{mode}", dname_markup, + "{linebreak}", opt_linebreak, + "{element}", str, + NULL ); g_free ( str ); + g_free ( dname_markup ); + g_free ( opt_linebreak ); } if ( attr_list != NULL ) { diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 13058262b..ef84dd779 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -219,6 +219,14 @@ static XrmOption xrmOptions[] = { "Max history size (WARNING: can cause slowdowns when set to high).", CONFIG_DEFAULT }, { xrm_Boolean, "combi-hide-mode-prefix", { .snum = &config.combi_hide_mode_prefix }, NULL, "Hide the prefix mode prefix on the combi view.", CONFIG_DEFAULT }, + { xrm_String, "combi-display-format", { .str = &config.combi_display_format }, NULL, + "Combi mode format string. (Supports: mode,element)", CONFIG_DEFAULT }, + { xrm_String, "combi-no-linebreak-modi", { .str = &config.combi_no_linebreak_modi }, NULL, + "Modi that do not use a linbreak for {linebreak} in combi mode, but -combi-no-linebreak-str instead.", CONFIG_DEFAULT }, + { xrm_String, "combi-no-linebreak-str", { .str = &config.combi_no_linebreak_str }, NULL, + "String used instead of linebreak in the output formatting for -combi-no-linebreak-modi.", CONFIG_DEFAULT }, + { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, + "Allow pango markup in combi mode entries.", CONFIG_DEFAULT }, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL, "Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT }, { xrm_String, "cache-dir", { .str = &config.cache_dir }, NULL, diff --git a/test/run_combi_mode_format.sh b/test/run_combi_mode_format.sh new file mode 100755 index 000000000..e83a2c7df --- /dev/null +++ b/test/run_combi_mode_format.sh @@ -0,0 +1,6 @@ +rofi -show combi -combi-modi "window,drun" -eh 2 \ + -drun-display-format "[({generic})]"$'\n'"{name}" \ + -combi-display-format "[[{mode}]]{linebreak}{element}" \ + -combi-no-linebreak-str " " \ + -markup-combi 1 \ + -combi-no-linebreak-modi "drun" From 88e5f9b63b2ebb6b788fc3da5d5b855e09b1c4f1 Mon Sep 17 00:00:00 2001 From: jchtt Date: Mon, 11 May 2020 22:47:55 -0400 Subject: [PATCH 2/7] Fixed indent --- config/config.c | 30 +++---- data/uncrustify.cfg | 2 +- include/rofi-types.h | 11 ++- include/theme.h | 1 - include/view.h | 1 - source/dialogs/combi.c | 84 +++++++++--------- source/dialogs/dmenu.c | 1 - source/dialogs/drun.c | 2 +- source/dialogs/script.c | 46 +++++----- source/rofi-icon-fetcher.c | 105 +++++++++++----------- source/rofi.c | 33 +++---- source/theme.c | 177 +++++++++++++++++++------------------ source/view.c | 6 +- source/widgets/listview.c | 25 +++--- source/widgets/textbox.c | 4 +- source/widgets/widget.c | 17 ++-- source/xcb.c | 2 +- source/xrmoptions.c | 2 +- 18 files changed, 279 insertions(+), 270 deletions(-) diff --git a/config/config.c b/config/config.c index c21ced7b4..116297bbf 100644 --- a/config/config.c +++ b/config/config.c @@ -41,13 +41,13 @@ Settings config = { .modi = "run,ssh", #endif /** Border width around the window. */ - .menu_bw = 1, + .menu_bw = 1, /** The width of the switcher. (0100 in % > 100 in pixels) */ - .menu_width = 50, + .menu_width = 50, /** Maximum number of options to show. */ - .menu_lines = 15, + .menu_lines = 15, /** Number of columns */ - .menu_columns = 1, + .menu_columns = 1, /** Font */ .menu_font = "mono 12", @@ -82,11 +82,11 @@ Settings config = { */ .location = WL_CENTER, /** Padding between elements */ - .padding = 5, + .padding = 5, /** Y offset */ - .y_offset = 0, + .y_offset = 0, /** X offset */ - .x_offset = 0, + .x_offset = 0, /** Always show config.menu_lines lines, even if less lines are available */ .fixed_num_lines = TRUE, /** Do not use history */ @@ -102,7 +102,7 @@ Settings config = { /** Cycle through in the element list */ .cycle = TRUE, /** Height of an element in #chars */ - .element_height = 1, + .element_height = 1, /** Sidebar mode, show the modi */ .sidebar_mode = FALSE, /** auto select */ @@ -129,8 +129,8 @@ Settings config = { /** Monitor */ .monitor = "-5", /** set line margin */ - .line_margin = 2, - .line_padding = 1, + .line_margin = 2, + .line_padding = 1, /** Set filter */ .filter = NULL, /** Separator style: dash/solid */ @@ -139,10 +139,10 @@ Settings config = { .hide_scrollbar = FALSE, .fullscreen = FALSE, .fake_transparency = FALSE, - .dpi = -1, - .threads = 0, - .scroll_method = 0, - .scrollbar_width = 8, + .dpi = -1, + .threads = 0, + .scroll_method = 0, + .scrollbar_width = 8, .fake_background = "screenshot", .window_format = "{w} {c} {t}", .click_to_exit = TRUE, @@ -153,7 +153,7 @@ Settings config = { .color_urgent = NULL, .color_window = NULL, .plugin_path = PLUGIN_PATH, - .max_history_size = 25, + .max_history_size = 25, .combi_hide_mode_prefix = FALSE, /** Combi format display */ .combi_display_format = "{mode} {element}", diff --git a/data/uncrustify.cfg b/data/uncrustify.cfg index 3e11e22f5..0b94fe7c5 100644 --- a/data/uncrustify.cfg +++ b/data/uncrustify.cfg @@ -74,7 +74,7 @@ align_var_struct_span = 3 align_right_cmt_span = 3 align_pp_define_span = 3 align_pp_define_gap = 4 -align_number_left = TRUE +align_number_right = TRUE align_typedef_span = 5 align_typedef_gap = 3 diff --git a/include/rofi-types.h b/include/rofi-types.h index ced7e321f..9ae17ab36 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -100,22 +100,21 @@ typedef enum ROFI_DISTANCE_MODIFIER_GROUP, } RofiDistanceModifier; -typedef struct RofiDistanceUnit +typedef struct RofiDistanceUnit { /** Distance */ - double distance; + double distance; /** Unit type of the distance */ - RofiPixelUnit type; + RofiPixelUnit type; /** Type */ - RofiDistanceModifier modtype; + RofiDistanceModifier modtype; /** Modifier */ struct RofiDistanceUnit *left; /** Modifier */ struct RofiDistanceUnit *right; - } RofiDistanceUnit; typedef struct @@ -123,7 +122,7 @@ typedef struct /** Base */ RofiDistanceUnit base; /** Style of the line (optional)*/ - RofiLineStyle style; + RofiLineStyle style; } RofiDistance; /** diff --git a/include/theme.h b/include/theme.h index 055bea710..28dd09821 100644 --- a/include/theme.h +++ b/include/theme.h @@ -249,7 +249,6 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doub */ void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d ); - /** * @param widget The widget to query * @param property The property to query. diff --git a/include/view.h b/include/view.h index ba07f32e3..f5deac96a 100644 --- a/include/view.h +++ b/include/view.h @@ -307,7 +307,6 @@ void rofi_capture_screenshot ( void ); */ void rofi_view_set_window_title ( const char * title ); - /** * set ellipsize mode to start. */ diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 0037fea2c..bb0b197a4 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -48,7 +48,7 @@ typedef struct { Mode *mode; gboolean disable; - gboolean print_newline; + gboolean print_newline; } CombiMode; typedef struct @@ -72,8 +72,8 @@ static void combi_mode_parse_switchers ( Mode *sw ) const char * const sep = ",#"; // Split token on ','. This modifies switcher_str. - GHashTable *ht; - ht = g_hash_table_new ( g_str_hash, g_str_equal ); + GHashTable *ht; + ht = g_hash_table_new ( g_str_hash, g_str_equal ); for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { @@ -83,20 +83,20 @@ static void combi_mode_parse_switchers ( Mode *sw ) Mode *mode = rofi_collect_modi_search ( token ); if ( mode ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = mode; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); - /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = mode; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ } else { // If not build in, use custom switchers. Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = sw; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = sw; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); } else { // Report error, don't continue. @@ -109,17 +109,17 @@ static void combi_mode_parse_switchers ( Mode *sw ) savept = NULL; for ( char *token = strtok_r ( config.combi_no_linebreak_modi, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { - CombiMode *mode = g_hash_table_lookup ( ht, token ); - if ( mode != NULL ) { - mode->print_newline = FALSE; - } - else { - g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); - } - } + CombiMode *mode = g_hash_table_lookup ( ht, token ); + if ( mode != NULL ) { + mode->print_newline = FALSE; + } + else { + g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); + } + } // Free string that was modified by strtok_r g_free ( switcher_str ); - g_hash_table_destroy( ht ); + g_hash_table_destroy ( ht ); } static int combi_mode_init ( Mode *sw ) @@ -179,11 +179,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned CombiModePrivateData *pd = mode_get_private_data ( sw ); if ( input[0][0] == '!' ) { - int switcher = -1; + int switcher = -1; // Implement strchrnul behaviour. - char *eob = g_utf8_strchr ( input[0], -1,' ' ); + char *eob = g_utf8_strchr ( input[0], -1, ' ' ); if ( eob == NULL ) { - eob = &(input[0][strlen(input[0])]); + eob = &( input[0][strlen ( input[0] )] ); } ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1; if ( bang_len > 0 ) { @@ -208,11 +208,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned return mretv & MENU_LOWER_MASK; } - unsigned offset = 0; + unsigned offset = 0; for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - if ( pd->switchers[i].disable ) { - offset += pd->lengths[i]; - } + if ( pd->switchers[i].disable ) { + offset += pd->lengths[i]; + } if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[i] ); @@ -236,9 +236,9 @@ static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigne static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - if (config.markup_combi) { - *state |= MARKUP; - } + if ( config.markup_combi ) { + *state |= MARKUP; + } if ( !get_entry ) { for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { @@ -254,16 +254,16 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat char * str = retv = 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 ); if ( !config.combi_hide_mode_prefix ) { - char *dname_markup = g_markup_escape_text ( dname, -1 ); - char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str); - retv = helper_string_replace_if_exists( config.combi_display_format, - "{mode}", dname_markup, - "{linebreak}", opt_linebreak, - "{element}", str, - NULL ); + char *dname_markup = g_markup_escape_text ( dname, -1 ); + char *opt_linebreak = g_strdup ( pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str ); + retv = helper_string_replace_if_exists ( config.combi_display_format, + "{mode}", dname_markup, + "{linebreak}", opt_linebreak, + "{element}", str, + NULL ); g_free ( str ); - g_free ( dname_markup ); - g_free ( opt_linebreak ); + g_free ( dname_markup ); + g_free ( opt_linebreak ); } if ( attr_list != NULL ) { @@ -321,10 +321,10 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) } if ( input != NULL && input[0] == '!' ) { // Implement strchrnul behaviour. - const char *eob = g_utf8_strchr ( input, -1, ' ' ); + const char *eob = g_utf8_strchr ( input, -1, ' ' ); if ( eob == NULL ) { // Set it to end. - eob = &(input[strlen(input)]); + eob = &( input[strlen ( input )] ); } ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1; if ( bang_len > 0 ) { diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 5e9af2d4b..d82299be7 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -734,7 +734,6 @@ int dmenu_switcher_dialog ( void ) find_arg_str ( "-p", &( dmenu_mode.display_name ) ); RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize ); - if ( find_arg ( "-keep-right" ) >= 0 ) { rofi_view_ellipsize_start ( state ); } diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index afc19ba62..67549bf94 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -182,7 +182,7 @@ static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpoi case 'm': break; case '%': - g_string_append(res, "%"); + g_string_append ( res, "%" ); break; case 'k': if ( e->e->path ) { diff --git a/source/dialogs/script.c b/source/dialogs/script.c index c7cc6d706..ab2a3f4a7 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -68,7 +68,7 @@ typedef struct char *message; char *prompt; gboolean do_markup; - char delim; + char delim; /** no custom */ gboolean no_custom; } ScriptModePrivateData; @@ -83,7 +83,7 @@ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry * length_key++; } // Should be not last character in buffer. - if ( (length_key+1) < (length) ) { + if ( ( length_key + 1 ) < ( length ) ) { buffer[length_key] = '\0'; char *value = buffer + length_key + 1; if ( strcasecmp ( buffer, "icon" ) == 0 ) { @@ -110,7 +110,7 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) length_key++; } - if ( (length_key+1) < length ) { + if ( ( length_key + 1 ) < length ) { line[length_key] = '\0'; char *value = line + length_key + 1; if ( strcasecmp ( line, "message" ) == 0 ) { @@ -133,31 +133,30 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) } else if ( strcasecmp ( line, "delim" ) == 0 ) { pd->delim = helper_parse_char ( value ); - } else if ( strcasecmp ( line, "no-custom" ) == 0 ) { - pd->no_custom = ( strcasecmp ( value, "true") == 0 ); + } + else if ( strcasecmp ( line, "no-custom" ) == 0 ) { + pd->no_custom = ( strcasecmp ( value, "true" ) == 0 ); } } } static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *length, int value ) { - ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; - int fd = -1; - GError *error = NULL; - DmenuScriptEntry *retv = NULL; - char **argv = NULL; - int argc = 0; + ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; + int fd = -1; + GError *error = NULL; + DmenuScriptEntry *retv = NULL; + char **argv = NULL; + int argc = 0; *length = 0; - // Environment char ** env = g_get_environ (); - char *str_value = g_strdup_printf("%d", value); - env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE); + char *str_value = g_strdup_printf ( "%d", value ); + env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE ); g_free ( str_value ); - if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) { argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); argv[argc] = g_strdup ( arg ); @@ -166,7 +165,7 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l } g_strfreev ( env ); if ( error != NULL ) { - char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*)sw->ed, error->message ); + char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*) sw->ed, error->message ); rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. @@ -233,7 +232,7 @@ static int script_mode_init ( Mode *sw ) { if ( sw->private_data == NULL ) { ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); - pd->delim = '\n'; + pd->delim = '\n'; sw->private_data = (void *) pd; pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0 ); } @@ -274,11 +273,13 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned //retv = 1+( mretv & MENU_LOWER_MASK ); script_mode_reset_highlight ( sw ); if ( selected_line != UINT32_MAX ) { - new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length,10+( mretv & MENU_LOWER_MASK ) ); - } else { + new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); + } + else { if ( rmpd->no_custom == FALSE ) { - new_list = execute_executor ( sw, *input, &new_length,10+( mretv & MENU_LOWER_MASK ) ); - } else { + new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); + } + else { return RELOAD_DIALOG; } } @@ -294,7 +295,8 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned if ( rmpd->no_custom == FALSE ) { script_mode_reset_highlight ( sw ); new_list = execute_executor ( sw, *input, &new_length, 2 ); - } else { + } + else { return RELOAD_DIALOG; } } diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c index 7be6db145..33e52c061 100644 --- a/source/rofi-icon-fetcher.c +++ b/source/rofi-icon-fetcher.c @@ -133,64 +133,66 @@ void rofi_icon_fetcher_destroy ( void ) g_free ( rofi_icon_fetcher_data ); } +static cairo_surface_t* cairo_image_surface_create_from_jpeg_private ( struct jpeg_decompress_struct* cinfo ) +{ + cairo_surface_t* surface = 0; + unsigned char * data = 0; + unsigned char * rgb = 0; + jpeg_read_header ( cinfo, TRUE ); + jpeg_start_decompress ( cinfo ); -static cairo_surface_t* cairo_image_surface_create_from_jpeg_private(struct jpeg_decompress_struct* cinfo) { - cairo_surface_t* surface = 0; - unsigned char* data = 0; - unsigned char* rgb = 0; - - jpeg_read_header(cinfo, TRUE); - jpeg_start_decompress(cinfo); - - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height); - data = cairo_image_surface_get_data(surface); - rgb = (unsigned char*)(malloc(cinfo->output_width * cinfo->output_components)); + surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height ); + data = cairo_image_surface_get_data ( surface ); + rgb = (unsigned char*) ( malloc ( cinfo->output_width * cinfo->output_components ) ); - while(cinfo->output_scanline < cinfo->output_height) { - unsigned int i; - int scanline = cinfo->output_scanline * cairo_image_surface_get_stride(surface); + while ( cinfo->output_scanline < cinfo->output_height ) { + unsigned int i; + int scanline = cinfo->output_scanline * cairo_image_surface_get_stride ( surface ); - jpeg_read_scanlines(cinfo, &rgb, 1); + jpeg_read_scanlines ( cinfo, &rgb, 1 ); - for(i = 0; i < cinfo->output_width; i++) { - int offset = scanline + (i * 4); + for ( i = 0; i < cinfo->output_width; i++ ) { + int offset = scanline + ( i * 4 ); - data[offset + 3] = 255; - data[offset + 2] = rgb[(i * 3)]; - data[offset + 1] = rgb[(i * 3) + 1]; - data[offset ] = rgb[(i * 3) + 2]; - } - } + data[offset + 3] = 255; + data[offset + 2] = rgb[( i * 3 )]; + data[offset + 1] = rgb[( i * 3 ) + 1]; + data[offset ] = rgb[( i * 3 ) + 2]; + } + } - free(rgb); + free ( rgb ); - jpeg_finish_decompress(cinfo); - jpeg_destroy_decompress(cinfo); + jpeg_finish_decompress ( cinfo ); + jpeg_destroy_decompress ( cinfo ); - cairo_surface_mark_dirty(surface); + cairo_surface_mark_dirty ( surface ); - return surface; + return surface; } -static cairo_surface_t* cairo_image_surface_create_from_jpeg(const char* file) { - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - cairo_surface_t* surface; - FILE* infile; +static cairo_surface_t* cairo_image_surface_create_from_jpeg ( const char* file ) +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + cairo_surface_t * surface; + FILE * infile; - if((infile = fopen(file, "rb")) == NULL) return NULL; + if ( ( infile = fopen ( file, "rb" ) ) == NULL ) { + return NULL; + } - cinfo.err = jpeg_std_error(&jerr); + cinfo.err = jpeg_std_error ( &jerr ); - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, infile); + jpeg_create_decompress ( &cinfo ); + jpeg_stdio_src ( &cinfo, infile ); - surface = cairo_image_surface_create_from_jpeg_private(&cinfo); + surface = cairo_image_surface_create_from_jpeg_private ( &cinfo ); - fclose(infile); + fclose ( infile ); - return surface; + return surface; } static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data ) @@ -235,29 +237,26 @@ static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpoint } if ( icon_surf ) { if ( cairo_surface_status ( icon_surf ) == CAIRO_STATUS_SUCCESS ) { - float sw = sentry->size/(float)cairo_image_surface_get_width( icon_surf ); - float sh = sentry->size/(float)cairo_image_surface_get_height( icon_surf ); + float sw = sentry->size / (float) cairo_image_surface_get_width ( icon_surf ); + float sh = sentry->size / (float) cairo_image_surface_get_height ( icon_surf ); - float scale = ( sw > sh)? sh:sw; - if ( scale < 0.5 ) - { - cairo_surface_t * surface = cairo_image_surface_create( - cairo_image_surface_get_format( icon_surf ), - cairo_image_surface_get_width( icon_surf )*scale, - cairo_image_surface_get_height( icon_surf )*scale); + float scale = ( sw > sh ) ? sh : sw; + if ( scale < 0.5 ) { + cairo_surface_t * surface = cairo_image_surface_create ( + cairo_image_surface_get_format ( icon_surf ), + cairo_image_surface_get_width ( icon_surf ) * scale, + cairo_image_surface_get_height ( icon_surf ) * scale ); cairo_t *d = cairo_create ( surface ); cairo_scale ( d, scale, scale ); - cairo_set_source_surface ( d, icon_surf, 0.0,0.0); - cairo_pattern_set_filter (cairo_get_source (d), CAIRO_FILTER_FAST); + cairo_set_source_surface ( d, icon_surf, 0.0, 0.0 ); + cairo_pattern_set_filter ( cairo_get_source ( d ), CAIRO_FILTER_FAST ); cairo_paint ( d ); cairo_destroy ( d ); cairo_surface_destroy ( icon_surf ); icon_surf = surface; } - - } // check if surface is valid. if ( cairo_surface_status ( icon_surf ) != CAIRO_STATUS_SUCCESS ) { diff --git a/source/rofi.c b/source/rofi.c index b839109aa..e278c2780 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -193,10 +193,10 @@ static void run_switcher ( ModeMode mode ) RofiViewState * state = rofi_view_create ( modi[mode], config.filter, 0, process_result ); // User can pre-select a row. - if ( find_arg ( "-selected-row" ) >= 0 ){ - unsigned int sr = 0; - find_arg_uint ( "-selected-row", &(sr) ); - rofi_view_set_selected_line ( state, sr ); + if ( find_arg ( "-selected-row" ) >= 0 ) { + unsigned int sr = 0; + find_arg_uint ( "-selected-row", &( sr ) ); + rofi_view_set_selected_line ( state, sr ); } if ( state ) { rofi_view_set_active ( state ); @@ -512,7 +512,7 @@ static void rofi_collect_modi_dir ( const char *base_dir ) if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) { continue; } - char *fn = g_build_filename ( base_dir, dn, NULL ); + char *fn = g_build_filename ( base_dir, dn, NULL ); g_debug ( "Trying to open: %s plugin", fn ); GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL ); if ( mod ) { @@ -565,7 +565,7 @@ static void rofi_collect_modi ( void ) g_debug ( "Parse plugin path: %s", config.plugin_path ); rofi_collect_modi_dir ( config.plugin_path ); /* ROFI_PLUGIN_PATH */ - const char *path = g_getenv("ROFI_PLUGIN_PATH"); + const char *path = g_getenv ( "ROFI_PLUGIN_PATH" ); if ( path != NULL ) { gchar ** paths = g_strsplit ( path, ":", -1 ); for ( unsigned int i = 0; paths[i]; i++ ) { @@ -869,40 +869,41 @@ int main ( int argc, char *argv[] ) if ( find_arg ( "-no-config" ) < 0 ) { // Load distro default settings - gboolean found_system = FALSE; - const char * const * dirs = g_get_system_config_dirs(); - if ( dirs ) - { - for ( unsigned int i =0; !found_system && dirs[i]; i++ ) { + gboolean found_system = FALSE; + const char * const * dirs = g_get_system_config_dirs (); + if ( dirs ) { + for ( unsigned int i = 0; !found_system && dirs[i]; i++ ) { /** New format. */ gchar *etc = g_build_filename ( dirs[i], "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Parsing: %s", etc ); rofi_theme_parse_file ( etc ); - found_system = TRUE; - } else { + found_system = TRUE; + } + else { /** Old format. */ gchar *xetc = g_build_filename ( dirs[i], "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) { config_parse_xresource_options_file ( xetc ); old_config_format = TRUE; - found_system = TRUE; + found_system = TRUE; } g_free ( xetc ); } g_free ( etc ); } } - if ( ! found_system ) { + if ( !found_system ) { /** New format. */ gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Look for default config file: %s", etc ); rofi_theme_parse_file ( etc ); - } else { + } + else { /** Old format. */ gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); diff --git a/source/theme.c b/source/theme.c index 85bf7c866..78137c979 100644 --- a/source/theme.c +++ b/source/theme.c @@ -84,25 +84,23 @@ Property *rofi_theme_property_create ( PropertyType type ) static RofiDistanceUnit *rofi_theme_property_copy_distance_unit ( RofiDistanceUnit *unit ) { - RofiDistanceUnit *retv = g_slice_new0( RofiDistanceUnit ); - *retv = *unit; + RofiDistanceUnit *retv = g_slice_new0 ( RofiDistanceUnit ); + *retv = *unit; if ( unit->left ) { - retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); + retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); } if ( unit->right ) { - retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); + retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); } return retv; } RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance ) { RofiDistance retv = distance; - if ( distance.base.left ) - { + if ( distance.base.left ) { retv.base.left = rofi_theme_property_copy_distance_unit ( distance.base.left ); } - if ( distance.base.right ) - { + if ( distance.base.right ) { retv.base.right = rofi_theme_property_copy_distance_unit ( distance.base.right ); } return retv; @@ -129,14 +127,14 @@ Property* rofi_theme_property_copy ( Property *p ) } break; case P_PADDING: - { - retv->value = p->value; - retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top); - retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left); - retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom); - retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right); - break; - } + { + retv->value = p->value; + retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top ); + retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left ); + retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom ); + retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right ); + break; + } default: retv->value = p->value; } @@ -153,7 +151,7 @@ static void rofi_theme_distance_unit_property_free ( RofiDistanceUnit *unit ) rofi_theme_distance_unit_property_free ( unit->right ); unit->right = NULL; } - g_slice_free ( RofiDistanceUnit, unit); + g_slice_free ( RofiDistanceUnit, unit ); } static void rofi_theme_distance_property_free ( RofiDistance *distance ) { @@ -182,11 +180,11 @@ void rofi_theme_property_free ( Property *p ) rofi_theme_property_free ( p->value.link.def_value ); } } - if ( p->type == P_PADDING) { - rofi_theme_distance_property_free( &(p->value.padding.top)); - rofi_theme_distance_property_free( &(p->value.padding.right)); - rofi_theme_distance_property_free( &(p->value.padding.bottom)); - rofi_theme_distance_property_free( &(p->value.padding.left)); + if ( p->type == P_PADDING ) { + rofi_theme_distance_property_free ( &( p->value.padding.top ) ); + rofi_theme_distance_property_free ( &( p->value.padding.right ) ); + rofi_theme_distance_property_free ( &( p->value.padding.bottom ) ); + rofi_theme_distance_property_free ( &( p->value.padding.left ) ); } g_slice_free ( Property, p ); } @@ -216,7 +214,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) rofi_theme_widget_add_properties ( tt, table ); - RofiDistance dsize = (RofiDistance){ .base = {1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + RofiDistance dsize = (RofiDistance){ .base = { 1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; Property *pts = rofi_theme_property_create ( P_PADDING ); pts->value.padding.top = pts->value.padding.right = pts->value.padding.bottom = pts->value.padding.left = dsize; pts->name = g_strdup ( "size" ); @@ -229,7 +227,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); Property *psp = rofi_theme_property_create ( P_PADDING ); psp->name = g_strdup ( "spacing" ); - RofiDistance d = (RofiDistance){ .base = {5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = { 5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; psp->value.padding = (RofiPadding){ d, d, d, d }; g_hash_table_replace ( table, psp->name, psp ); rofi_theme_widget_add_properties ( t, table ); @@ -277,27 +275,33 @@ inline static void printf_double ( double d ) static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) { - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) - fputs("( " , stdout); - if ( unit->left ) + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( "( ", stdout ); + } + if ( unit->left ) { rofi_theme_print_distance_unit ( unit->left ); + } if ( unit->modtype == ROFI_DISTANCE_MODIFIER_ADD ) { fputs ( " + ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { fputs ( " - ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { fputs ( " / ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY ) { fputs ( " * ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO ) { fputs ( " % ", stdout ); - } - if ( unit->right ) + } + if ( unit->right ) { rofi_theme_print_distance_unit ( unit->right ); - - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) - { + } + + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) { if ( unit->type == ROFI_PU_PX ) { printf ( "%upx ", (unsigned int) unit->distance ); } @@ -314,18 +318,19 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) fputs ( "em ", stdout ); } } - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) - fputs(" )" , stdout); + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( " )", stdout ); + } } static void rofi_theme_print_distance ( RofiDistance d ) { - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ - fputs( "calc( ", stdout ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( "calc( ", stdout ); } - rofi_theme_print_distance_unit ( &(d.base) ); - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ - fputs( ")", stdout ); + rofi_theme_print_distance_unit ( &( d.base ) ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( ")", stdout ); } if ( d.style == ROFI_HL_DASH ) { printf ( "dash " ); @@ -742,17 +747,17 @@ RofiDistance rofi_theme_get_distance ( const widget *widget, const char *propert if ( widget->parent ) { return rofi_theme_get_distance ( widget->parent, property, def ); } - return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; } if ( p->type == P_INTEGER ) { - return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; } else { return p->value.padding.left; } } g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); - return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; } int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ) @@ -868,7 +873,7 @@ RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property, pad = p->value.padding; } else { - RofiDistance d = (RofiDistance){ .base = {p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; return (RofiPadding){ d, d, d, d }; } } @@ -923,7 +928,6 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) { int val = unit->distance; - if ( unit->type == ROFI_PU_EM ) { val = unit->distance * textbox_get_estimated_char_height (); } @@ -945,48 +949,46 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) return val; } - static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori ) { - switch ( unit->modtype) + switch ( unit->modtype ) { - case ROFI_DISTANCE_MODIFIER_GROUP: - return distance_unit_get_pixel ( unit->left, ori ); - break; - case ROFI_DISTANCE_MODIFIER_ADD: - return distance_unit_get_pixel ( unit->left, ori)+ distance_unit_get_pixel ( unit->right, ori); - case ROFI_DISTANCE_MODIFIER_SUBTRACT: - return distance_unit_get_pixel ( unit->left, ori)- distance_unit_get_pixel ( unit->right, ori); - case ROFI_DISTANCE_MODIFIER_MULTIPLY: - return distance_unit_get_pixel ( unit->left, ori)* distance_unit_get_pixel ( unit->right, ori); - case ROFI_DISTANCE_MODIFIER_DIVIDE: - { - int a = distance_unit_get_pixel ( unit->left, ori); - int b = distance_unit_get_pixel ( unit->right, ori); - if ( b != 0 ) { - return a/b; - } - return a; - } - case ROFI_DISTANCE_MODIFIER_MODULO: - { - int a = distance_unit_get_pixel ( unit->left, ori); - int b = distance_unit_get_pixel ( unit->right, ori); - if ( b != 0 ) { - return a%b; - } - return 0; - } - default: - break; + case ROFI_DISTANCE_MODIFIER_GROUP: + return distance_unit_get_pixel ( unit->left, ori ); + break; + case ROFI_DISTANCE_MODIFIER_ADD: + return distance_unit_get_pixel ( unit->left, ori ) + distance_unit_get_pixel ( unit->right, ori ); + case ROFI_DISTANCE_MODIFIER_SUBTRACT: + return distance_unit_get_pixel ( unit->left, ori ) - distance_unit_get_pixel ( unit->right, ori ); + case ROFI_DISTANCE_MODIFIER_MULTIPLY: + return distance_unit_get_pixel ( unit->left, ori ) * distance_unit_get_pixel ( unit->right, ori ); + case ROFI_DISTANCE_MODIFIER_DIVIDE: + { + int a = distance_unit_get_pixel ( unit->left, ori ); + int b = distance_unit_get_pixel ( unit->right, ori ); + if ( b != 0 ) { + return a / b; + } + return a; + } + case ROFI_DISTANCE_MODIFIER_MODULO: + { + int a = distance_unit_get_pixel ( unit->left, ori ); + int b = distance_unit_get_pixel ( unit->right, ori ); + if ( b != 0 ) { + return a % b; + } + return 0; + } + default: + break; } return get_pixels ( unit, ori ); } - int distance_get_pixel ( RofiDistance d, RofiOrientation ori ) { - return distance_unit_get_pixel ( &(d.base), ori); + return distance_unit_get_pixel ( &( d.base ), ori ); } void distance_get_linestyle ( RofiDistance d, cairo_t *draw ) @@ -1009,13 +1011,13 @@ gboolean rofi_theme_is_empty ( void ) return TRUE; } if ( rofi_theme->num_widgets == 3 ) { - // HACK: check for default added elements. - for ( unsigned int i = 0; i < rofi_theme->num_widgets;i++) { - if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7) != 0 ){ - return FALSE; + // HACK: check for default added elements. + for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) { + if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7 ) != 0 ) { + return FALSE; + } } - } - return TRUE; + return TRUE; } return FALSE; @@ -1312,7 +1314,6 @@ ThemeMediaType rofi_theme_parse_media_type ( const char *type ) return THEME_MEDIA_TYPE_INVALID; } - gboolean rofi_theme_has_property ( const widget *widget, const char *property ) { ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); diff --git a/source/view.c b/source/view.c index 2c746e37d..f450bd468 100644 --- a/source/view.c +++ b/source/view.c @@ -126,9 +126,9 @@ struct .fake_bgrel = FALSE, .flags = MENU_NORMAL, .views = G_QUEUE_INIT, - .idle_timeout = 0, - .count = 0L, - .repaint_source = 0, + .idle_timeout = 0, + .count = 0L, + .repaint_source = 0, .fullscreen = FALSE, }; diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 81f346780..0397b43ff 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -45,10 +45,10 @@ /** * Orientation of the listview */ - /** Vertical (classical) list */ -#define LISTVIEW ROFI_ORIENTATION_VERTICAL - /** Horizontal list. (barview) */ -#define BARVIEW ROFI_ORIENTATION_HORIZONTAL +/** Vertical (classical) list */ +#define LISTVIEW ROFI_ORIENTATION_VERTICAL +/** Horizontal list. (barview) */ +#define BARVIEW ROFI_ORIENTATION_HORIZONTAL /** * The moving direction of the selection, this (in barview) affects the scrolling. @@ -69,7 +69,7 @@ typedef struct struct _listview { - widget widget; + widget widget; RofiOrientation type; @@ -553,8 +553,8 @@ static void listview_resize ( widget *wid, short w, short h ) lv->max_elements = lv->max_rows * lv->menu_columns; widget_move ( WIDGET ( lv->scrollbar ), - lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), - widget_padding_get_top ( WIDGET ( lv ) ) ); + lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), + widget_padding_get_top ( WIDGET ( lv ) ) ); widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height ); @@ -661,10 +661,13 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca listview_create_row ( lv, &row ); // FIXME: hack to scale hight correctly. if ( lv->eh > 1 && row.textbox ) { - char buff[lv->eh*2+1] ; - memset( buff, '\0', lv->eh*2+1); - for ( unsigned int i = 0; i < (lv->eh-1); i++) { buff[i*2] = 'a'; buff[i*2+1] ='\n'; }; - textbox_text( row.textbox, buff); + char buff[lv->eh * 2 + 1]; + memset ( buff, '\0', lv->eh * 2 + 1 ); + for ( unsigned int i = 0; i < ( lv->eh - 1 ); i++ ) { + buff[i * 2] = 'a'; buff[i * 2 + 1] = '\n'; + } + ; + textbox_text ( row.textbox, buff ); } lv->element_height = widget_get_desired_height ( WIDGET ( row.box ) ); widget_free ( WIDGET ( row.box ) ); diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 482d10377..ca4f415e1 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -276,7 +276,7 @@ static void __textbox_update_pango_text ( textbox *tb ) tb->show_placeholder = FALSE; if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) { size_t l = g_utf8_strlen ( tb->text, -1 ); - char string [l + 1]; + char string[l + 1]; memset ( string, '*', l ); string[l] = '\0'; pango_layout_set_text ( tb->layout, string, l ); @@ -911,7 +911,7 @@ double textbox_get_estimated_ch ( void ) int textbox_get_estimated_height ( const textbox *tb, int eh ) { int height = pango_font_metrics_get_ascent ( tb->metrics ) + pango_font_metrics_get_descent ( tb->metrics ); - return ceil(( eh * height ) / (double)PANGO_SCALE) + widget_padding_get_padding_height ( WIDGET ( tb ) ); + return ceil ( ( eh * height ) / (double) PANGO_SCALE ) + widget_padding_get_padding_height ( WIDGET ( tb ) ); } int textbox_get_desired_width ( widget *wid ) { diff --git a/source/widgets/widget.c b/source/widgets/widget.c index c0e898596..517b7f5b9 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -40,11 +40,18 @@ void widget_init ( widget *wid, widget *parent, WidgetType type, const char *nam wid->parent = parent; wid->name = g_strdup ( name ); wid->def_padding = - (RofiPadding){ { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, - { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; - wid->def_border = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; - wid->def_border_radius = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; - wid->def_margin = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + (RofiPadding){ { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + wid->def_border = + (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + wid->def_border_radius = + (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + wid->def_margin = + (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; wid->padding = rofi_theme_get_padding ( wid, "padding", wid->def_padding ); wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border ); diff --git a/source/xcb.c b/source/xcb.c index dd42e98b1..39b738f4d 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -79,7 +79,7 @@ WindowManagerQuirk current_window_manager = WM_EWHM; struct _xcb_stuff xcb_int = { .connection = NULL, .screen = NULL, - .screen_nbr = -1, + .screen_nbr = -1, .sndisplay = NULL, .sncontext = NULL, .monitors = NULL diff --git a/source/xrmoptions.c b/source/xrmoptions.c index ef84dd779..f63e82fab 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -225,7 +225,7 @@ static XrmOption xrmOptions[] = { "Modi that do not use a linbreak for {linebreak} in combi mode, but -combi-no-linebreak-str instead.", CONFIG_DEFAULT }, { xrm_String, "combi-no-linebreak-str", { .str = &config.combi_no_linebreak_str }, NULL, "String used instead of linebreak in the output formatting for -combi-no-linebreak-modi.", CONFIG_DEFAULT }, - { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, + { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, "Allow pango markup in combi mode entries.", CONFIG_DEFAULT }, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL, "Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT }, From 4c169586e117e7a85a9906acf3489a35c230a5a5 Mon Sep 17 00:00:00 2001 From: jchtt Date: Mon, 11 May 2020 22:54:16 -0400 Subject: [PATCH 3/7] Revert "Fixed indent" This reverts commit 88e5f9b63b2ebb6b788fc3da5d5b855e09b1c4f1. --- config/config.c | 30 +++---- data/uncrustify.cfg | 2 +- include/rofi-types.h | 11 +-- include/theme.h | 1 + include/view.h | 1 + source/dialogs/combi.c | 84 +++++++++--------- source/dialogs/dmenu.c | 1 + source/dialogs/drun.c | 2 +- source/dialogs/script.c | 46 +++++----- source/rofi-icon-fetcher.c | 105 +++++++++++----------- source/rofi.c | 33 ++++--- source/theme.c | 177 ++++++++++++++++++------------------- source/view.c | 6 +- source/widgets/listview.c | 25 +++--- source/widgets/textbox.c | 4 +- source/widgets/widget.c | 17 ++-- source/xcb.c | 2 +- source/xrmoptions.c | 2 +- 18 files changed, 270 insertions(+), 279 deletions(-) diff --git a/config/config.c b/config/config.c index 116297bbf..c21ced7b4 100644 --- a/config/config.c +++ b/config/config.c @@ -41,13 +41,13 @@ Settings config = { .modi = "run,ssh", #endif /** Border width around the window. */ - .menu_bw = 1, + .menu_bw = 1, /** The width of the switcher. (0100 in % > 100 in pixels) */ - .menu_width = 50, + .menu_width = 50, /** Maximum number of options to show. */ - .menu_lines = 15, + .menu_lines = 15, /** Number of columns */ - .menu_columns = 1, + .menu_columns = 1, /** Font */ .menu_font = "mono 12", @@ -82,11 +82,11 @@ Settings config = { */ .location = WL_CENTER, /** Padding between elements */ - .padding = 5, + .padding = 5, /** Y offset */ - .y_offset = 0, + .y_offset = 0, /** X offset */ - .x_offset = 0, + .x_offset = 0, /** Always show config.menu_lines lines, even if less lines are available */ .fixed_num_lines = TRUE, /** Do not use history */ @@ -102,7 +102,7 @@ Settings config = { /** Cycle through in the element list */ .cycle = TRUE, /** Height of an element in #chars */ - .element_height = 1, + .element_height = 1, /** Sidebar mode, show the modi */ .sidebar_mode = FALSE, /** auto select */ @@ -129,8 +129,8 @@ Settings config = { /** Monitor */ .monitor = "-5", /** set line margin */ - .line_margin = 2, - .line_padding = 1, + .line_margin = 2, + .line_padding = 1, /** Set filter */ .filter = NULL, /** Separator style: dash/solid */ @@ -139,10 +139,10 @@ Settings config = { .hide_scrollbar = FALSE, .fullscreen = FALSE, .fake_transparency = FALSE, - .dpi = -1, - .threads = 0, - .scroll_method = 0, - .scrollbar_width = 8, + .dpi = -1, + .threads = 0, + .scroll_method = 0, + .scrollbar_width = 8, .fake_background = "screenshot", .window_format = "{w} {c} {t}", .click_to_exit = TRUE, @@ -153,7 +153,7 @@ Settings config = { .color_urgent = NULL, .color_window = NULL, .plugin_path = PLUGIN_PATH, - .max_history_size = 25, + .max_history_size = 25, .combi_hide_mode_prefix = FALSE, /** Combi format display */ .combi_display_format = "{mode} {element}", diff --git a/data/uncrustify.cfg b/data/uncrustify.cfg index 0b94fe7c5..3e11e22f5 100644 --- a/data/uncrustify.cfg +++ b/data/uncrustify.cfg @@ -74,7 +74,7 @@ align_var_struct_span = 3 align_right_cmt_span = 3 align_pp_define_span = 3 align_pp_define_gap = 4 -align_number_right = TRUE +align_number_left = TRUE align_typedef_span = 5 align_typedef_gap = 3 diff --git a/include/rofi-types.h b/include/rofi-types.h index 9ae17ab36..ced7e321f 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -100,21 +100,22 @@ typedef enum ROFI_DISTANCE_MODIFIER_GROUP, } RofiDistanceModifier; -typedef struct RofiDistanceUnit +typedef struct RofiDistanceUnit { /** Distance */ - double distance; + double distance; /** Unit type of the distance */ - RofiPixelUnit type; + RofiPixelUnit type; /** Type */ - RofiDistanceModifier modtype; + RofiDistanceModifier modtype; /** Modifier */ struct RofiDistanceUnit *left; /** Modifier */ struct RofiDistanceUnit *right; + } RofiDistanceUnit; typedef struct @@ -122,7 +123,7 @@ typedef struct /** Base */ RofiDistanceUnit base; /** Style of the line (optional)*/ - RofiLineStyle style; + RofiLineStyle style; } RofiDistance; /** diff --git a/include/theme.h b/include/theme.h index 28dd09821..055bea710 100644 --- a/include/theme.h +++ b/include/theme.h @@ -249,6 +249,7 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doub */ void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d ); + /** * @param widget The widget to query * @param property The property to query. diff --git a/include/view.h b/include/view.h index f5deac96a..ba07f32e3 100644 --- a/include/view.h +++ b/include/view.h @@ -307,6 +307,7 @@ void rofi_capture_screenshot ( void ); */ void rofi_view_set_window_title ( const char * title ); + /** * set ellipsize mode to start. */ diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index bb0b197a4..0037fea2c 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -48,7 +48,7 @@ typedef struct { Mode *mode; gboolean disable; - gboolean print_newline; + gboolean print_newline; } CombiMode; typedef struct @@ -72,8 +72,8 @@ static void combi_mode_parse_switchers ( Mode *sw ) const char * const sep = ",#"; // Split token on ','. This modifies switcher_str. - GHashTable *ht; - ht = g_hash_table_new ( g_str_hash, g_str_equal ); + GHashTable *ht; + ht = g_hash_table_new ( g_str_hash, g_str_equal ); for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { @@ -83,20 +83,20 @@ static void combi_mode_parse_switchers ( Mode *sw ) Mode *mode = rofi_collect_modi_search ( token ); if ( mode ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = mode; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); - /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = mode; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ } else { // If not build in, use custom switchers. Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = sw; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = sw; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); } else { // Report error, don't continue. @@ -109,17 +109,17 @@ static void combi_mode_parse_switchers ( Mode *sw ) savept = NULL; for ( char *token = strtok_r ( config.combi_no_linebreak_modi, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { - CombiMode *mode = g_hash_table_lookup ( ht, token ); - if ( mode != NULL ) { - mode->print_newline = FALSE; - } - else { - g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); - } - } + CombiMode *mode = g_hash_table_lookup ( ht, token ); + if ( mode != NULL ) { + mode->print_newline = FALSE; + } + else { + g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); + } + } // Free string that was modified by strtok_r g_free ( switcher_str ); - g_hash_table_destroy ( ht ); + g_hash_table_destroy( ht ); } static int combi_mode_init ( Mode *sw ) @@ -179,11 +179,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned CombiModePrivateData *pd = mode_get_private_data ( sw ); if ( input[0][0] == '!' ) { - int switcher = -1; + int switcher = -1; // Implement strchrnul behaviour. - char *eob = g_utf8_strchr ( input[0], -1, ' ' ); + char *eob = g_utf8_strchr ( input[0], -1,' ' ); if ( eob == NULL ) { - eob = &( input[0][strlen ( input[0] )] ); + eob = &(input[0][strlen(input[0])]); } ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1; if ( bang_len > 0 ) { @@ -208,11 +208,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned return mretv & MENU_LOWER_MASK; } - unsigned offset = 0; + unsigned offset = 0; for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - if ( pd->switchers[i].disable ) { - offset += pd->lengths[i]; - } + if ( pd->switchers[i].disable ) { + offset += pd->lengths[i]; + } if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[i] ); @@ -236,9 +236,9 @@ static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigne static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - if ( config.markup_combi ) { - *state |= MARKUP; - } + if (config.markup_combi) { + *state |= MARKUP; + } if ( !get_entry ) { for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { @@ -254,16 +254,16 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat char * str = retv = 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 ); if ( !config.combi_hide_mode_prefix ) { - char *dname_markup = g_markup_escape_text ( dname, -1 ); - char *opt_linebreak = g_strdup ( pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str ); - retv = helper_string_replace_if_exists ( config.combi_display_format, - "{mode}", dname_markup, - "{linebreak}", opt_linebreak, - "{element}", str, - NULL ); + char *dname_markup = g_markup_escape_text ( dname, -1 ); + char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str); + retv = helper_string_replace_if_exists( config.combi_display_format, + "{mode}", dname_markup, + "{linebreak}", opt_linebreak, + "{element}", str, + NULL ); g_free ( str ); - g_free ( dname_markup ); - g_free ( opt_linebreak ); + g_free ( dname_markup ); + g_free ( opt_linebreak ); } if ( attr_list != NULL ) { @@ -321,10 +321,10 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) } if ( input != NULL && input[0] == '!' ) { // Implement strchrnul behaviour. - const char *eob = g_utf8_strchr ( input, -1, ' ' ); + const char *eob = g_utf8_strchr ( input, -1, ' ' ); if ( eob == NULL ) { // Set it to end. - eob = &( input[strlen ( input )] ); + eob = &(input[strlen(input)]); } ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1; if ( bang_len > 0 ) { diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index d82299be7..5e9af2d4b 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -734,6 +734,7 @@ int dmenu_switcher_dialog ( void ) find_arg_str ( "-p", &( dmenu_mode.display_name ) ); RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize ); + if ( find_arg ( "-keep-right" ) >= 0 ) { rofi_view_ellipsize_start ( state ); } diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 67549bf94..afc19ba62 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -182,7 +182,7 @@ static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpoi case 'm': break; case '%': - g_string_append ( res, "%" ); + g_string_append(res, "%"); break; case 'k': if ( e->e->path ) { diff --git a/source/dialogs/script.c b/source/dialogs/script.c index ab2a3f4a7..c7cc6d706 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -68,7 +68,7 @@ typedef struct char *message; char *prompt; gboolean do_markup; - char delim; + char delim; /** no custom */ gboolean no_custom; } ScriptModePrivateData; @@ -83,7 +83,7 @@ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry * length_key++; } // Should be not last character in buffer. - if ( ( length_key + 1 ) < ( length ) ) { + if ( (length_key+1) < (length) ) { buffer[length_key] = '\0'; char *value = buffer + length_key + 1; if ( strcasecmp ( buffer, "icon" ) == 0 ) { @@ -110,7 +110,7 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) length_key++; } - if ( ( length_key + 1 ) < length ) { + if ( (length_key+1) < length ) { line[length_key] = '\0'; char *value = line + length_key + 1; if ( strcasecmp ( line, "message" ) == 0 ) { @@ -133,30 +133,31 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) } else if ( strcasecmp ( line, "delim" ) == 0 ) { pd->delim = helper_parse_char ( value ); - } - else if ( strcasecmp ( line, "no-custom" ) == 0 ) { - pd->no_custom = ( strcasecmp ( value, "true" ) == 0 ); + } else if ( strcasecmp ( line, "no-custom" ) == 0 ) { + pd->no_custom = ( strcasecmp ( value, "true") == 0 ); } } } static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *length, int value ) { - ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; - int fd = -1; - GError *error = NULL; - DmenuScriptEntry *retv = NULL; - char **argv = NULL; - int argc = 0; + ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; + int fd = -1; + GError *error = NULL; + DmenuScriptEntry *retv = NULL; + char **argv = NULL; + int argc = 0; *length = 0; + // Environment char ** env = g_get_environ (); - char *str_value = g_strdup_printf ( "%d", value ); - env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE ); + char *str_value = g_strdup_printf("%d", value); + env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE); g_free ( str_value ); + if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) { argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); argv[argc] = g_strdup ( arg ); @@ -165,7 +166,7 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l } g_strfreev ( env ); if ( error != NULL ) { - char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*) sw->ed, error->message ); + char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*)sw->ed, error->message ); rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. @@ -232,7 +233,7 @@ static int script_mode_init ( Mode *sw ) { if ( sw->private_data == NULL ) { ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); - pd->delim = '\n'; + pd->delim = '\n'; sw->private_data = (void *) pd; pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0 ); } @@ -273,13 +274,11 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned //retv = 1+( mretv & MENU_LOWER_MASK ); script_mode_reset_highlight ( sw ); if ( selected_line != UINT32_MAX ) { - new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); - } - else { + new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length,10+( mretv & MENU_LOWER_MASK ) ); + } else { if ( rmpd->no_custom == FALSE ) { - new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); - } - else { + new_list = execute_executor ( sw, *input, &new_length,10+( mretv & MENU_LOWER_MASK ) ); + } else { return RELOAD_DIALOG; } } @@ -295,8 +294,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned if ( rmpd->no_custom == FALSE ) { script_mode_reset_highlight ( sw ); new_list = execute_executor ( sw, *input, &new_length, 2 ); - } - else { + } else { return RELOAD_DIALOG; } } diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c index 33e52c061..7be6db145 100644 --- a/source/rofi-icon-fetcher.c +++ b/source/rofi-icon-fetcher.c @@ -133,66 +133,64 @@ void rofi_icon_fetcher_destroy ( void ) g_free ( rofi_icon_fetcher_data ); } -static cairo_surface_t* cairo_image_surface_create_from_jpeg_private ( struct jpeg_decompress_struct* cinfo ) -{ - cairo_surface_t* surface = 0; - unsigned char * data = 0; - unsigned char * rgb = 0; - jpeg_read_header ( cinfo, TRUE ); - jpeg_start_decompress ( cinfo ); - surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height ); - data = cairo_image_surface_get_data ( surface ); - rgb = (unsigned char*) ( malloc ( cinfo->output_width * cinfo->output_components ) ); +static cairo_surface_t* cairo_image_surface_create_from_jpeg_private(struct jpeg_decompress_struct* cinfo) { + cairo_surface_t* surface = 0; + unsigned char* data = 0; + unsigned char* rgb = 0; - while ( cinfo->output_scanline < cinfo->output_height ) { - unsigned int i; - int scanline = cinfo->output_scanline * cairo_image_surface_get_stride ( surface ); + jpeg_read_header(cinfo, TRUE); + jpeg_start_decompress(cinfo); - jpeg_read_scanlines ( cinfo, &rgb, 1 ); + surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height); + data = cairo_image_surface_get_data(surface); + rgb = (unsigned char*)(malloc(cinfo->output_width * cinfo->output_components)); - for ( i = 0; i < cinfo->output_width; i++ ) { - int offset = scanline + ( i * 4 ); + while(cinfo->output_scanline < cinfo->output_height) { + unsigned int i; + int scanline = cinfo->output_scanline * cairo_image_surface_get_stride(surface); - data[offset + 3] = 255; - data[offset + 2] = rgb[( i * 3 )]; - data[offset + 1] = rgb[( i * 3 ) + 1]; - data[offset ] = rgb[( i * 3 ) + 2]; - } - } + jpeg_read_scanlines(cinfo, &rgb, 1); + + for(i = 0; i < cinfo->output_width; i++) { + int offset = scanline + (i * 4); + + data[offset + 3] = 255; + data[offset + 2] = rgb[(i * 3)]; + data[offset + 1] = rgb[(i * 3) + 1]; + data[offset ] = rgb[(i * 3) + 2]; + } + } - free ( rgb ); + free(rgb); - jpeg_finish_decompress ( cinfo ); - jpeg_destroy_decompress ( cinfo ); + jpeg_finish_decompress(cinfo); + jpeg_destroy_decompress(cinfo); - cairo_surface_mark_dirty ( surface ); + cairo_surface_mark_dirty(surface); - return surface; + return surface; } -static cairo_surface_t* cairo_image_surface_create_from_jpeg ( const char* file ) -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - cairo_surface_t * surface; - FILE * infile; +static cairo_surface_t* cairo_image_surface_create_from_jpeg(const char* file) { + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + cairo_surface_t* surface; + FILE* infile; - if ( ( infile = fopen ( file, "rb" ) ) == NULL ) { - return NULL; - } + if((infile = fopen(file, "rb")) == NULL) return NULL; - cinfo.err = jpeg_std_error ( &jerr ); + cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress ( &cinfo ); - jpeg_stdio_src ( &cinfo, infile ); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, infile); - surface = cairo_image_surface_create_from_jpeg_private ( &cinfo ); + surface = cairo_image_surface_create_from_jpeg_private(&cinfo); - fclose ( infile ); + fclose(infile); - return surface; + return surface; } static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data ) @@ -237,26 +235,29 @@ static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpoint } if ( icon_surf ) { if ( cairo_surface_status ( icon_surf ) == CAIRO_STATUS_SUCCESS ) { - float sw = sentry->size / (float) cairo_image_surface_get_width ( icon_surf ); - float sh = sentry->size / (float) cairo_image_surface_get_height ( icon_surf ); + float sw = sentry->size/(float)cairo_image_surface_get_width( icon_surf ); + float sh = sentry->size/(float)cairo_image_surface_get_height( icon_surf ); - float scale = ( sw > sh ) ? sh : sw; - if ( scale < 0.5 ) { - cairo_surface_t * surface = cairo_image_surface_create ( - cairo_image_surface_get_format ( icon_surf ), - cairo_image_surface_get_width ( icon_surf ) * scale, - cairo_image_surface_get_height ( icon_surf ) * scale ); + float scale = ( sw > sh)? sh:sw; + if ( scale < 0.5 ) + { + cairo_surface_t * surface = cairo_image_surface_create( + cairo_image_surface_get_format( icon_surf ), + cairo_image_surface_get_width( icon_surf )*scale, + cairo_image_surface_get_height( icon_surf )*scale); cairo_t *d = cairo_create ( surface ); cairo_scale ( d, scale, scale ); - cairo_set_source_surface ( d, icon_surf, 0.0, 0.0 ); - cairo_pattern_set_filter ( cairo_get_source ( d ), CAIRO_FILTER_FAST ); + cairo_set_source_surface ( d, icon_surf, 0.0,0.0); + cairo_pattern_set_filter (cairo_get_source (d), CAIRO_FILTER_FAST); cairo_paint ( d ); cairo_destroy ( d ); cairo_surface_destroy ( icon_surf ); icon_surf = surface; } + + } // check if surface is valid. if ( cairo_surface_status ( icon_surf ) != CAIRO_STATUS_SUCCESS ) { diff --git a/source/rofi.c b/source/rofi.c index e278c2780..b839109aa 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -193,10 +193,10 @@ static void run_switcher ( ModeMode mode ) RofiViewState * state = rofi_view_create ( modi[mode], config.filter, 0, process_result ); // User can pre-select a row. - if ( find_arg ( "-selected-row" ) >= 0 ) { - unsigned int sr = 0; - find_arg_uint ( "-selected-row", &( sr ) ); - rofi_view_set_selected_line ( state, sr ); + if ( find_arg ( "-selected-row" ) >= 0 ){ + unsigned int sr = 0; + find_arg_uint ( "-selected-row", &(sr) ); + rofi_view_set_selected_line ( state, sr ); } if ( state ) { rofi_view_set_active ( state ); @@ -512,7 +512,7 @@ static void rofi_collect_modi_dir ( const char *base_dir ) if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) { continue; } - char *fn = g_build_filename ( base_dir, dn, NULL ); + char *fn = g_build_filename ( base_dir, dn, NULL ); g_debug ( "Trying to open: %s plugin", fn ); GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL ); if ( mod ) { @@ -565,7 +565,7 @@ static void rofi_collect_modi ( void ) g_debug ( "Parse plugin path: %s", config.plugin_path ); rofi_collect_modi_dir ( config.plugin_path ); /* ROFI_PLUGIN_PATH */ - const char *path = g_getenv ( "ROFI_PLUGIN_PATH" ); + const char *path = g_getenv("ROFI_PLUGIN_PATH"); if ( path != NULL ) { gchar ** paths = g_strsplit ( path, ":", -1 ); for ( unsigned int i = 0; paths[i]; i++ ) { @@ -869,41 +869,40 @@ int main ( int argc, char *argv[] ) if ( find_arg ( "-no-config" ) < 0 ) { // Load distro default settings - gboolean found_system = FALSE; - const char * const * dirs = g_get_system_config_dirs (); - if ( dirs ) { - for ( unsigned int i = 0; !found_system && dirs[i]; i++ ) { + gboolean found_system = FALSE; + const char * const * dirs = g_get_system_config_dirs(); + if ( dirs ) + { + for ( unsigned int i =0; !found_system && dirs[i]; i++ ) { /** New format. */ gchar *etc = g_build_filename ( dirs[i], "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Parsing: %s", etc ); rofi_theme_parse_file ( etc ); - found_system = TRUE; - } - else { + found_system = TRUE; + } else { /** Old format. */ gchar *xetc = g_build_filename ( dirs[i], "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) { config_parse_xresource_options_file ( xetc ); old_config_format = TRUE; - found_system = TRUE; + found_system = TRUE; } g_free ( xetc ); } g_free ( etc ); } } - if ( !found_system ) { + if ( ! found_system ) { /** New format. */ gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Look for default config file: %s", etc ); rofi_theme_parse_file ( etc ); - } - else { + } else { /** Old format. */ gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); diff --git a/source/theme.c b/source/theme.c index 78137c979..85bf7c866 100644 --- a/source/theme.c +++ b/source/theme.c @@ -84,23 +84,25 @@ Property *rofi_theme_property_create ( PropertyType type ) static RofiDistanceUnit *rofi_theme_property_copy_distance_unit ( RofiDistanceUnit *unit ) { - RofiDistanceUnit *retv = g_slice_new0 ( RofiDistanceUnit ); - *retv = *unit; + RofiDistanceUnit *retv = g_slice_new0( RofiDistanceUnit ); + *retv = *unit; if ( unit->left ) { - retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); + retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); } if ( unit->right ) { - retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); + retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); } return retv; } RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance ) { RofiDistance retv = distance; - if ( distance.base.left ) { + if ( distance.base.left ) + { retv.base.left = rofi_theme_property_copy_distance_unit ( distance.base.left ); } - if ( distance.base.right ) { + if ( distance.base.right ) + { retv.base.right = rofi_theme_property_copy_distance_unit ( distance.base.right ); } return retv; @@ -127,14 +129,14 @@ Property* rofi_theme_property_copy ( Property *p ) } break; case P_PADDING: - { - retv->value = p->value; - retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top ); - retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left ); - retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom ); - retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right ); - break; - } + { + retv->value = p->value; + retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top); + retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left); + retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom); + retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right); + break; + } default: retv->value = p->value; } @@ -151,7 +153,7 @@ static void rofi_theme_distance_unit_property_free ( RofiDistanceUnit *unit ) rofi_theme_distance_unit_property_free ( unit->right ); unit->right = NULL; } - g_slice_free ( RofiDistanceUnit, unit ); + g_slice_free ( RofiDistanceUnit, unit); } static void rofi_theme_distance_property_free ( RofiDistance *distance ) { @@ -180,11 +182,11 @@ void rofi_theme_property_free ( Property *p ) rofi_theme_property_free ( p->value.link.def_value ); } } - if ( p->type == P_PADDING ) { - rofi_theme_distance_property_free ( &( p->value.padding.top ) ); - rofi_theme_distance_property_free ( &( p->value.padding.right ) ); - rofi_theme_distance_property_free ( &( p->value.padding.bottom ) ); - rofi_theme_distance_property_free ( &( p->value.padding.left ) ); + if ( p->type == P_PADDING) { + rofi_theme_distance_property_free( &(p->value.padding.top)); + rofi_theme_distance_property_free( &(p->value.padding.right)); + rofi_theme_distance_property_free( &(p->value.padding.bottom)); + rofi_theme_distance_property_free( &(p->value.padding.left)); } g_slice_free ( Property, p ); } @@ -214,7 +216,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) rofi_theme_widget_add_properties ( tt, table ); - RofiDistance dsize = (RofiDistance){ .base = { 1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + RofiDistance dsize = (RofiDistance){ .base = {1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; Property *pts = rofi_theme_property_create ( P_PADDING ); pts->value.padding.top = pts->value.padding.right = pts->value.padding.bottom = pts->value.padding.left = dsize; pts->name = g_strdup ( "size" ); @@ -227,7 +229,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); Property *psp = rofi_theme_property_create ( P_PADDING ); psp->name = g_strdup ( "spacing" ); - RofiDistance d = (RofiDistance){ .base = { 5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = {5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; psp->value.padding = (RofiPadding){ d, d, d, d }; g_hash_table_replace ( table, psp->name, psp ); rofi_theme_widget_add_properties ( t, table ); @@ -275,33 +277,27 @@ inline static void printf_double ( double d ) static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) { - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( "( ", stdout ); - } - if ( unit->left ) { + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) + fputs("( " , stdout); + if ( unit->left ) rofi_theme_print_distance_unit ( unit->left ); - } if ( unit->modtype == ROFI_DISTANCE_MODIFIER_ADD ) { fputs ( " + ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { fputs ( " - ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { fputs ( " / ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) { fputs ( " * ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO) { fputs ( " % ", stdout ); - } - if ( unit->right ) { + } + if ( unit->right ) rofi_theme_print_distance_unit ( unit->right ); - } - - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) { + + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) + { if ( unit->type == ROFI_PU_PX ) { printf ( "%upx ", (unsigned int) unit->distance ); } @@ -318,19 +314,18 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) fputs ( "em ", stdout ); } } - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( " )", stdout ); - } + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) + fputs(" )" , stdout); } static void rofi_theme_print_distance ( RofiDistance d ) { - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( "calc( ", stdout ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ + fputs( "calc( ", stdout ); } - rofi_theme_print_distance_unit ( &( d.base ) ); - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( ")", stdout ); + rofi_theme_print_distance_unit ( &(d.base) ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ + fputs( ")", stdout ); } if ( d.style == ROFI_HL_DASH ) { printf ( "dash " ); @@ -747,17 +742,17 @@ RofiDistance rofi_theme_get_distance ( const widget *widget, const char *propert if ( widget->parent ) { return rofi_theme_get_distance ( widget->parent, property, def ); } - return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; } if ( p->type == P_INTEGER ) { - return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; } else { return p->value.padding.left; } } g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); - return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; } int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ) @@ -873,7 +868,7 @@ RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property, pad = p->value.padding; } else { - RofiDistance d = (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = {p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; return (RofiPadding){ d, d, d, d }; } } @@ -928,6 +923,7 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) { int val = unit->distance; + if ( unit->type == ROFI_PU_EM ) { val = unit->distance * textbox_get_estimated_char_height (); } @@ -949,46 +945,48 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) return val; } + static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori ) { - switch ( unit->modtype ) + switch ( unit->modtype) { - case ROFI_DISTANCE_MODIFIER_GROUP: - return distance_unit_get_pixel ( unit->left, ori ); - break; - case ROFI_DISTANCE_MODIFIER_ADD: - return distance_unit_get_pixel ( unit->left, ori ) + distance_unit_get_pixel ( unit->right, ori ); - case ROFI_DISTANCE_MODIFIER_SUBTRACT: - return distance_unit_get_pixel ( unit->left, ori ) - distance_unit_get_pixel ( unit->right, ori ); - case ROFI_DISTANCE_MODIFIER_MULTIPLY: - return distance_unit_get_pixel ( unit->left, ori ) * distance_unit_get_pixel ( unit->right, ori ); - case ROFI_DISTANCE_MODIFIER_DIVIDE: - { - int a = distance_unit_get_pixel ( unit->left, ori ); - int b = distance_unit_get_pixel ( unit->right, ori ); - if ( b != 0 ) { - return a / b; - } - return a; - } - case ROFI_DISTANCE_MODIFIER_MODULO: - { - int a = distance_unit_get_pixel ( unit->left, ori ); - int b = distance_unit_get_pixel ( unit->right, ori ); - if ( b != 0 ) { - return a % b; - } - return 0; - } - default: - break; + case ROFI_DISTANCE_MODIFIER_GROUP: + return distance_unit_get_pixel ( unit->left, ori ); + break; + case ROFI_DISTANCE_MODIFIER_ADD: + return distance_unit_get_pixel ( unit->left, ori)+ distance_unit_get_pixel ( unit->right, ori); + case ROFI_DISTANCE_MODIFIER_SUBTRACT: + return distance_unit_get_pixel ( unit->left, ori)- distance_unit_get_pixel ( unit->right, ori); + case ROFI_DISTANCE_MODIFIER_MULTIPLY: + return distance_unit_get_pixel ( unit->left, ori)* distance_unit_get_pixel ( unit->right, ori); + case ROFI_DISTANCE_MODIFIER_DIVIDE: + { + int a = distance_unit_get_pixel ( unit->left, ori); + int b = distance_unit_get_pixel ( unit->right, ori); + if ( b != 0 ) { + return a/b; + } + return a; + } + case ROFI_DISTANCE_MODIFIER_MODULO: + { + int a = distance_unit_get_pixel ( unit->left, ori); + int b = distance_unit_get_pixel ( unit->right, ori); + if ( b != 0 ) { + return a%b; + } + return 0; + } + default: + break; } return get_pixels ( unit, ori ); } + int distance_get_pixel ( RofiDistance d, RofiOrientation ori ) { - return distance_unit_get_pixel ( &( d.base ), ori ); + return distance_unit_get_pixel ( &(d.base), ori); } void distance_get_linestyle ( RofiDistance d, cairo_t *draw ) @@ -1011,13 +1009,13 @@ gboolean rofi_theme_is_empty ( void ) return TRUE; } if ( rofi_theme->num_widgets == 3 ) { - // HACK: check for default added elements. - for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) { - if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7 ) != 0 ) { - return FALSE; - } + // HACK: check for default added elements. + for ( unsigned int i = 0; i < rofi_theme->num_widgets;i++) { + if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7) != 0 ){ + return FALSE; } - return TRUE; + } + return TRUE; } return FALSE; @@ -1314,6 +1312,7 @@ ThemeMediaType rofi_theme_parse_media_type ( const char *type ) return THEME_MEDIA_TYPE_INVALID; } + gboolean rofi_theme_has_property ( const widget *widget, const char *property ) { ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); diff --git a/source/view.c b/source/view.c index f450bd468..2c746e37d 100644 --- a/source/view.c +++ b/source/view.c @@ -126,9 +126,9 @@ struct .fake_bgrel = FALSE, .flags = MENU_NORMAL, .views = G_QUEUE_INIT, - .idle_timeout = 0, - .count = 0L, - .repaint_source = 0, + .idle_timeout = 0, + .count = 0L, + .repaint_source = 0, .fullscreen = FALSE, }; diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 0397b43ff..81f346780 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -45,10 +45,10 @@ /** * Orientation of the listview */ -/** Vertical (classical) list */ -#define LISTVIEW ROFI_ORIENTATION_VERTICAL -/** Horizontal list. (barview) */ -#define BARVIEW ROFI_ORIENTATION_HORIZONTAL + /** Vertical (classical) list */ +#define LISTVIEW ROFI_ORIENTATION_VERTICAL + /** Horizontal list. (barview) */ +#define BARVIEW ROFI_ORIENTATION_HORIZONTAL /** * The moving direction of the selection, this (in barview) affects the scrolling. @@ -69,7 +69,7 @@ typedef struct struct _listview { - widget widget; + widget widget; RofiOrientation type; @@ -553,8 +553,8 @@ static void listview_resize ( widget *wid, short w, short h ) lv->max_elements = lv->max_rows * lv->menu_columns; widget_move ( WIDGET ( lv->scrollbar ), - lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), - widget_padding_get_top ( WIDGET ( lv ) ) ); + lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), + widget_padding_get_top ( WIDGET ( lv ) ) ); widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height ); @@ -661,13 +661,10 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca listview_create_row ( lv, &row ); // FIXME: hack to scale hight correctly. if ( lv->eh > 1 && row.textbox ) { - char buff[lv->eh * 2 + 1]; - memset ( buff, '\0', lv->eh * 2 + 1 ); - for ( unsigned int i = 0; i < ( lv->eh - 1 ); i++ ) { - buff[i * 2] = 'a'; buff[i * 2 + 1] = '\n'; - } - ; - textbox_text ( row.textbox, buff ); + char buff[lv->eh*2+1] ; + memset( buff, '\0', lv->eh*2+1); + for ( unsigned int i = 0; i < (lv->eh-1); i++) { buff[i*2] = 'a'; buff[i*2+1] ='\n'; }; + textbox_text( row.textbox, buff); } lv->element_height = widget_get_desired_height ( WIDGET ( row.box ) ); widget_free ( WIDGET ( row.box ) ); diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index ca4f415e1..482d10377 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -276,7 +276,7 @@ static void __textbox_update_pango_text ( textbox *tb ) tb->show_placeholder = FALSE; if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) { size_t l = g_utf8_strlen ( tb->text, -1 ); - char string[l + 1]; + char string [l + 1]; memset ( string, '*', l ); string[l] = '\0'; pango_layout_set_text ( tb->layout, string, l ); @@ -911,7 +911,7 @@ double textbox_get_estimated_ch ( void ) int textbox_get_estimated_height ( const textbox *tb, int eh ) { int height = pango_font_metrics_get_ascent ( tb->metrics ) + pango_font_metrics_get_descent ( tb->metrics ); - return ceil ( ( eh * height ) / (double) PANGO_SCALE ) + widget_padding_get_padding_height ( WIDGET ( tb ) ); + return ceil(( eh * height ) / (double)PANGO_SCALE) + widget_padding_get_padding_height ( WIDGET ( tb ) ); } int textbox_get_desired_width ( widget *wid ) { diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 517b7f5b9..c0e898596 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -40,18 +40,11 @@ void widget_init ( widget *wid, widget *parent, WidgetType type, const char *nam wid->parent = parent; wid->name = g_strdup ( name ); wid->def_padding = - (RofiPadding){ { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; - wid->def_border = - (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; - wid->def_border_radius = - (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; - wid->def_margin = - (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + (RofiPadding){ { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, + { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + wid->def_border = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + wid->def_border_radius = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + wid->def_margin = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; wid->padding = rofi_theme_get_padding ( wid, "padding", wid->def_padding ); wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border ); diff --git a/source/xcb.c b/source/xcb.c index 39b738f4d..dd42e98b1 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -79,7 +79,7 @@ WindowManagerQuirk current_window_manager = WM_EWHM; struct _xcb_stuff xcb_int = { .connection = NULL, .screen = NULL, - .screen_nbr = -1, + .screen_nbr = -1, .sndisplay = NULL, .sncontext = NULL, .monitors = NULL diff --git a/source/xrmoptions.c b/source/xrmoptions.c index f63e82fab..ef84dd779 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -225,7 +225,7 @@ static XrmOption xrmOptions[] = { "Modi that do not use a linbreak for {linebreak} in combi mode, but -combi-no-linebreak-str instead.", CONFIG_DEFAULT }, { xrm_String, "combi-no-linebreak-str", { .str = &config.combi_no_linebreak_str }, NULL, "String used instead of linebreak in the output formatting for -combi-no-linebreak-modi.", CONFIG_DEFAULT }, - { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, + { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, "Allow pango markup in combi mode entries.", CONFIG_DEFAULT }, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL, "Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT }, From d3d2e843fefeb0a0da502c6c973875d132f3f461 Mon Sep 17 00:00:00 2001 From: jchtt Date: Mon, 11 May 2020 22:54:58 -0400 Subject: [PATCH 4/7] Fixed indent, second try --- include/rofi-types.h | 11 ++- include/theme.h | 1 - include/view.h | 1 - source/dialogs/combi.c | 84 +++++++++--------- source/dialogs/dmenu.c | 1 - source/dialogs/drun.c | 2 +- source/dialogs/script.c | 46 +++++----- source/rofi-icon-fetcher.c | 105 +++++++++++----------- source/rofi.c | 33 +++---- source/theme.c | 177 +++++++++++++++++++------------------ source/widgets/listview.c | 25 +++--- source/widgets/textbox.c | 4 +- source/widgets/widget.c | 17 ++-- source/xrmoptions.c | 2 +- 14 files changed, 259 insertions(+), 250 deletions(-) diff --git a/include/rofi-types.h b/include/rofi-types.h index ced7e321f..9ae17ab36 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -100,22 +100,21 @@ typedef enum ROFI_DISTANCE_MODIFIER_GROUP, } RofiDistanceModifier; -typedef struct RofiDistanceUnit +typedef struct RofiDistanceUnit { /** Distance */ - double distance; + double distance; /** Unit type of the distance */ - RofiPixelUnit type; + RofiPixelUnit type; /** Type */ - RofiDistanceModifier modtype; + RofiDistanceModifier modtype; /** Modifier */ struct RofiDistanceUnit *left; /** Modifier */ struct RofiDistanceUnit *right; - } RofiDistanceUnit; typedef struct @@ -123,7 +122,7 @@ typedef struct /** Base */ RofiDistanceUnit base; /** Style of the line (optional)*/ - RofiLineStyle style; + RofiLineStyle style; } RofiDistance; /** diff --git a/include/theme.h b/include/theme.h index 055bea710..28dd09821 100644 --- a/include/theme.h +++ b/include/theme.h @@ -249,7 +249,6 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doub */ void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d ); - /** * @param widget The widget to query * @param property The property to query. diff --git a/include/view.h b/include/view.h index ba07f32e3..f5deac96a 100644 --- a/include/view.h +++ b/include/view.h @@ -307,7 +307,6 @@ void rofi_capture_screenshot ( void ); */ void rofi_view_set_window_title ( const char * title ); - /** * set ellipsize mode to start. */ diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 0037fea2c..bb0b197a4 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -48,7 +48,7 @@ typedef struct { Mode *mode; gboolean disable; - gboolean print_newline; + gboolean print_newline; } CombiMode; typedef struct @@ -72,8 +72,8 @@ static void combi_mode_parse_switchers ( Mode *sw ) const char * const sep = ",#"; // Split token on ','. This modifies switcher_str. - GHashTable *ht; - ht = g_hash_table_new ( g_str_hash, g_str_equal ); + GHashTable *ht; + ht = g_hash_table_new ( g_str_hash, g_str_equal ); for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { @@ -83,20 +83,20 @@ static void combi_mode_parse_switchers ( Mode *sw ) Mode *mode = rofi_collect_modi_search ( token ); if ( mode ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = mode; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); - /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = mode; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ } else { // If not build in, use custom switchers. Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = sw; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = sw; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); } else { // Report error, don't continue. @@ -109,17 +109,17 @@ static void combi_mode_parse_switchers ( Mode *sw ) savept = NULL; for ( char *token = strtok_r ( config.combi_no_linebreak_modi, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { - CombiMode *mode = g_hash_table_lookup ( ht, token ); - if ( mode != NULL ) { - mode->print_newline = FALSE; - } - else { - g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); - } - } + CombiMode *mode = g_hash_table_lookup ( ht, token ); + if ( mode != NULL ) { + mode->print_newline = FALSE; + } + else { + g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); + } + } // Free string that was modified by strtok_r g_free ( switcher_str ); - g_hash_table_destroy( ht ); + g_hash_table_destroy ( ht ); } static int combi_mode_init ( Mode *sw ) @@ -179,11 +179,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned CombiModePrivateData *pd = mode_get_private_data ( sw ); if ( input[0][0] == '!' ) { - int switcher = -1; + int switcher = -1; // Implement strchrnul behaviour. - char *eob = g_utf8_strchr ( input[0], -1,' ' ); + char *eob = g_utf8_strchr ( input[0], -1, ' ' ); if ( eob == NULL ) { - eob = &(input[0][strlen(input[0])]); + eob = &( input[0][strlen ( input[0] )] ); } ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1; if ( bang_len > 0 ) { @@ -208,11 +208,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned return mretv & MENU_LOWER_MASK; } - unsigned offset = 0; + unsigned offset = 0; for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - if ( pd->switchers[i].disable ) { - offset += pd->lengths[i]; - } + if ( pd->switchers[i].disable ) { + offset += pd->lengths[i]; + } if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[i] ); @@ -236,9 +236,9 @@ static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigne static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - if (config.markup_combi) { - *state |= MARKUP; - } + if ( config.markup_combi ) { + *state |= MARKUP; + } if ( !get_entry ) { for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { @@ -254,16 +254,16 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat char * str = retv = 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 ); if ( !config.combi_hide_mode_prefix ) { - char *dname_markup = g_markup_escape_text ( dname, -1 ); - char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str); - retv = helper_string_replace_if_exists( config.combi_display_format, - "{mode}", dname_markup, - "{linebreak}", opt_linebreak, - "{element}", str, - NULL ); + char *dname_markup = g_markup_escape_text ( dname, -1 ); + char *opt_linebreak = g_strdup ( pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str ); + retv = helper_string_replace_if_exists ( config.combi_display_format, + "{mode}", dname_markup, + "{linebreak}", opt_linebreak, + "{element}", str, + NULL ); g_free ( str ); - g_free ( dname_markup ); - g_free ( opt_linebreak ); + g_free ( dname_markup ); + g_free ( opt_linebreak ); } if ( attr_list != NULL ) { @@ -321,10 +321,10 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) } if ( input != NULL && input[0] == '!' ) { // Implement strchrnul behaviour. - const char *eob = g_utf8_strchr ( input, -1, ' ' ); + const char *eob = g_utf8_strchr ( input, -1, ' ' ); if ( eob == NULL ) { // Set it to end. - eob = &(input[strlen(input)]); + eob = &( input[strlen ( input )] ); } ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1; if ( bang_len > 0 ) { diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 5e9af2d4b..d82299be7 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -734,7 +734,6 @@ int dmenu_switcher_dialog ( void ) find_arg_str ( "-p", &( dmenu_mode.display_name ) ); RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize ); - if ( find_arg ( "-keep-right" ) >= 0 ) { rofi_view_ellipsize_start ( state ); } diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index afc19ba62..67549bf94 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -182,7 +182,7 @@ static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpoi case 'm': break; case '%': - g_string_append(res, "%"); + g_string_append ( res, "%" ); break; case 'k': if ( e->e->path ) { diff --git a/source/dialogs/script.c b/source/dialogs/script.c index c7cc6d706..ab2a3f4a7 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -68,7 +68,7 @@ typedef struct char *message; char *prompt; gboolean do_markup; - char delim; + char delim; /** no custom */ gboolean no_custom; } ScriptModePrivateData; @@ -83,7 +83,7 @@ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry * length_key++; } // Should be not last character in buffer. - if ( (length_key+1) < (length) ) { + if ( ( length_key + 1 ) < ( length ) ) { buffer[length_key] = '\0'; char *value = buffer + length_key + 1; if ( strcasecmp ( buffer, "icon" ) == 0 ) { @@ -110,7 +110,7 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) length_key++; } - if ( (length_key+1) < length ) { + if ( ( length_key + 1 ) < length ) { line[length_key] = '\0'; char *value = line + length_key + 1; if ( strcasecmp ( line, "message" ) == 0 ) { @@ -133,31 +133,30 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) } else if ( strcasecmp ( line, "delim" ) == 0 ) { pd->delim = helper_parse_char ( value ); - } else if ( strcasecmp ( line, "no-custom" ) == 0 ) { - pd->no_custom = ( strcasecmp ( value, "true") == 0 ); + } + else if ( strcasecmp ( line, "no-custom" ) == 0 ) { + pd->no_custom = ( strcasecmp ( value, "true" ) == 0 ); } } } static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *length, int value ) { - ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; - int fd = -1; - GError *error = NULL; - DmenuScriptEntry *retv = NULL; - char **argv = NULL; - int argc = 0; + ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; + int fd = -1; + GError *error = NULL; + DmenuScriptEntry *retv = NULL; + char **argv = NULL; + int argc = 0; *length = 0; - // Environment char ** env = g_get_environ (); - char *str_value = g_strdup_printf("%d", value); - env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE); + char *str_value = g_strdup_printf ( "%d", value ); + env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE ); g_free ( str_value ); - if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) { argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); argv[argc] = g_strdup ( arg ); @@ -166,7 +165,7 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l } g_strfreev ( env ); if ( error != NULL ) { - char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*)sw->ed, error->message ); + char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*) sw->ed, error->message ); rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. @@ -233,7 +232,7 @@ static int script_mode_init ( Mode *sw ) { if ( sw->private_data == NULL ) { ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); - pd->delim = '\n'; + pd->delim = '\n'; sw->private_data = (void *) pd; pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0 ); } @@ -274,11 +273,13 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned //retv = 1+( mretv & MENU_LOWER_MASK ); script_mode_reset_highlight ( sw ); if ( selected_line != UINT32_MAX ) { - new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length,10+( mretv & MENU_LOWER_MASK ) ); - } else { + new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); + } + else { if ( rmpd->no_custom == FALSE ) { - new_list = execute_executor ( sw, *input, &new_length,10+( mretv & MENU_LOWER_MASK ) ); - } else { + new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); + } + else { return RELOAD_DIALOG; } } @@ -294,7 +295,8 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned if ( rmpd->no_custom == FALSE ) { script_mode_reset_highlight ( sw ); new_list = execute_executor ( sw, *input, &new_length, 2 ); - } else { + } + else { return RELOAD_DIALOG; } } diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c index 7be6db145..33e52c061 100644 --- a/source/rofi-icon-fetcher.c +++ b/source/rofi-icon-fetcher.c @@ -133,64 +133,66 @@ void rofi_icon_fetcher_destroy ( void ) g_free ( rofi_icon_fetcher_data ); } +static cairo_surface_t* cairo_image_surface_create_from_jpeg_private ( struct jpeg_decompress_struct* cinfo ) +{ + cairo_surface_t* surface = 0; + unsigned char * data = 0; + unsigned char * rgb = 0; + jpeg_read_header ( cinfo, TRUE ); + jpeg_start_decompress ( cinfo ); -static cairo_surface_t* cairo_image_surface_create_from_jpeg_private(struct jpeg_decompress_struct* cinfo) { - cairo_surface_t* surface = 0; - unsigned char* data = 0; - unsigned char* rgb = 0; - - jpeg_read_header(cinfo, TRUE); - jpeg_start_decompress(cinfo); - - surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height); - data = cairo_image_surface_get_data(surface); - rgb = (unsigned char*)(malloc(cinfo->output_width * cinfo->output_components)); + surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height ); + data = cairo_image_surface_get_data ( surface ); + rgb = (unsigned char*) ( malloc ( cinfo->output_width * cinfo->output_components ) ); - while(cinfo->output_scanline < cinfo->output_height) { - unsigned int i; - int scanline = cinfo->output_scanline * cairo_image_surface_get_stride(surface); + while ( cinfo->output_scanline < cinfo->output_height ) { + unsigned int i; + int scanline = cinfo->output_scanline * cairo_image_surface_get_stride ( surface ); - jpeg_read_scanlines(cinfo, &rgb, 1); + jpeg_read_scanlines ( cinfo, &rgb, 1 ); - for(i = 0; i < cinfo->output_width; i++) { - int offset = scanline + (i * 4); + for ( i = 0; i < cinfo->output_width; i++ ) { + int offset = scanline + ( i * 4 ); - data[offset + 3] = 255; - data[offset + 2] = rgb[(i * 3)]; - data[offset + 1] = rgb[(i * 3) + 1]; - data[offset ] = rgb[(i * 3) + 2]; - } - } + data[offset + 3] = 255; + data[offset + 2] = rgb[( i * 3 )]; + data[offset + 1] = rgb[( i * 3 ) + 1]; + data[offset ] = rgb[( i * 3 ) + 2]; + } + } - free(rgb); + free ( rgb ); - jpeg_finish_decompress(cinfo); - jpeg_destroy_decompress(cinfo); + jpeg_finish_decompress ( cinfo ); + jpeg_destroy_decompress ( cinfo ); - cairo_surface_mark_dirty(surface); + cairo_surface_mark_dirty ( surface ); - return surface; + return surface; } -static cairo_surface_t* cairo_image_surface_create_from_jpeg(const char* file) { - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - cairo_surface_t* surface; - FILE* infile; +static cairo_surface_t* cairo_image_surface_create_from_jpeg ( const char* file ) +{ + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + cairo_surface_t * surface; + FILE * infile; - if((infile = fopen(file, "rb")) == NULL) return NULL; + if ( ( infile = fopen ( file, "rb" ) ) == NULL ) { + return NULL; + } - cinfo.err = jpeg_std_error(&jerr); + cinfo.err = jpeg_std_error ( &jerr ); - jpeg_create_decompress(&cinfo); - jpeg_stdio_src(&cinfo, infile); + jpeg_create_decompress ( &cinfo ); + jpeg_stdio_src ( &cinfo, infile ); - surface = cairo_image_surface_create_from_jpeg_private(&cinfo); + surface = cairo_image_surface_create_from_jpeg_private ( &cinfo ); - fclose(infile); + fclose ( infile ); - return surface; + return surface; } static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data ) @@ -235,29 +237,26 @@ static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpoint } if ( icon_surf ) { if ( cairo_surface_status ( icon_surf ) == CAIRO_STATUS_SUCCESS ) { - float sw = sentry->size/(float)cairo_image_surface_get_width( icon_surf ); - float sh = sentry->size/(float)cairo_image_surface_get_height( icon_surf ); + float sw = sentry->size / (float) cairo_image_surface_get_width ( icon_surf ); + float sh = sentry->size / (float) cairo_image_surface_get_height ( icon_surf ); - float scale = ( sw > sh)? sh:sw; - if ( scale < 0.5 ) - { - cairo_surface_t * surface = cairo_image_surface_create( - cairo_image_surface_get_format( icon_surf ), - cairo_image_surface_get_width( icon_surf )*scale, - cairo_image_surface_get_height( icon_surf )*scale); + float scale = ( sw > sh ) ? sh : sw; + if ( scale < 0.5 ) { + cairo_surface_t * surface = cairo_image_surface_create ( + cairo_image_surface_get_format ( icon_surf ), + cairo_image_surface_get_width ( icon_surf ) * scale, + cairo_image_surface_get_height ( icon_surf ) * scale ); cairo_t *d = cairo_create ( surface ); cairo_scale ( d, scale, scale ); - cairo_set_source_surface ( d, icon_surf, 0.0,0.0); - cairo_pattern_set_filter (cairo_get_source (d), CAIRO_FILTER_FAST); + cairo_set_source_surface ( d, icon_surf, 0.0, 0.0 ); + cairo_pattern_set_filter ( cairo_get_source ( d ), CAIRO_FILTER_FAST ); cairo_paint ( d ); cairo_destroy ( d ); cairo_surface_destroy ( icon_surf ); icon_surf = surface; } - - } // check if surface is valid. if ( cairo_surface_status ( icon_surf ) != CAIRO_STATUS_SUCCESS ) { diff --git a/source/rofi.c b/source/rofi.c index b839109aa..e278c2780 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -193,10 +193,10 @@ static void run_switcher ( ModeMode mode ) RofiViewState * state = rofi_view_create ( modi[mode], config.filter, 0, process_result ); // User can pre-select a row. - if ( find_arg ( "-selected-row" ) >= 0 ){ - unsigned int sr = 0; - find_arg_uint ( "-selected-row", &(sr) ); - rofi_view_set_selected_line ( state, sr ); + if ( find_arg ( "-selected-row" ) >= 0 ) { + unsigned int sr = 0; + find_arg_uint ( "-selected-row", &( sr ) ); + rofi_view_set_selected_line ( state, sr ); } if ( state ) { rofi_view_set_active ( state ); @@ -512,7 +512,7 @@ static void rofi_collect_modi_dir ( const char *base_dir ) if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) { continue; } - char *fn = g_build_filename ( base_dir, dn, NULL ); + char *fn = g_build_filename ( base_dir, dn, NULL ); g_debug ( "Trying to open: %s plugin", fn ); GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL ); if ( mod ) { @@ -565,7 +565,7 @@ static void rofi_collect_modi ( void ) g_debug ( "Parse plugin path: %s", config.plugin_path ); rofi_collect_modi_dir ( config.plugin_path ); /* ROFI_PLUGIN_PATH */ - const char *path = g_getenv("ROFI_PLUGIN_PATH"); + const char *path = g_getenv ( "ROFI_PLUGIN_PATH" ); if ( path != NULL ) { gchar ** paths = g_strsplit ( path, ":", -1 ); for ( unsigned int i = 0; paths[i]; i++ ) { @@ -869,40 +869,41 @@ int main ( int argc, char *argv[] ) if ( find_arg ( "-no-config" ) < 0 ) { // Load distro default settings - gboolean found_system = FALSE; - const char * const * dirs = g_get_system_config_dirs(); - if ( dirs ) - { - for ( unsigned int i =0; !found_system && dirs[i]; i++ ) { + gboolean found_system = FALSE; + const char * const * dirs = g_get_system_config_dirs (); + if ( dirs ) { + for ( unsigned int i = 0; !found_system && dirs[i]; i++ ) { /** New format. */ gchar *etc = g_build_filename ( dirs[i], "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Parsing: %s", etc ); rofi_theme_parse_file ( etc ); - found_system = TRUE; - } else { + found_system = TRUE; + } + else { /** Old format. */ gchar *xetc = g_build_filename ( dirs[i], "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) { config_parse_xresource_options_file ( xetc ); old_config_format = TRUE; - found_system = TRUE; + found_system = TRUE; } g_free ( xetc ); } g_free ( etc ); } } - if ( ! found_system ) { + if ( !found_system ) { /** New format. */ gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Look for default config file: %s", etc ); rofi_theme_parse_file ( etc ); - } else { + } + else { /** Old format. */ gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); diff --git a/source/theme.c b/source/theme.c index 85bf7c866..78137c979 100644 --- a/source/theme.c +++ b/source/theme.c @@ -84,25 +84,23 @@ Property *rofi_theme_property_create ( PropertyType type ) static RofiDistanceUnit *rofi_theme_property_copy_distance_unit ( RofiDistanceUnit *unit ) { - RofiDistanceUnit *retv = g_slice_new0( RofiDistanceUnit ); - *retv = *unit; + RofiDistanceUnit *retv = g_slice_new0 ( RofiDistanceUnit ); + *retv = *unit; if ( unit->left ) { - retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); + retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); } if ( unit->right ) { - retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); + retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); } return retv; } RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance ) { RofiDistance retv = distance; - if ( distance.base.left ) - { + if ( distance.base.left ) { retv.base.left = rofi_theme_property_copy_distance_unit ( distance.base.left ); } - if ( distance.base.right ) - { + if ( distance.base.right ) { retv.base.right = rofi_theme_property_copy_distance_unit ( distance.base.right ); } return retv; @@ -129,14 +127,14 @@ Property* rofi_theme_property_copy ( Property *p ) } break; case P_PADDING: - { - retv->value = p->value; - retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top); - retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left); - retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom); - retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right); - break; - } + { + retv->value = p->value; + retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top ); + retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left ); + retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom ); + retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right ); + break; + } default: retv->value = p->value; } @@ -153,7 +151,7 @@ static void rofi_theme_distance_unit_property_free ( RofiDistanceUnit *unit ) rofi_theme_distance_unit_property_free ( unit->right ); unit->right = NULL; } - g_slice_free ( RofiDistanceUnit, unit); + g_slice_free ( RofiDistanceUnit, unit ); } static void rofi_theme_distance_property_free ( RofiDistance *distance ) { @@ -182,11 +180,11 @@ void rofi_theme_property_free ( Property *p ) rofi_theme_property_free ( p->value.link.def_value ); } } - if ( p->type == P_PADDING) { - rofi_theme_distance_property_free( &(p->value.padding.top)); - rofi_theme_distance_property_free( &(p->value.padding.right)); - rofi_theme_distance_property_free( &(p->value.padding.bottom)); - rofi_theme_distance_property_free( &(p->value.padding.left)); + if ( p->type == P_PADDING ) { + rofi_theme_distance_property_free ( &( p->value.padding.top ) ); + rofi_theme_distance_property_free ( &( p->value.padding.right ) ); + rofi_theme_distance_property_free ( &( p->value.padding.bottom ) ); + rofi_theme_distance_property_free ( &( p->value.padding.left ) ); } g_slice_free ( Property, p ); } @@ -216,7 +214,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) rofi_theme_widget_add_properties ( tt, table ); - RofiDistance dsize = (RofiDistance){ .base = {1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + RofiDistance dsize = (RofiDistance){ .base = { 1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; Property *pts = rofi_theme_property_create ( P_PADDING ); pts->value.padding.top = pts->value.padding.right = pts->value.padding.bottom = pts->value.padding.left = dsize; pts->name = g_strdup ( "size" ); @@ -229,7 +227,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); Property *psp = rofi_theme_property_create ( P_PADDING ); psp->name = g_strdup ( "spacing" ); - RofiDistance d = (RofiDistance){ .base = {5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = { 5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; psp->value.padding = (RofiPadding){ d, d, d, d }; g_hash_table_replace ( table, psp->name, psp ); rofi_theme_widget_add_properties ( t, table ); @@ -277,27 +275,33 @@ inline static void printf_double ( double d ) static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) { - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) - fputs("( " , stdout); - if ( unit->left ) + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( "( ", stdout ); + } + if ( unit->left ) { rofi_theme_print_distance_unit ( unit->left ); + } if ( unit->modtype == ROFI_DISTANCE_MODIFIER_ADD ) { fputs ( " + ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { fputs ( " - ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { fputs ( " / ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY ) { fputs ( " * ", stdout ); - } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO) { + } + else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO ) { fputs ( " % ", stdout ); - } - if ( unit->right ) + } + if ( unit->right ) { rofi_theme_print_distance_unit ( unit->right ); - - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) - { + } + + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) { if ( unit->type == ROFI_PU_PX ) { printf ( "%upx ", (unsigned int) unit->distance ); } @@ -314,18 +318,19 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) fputs ( "em ", stdout ); } } - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) - fputs(" )" , stdout); + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( " )", stdout ); + } } static void rofi_theme_print_distance ( RofiDistance d ) { - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ - fputs( "calc( ", stdout ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( "calc( ", stdout ); } - rofi_theme_print_distance_unit ( &(d.base) ); - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ - fputs( ")", stdout ); + rofi_theme_print_distance_unit ( &( d.base ) ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { + fputs ( ")", stdout ); } if ( d.style == ROFI_HL_DASH ) { printf ( "dash " ); @@ -742,17 +747,17 @@ RofiDistance rofi_theme_get_distance ( const widget *widget, const char *propert if ( widget->parent ) { return rofi_theme_get_distance ( widget->parent, property, def ); } - return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; } if ( p->type == P_INTEGER ) { - return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; } else { return p->value.padding.left; } } g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); - return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; } int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ) @@ -868,7 +873,7 @@ RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property, pad = p->value.padding; } else { - RofiDistance d = (RofiDistance){ .base = {p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; return (RofiPadding){ d, d, d, d }; } } @@ -923,7 +928,6 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) { int val = unit->distance; - if ( unit->type == ROFI_PU_EM ) { val = unit->distance * textbox_get_estimated_char_height (); } @@ -945,48 +949,46 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) return val; } - static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori ) { - switch ( unit->modtype) + switch ( unit->modtype ) { - case ROFI_DISTANCE_MODIFIER_GROUP: - return distance_unit_get_pixel ( unit->left, ori ); - break; - case ROFI_DISTANCE_MODIFIER_ADD: - return distance_unit_get_pixel ( unit->left, ori)+ distance_unit_get_pixel ( unit->right, ori); - case ROFI_DISTANCE_MODIFIER_SUBTRACT: - return distance_unit_get_pixel ( unit->left, ori)- distance_unit_get_pixel ( unit->right, ori); - case ROFI_DISTANCE_MODIFIER_MULTIPLY: - return distance_unit_get_pixel ( unit->left, ori)* distance_unit_get_pixel ( unit->right, ori); - case ROFI_DISTANCE_MODIFIER_DIVIDE: - { - int a = distance_unit_get_pixel ( unit->left, ori); - int b = distance_unit_get_pixel ( unit->right, ori); - if ( b != 0 ) { - return a/b; - } - return a; - } - case ROFI_DISTANCE_MODIFIER_MODULO: - { - int a = distance_unit_get_pixel ( unit->left, ori); - int b = distance_unit_get_pixel ( unit->right, ori); - if ( b != 0 ) { - return a%b; - } - return 0; - } - default: - break; + case ROFI_DISTANCE_MODIFIER_GROUP: + return distance_unit_get_pixel ( unit->left, ori ); + break; + case ROFI_DISTANCE_MODIFIER_ADD: + return distance_unit_get_pixel ( unit->left, ori ) + distance_unit_get_pixel ( unit->right, ori ); + case ROFI_DISTANCE_MODIFIER_SUBTRACT: + return distance_unit_get_pixel ( unit->left, ori ) - distance_unit_get_pixel ( unit->right, ori ); + case ROFI_DISTANCE_MODIFIER_MULTIPLY: + return distance_unit_get_pixel ( unit->left, ori ) * distance_unit_get_pixel ( unit->right, ori ); + case ROFI_DISTANCE_MODIFIER_DIVIDE: + { + int a = distance_unit_get_pixel ( unit->left, ori ); + int b = distance_unit_get_pixel ( unit->right, ori ); + if ( b != 0 ) { + return a / b; + } + return a; + } + case ROFI_DISTANCE_MODIFIER_MODULO: + { + int a = distance_unit_get_pixel ( unit->left, ori ); + int b = distance_unit_get_pixel ( unit->right, ori ); + if ( b != 0 ) { + return a % b; + } + return 0; + } + default: + break; } return get_pixels ( unit, ori ); } - int distance_get_pixel ( RofiDistance d, RofiOrientation ori ) { - return distance_unit_get_pixel ( &(d.base), ori); + return distance_unit_get_pixel ( &( d.base ), ori ); } void distance_get_linestyle ( RofiDistance d, cairo_t *draw ) @@ -1009,13 +1011,13 @@ gboolean rofi_theme_is_empty ( void ) return TRUE; } if ( rofi_theme->num_widgets == 3 ) { - // HACK: check for default added elements. - for ( unsigned int i = 0; i < rofi_theme->num_widgets;i++) { - if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7) != 0 ){ - return FALSE; + // HACK: check for default added elements. + for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) { + if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7 ) != 0 ) { + return FALSE; + } } - } - return TRUE; + return TRUE; } return FALSE; @@ -1312,7 +1314,6 @@ ThemeMediaType rofi_theme_parse_media_type ( const char *type ) return THEME_MEDIA_TYPE_INVALID; } - gboolean rofi_theme_has_property ( const widget *widget, const char *property ) { ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 81f346780..0397b43ff 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -45,10 +45,10 @@ /** * Orientation of the listview */ - /** Vertical (classical) list */ -#define LISTVIEW ROFI_ORIENTATION_VERTICAL - /** Horizontal list. (barview) */ -#define BARVIEW ROFI_ORIENTATION_HORIZONTAL +/** Vertical (classical) list */ +#define LISTVIEW ROFI_ORIENTATION_VERTICAL +/** Horizontal list. (barview) */ +#define BARVIEW ROFI_ORIENTATION_HORIZONTAL /** * The moving direction of the selection, this (in barview) affects the scrolling. @@ -69,7 +69,7 @@ typedef struct struct _listview { - widget widget; + widget widget; RofiOrientation type; @@ -553,8 +553,8 @@ static void listview_resize ( widget *wid, short w, short h ) lv->max_elements = lv->max_rows * lv->menu_columns; widget_move ( WIDGET ( lv->scrollbar ), - lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), - widget_padding_get_top ( WIDGET ( lv ) ) ); + lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), + widget_padding_get_top ( WIDGET ( lv ) ) ); widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height ); @@ -661,10 +661,13 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca listview_create_row ( lv, &row ); // FIXME: hack to scale hight correctly. if ( lv->eh > 1 && row.textbox ) { - char buff[lv->eh*2+1] ; - memset( buff, '\0', lv->eh*2+1); - for ( unsigned int i = 0; i < (lv->eh-1); i++) { buff[i*2] = 'a'; buff[i*2+1] ='\n'; }; - textbox_text( row.textbox, buff); + char buff[lv->eh * 2 + 1]; + memset ( buff, '\0', lv->eh * 2 + 1 ); + for ( unsigned int i = 0; i < ( lv->eh - 1 ); i++ ) { + buff[i * 2] = 'a'; buff[i * 2 + 1] = '\n'; + } + ; + textbox_text ( row.textbox, buff ); } lv->element_height = widget_get_desired_height ( WIDGET ( row.box ) ); widget_free ( WIDGET ( row.box ) ); diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index 482d10377..ca4f415e1 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -276,7 +276,7 @@ static void __textbox_update_pango_text ( textbox *tb ) tb->show_placeholder = FALSE; if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) { size_t l = g_utf8_strlen ( tb->text, -1 ); - char string [l + 1]; + char string[l + 1]; memset ( string, '*', l ); string[l] = '\0'; pango_layout_set_text ( tb->layout, string, l ); @@ -911,7 +911,7 @@ double textbox_get_estimated_ch ( void ) int textbox_get_estimated_height ( const textbox *tb, int eh ) { int height = pango_font_metrics_get_ascent ( tb->metrics ) + pango_font_metrics_get_descent ( tb->metrics ); - return ceil(( eh * height ) / (double)PANGO_SCALE) + widget_padding_get_padding_height ( WIDGET ( tb ) ); + return ceil ( ( eh * height ) / (double) PANGO_SCALE ) + widget_padding_get_padding_height ( WIDGET ( tb ) ); } int textbox_get_desired_width ( widget *wid ) { diff --git a/source/widgets/widget.c b/source/widgets/widget.c index c0e898596..517b7f5b9 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -40,11 +40,18 @@ void widget_init ( widget *wid, widget *parent, WidgetType type, const char *nam wid->parent = parent; wid->name = g_strdup ( name ); wid->def_padding = - (RofiPadding){ { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, - { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; - wid->def_border = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; - wid->def_border_radius = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; - wid->def_margin = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + (RofiPadding){ { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + wid->def_border = + (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + wid->def_border_radius = + (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + wid->def_margin = + (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, + { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; wid->padding = rofi_theme_get_padding ( wid, "padding", wid->def_padding ); wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index ef84dd779..f63e82fab 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -225,7 +225,7 @@ static XrmOption xrmOptions[] = { "Modi that do not use a linbreak for {linebreak} in combi mode, but -combi-no-linebreak-str instead.", CONFIG_DEFAULT }, { xrm_String, "combi-no-linebreak-str", { .str = &config.combi_no_linebreak_str }, NULL, "String used instead of linebreak in the output formatting for -combi-no-linebreak-modi.", CONFIG_DEFAULT }, - { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, + { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, "Allow pango markup in combi mode entries.", CONFIG_DEFAULT }, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL, "Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT }, From ba441faf0dea5aa9d0298e0300d4289ef07fe5df Mon Sep 17 00:00:00 2001 From: jchtt Date: Mon, 11 May 2020 22:56:47 -0400 Subject: [PATCH 5/7] Revert "Fixed indent, second try" This reverts commit d3d2e843fefeb0a0da502c6c973875d132f3f461. --- include/rofi-types.h | 11 +-- include/theme.h | 1 + include/view.h | 1 + source/dialogs/combi.c | 84 +++++++++--------- source/dialogs/dmenu.c | 1 + source/dialogs/drun.c | 2 +- source/dialogs/script.c | 46 +++++----- source/rofi-icon-fetcher.c | 105 +++++++++++----------- source/rofi.c | 33 ++++--- source/theme.c | 177 ++++++++++++++++++------------------- source/widgets/listview.c | 25 +++--- source/widgets/textbox.c | 4 +- source/widgets/widget.c | 17 ++-- source/xrmoptions.c | 2 +- 14 files changed, 250 insertions(+), 259 deletions(-) diff --git a/include/rofi-types.h b/include/rofi-types.h index 9ae17ab36..ced7e321f 100644 --- a/include/rofi-types.h +++ b/include/rofi-types.h @@ -100,21 +100,22 @@ typedef enum ROFI_DISTANCE_MODIFIER_GROUP, } RofiDistanceModifier; -typedef struct RofiDistanceUnit +typedef struct RofiDistanceUnit { /** Distance */ - double distance; + double distance; /** Unit type of the distance */ - RofiPixelUnit type; + RofiPixelUnit type; /** Type */ - RofiDistanceModifier modtype; + RofiDistanceModifier modtype; /** Modifier */ struct RofiDistanceUnit *left; /** Modifier */ struct RofiDistanceUnit *right; + } RofiDistanceUnit; typedef struct @@ -122,7 +123,7 @@ typedef struct /** Base */ RofiDistanceUnit base; /** Style of the line (optional)*/ - RofiLineStyle style; + RofiLineStyle style; } RofiDistance; /** diff --git a/include/theme.h b/include/theme.h index 28dd09821..055bea710 100644 --- a/include/theme.h +++ b/include/theme.h @@ -249,6 +249,7 @@ double rofi_theme_get_double ( const widget *widget, const char *property, doub */ void rofi_theme_get_color ( const widget *widget, const char *property, cairo_t *d ); + /** * @param widget The widget to query * @param property The property to query. diff --git a/include/view.h b/include/view.h index f5deac96a..ba07f32e3 100644 --- a/include/view.h +++ b/include/view.h @@ -307,6 +307,7 @@ void rofi_capture_screenshot ( void ); */ void rofi_view_set_window_title ( const char * title ); + /** * set ellipsize mode to start. */ diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index bb0b197a4..0037fea2c 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -48,7 +48,7 @@ typedef struct { Mode *mode; gboolean disable; - gboolean print_newline; + gboolean print_newline; } CombiMode; typedef struct @@ -72,8 +72,8 @@ static void combi_mode_parse_switchers ( Mode *sw ) const char * const sep = ",#"; // Split token on ','. This modifies switcher_str. - GHashTable *ht; - ht = g_hash_table_new ( g_str_hash, g_str_equal ); + GHashTable *ht; + ht = g_hash_table_new ( g_str_hash, g_str_equal ); for ( char *token = strtok_r ( switcher_str, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { @@ -83,20 +83,20 @@ static void combi_mode_parse_switchers ( Mode *sw ) Mode *mode = rofi_collect_modi_search ( token ); if ( mode ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = mode; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); - /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = mode; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + /* g_hash_table_insert( ht, token, pd->switchers + pd->num_switchers ); */ } else { // If not build in, use custom switchers. Mode *sw = script_switcher_parse_setup ( token ); if ( sw != NULL ) { - pd->switchers[pd->num_switchers].disable = FALSE; - pd->switchers[pd->num_switchers].mode = sw; - pd->switchers[pd->num_switchers].print_newline = TRUE; - g_hash_table_insert ( ht, token, &( pd->switchers[pd->num_switchers++] ) ); + pd->switchers[pd->num_switchers].disable = FALSE; + pd->switchers[pd->num_switchers].mode = sw; + pd->switchers[pd->num_switchers].print_newline = TRUE; + g_hash_table_insert( ht, token, &( pd->switchers[pd->num_switchers++] ) ); } else { // Report error, don't continue. @@ -109,17 +109,17 @@ static void combi_mode_parse_switchers ( Mode *sw ) savept = NULL; for ( char *token = strtok_r ( config.combi_no_linebreak_modi, sep, &savept ); token != NULL; token = strtok_r ( NULL, sep, &savept ) ) { - CombiMode *mode = g_hash_table_lookup ( ht, token ); - if ( mode != NULL ) { - mode->print_newline = FALSE; - } - else { - g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); - } - } + CombiMode *mode = g_hash_table_lookup ( ht, token ); + if ( mode != NULL ) { + mode->print_newline = FALSE; + } + else { + g_warning ( "%s is in -combi-no-linebreak-modi but not in -combi-modi.", token ); + } + } // Free string that was modified by strtok_r g_free ( switcher_str ); - g_hash_table_destroy ( ht ); + g_hash_table_destroy( ht ); } static int combi_mode_init ( Mode *sw ) @@ -179,11 +179,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned CombiModePrivateData *pd = mode_get_private_data ( sw ); if ( input[0][0] == '!' ) { - int switcher = -1; + int switcher = -1; // Implement strchrnul behaviour. - char *eob = g_utf8_strchr ( input[0], -1, ' ' ); + char *eob = g_utf8_strchr ( input[0], -1,' ' ); if ( eob == NULL ) { - eob = &( input[0][strlen ( input[0] )] ); + eob = &(input[0][strlen(input[0])]); } ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1; if ( bang_len > 0 ) { @@ -208,11 +208,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned return mretv & MENU_LOWER_MASK; } - unsigned offset = 0; + unsigned offset = 0; for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - if ( pd->switchers[i].disable ) { - offset += pd->lengths[i]; - } + if ( pd->switchers[i].disable ) { + offset += pd->lengths[i]; + } if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { return mode_result ( pd->switchers[i].mode, mretv, input, selected_line - pd->starts[i] ); @@ -236,9 +236,9 @@ static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigne static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - if ( config.markup_combi ) { - *state |= MARKUP; - } + if (config.markup_combi) { + *state |= MARKUP; + } if ( !get_entry ) { for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { @@ -254,16 +254,16 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat char * str = retv = 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 ); if ( !config.combi_hide_mode_prefix ) { - char *dname_markup = g_markup_escape_text ( dname, -1 ); - char *opt_linebreak = g_strdup ( pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str ); - retv = helper_string_replace_if_exists ( config.combi_display_format, - "{mode}", dname_markup, - "{linebreak}", opt_linebreak, - "{element}", str, - NULL ); + char *dname_markup = g_markup_escape_text ( dname, -1 ); + char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str); + retv = helper_string_replace_if_exists( config.combi_display_format, + "{mode}", dname_markup, + "{linebreak}", opt_linebreak, + "{element}", str, + NULL ); g_free ( str ); - g_free ( dname_markup ); - g_free ( opt_linebreak ); + g_free ( dname_markup ); + g_free ( opt_linebreak ); } if ( attr_list != NULL ) { @@ -321,10 +321,10 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) } if ( input != NULL && input[0] == '!' ) { // Implement strchrnul behaviour. - const char *eob = g_utf8_strchr ( input, -1, ' ' ); + const char *eob = g_utf8_strchr ( input, -1, ' ' ); if ( eob == NULL ) { // Set it to end. - eob = &( input[strlen ( input )] ); + eob = &(input[strlen(input)]); } ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1; if ( bang_len > 0 ) { diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index d82299be7..5e9af2d4b 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -734,6 +734,7 @@ int dmenu_switcher_dialog ( void ) find_arg_str ( "-p", &( dmenu_mode.display_name ) ); RofiViewState *state = rofi_view_create ( &dmenu_mode, input, menu_flags, dmenu_finalize ); + if ( find_arg ( "-keep-right" ) >= 0 ) { rofi_view_ellipsize_start ( state ); } diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 67549bf94..afc19ba62 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -182,7 +182,7 @@ static gboolean drun_helper_eval_cb ( const GMatchInfo *info, GString *res, gpoi case 'm': break; case '%': - g_string_append ( res, "%" ); + g_string_append(res, "%"); break; case 'k': if ( e->e->path ) { diff --git a/source/dialogs/script.c b/source/dialogs/script.c index ab2a3f4a7..c7cc6d706 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -68,7 +68,7 @@ typedef struct char *message; char *prompt; gboolean do_markup; - char delim; + char delim; /** no custom */ gboolean no_custom; } ScriptModePrivateData; @@ -83,7 +83,7 @@ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry * length_key++; } // Should be not last character in buffer. - if ( ( length_key + 1 ) < ( length ) ) { + if ( (length_key+1) < (length) ) { buffer[length_key] = '\0'; char *value = buffer + length_key + 1; if ( strcasecmp ( buffer, "icon" ) == 0 ) { @@ -110,7 +110,7 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) length_key++; } - if ( ( length_key + 1 ) < length ) { + if ( (length_key+1) < length ) { line[length_key] = '\0'; char *value = line + length_key + 1; if ( strcasecmp ( line, "message" ) == 0 ) { @@ -133,30 +133,31 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) } else if ( strcasecmp ( line, "delim" ) == 0 ) { pd->delim = helper_parse_char ( value ); - } - else if ( strcasecmp ( line, "no-custom" ) == 0 ) { - pd->no_custom = ( strcasecmp ( value, "true" ) == 0 ); + } else if ( strcasecmp ( line, "no-custom" ) == 0 ) { + pd->no_custom = ( strcasecmp ( value, "true") == 0 ); } } } static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *length, int value ) { - ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; - int fd = -1; - GError *error = NULL; - DmenuScriptEntry *retv = NULL; - char **argv = NULL; - int argc = 0; + ScriptModePrivateData *pd = (ScriptModePrivateData *) sw->private_data; + int fd = -1; + GError *error = NULL; + DmenuScriptEntry *retv = NULL; + char **argv = NULL; + int argc = 0; *length = 0; + // Environment char ** env = g_get_environ (); - char *str_value = g_strdup_printf ( "%d", value ); - env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE ); + char *str_value = g_strdup_printf("%d", value); + env = g_environ_setenv ( env, "ROFI_RETV", str_value, TRUE); g_free ( str_value ); + if ( g_shell_parse_argv ( sw->ed, &argc, &argv, &error ) ) { argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); argv[argc] = g_strdup ( arg ); @@ -165,7 +166,7 @@ static DmenuScriptEntry *execute_executor ( Mode *sw, char *arg, unsigned int *l } g_strfreev ( env ); if ( error != NULL ) { - char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*) sw->ed, error->message ); + char *msg = g_strdup_printf ( "Failed to execute: '%s'\nError: '%s'", (char*)sw->ed, error->message ); rofi_view_error_dialog ( msg, FALSE ); g_free ( msg ); // print error. @@ -232,7 +233,7 @@ static int script_mode_init ( Mode *sw ) { if ( sw->private_data == NULL ) { ScriptModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) ); - pd->delim = '\n'; + pd->delim = '\n'; sw->private_data = (void *) pd; pd->cmd_list = execute_executor ( sw, NULL, &( pd->cmd_list_length ), 0 ); } @@ -273,13 +274,11 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned //retv = 1+( mretv & MENU_LOWER_MASK ); script_mode_reset_highlight ( sw ); if ( selected_line != UINT32_MAX ) { - new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); - } - else { + new_list = execute_executor ( sw, rmpd->cmd_list[selected_line].entry, &new_length,10+( mretv & MENU_LOWER_MASK ) ); + } else { if ( rmpd->no_custom == FALSE ) { - new_list = execute_executor ( sw, *input, &new_length, 10 + ( mretv & MENU_LOWER_MASK ) ); - } - else { + new_list = execute_executor ( sw, *input, &new_length,10+( mretv & MENU_LOWER_MASK ) ); + } else { return RELOAD_DIALOG; } } @@ -295,8 +294,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned if ( rmpd->no_custom == FALSE ) { script_mode_reset_highlight ( sw ); new_list = execute_executor ( sw, *input, &new_length, 2 ); - } - else { + } else { return RELOAD_DIALOG; } } diff --git a/source/rofi-icon-fetcher.c b/source/rofi-icon-fetcher.c index 33e52c061..7be6db145 100644 --- a/source/rofi-icon-fetcher.c +++ b/source/rofi-icon-fetcher.c @@ -133,66 +133,64 @@ void rofi_icon_fetcher_destroy ( void ) g_free ( rofi_icon_fetcher_data ); } -static cairo_surface_t* cairo_image_surface_create_from_jpeg_private ( struct jpeg_decompress_struct* cinfo ) -{ - cairo_surface_t* surface = 0; - unsigned char * data = 0; - unsigned char * rgb = 0; - jpeg_read_header ( cinfo, TRUE ); - jpeg_start_decompress ( cinfo ); - surface = cairo_image_surface_create ( CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height ); - data = cairo_image_surface_get_data ( surface ); - rgb = (unsigned char*) ( malloc ( cinfo->output_width * cinfo->output_components ) ); +static cairo_surface_t* cairo_image_surface_create_from_jpeg_private(struct jpeg_decompress_struct* cinfo) { + cairo_surface_t* surface = 0; + unsigned char* data = 0; + unsigned char* rgb = 0; - while ( cinfo->output_scanline < cinfo->output_height ) { - unsigned int i; - int scanline = cinfo->output_scanline * cairo_image_surface_get_stride ( surface ); + jpeg_read_header(cinfo, TRUE); + jpeg_start_decompress(cinfo); - jpeg_read_scanlines ( cinfo, &rgb, 1 ); + surface = cairo_image_surface_create(CAIRO_FORMAT_RGB24, cinfo->image_width, cinfo->image_height); + data = cairo_image_surface_get_data(surface); + rgb = (unsigned char*)(malloc(cinfo->output_width * cinfo->output_components)); - for ( i = 0; i < cinfo->output_width; i++ ) { - int offset = scanline + ( i * 4 ); + while(cinfo->output_scanline < cinfo->output_height) { + unsigned int i; + int scanline = cinfo->output_scanline * cairo_image_surface_get_stride(surface); - data[offset + 3] = 255; - data[offset + 2] = rgb[( i * 3 )]; - data[offset + 1] = rgb[( i * 3 ) + 1]; - data[offset ] = rgb[( i * 3 ) + 2]; - } - } + jpeg_read_scanlines(cinfo, &rgb, 1); + + for(i = 0; i < cinfo->output_width; i++) { + int offset = scanline + (i * 4); + + data[offset + 3] = 255; + data[offset + 2] = rgb[(i * 3)]; + data[offset + 1] = rgb[(i * 3) + 1]; + data[offset ] = rgb[(i * 3) + 2]; + } + } - free ( rgb ); + free(rgb); - jpeg_finish_decompress ( cinfo ); - jpeg_destroy_decompress ( cinfo ); + jpeg_finish_decompress(cinfo); + jpeg_destroy_decompress(cinfo); - cairo_surface_mark_dirty ( surface ); + cairo_surface_mark_dirty(surface); - return surface; + return surface; } -static cairo_surface_t* cairo_image_surface_create_from_jpeg ( const char* file ) -{ - struct jpeg_decompress_struct cinfo; - struct jpeg_error_mgr jerr; - cairo_surface_t * surface; - FILE * infile; +static cairo_surface_t* cairo_image_surface_create_from_jpeg(const char* file) { + struct jpeg_decompress_struct cinfo; + struct jpeg_error_mgr jerr; + cairo_surface_t* surface; + FILE* infile; - if ( ( infile = fopen ( file, "rb" ) ) == NULL ) { - return NULL; - } + if((infile = fopen(file, "rb")) == NULL) return NULL; - cinfo.err = jpeg_std_error ( &jerr ); + cinfo.err = jpeg_std_error(&jerr); - jpeg_create_decompress ( &cinfo ); - jpeg_stdio_src ( &cinfo, infile ); + jpeg_create_decompress(&cinfo); + jpeg_stdio_src(&cinfo, infile); - surface = cairo_image_surface_create_from_jpeg_private ( &cinfo ); + surface = cairo_image_surface_create_from_jpeg_private(&cinfo); - fclose ( infile ); + fclose(infile); - return surface; + return surface; } static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpointer user_data ) @@ -237,26 +235,29 @@ static void rofi_icon_fetcher_worker ( thread_state *sdata, G_GNUC_UNUSED gpoint } if ( icon_surf ) { if ( cairo_surface_status ( icon_surf ) == CAIRO_STATUS_SUCCESS ) { - float sw = sentry->size / (float) cairo_image_surface_get_width ( icon_surf ); - float sh = sentry->size / (float) cairo_image_surface_get_height ( icon_surf ); + float sw = sentry->size/(float)cairo_image_surface_get_width( icon_surf ); + float sh = sentry->size/(float)cairo_image_surface_get_height( icon_surf ); - float scale = ( sw > sh ) ? sh : sw; - if ( scale < 0.5 ) { - cairo_surface_t * surface = cairo_image_surface_create ( - cairo_image_surface_get_format ( icon_surf ), - cairo_image_surface_get_width ( icon_surf ) * scale, - cairo_image_surface_get_height ( icon_surf ) * scale ); + float scale = ( sw > sh)? sh:sw; + if ( scale < 0.5 ) + { + cairo_surface_t * surface = cairo_image_surface_create( + cairo_image_surface_get_format( icon_surf ), + cairo_image_surface_get_width( icon_surf )*scale, + cairo_image_surface_get_height( icon_surf )*scale); cairo_t *d = cairo_create ( surface ); cairo_scale ( d, scale, scale ); - cairo_set_source_surface ( d, icon_surf, 0.0, 0.0 ); - cairo_pattern_set_filter ( cairo_get_source ( d ), CAIRO_FILTER_FAST ); + cairo_set_source_surface ( d, icon_surf, 0.0,0.0); + cairo_pattern_set_filter (cairo_get_source (d), CAIRO_FILTER_FAST); cairo_paint ( d ); cairo_destroy ( d ); cairo_surface_destroy ( icon_surf ); icon_surf = surface; } + + } // check if surface is valid. if ( cairo_surface_status ( icon_surf ) != CAIRO_STATUS_SUCCESS ) { diff --git a/source/rofi.c b/source/rofi.c index e278c2780..b839109aa 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -193,10 +193,10 @@ static void run_switcher ( ModeMode mode ) RofiViewState * state = rofi_view_create ( modi[mode], config.filter, 0, process_result ); // User can pre-select a row. - if ( find_arg ( "-selected-row" ) >= 0 ) { - unsigned int sr = 0; - find_arg_uint ( "-selected-row", &( sr ) ); - rofi_view_set_selected_line ( state, sr ); + if ( find_arg ( "-selected-row" ) >= 0 ){ + unsigned int sr = 0; + find_arg_uint ( "-selected-row", &(sr) ); + rofi_view_set_selected_line ( state, sr ); } if ( state ) { rofi_view_set_active ( state ); @@ -512,7 +512,7 @@ static void rofi_collect_modi_dir ( const char *base_dir ) if ( !g_str_has_suffix ( dn, G_MODULE_SUFFIX ) ) { continue; } - char *fn = g_build_filename ( base_dir, dn, NULL ); + char *fn = g_build_filename ( base_dir, dn, NULL ); g_debug ( "Trying to open: %s plugin", fn ); GModule *mod = g_module_open ( fn, G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL ); if ( mod ) { @@ -565,7 +565,7 @@ static void rofi_collect_modi ( void ) g_debug ( "Parse plugin path: %s", config.plugin_path ); rofi_collect_modi_dir ( config.plugin_path ); /* ROFI_PLUGIN_PATH */ - const char *path = g_getenv ( "ROFI_PLUGIN_PATH" ); + const char *path = g_getenv("ROFI_PLUGIN_PATH"); if ( path != NULL ) { gchar ** paths = g_strsplit ( path, ":", -1 ); for ( unsigned int i = 0; paths[i]; i++ ) { @@ -869,41 +869,40 @@ int main ( int argc, char *argv[] ) if ( find_arg ( "-no-config" ) < 0 ) { // Load distro default settings - gboolean found_system = FALSE; - const char * const * dirs = g_get_system_config_dirs (); - if ( dirs ) { - for ( unsigned int i = 0; !found_system && dirs[i]; i++ ) { + gboolean found_system = FALSE; + const char * const * dirs = g_get_system_config_dirs(); + if ( dirs ) + { + for ( unsigned int i =0; !found_system && dirs[i]; i++ ) { /** New format. */ gchar *etc = g_build_filename ( dirs[i], "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Parsing: %s", etc ); rofi_theme_parse_file ( etc ); - found_system = TRUE; - } - else { + found_system = TRUE; + } else { /** Old format. */ gchar *xetc = g_build_filename ( dirs[i], "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) { config_parse_xresource_options_file ( xetc ); old_config_format = TRUE; - found_system = TRUE; + found_system = TRUE; } g_free ( xetc ); } g_free ( etc ); } } - if ( !found_system ) { + if ( ! found_system ) { /** New format. */ gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL ); g_debug ( "Look for default config file: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { g_debug ( "Look for default config file: %s", etc ); rofi_theme_parse_file ( etc ); - } - else { + } else { /** Old format. */ gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL ); g_debug ( "Look for default config file: %s", xetc ); diff --git a/source/theme.c b/source/theme.c index 78137c979..85bf7c866 100644 --- a/source/theme.c +++ b/source/theme.c @@ -84,23 +84,25 @@ Property *rofi_theme_property_create ( PropertyType type ) static RofiDistanceUnit *rofi_theme_property_copy_distance_unit ( RofiDistanceUnit *unit ) { - RofiDistanceUnit *retv = g_slice_new0 ( RofiDistanceUnit ); - *retv = *unit; + RofiDistanceUnit *retv = g_slice_new0( RofiDistanceUnit ); + *retv = *unit; if ( unit->left ) { - retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); + retv->left = rofi_theme_property_copy_distance_unit ( unit->left ); } if ( unit->right ) { - retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); + retv->right = rofi_theme_property_copy_distance_unit ( unit->right ); } return retv; } RofiDistance rofi_theme_property_copy_distance ( RofiDistance const distance ) { RofiDistance retv = distance; - if ( distance.base.left ) { + if ( distance.base.left ) + { retv.base.left = rofi_theme_property_copy_distance_unit ( distance.base.left ); } - if ( distance.base.right ) { + if ( distance.base.right ) + { retv.base.right = rofi_theme_property_copy_distance_unit ( distance.base.right ); } return retv; @@ -127,14 +129,14 @@ Property* rofi_theme_property_copy ( Property *p ) } break; case P_PADDING: - { - retv->value = p->value; - retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top ); - retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left ); - retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom ); - retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right ); - break; - } + { + retv->value = p->value; + retv->value.padding.top = rofi_theme_property_copy_distance ( p->value.padding.top); + retv->value.padding.left = rofi_theme_property_copy_distance ( p->value.padding.left); + retv->value.padding.bottom = rofi_theme_property_copy_distance ( p->value.padding.bottom); + retv->value.padding.right = rofi_theme_property_copy_distance ( p->value.padding.right); + break; + } default: retv->value = p->value; } @@ -151,7 +153,7 @@ static void rofi_theme_distance_unit_property_free ( RofiDistanceUnit *unit ) rofi_theme_distance_unit_property_free ( unit->right ); unit->right = NULL; } - g_slice_free ( RofiDistanceUnit, unit ); + g_slice_free ( RofiDistanceUnit, unit); } static void rofi_theme_distance_property_free ( RofiDistance *distance ) { @@ -180,11 +182,11 @@ void rofi_theme_property_free ( Property *p ) rofi_theme_property_free ( p->value.link.def_value ); } } - if ( p->type == P_PADDING ) { - rofi_theme_distance_property_free ( &( p->value.padding.top ) ); - rofi_theme_distance_property_free ( &( p->value.padding.right ) ); - rofi_theme_distance_property_free ( &( p->value.padding.bottom ) ); - rofi_theme_distance_property_free ( &( p->value.padding.left ) ); + if ( p->type == P_PADDING) { + rofi_theme_distance_property_free( &(p->value.padding.top)); + rofi_theme_distance_property_free( &(p->value.padding.right)); + rofi_theme_distance_property_free( &(p->value.padding.bottom)); + rofi_theme_distance_property_free( &(p->value.padding.left)); } g_slice_free ( Property, p ); } @@ -214,7 +216,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) rofi_theme_widget_add_properties ( tt, table ); - RofiDistance dsize = (RofiDistance){ .base = { 1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + RofiDistance dsize = (RofiDistance){ .base = {1.2, ROFI_PU_CH, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; Property *pts = rofi_theme_property_create ( P_PADDING ); pts->value.padding.top = pts->value.padding.right = pts->value.padding.bottom = pts->value.padding.left = dsize; pts->name = g_strdup ( "size" ); @@ -227,7 +229,7 @@ static void rofi_theme_insert_listview_backwards_fix ( void ) table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); Property *psp = rofi_theme_property_create ( P_PADDING ); psp->name = g_strdup ( "spacing" ); - RofiDistance d = (RofiDistance){ .base = { 5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = {5, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; psp->value.padding = (RofiPadding){ d, d, d, d }; g_hash_table_replace ( table, psp->name, psp ); rofi_theme_widget_add_properties ( t, table ); @@ -275,33 +277,27 @@ inline static void printf_double ( double d ) static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) { - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( "( ", stdout ); - } - if ( unit->left ) { + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) + fputs("( " , stdout); + if ( unit->left ) rofi_theme_print_distance_unit ( unit->left ); - } if ( unit->modtype == ROFI_DISTANCE_MODIFIER_ADD ) { fputs ( " + ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_SUBTRACT ) { fputs ( " - ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_DIVIDE ) { fputs ( " / ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MULTIPLY) { fputs ( " * ", stdout ); - } - else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO ) { + } else if ( unit->modtype == ROFI_DISTANCE_MODIFIER_MODULO) { fputs ( " % ", stdout ); - } - if ( unit->right ) { + } + if ( unit->right ) rofi_theme_print_distance_unit ( unit->right ); - } - - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) { + + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_NONE ) + { if ( unit->type == ROFI_PU_PX ) { printf ( "%upx ", (unsigned int) unit->distance ); } @@ -318,19 +314,18 @@ static void rofi_theme_print_distance_unit ( RofiDistanceUnit *unit ) fputs ( "em ", stdout ); } } - if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( " )", stdout ); - } + if ( unit->modtype == ROFI_DISTANCE_MODIFIER_GROUP ) + fputs(" )" , stdout); } static void rofi_theme_print_distance ( RofiDistance d ) { - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( "calc( ", stdout ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ + fputs( "calc( ", stdout ); } - rofi_theme_print_distance_unit ( &( d.base ) ); - if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ) { - fputs ( ")", stdout ); + rofi_theme_print_distance_unit ( &(d.base) ); + if ( d.base.modtype == ROFI_DISTANCE_MODIFIER_GROUP ){ + fputs( ")", stdout ); } if ( d.style == ROFI_HL_DASH ) { printf ( "dash " ); @@ -747,17 +742,17 @@ RofiDistance rofi_theme_get_distance ( const widget *widget, const char *propert if ( widget->parent ) { return rofi_theme_get_distance ( widget->parent, property, def ); } - return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; } if ( p->type == P_INTEGER ) { - return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; } else { return p->value.padding.left; } } g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); - return (RofiDistance){ .base = { def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + return (RofiDistance){ .base = {def, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; } int rofi_theme_get_boolean ( const widget *widget, const char *property, int def ) @@ -873,7 +868,7 @@ RofiPadding rofi_theme_get_padding ( const widget *widget, const char *property, pad = p->value.padding; } else { - RofiDistance d = (RofiDistance){ .base = { p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, .style = ROFI_HL_SOLID }; + RofiDistance d = (RofiDistance){ .base = {p->value.i, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, .style = ROFI_HL_SOLID }; return (RofiPadding){ d, d, d, d }; } } @@ -928,6 +923,7 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) { int val = unit->distance; + if ( unit->type == ROFI_PU_EM ) { val = unit->distance * textbox_get_estimated_char_height (); } @@ -949,46 +945,48 @@ static int get_pixels ( RofiDistanceUnit *unit, RofiOrientation ori ) return val; } + static int distance_unit_get_pixel ( RofiDistanceUnit *unit, RofiOrientation ori ) { - switch ( unit->modtype ) + switch ( unit->modtype) { - case ROFI_DISTANCE_MODIFIER_GROUP: - return distance_unit_get_pixel ( unit->left, ori ); - break; - case ROFI_DISTANCE_MODIFIER_ADD: - return distance_unit_get_pixel ( unit->left, ori ) + distance_unit_get_pixel ( unit->right, ori ); - case ROFI_DISTANCE_MODIFIER_SUBTRACT: - return distance_unit_get_pixel ( unit->left, ori ) - distance_unit_get_pixel ( unit->right, ori ); - case ROFI_DISTANCE_MODIFIER_MULTIPLY: - return distance_unit_get_pixel ( unit->left, ori ) * distance_unit_get_pixel ( unit->right, ori ); - case ROFI_DISTANCE_MODIFIER_DIVIDE: - { - int a = distance_unit_get_pixel ( unit->left, ori ); - int b = distance_unit_get_pixel ( unit->right, ori ); - if ( b != 0 ) { - return a / b; - } - return a; - } - case ROFI_DISTANCE_MODIFIER_MODULO: - { - int a = distance_unit_get_pixel ( unit->left, ori ); - int b = distance_unit_get_pixel ( unit->right, ori ); - if ( b != 0 ) { - return a % b; - } - return 0; - } - default: - break; + case ROFI_DISTANCE_MODIFIER_GROUP: + return distance_unit_get_pixel ( unit->left, ori ); + break; + case ROFI_DISTANCE_MODIFIER_ADD: + return distance_unit_get_pixel ( unit->left, ori)+ distance_unit_get_pixel ( unit->right, ori); + case ROFI_DISTANCE_MODIFIER_SUBTRACT: + return distance_unit_get_pixel ( unit->left, ori)- distance_unit_get_pixel ( unit->right, ori); + case ROFI_DISTANCE_MODIFIER_MULTIPLY: + return distance_unit_get_pixel ( unit->left, ori)* distance_unit_get_pixel ( unit->right, ori); + case ROFI_DISTANCE_MODIFIER_DIVIDE: + { + int a = distance_unit_get_pixel ( unit->left, ori); + int b = distance_unit_get_pixel ( unit->right, ori); + if ( b != 0 ) { + return a/b; + } + return a; + } + case ROFI_DISTANCE_MODIFIER_MODULO: + { + int a = distance_unit_get_pixel ( unit->left, ori); + int b = distance_unit_get_pixel ( unit->right, ori); + if ( b != 0 ) { + return a%b; + } + return 0; + } + default: + break; } return get_pixels ( unit, ori ); } + int distance_get_pixel ( RofiDistance d, RofiOrientation ori ) { - return distance_unit_get_pixel ( &( d.base ), ori ); + return distance_unit_get_pixel ( &(d.base), ori); } void distance_get_linestyle ( RofiDistance d, cairo_t *draw ) @@ -1011,13 +1009,13 @@ gboolean rofi_theme_is_empty ( void ) return TRUE; } if ( rofi_theme->num_widgets == 3 ) { - // HACK: check for default added elements. - for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) { - if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7 ) != 0 ) { - return FALSE; - } + // HACK: check for default added elements. + for ( unsigned int i = 0; i < rofi_theme->num_widgets;i++) { + if ( strncmp ( rofi_theme->widgets[i]->name, "element", 7) != 0 ){ + return FALSE; } - return TRUE; + } + return TRUE; } return FALSE; @@ -1314,6 +1312,7 @@ ThemeMediaType rofi_theme_parse_media_type ( const char *type ) return THEME_MEDIA_TYPE_INVALID; } + gboolean rofi_theme_has_property ( const widget *widget, const char *property ) { ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 0397b43ff..81f346780 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -45,10 +45,10 @@ /** * Orientation of the listview */ -/** Vertical (classical) list */ -#define LISTVIEW ROFI_ORIENTATION_VERTICAL -/** Horizontal list. (barview) */ -#define BARVIEW ROFI_ORIENTATION_HORIZONTAL + /** Vertical (classical) list */ +#define LISTVIEW ROFI_ORIENTATION_VERTICAL + /** Horizontal list. (barview) */ +#define BARVIEW ROFI_ORIENTATION_HORIZONTAL /** * The moving direction of the selection, this (in barview) affects the scrolling. @@ -69,7 +69,7 @@ typedef struct struct _listview { - widget widget; + widget widget; RofiOrientation type; @@ -553,8 +553,8 @@ static void listview_resize ( widget *wid, short w, short h ) lv->max_elements = lv->max_rows * lv->menu_columns; widget_move ( WIDGET ( lv->scrollbar ), - lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), - widget_padding_get_top ( WIDGET ( lv ) ) ); + lv->widget.w - widget_padding_get_right ( WIDGET ( lv ) ) - widget_get_width ( WIDGET ( lv->scrollbar ) ), + widget_padding_get_top ( WIDGET ( lv ) ) ); widget_resize ( WIDGET ( lv->scrollbar ), widget_get_width ( WIDGET ( lv->scrollbar ) ), height ); @@ -661,13 +661,10 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca listview_create_row ( lv, &row ); // FIXME: hack to scale hight correctly. if ( lv->eh > 1 && row.textbox ) { - char buff[lv->eh * 2 + 1]; - memset ( buff, '\0', lv->eh * 2 + 1 ); - for ( unsigned int i = 0; i < ( lv->eh - 1 ); i++ ) { - buff[i * 2] = 'a'; buff[i * 2 + 1] = '\n'; - } - ; - textbox_text ( row.textbox, buff ); + char buff[lv->eh*2+1] ; + memset( buff, '\0', lv->eh*2+1); + for ( unsigned int i = 0; i < (lv->eh-1); i++) { buff[i*2] = 'a'; buff[i*2+1] ='\n'; }; + textbox_text( row.textbox, buff); } lv->element_height = widget_get_desired_height ( WIDGET ( row.box ) ); widget_free ( WIDGET ( row.box ) ); diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index ca4f415e1..482d10377 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -276,7 +276,7 @@ static void __textbox_update_pango_text ( textbox *tb ) tb->show_placeholder = FALSE; if ( ( tb->flags & TB_PASSWORD ) == TB_PASSWORD ) { size_t l = g_utf8_strlen ( tb->text, -1 ); - char string[l + 1]; + char string [l + 1]; memset ( string, '*', l ); string[l] = '\0'; pango_layout_set_text ( tb->layout, string, l ); @@ -911,7 +911,7 @@ double textbox_get_estimated_ch ( void ) int textbox_get_estimated_height ( const textbox *tb, int eh ) { int height = pango_font_metrics_get_ascent ( tb->metrics ) + pango_font_metrics_get_descent ( tb->metrics ); - return ceil ( ( eh * height ) / (double) PANGO_SCALE ) + widget_padding_get_padding_height ( WIDGET ( tb ) ); + return ceil(( eh * height ) / (double)PANGO_SCALE) + widget_padding_get_padding_height ( WIDGET ( tb ) ); } int textbox_get_desired_width ( widget *wid ) { diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 517b7f5b9..c0e898596 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -40,18 +40,11 @@ void widget_init ( widget *wid, widget *parent, WidgetType type, const char *nam wid->parent = parent; wid->name = g_strdup ( name ); wid->def_padding = - (RofiPadding){ { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; - wid->def_border = - (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; - wid->def_border_radius = - (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; - wid->def_margin = - (RofiPadding){ { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, - { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID }, { { 0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL }, ROFI_HL_SOLID } }; + (RofiPadding){ { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, + { {WIDGET_DEFAULT_PADDING, ROFI_PU_PX,ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + wid->def_border = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + wid->def_border_radius = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; + wid->def_margin = (RofiPadding){ { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL} , ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID }, { {0, ROFI_PU_PX, ROFI_DISTANCE_MODIFIER_NONE, NULL, NULL}, ROFI_HL_SOLID } }; wid->padding = rofi_theme_get_padding ( wid, "padding", wid->def_padding ); wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index f63e82fab..ef84dd779 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -225,7 +225,7 @@ static XrmOption xrmOptions[] = { "Modi that do not use a linbreak for {linebreak} in combi mode, but -combi-no-linebreak-str instead.", CONFIG_DEFAULT }, { xrm_String, "combi-no-linebreak-str", { .str = &config.combi_no_linebreak_str }, NULL, "String used instead of linebreak in the output formatting for -combi-no-linebreak-modi.", CONFIG_DEFAULT }, - { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, + { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, "Allow pango markup in combi mode entries.", CONFIG_DEFAULT }, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL, "Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT }, From b635c770ab6c48b13e9858e558ccdf856895aed1 Mon Sep 17 00:00:00 2001 From: jchtt Date: Tue, 12 May 2020 21:31:56 -0400 Subject: [PATCH 6/7] Added escaping for non-markup modes --- source/dialogs/combi.c | 20 ++++++++++++++++---- test/run_combi_mode_format.sh | 4 ++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 0037fea2c..7f2ed58c5 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -236,9 +236,6 @@ static int combi_mode_match ( const Mode *sw, rofi_int_matcher **tokens, unsigne static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *state, GList **attr_list, int get_entry ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - if (config.markup_combi) { - *state |= MARKUP; - } if ( !get_entry ) { for ( unsigned i = 0; i < pd->num_switchers; i++ ) { if ( selected_line >= pd->starts[i] && selected_line < ( pd->starts[i] + pd->lengths[i] ) ) { @@ -253,10 +250,24 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat char * retv; char * str = retv = 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 *format_str = g_strdup( config.combi_display_format ); if ( !config.combi_hide_mode_prefix ) { + if ( !(*state & MARKUP) && config.markup_combi ) { + // Mode does not use markup, but we want to, so escape output + char * tmp_str = g_markup_escape_text( str, -1 ); + g_free(str); + str = tmp_str; + *state |= MARKUP; + } + if ( (*state & MARKUP) && !config.markup_combi ) { + // Mode does use markup, but we did not want to, so escape pattern string + char * tmp_str = g_markup_escape_text( format_str, -1 ); + g_free(format_str); + format_str = tmp_str; + } char *dname_markup = g_markup_escape_text ( dname, -1 ); char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str); - retv = helper_string_replace_if_exists( config.combi_display_format, + retv = helper_string_replace_if_exists( format_str, "{mode}", dname_markup, "{linebreak}", opt_linebreak, "{element}", str, @@ -264,6 +275,7 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat g_free ( str ); g_free ( dname_markup ); g_free ( opt_linebreak ); + g_free ( format_str ); } if ( attr_list != NULL ) { diff --git a/test/run_combi_mode_format.sh b/test/run_combi_mode_format.sh index e83a2c7df..641f073b7 100755 --- a/test/run_combi_mode_format.sh +++ b/test/run_combi_mode_format.sh @@ -2,5 +2,5 @@ rofi -show combi -combi-modi "window,drun" -eh 2 \ -drun-display-format "[({generic})]"$'\n'"{name}" \ -combi-display-format "[[{mode}]]{linebreak}{element}" \ -combi-no-linebreak-str " " \ - -markup-combi 1 \ - -combi-no-linebreak-modi "drun" + -combi-no-linebreak-modi "drun" \ + -markup-combi 1 From dd1306d01a1c2799467d0d2fcd88bb2b612047e9 Mon Sep 17 00:00:00 2001 From: jchtt Date: Wed, 13 May 2020 08:41:19 -0400 Subject: [PATCH 7/7] Always use pango markup in combi mode. --- config/config.c | 1 - include/settings.h | 3 +-- source/dialogs/combi.c | 8 +------- source/xrmoptions.c | 2 -- test/run_combi_mode_format.sh | 4 +++- 5 files changed, 5 insertions(+), 13 deletions(-) diff --git a/config/config.c b/config/config.c index c21ced7b4..cd7ebb5ee 100644 --- a/config/config.c +++ b/config/config.c @@ -159,7 +159,6 @@ Settings config = { .combi_display_format = "{mode} {element}", .combi_no_linebreak_modi = "", .combi_no_linebreak_str = " ", - .markup_combi = FALSE, .matching_negate_char = '-', diff --git a/include/settings.h b/include/settings.h index 75e941a32..d1816190b 100644 --- a/include/settings.h +++ b/include/settings.h @@ -184,11 +184,10 @@ typedef struct /** Maximum history length per mode. */ unsigned int max_history_size; gboolean combi_hide_mode_prefix; - /** Combi mode show */ + /** Combi mode formatting */ char * combi_display_format; char * combi_no_linebreak_modi; char * combi_no_linebreak_str; - gboolean markup_combi; char matching_negate_char; diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 7f2ed58c5..fff4d9e62 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -252,19 +252,13 @@ static char * combi_mgrv ( const Mode *sw, unsigned int selected_line, int *stat const char *dname = mode_get_display_name ( pd->switchers[i].mode ); char *format_str = g_strdup( config.combi_display_format ); if ( !config.combi_hide_mode_prefix ) { - if ( !(*state & MARKUP) && config.markup_combi ) { + if ( ! ( *state & MARKUP ) ) { // Mode does not use markup, but we want to, so escape output char * tmp_str = g_markup_escape_text( str, -1 ); g_free(str); str = tmp_str; *state |= MARKUP; } - if ( (*state & MARKUP) && !config.markup_combi ) { - // Mode does use markup, but we did not want to, so escape pattern string - char * tmp_str = g_markup_escape_text( format_str, -1 ); - g_free(format_str); - format_str = tmp_str; - } char *dname_markup = g_markup_escape_text ( dname, -1 ); char *opt_linebreak = g_strdup(pd->switchers[i].print_newline ? "\n" : config.combi_no_linebreak_str); retv = helper_string_replace_if_exists( format_str, diff --git a/source/xrmoptions.c b/source/xrmoptions.c index ef84dd779..6f430ea9e 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -225,8 +225,6 @@ static XrmOption xrmOptions[] = { "Modi that do not use a linbreak for {linebreak} in combi mode, but -combi-no-linebreak-str instead.", CONFIG_DEFAULT }, { xrm_String, "combi-no-linebreak-str", { .str = &config.combi_no_linebreak_str }, NULL, "String used instead of linebreak in the output formatting for -combi-no-linebreak-modi.", CONFIG_DEFAULT }, - { xrm_Boolean, "markup-combi", { .str = &config.markup_combi }, NULL, - "Allow pango markup in combi mode entries.", CONFIG_DEFAULT }, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL, "Set the character used to negate the matching. ('\\0' to disable)", CONFIG_DEFAULT }, { xrm_String, "cache-dir", { .str = &config.cache_dir }, NULL, diff --git a/test/run_combi_mode_format.sh b/test/run_combi_mode_format.sh index 641f073b7..062eb4306 100755 --- a/test/run_combi_mode_format.sh +++ b/test/run_combi_mode_format.sh @@ -1,4 +1,6 @@ -rofi -show combi -combi-modi "window,drun" -eh 2 \ +rofi -show combi \ + -modi "test:./test_script.sh" \ + -combi-modi "test,window,drun" -eh 2 \ -drun-display-format "[({generic})]"$'\n'"{name}" \ -combi-display-format "[[{mode}]]{linebreak}{element}" \ -combi-no-linebreak-str " " \