1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2025-02-17 15:45:56 -05:00

Allow user to open an disabled modi.

This commit is contained in:
Dave Davenport 2016-02-04 09:20:10 +01:00
parent bb6ae77ba5
commit 69b88caac5
2 changed files with 67 additions and 52 deletions

View file

@ -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;

View file

@ -1968,19 +1968,15 @@ static void cleanup ()
* First the three build-in modi are checked: window, run, ssh
* if that fails, a script-switcher is created.
*/
static void setup_modi ( void )
static int add_mode ( const char * token )
{
char *savept = NULL;
// Make a copy, as strtok will modify it.
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 ) ) {
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
#ifdef WINDOW_MODE
if ( strcasecmp ( token, "window" ) == 0 ) {
modi[num_modi].sw = &window_mode;
num_modi++;
@ -1990,7 +1986,7 @@ static void setup_modi ( void )
num_modi++;
}
else
#endif // WINDOW_MODE
#endif // WINDOW_MODE
// SSh dialog
if ( strcasecmp ( token, "ssh" ) == 0 ) {
modi[num_modi].sw = &ssh_mode;
@ -2024,7 +2020,16 @@ static void setup_modi ( void )
token = NULL;
}
}
// Keybinding.
return ( index == num_modi ) ? -1 : (int) index;
}
static void setup_modi ( void )
{
char *savept = NULL;
// Make a copy, as strtok will modify it.
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 ) ) {
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 );
}