From e60ad9206c30573eba5af7c8c30ddda8d178ed0b Mon Sep 17 00:00:00 2001 From: jchtt Date: Sun, 10 May 2020 19:45:40 -0400 Subject: [PATCH 1/7] Implemented bang anywhere option for combi mode --- config/config.c | 2 + include/settings.h | 2 + source/dialogs/combi.c | 135 +++++++++++++++++++++++++++-------------- source/dialogs/drun.c | 3 + source/xrmoptions.c | 4 +- 5 files changed, 98 insertions(+), 48 deletions(-) diff --git a/config/config.c b/config/config.c index 62adab5dc..2bc0a4226 100644 --- a/config/config.c +++ b/config/config.c @@ -155,6 +155,8 @@ Settings config = { .plugin_path = PLUGIN_PATH, .max_history_size = 25, .combi_hide_mode_prefix = FALSE, + /** Combi bang anywhere */ + .combi_bang_anywhere = FALSE, .matching_negate_char = '-', diff --git a/include/settings.h b/include/settings.h index b1f35e33d..6c6aa09c2 100644 --- a/include/settings.h +++ b/include/settings.h @@ -184,6 +184,8 @@ typedef struct /** Maximum history length per mode. */ unsigned int max_history_size; gboolean combi_hide_mode_prefix; + /** Combi mode bang anywhere */ + gboolean combi_bang_anywhere; char matching_negate_char; diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 691afce9f..636174832 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -150,41 +150,87 @@ static void combi_mode_destroy ( Mode *sw ) mode_set_private_data ( sw, NULL ); } } + +static void split_bang( const char *input, char **bang, char **rest ) { + // Splits string input into a part containing the bang and the part containing the rest, + // saved in the pointers bang and rest. + if ( input != NULL) { + char *sob = g_utf8_strchr ( input, -1, '!' ); + char *prev_char = g_utf8_find_prev_char( input, sob ); + + if (sob != NULL && (prev_char == NULL || ( config.combi_bang_anywhere && prev_char[0] == ' ' ))) { + glong sob_offset = g_utf8_pointer_to_offset( input, sob ); + const char *eob = g_utf8_strchr ( sob, -1, ' ' ); + if ( eob == NULL ) { + // Set it to end. + eob = &(input[strlen(input)]); + } + ssize_t bang_len = g_utf8_pointer_to_offset ( sob, eob ); + + if ( bang_len > 1 ) { + *bang = g_utf8_substring( input, sob_offset + 1, sob_offset + bang_len ); + + char *head = g_utf8_substring ( input, 0, ( eob[0] != ' ' && prev_char != NULL) ? sob_offset - 1 : sob_offset ); + const char *tail = ( eob[0] == ' ' ) ? g_utf8_next_char( eob ) : eob; + *rest = g_strdup_printf ( "%s%s", head, tail ); + g_free(head); + return; + } + } + } + *bang = g_strdup(""); + *rest = g_strdup(input); + return; +} + static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - if ( input[0][0] == '!' ) { - int switcher = -1; - // Implement strchrnul behaviour. - char *eob = g_utf8_strchr ( input[0], -1,' ' ); - if ( eob == NULL ) { - eob = &(input[0][strlen(input[0])]); - } - ssize_t bang_len = g_utf8_pointer_to_offset ( input[0], eob ) - 1; - if ( bang_len > 0 ) { - for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) { - const char *mode_name = mode_get_name ( pd->switchers[i].mode ); - size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); - if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( &input[0][1], mode_name, bang_len ) == 0 ) { - switcher = i; - } - } - } + gboolean return_from_fun = FALSE; + ModeMode retv; + char *bang; + char *rest; + split_bang(*input, &bang, &rest); + + ssize_t bang_len = strlen(bang); + if ( bang_len > 0 ) { + int switcher = -1; + for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) { + const char *mode_name = mode_get_name ( pd->switchers[i].mode ); + size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); + if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) { + switcher = i; + } + } if ( switcher >= 0 ) { - if ( eob[0] == ' ' ) { - char *n = eob + 1; - return mode_result ( pd->switchers[switcher].mode, mretv, &n, + if ( strlen( rest ) > 0) { + retv = mode_result ( pd->switchers[switcher].mode, mretv, &rest, selected_line - pd->starts[switcher] ); + return_from_fun = TRUE; } - return MODE_EXIT; + else { + retv = MODE_EXIT; + return_from_fun = TRUE; + } } - } + } + + g_free( bang ); + g_free( rest ); + if ( return_from_fun ) { + return retv; + } + if ( mretv & MENU_QUICK_SWITCH ) { 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] ); @@ -274,36 +320,33 @@ static cairo_surface_t * combi_get_icon ( const Mode *sw, unsigned int index, in return NULL; } + static char * combi_preprocess_input ( Mode *sw, const char *input ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); for ( unsigned i = 0; i < pd->num_switchers; i++ ) { pd->switchers[i].disable = FALSE; } - if ( input != NULL && input[0] == '!' ) { - // Implement strchrnul behaviour. - const char *eob = g_utf8_strchr ( input, -1, ' ' ); - if ( eob == NULL ) { - // Set it to end. - eob = &(input[strlen(input)]); - } - ssize_t bang_len = g_utf8_pointer_to_offset ( input, eob ) - 1; - if ( bang_len > 0 ) { - for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - const char *mode_name = mode_get_name ( pd->switchers[i].mode ); - size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); - if ( !( (size_t) bang_len <= mode_name_len && utf8_strncmp ( &input[1], mode_name, bang_len ) == 0 ) ) { - // No match. - pd->switchers[i].disable = TRUE; - } - } - if ( eob[0] == '\0' || eob[1] == '\0' ) { - return NULL; - } - return g_strdup ( eob + 1 ); - } - } - return g_strdup ( input ); + + char *bang; + char *rest; + split_bang(input, &bang, &rest); + /* printf("split_bang: %s; %s;\n", bang, rest); */ + + + ssize_t bang_len = strlen(bang); + if ( strlen(bang) > 0 ) { + for ( unsigned i = 0; i < pd->num_switchers; i++ ) { + const char *mode_name = mode_get_name ( pd->switchers[i].mode ); + size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); + if ( !( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) ) { + // No match. + pd->switchers[i].disable = TRUE; + } + } + } + g_free(bang); + return rest; } Mode combi_mode = diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index afc19ba62..94b92bd5a 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -1022,7 +1022,9 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in char *en = NULL; char *ec = NULL; if ( dr->generic_name ) { + /* printf("%s\n", dr->generic_name); */ egn = g_markup_escape_text ( dr->generic_name, -1 ); + /* printf("%s\n", egn); */ } if ( dr->name ) { en = g_markup_escape_text ( dr->name, -1 ); @@ -1039,6 +1041,7 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in "{categories}", cats, "{keywords}", keywords, NULL ); + printf("%s\n", retv); g_free ( egn ); g_free ( en ); g_free ( ec ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 13058262b..5d9f45351 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -217,8 +217,8 @@ static XrmOption xrmOptions[] = { "Color scheme window", CONFIG_DEFAULT }, { xrm_Number, "max-history-size", { .num = &config.max_history_size }, NULL, "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_Boolean, "combi-bang-anywhere", { .snum = &config.combi_bang_anywhere }, NULL, + "Allow bang (!) to be used anywhere in the string if it occurs after a space character.", 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, From 0a3e72054e649a170cffee5111cbb13ec7114219 Mon Sep 17 00:00:00 2001 From: jchtt Date: Sun, 10 May 2020 19:53:04 -0400 Subject: [PATCH 2/7] Clean up --- source/dialogs/combi.c | 2 -- source/dialogs/drun.c | 3 --- source/xrmoptions.c | 2 ++ 3 files changed, 2 insertions(+), 5 deletions(-) diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 636174832..41816ba60 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -331,8 +331,6 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) char *bang; char *rest; split_bang(input, &bang, &rest); - /* printf("split_bang: %s; %s;\n", bang, rest); */ - ssize_t bang_len = strlen(bang); if ( strlen(bang) > 0 ) { diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 94b92bd5a..afc19ba62 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -1022,9 +1022,7 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in char *en = NULL; char *ec = NULL; if ( dr->generic_name ) { - /* printf("%s\n", dr->generic_name); */ egn = g_markup_escape_text ( dr->generic_name, -1 ); - /* printf("%s\n", egn); */ } if ( dr->name ) { en = g_markup_escape_text ( dr->name, -1 ); @@ -1041,7 +1039,6 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in "{categories}", cats, "{keywords}", keywords, NULL ); - printf("%s\n", retv); g_free ( egn ); g_free ( en ); g_free ( ec ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 5d9f45351..26c028191 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -217,6 +217,8 @@ static XrmOption xrmOptions[] = { "Color scheme window", CONFIG_DEFAULT }, { xrm_Number, "max-history-size", { .num = &config.max_history_size }, NULL, "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_Boolean, "combi-bang-anywhere", { .snum = &config.combi_bang_anywhere }, NULL, "Allow bang (!) to be used anywhere in the string if it occurs after a space character.", CONFIG_DEFAULT }, { xrm_Char, "matching-negate-char", { .charc = &config.matching_negate_char }, NULL, From ea0d52e5aa90b21fa978cb8c7d836f4bd2fdb8b7 Mon Sep 17 00:00:00 2001 From: jchtt Date: Mon, 11 May 2020 22:46:35 -0400 Subject: [PATCH 3/7] Fixed indent --- config/config.c | 32 +++---- data/uncrustify.cfg | 2 +- include/rofi-types.h | 11 ++- include/theme.h | 1 - include/view.h | 1 - source/dialogs/combi.c | 148 +++++++++++++++---------------- 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, 312 insertions(+), 303 deletions(-) diff --git a/config/config.c b/config/config.c index 2bc0a4226..8344349e7 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,10 +153,10 @@ 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 bang anywhere */ - .combi_bang_anywhere = FALSE, + .combi_bang_anywhere = FALSE, .matching_negate_char = '-', 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 41816ba60..e10f47340 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -151,86 +151,87 @@ static void combi_mode_destroy ( Mode *sw ) } } -static void split_bang( const char *input, char **bang, char **rest ) { - // Splits string input into a part containing the bang and the part containing the rest, - // saved in the pointers bang and rest. - if ( input != NULL) { - char *sob = g_utf8_strchr ( input, -1, '!' ); - char *prev_char = g_utf8_find_prev_char( input, sob ); +static void split_bang ( const char *input, char **bang, char **rest ) +{ + // Splits string input into a part containing the bang and the part containing the rest, + // saved in the pointers bang and rest. + if ( input != NULL ) { + char *sob = g_utf8_strchr ( input, -1, '!' ); + char *prev_char = g_utf8_find_prev_char ( input, sob ); - if (sob != NULL && (prev_char == NULL || ( config.combi_bang_anywhere && prev_char[0] == ' ' ))) { - glong sob_offset = g_utf8_pointer_to_offset( input, sob ); - const char *eob = g_utf8_strchr ( sob, -1, ' ' ); - if ( eob == NULL ) { - // Set it to end. - eob = &(input[strlen(input)]); - } - ssize_t bang_len = g_utf8_pointer_to_offset ( sob, eob ); + if ( sob != NULL && ( prev_char == NULL || ( config.combi_bang_anywhere && prev_char[0] == ' ' ) ) ) { + glong sob_offset = g_utf8_pointer_to_offset ( input, sob ); + const char *eob = g_utf8_strchr ( sob, -1, ' ' ); + if ( eob == NULL ) { + // Set it to end. + eob = &( input[strlen ( input )] ); + } + ssize_t bang_len = g_utf8_pointer_to_offset ( sob, eob ); - if ( bang_len > 1 ) { - *bang = g_utf8_substring( input, sob_offset + 1, sob_offset + bang_len ); + if ( bang_len > 1 ) { + *bang = g_utf8_substring ( input, sob_offset + 1, sob_offset + bang_len ); - char *head = g_utf8_substring ( input, 0, ( eob[0] != ' ' && prev_char != NULL) ? sob_offset - 1 : sob_offset ); - const char *tail = ( eob[0] == ' ' ) ? g_utf8_next_char( eob ) : eob; - *rest = g_strdup_printf ( "%s%s", head, tail ); - g_free(head); - return; - } - } + char *head = g_utf8_substring ( input, 0, ( eob[0] != ' ' && prev_char != NULL ) ? sob_offset - 1 : sob_offset ); + const char *tail = ( eob[0] == ' ' ) ? g_utf8_next_char ( eob ) : eob; + *rest = g_strdup_printf ( "%s%s", head, tail ); + g_free ( head ); + return; + } + } } - *bang = g_strdup(""); - *rest = g_strdup(input); - return; + *bang = g_strdup ( "" ); + *rest = g_strdup ( input ); + return; } static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - gboolean return_from_fun = FALSE; - ModeMode retv; - char *bang; - char *rest; - split_bang(*input, &bang, &rest); + gboolean return_from_fun = FALSE; + ModeMode retv; + char *bang; + char *rest; + split_bang ( *input, &bang, &rest ); - ssize_t bang_len = strlen(bang); - if ( bang_len > 0 ) { - int switcher = -1; - for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) { - const char *mode_name = mode_get_name ( pd->switchers[i].mode ); - size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); - if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) { - switcher = i; - } - } + ssize_t bang_len = strlen ( bang ); + if ( bang_len > 0 ) { + int switcher = -1; + for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) { + const char *mode_name = mode_get_name ( pd->switchers[i].mode ); + size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); + if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) { + switcher = i; + } + } if ( switcher >= 0 ) { - if ( strlen( rest ) > 0) { + if ( strlen ( rest ) > 0 ) { retv = mode_result ( pd->switchers[switcher].mode, mretv, &rest, selected_line - pd->starts[switcher] ); - return_from_fun = TRUE; + return_from_fun = TRUE; + } + else { + retv = MODE_EXIT; + return_from_fun = TRUE; } - else { - retv = MODE_EXIT; - return_from_fun = TRUE; - } } - } + } - g_free( bang ); - g_free( rest ); - if ( return_from_fun ) { - return retv; - } + g_free ( bang ); + g_free ( rest ); + if ( return_from_fun ) { + return retv; + } if ( mretv & MENU_QUICK_SWITCH ) { 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] ); @@ -320,7 +321,6 @@ static cairo_surface_t * combi_get_icon ( const Mode *sw, unsigned int index, in return NULL; } - static char * combi_preprocess_input ( Mode *sw, const char *input ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); @@ -328,23 +328,23 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) pd->switchers[i].disable = FALSE; } - char *bang; - char *rest; - split_bang(input, &bang, &rest); + char *bang; + char *rest; + split_bang ( input, &bang, &rest ); - ssize_t bang_len = strlen(bang); - if ( strlen(bang) > 0 ) { - for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - const char *mode_name = mode_get_name ( pd->switchers[i].mode ); - size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); - if ( !( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) ) { - // No match. - pd->switchers[i].disable = TRUE; - } - } - } - g_free(bang); - return rest; + ssize_t bang_len = strlen ( bang ); + if ( strlen ( bang ) > 0 ) { + for ( unsigned i = 0; i < pd->num_switchers; i++ ) { + const char *mode_name = mode_get_name ( pd->switchers[i].mode ); + size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); + if ( !( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) ) { + // No match. + pd->switchers[i].disable = TRUE; + } + } + } + g_free ( bang ); + return rest; } Mode combi_mode = 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 26c028191..d400aefad 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -219,7 +219,7 @@ 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_Boolean, "combi-bang-anywhere", { .snum = &config.combi_bang_anywhere }, NULL, + { xrm_Boolean, "combi-bang-anywhere", { .snum = &config.combi_bang_anywhere }, NULL, "Allow bang (!) to be used anywhere in the string if it occurs after a space character.", 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 7b625befe8466b4420c7dac1926c866ed29f982b Mon Sep 17 00:00:00 2001 From: jchtt Date: Mon, 11 May 2020 23:01:36 -0400 Subject: [PATCH 4/7] Revert "Fixed indent" This reverts commit ea0d52e5aa90b21fa978cb8c7d836f4bd2fdb8b7. --- config/config.c | 32 +++---- data/uncrustify.cfg | 2 +- include/rofi-types.h | 11 +-- include/theme.h | 1 + include/view.h | 1 + source/dialogs/combi.c | 148 +++++++++++++++---------------- 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, 303 insertions(+), 312 deletions(-) diff --git a/config/config.c b/config/config.c index 8344349e7..2bc0a4226 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,10 +153,10 @@ 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 bang anywhere */ - .combi_bang_anywhere = FALSE, + .combi_bang_anywhere = FALSE, .matching_negate_char = '-', 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 e10f47340..41816ba60 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -151,87 +151,86 @@ static void combi_mode_destroy ( Mode *sw ) } } -static void split_bang ( const char *input, char **bang, char **rest ) -{ - // Splits string input into a part containing the bang and the part containing the rest, - // saved in the pointers bang and rest. - if ( input != NULL ) { - char *sob = g_utf8_strchr ( input, -1, '!' ); - char *prev_char = g_utf8_find_prev_char ( input, sob ); +static void split_bang( const char *input, char **bang, char **rest ) { + // Splits string input into a part containing the bang and the part containing the rest, + // saved in the pointers bang and rest. + if ( input != NULL) { + char *sob = g_utf8_strchr ( input, -1, '!' ); + char *prev_char = g_utf8_find_prev_char( input, sob ); - if ( sob != NULL && ( prev_char == NULL || ( config.combi_bang_anywhere && prev_char[0] == ' ' ) ) ) { - glong sob_offset = g_utf8_pointer_to_offset ( input, sob ); - const char *eob = g_utf8_strchr ( sob, -1, ' ' ); - if ( eob == NULL ) { - // Set it to end. - eob = &( input[strlen ( input )] ); - } - ssize_t bang_len = g_utf8_pointer_to_offset ( sob, eob ); + if (sob != NULL && (prev_char == NULL || ( config.combi_bang_anywhere && prev_char[0] == ' ' ))) { + glong sob_offset = g_utf8_pointer_to_offset( input, sob ); + const char *eob = g_utf8_strchr ( sob, -1, ' ' ); + if ( eob == NULL ) { + // Set it to end. + eob = &(input[strlen(input)]); + } + ssize_t bang_len = g_utf8_pointer_to_offset ( sob, eob ); - if ( bang_len > 1 ) { - *bang = g_utf8_substring ( input, sob_offset + 1, sob_offset + bang_len ); + if ( bang_len > 1 ) { + *bang = g_utf8_substring( input, sob_offset + 1, sob_offset + bang_len ); - char *head = g_utf8_substring ( input, 0, ( eob[0] != ' ' && prev_char != NULL ) ? sob_offset - 1 : sob_offset ); - const char *tail = ( eob[0] == ' ' ) ? g_utf8_next_char ( eob ) : eob; - *rest = g_strdup_printf ( "%s%s", head, tail ); - g_free ( head ); - return; - } - } + char *head = g_utf8_substring ( input, 0, ( eob[0] != ' ' && prev_char != NULL) ? sob_offset - 1 : sob_offset ); + const char *tail = ( eob[0] == ' ' ) ? g_utf8_next_char( eob ) : eob; + *rest = g_strdup_printf ( "%s%s", head, tail ); + g_free(head); + return; + } + } } - *bang = g_strdup ( "" ); - *rest = g_strdup ( input ); - return; + *bang = g_strdup(""); + *rest = g_strdup(input); + return; } static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); - gboolean return_from_fun = FALSE; - ModeMode retv; - char *bang; - char *rest; - split_bang ( *input, &bang, &rest ); + gboolean return_from_fun = FALSE; + ModeMode retv; + char *bang; + char *rest; + split_bang(*input, &bang, &rest); - ssize_t bang_len = strlen ( bang ); - if ( bang_len > 0 ) { - int switcher = -1; - for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) { - const char *mode_name = mode_get_name ( pd->switchers[i].mode ); - size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); - if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) { - switcher = i; - } - } + ssize_t bang_len = strlen(bang); + if ( bang_len > 0 ) { + int switcher = -1; + for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) { + const char *mode_name = mode_get_name ( pd->switchers[i].mode ); + size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); + if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) { + switcher = i; + } + } if ( switcher >= 0 ) { - if ( strlen ( rest ) > 0 ) { + if ( strlen( rest ) > 0) { retv = mode_result ( pd->switchers[switcher].mode, mretv, &rest, selected_line - pd->starts[switcher] ); - return_from_fun = TRUE; - } - else { - retv = MODE_EXIT; - return_from_fun = TRUE; + return_from_fun = TRUE; } + else { + retv = MODE_EXIT; + return_from_fun = TRUE; + } } - } + } - g_free ( bang ); - g_free ( rest ); - if ( return_from_fun ) { - return retv; - } + g_free( bang ); + g_free( rest ); + if ( return_from_fun ) { + return retv; + } if ( mretv & MENU_QUICK_SWITCH ) { 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] ); @@ -321,6 +320,7 @@ static cairo_surface_t * combi_get_icon ( const Mode *sw, unsigned int index, in return NULL; } + static char * combi_preprocess_input ( Mode *sw, const char *input ) { CombiModePrivateData *pd = mode_get_private_data ( sw ); @@ -328,23 +328,23 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) pd->switchers[i].disable = FALSE; } - char *bang; - char *rest; - split_bang ( input, &bang, &rest ); + char *bang; + char *rest; + split_bang(input, &bang, &rest); - ssize_t bang_len = strlen ( bang ); - if ( strlen ( bang ) > 0 ) { - for ( unsigned i = 0; i < pd->num_switchers; i++ ) { - const char *mode_name = mode_get_name ( pd->switchers[i].mode ); - size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); - if ( !( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) ) { - // No match. - pd->switchers[i].disable = TRUE; - } - } - } - g_free ( bang ); - return rest; + ssize_t bang_len = strlen(bang); + if ( strlen(bang) > 0 ) { + for ( unsigned i = 0; i < pd->num_switchers; i++ ) { + const char *mode_name = mode_get_name ( pd->switchers[i].mode ); + size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); + if ( !( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) ) { + // No match. + pd->switchers[i].disable = TRUE; + } + } + } + g_free(bang); + return rest; } Mode combi_mode = 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 d400aefad..26c028191 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -219,7 +219,7 @@ 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_Boolean, "combi-bang-anywhere", { .snum = &config.combi_bang_anywhere }, NULL, + { xrm_Boolean, "combi-bang-anywhere", { .snum = &config.combi_bang_anywhere }, NULL, "Allow bang (!) to be used anywhere in the string if it occurs after a space character.", 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 d08b6bff52d40eb7201ccdd73fe8335b917cc775 Mon Sep 17 00:00:00 2001 From: jchtt Date: Tue, 12 May 2020 22:05:29 -0400 Subject: [PATCH 5/7] Cleaned up results code --- source/dialogs/combi.c | 39 --------------------------------------- 1 file changed, 39 deletions(-) diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 41816ba60..96acdabfb 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -187,50 +187,11 @@ static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned { CombiModePrivateData *pd = mode_get_private_data ( sw ); - gboolean return_from_fun = FALSE; - ModeMode retv; - char *bang; - char *rest; - split_bang(*input, &bang, &rest); - - ssize_t bang_len = strlen(bang); - if ( bang_len > 0 ) { - int switcher = -1; - for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) { - const char *mode_name = mode_get_name ( pd->switchers[i].mode ); - size_t mode_name_len = g_utf8_strlen ( mode_name, -1 ); - if ( (size_t) bang_len <= mode_name_len && utf8_strncmp ( bang, mode_name, bang_len ) == 0 ) { - switcher = i; - } - } - if ( switcher >= 0 ) { - if ( strlen( rest ) > 0) { - retv = mode_result ( pd->switchers[switcher].mode, mretv, &rest, - selected_line - pd->starts[switcher] ); - return_from_fun = TRUE; - } - else { - retv = MODE_EXIT; - return_from_fun = TRUE; - } - } - } - - g_free( bang ); - g_free( rest ); - if ( return_from_fun ) { - return retv; - } - if ( mretv & MENU_QUICK_SWITCH ) { 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] ); From 8c005e03fc49c2564a5fd3e7132f81a7773d7dec Mon Sep 17 00:00:00 2001 From: jchtt Date: Tue, 12 May 2020 22:24:52 -0400 Subject: [PATCH 6/7] Reworked split_bang function. --- source/dialogs/combi.c | 57 +++++++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 23 deletions(-) diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 96acdabfb..70706255b 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -154,32 +154,43 @@ static void combi_mode_destroy ( Mode *sw ) static void split_bang( const char *input, char **bang, char **rest ) { // Splits string input into a part containing the bang and the part containing the rest, // saved in the pointers bang and rest. - if ( input != NULL) { - char *sob = g_utf8_strchr ( input, -1, '!' ); - char *prev_char = g_utf8_find_prev_char( input, sob ); + + *bang = g_strdup(""); + *rest = g_strdup(input); - if (sob != NULL && (prev_char == NULL || ( config.combi_bang_anywhere && prev_char[0] == ' ' ))) { - glong sob_offset = g_utf8_pointer_to_offset( input, sob ); - const char *eob = g_utf8_strchr ( sob, -1, ' ' ); - if ( eob == NULL ) { - // Set it to end. - eob = &(input[strlen(input)]); - } - ssize_t bang_len = g_utf8_pointer_to_offset ( sob, eob ); + if ( input == NULL ) { + return; + } - if ( bang_len > 1 ) { - *bang = g_utf8_substring( input, sob_offset + 1, sob_offset + bang_len ); + char *sob = g_utf8_strchr ( input, -1, '!' ); + if ( sob == NULL ) { + return; + } + char *prev_char = g_utf8_find_prev_char( input, sob ); + if ( prev_char != NULL && (!config.combi_bang_anywhere || !g_unichar_isspace ( g_utf8_get_char( prev_char ) ) ) ) { + + return; + } - char *head = g_utf8_substring ( input, 0, ( eob[0] != ' ' && prev_char != NULL) ? sob_offset - 1 : sob_offset ); - const char *tail = ( eob[0] == ' ' ) ? g_utf8_next_char( eob ) : eob; - *rest = g_strdup_printf ( "%s%s", head, tail ); - g_free(head); - return; - } - } - } - *bang = g_strdup(""); - *rest = g_strdup(input); + glong sob_offset = g_utf8_pointer_to_offset( input, sob ); + const char *eob = g_utf8_strchr ( sob, -1, ' ' ); + if ( eob == NULL ) { + // Set it to end. + eob = &(input[strlen(input)]); + } + ssize_t bang_len = g_utf8_pointer_to_offset ( sob, eob ); + + if ( bang_len <= 1 ) { + return; + } + + *bang = g_utf8_substring( input, sob_offset + 1, sob_offset + bang_len ); + + char *head = g_utf8_substring ( input, 0, ( eob[0] != ' ' && prev_char != NULL) ? sob_offset - 1 : sob_offset ); + const char *tail = ( eob[0] == ' ' ) ? g_utf8_next_char( eob ) : eob; + g_free(*rest); + *rest = g_strdup_printf ( "%s%s", head, tail ); + g_free(head); return; } From c2c973bcb6e84fa313cfb25f88a1ce21fcd98229 Mon Sep 17 00:00:00 2001 From: jchtt Date: Wed, 13 May 2020 23:10:51 -0400 Subject: [PATCH 7/7] More cleanup --- source/dialogs/combi.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index 70706255b..786f5f27a 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -155,22 +155,33 @@ static void split_bang( const char *input, char **bang, char **rest ) { // Splits string input into a part containing the bang and the part containing the rest, // saved in the pointers bang and rest. - *bang = g_strdup(""); + *bang = NULL; *rest = g_strdup(input); if ( input == NULL ) { return; } - char *sob = g_utf8_strchr ( input, -1, '!' ); + char *sob = input; + sob = g_utf8_strchr ( input, -1, '!' ); if ( sob == NULL ) { return; } char *prev_char = g_utf8_find_prev_char( input, sob ); - if ( prev_char != NULL && (!config.combi_bang_anywhere || !g_unichar_isspace ( g_utf8_get_char( prev_char ) ) ) ) { - + if ( !config.combi_bang_anywhere && prev_char != NULL ) { return; } + while ( prev_char != NULL && !g_unichar_isspace ( g_utf8_get_char( prev_char ) ) ) { + sob = g_utf8_next_char ( sob ); + if ( sob == NULL ) { + return; + } + sob = g_utf8_strchr ( sob, -1, '!' ); + if ( sob == NULL ) { + return; + } + prev_char = g_utf8_find_prev_char( input, sob ); + } glong sob_offset = g_utf8_pointer_to_offset( input, sob ); const char *eob = g_utf8_strchr ( sob, -1, ' ' ); @@ -304,8 +315,9 @@ static char * combi_preprocess_input ( Mode *sw, const char *input ) char *rest; split_bang(input, &bang, &rest); - ssize_t bang_len = strlen(bang); - if ( strlen(bang) > 0 ) { + /* ssize_t bang_len = strlen(bang); */ + ssize_t bang_len = g_utf8_strlen(bang, -1); + if ( bang != NULL ) { for ( unsigned i = 0; i < pd->num_switchers; i++ ) { const char *mode_name = mode_get_name ( pd->switchers[i].mode ); size_t mode_name_len = g_utf8_strlen ( mode_name, -1 );