/** * Parse an option from the commandline vector. */ static void config_parse_cmd_option ( XrmOption *option ) { // Prepend a - to the option name. char *key = g_strdup_printf ( "-%s", option->name ); switch ( option->type ) { case xrm_Number: if ( find_arg_uint ( key, option->value.num ) == TRUE ) { option->source = CONFIG_CMDLINE; } break; case xrm_SNumber: if ( find_arg_int ( key, option->value.snum ) == TRUE ) { option->source = CONFIG_CMDLINE; } break; case xrm_String: if ( find_arg_str ( key, option->value.str ) == TRUE ) { if ( option->mem != NULL ) { g_free ( option->mem ); option->mem = NULL; } option->source = CONFIG_CMDLINE; } break; case xrm_Boolean: if ( find_arg ( key ) >= 0 ) { *( option->value.num ) = TRUE; option->source = CONFIG_CMDLINE; } else { g_free ( key ); key = g_strdup_printf ( "-no-%s", option->name ); if ( find_arg ( key ) >= 0 ) { *( option->value.num ) = FALSE; option->source = CONFIG_CMDLINE; } } break; case xrm_Char: if ( find_arg_char ( key, option->value.charc ) == TRUE ) { option->source = CONFIG_CMDLINE; } break; default: break; } g_free ( key ); }
int dmenu_switcher_dialog ( char **input ) { char *dmenu_prompt = "dmenu "; int selected_line = -1; int retv = FALSE; int length = 0; char **list = get_dmenu ( &length ); int restart = FALSE; char *message = NULL; menu_match_cb filter = token_match; find_arg_str ( "-mesg", &message ); // By default we print the unescaped line back. char *format = "s"; // This is here for compatibility reason. // Use -format 'i' instead. if ( find_arg ( "-i" ) >= 0 ) { format = "i"; } // Allow user to override the output format. find_arg_str ( "-format", &format ); // Check prompt find_arg_str ( "-p", &dmenu_prompt ); find_arg_int ( "-l", &selected_line ); // Urgent. char *str = NULL; find_arg_str ( "-u", &str ); if ( str != NULL ) { parse_ranges ( str, &urgent_list, &num_urgent_list ); } // Active str = NULL; find_arg_str ( "-a", &str ); if ( str != NULL ) { parse_ranges ( str, &active_list, &num_active_list ); } int only_selected = FALSE; if ( find_arg ( "-only-match" ) >= 0 || find_arg ( "-no-custom" ) >= 0 ) { only_selected = TRUE; if ( length == 0 ) { return TRUE; } } find_arg_str_alloc ( "-filter", input ); if ( find_arg ( "-z" ) >= 0 ) { filter = fuzzy_token_match; } char *select = NULL; find_arg_str ( "-select", &select ); if ( select != NULL ) { char **tokens = tokenize ( select, config.case_sensitive ); int i = 0; for ( i = 0; i < length; i++ ) { if ( token_match ( tokens, list[i], config.case_sensitive, 0, NULL ) ) { selected_line = i; break; } } g_strfreev ( tokens ); } do { int next_pos = selected_line; int mretv = menu ( list, length, input, dmenu_prompt, filter, NULL, &selected_line, config.levenshtein_sort, get_display_data, list, &next_pos, message ); // Special behavior. if ( only_selected ) { /** * Select item mode. */ restart = ( find_arg ( "-only-match" ) >= 0 ); if ( ( mretv & ( MENU_OK | MENU_QUICK_SWITCH ) ) && list[selected_line] != NULL ) { dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); retv = TRUE; if ( ( mretv & MENU_QUICK_SWITCH ) ) { retv = 10 + ( mretv & MENU_LOWER_MASK ); } return retv; } selected_line = next_pos - 1; continue; } // We normally do not want to restart the loop. restart = FALSE; // Normal mode if ( ( mretv & MENU_OK ) && list[selected_line] != NULL ) { dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. selected_line = MIN ( next_pos, length - 1 ); } retv = TRUE; } // Custom input else if ( ( mretv & ( MENU_CUSTOM_INPUT ) ) ) { dmenu_output_formatted_line ( format, *input, -1, *input ); if ( ( mretv & MENU_SHIFT ) ) { restart = TRUE; // Move to next line. selected_line = MIN ( next_pos, length - 1 ); } retv = TRUE; } // Quick switch with entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && selected_line >= 0 ) { dmenu_output_formatted_line ( format, list[selected_line], selected_line, *input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); } // Quick switch without entry selected. else if ( ( mretv & MENU_QUICK_SWITCH ) && selected_line == -1 ) { dmenu_output_formatted_line ( format, *input, -1, *input ); restart = FALSE; retv = 10 + ( mretv & MENU_LOWER_MASK ); } } while ( restart ); g_strfreev ( list ); g_free ( urgent_list ); g_free ( active_list ); return retv; }