diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-02-04 09:20:10 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-02-04 09:20:10 +0100 |
commit | 69b88caac5dc1dcac5227850c6aa6893a0eac449 (patch) | |
tree | b51867d3da518c5d5e66c995c35a9283cb7d728e /source | |
parent | bb6ae77ba5ed9493bb9164f498c5889413572820 (diff) |
Allow user to open an disabled modi.
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/dmenu.c | 3 | ||||
-rw-r--r-- | source/rofi.c | 116 |
2 files changed, 67 insertions, 52 deletions
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 46c87753..9d6cdc3e 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -431,8 +431,7 @@ int dmenu_switcher_dialog ( void ) // In no custom mode we allow canceling. restart = ( find_arg ( "-only-match" ) >= 0 ); } - else if ( pd->selected_line != UINT32_MAX ){ - + else if ( pd->selected_line != UINT32_MAX ) { if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && cmd_list[pd->selected_line] != NULL ) { dmenu_output_formatted_line ( pd->format, cmd_list[pd->selected_line], pd->selected_line, input ); retv = TRUE; diff --git a/source/rofi.c b/source/rofi.c index bd04b1ce..45389f0a 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1968,6 +1968,60 @@ static void cleanup () * First the three build-in modi are checked: window, run, ssh * if that fails, a script-switcher is created. */ +static int add_mode ( const char * token ) +{ + unsigned int index = num_modi; + // Resize and add entry. + modi = (ModeHolder *) g_realloc ( modi, sizeof ( ModeHolder ) * ( num_modi + 1 ) ); + modi[num_modi].tb = NULL; + + // Window switcher. +#ifdef WINDOW_MODE + if ( strcasecmp ( token, "window" ) == 0 ) { + modi[num_modi].sw = &window_mode; + num_modi++; + } + else if ( strcasecmp ( token, "windowcd" ) == 0 ) { + modi[num_modi].sw = &window_mode_cd; + num_modi++; + } + else +#endif // WINDOW_MODE + // SSh dialog + if ( strcasecmp ( token, "ssh" ) == 0 ) { + modi[num_modi].sw = &ssh_mode; + num_modi++; + } + // Run dialog + else if ( strcasecmp ( token, "run" ) == 0 ) { + modi[num_modi].sw = &run_mode; + num_modi++; + } + else if ( strcasecmp ( token, "drun" ) == 0 ) { + modi[num_modi].sw = &drun_mode; + num_modi++; + } + // combi dialog + else if ( strcasecmp ( token, "combi" ) == 0 ) { + modi[num_modi].sw = &combi_mode; + num_modi++; + } + else { + // If not build in, use custom modi. + Mode *sw = script_switcher_parse_setup ( token ); + if ( sw != NULL ) { + modi[num_modi].sw = sw; + mode_set_config ( sw ); + num_modi++; + } + else{ + // Report error, don't continue. + fprintf ( stderr, "Invalid script switcher: %s\n", token ); + token = NULL; + } + } + return ( index == num_modi ) ? -1 : (int) index; +} static void setup_modi ( void ) { char *savept = NULL; @@ -1975,56 +2029,7 @@ static void setup_modi ( void ) char *switcher_str = g_strdup ( config.modi ); // Split token on ','. This modifies switcher_str. for ( char *token = strtok_r ( switcher_str, ",", &savept ); token != NULL; token = strtok_r ( NULL, ",", &savept ) ) { - // Resize and add entry. - modi = (ModeHolder *) g_realloc ( modi, sizeof ( ModeHolder ) * ( num_modi + 1 ) ); - modi[num_modi].tb = NULL; - - // Window switcher. - #ifdef WINDOW_MODE - if ( strcasecmp ( token, "window" ) == 0 ) { - modi[num_modi].sw = &window_mode; - num_modi++; - } - else if ( strcasecmp ( token, "windowcd" ) == 0 ) { - modi[num_modi].sw = &window_mode_cd; - num_modi++; - } - else - #endif // WINDOW_MODE - // SSh dialog - if ( strcasecmp ( token, "ssh" ) == 0 ) { - modi[num_modi].sw = &ssh_mode; - num_modi++; - } - // Run dialog - else if ( strcasecmp ( token, "run" ) == 0 ) { - modi[num_modi].sw = &run_mode; - num_modi++; - } - else if ( strcasecmp ( token, "drun" ) == 0 ) { - modi[num_modi].sw = &drun_mode; - num_modi++; - } - // combi dialog - else if ( strcasecmp ( token, "combi" ) == 0 ) { - modi[num_modi].sw = &combi_mode; - num_modi++; - } - else { - // If not build in, use custom modi. - Mode *sw = script_switcher_parse_setup ( token ); - if ( sw != NULL ) { - modi[num_modi].sw = sw; - mode_set_config ( sw ); - num_modi++; - } - else{ - // Report error, don't continue. - fprintf ( stderr, "Invalid script switcher: %s\n", token ); - token = NULL; - } - } - // Keybinding. + add_mode ( token ); } // Free string that was modified by strtok_r g_free ( switcher_str ); @@ -2481,6 +2486,17 @@ int main ( int argc, char *argv[] ) char *sname = NULL; if ( find_arg_str ( "-show", &sname ) == TRUE ) { int index = switcher_get ( sname ); + if ( index < 0 ) { + // Add it to the list + index = add_mode ( sname ); + // Complain + if ( index >= 0 ) { + fprintf ( stdout, "Mode %s not enabled. Please add it to the list of enabled modi: %s\n", + sname, config.modi ); + fprintf ( stdout, "Adding mode: %s\n", sname ); + } + // Run it anyway if found. + } if ( index >= 0 ) { run_switcher ( index ); } |