mirror of
https://github.com/davatorium/rofi.git
synced 2025-01-27 15:25:24 -05:00
parent
bdeb57a2c4
commit
fa2bcd778c
9 changed files with 55 additions and 3 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 );
|
||||
|
|
Loading…
Add table
Reference in a new issue