Exemple #1
0
static ModeMode combi_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
{
    CombiModePrivateData *pd = mode_get_private_data ( sw );
    if ( *input[0] == '!' ) {
        int switcher = -1;
        for ( unsigned i = 0; switcher == -1 && i < pd->num_switchers; i++ ) {
            if ( ( *input )[1] == mode_get_name ( pd->switchers[i] )[0] ) {
                switcher = i;
            }
        }
        if ( switcher >= 0  ) {
            char *n = strchr ( *input, ' ' );
            // skip whitespace
            if ( n != NULL ) {
                n++;
                return mode_result ( pd->switchers[switcher], mretv, &n,
                                     selected_line - pd->starts[switcher] );
            }
            return MODE_EXIT;
        }
    }

    for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
        if ( selected_line >= pd->starts[i] &&
                selected_line < ( pd->starts[i] + pd->lengths[i] ) ) {
            return mode_result ( pd->switchers[i], mretv, input, selected_line - pd->starts[i] );
        }
    }
    return MODE_EXIT;
}
Exemple #2
0
static int combi_mode_match ( const Mode *sw, char **tokens, int not_ascii,
                              int case_sensitive, unsigned int index )
{
    CombiModePrivateData *pd = mode_get_private_data ( sw );
    if ( config.regex || config.glob ) {
        // Bang support only works in text mode.
        for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
            if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
                return mode_token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
                                          index - pd->starts[i]  );
            }
        }
    }
    else {
        for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
            if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
                if ( tokens && tokens[0][0] == '!' ) {
                    if ( tokens[0][1] == mode_get_name ( pd->switchers[i] )[0] ) {
                        return mode_token_match ( pd->switchers[i], &tokens[1], not_ascii, case_sensitive,
                                                  index - pd->starts[i] );
                    }
                    return 0;
                }
                else {
                    return mode_token_match ( pd->switchers[i], tokens, not_ascii, case_sensitive,
                                              index - pd->starts[i]  );
                }
            }
        }
    }
    abort ();
    return 0;
}
Exemple #3
0
/**
 * @param name Name of the switcher to lookup.
 *
 * Find the index of the switcher with name.
 *
 * @returns index of the switcher in modi, -1 if not found.
 */
static int switcher_get ( const char *name )
{
    for ( unsigned int i = 0; i < num_modi; i++ ) {
        if ( strcmp ( mode_get_name ( modi[i] ), name ) == 0 ) {
            return i;
        }
    }
    return -1;
}
Exemple #4
0
static void __run_switcher_internal ( ModeMode mode, char *input )
{
    char          *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode] ) );
    curr_switcher = mode;
    RofiViewState * state = rofi_view_create ( modi[mode], input, prompt, NULL, MENU_NORMAL, process_result );
    if ( state ) {
        rofi_view_set_active ( state );
    }
    else {
        g_main_loop_quit ( main_loop  );
    }
    g_free ( prompt );
}
Exemple #5
0
static char * combi_get_completion ( const Mode *sw, unsigned int index )
{
    CombiModePrivateData *pd = mode_get_private_data ( sw );
    for ( unsigned i = 0; i < pd->num_switchers; i++ ) {
        if ( index >= pd->starts[i] && index < ( pd->starts[i] + pd->lengths[i] ) ) {
            char *comp = mode_get_completion ( pd->switchers[i], index - pd->starts[i] );
            char *mcomp = g_strdup_printf ( "!%c %s", mode_get_name ( pd->switchers[i] )[0], comp );
            g_free(comp);
            return mcomp;
        }
    }
    // Should never get here.
    g_error ( "Failure, could not resolve sub-switcher." );
    return NULL;
}