diff --git a/config/config.c b/config/config.c index 5f7cdf66..e3cf8356 100644 --- a/config/config.c +++ b/config/config.c @@ -36,39 +36,39 @@ Settings config = { /** List of enabled modi. */ /** -modi */ #ifdef WINDOW_MODE - .modi = "window,run,ssh", + .modi = "window,run,ssh", #else - .modi = "run,ssh", + .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", + .menu_font = "mono 12", /** Whether to load and show icons */ - .show_icons = FALSE, + .show_icons = FALSE, /** Terminal to use. (for ssh and open in terminal) */ .terminal_emulator = "rofi-sensible-terminal", .ssh_client = "ssh", /** Command when executing ssh. */ - .ssh_command = "{terminal} -e {ssh-client} {host} [-p {port}]", + .ssh_command = "{terminal} -e {ssh-client} {host} [-p {port}]", /** Command when running */ - .run_command = "{cmd}", + .run_command = "{cmd}", /** Command used to list executable commands. empty -> internal */ - .run_list_command = "", + .run_list_command = "", /** Command executed when running application in terminal */ - .run_shell_command = "{terminal} -e {cmd}", + .run_shell_command = "{terminal} -e {cmd}", /** Command executed on accep-entry-custom for window modus */ - .window_command = "wmctrl -i -R {window}", + .window_command = "wmctrl -i -R {window}", /** No default icon theme, we search Adwaita and gnome as fallback */ - .icon_theme = NULL, + .icon_theme = NULL, /** * Location of the window. * Enumeration indicating location or gravity of window. @@ -80,61 +80,61 @@ Settings config = { * WL_SOUTH_WEST WL_SOUTH WL_SOUTH_EAST * */ - .location = WL_CENTER, + .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, + .fixed_num_lines = TRUE, /** Do not use history */ - .disable_history = FALSE, + .disable_history = FALSE, /** Programs ignored for history */ - .ignored_prefixes = "", + .ignored_prefixes = "", /** Sort the displayed list */ - .sort = FALSE, + .sort = FALSE, /** Use levenshtein sorting when matching */ - .sorting_method = SORT_NORMAL, + .sorting_method = SORT_NORMAL, /** Case sensitivity of the search */ - .case_sensitive = FALSE, + .case_sensitive = FALSE, /** Cycle through in the element list */ - .cycle = TRUE, + .cycle = TRUE, /** Height of an element in #chars */ - .element_height = 1, + .element_height = 1, /** Sidebar mode, show the modi */ - .sidebar_mode = FALSE, + .sidebar_mode = FALSE, /** auto select */ - .auto_select = FALSE, + .auto_select = FALSE, /** Parse /etc/hosts file in ssh view. */ - .parse_hosts = FALSE, + .parse_hosts = FALSE, /** Parse ~/.ssh/known_hosts file in ssh view. */ - .parse_known_hosts = TRUE, + .parse_known_hosts = TRUE, /** Modi to combine into one view. */ .combi_modi = "window,run", .tokenize = TRUE, .matching = "normal", .matching_method = MM_NORMAL, /** Desktop entry fields to match*/ - .drun_match_fields = "name,generic,exec,categories,keywords", - .drun_categories = NULL, + .drun_match_fields = "name,generic,exec,categories,keywords", + .drun_categories = NULL, /** Desktop format display */ - .drun_display_format = "{name} [({generic})]", + .drun_display_format = "{name} [({generic})]", /** Desktop entry show actions */ - .drun_show_actions = FALSE, + .drun_show_actions = FALSE, /** Desktop entry show actions */ /** Window fields to match in window mode*/ - .window_match_fields = "all", + .window_match_fields = "all", /** Monitor */ - .monitor = "-5", + .monitor = "-5", /** set line margin */ .line_margin = 2, .line_padding = 1, /** Set filter */ - .filter = NULL, + .filter = NULL, /** Separator style: dash/solid */ - .separator_style = "dash", + .separator_style = "dash", /** Hide scrollbar */ .hide_scrollbar = FALSE, .fullscreen = FALSE, @@ -156,10 +156,10 @@ Settings config = { .max_history_size = 25, .combi_hide_mode_prefix = FALSE, - .matching_negate_char = '-', + .matching_negate_char = '-', - .cache_dir = NULL, - .window_thumbnail = FALSE, - .drun_use_desktop_cache = FALSE, + .cache_dir = NULL, + .window_thumbnail = FALSE, + .drun_use_desktop_cache = FALSE, .drun_reload_desktop_cache = FALSE }; diff --git a/include/dialogs/dmenuscriptshared.h b/include/dialogs/dmenuscriptshared.h index 31e8aae5..12423869 100644 --- a/include/dialogs/dmenuscriptshared.h +++ b/include/dialogs/dmenuscriptshared.h @@ -1,7 +1,8 @@ #ifndef ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H #define ROFI_DIALOGS_DMENU_SCRIPT_SHARED_H -typedef struct { +typedef struct +{ /** Entry content. (visible part) */ char *entry; /** Icon name to display. */ diff --git a/include/helper.h b/include/helper.h index 900817ee..9554c712 100644 --- a/include/helper.h +++ b/include/helper.h @@ -337,7 +337,6 @@ void parse_ranges ( char *input, rofi_range_pair **list, unsigned int *length ); */ void rofi_output_formatted_line ( const char *format, const char *string, int selected_line, const char *filter ); - /** * @param string The string with elements to be replaced * @param ... Set of {key}, value that will be replaced, terminated by a NULL diff --git a/include/theme.h b/include/theme.h index aff116d5..751d83b3 100644 --- a/include/theme.h +++ b/include/theme.h @@ -35,7 +35,8 @@ /** * Describe the media constraint type. */ -typedef enum { +typedef enum +{ /** Minimum width constraint. */ THEME_MEDIA_TYPE_MIN_WIDTH, /** Maximum width constraint. */ @@ -57,9 +58,10 @@ typedef enum { /** * Theme Media description. */ -typedef struct ThemeMedia { +typedef struct ThemeMedia +{ ThemeMediaType type; - double value; + double value; } ThemeMedia; /** diff --git a/include/view-internal.h b/include/view-internal.h index a6f7a632..af6e130f 100644 --- a/include/view-internal.h +++ b/include/view-internal.h @@ -103,9 +103,9 @@ struct RofiViewState textbox **modi; /** Total rows. */ - textbox *tb_total_rows; + textbox *tb_total_rows; /** filtered rows */ - textbox *tb_filtered_rows; + textbox *tb_filtered_rows; /** Settings of the menu */ MenuFlags menu_flags; diff --git a/include/widgets/listview.h b/include/widgets/listview.h index c10e1831..0aa6fab0 100644 --- a/include/widgets/listview.h +++ b/include/widgets/listview.h @@ -61,7 +61,7 @@ typedef enum * * Update callback, this is called to set the value of each (visible) element. */ -typedef void ( *listview_update_callback )( textbox *tb,icon *ico, unsigned int entry, void *udata, TextBoxFontType *type, gboolean full ); +typedef void ( *listview_update_callback )( textbox *tb, icon *ico, unsigned int entry, void *udata, TextBoxFontType *type, gboolean full ); /** * Callback when a element is activated. diff --git a/include/widgets/textbox.h b/include/widgets/textbox.h index 452be594..229e34d9 100644 --- a/include/widgets/textbox.h +++ b/include/widgets/textbox.h @@ -49,27 +49,27 @@ */ typedef struct { - widget widget; - unsigned long flags; - short cursor; - char *text; - const char *placeholder; - int show_placeholder; - PangoLayout *layout; - int tbft; - int markup; - int changed; + widget widget; + unsigned long flags; + short cursor; + char *text; + const char *placeholder; + int show_placeholder; + PangoLayout *layout; + int tbft; + int markup; + int changed; - int blink; - guint blink_timeout; + int blink; + guint blink_timeout; - double yalign; - double xalign; + double yalign; + double xalign; - PangoFontMetrics *metrics; + PangoFontMetrics *metrics; PangoEllipsizeMode emode; // - const char *theme_name; + const char *theme_name; } textbox; /** diff --git a/include/widgets/widget.h b/include/widgets/widget.h index abe0c4f6..dd4a5d7e 100644 --- a/include/widgets/widget.h +++ b/include/widgets/widget.h @@ -142,7 +142,6 @@ void widget_move ( widget *widget, short x, short y ); */ WidgetType widget_type ( widget *widget ); - /** * @param widget Handle to widget * @param type The widget type. diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 96eddf57..eeef4dba 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -53,7 +53,6 @@ #include "dialogs/dmenuscriptshared.h" - static int dmenu_mode_init ( Mode *sw ); static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ); static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_line, int height ); @@ -90,7 +89,7 @@ typedef struct unsigned int num_selected_list; unsigned int do_markup; // List with entries. - DmenuScriptEntry *cmd_list; + DmenuScriptEntry *cmd_list; unsigned int cmd_list_real_length; unsigned int cmd_list_length; unsigned int only_selected; @@ -123,14 +122,14 @@ static void read_add ( DmenuModePrivateData * pd, char *data, gsize len ) pd->cmd_list[pd->cmd_list_length].icon_fetch_uid = 0; pd->cmd_list[pd->cmd_list_length].icon_name = NULL; pd->cmd_list[pd->cmd_list_length].meta = NULL; - char *end = strchr(data, '\0'); + char *end = strchr ( data, '\0' ); if ( end != NULL ) { - data_len = end-data; - dmenuscript_parse_entry_extras ( NULL, &(pd->cmd_list[pd->cmd_list_length]), end+1, len-data_len); + data_len = end - data; + dmenuscript_parse_entry_extras ( NULL, &( pd->cmd_list[pd->cmd_list_length] ), end + 1, len - data_len ); } char *utfstr = rofi_force_utf8 ( data, data_len ); - pd->cmd_list[pd->cmd_list_length].entry = utfstr; - pd->cmd_list[pd->cmd_list_length + 1].entry = NULL; + pd->cmd_list[pd->cmd_list_length].entry = utfstr; + pd->cmd_list[pd->cmd_list_length + 1].entry = NULL; pd->cmd_list_length++; } @@ -250,17 +249,21 @@ static gchar * dmenu_format_output_string ( const DmenuModePrivateData *pd, cons static inline unsigned int get_index ( unsigned int length, int index ) { - if ( index >= 0 ) return index; - if ( ((unsigned int)-index) <= length ) return (length+index); + if ( index >= 0 ) { + return index; + } + if ( ( (unsigned int) -index ) <= length ) { + return length + index; + } // Out of range. return UINT_MAX; } static char *get_display_data ( const Mode *data, unsigned int index, int *state, G_GNUC_UNUSED GList **list, int get_entry ) { - Mode *sw = (Mode *) data; - DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw ); - DmenuScriptEntry *retv = (DmenuScriptEntry *) pd->cmd_list; + Mode *sw = (Mode *) data; + DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw ); + DmenuScriptEntry *retv = (DmenuScriptEntry *) pd->cmd_list; for ( unsigned int i = 0; i < pd->num_active_list; i++ ) { unsigned int start = get_index ( pd->cmd_list_length, pd->active_list[i].start ); unsigned int stop = get_index ( pd->cmd_list_length, pd->active_list[i].stop ); @@ -433,18 +436,18 @@ static int dmenu_mode_init ( Mode *sw ) static int dmenu_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ) { DmenuModePrivateData *rmpd = (DmenuModePrivateData *) mode_get_private_data ( sw ); - if ( rmpd->do_markup) { + if ( rmpd->do_markup ) { /** Strip out the markup when matching. */ char *esc = NULL; - pango_parse_markup(rmpd->cmd_list[index].entry, -1, 0, NULL, &esc, NULL, NULL); + pango_parse_markup ( rmpd->cmd_list[index].entry, -1, 0, NULL, &esc, NULL, NULL ); if ( esc ) { - int retv = helper_token_match ( tokens, esc); - g_free (esc); + int retv = helper_token_match ( tokens, esc ); + g_free ( esc ); return retv; } return FALSE; - - } else { + } + else { return helper_token_match ( tokens, rmpd->cmd_list[index].entry ); } } @@ -460,7 +463,7 @@ static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_l { DmenuModePrivateData *pd = (DmenuModePrivateData *) mode_get_private_data ( sw ); g_return_val_if_fail ( pd->cmd_list != NULL, NULL ); - DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); + DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); if ( dr->icon_name == NULL ) { return NULL; } @@ -471,7 +474,6 @@ static cairo_surface_t *dmenu_get_icon ( const Mode *sw, unsigned int selected_l return rofi_icon_fetcher_get ( dr->icon_fetch_uid ); } - static void dmenu_finish ( RofiViewState *state, int retv ) { if ( retv == FALSE ) { @@ -491,19 +493,19 @@ static void dmenu_finish ( RofiViewState *state, int retv ) static void dmenu_print_results ( DmenuModePrivateData *pd, const char *input ) { DmenuScriptEntry *cmd_list = pd->cmd_list; - int seen = FALSE; + int seen = FALSE; if ( pd->selected_list != NULL ) { for ( unsigned int st = 0; st < pd->cmd_list_length; st++ ) { if ( bitget ( pd->selected_list, st ) ) { seen = TRUE; - rofi_output_formatted_line ( pd->format, cmd_list[st].entry , st, input ); + rofi_output_formatted_line ( pd->format, cmd_list[st].entry, st, input ); } } } if ( !seen ) { const char *cmd = input; if ( pd->selected_line != UINT32_MAX ) { - cmd = cmd_list[pd->selected_line].entry ; + cmd = cmd_list[pd->selected_line].entry; } rofi_output_formatted_line ( pd->format, cmd, pd->selected_line, input ); } @@ -514,7 +516,7 @@ static void dmenu_finalize ( RofiViewState *state ) int retv = FALSE; DmenuModePrivateData *pd = (DmenuModePrivateData *) rofi_view_get_mode ( state )->private_data; unsigned int cmd_list_length = pd->cmd_list_length; - DmenuScriptEntry *cmd_list = pd->cmd_list; + DmenuScriptEntry *cmd_list = pd->cmd_list; char *input = g_strdup ( rofi_view_get_user_input ( state ) ); pd->selected_line = rofi_view_get_selected_line ( state );; @@ -647,9 +649,9 @@ int dmenu_switcher_dialog ( void ) get_dmenu_sync ( pd ); } } - char *input = NULL; - unsigned int cmd_list_length = pd->cmd_list_length; - DmenuScriptEntry *cmd_list = pd->cmd_list; + char *input = NULL; + unsigned int cmd_list_length = pd->cmd_list_length; + DmenuScriptEntry *cmd_list = pd->cmd_list; pd->only_selected = FALSE; pd->multi_select = FALSE; @@ -667,7 +669,7 @@ int dmenu_switcher_dialog ( void ) } } if ( config.auto_select && cmd_list_length == 1 ) { - rofi_output_formatted_line ( pd->format, cmd_list[0].entry , 0, config.filter ); + rofi_output_formatted_line ( pd->format, cmd_list[0].entry, 0, config.filter ); return TRUE; } if ( find_arg ( "-password" ) >= 0 ) { @@ -694,7 +696,7 @@ int dmenu_switcher_dialog ( void ) unsigned int i = 0; for ( i = 0; i < cmd_list_length; i++ ) { if ( tokens == NULL || helper_token_match ( tokens, cmd_list[i].entry ) ) { - rofi_output_formatted_line ( pd->format, cmd_list[i].entry , i, config.filter ); + rofi_output_formatted_line ( pd->format, cmd_list[i].entry, i, config.filter ); } } helper_tokenize_free ( tokens ); diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 943741b0..0a0d7ff2 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -55,7 +55,7 @@ #include "rofi-icon-fetcher.h" -#define DRUN_CACHE_FILE "rofi3.druncache" +#define DRUN_CACHE_FILE "rofi3.druncache" #define DRUN_DESKTOP_CACHE_FILE "rofi-drun-desktop.cache" char *DRUN_GROUP_NAME = "Desktop Entry"; @@ -142,8 +142,7 @@ struct _DRunModePrivateData unsigned int disabled_entries_length; unsigned int expected_line_height; - - char **show_categories; + char **show_categories; // Theme const gchar *icon_theme; @@ -234,11 +233,10 @@ static void exec_cmd_entry ( DRunModeEntry *e ) } if ( e->key_file == NULL ) { - GKeyFile *kf = g_key_file_new (); + GKeyFile *kf = g_key_file_new (); GError *error = NULL; gboolean res = g_key_file_load_from_file ( kf, e->path, 0, &error ); - if ( res ) - { + if ( res ) { e->key_file = kf; } else { @@ -282,11 +280,10 @@ static void exec_cmd_entry ( DRunModeEntry *e ) g_free ( str ); } - static gboolean rofi_strv_contains ( const char * const *categories, const char *const *field ) { - for ( int i = 0; categories && categories[i] ; i++ ){ - for ( int j = 0; field[j] ; j++ ){ + for ( int i = 0; categories && categories[i]; i++ ) { + for ( int j = 0; field[j]; j++ ) { if ( g_str_equal ( categories[i], field[j] ) ) { return TRUE; } @@ -314,7 +311,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const // Check if item is on disabled list. if ( g_hash_table_contains ( pd->disabled_entries, id ) && !parse_action ) { g_debug ( "[%s] [%s] Skipping, was previously seen.", id, path ); - return ; + return; } GKeyFile *kf = g_key_file_new (); GError *error = NULL; @@ -324,14 +321,14 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const g_debug ( "[%s] [%s] Failed to parse desktop file because: %s.", id, path, error->message ); g_error_free ( error ); g_key_file_free ( kf ); - return ; + return; } if ( g_key_file_has_group ( kf, action ) == FALSE ) { // No type? ignore. g_debug ( "[%s] [%s] Invalid desktop file: No %s group", id, path, action ); g_key_file_free ( kf ); - return ; + return; } // Skip non Application entries. gchar *key = g_key_file_get_string ( kf, DRUN_GROUP_NAME, "Type", NULL ); @@ -339,13 +336,13 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const // No type? ignore. g_debug ( "[%s] [%s] Invalid desktop file: No type indicated", id, path ); g_key_file_free ( kf ); - return ; + return; } if ( g_strcmp0 ( key, "Application" ) ) { g_debug ( "[%s] [%s] Skipping desktop file: Not of type application (%s)", id, path, key ); g_free ( key ); g_key_file_free ( kf ); - return ; + return; } g_free ( key ); @@ -353,7 +350,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const if ( !g_key_file_has_key ( kf, DRUN_GROUP_NAME, "Name", NULL ) ) { g_debug ( "[%s] [%s] Invalid desktop file: no 'Name' key present.", id, path ); g_key_file_free ( kf ); - return ; + return; } // Skip hidden entries. @@ -361,7 +358,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'Hidden' key is true", id, path ); g_key_file_free ( kf ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); - return ; + return; } if ( pd->current_desktop_list ) { gboolean show = TRUE; @@ -396,7 +393,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'OnlyShowIn'/'NotShowIn' keys don't match current desktop", id, path ); g_key_file_free ( kf ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); - return ; + return; } } // Skip entries that have NoDisplay set. @@ -404,13 +401,13 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const g_debug ( "[%s] [%s] Adding desktop file to disabled list: 'NoDisplay' key is true", id, path ); g_key_file_free ( kf ); g_hash_table_add ( pd->disabled_entries, g_strdup ( id ) ); - return ; + return; } // We need Exec, don't support DBusActivatable if ( !g_key_file_has_key ( kf, DRUN_GROUP_NAME, "Exec", NULL ) ) { g_debug ( "[%s] [%s] Unsupported desktop file: no 'Exec' key present.", id, path ); g_key_file_free ( kf ); - return ; + return; } if ( g_key_file_has_key ( kf, DRUN_GROUP_NAME, "TryExec", NULL ) ) { @@ -420,7 +417,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const if ( fp == NULL ) { g_free ( te ); g_key_file_free ( kf ); - return ; + return; } g_free ( fp ); } @@ -428,7 +425,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const if ( g_file_test ( te, G_FILE_TEST_IS_EXECUTABLE ) == FALSE ) { g_free ( te ); g_key_file_free ( kf ); - return ; + return; } } g_free ( te ); @@ -437,10 +434,10 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const char **categories = NULL; if ( pd->show_categories ) { categories = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL ); - if ( !rofi_strv_contains( (const char * const *)categories, (const char *const *)pd->show_categories ) ){ - g_strfreev(categories); + if ( !rofi_strv_contains ( (const char * const *) categories, (const char *const *) pd->show_categories ) ) { + g_strfreev ( categories ); g_key_file_free ( kf ); - return ; + return; } } @@ -478,23 +475,25 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const pd->entry_list[pd->cmd_list_length].generic_name = gn; if ( matching_entry_fields[DRUN_MATCH_FIELD_KEYWORDS].enabled ) { - pd->entry_list[pd->cmd_list_length].keywords = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Keywords", NULL, NULL, NULL ); - } else { + pd->entry_list[pd->cmd_list_length].keywords = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Keywords", NULL, NULL, NULL ); + } + else { pd->entry_list[pd->cmd_list_length].keywords = NULL; } if ( matching_entry_fields[DRUN_MATCH_FIELD_CATEGORIES].enabled ) { if ( categories ) { pd->entry_list[pd->cmd_list_length].categories = categories; - categories = NULL; - } else { + categories = NULL; + } + else { pd->entry_list[pd->cmd_list_length].categories = g_key_file_get_locale_string_list ( kf, DRUN_GROUP_NAME, "Categories", NULL, NULL, NULL ); } } else { pd->entry_list[pd->cmd_list_length].categories = NULL; } - g_strfreev(categories); + g_strfreev ( categories ); pd->entry_list[pd->cmd_list_length].exec = g_key_file_get_string ( kf, action, "Exec", NULL ); @@ -530,7 +529,7 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const } g_strfreev ( actions ); } - return ; + return; } /** @@ -641,86 +640,88 @@ static gint drun_int_sort_list ( gconstpointer a, gconstpointer b, G_GNUC_UNUSED if ( da->sort_index < 0 && db->sort_index < 0 ) { return g_utf8_collate ( da->name, db->name ); - } else { + } + else { return db->sort_index - da->sort_index; } } /******************************************* - * Cache voodoo * - *******************************************/ +* Cache voodoo * +*******************************************/ -#define CACHE_VERSION 1 +#define CACHE_VERSION 1 static void drun_write_str ( FILE *fd, const char *str ) { - size_t l = (str == NULL? 0 : strlen(str)); - fwrite ( &l, sizeof(l),1, fd ); + size_t l = ( str == NULL ? 0 : strlen ( str ) ); + fwrite ( &l, sizeof ( l ), 1, fd ); // Only write string if it is not NULL or empty. if ( l > 0 ) { // Also writeout terminating '\0' - fwrite ( str, 1, l+1, fd ); + fwrite ( str, 1, l + 1, fd ); } } static void drun_read_string ( FILE *fd, char **str ) { size_t l = 0; - if ( fread ( &l, sizeof(l), 1, fd ) != 1 ){ - g_warning( "Failed to read entry, cache corrupt?" ); + if ( fread ( &l, sizeof ( l ), 1, fd ) != 1 ) { + g_warning ( "Failed to read entry, cache corrupt?" ); return; } - (*str) = NULL; + ( *str ) = NULL; if ( l > 0 ) { // Include \0 l++; - (*str) = g_malloc(l); - if ( fread ( (*str), 1, l, fd ) != l ){ - g_warning( "Failed to read entry, cache corrupt?" ); + ( *str ) = g_malloc ( l ); + if ( fread ( ( *str ), 1, l, fd ) != l ) { + g_warning ( "Failed to read entry, cache corrupt?" ); } } } static void drun_write_strv ( FILE *fd, char **str ) { - guint vl = (str == NULL? 0 : g_strv_length ( str )); - fwrite ( &vl, sizeof(vl),1, fd ); - for ( guint index = 0; index < vl ; index++ ) { + guint vl = ( str == NULL ? 0 : g_strv_length ( str ) ); + fwrite ( &vl, sizeof ( vl ), 1, fd ); + for ( guint index = 0; index < vl; index++ ) { drun_write_str ( fd, str[index] ); } } static void drun_read_stringv ( FILE *fd, char ***str ) { guint vl = 0; - (*str) = NULL; - if ( fread ( &vl, sizeof(vl), 1, fd ) != 1 ){ - g_warning( "Failed to read entry, cache corrupt?" ); + ( *str ) = NULL; + if ( fread ( &vl, sizeof ( vl ), 1, fd ) != 1 ) { + g_warning ( "Failed to read entry, cache corrupt?" ); return; } - if ( vl > 0 ){ + if ( vl > 0 ) { // Include terminating NULL entry. - (*str) = g_malloc0((vl+1)*sizeof(**str)); + ( *str ) = g_malloc0 ( ( vl + 1 ) * sizeof ( **str ) ); for ( guint index = 0; index < vl; index++ ) { - drun_read_string ( fd, &((*str)[index])); + drun_read_string ( fd, &( ( *str )[index] ) ); } } } static void write_cache ( DRunModePrivateData *pd, const char *cache_file ) { - if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) return; + if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) { + return; + } TICK_N ( "DRUN Write CACHE: start" ); FILE *fd = fopen ( cache_file, "w" ); - if ( fd == NULL ){ + if ( fd == NULL ) { g_warning ( "Failed to write to cache file" ); return; } uint8_t version = CACHE_VERSION; - fwrite ( &version, sizeof(version),1, fd ); + fwrite ( &version, sizeof ( version ), 1, fd ); - fwrite ( &(pd->cmd_list_length), sizeof(pd->cmd_list_length),1,fd ); - for ( unsigned int index = 0; index < pd->cmd_list_length; index ++ ) - { - DRunModeEntry *entry = & ( pd->entry_list[index] ); + fwrite ( &( pd->cmd_list_length ), sizeof ( pd->cmd_list_length ), 1, fd ); + for ( unsigned int index = 0; index < pd->cmd_list_length; index++ ) { + DRunModeEntry *entry = &( pd->entry_list[index] ); drun_write_str ( fd, entry->action ); drun_write_str ( fd, entry->root ); @@ -736,20 +737,20 @@ static void write_cache ( DRunModePrivateData *pd, const char *cache_file ) drun_write_strv ( fd, entry->keywords ); drun_write_str ( fd, entry->comment ); - } - fclose ( fd) ; + fclose ( fd ); TICK_N ( "DRUN Write CACHE: end" ); } - /** * Read cache file. returns FALSE when success. */ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_file ) { - if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) return TRUE; + if ( cache_file == NULL || config.drun_use_desktop_cache == FALSE ) { + return TRUE; + } if ( config.drun_reload_desktop_cache ) { return TRUE; @@ -764,8 +765,7 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil // Read version. uint8_t version = 0; - if ( fread ( &version, sizeof(version),1, fd ) != 1 ) - { + if ( fread ( &version, sizeof ( version ), 1, fd ) != 1 ) { fclose ( fd ); g_warning ( "Cache corrupt, ignoring." ); TICK_N ( "DRUN Read CACHE: stop" ); @@ -779,7 +779,7 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil return FALSE; } - if ( fread ( &(pd->cmd_list_length), sizeof(pd->cmd_list_length),1,fd ) != 1 ){ + if ( fread ( &( pd->cmd_list_length ), sizeof ( pd->cmd_list_length ), 1, fd ) != 1 ) { fclose ( fd ); g_warning ( "Cache corrupt, ignoring." ); TICK_N ( "DRUN Read CACHE: stop" ); @@ -788,29 +788,27 @@ static gboolean drun_read_cache ( DRunModePrivateData *pd, const char *cache_fil // set actual length to length; pd->cmd_list_length_actual = pd->cmd_list_length; - pd->entry_list = g_malloc0 ( pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) )); + pd->entry_list = g_malloc0 ( pd->cmd_list_length_actual * sizeof ( *( pd->entry_list ) ) ); - for ( unsigned int index = 0; index < pd->cmd_list_length; index++ ) - { - DRunModeEntry *entry = & ( pd->entry_list[index] ); + for ( unsigned int index = 0; index < pd->cmd_list_length; index++ ) { + DRunModeEntry *entry = &( pd->entry_list[index] ); - drun_read_string ( fd, &(entry->action) ); - drun_read_string ( fd, &(entry->root) ); - drun_read_string ( fd, &(entry->path) ); - drun_read_string ( fd, &(entry->app_id) ); - drun_read_string ( fd, &(entry->desktop_id) ); - drun_read_string ( fd, &(entry->icon_name) ); - drun_read_string ( fd, &(entry->exec) ); - drun_read_string ( fd, &(entry->name) ); - drun_read_string ( fd, &(entry->generic_name) ); + drun_read_string ( fd, &( entry->action ) ); + drun_read_string ( fd, &( entry->root ) ); + drun_read_string ( fd, &( entry->path ) ); + drun_read_string ( fd, &( entry->app_id ) ); + drun_read_string ( fd, &( entry->desktop_id ) ); + drun_read_string ( fd, &( entry->icon_name ) ); + drun_read_string ( fd, &( entry->exec ) ); + drun_read_string ( fd, &( entry->name ) ); + drun_read_string ( fd, &( entry->generic_name ) ); - drun_read_stringv ( fd, &(entry->categories) ); - drun_read_stringv ( fd, &(entry->keywords) ); + drun_read_stringv ( fd, &( entry->categories ) ); + drun_read_stringv ( fd, &( entry->keywords ) ); - drun_read_string ( fd, &(entry->comment) ); + drun_read_string ( fd, &( entry->comment ) ); } - fclose ( fd ); TICK_N ( "DRUN Read CACHE: stop" ); return FALSE; @@ -820,9 +818,7 @@ static void get_apps ( DRunModePrivateData *pd ) { char *cache_file = g_build_filename ( cache_dir, DRUN_DESKTOP_CACHE_FILE, NULL ); TICK_N ( "Get Desktop apps (start)" ); - if ( drun_read_cache ( pd, cache_file ) ) - { - + if ( drun_read_cache ( pd, cache_file ) ) { gchar *dir; // First read the user directory. dir = g_build_filename ( g_get_user_data_dir (), "applications", NULL ); @@ -906,8 +902,8 @@ static int drun_mode_init ( Mode *sw ) const char *current_desktop = g_getenv ( "XDG_CURRENT_DESKTOP" ); pd->current_desktop_list = current_desktop ? g_strsplit ( current_desktop, ":", 0 ) : NULL; - if ( config.drun_categories && *(config.drun_categories) ){ - pd->show_categories = g_strsplit(config.drun_categories, ",",0); + if ( config.drun_categories && *( config.drun_categories ) ) { + pd->show_categories = g_strsplit ( config.drun_categories, ",", 0 ); } drun_mode_parse_entry_fields (); @@ -1000,27 +996,27 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in return g_strdup ( "Failed" ); } /* Free temp storage. */ - DRunModeEntry *dr = &( pd->entry_list[selected_line] ); - gchar *cats = NULL; - if ( dr->categories ){ - char *tcats = g_strjoinv(",", dr->categories); + DRunModeEntry *dr = &( pd->entry_list[selected_line] ); + gchar *cats = NULL; + if ( dr->categories ) { + char *tcats = g_strjoinv ( ",", dr->categories ); if ( tcats ) { cats = g_markup_escape_text ( tcats, -1 ); - g_free (tcats); + g_free ( tcats ); } } - gchar *keywords= NULL; - if ( dr->keywords ){ - char *tkeyw= g_strjoinv(",", dr->keywords); + gchar *keywords = NULL; + if ( dr->keywords ) { + char *tkeyw = g_strjoinv ( ",", dr->keywords ); if ( tkeyw ) { keywords = g_markup_escape_text ( tkeyw, -1 ); - g_free (tkeyw); + g_free ( tkeyw ); } } // Needed for display. char *egn = NULL; - char *en = NULL; - char *ec = NULL; + char *en = NULL; + char *ec = NULL; if ( dr->generic_name ) { egn = g_markup_escape_text ( dr->generic_name, -1 ); } @@ -1028,22 +1024,21 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, in en = g_markup_escape_text ( dr->name, -1 ); } if ( dr->comment ) { - ec = g_markup_escape_text ( dr->comment , -1 ); + ec = g_markup_escape_text ( dr->comment, -1 ); } - char *retv = helper_string_replace_if_exists ( config.drun_display_format, - "{generic}", egn, - "{name}", en, - "{comment}", ec, - "{exec}", dr->exec, - "{categories}", cats, - "{keywords}", keywords, - NULL); + "{generic}", egn, + "{name}", en, + "{comment}", ec, + "{exec}", dr->exec, + "{categories}", cats, + "{keywords}", keywords, + NULL ); g_free ( egn ); g_free ( en ); g_free ( ec ); - g_free(cats); + g_free ( cats ); return retv; } diff --git a/source/dialogs/script.c b/source/dialogs/script.c index 514e43ba..254fab0b 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -45,18 +45,16 @@ #include "mode-private.h" - #include "rofi-icon-fetcher.h" #include "dialogs/dmenuscriptshared.h" - typedef struct { /** ID of the current script. */ unsigned int id; /** List of visible items. */ - DmenuScriptEntry *cmd_list; + DmenuScriptEntry *cmd_list; /** length list of visible items. */ unsigned int cmd_list_length; @@ -77,18 +75,18 @@ typedef struct */ void dmenuscript_parse_entry_extras ( G_GNUC_UNUSED Mode *sw, DmenuScriptEntry *entry, char *buffer, size_t length ) { - size_t length_key = 0;//strlen ( line ); + size_t length_key = 0; //strlen ( line ); while ( length_key <= length && buffer[length_key] != '\x1f' ) { length_key++; } if ( length_key < length ) { buffer[length_key] = '\0'; char *value = buffer + length_key + 1; - if ( strcasecmp(buffer, "icon" ) == 0 ) { - entry->icon_name = g_strdup(value); + if ( strcasecmp ( buffer, "icon" ) == 0 ) { + entry->icon_name = g_strdup ( value ); } - if ( strcasecmp(buffer, "meta" ) == 0 ) { - entry->meta = g_strdup(value); + if ( strcasecmp ( buffer, "meta" ) == 0 ) { + entry->meta = g_strdup ( value ); } } } @@ -131,11 +129,11 @@ static void parse_header_entry ( Mode *sw, char *line, ssize_t length ) static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg, unsigned int *length ) { - int fd = -1; - GError *error = NULL; - DmenuScriptEntry *retv = NULL; - char **argv = NULL; - int argc = 0; + int fd = -1; + GError *error = NULL; + DmenuScriptEntry *retv = NULL; + char **argv = NULL; + int argc = 0; *length = 0; if ( g_shell_parse_argv ( command, &argc, &argv, &error ) ) { argv = g_realloc ( argv, ( argc + 2 ) * sizeof ( char* ) ); @@ -171,13 +169,13 @@ static DmenuScriptEntry *get_script_output ( Mode *sw, char *command, char *arg, actual_size += 256; retv = g_realloc ( retv, ( actual_size ) * sizeof ( DmenuScriptEntry ) ); } - size_t buf_length = strlen(buffer)+1; - retv[( *length )].entry = g_memdup ( buffer, buf_length); - retv[( *length )].icon_name = NULL; - retv[( *length )].meta = NULL; - retv[(*length)].icon_fetch_uid = 0; - if ( buf_length > 0 && (read_length > (ssize_t)buf_length) ) { - dmenuscript_parse_entry_extras ( sw, &(retv[(*length)]), buffer+buf_length, read_length-buf_length); + size_t buf_length = strlen ( buffer ) + 1; + retv[( *length )].entry = g_memdup ( buffer, buf_length ); + retv[( *length )].icon_name = NULL; + retv[( *length )].meta = NULL; + retv[( *length )].icon_fetch_uid = 0; + if ( buf_length > 0 && ( read_length > (ssize_t) buf_length ) ) { + dmenuscript_parse_entry_extras ( sw, &( retv[( *length )] ), buffer + buf_length, read_length - buf_length ); } retv[( *length ) + 1].entry = NULL; ( *length )++; @@ -242,7 +240,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned { ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; ModeMode retv = MODE_EXIT; - DmenuScriptEntry *new_list = NULL; + DmenuScriptEntry *new_list = NULL; unsigned int new_length = 0; if ( ( mretv & MENU_NEXT ) ) { @@ -265,7 +263,7 @@ static ModeMode script_mode_result ( Mode *sw, int mretv, char **input, unsigned // If a new list was generated, use that an loop around. if ( new_list != NULL ) { - for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ){ + for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) { g_free ( rmpd->cmd_list[i].entry ); g_free ( rmpd->cmd_list[i].icon_name ); g_free ( rmpd->cmd_list[i].meta ); @@ -283,7 +281,7 @@ static void script_mode_destroy ( Mode *sw ) { ScriptModePrivateData *rmpd = (ScriptModePrivateData *) sw->private_data; if ( rmpd != NULL ) { - for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ){ + for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ) { g_free ( rmpd->cmd_list[i].entry ); g_free ( rmpd->cmd_list[i].icon_name ); g_free ( rmpd->cmd_list[i].meta ); @@ -299,8 +297,12 @@ static void script_mode_destroy ( Mode *sw ) } static inline unsigned int get_index ( unsigned int length, int index ) { - if ( index >= 0 ) return index; - if ( ((unsigned int)-index) <= length ) return (length+index); + if ( index >= 0 ) { + return index; + } + if ( ( (unsigned int) -index ) <= length ) { + return length + index; + } // Out of range. return UINT_MAX; } @@ -330,20 +332,20 @@ static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_ static int script_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index ) { ScriptModePrivateData *rmpd = sw->private_data; - int match = 1; + int match = 1; if ( tokens ) { - for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { - rofi_int_matcher *ftokens[2] = { tokens[j], NULL }; - int test = 0; - test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry ); - if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) { - test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta); - } + for ( int j = 0; match && tokens != NULL && tokens[j] != NULL; j++ ) { + rofi_int_matcher *ftokens[2] = { tokens[j], NULL }; + int test = 0; + test = helper_token_match ( ftokens, rmpd->cmd_list[index].entry ); + if ( test == tokens[j]->invert && rmpd->cmd_list[index].meta ) { + test = helper_token_match ( ftokens, rmpd->cmd_list[index].meta ); + } - if ( test == 0 ) { - match = 0; - } - } + if ( test == 0 ) { + match = 0; + } + } } return match; } @@ -356,7 +358,7 @@ static cairo_surface_t *script_get_icon ( const Mode *sw, unsigned int selected_ { ScriptModePrivateData *pd = (ScriptModePrivateData *) mode_get_private_data ( sw ); g_return_val_if_fail ( pd->cmd_list != NULL, NULL ); - DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); + DmenuScriptEntry *dr = &( pd->cmd_list[selected_line] ); if ( dr->icon_name == NULL ) { return NULL; } diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 74937bc5..8ea45c80 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -59,7 +59,8 @@ /** * Holding an ssh entry. */ -typedef struct _SshEntry { +typedef struct _SshEntry +{ /** SSH hostname */ char *hostname; /** SSH port number */ @@ -70,9 +71,9 @@ typedef struct _SshEntry { */ typedef struct { - GList *user_known_hosts; + GList *user_known_hosts; /** List if available ssh hosts.*/ - SshEntry *hosts_list; + SshEntry *hosts_list; /** Length of the #hosts_list.*/ unsigned int hosts_list_length; } SSHModePrivateData; @@ -88,7 +89,6 @@ typedef struct */ #define SSH_TOKEN_DELIM "= \t\r\n" - /** * @param entry The host to connect too * @@ -96,18 +96,18 @@ typedef struct * * @returns FALSE On failure, TRUE on success */ -static int execshssh ( const SshEntry *entry) +static int execshssh ( const SshEntry *entry ) { - char **args = NULL; - int argsv = 0; + char **args = NULL; + int argsv = 0; gchar *portstr = NULL; if ( entry->port > 0 ) { - portstr = g_strdup_printf("%d", entry->port); + portstr = g_strdup_printf ( "%d", entry->port ); } helper_parse_setup ( config.ssh_command, &args, &argsv, - "{host}", entry->hostname, - "{port}", portstr, - (char *) 0 ); + "{host}", entry->hostname, + "{port}", portstr, + (char *) 0 ); g_free ( portstr ); gsize l = strlen ( "Connecting to '' via rofi" ) + strlen ( entry->hostname ) + 1; @@ -130,7 +130,7 @@ static int execshssh ( const SshEntry *entry) */ static void exec_ssh ( const SshEntry *entry ) { - if ( !(entry->hostname )|| !(entry->hostname[0]) ) { + if ( !( entry->hostname ) || !( entry->hostname[0] ) ) { return; } @@ -143,10 +143,11 @@ static void exec_ssh ( const SshEntry *entry ) char *path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL ); // TODO update. if ( entry->port > 0 ) { - char *store = g_strdup_printf("%s\x1F%d", entry->hostname, entry->port ); + char *store = g_strdup_printf ( "%s\x1F%d", entry->hostname, entry->port ); history_set ( path, store ); g_free ( store ); - } else { + } + else { history_set ( path, entry->hostname ); } g_free ( path ); @@ -178,16 +179,16 @@ static void delete_ssh ( const char *host ) */ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsigned int *length ) { - FILE *fd = fopen ( path, "r" ); + FILE *fd = fopen ( path, "r" ); if ( fd != NULL ) { char *buffer = NULL; size_t buffer_length = 0; // Reading one line per time. while ( getline ( &buffer, &buffer_length, fd ) > 0 ) { // Strip whitespace. - char *start = g_strstrip(&(buffer[0])); + char *start = g_strstrip ( &( buffer[0] ) ); // Find start. - if ( *start == '#' || *start == '@' ){ + if ( *start == '#' || *start == '@' ) { // skip comments or cert-authority or revoked items. continue; } @@ -196,32 +197,34 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi continue; } // Find end of hostname set. - char *end = strstr ( start, " " ); + char *end = strstr ( start, " " ); if ( end == NULL ) { // Something is wrong. continue; } *end = '\0'; char *sep = start; - start = strsep(&sep,", " ); - while ( start ) - { + start = strsep ( &sep, ", " ); + while ( start ) { int port = 0; if ( start[0] == '[' ) { start++; - char *end = strchr ( start, ']'); - if ( end[1] == ':' ){ + char *end = strchr ( start, ']' ); + if ( end[1] == ':' ) { *end = '\0'; errno = 0; - gchar *endptr = NULL; - gint64 number = g_ascii_strtoll ( &(end[2]), &endptr, 10); + gchar *endptr = NULL; + gint64 number = g_ascii_strtoll ( &( end[2] ), &endptr, 10 ); if ( errno != 0 ) { - g_warning ( "Failed to parse port number: %s.", &(end[2]) ); - } else if ( endptr == &(end[2])) { - g_warning ( "Failed to parse port number: %s, invalid number.", &(end[2]) ); - } else if ( number < 0 || number > 65535 ) { - g_warning ( "Failed to parse port number: %s, out of range.", &(end[2]) ); - } else { + g_warning ( "Failed to parse port number: %s.", &( end[2] ) ); + } + else if ( endptr == &( end[2] ) ) { + g_warning ( "Failed to parse port number: %s, invalid number.", &( end[2] ) ); + } + else if ( number < 0 || number > 65535 ) { + g_warning ( "Failed to parse port number: %s, out of range.", &( end[2] ) ); + } + else { port = number; } } @@ -245,7 +248,7 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi retv[( *length ) + 1].port = 0; ( *length )++; } - start = strsep(&sep,", " ); + start = strsep ( &sep, ", " ); } } if ( buffer != NULL ) { @@ -254,7 +257,8 @@ static SshEntry *read_known_hosts_file ( const char *path, SshEntry * retv, unsi if ( fclose ( fd ) != 0 ) { g_warning ( "Failed to close hosts file: '%s'", g_strerror ( errno ) ); } - } else { + } + else { g_debug ( "Failed to open KnownHostFile: '%s'", path ); } @@ -338,12 +342,13 @@ static SshEntry *read_hosts_file ( SshEntry * retv, unsigned int *length ) static void add_known_hosts_file ( SSHModePrivateData *pd, const char *token ) { - GList *item = g_list_find_custom ( pd->user_known_hosts, token, (GCompareFunc)g_strcmp0 ); + GList *item = g_list_find_custom ( pd->user_known_hosts, token, (GCompareFunc) g_strcmp0 ); if ( item == NULL ) { - g_debug("Add '%s' to UserKnownHost list", token); + g_debug ( "Add '%s' to UserKnownHost list", token ); pd->user_known_hosts = g_list_append ( pd->user_known_hosts, g_strdup ( token ) ); - } else { - g_debug("File '%s' already in UserKnownHostsFile list", token); + } + else { + g_debug ( "File '%s' already in UserKnownHostsFile list", token ); } } @@ -368,7 +373,7 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename if ( !token || *token == '#' ) { continue; } - char *low_token = g_ascii_strdown(token, -1); + char *low_token = g_ascii_strdown ( token, -1 ); if ( g_strcmp0 ( low_token, "include" ) == 0 ) { token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ); g_debug ( "Found Include: %s", token ); @@ -396,7 +401,7 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename } else if ( g_strcmp0 ( low_token, "userknownhostsfile" ) == 0 ) { while ( ( token = strtok_r ( NULL, SSH_TOKEN_DELIM, &strtok_pointer ) ) ) { - g_debug("Found extra UserKnownHostsFile: %s", token); + g_debug ( "Found extra UserKnownHostsFile: %s", token ); add_known_hosts_file ( pd, token ); } } @@ -463,7 +468,7 @@ static void parse_ssh_config_file ( SSHModePrivateData *pd, const char *filename */ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length ) { - SshEntry *retv = NULL; + SshEntry *retv = NULL; unsigned int num_favorites = 0; char *path; @@ -474,29 +479,32 @@ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length ) path = g_build_filename ( cache_dir, SSH_CACHE_FILE, NULL ); char **h = history_get_list ( path, length ); - retv = malloc ( (*length)*sizeof(SshEntry)); - for ( unsigned int i = 0; i < (*length); i++ ){ - int port = 0; + retv = malloc ( ( *length ) * sizeof ( SshEntry ) ); + for ( unsigned int i = 0; i < ( *length ); i++ ) { + int port = 0; char *portstr = strchr ( h[i], '\x1F' ); if ( portstr != NULL ) { *portstr = '\0'; - errno = 0; - gchar *endptr= NULL; - gint64 number = g_ascii_strtoll ( &(portstr[1]), &endptr, 10); + errno = 0; + gchar *endptr = NULL; + gint64 number = g_ascii_strtoll ( &( portstr[1] ), &endptr, 10 ); if ( errno != 0 ) { - g_warning ( "Failed to parse port number: %s.", &(portstr[1]) ); - } else if ( endptr == &(portstr[1])) { - g_warning ( "Failed to parse port number: %s, invalid number.", &(portstr[1]) ); - } else if ( number < 0 || number > 65535 ) { - g_warning ( "Failed to parse port number: %s, out of range.", &(portstr[1]) ); - } else { + g_warning ( "Failed to parse port number: %s.", &( portstr[1] ) ); + } + else if ( endptr == &( portstr[1] ) ) { + g_warning ( "Failed to parse port number: %s, invalid number.", &( portstr[1] ) ); + } + else if ( number < 0 || number > 65535 ) { + g_warning ( "Failed to parse port number: %s, out of range.", &( portstr[1] ) ); + } + else { port = number; } } retv[i].hostname = h[i]; - retv[i].port = port; + retv[i].port = port; } - g_free (h); + g_free ( h ); g_free ( path ); num_favorites = ( *length ); @@ -509,23 +517,21 @@ static SshEntry * get_ssh ( SSHModePrivateData *pd, unsigned int *length ) char *path = g_build_filename ( g_get_home_dir (), ".ssh", "known_hosts", NULL ); retv = read_known_hosts_file ( path, retv, length ); g_free ( path ); - for ( GList *iter = g_list_first ( pd->user_known_hosts); iter; iter = g_list_next ( iter ) ) { - char *path = rofi_expand_path ( (const char *)iter->data); - retv = read_known_hosts_file ( (const char*)path, retv, length ); - g_free (path); + for ( GList *iter = g_list_first ( pd->user_known_hosts ); iter; iter = g_list_next ( iter ) ) { + char *path = rofi_expand_path ( (const char *) iter->data ); + retv = read_known_hosts_file ( (const char*) path, retv, length ); + g_free ( path ); } } if ( config.parse_hosts == TRUE ) { retv = read_hosts_file ( retv, length ); } - g_free ( path ); return retv; } - /** * @param sw Object handle to the SSH Mode object * @@ -563,8 +569,8 @@ static void ssh_mode_destroy ( Mode *sw ) { SSHModePrivateData *rmpd = (SSHModePrivateData *) mode_get_private_data ( sw ); if ( rmpd != NULL ) { - for ( unsigned int i = 0; i < rmpd->hosts_list_length; i++ ){ - g_free( rmpd->hosts_list[i].hostname ); + for ( unsigned int i = 0; i < rmpd->hosts_list_length; i++ ) { + g_free ( rmpd->hosts_list[i].hostname ); } g_list_free_full ( rmpd->user_known_hosts, g_free ); g_free ( rmpd->hosts_list ); @@ -597,7 +603,7 @@ static ModeMode ssh_mode_result ( Mode *sw, int mretv, char **input, unsigned in retv = ( mretv & MENU_LOWER_MASK ); } else if ( ( mretv & MENU_OK ) && rmpd->hosts_list[selected_line].hostname != NULL ) { - exec_ssh ( &(rmpd->hosts_list[selected_line]) ); + exec_ssh ( &( rmpd->hosts_list[selected_line] ) ); } else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) { SshEntry entry = { .hostname = *input, .port = 0 }; diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 7649545d..e5eb33cb 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -470,7 +470,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) ModeModePrivateData *pd = (ModeModePrivateData *) mode_get_private_data ( sw ); // find window list xcb_window_t curr_win_id; - int found = 0; + int found = 0; // Create cache @@ -488,7 +488,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) } c = xcb_ewmh_get_client_list_stacking ( &xcb->ewmh, 0 ); - xcb_ewmh_get_windows_reply_t clients = {0,}; + xcb_ewmh_get_windows_reply_t clients = { 0, }; if ( xcb_ewmh_get_client_list_stacking_reply ( &xcb->ewmh, c, &clients, NULL ) ) { found = 1; } @@ -498,7 +498,7 @@ static void _window_mode_load_data ( Mode *sw, unsigned int cd ) found = 1; } } - if ( ! found ) { + if ( !found ) { return; } diff --git a/source/helper.c b/source/helper.c index 02bddc29..071da9bd 100644 --- a/source/helper.c +++ b/source/helper.c @@ -79,7 +79,6 @@ void cmd_set_arguments ( int argc, char **argv ) stored_argv = argv; } - int helper_parse_setup ( char * string, char ***output, int *length, ... ) { GError *error = NULL; @@ -433,8 +432,8 @@ PangoAttrList *helper_token_match_get_pango_attr ( RofiHighlightColorStyle th, r pa->end_index = end; pango_attr_list_insert ( retv, pa ); - if ( th.color.alpha < 1.0 ){ - pa = pango_attr_foreground_alpha_new(th.color.alpha*65535); + if ( th.color.alpha < 1.0 ) { + pa = pango_attr_foreground_alpha_new ( th.color.alpha * 65535 ); pa->start_index = start; pa->end_index = end; pango_attr_list_insert ( retv, pa ); @@ -1135,12 +1134,13 @@ cairo_surface_t* cairo_image_surface_create_from_svg ( const gchar* file, int he static void parse_pair ( char *input, rofi_range_pair *item ) { // Skip leading blanks. - while ( input != NULL && isblank(*input) ) + while ( input != NULL && isblank ( *input ) ) { ++input; + } - const char *sep[] = { "-", ":" }; - int pythonic = ( strchr(input, ':') || input[0] == '-' ) ? 1 : 0; - int index = 0; + const char *sep[] = { "-", ":" }; + int pythonic = ( strchr ( input, ':' ) || input[0] == '-' ) ? 1 : 0; + int index = 0; for ( char *token = strsep ( &input, sep[pythonic] ); token != NULL; token = strsep ( &input, sep[pythonic] ) ) { if ( index == 0 ) { @@ -1208,12 +1208,13 @@ void rofi_output_formatted_line ( const char *format, const char *string, int se } else if ( format[i] == 'p' ) { char *esc = NULL; - pango_parse_markup(string, -1, 0, NULL, &esc, NULL, NULL); - if ( esc ){ + pango_parse_markup ( string, -1, 0, NULL, &esc, NULL, NULL ); + if ( esc ) { fputs ( esc, stdout ); g_free ( esc ); - } else { - fputs ( "invalid string" , stdout ); + } + else { + fputs ( "invalid string", stdout ); } } else if ( format[i] == 'q' ) { @@ -1241,15 +1242,14 @@ void rofi_output_formatted_line ( const char *format, const char *string, int se fflush ( stdout ); } - static gboolean helper_eval_cb2 ( const GMatchInfo *info, GString *res, gpointer data ) { gchar *match; // Get the match - int num_match = g_match_info_get_match_count(info); + int num_match = g_match_info_get_match_count ( info ); // Just {text} This is inside () 5. if ( num_match == 5 ) { - match = g_match_info_fetch ( info, 4); + match = g_match_info_fetch ( info, 4 ); if ( match != NULL ) { // Lookup the match, so we can replace it. gchar *r = g_hash_table_lookup ( (GHashTable *) data, match ); @@ -1263,21 +1263,21 @@ static gboolean helper_eval_cb2 ( const GMatchInfo *info, GString *res, gpointer } // {} with [] guard around it. else if ( num_match == 4 ) { - match = g_match_info_fetch ( info, 2); + match = g_match_info_fetch ( info, 2 ); if ( match != NULL ) { // Lookup the match, so we can replace it. gchar *r = g_hash_table_lookup ( (GHashTable *) data, match ); if ( r != NULL ) { // Add (optional) prefix - gchar *prefix = g_match_info_fetch (info, 1); + gchar *prefix = g_match_info_fetch ( info, 1 ); g_string_append ( res, prefix ); - g_free (prefix ); + g_free ( prefix ); // Append the replacement to the string. g_string_append ( res, r ); // Add (optional) postfix - gchar *post = g_match_info_fetch (info, 3); + gchar *post = g_match_info_fetch ( info, 3 ); g_string_append ( res, post ); - g_free (post ); + g_free ( post ); } // Free match. g_free ( match ); @@ -1292,7 +1292,7 @@ char *helper_string_replace_if_exists ( char * string, ... ) { GHashTable *h; h = g_hash_table_new ( g_str_hash, g_str_equal ); - va_list ap; + va_list ap; va_start ( ap, string ); // Add list from variable arguments. while ( 1 ) { @@ -1324,12 +1324,12 @@ char *helper_string_replace_if_exists ( char * string, ... ) */ char *helper_string_replace_if_exists_v ( char * string, GHashTable *h ) { - GError *error = NULL; - char *res = NULL; + GError *error = NULL; + char *res = NULL; // Replace hits within {-\w+}. GRegex *reg = g_regex_new ( "\\[(.*)({[-\\w]+})(.*)\\]|({[\\w-]+})", 0, 0, &error ); - if ( error == NULL ){ + if ( error == NULL ) { res = g_regex_replace_eval ( reg, string, -1, 0, 0, helper_eval_cb2, h, &error ); } // Free regex. diff --git a/source/keyb.c b/source/keyb.c index 01adfb95..7a8c09b1 100644 --- a/source/keyb.c +++ b/source/keyb.c @@ -77,7 +77,7 @@ ActionBindingEntry rofi_bindings[] = { .id = ROW_LAST, .name = "kb-row-last", .binding = "End,KP_End", .comment = "Go to the last entry" }, { .id = ROW_SELECT, .name = "kb-row-select", .binding = "Control+space", .comment = "Set selected item as input text" }, { .id = SCREENSHOT, .name = "kb-screenshot", .binding = "Alt+S", .comment = "Take a screenshot of the rofi window" }, - { .id = CHANGE_ELLIPSIZE, .name = "kb-ellipsize", .binding = "Alt+period", .comment = "Toggle between ellipsize modes for displayed data" }, + { .id = CHANGE_ELLIPSIZE, .name = "kb-ellipsize", .binding = "Alt+period", .comment = "Toggle between ellipsize modes for displayed data" }, { .id = TOGGLE_CASE_SENSITIVITY, .name = "kb-toggle-case-sensitivity", .binding = "grave,dead_grave", .comment = "Toggle case sensitivity" }, { .id = TOGGLE_SORT, .name = "kb-toggle-sort", .binding = "Alt+grave", .comment = "Toggle sort" }, { .id = CANCEL, .name = "kb-cancel", .binding = "Escape,Control+g,Control+bracketleft", .comment = "Quit rofi" }, diff --git a/source/rofi.c b/source/rofi.c index 2d300e30..a9b5150a 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -115,11 +115,11 @@ NkBindings *bindings = NULL; GMainLoop *main_loop = NULL; /** Flag indicating we are in dmenu mode. */ -static int dmenu_mode = FALSE; +static int dmenu_mode = FALSE; /** Rofi's return code */ -int return_code = EXIT_SUCCESS; +int return_code = EXIT_SUCCESS; -static gboolean old_config_format = FALSE; +static gboolean old_config_format = FALSE; void process_result ( RofiViewState *state ); @@ -364,8 +364,8 @@ static void help_print_disabled_mode ( const char *mode ) } static void help_print_mode_not_found ( const char *mode ) { - GString *str = g_string_new (""); - g_string_printf(str, "Mode %s is not found.\nThe following modi are known:\n", mode ); + GString *str = g_string_new ( "" ); + g_string_printf ( str, "Mode %s is not found.\nThe following modi are known:\n", mode ); for ( unsigned int i = 0; i < num_available_modi; i++ ) { gboolean active = FALSE; for ( unsigned int j = 0; j < num_modi; j++ ) { @@ -374,10 +374,10 @@ static void help_print_mode_not_found ( const char *mode ) break; } } - g_string_append_printf (str, " * %s%s\n", - active ? "+" : "", - available_modi[i]->name - ); + g_string_append_printf ( str, " * %s%s\n", + active ? "+" : "", + available_modi[i]->name + ); } rofi_add_error_message ( str ); } @@ -663,7 +663,6 @@ static void show_error_dialog () rofi_view_error_dialog ( emesg->str, ERROR_MSG_MARKUP ); g_string_free ( emesg, TRUE ); rofi_set_return_code ( EX_DATAERR ); - } static gboolean startup ( G_GNUC_UNUSED gpointer data ) @@ -852,11 +851,12 @@ int main ( int argc, char *argv[] ) if ( find_arg ( "-no-config" ) < 0 ) { gchar *etc = g_build_filename ( SYSCONFDIR, "rofi.rasi", NULL ); - g_debug ( "Testing: %s", etc); + g_debug ( "Testing: %s", etc ); if ( g_file_test ( etc, G_FILE_TEST_IS_REGULAR ) ) { - g_debug ( "Parsing: %s", etc); + g_debug ( "Parsing: %s", etc ); rofi_theme_parse_file ( etc ); - } else { + } + else { // Load distro default settings gchar *xetc = g_build_filename ( SYSCONFDIR, "rofi.conf", NULL ); if ( g_file_test ( xetc, G_FILE_TEST_IS_REGULAR ) ) { @@ -896,7 +896,7 @@ int main ( int argc, char *argv[] ) TICK_N ( "Load cmd config " ); if ( old_config_format ) { - g_warning ( "The old Xresources based configuration format is deprecated."); + g_warning ( "The old Xresources based configuration format is deprecated." ); g_warning ( "Please upgrade: rofi -upgrade-config." ); } parse_keys_abe ( bindings ); @@ -975,9 +975,8 @@ int main ( int argc, char *argv[] ) cleanup (); return EXIT_SUCCESS; } - if ( find_arg ( "-upgrade-config") >= 0 ) { - - setup_modi(); + if ( find_arg ( "-upgrade-config" ) >= 0 ) { + setup_modi (); for ( unsigned int i = 0; i < num_modi; i++ ) { mode_init ( modi[i] ); @@ -986,7 +985,7 @@ int main ( int argc, char *argv[] ) const char *cpath = g_get_user_config_dir (); if ( cpath ) { char *fcpath = g_build_filename ( cpath, "rofi", NULL ); - if ( !g_file_test ( fcpath, G_FILE_TEST_IS_DIR ) && g_mkdir_with_parents ( fcpath, 0700) < 0 ) { + if ( !g_file_test ( fcpath, G_FILE_TEST_IS_DIR ) && g_mkdir_with_parents ( fcpath, 0700 ) < 0 ) { g_warning ( "Failed to create rofi configuration directory: %s", fcpath ); cleanup (); g_free ( fcpath ); @@ -1000,20 +999,21 @@ int main ( int argc, char *argv[] ) g_free ( fcpath ); return EXIT_FAILURE; } - FILE *fd = fopen(fcpath, "w" ); + FILE *fd = fopen ( fcpath, "w" ); if ( fd == NULL ) { - g_warning ( "Failed to open new rofi configuration file: %s: %s", fcpath , strerror(errno)); + g_warning ( "Failed to open new rofi configuration file: %s: %s", fcpath, strerror ( errno ) ); cleanup (); g_free ( fcpath ); return EXIT_FAILURE; } config_parse_dump_config_rasi_format ( fd, TRUE ); - fprintf(stdout, "\n***** Generated configuration file in: %s *****\n", fcpath ); + fprintf ( stdout, "\n***** Generated configuration file in: %s *****\n", fcpath ); fflush ( fd ); fclose ( fd ); - g_free( fcpath ); - } else { + g_free ( fcpath ); + } + else { g_warning ( "Failed to get user configuration directory." ); cleanup (); return EXIT_FAILURE; diff --git a/source/theme.c b/source/theme.c index 79b55bca..51bb2236 100644 --- a/source/theme.c +++ b/source/theme.c @@ -96,8 +96,8 @@ Property* rofi_theme_property_copy ( Property *p ) case P_LINK: retv->value.link.name = g_strdup ( p->value.link.name ); retv->value.link.ref = NULL; - if ( p->value.link.def_value ){ - retv->value.link.def_value = rofi_theme_property_copy(p->value.link.def_value); + if ( p->value.link.def_value ) { + retv->value.link.def_value = rofi_theme_property_copy ( p->value.link.def_value ); } break; default: @@ -129,49 +129,44 @@ void rofi_theme_property_free ( Property *p ) */ static void rofi_theme_insert_listview_backwards_fix ( void ) { - GHashTable *table= g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); - ThemeWidget *t = rofi_theme_find_or_create_name ( rofi_theme, "element" ); - ThemeWidget *tt = rofi_theme_find_or_create_name ( rofi_theme, "element-text" ); - ThemeWidget *ti = rofi_theme_find_or_create_name ( rofi_theme, "element-icon" ); + GHashTable *table = g_hash_table_new_full ( g_str_hash, g_str_equal, NULL, (GDestroyNotify) rofi_theme_property_free ); + ThemeWidget *t = rofi_theme_find_or_create_name ( rofi_theme, "element" ); + ThemeWidget *tt = rofi_theme_find_or_create_name ( rofi_theme, "element-text" ); + ThemeWidget *ti = rofi_theme_find_or_create_name ( rofi_theme, "element-icon" ); // Inherit text color Property *ptc = rofi_theme_property_create ( P_INHERIT ); - ptc->name = g_strdup("text-color"); + ptc->name = g_strdup ( "text-color" ); g_hash_table_replace ( table, ptc->name, ptc ); // Transparent background Property *ptb = rofi_theme_property_create ( P_COLOR ); - ptb->name = g_strdup("background-color"); + ptb->name = g_strdup ( "background-color" ); ptb->value.color.red = 0.0; ptb->value.color.green = 0.0; ptb->value.color.blue = 0.0; ptb->value.color.alpha = 0.0; g_hash_table_replace ( table, ptb->name, ptb ); + rofi_theme_widget_add_properties ( tt, table ); - rofi_theme_widget_add_properties ( tt, table); - - - RofiDistance dsize = (RofiDistance){1.2, ROFI_PU_CH, ROFI_HL_SOLID }; - Property *pts = rofi_theme_property_create ( P_PADDING ); + RofiDistance dsize = (RofiDistance){ 1.2, ROFI_PU_CH, 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" ); + pts->name = g_strdup ( "size" ); g_hash_table_replace ( table, pts->name, pts ); - - rofi_theme_widget_add_properties ( ti, table); + rofi_theme_widget_add_properties ( ti, table ); /** Add spacing between icon and text. */ g_hash_table_destroy ( table ); - 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){5, ROFI_PU_PX, ROFI_HL_SOLID }; - psp->value.padding = (RofiPadding){d,d,d,d}; + 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){ 5, ROFI_PU_PX, 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); + rofi_theme_widget_add_properties ( t, table ); g_hash_table_destroy ( table ); - - } void rofi_theme_reset ( void ) @@ -247,102 +242,102 @@ static void int_rofi_theme_print_property ( Property *p ) { switch ( p->type ) { - case P_LIST: - printf ( "[ " ); - for ( GList *iter = p->value.list; iter != NULL; iter = g_list_next ( iter ) ) { - printf ( "%s", (char *) ( iter->data ) ); - if ( iter->next != NULL ) { - printf ( "," ); - } + case P_LIST: + printf ( "[ " ); + for ( GList *iter = p->value.list; iter != NULL; iter = g_list_next ( iter ) ) { + printf ( "%s", (char *) ( iter->data ) ); + if ( iter->next != NULL ) { + printf ( "," ); } - printf ( " ]" ); - break; - case P_ORIENTATION: - printf ( "%s", ( p->value.i == ROFI_ORIENTATION_HORIZONTAL ) ? "horizontal" : "vertical" ); - break; - case P_HIGHLIGHT: - if ( p->value.highlight.style & ROFI_HL_BOLD ) { - printf ( "bold " ); - } - if ( p->value.highlight.style & ROFI_HL_UNDERLINE ) { - printf ( "underline " ); - } - if ( p->value.highlight.style & ROFI_HL_STRIKETHROUGH ) { - printf ( "strikethrough " ); - } - if ( p->value.highlight.style & ROFI_HL_ITALIC ) { - printf ( "italic " ); - } - if ( p->value.highlight.style & ROFI_HL_COLOR ) { - printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", - ( p->value.highlight.color.red * 255.0 ), - ( p->value.highlight.color.green * 255.0 ), - ( p->value.highlight.color.blue * 255.0 ), - ( p->value.highlight.color.alpha * 100.0 ) ); - } - break; - case P_POSITION: - printf ( "%s", WindowLocationStr[p->value.i] ); - break; - case P_STRING: - printf ( "\"%s\"", p->value.s ); - break; - case P_INTEGER: - printf ( "%d", p->value.i ); - break; - case P_DOUBLE: - printf ( "%.2f", p->value.f ); - break; - case P_BOOLEAN: - printf ( "%s", p->value.b ? "true" : "false" ); - break; - case P_COLOR: + } + printf ( " ]" ); + break; + case P_ORIENTATION: + printf ( "%s", ( p->value.i == ROFI_ORIENTATION_HORIZONTAL ) ? "horizontal" : "vertical" ); + break; + case P_HIGHLIGHT: + if ( p->value.highlight.style & ROFI_HL_BOLD ) { + printf ( "bold " ); + } + if ( p->value.highlight.style & ROFI_HL_UNDERLINE ) { + printf ( "underline " ); + } + if ( p->value.highlight.style & ROFI_HL_STRIKETHROUGH ) { + printf ( "strikethrough " ); + } + if ( p->value.highlight.style & ROFI_HL_ITALIC ) { + printf ( "italic " ); + } + if ( p->value.highlight.style & ROFI_HL_COLOR ) { printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", - ( p->value.color.red * 255.0 ), - ( p->value.color.green * 255.0 ), - ( p->value.color.blue * 255.0 ), - ( p->value.color.alpha * 100.0 ) ); - break; - case P_PADDING: - if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && - distance_compare ( p->value.padding.left, p->value.padding.right ) && - distance_compare ( p->value.padding.left, p->value.padding.top ) ) { - rofi_theme_print_distance ( p->value.padding.left ); - } - else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && - distance_compare ( p->value.padding.left, p->value.padding.right ) ) { - rofi_theme_print_distance ( p->value.padding.top ); - rofi_theme_print_distance ( p->value.padding.left ); - } - else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom ) && - distance_compare ( p->value.padding.left, p->value.padding.right ) ) { - rofi_theme_print_distance ( p->value.padding.top ); - rofi_theme_print_distance ( p->value.padding.left ); - rofi_theme_print_distance ( p->value.padding.bottom ); - } - else { - rofi_theme_print_distance ( p->value.padding.top ); - rofi_theme_print_distance ( p->value.padding.right ); - rofi_theme_print_distance ( p->value.padding.bottom ); - rofi_theme_print_distance ( p->value.padding.left ); - } - break; - case P_LINK: - if ( p->value.link.def_value) { - printf( "var( %s, ", p->value.link.name ); - int_rofi_theme_print_property ( p->value.link.def_value ); - printf (")"); - }else { - printf ( "var(%s)", p->value.link.name ); - } - break; - case P_INHERIT: - printf ( "inherit" ); - break; - default: - break; + ( p->value.highlight.color.red * 255.0 ), + ( p->value.highlight.color.green * 255.0 ), + ( p->value.highlight.color.blue * 255.0 ), + ( p->value.highlight.color.alpha * 100.0 ) ); + } + break; + case P_POSITION: + printf ( "%s", WindowLocationStr[p->value.i] ); + break; + case P_STRING: + printf ( "\"%s\"", p->value.s ); + break; + case P_INTEGER: + printf ( "%d", p->value.i ); + break; + case P_DOUBLE: + printf ( "%.2f", p->value.f ); + break; + case P_BOOLEAN: + printf ( "%s", p->value.b ? "true" : "false" ); + break; + case P_COLOR: + printf ( "rgba ( %.0f, %.0f, %.0f, %.0f %% )", + ( p->value.color.red * 255.0 ), + ( p->value.color.green * 255.0 ), + ( p->value.color.blue * 255.0 ), + ( p->value.color.alpha * 100.0 ) ); + break; + case P_PADDING: + if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && + distance_compare ( p->value.padding.left, p->value.padding.right ) && + distance_compare ( p->value.padding.left, p->value.padding.top ) ) { + rofi_theme_print_distance ( p->value.padding.left ); + } + else if ( distance_compare ( p->value.padding.top, p->value.padding.bottom ) && + distance_compare ( p->value.padding.left, p->value.padding.right ) ) { + rofi_theme_print_distance ( p->value.padding.top ); + rofi_theme_print_distance ( p->value.padding.left ); + } + else if ( !distance_compare ( p->value.padding.top, p->value.padding.bottom ) && + distance_compare ( p->value.padding.left, p->value.padding.right ) ) { + rofi_theme_print_distance ( p->value.padding.top ); + rofi_theme_print_distance ( p->value.padding.left ); + rofi_theme_print_distance ( p->value.padding.bottom ); + } + else { + rofi_theme_print_distance ( p->value.padding.top ); + rofi_theme_print_distance ( p->value.padding.right ); + rofi_theme_print_distance ( p->value.padding.bottom ); + rofi_theme_print_distance ( p->value.padding.left ); + } + break; + case P_LINK: + if ( p->value.link.def_value ) { + printf ( "var( %s, ", p->value.link.name ); + int_rofi_theme_print_property ( p->value.link.def_value ); + printf ( ")" ); + } + else { + printf ( "var(%s)", p->value.link.name ); + } + break; + case P_INHERIT: + printf ( "inherit" ); + break; + default: + break; } - } static void rofi_theme_print_property_index ( size_t pnl, int depth, Property *p ) @@ -518,7 +513,7 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth ) { // Set name, remove '@' prefix. const char *name = p->value.link.name;// + (*(p->value.link.name)== '@'?1:0; - g_info ( "Resolving link to %s", p->value.link.name); + g_info ( "Resolving link to %s", p->value.link.name ); if ( depth > 20 ) { g_warning ( "Found more then 20 redirects for property. Stopping." ); p->value.link.ref = p; @@ -527,7 +522,7 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth ) if ( rofi_theme->properties && g_hash_table_contains ( rofi_theme->properties, name ) ) { Property *pr = g_hash_table_lookup ( rofi_theme->properties, name ); - g_info ("Resolving link %s found: %s", p->value.link.name, pr->name); + g_info ( "Resolving link %s found: %s", p->value.link.name, pr->name ); if ( pr->type == P_LINK ) { if ( pr->value.link.ref == NULL ) { rofi_theme_resolve_link_property ( pr, depth + 1 ); @@ -543,7 +538,7 @@ static void rofi_theme_resolve_link_property ( Property *p, int depth ) } } // No found and we have default value. - if ( p->value.link.def_value ){ + if ( p->value.link.def_value ) { p->value.link.ref = p->value.link.def_value; return; } @@ -1022,21 +1017,20 @@ char * rofi_theme_parse_prepare_file ( const char *file, const char *parent_file return filename; } - void rofi_theme_parse_merge_widgets ( ThemeWidget *parent, ThemeWidget *child ) { g_assert ( parent != NULL ); g_assert ( child != NULL ); - if ( parent == rofi_theme && g_strcmp0(child->name, "*") == 0 ){ - rofi_theme_widget_add_properties ( parent, child->properties); + if ( parent == rofi_theme && g_strcmp0 ( child->name, "*" ) == 0 ) { + rofi_theme_widget_add_properties ( parent, child->properties ); return; } - ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name); - rofi_theme_widget_add_properties ( w, child->properties); - for ( unsigned int i =0; i < child->num_widgets; i++) { - rofi_theme_parse_merge_widgets ( w, child->widgets[i]); + ThemeWidget *w = rofi_theme_find_or_create_name ( parent, child->name ); + rofi_theme_widget_add_properties ( w, child->properties ); + for ( unsigned int i = 0; i < child->num_widgets; i++ ) { + rofi_theme_parse_merge_widgets ( w, child->widgets[i] ); } } @@ -1044,108 +1038,114 @@ void rofi_theme_parse_process_conditionals ( void ) { workarea mon; monitor_active ( &mon ); - if ( rofi_theme == NULL ) return; + if ( rofi_theme == NULL ) { + return; + } for ( unsigned int i = 0; i < rofi_theme->num_widgets; i++ ) { - ThemeWidget *widget = rofi_theme->widgets[i]; - if ( widget->media != NULL ) { - switch ( widget->media->type ) - { - case THEME_MEDIA_TYPE_MIN_WIDTH: - { - int w = widget->media->value; - if ( mon.w >= w ){ - for ( unsigned int x =0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); - } - } - break; - } - case THEME_MEDIA_TYPE_MAX_WIDTH: - { - int w = widget->media->value; - if ( mon.w < w ){ - for ( unsigned int x =0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); - } - } - break; - } - case THEME_MEDIA_TYPE_MIN_HEIGHT: - { - int h = widget->media->value; - if ( mon.h >= h ){ - for ( unsigned int x =0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); - } - } - break; - } - case THEME_MEDIA_TYPE_MAX_HEIGHT: - { - int h = widget->media->value; - if ( mon.h < h ){ - for ( unsigned int x =0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); - } - } - break; - } - case THEME_MEDIA_TYPE_MON_ID: - { - if ( mon.monitor_id == widget->media->value ){ - for ( unsigned int x =0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); - } - } - break; - } - case THEME_MEDIA_TYPE_MIN_ASPECT_RATIO: - { - double r = widget->media->value; - if ( (mon.w/(double)mon.h) >= r ){ - for ( unsigned int x =0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); - } - } - break; - } - case THEME_MEDIA_TYPE_MAX_ASPECT_RATIO: - { - double r = widget->media->value; - if ( (mon.w/(double)mon.h) < r ){ - for ( unsigned int x =0; x < widget->num_widgets; x++) { - rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); - } - } - break; - } - default: - { - break; - } + ThemeWidget *widget = rofi_theme->widgets[i]; + if ( widget->media != NULL ) { + switch ( widget->media->type ) + { + case THEME_MEDIA_TYPE_MIN_WIDTH: + { + int w = widget->media->value; + if ( mon.w >= w ) { + for ( unsigned int x = 0; x < widget->num_widgets; x++ ) { + rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); + } } + break; } + case THEME_MEDIA_TYPE_MAX_WIDTH: + { + int w = widget->media->value; + if ( mon.w < w ) { + for ( unsigned int x = 0; x < widget->num_widgets; x++ ) { + rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); + } + } + break; + } + case THEME_MEDIA_TYPE_MIN_HEIGHT: + { + int h = widget->media->value; + if ( mon.h >= h ) { + for ( unsigned int x = 0; x < widget->num_widgets; x++ ) { + rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); + } + } + break; + } + case THEME_MEDIA_TYPE_MAX_HEIGHT: + { + int h = widget->media->value; + if ( mon.h < h ) { + for ( unsigned int x = 0; x < widget->num_widgets; x++ ) { + rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); + } + } + break; + } + case THEME_MEDIA_TYPE_MON_ID: + { + if ( mon.monitor_id == widget->media->value ) { + for ( unsigned int x = 0; x < widget->num_widgets; x++ ) { + rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); + } + } + break; + } + case THEME_MEDIA_TYPE_MIN_ASPECT_RATIO: + { + double r = widget->media->value; + if ( ( mon.w / (double) mon.h ) >= r ) { + for ( unsigned int x = 0; x < widget->num_widgets; x++ ) { + rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); + } + } + break; + } + case THEME_MEDIA_TYPE_MAX_ASPECT_RATIO: + { + double r = widget->media->value; + if ( ( mon.w / (double) mon.h ) < r ) { + for ( unsigned int x = 0; x < widget->num_widgets; x++ ) { + rofi_theme_parse_merge_widgets ( rofi_theme, widget->widgets[x] ); + } + } + break; + } + default: + { + break; + } + } + } } } - ThemeMediaType rofi_theme_parse_media_type ( const char *type ) { - if ( g_strcmp0( type, "monitor-id" ) == 0 ) { + if ( g_strcmp0 ( type, "monitor-id" ) == 0 ) { return THEME_MEDIA_TYPE_MON_ID; - } else if ( g_strcmp0 ( type, "min-width") == 0 ) { + } + else if ( g_strcmp0 ( type, "min-width" ) == 0 ) { return THEME_MEDIA_TYPE_MIN_WIDTH; - } else if ( g_strcmp0 ( type, "min-height") == 0 ) { + } + else if ( g_strcmp0 ( type, "min-height" ) == 0 ) { return THEME_MEDIA_TYPE_MIN_HEIGHT; - } else if ( g_strcmp0 ( type, "max-width") == 0 ) { + } + else if ( g_strcmp0 ( type, "max-width" ) == 0 ) { return THEME_MEDIA_TYPE_MAX_WIDTH; - } else if ( g_strcmp0 ( type, "max-height") == 0 ) { + } + else if ( g_strcmp0 ( type, "max-height" ) == 0 ) { return THEME_MEDIA_TYPE_MAX_HEIGHT; - } else if ( g_strcmp0 ( type, "min-aspect-ratio") == 0 ) { + } + else if ( g_strcmp0 ( type, "min-aspect-ratio" ) == 0 ) { return THEME_MEDIA_TYPE_MIN_ASPECT_RATIO; - } else if ( g_strcmp0 ( type, "max-aspect-ratio") == 0 ) { + } + else if ( g_strcmp0 ( type, "max-aspect-ratio" ) == 0 ) { return THEME_MEDIA_TYPE_MAX_ASPECT_RATIO; } return THEME_MEDIA_TYPE_INVALID; } - diff --git a/source/timings.c b/source/timings.c index 410592b2..db004656 100644 --- a/source/timings.c +++ b/source/timings.c @@ -35,7 +35,7 @@ /** * Timer used to calculate time stamps. */ -GTimer *global_timer = NULL; +GTimer *global_timer = NULL; /** * Last timestamp made. */ @@ -58,8 +58,7 @@ void rofi_timings_tick ( const char *file, char const *str, int line, char const void rofi_timings_quit ( void ) { - double now = g_timer_elapsed ( global_timer, NULL ); - g_debug ( "%4.6f (%2.6f): Stopped", now, 0.0 ); - g_timer_destroy ( global_timer ); + double now = g_timer_elapsed ( global_timer, NULL ); + g_debug ( "%4.6f (%2.6f): Stopped", now, 0.0 ); + g_timer_destroy ( global_timer ); } - diff --git a/source/view.c b/source/view.c index 05fbae23..3f3b6319 100644 --- a/source/view.c +++ b/source/view.c @@ -926,14 +926,14 @@ inline static void rofi_view_nav_last ( RofiViewState * state ) listview_set_selected ( state->list_view, -1 ); } -static void update_callback ( textbox *t,icon *ico, unsigned int index, void *udata, TextBoxFontType *type, gboolean full ) +static void update_callback ( textbox *t, icon *ico, unsigned int index, void *udata, TextBoxFontType *type, gboolean full ) { RofiViewState *state = (RofiViewState *) udata; if ( full ) { GList *add_list = NULL; int fstate = 0; char *text = mode_get_display_value ( state->sw, state->line_map[index], &fstate, &add_list, TRUE ); - (*type) |= fstate; + ( *type ) |= fstate; // TODO needed for markup. textbox_font ( t, *type ); // Move into list view. @@ -945,9 +945,9 @@ static void update_callback ( textbox *t,icon *ico, unsigned int index, void *ud else{ list = pango_attr_list_new (); } - if( ico ) { - int icon_height = widget_get_desired_height( WIDGET(ico) ); - cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height ); + if ( ico ) { + int icon_height = widget_get_desired_height ( WIDGET ( ico ) ); + cairo_surface_t *icon = mode_get_icon ( state->sw, state->line_map[index], icon_height ); icon_set_surface ( ico, icon ); } @@ -967,7 +967,7 @@ static void update_callback ( textbox *t,icon *ico, unsigned int index, void *ud else { int fstate = 0; mode_get_display_value ( state->sw, state->line_map[index], &fstate, NULL, FALSE ); - (*type) |= fstate; + ( *type ) |= fstate; // TODO needed for markup. textbox_font ( t, *type ); } @@ -1030,12 +1030,12 @@ static void rofi_view_refilter ( RofiViewState *state ) _rofi_view_reload_row ( state ); state->reload = FALSE; } - TICK_N ("Filter reload rows"); + TICK_N ( "Filter reload rows" ); if ( state->tokens ) { helper_tokenize_free ( state->tokens ); state->tokens = NULL; } - TICK_N ("Filter tokenize"); + TICK_N ( "Filter tokenize" ); if ( state->text && strlen ( state->text->text ) > 0 ) { unsigned int j = 0; gchar *pattern = mode_preprocess_input ( state->sw, state->text->text ); @@ -1102,22 +1102,20 @@ static void rofi_view_refilter ( RofiViewState *state ) } state->filtered_lines = state->num_lines; } - TICK_N ("Filter matching done"); + TICK_N ( "Filter matching done" ); listview_set_num_elements ( state->list_view, state->filtered_lines ); if ( state->tb_filtered_rows ) { - char *r = g_strdup_printf("%u", state->filtered_lines); - textbox_text( state->tb_filtered_rows, r ); - g_free(r); + char *r = g_strdup_printf ( "%u", state->filtered_lines ); + textbox_text ( state->tb_filtered_rows, r ); + g_free ( r ); } - if ( state->tb_total_rows ) { - char *r = g_strdup_printf("%u", state->num_lines); - textbox_text( state->tb_total_rows, r ); - g_free(r); + if ( state->tb_total_rows ) { + char *r = g_strdup_printf ( "%u", state->num_lines ); + textbox_text ( state->tb_total_rows, r ); + g_free ( r ); } - TICK_N ("Update filter lines"); - - + TICK_N ( "Update filter lines" ); if ( config.auto_select == TRUE && state->filtered_lines == 1 && state->num_lines > 1 ) { ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; @@ -1133,7 +1131,7 @@ static void rofi_view_refilter ( RofiViewState *state ) rofi_view_window_update_size ( state ); g_debug ( "Resize based on re-filter" ); } - TICK_N ("Filter resize window based on window "); + TICK_N ( "Filter resize window based on window " ); state->refilter = FALSE; TICK_N ( "Filter done" ); } @@ -1528,25 +1526,29 @@ static WidgetTriggerActionResult textbox_button_trigger_action ( widget *wid, Mo switch ( action ) { case MOUSE_CLICK_DOWN: - { - const char * type = rofi_theme_get_string ( wid, "action", "ok" ); - ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; - if ( strcmp(type, "ok") == 0 ) { - state->retv = MENU_OK; - } else if ( strcmp ( type, "ok|alternate" ) == 0 ) { - state->retv = MENU_CUSTOM_ACTION|MENU_OK; - } else if ( strcmp ( type, "custom") ) { - state->retv = MENU_CUSTOM_INPUT; - } else if ( strcmp ( type, "custom|alternate" ) == 0 ) { - state->retv = MENU_CUSTOM_ACTION|MENU_CUSTOM_INPUT; - } else { - g_warning("Invalid action specified."); - return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; - } - state->quit = TRUE; - state->skip_absorb = TRUE; - return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; + { + const char * type = rofi_theme_get_string ( wid, "action", "ok" ); + ( state->selected_line ) = state->line_map[listview_get_selected ( state->list_view )]; + if ( strcmp ( type, "ok" ) == 0 ) { + state->retv = MENU_OK; } + else if ( strcmp ( type, "ok|alternate" ) == 0 ) { + state->retv = MENU_CUSTOM_ACTION | MENU_OK; + } + else if ( strcmp ( type, "custom" ) ) { + state->retv = MENU_CUSTOM_INPUT; + } + else if ( strcmp ( type, "custom|alternate" ) == 0 ) { + state->retv = MENU_CUSTOM_ACTION | MENU_CUSTOM_INPUT; + } + else { + g_warning ( "Invalid action specified." ); + return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; + } + state->quit = TRUE; + state->skip_absorb = TRUE; + return WIDGET_TRIGGER_ACTION_RESULT_HANDLED; + } case MOUSE_CLICK_UP: case MOUSE_DCLICK_DOWN: case MOUSE_DCLICK_UP: @@ -1609,7 +1611,8 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, box_add ( (box *) parent_widget, WIDGET ( wid ), TRUE ); if ( config.sidebar_mode ) { defaults = "inputbar,message,listview,mode-switcher"; - } else { + } + else { defaults = "inputbar,message,listview"; } } @@ -1635,14 +1638,14 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, box_add ( (box *) parent_widget, WIDGET ( state->prompt ), FALSE ); defaults = NULL; } - else if ( strcmp ( name, "num-rows" ) == 0 ){ - state->tb_total_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); + else if ( strcmp ( name, "num-rows" ) == 0 ) { + state->tb_total_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); box_add ( (box *) parent_widget, WIDGET ( state->tb_total_rows ), FALSE ); defaults = NULL; } - else if ( strcmp ( name, "num-filtered-rows" ) == 0 ){ - state->tb_filtered_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH|TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); - box_add ( (box *) parent_widget, WIDGET ( state->tb_filtered_rows), FALSE ); + else if ( strcmp ( name, "num-filtered-rows" ) == 0 ) { + state->tb_filtered_rows = textbox_create ( parent_widget, WIDGET_TYPE_TEXTBOX_TEXT, name, TB_AUTOWIDTH | TB_AUTOHEIGHT, NORMAL, "", 0, 0 ); + box_add ( (box *) parent_widget, WIDGET ( state->tb_filtered_rows ), FALSE ); defaults = NULL; } /** @@ -1720,14 +1723,14 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, for ( unsigned int j = 0; j < state->num_modi; j++ ) { const Mode * mode = rofi_get_mode ( j ); state->modi[j] = textbox_create ( WIDGET ( state->sidebar_bar ), WIDGET_TYPE_MODE_SWITCHER, "button", TB_AUTOHEIGHT, ( mode == state->sw ) ? HIGHLIGHT : NORMAL, - mode_get_display_name ( mode ), 0.5, 0.5 ); + mode_get_display_name ( mode ), 0.5, 0.5 ); box_add ( state->sidebar_bar, WIDGET ( state->modi[j] ), TRUE ); widget_set_trigger_action_handler ( WIDGET ( state->modi[j] ), textbox_sidebar_modi_trigger_action, state ); } } else if ( g_ascii_strcasecmp ( name, "overlay" ) == 0 ) { state->overlay = textbox_create ( WIDGET ( parent_widget ), WIDGET_TYPE_TEXTBOX_TEXT, "overlay", TB_AUTOWIDTH | TB_AUTOHEIGHT, URGENT, "blaat", 0.5, 0 ); - box_add ( (box *) parent_widget, WIDGET ( state->overlay), FALSE ); + box_add ( (box *) parent_widget, WIDGET ( state->overlay ), FALSE ); widget_disable ( WIDGET ( state->overlay ) ); } else if ( g_ascii_strncasecmp ( name, "textbox", 7 ) == 0 ) { @@ -1780,10 +1783,11 @@ RofiViewState *rofi_view_create ( Mode *sw, state->num_lines = mode_get_num_entries ( sw ); if ( state->sw ) { - char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name (state->sw ) ); + char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name ( state->sw ) ); rofi_view_set_window_title ( title ); g_free ( title ); - } else { + } + else { rofi_view_set_window_title ( "rofi" ); } TICK_N ( "Startup notification" ); @@ -1804,7 +1808,6 @@ RofiViewState *rofi_view_create ( Mode *sw, textbox_cursor_end ( state->text ); } - // filtered list state->line_map = g_malloc0_n ( state->num_lines, sizeof ( unsigned int ) ); state->distance = (int *) g_malloc0_n ( state->num_lines, sizeof ( int ) ); @@ -1993,10 +1996,11 @@ void rofi_view_switch_mode ( RofiViewState *state, Mode *mode ) rofi_view_update_prompt ( state ); } if ( state->sw ) { - char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name (state->sw ) ); + char * title = g_strdup_printf ( "rofi - %s", mode_get_display_name ( state->sw ) ); rofi_view_set_window_title ( title ); g_free ( title ); - } else { + } + else { rofi_view_set_window_title ( "rofi" ); } if ( state->sidebar_bar ) { @@ -2019,7 +2023,7 @@ xcb_window_t rofi_view_get_window ( void ) void rofi_view_set_window_title ( const char * title ) { - ssize_t len = strlen(title); + ssize_t len = strlen ( title ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, xcb->ewmh._NET_WM_NAME, xcb->ewmh.UTF8_STRING, 8, len, title ); xcb_change_property ( xcb->connection, XCB_PROP_MODE_REPLACE, CacheState.main_window, XCB_ATOM_WM_NAME, XCB_ATOM_STRING, 8, len, title ); } diff --git a/source/widgets/icon.c b/source/widgets/icon.c index eca441b4..190041b9 100644 --- a/source/widgets/icon.c +++ b/source/widgets/icon.c @@ -46,7 +46,7 @@ struct _icon uint32_t icon_fetch_id; - double yalign,xalign; + double yalign, xalign; // Source surface. cairo_surface_t *icon; @@ -85,16 +85,16 @@ static void icon_draw ( widget *wid, cairo_t *draw ) int icons = MAX ( iconh, iconw ); double scale = (double) b->size / icons; - int lpad = widget_padding_get_left ( WIDGET ( b ) ) ; - int rpad = widget_padding_get_right ( WIDGET ( b ) ) ; - int tpad = widget_padding_get_top ( WIDGET ( b ) ) ; - int bpad = widget_padding_get_bottom ( WIDGET ( b ) ) ; + int lpad = widget_padding_get_left ( WIDGET ( b ) ); + int rpad = widget_padding_get_right ( WIDGET ( b ) ); + int tpad = widget_padding_get_top ( WIDGET ( b ) ); + int bpad = widget_padding_get_bottom ( WIDGET ( b ) ); cairo_save ( draw ); cairo_translate ( draw, - lpad + ( b->widget.w - iconw * scale - lpad -rpad )*b->xalign, - tpad + ( b->widget.h- iconh * scale -tpad - bpad )*b->yalign ); + lpad + ( b->widget.w - iconw * scale - lpad - rpad ) * b->xalign, + tpad + ( b->widget.h - iconh * scale - tpad - bpad ) * b->yalign ); cairo_scale ( draw, scale, scale ); cairo_set_source_surface ( draw, b->icon, 0, 0 ); cairo_paint ( draw ); @@ -149,7 +149,7 @@ icon * icon_create ( widget *parent, const char *name ) b->widget.get_desired_height = icon_get_desired_height; b->widget.get_desired_width = icon_get_desired_width; - RofiDistance d = rofi_theme_get_distance ( WIDGET (b), "size" , b->size ); + RofiDistance d = rofi_theme_get_distance ( WIDGET ( b ), "size", b->size ); b->size = distance_get_pixel ( d, ROFI_ORIENTATION_VERTICAL ); const char * filename = rofi_theme_get_string ( WIDGET ( b ), "filename", NULL ); diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 1bd6289d..f1eb4197 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -62,11 +62,12 @@ typedef enum RIGHT_TO_LEFT = 1 } MoveDirection; -typedef struct { - box *box; - textbox *textbox; - textbox *index; - icon *icon; +typedef struct +{ + box *box; + textbox *textbox; + textbox *index; + icon *icon; } _listview_row; struct _listview @@ -121,7 +122,6 @@ struct _listview char *listview_name; - PangoEllipsizeMode emode; /** Barview */ struct @@ -170,45 +170,46 @@ static void listview_set_style ( widget *w, TextBoxFontType tbft ) static void listview_create_row ( listview *lv, _listview_row *row ) { TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0; - row->box = box_create ( WIDGET ( lv ), "element",ROFI_ORIENTATION_HORIZONTAL ); - widget_set_type ( WIDGET(row->box), WIDGET_TYPE_LISTVIEW_ELEMENT); - GList *list = rofi_theme_get_list ( WIDGET(row->box), "children", "element-icon,element-text"); + row->box = box_create ( WIDGET ( lv ), "element", ROFI_ORIENTATION_HORIZONTAL ); + widget_set_type ( WIDGET ( row->box ), WIDGET_TYPE_LISTVIEW_ELEMENT ); + GList *list = rofi_theme_get_list ( WIDGET ( row->box ), "children", "element-icon,element-text" ); row->textbox = NULL; row->icon = NULL; row->index = NULL; - for ( GList *iter = g_list_first(list); iter != NULL;iter = g_list_next(iter)){ - if ( strcasecmp((char *)iter->data, "element-icon") == 0 ) { + for ( GList *iter = g_list_first ( list ); iter != NULL; iter = g_list_next ( iter ) ) { + if ( strcasecmp ( (char *) iter->data, "element-icon" ) == 0 ) { if ( config.show_icons ) { row->icon = icon_create ( WIDGET ( row->box ), "element-icon" ); - box_add ( row->box, WIDGET ( row->icon ), FALSE); + box_add ( row->box, WIDGET ( row->icon ), FALSE ); } - } else if ( strcasecmp ((char *)iter->data, "element-text") == 0 ){ - row->textbox= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT|flags, NORMAL, "DDD", 0, 0 ); - box_add ( row->box, WIDGET ( row->textbox ), TRUE); - } else if ( strcasecmp ( (char*)iter->data, "element-index" ) == 0 ){ - row->index= textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT, NORMAL, " ", 0, 0 ); - box_add ( row->box, WIDGET ( row->index ), FALSE); + } + else if ( strcasecmp ( (char *) iter->data, "element-text" ) == 0 ) { + row->textbox = textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT | flags, NORMAL, "DDD", 0, 0 ); + box_add ( row->box, WIDGET ( row->textbox ), TRUE ); + } + else if ( strcasecmp ( (char*) iter->data, "element-index" ) == 0 ) { + row->index = textbox_create ( WIDGET ( row->box ), WIDGET_TYPE_TEXTBOX_TEXT, "element-text", TB_AUTOHEIGHT, NORMAL, " ", 0, 0 ); + box_add ( row->box, WIDGET ( row->index ), FALSE ); } } g_list_free_full ( list, g_free ); } - static void listview_set_state ( _listview_row r, TextBoxFontType type ) { - listview_set_style ( WIDGET(r.box), type); + listview_set_style ( WIDGET ( r.box ), type ); if ( r.textbox ) { - listview_set_style ( WIDGET(r.textbox), type); + listview_set_style ( WIDGET ( r.textbox ), type ); } if ( r.index ) { - listview_set_style ( WIDGET(r.index), type); + listview_set_style ( WIDGET ( r.index ), type ); } if ( r.icon ) { - listview_set_style ( WIDGET(r.icon), type); + listview_set_style ( WIDGET ( r.icon ), type ); } - widget_queue_redraw ( WIDGET( r.box ) ); + widget_queue_redraw ( WIDGET ( r.box ) ); } static int listview_get_desired_height ( widget *wid ); @@ -292,18 +293,19 @@ static void update_element ( listview *lv, unsigned int tb, unsigned int index, if ( lv->boxes[tb].index ) { if ( index < 10 ) { - char str[2] = { - ((index+1)%10)+'0', + char str[2] = { + ( ( index + 1 ) % 10 ) + '0', '\0' }; - textbox_text( lv->boxes[tb].index, str ); - } else { - textbox_text( lv->boxes[tb].index, " " ); + textbox_text ( lv->boxes[tb].index, str ); + } + else { + textbox_text ( lv->boxes[tb].index, " " ); } } if ( lv->callback ) { lv->callback ( lv->boxes[tb].textbox, lv->boxes[tb].icon, index, lv->udata, &type, full ); - listview_set_state ( lv->boxes[tb], type); + listview_set_state ( lv->boxes[tb], type ); } } @@ -336,8 +338,8 @@ static void barview_draw ( widget *wid, cairo_t *draw ) } twidth = width; } - widget_move ( WIDGET(lv->boxes[i].box), left_offset, top_offset); - widget_resize ( WIDGET (lv->boxes[i].box), twidth, lv->element_height); + widget_move ( WIDGET ( lv->boxes[i].box ), left_offset, top_offset ); + widget_resize ( WIDGET ( lv->boxes[i].box ), twidth, lv->element_height ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); width -= twidth + spacing_hori; @@ -357,8 +359,8 @@ static void barview_draw ( widget *wid, cairo_t *draw ) twidth = width; } right_offset -= twidth; - widget_move ( WIDGET(lv->boxes[i].box), right_offset, top_offset); - widget_resize ( WIDGET (lv->boxes[i].box), twidth, lv->element_height); + widget_move ( WIDGET ( lv->boxes[i].box ), right_offset, top_offset ); + widget_resize ( WIDGET ( lv->boxes[i].box ), twidth, lv->element_height ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); width -= twidth + spacing_hori; @@ -369,8 +371,8 @@ static void barview_draw ( widget *wid, cairo_t *draw ) offset -= lv->barview.cur_visible - 1; lv->last_offset = offset; for ( unsigned int i = 0; i < ( lv->barview.cur_visible / 2 ); i++ ) { - _listview_row temp = lv->boxes[i]; - int sw = lv->barview.cur_visible - i - 1; + _listview_row temp = lv->boxes[i]; + int sw = lv->barview.cur_visible - i - 1; lv->boxes[i] = lv->boxes[sw]; lv->boxes[sw] = temp; } @@ -379,7 +381,7 @@ static void barview_draw ( widget *wid, cairo_t *draw ) } else { for ( unsigned int i = 0; i < lv->barview.cur_visible; i++ ) { - update_element ( lv, i, i + offset, TRUE); + update_element ( lv, i, i + offset, TRUE ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); } } @@ -426,39 +428,37 @@ static void listview_draw ( widget *wid, cairo_t *draw ) width -= spacing_hori; width -= widget_get_width ( WIDGET ( lv->scrollbar ) ); } - unsigned int element_width = ( width - spacing_hori * ( lv->cur_columns - 1 )) / lv->cur_columns; + unsigned int element_width = ( width - spacing_hori * ( lv->cur_columns - 1 ) ) / lv->cur_columns; - int d = width - (element_width+spacing_hori)*(lv->cur_columns-1)-element_width; - if ( lv->cur_columns > 1) - { - int diff = d/(lv->cur_columns-1); - if ( diff >= 1 ){ - spacing_hori+=1; - d -= lv->cur_columns-1; + int d = width - ( element_width + spacing_hori ) * ( lv->cur_columns - 1 ) - element_width; + if ( lv->cur_columns > 1 ) { + int diff = d / ( lv->cur_columns - 1 ); + if ( diff >= 1 ) { + spacing_hori += 1; + d -= lv->cur_columns - 1; } } for ( unsigned int i = 0; i < max; i++ ) { unsigned int ex = left_offset + ( ( i ) / lv->max_rows ) * ( element_width + spacing_hori ); - if ( (i)/lv->max_rows == (lv->cur_columns-1) ) { - ex+=d; + if ( ( i ) / lv->max_rows == ( lv->cur_columns - 1 ) ) { + ex += d; } if ( lv->reverse ) { unsigned int ey = wid->h - ( widget_padding_get_bottom ( wid ) + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert ) ) - lv->element_height; - widget_move ( WIDGET(lv->boxes[i].box), ex, ey); - widget_resize ( WIDGET (lv->boxes[i].box), element_width, lv->element_height); + widget_move ( WIDGET ( lv->boxes[i].box ), ex, ey ); + widget_resize ( WIDGET ( lv->boxes[i].box ), element_width, lv->element_height ); } else { unsigned int ey = top_offset + ( ( i ) % lv->max_rows ) * ( lv->element_height + spacing_vert ); - widget_move ( WIDGET(lv->boxes[i].box), ex, ey); - widget_resize ( WIDGET (lv->boxes[i].box), element_width, lv->element_height); + widget_move ( WIDGET ( lv->boxes[i].box ), ex, ey ); + widget_resize ( WIDGET ( lv->boxes[i].box ), element_width, lv->element_height ); } update_element ( lv, i, i + offset, TRUE ); widget_draw ( WIDGET ( lv->boxes[i].box ), draw ); } lv->rchanged = FALSE; - } else { for ( unsigned int i = 0; i < max; i++ ) { @@ -490,12 +490,12 @@ static void listview_recompute_elements ( listview *lv ) if ( lv->max_rows == 0 ) { return; } - if ( !(lv->fixed_columns) && lv->req_elements < lv->max_elements ) { + if ( !( lv->fixed_columns ) && lv->req_elements < lv->max_elements ) { newne = lv->req_elements; lv->cur_columns = ( lv->req_elements + ( lv->max_rows - 1 ) ) / lv->max_rows; } else { - newne = MIN( lv->req_elements, lv->max_elements); + newne = MIN ( lv->req_elements, lv->max_elements ); lv->cur_columns = lv->menu_columns; } for ( unsigned int i = newne; i < lv->cur_elements; i++ ) { @@ -504,9 +504,9 @@ static void listview_recompute_elements ( listview *lv ) lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( _listview_row ) ); if ( newne > 0 ) { for ( unsigned int i = lv->cur_elements; i < newne; i++ ) { - listview_create_row ( lv, &(lv->boxes[i]) ); + listview_create_row ( lv, &( lv->boxes[i] ) ); widget_set_trigger_action_handler ( WIDGET ( lv->boxes[i].box ), listview_element_trigger_action, lv ); - listview_set_state ( lv->boxes[i], NORMAL); + listview_set_state ( lv->boxes[i], NORMAL ); } } lv->rchanged = TRUE; @@ -518,14 +518,14 @@ void listview_set_num_elements ( listview *lv, unsigned int rows ) if ( lv == NULL ) { return; } - TICK_N(__FUNCTION__); + TICK_N ( __FUNCTION__ ); lv->req_elements = rows; listview_set_selected ( lv, lv->selected ); - TICK_N("Set selected"); + TICK_N ( "Set selected" ); listview_recompute_elements ( lv ); - TICK_N("recompute elements"); + TICK_N ( "recompute elements" ); widget_queue_redraw ( WIDGET ( lv ) ); - TICK_N("queue redraw"); + TICK_N ( "queue redraw" ); } unsigned int listview_get_selected ( listview *lv ) @@ -626,7 +626,7 @@ static WidgetTriggerActionResult listview_element_trigger_action ( widget *wid, listview *lv = (listview *) user_data; unsigned int max = MIN ( lv->cur_elements, lv->req_elements - lv->last_offset ); unsigned int i; - for ( i = 0; i < max && WIDGET ( lv->boxes[i].box) != wid; i++ ) { + for ( i = 0; i < max && WIDGET ( lv->boxes[i].box ) != wid; i++ ) { } if ( i == max ) { return WIDGET_TRIGGER_ACTION_RESULT_IGNORED; @@ -667,8 +667,8 @@ listview *listview_create ( widget *parent, const char *name, listview_update_ca // Calculate height of an element. // _listview_row row; - listview_create_row ( lv, &row); - lv->element_height = widget_get_desired_height ( WIDGET(row.box) ); + listview_create_row ( lv, &row ); + lv->element_height = widget_get_desired_height ( WIDGET ( row.box ) ); widget_free ( WIDGET ( row.box ) ); lv->callback = cb; @@ -967,12 +967,14 @@ void listview_set_fixed_num_lines ( listview *lv ) void listview_toggle_ellipsizing ( listview *lv ) { if ( lv ) { - PangoEllipsizeMode mode = lv->emode; + PangoEllipsizeMode mode = lv->emode; if ( mode == PANGO_ELLIPSIZE_START ) { mode = PANGO_ELLIPSIZE_MIDDLE; - } else if ( mode == PANGO_ELLIPSIZE_MIDDLE ) { + } + else if ( mode == PANGO_ELLIPSIZE_MIDDLE ) { mode = PANGO_ELLIPSIZE_END; - } else if ( mode == PANGO_ELLIPSIZE_END ) { + } + else if ( mode == PANGO_ELLIPSIZE_END ) { mode = PANGO_ELLIPSIZE_START; } lv->emode = mode; diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c index d2135392..aa299113 100644 --- a/source/widgets/textbox.c +++ b/source/widgets/textbox.c @@ -156,7 +156,7 @@ static void textbox_initialize_font ( textbox *tb ) if ( tbfc ) { // Update for used font. pango_layout_set_font_description ( tb->layout, tbfc->pfd ); - tb->metrics = tbfc->metrics; + tb->metrics = tbfc->metrics; } } } @@ -189,11 +189,11 @@ textbox* textbox_create ( widget *parent, WidgetType type, const char *name, Tex } const char *txt = rofi_theme_get_string ( WIDGET ( tb ), "str", text ); - if ( txt == NULL || (*txt) == '\0' ){ + if ( txt == NULL || ( *txt ) == '\0' ) { txt = rofi_theme_get_string ( WIDGET ( tb ), "content", text ); } - const char *placeholder = rofi_theme_get_string ( WIDGET(tb), "placeholder", NULL); - if ( placeholder){ + const char *placeholder = rofi_theme_get_string ( WIDGET ( tb ), "placeholder", NULL ); + if ( placeholder ) { tb->placeholder = placeholder; } textbox_text ( tb, txt ? txt : "" ); @@ -205,8 +205,8 @@ textbox* textbox_create ( widget *parent, WidgetType type, const char *name, Tex tb->blink_timeout = 0; tb->blink = 1; if ( ( flags & TB_EDITABLE ) == TB_EDITABLE ) { - if ( rofi_theme_get_boolean ( WIDGET(tb), "blink", TRUE) ) { - tb->blink_timeout = g_timeout_add ( 1200, textbox_blink, tb ); + if ( rofi_theme_get_boolean ( WIDGET ( tb ), "blink", TRUE ) ) { + tb->blink_timeout = g_timeout_add ( 1200, textbox_blink, tb ); } tb->widget.trigger_action = textbox_editable_trigger_action; } @@ -268,8 +268,7 @@ void textbox_font ( textbox *tb, TextBoxFontType tbft ) static void __textbox_update_pango_text ( textbox *tb ) { pango_layout_set_attributes ( tb->layout, NULL ); - if ( tb->placeholder && (tb->text == NULL || tb->text[0] == 0) ) - { + if ( tb->placeholder && ( tb->text == NULL || tb->text[0] == 0 ) ) { tb->show_placeholder = TRUE; pango_layout_set_text ( tb->layout, tb->placeholder, -1 ); return; @@ -344,7 +343,6 @@ void textbox_text ( textbox *tb, const char *text ) widget_queue_redraw ( WIDGET ( tb ) ); } - // within the parent handled auto width/height modes void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) { @@ -360,7 +358,8 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h ) } else if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { pango_layout_set_ellipsize ( tb->layout, tb->emode ); - } else { + } + else { pango_layout_set_ellipsize ( tb->layout, PANGO_ELLIPSIZE_NONE ); } } @@ -450,7 +449,6 @@ static void textbox_draw ( widget *wid, cairo_t *draw ) cairo_move_to ( draw, x, top ); pango_cairo_show_layout ( draw, tb->layout ); - // draw the cursor rofi_theme_get_color ( WIDGET ( tb ), "text-color", draw ); if ( tb->flags & TB_EDITABLE && tb->blink ) { @@ -470,7 +468,6 @@ static void textbox_draw ( widget *wid, cairo_t *draw ) cairo_fill ( draw ); } - if ( ( tb->flags & TB_INDICATOR ) == TB_INDICATOR && ( tb->tbft & ( SELECTED ) ) ) { cairo_arc ( draw, DOT_OFFSET / 2.0, tb->widget.h / 2.0, 2.0, 0, 2.0 * M_PI ); cairo_fill ( draw ); @@ -941,11 +938,9 @@ int textbox_get_desired_width ( widget *wid ) return width + padding + offset; } - void textbox_set_ellipsize ( textbox *tb, PangoEllipsizeMode mode ) { - if ( tb ) - { + if ( tb ) { tb->emode = mode; if ( ( tb->flags & TB_WRAP ) != TB_WRAP ) { // Store the mode. diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 749ba746..5dfd9437 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -107,7 +107,7 @@ void widget_move ( widget *widget, short x, short y ) void widget_set_type ( widget *widget, WidgetType type ) { if ( widget == NULL ) { - return ; + return; } widget->type = type; } diff --git a/source/xcb.c b/source/xcb.c index 8f486d97..dd42e98b 100644 --- a/source/xcb.c +++ b/source/xcb.c @@ -99,72 +99,74 @@ static xcb_visualtype_t *root_visual = NULL; xcb_atom_t netatoms[NUM_NETATOMS]; const char *netatom_names[] = { EWMH_ATOMS ( ATOM_CHAR ) }; -static xcb_visualtype_t * lookup_visual (xcb_screen_t *s, xcb_visualid_t visual) +static xcb_visualtype_t * lookup_visual ( xcb_screen_t *s, xcb_visualid_t visual ) { xcb_depth_iterator_t d; - d = xcb_screen_allowed_depths_iterator (s); - for (; d.rem; xcb_depth_next (&d)) { - xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator (d.data); - for (; v.rem; xcb_visualtype_next (&v)) { - if (v.data->visual_id == visual) + d = xcb_screen_allowed_depths_iterator ( s ); + for (; d.rem; xcb_depth_next ( &d ) ) { + xcb_visualtype_iterator_t v = xcb_depth_visuals_iterator ( d.data ); + for (; v.rem; xcb_visualtype_next ( &v ) ) { + if ( v.data->visual_id == visual ) { return v.data; + } } } return 0; } - cairo_surface_t *x11_helper_get_screenshot_surface_window ( xcb_window_t window, int size ) { xcb_get_geometry_cookie_t cookie; - xcb_get_geometry_reply_t *reply; + xcb_get_geometry_reply_t *reply; - cookie = xcb_get_geometry(xcb->connection, window); - reply = xcb_get_geometry_reply(xcb->connection, cookie, NULL); + cookie = xcb_get_geometry ( xcb->connection, window ); + reply = xcb_get_geometry_reply ( xcb->connection, cookie, NULL ); if ( reply == NULL ) { return NULL; } - xcb_get_window_attributes_cookie_t attributesCookie = xcb_get_window_attributes (xcb->connection, window); - xcb_get_window_attributes_reply_t *attributes = xcb_get_window_attributes_reply (xcb->connection, - attributesCookie, - NULL ); - if ( attributes == NULL || ( attributes->map_state != XCB_MAP_STATE_VIEWABLE ) ) { - free(reply); - if ( attributes ) free(attributes); + xcb_get_window_attributes_cookie_t attributesCookie = xcb_get_window_attributes ( xcb->connection, window ); + xcb_get_window_attributes_reply_t *attributes = xcb_get_window_attributes_reply ( xcb->connection, + attributesCookie, + NULL ); + if ( attributes == NULL || ( attributes->map_state != XCB_MAP_STATE_VIEWABLE ) ) { + free ( reply ); + if ( attributes ) { + free ( attributes ); + } return NULL; } // Create a cairo surface for the window. - xcb_visualtype_t * vt = lookup_visual(xcb->screen, attributes->visual); + xcb_visualtype_t * vt = lookup_visual ( xcb->screen, attributes->visual ); free ( attributes ); - cairo_surface_t *t = cairo_xcb_surface_create ( xcb->connection, window, vt , reply->width, reply->height ); + cairo_surface_t *t = cairo_xcb_surface_create ( xcb->connection, window, vt, reply->width, reply->height ); if ( cairo_surface_status ( t ) != CAIRO_STATUS_SUCCESS ) { - cairo_surface_destroy(t); - free(reply); + cairo_surface_destroy ( t ); + free ( reply ); return NULL; } // Scale the image, as we don't want to keep large one around. - int max = MAX(reply->width, reply->height); - double scale = (double)size/ max; + int max = MAX ( reply->width, reply->height ); + double scale = (double) size / max; - cairo_surface_t *s2 = cairo_surface_create_similar_image ( t, CAIRO_FORMAT_ARGB32, reply->width*scale,reply->height*scale ); + cairo_surface_t *s2 = cairo_surface_create_similar_image ( t, CAIRO_FORMAT_ARGB32, reply->width * scale, reply->height * scale ); free ( reply ); if ( cairo_surface_status ( s2 ) != CAIRO_STATUS_SUCCESS ) { - cairo_surface_destroy ( t ) ; + cairo_surface_destroy ( t ); return NULL; } // Paint it in. - cairo_t *d = cairo_create (s2); + cairo_t *d = cairo_create ( s2 ); cairo_scale ( d, scale, scale ); cairo_set_source_surface ( d, t, 0, 0 ); - cairo_paint ( d); - cairo_destroy(d); + cairo_paint ( d ); + cairo_destroy ( d ); - cairo_surface_destroy(t); + cairo_surface_destroy ( t ); return s2; } /** @@ -1056,8 +1058,8 @@ static int take_pointer ( xcb_window_t w, int iters ) break; } struct timespec del = { - .tv_sec = 0, - .tv_nsec = 1000000 + .tv_sec = 0, + .tv_nsec = 1000000 }; nanosleep ( &del, NULL ); } @@ -1087,8 +1089,8 @@ static int take_keyboard ( xcb_window_t w, int iters ) break; } struct timespec del = { - .tv_sec = 0, - .tv_nsec = 1000000 + .tv_sec = 0, + .tv_nsec = 1000000 }; nanosleep ( &del, NULL ); } diff --git a/source/xrmoptions.c b/source/xrmoptions.c index fa1d158e..a8e9cbf5 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -81,153 +81,153 @@ typedef struct * Currently supports string, boolean and number (signed and unsigned). */ static XrmOption xrmOptions[] = { - { xrm_String, "switchers", { .str = &config.modi }, NULL, + { xrm_String, "switchers", { .str = &config.modi }, NULL, "", CONFIG_DEFAULT }, - { xrm_String, "modi", { .str = &config.modi }, NULL, + { xrm_String, "modi", { .str = &config.modi }, NULL, "Enabled modi", CONFIG_DEFAULT }, - { xrm_SNumber, "width", { .snum = &config.menu_width }, NULL, + { xrm_SNumber, "width", { .snum = &config.menu_width }, NULL, "Window width", CONFIG_DEFAULT }, - { xrm_Number, "lines", { .num = &config.menu_lines }, NULL, + { xrm_Number, "lines", { .num = &config.menu_lines }, NULL, "Number of lines", CONFIG_DEFAULT }, - { xrm_Number, "columns", { .num = &config.menu_columns }, NULL, + { xrm_Number, "columns", { .num = &config.menu_columns }, NULL, "Number of columns", CONFIG_DEFAULT }, - { xrm_String, "font", { .str = &config.menu_font }, NULL, + { xrm_String, "font", { .str = &config.menu_font }, NULL, "Font to use", CONFIG_DEFAULT }, - { xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL, + { xrm_Number, "borderwidth", { .num = &config.menu_bw }, NULL, "", CONFIG_DEFAULT }, - { xrm_Number, "bw", { .num = &config.menu_bw }, NULL, + { xrm_Number, "bw", { .num = &config.menu_bw }, NULL, "Border width", CONFIG_DEFAULT }, - { xrm_Number, "location", { .num = &config.location }, NULL, + { xrm_Number, "location", { .num = &config.location }, NULL, "Location on screen", CONFIG_DEFAULT }, - { xrm_Number, "padding", { .num = &config.padding }, NULL, + { xrm_Number, "padding", { .num = &config.padding }, NULL, "Padding", CONFIG_DEFAULT }, - { xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL, + { xrm_SNumber, "yoffset", { .snum = &config.y_offset }, NULL, "Y-offset relative to location", CONFIG_DEFAULT }, - { xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL, + { xrm_SNumber, "xoffset", { .snum = &config.x_offset }, NULL, "X-offset relative to location", CONFIG_DEFAULT }, - { xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL, + { xrm_Boolean, "fixed-num-lines", { .num = &config.fixed_num_lines }, NULL, "Always show number of lines", CONFIG_DEFAULT }, - { xrm_Boolean, "show-icons", { .snum = &config.show_icons }, NULL, + { xrm_Boolean, "show-icons", { .snum = &config.show_icons }, NULL, "Whether to load and show icons", CONFIG_DEFAULT }, - { xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL, + { xrm_String, "terminal", { .str = &config.terminal_emulator }, NULL, "Terminal to use", CONFIG_DEFAULT }, - { xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL, + { xrm_String, "ssh-client", { .str = &config.ssh_client }, NULL, "Ssh client to use", CONFIG_DEFAULT }, - { xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL, + { xrm_String, "ssh-command", { .str = &config.ssh_command }, NULL, "Ssh command to execute", CONFIG_DEFAULT }, - { xrm_String, "run-command", { .str = &config.run_command }, NULL, + { xrm_String, "run-command", { .str = &config.run_command }, NULL, "Run command to execute", CONFIG_DEFAULT }, - { xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL, + { xrm_String, "run-list-command", { .str = &config.run_list_command }, NULL, "Command to get extra run targets", CONFIG_DEFAULT }, - { xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL, + { xrm_String, "run-shell-command", { .str = &config.run_shell_command }, NULL, "Run command to execute that runs in shell", CONFIG_DEFAULT }, - { xrm_String, "window-command", { .str = &config.window_command }, NULL, + { xrm_String, "window-command", { .str = &config.window_command }, NULL, "Command executed on accep-entry-custom for window modus", CONFIG_DEFAULT }, - { xrm_String, "window-match-fields", { .str = &config.window_match_fields }, NULL, + { xrm_String, "window-match-fields", { .str = &config.window_match_fields }, NULL, "Window fields to match in window mode", CONFIG_DEFAULT }, - { xrm_String, "icon-theme", { .str = &config.icon_theme }, NULL, + { xrm_String, "icon-theme", { .str = &config.icon_theme }, NULL, "Theme to use to look for icons", CONFIG_DEFAULT }, - { xrm_String, "drun-match-fields", { .str = &config.drun_match_fields }, NULL, + { xrm_String, "drun-match-fields", { .str = &config.drun_match_fields }, NULL, "Desktop entry fields to match in drun", CONFIG_DEFAULT }, - { xrm_String, "drun-categories", { .str = &config.drun_categories }, NULL, + { xrm_String, "drun-categories", { .str = &config.drun_categories }, NULL, "Only show Desktop entry from these categories", CONFIG_DEFAULT }, - { xrm_Boolean, "drun-show-actions", { .num = &config.drun_show_actions }, NULL, + { xrm_Boolean, "drun-show-actions", { .num = &config.drun_show_actions }, NULL, "Desktop entry show actions.", CONFIG_DEFAULT }, - { xrm_String, "drun-display-format", { .str = &config.drun_display_format }, NULL, + { xrm_String, "drun-display-format", { .str = &config.drun_display_format }, NULL, "DRUN format string. (Supports: generic,name,comment,exec,categories)", CONFIG_DEFAULT }, - { xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL, + { xrm_Boolean, "disable-history", { .num = &config.disable_history }, NULL, "Disable history in run/ssh", CONFIG_DEFAULT }, - { xrm_String, "ignored-prefixes", { .str = &config.ignored_prefixes }, NULL, + { xrm_String, "ignored-prefixes", { .str = &config.ignored_prefixes }, NULL, "Programs ignored for history", CONFIG_DEFAULT }, - { xrm_Boolean, "sort", { .num = &config.sort }, NULL, + { xrm_Boolean, "sort", { .num = &config.sort }, NULL, "Use sorting", CONFIG_DEFAULT }, - { xrm_String, "sorting-method", { .str = &config.sorting_method }, NULL, + { xrm_String, "sorting-method", { .str = &config.sorting_method }, NULL, "Choose the strategy used for sorting: normal (levenshtein) or fzf.", CONFIG_DEFAULT }, - { xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, + { xrm_Boolean, "case-sensitive", { .num = &config.case_sensitive }, NULL, "Set case-sensitivity", CONFIG_DEFAULT }, - { xrm_Boolean, "cycle", { .num = &config.cycle }, NULL, + { xrm_Boolean, "cycle", { .num = &config.cycle }, NULL, "Cycle through the results list", CONFIG_DEFAULT }, - { xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL, + { xrm_Boolean, "sidebar-mode", { .num = &config.sidebar_mode }, NULL, "Enable sidebar-mode", CONFIG_DEFAULT }, - { xrm_SNumber, "eh", { .snum = &config.element_height }, NULL, + { xrm_SNumber, "eh", { .snum = &config.element_height }, NULL, "Row height (in chars)", CONFIG_DEFAULT }, - { xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL, + { xrm_Boolean, "auto-select", { .num = &config.auto_select }, NULL, "Enable auto select mode", CONFIG_DEFAULT }, - { xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL, + { xrm_Boolean, "parse-hosts", { .num = &config.parse_hosts }, NULL, "Parse hosts file for ssh mode", CONFIG_DEFAULT }, - { xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL, + { xrm_Boolean, "parse-known-hosts", { .num = &config.parse_known_hosts }, NULL, "Parse known_hosts file for ssh mode", CONFIG_DEFAULT }, - { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL, + { xrm_String, "combi-modi", { .str = &config.combi_modi }, NULL, "Set the modi to combine in combi mode", CONFIG_DEFAULT }, - { xrm_String, "matching", { .str = &config.matching }, NULL, + { xrm_String, "matching", { .str = &config.matching }, NULL, "Set the matching algorithm. (normal, regex, glob, fuzzy)", CONFIG_DEFAULT }, - { xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL, + { xrm_Boolean, "tokenize", { .num = &config.tokenize }, NULL, "Tokenize input string", CONFIG_DEFAULT }, - { xrm_String, "monitor", { .str = &config.monitor }, NULL, + { xrm_String, "monitor", { .str = &config.monitor }, NULL, "", CONFIG_DEFAULT }, /* Alias for dmenu compatibility. */ - { xrm_String, "m", { .str = &config.monitor }, NULL, + { xrm_String, "m", { .str = &config.monitor }, NULL, "Monitor id to show on", CONFIG_DEFAULT }, - { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL, + { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL, "Margin between rows *DEPRECATED*", CONFIG_DEFAULT }, - { xrm_Number, "line-padding", { .num = &config.line_padding }, NULL, + { xrm_Number, "line-padding", { .num = &config.line_padding }, NULL, "Padding within rows *DEPRECATED*", CONFIG_DEFAULT }, - { xrm_String, "filter", { .str = &config.filter }, NULL, + { xrm_String, "filter", { .str = &config.filter }, NULL, "Pre-set filter", CONFIG_DEFAULT }, - { xrm_String, "separator-style", { .str = &config.separator_style }, NULL, + { xrm_String, "separator-style", { .str = &config.separator_style }, NULL, "Separator style (none, dash, solid) *DEPRECATED*", CONFIG_DEFAULT }, - { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, + { xrm_Boolean, "hide-scrollbar", { .num = &config.hide_scrollbar }, NULL, "Hide scroll-bar *DEPRECATED*", CONFIG_DEFAULT }, - { xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL, + { xrm_Boolean, "fullscreen", { .num = &config.fullscreen }, NULL, "Fullscreen", CONFIG_DEFAULT }, - { xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL, + { xrm_Boolean, "fake-transparency", { .num = &config.fake_transparency }, NULL, "Fake transparency *DEPRECATED*", CONFIG_DEFAULT }, - { xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL, + { xrm_SNumber, "dpi", { .snum = &config.dpi }, NULL, "DPI", CONFIG_DEFAULT }, - { xrm_Number, "threads", { .num = &config.threads }, NULL, + { xrm_Number, "threads", { .num = &config.threads }, NULL, "Threads to use for string matching", CONFIG_DEFAULT }, - { xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, + { xrm_Number, "scrollbar-width", { .num = &config.scrollbar_width }, NULL, "Scrollbar width *DEPRECATED*", CONFIG_DEFAULT }, - { xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL, + { xrm_Number, "scroll-method", { .num = &config.scroll_method }, NULL, "Scrolling method. (0: Page, 1: Centered)", CONFIG_DEFAULT }, - { xrm_String, "fake-background", { .str = &config.fake_background }, NULL, + { xrm_String, "fake-background", { .str = &config.fake_background }, NULL, "Background to use for fake transparency. (background or screenshot) *DEPRECATED*", CONFIG_DEFAULT }, - { xrm_String, "window-format", { .str = &config.window_format }, NULL, + { xrm_String, "window-format", { .str = &config.window_format }, NULL, "Window Format. w (desktop name), t (title), n (name), r (role), c (class)", CONFIG_DEFAULT }, - { xrm_Boolean, "click-to-exit", { .snum = &config.click_to_exit }, NULL, + { xrm_Boolean, "click-to-exit", { .snum = &config.click_to_exit }, NULL, "Click outside the window to exit", CONFIG_DEFAULT }, - { xrm_Boolean, "show-match", { .snum = &config.show_match }, NULL, + { xrm_Boolean, "show-match", { .snum = &config.show_match }, NULL, "Indicate how it match by underlining it.", CONFIG_DEFAULT }, - { xrm_String, "theme", { .str = &config.theme }, NULL, + { xrm_String, "theme", { .str = &config.theme }, NULL, "New style theme file", CONFIG_DEFAULT }, - { xrm_String, "color-normal", { .str = &config.color_normal }, NULL, + { xrm_String, "color-normal", { .str = &config.color_normal }, NULL, "Color scheme for normal row", CONFIG_DEFAULT }, - { xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL, + { xrm_String, "color-urgent", { .str = &config.color_urgent }, NULL, "Color scheme for urgent row", CONFIG_DEFAULT }, - { xrm_String, "color-active", { .str = &config.color_active }, NULL, + { xrm_String, "color-active", { .str = &config.color_active }, NULL, "Color scheme for active row", CONFIG_DEFAULT }, - { xrm_String, "color-window", { .str = &config.color_window }, NULL, + { xrm_String, "color-window", { .str = &config.color_window }, NULL, "Color scheme window", CONFIG_DEFAULT }, - { xrm_Number, "max-history-size", { .num = &config.max_history_size }, NULL, + { 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, + { 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_Char, "matching-negate-char", { .charc= &config.matching_negate_char }, NULL, + { 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, + { xrm_String, "cache-dir", { .str = &config.cache_dir }, NULL, "Directory where history and temporary files are stored.", CONFIG_DEFAULT }, - { xrm_Boolean, "window-thumbnail", { .snum = &config.window_thumbnail }, NULL, + { xrm_Boolean, "window-thumbnail", { .snum = &config.window_thumbnail }, NULL, "Show window thumbnail in window switcher if availalbe.", CONFIG_DEFAULT }, - { xrm_Boolean, "drun-use-desktop-cache", { .snum = &config.drun_use_desktop_cache }, NULL, + { xrm_Boolean, "drun-use-desktop-cache", { .snum = &config.drun_use_desktop_cache }, NULL, "DRUN: build and use a cache with desktop file content.", CONFIG_DEFAULT }, - { xrm_Boolean, "drun-reload-desktop-cache", { .snum = &config.drun_reload_desktop_cache}, NULL, + { xrm_Boolean, "drun-reload-desktop-cache", { .snum = &config.drun_reload_desktop_cache }, NULL, "DRUN: If enabled, reload the cache with desktop file content.", CONFIG_DEFAULT }, }; @@ -582,45 +582,45 @@ void config_parse_xresource_dump ( void ) static void config_parse_dump_config_option ( FILE *out, XrmOption *option ) { if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) { - fprintf ( out, "/*" ); + fprintf ( out, "/*" ); } - fprintf ( out, "\t%s: ", option->name ); + fprintf ( out, "\t%s: ", option->name ); switch ( option->type ) { case xrm_Number: - fprintf ( out, "%u", *( option->value.num ) ); + fprintf ( out, "%u", *( option->value.num ) ); break; case xrm_SNumber: - fprintf ( out, "%i", *( option->value.snum ) ); + fprintf ( out, "%i", *( option->value.snum ) ); break; case xrm_String: if ( ( *( option->value.str ) ) != NULL ) { // TODO should this be escaped? - fprintf ( out, "\"%s\"", *( option->value.str ) ); + fprintf ( out, "\"%s\"", *( option->value.str ) ); } break; case xrm_Boolean: - fprintf ( out, "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" ); + fprintf ( out, "%s", ( *( option->value.num ) == TRUE ) ? "true" : "false" ); break; case xrm_Char: // TODO if ( *( option->value.charc ) > 32 && *( option->value.charc ) < 127 ) { - fprintf ( out, "'%c'", *( option->value.charc ) ); + fprintf ( out, "'%c'", *( option->value.charc ) ); } else { - fprintf ( out, "'\\x%02X'", *( option->value.charc ) ); + fprintf ( out, "'\\x%02X'", *( option->value.charc ) ); } - fprintf ( out, " /* unsupported */" ); + fprintf ( out, " /* unsupported */" ); break; default: break; } - fprintf ( out, ";" ); + fprintf ( out, ";" ); if ( option->type == xrm_Char || option->source == CONFIG_DEFAULT ) { - fprintf ( out, "*/" ); + fprintf ( out, "*/" ); } - fprintf ( out, "\n" ); + fprintf ( out, "\n" ); } void config_parse_dump_config_rasi_format ( FILE *out, gboolean changes )