diff options
-rw-r--r-- | include/rofi.h | 4 | ||||
-rw-r--r-- | source/dialogs/combi.c | 23 | ||||
-rw-r--r-- | source/dialogs/dmenu.c | 1 | ||||
-rw-r--r-- | source/dialogs/drun.c | 17 | ||||
-rw-r--r-- | source/dialogs/run.c | 1 | ||||
-rw-r--r-- | source/dialogs/script.c | 1 | ||||
-rw-r--r-- | source/dialogs/ssh.c | 1 | ||||
-rw-r--r-- | source/dialogs/window.c | 2 | ||||
-rw-r--r-- | source/rofi.c | 8 |
9 files changed, 55 insertions, 3 deletions
diff --git a/include/rofi.h b/include/rofi.h index a47a3aae..c790b0f6 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -34,6 +34,8 @@ typedef enum typedef void ( *switcher_free )( Switcher *data ); typedef char * ( *get_display_value )( unsigned int selected_line, const Switcher *data, int *state, int get_entry ); + +typedef char * ( *get_completion )( const Switcher *sw, unsigned int selected_line ); /** * State returned by the rofi window. */ @@ -289,6 +291,8 @@ struct _Switcher int ( *is_not_ascii )( const struct _Switcher *sw, unsigned int index ); + get_completion get_completion; + // Pointer to private data. void *private_data; diff --git a/source/dialogs/combi.c b/source/dialogs/combi.c index cfaa80a5..35e0f9ab 100644 --- a/source/dialogs/combi.c +++ b/source/dialogs/combi.c @@ -226,6 +226,28 @@ static int combi_is_not_ascii ( const Switcher *sw, unsigned int index ) } return FALSE; } +static char * combi_get_completion ( const Switcher *sw, unsigned int index ) +{ + CombiModePrivateData *pd = sw->private_data; + for ( unsigned i = 0; i < pd->num_switchers; i++ ) { + if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) { + char * str = NULL; + if ( pd->switchers[i]->get_completion != NULL ) { + str = pd->switchers[i]->get_completion ( pd->switchers[i], index - pd->starts[i] ); + } + else { + int state; + str = pd->switchers[i]->mgrv ( index - pd->starts[i], (void *) pd->switchers[i], &state, TRUE ); + } + char *retv = g_strdup_printf ( "!%c %s", pd->switchers[i]->name[0], str ); + g_free ( str ); + return retv; + } + } + // Should never get here. + g_error ( "Failure, could not resolve sub-switcher." ); + return NULL; +} Switcher combi_mode = { @@ -238,6 +260,7 @@ Switcher combi_mode = .result = combi_mode_result, .destroy = combi_mode_destroy, .token_match = combi_mode_match, + .get_completion = combi_get_completion, .mgrv = combi_mgrv, .is_not_ascii = combi_is_not_ascii, .private_data = NULL, diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 7c87eb59..5161fbf0 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -303,6 +303,7 @@ Switcher dmenu_mode = .destroy = dmenu_mode_free, .token_match = dmenu_token_match, .mgrv = get_display_data, + .get_completion = NULL, .is_not_ascii = dmenu_is_not_ascii, .private_data = NULL, .free = NULL diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c index 0ebdd0a5..981caedd 100644 --- a/source/dialogs/drun.c +++ b/source/dialogs/drun.c @@ -113,7 +113,7 @@ static void exec_cmd_entry ( DRunModeEntry *e ) str[i++] = ' '; } // We might have hit '\0' in prev. loop, break out of for then. - if ( str[i] == '\0') { + if ( str[i] == '\0' ) { break; } } @@ -167,7 +167,7 @@ static void get_apps_dir ( DRunModePrivateData *pd, const char *bp ) } if ( g_key_file_has_key ( kf, "Desktop Entry", "Exec", NULL ) ) { size_t nl = ( ( pd->cmd_list_length ) + 1 ); - pd->entry_list = g_realloc ( pd->entry_list, nl * sizeof ( *( pd->entry_list ) ) ); + pd->entry_list = g_realloc ( pd->entry_list, nl * sizeof ( *( pd->entry_list ) ) ); pd->entry_list[pd->cmd_list_length].terminal = FALSE; if ( g_key_file_has_key ( kf, "Desktop Entry", "Name", NULL ) ) { gchar *n = g_key_file_get_locale_string ( kf, "Desktop Entry", "Name", NULL, NULL ); @@ -296,6 +296,18 @@ static char *mgrv ( unsigned int selected_line, const Switcher *sw, int *state, dr->generic_name ); } } +static char *drun_get_completion ( const Switcher *sw, unsigned int index ) +{ + DRunModePrivateData *pd = (DRunModePrivateData *) sw->private_data; + /* Free temp storage. */ + DRunModeEntry *dr = &( pd->entry_list[index] ); + if ( dr->generic_name == NULL ) { + return g_strdup ( dr->name ); + } + else { + return g_strdup_printf ( "%s", dr->name ); + } +} static int drun_token_match ( const Switcher *data, char **tokens, @@ -342,6 +354,7 @@ Switcher drun_mode = .result = drun_mode_result, .destroy = drun_mode_destroy, .token_match = drun_token_match, + .get_completion = drun_get_completion, .mgrv = mgrv, .is_not_ascii = drun_is_not_ascii, .private_data = NULL, diff --git a/source/dialogs/run.c b/source/dialogs/run.c index 5ba2fd5b..00e54a5c 100644 --- a/source/dialogs/run.c +++ b/source/dialogs/run.c @@ -354,6 +354,7 @@ Switcher run_mode = .destroy = run_mode_destroy, .token_match = run_token_match, .mgrv = mgrv, + .get_completion = NULL, .is_not_ascii = run_is_not_ascii, .private_data = NULL, .free = NULL diff --git a/source/dialogs/script.c b/source/dialogs/script.c index a2f49653..179554f8 100644 --- a/source/dialogs/script.c +++ b/source/dialogs/script.c @@ -199,6 +199,7 @@ Switcher *script_switcher_parse_setup ( const char *str ) sw->result = script_mode_result; sw->destroy = script_mode_destroy; sw->token_match = script_token_match; + sw->get_completion = NULL, sw->mgrv = mgrv; sw->is_not_ascii = script_is_not_ascii; diff --git a/source/dialogs/ssh.c b/source/dialogs/ssh.c index 4a247a55..82e4f229 100644 --- a/source/dialogs/ssh.c +++ b/source/dialogs/ssh.c @@ -405,6 +405,7 @@ Switcher ssh_mode = .destroy = ssh_mode_destroy, .token_match = ssh_token_match, .mgrv = mgrv, + .get_completion = NULL, .is_not_ascii = ssh_is_not_ascii, .private_data = NULL, .free = NULL diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 258e4476..c7b8b45c 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -594,6 +594,7 @@ Switcher window_mode = .destroy = window_mode_destroy, .token_match = window_match, .mgrv = mgrv, + .get_completion = NULL, .is_not_ascii = window_is_not_ascii, .private_data = NULL, .free = NULL @@ -610,6 +611,7 @@ Switcher window_mode_cd = .destroy = window_mode_destroy, .token_match = window_match, .mgrv = mgrv, + .get_completion = NULL, .is_not_ascii = window_is_not_ascii, .private_data = NULL, .free = NULL diff --git a/source/rofi.c b/source/rofi.c index ab6ea769..5e89cc6c 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -644,7 +644,13 @@ static int menu_keyboard_navigation ( MenuState *state, KeySym key, unsigned int // If a valid item is selected, return that.. if ( state->selected < state->filtered_lines ) { int st; - char * str = state->sw->mgrv ( state->line_map[state->selected], state->sw, &st, TRUE ); + char *str = NULL; + if ( state->sw->get_completion ) { + str = state->sw->get_completion ( state->sw, state->line_map[state->selected] ); + } + else { + str = state->sw->mgrv ( state->line_map[state->selected], state->sw, &st, TRUE ); + } textbox_text ( state->text, str ); g_free ( str ); textbox_cursor_end ( state->text ); |