diff options
-rw-r--r-- | Changelog | 6 | ||||
-rw-r--r-- | doc/rofi-manpage.markdown | 4 | ||||
-rw-r--r-- | doc/rofi.1 | 8 | ||||
-rw-r--r-- | include/dialogs/dmenu-dialog.h | 6 | ||||
-rw-r--r-- | source/dialogs/dmenu-dialog.c | 33 | ||||
-rw-r--r-- | source/rofi.c | 7 |
6 files changed, 45 insertions, 19 deletions
@@ -1,4 +1,8 @@ -0.15.2: (unreleased) +0.15.3: (unreleased) + New feature: + - Number mode for dmenu. allows user to get index back instead of content. + +0.15.2: Removed features: - Remove (broken) hmode - Old style key binding and mode launcher. diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 0727af02..bc82fb1b 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -356,6 +356,10 @@ daemon listening to specific key-combinations. Default: *0* +`-i` + + Number mode, return the index of the selected row. (starting at 0) + ### Message dialog `-e` *message* @@ -439,6 +439,14 @@ Select a certain line. Default: *0* .fi .RE +.PP +\fB\fC\-i\fR +.PP +.RS +.nf +Number mode, return the index of the selected row. (starting at 0) +.fi +.RE .SS Message dialog .PP \fB\fC\-e\fR \fImessage\fP diff --git a/include/dialogs/dmenu-dialog.h b/include/dialogs/dmenu-dialog.h index 8876cc97..da08b44b 100644 --- a/include/dialogs/dmenu-dialog.h +++ b/include/dialogs/dmenu-dialog.h @@ -1,12 +1,6 @@ #ifndef __DMENU_DIALOG_H__ #define __DMENU_DIALOG_H__ -/** - * Prompt used in dmenu. - */ -extern char *dmenu_prompt; -extern int dmenu_selected_line; - /** * @param input Pointer to the user-input string. diff --git a/source/dialogs/dmenu-dialog.c b/source/dialogs/dmenu-dialog.c index 42552a12..93501ea5 100644 --- a/source/dialogs/dmenu-dialog.c +++ b/source/dialogs/dmenu-dialog.c @@ -36,8 +36,6 @@ #include "dialogs/dmenu-dialog.h" #include "helper.h" -char *dmenu_prompt = "dmenu "; -int dmenu_selected_line = 0; static char **get_dmenu ( int *length ) { @@ -66,14 +64,28 @@ static char **get_dmenu ( int *length ) return retv; } +// Remote pointer to input arguments. +extern int stored_argc; +extern char **stored_argv; + int dmenu_switcher_dialog ( char **input ) { - int selected_line = dmenu_selected_line; + char *dmenu_prompt = "dmenu "; + int selected_line = 0; int retv = FALSE; int length = 0; char **list = get_dmenu ( &length ); int restart = FALSE; + int number_mode = FALSE; + // Check if the user requested number mode. + if ( find_arg ( stored_argc, stored_argv, "-i" ) >= 0 ) { + number_mode = TRUE; + } + // Check prompt + find_arg_str ( stored_argc, stored_argv, "-p", &dmenu_prompt ); + find_arg_int ( stored_argc, stored_argv, "-l", &selected_line ); + do { int shift = 0; int mretv = menu ( list, length, input, dmenu_prompt, NULL, &shift, @@ -82,7 +94,12 @@ int dmenu_switcher_dialog ( char **input ) // We normally do not want to restart the loop. restart = FALSE; if ( mretv == MENU_OK && list[selected_line] != NULL ) { - fputs ( list[selected_line], stdout ); + if ( number_mode ) { + fprintf ( stdout, "%d", selected_line ); + } + else { + fputs ( list[selected_line], stdout ); + } fputc ( '\n', stdout ); fflush ( stdout ); if ( shift ) { @@ -93,9 +110,11 @@ int dmenu_switcher_dialog ( char **input ) retv = TRUE; } else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) { - fputs ( *input, stdout ); - fputc ( '\n', stdout ); - fflush ( stdout ); + if ( !number_mode ) { + fputs ( *input, stdout ); + fputc ( '\n', stdout ); + fflush ( stdout ); + } if ( shift ) { restart = TRUE; // Move to next line. diff --git a/source/rofi.c b/source/rofi.c index 87828fec..5b59512e 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -1582,8 +1582,8 @@ static void setup_switchers ( void ) /** * Keep a copy of arc, argv around, so we can use the same parsing method */ -static int stored_argc; -static char **stored_argv; +int stored_argc; +char **stored_argv; /** * @param display Pointer to the X connection to use. @@ -1739,9 +1739,6 @@ int main ( int argc, char *argv[] ) if ( dmenu_mode == TRUE ) { // force off sidebar mode: config.sidebar_mode = FALSE; - // Check prompt - find_arg_str ( argc, argv, "-p", &dmenu_prompt ); - find_arg_int ( argc, argv, "-l", &dmenu_selected_line ); int retv = run_dmenu (); // User canceled the operation. |