1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Add number mode for dmenu (Request from Taharqa)

* option -i.
This commit is contained in:
Dave Davenport 2015-03-11 18:05:39 +01:00
parent 51ac73b7b8
commit c89a272d4d
6 changed files with 45 additions and 19 deletions

View file

@ -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: Removed features:
- Remove (broken) hmode - Remove (broken) hmode
- Old style key binding and mode launcher. - Old style key binding and mode launcher.

View file

@ -356,6 +356,10 @@ daemon listening to specific key-combinations.
Default: *0* Default: *0*
`-i`
Number mode, return the index of the selected row. (starting at 0)
### Message dialog ### Message dialog
`-e` *message* `-e` *message*

View file

@ -439,6 +439,14 @@ Select a certain line.
Default: *0* Default: *0*
.fi .fi
.RE .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 .SS Message dialog
.PP .PP
\fB\fC\-e\fR \fImessage\fP \fB\fC\-e\fR \fImessage\fP

View file

@ -1,12 +1,6 @@
#ifndef __DMENU_DIALOG_H__ #ifndef __DMENU_DIALOG_H__
#define __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. * @param input Pointer to the user-input string.

View file

@ -36,8 +36,6 @@
#include "dialogs/dmenu-dialog.h" #include "dialogs/dmenu-dialog.h"
#include "helper.h" #include "helper.h"
char *dmenu_prompt = "dmenu ";
int dmenu_selected_line = 0;
static char **get_dmenu ( int *length ) static char **get_dmenu ( int *length )
{ {
@ -66,14 +64,28 @@ static char **get_dmenu ( int *length )
return retv; return retv;
} }
// Remote pointer to input arguments.
extern int stored_argc;
extern char **stored_argv;
int dmenu_switcher_dialog ( char **input ) int dmenu_switcher_dialog ( char **input )
{ {
int selected_line = dmenu_selected_line; char *dmenu_prompt = "dmenu ";
int selected_line = 0;
int retv = FALSE; int retv = FALSE;
int length = 0; int length = 0;
char **list = get_dmenu ( &length ); char **list = get_dmenu ( &length );
int restart = FALSE; 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 { do {
int shift = 0; int shift = 0;
int mretv = menu ( list, length, input, dmenu_prompt, NULL, &shift, 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. // We normally do not want to restart the loop.
restart = FALSE; restart = FALSE;
if ( mretv == MENU_OK && list[selected_line] != NULL ) { if ( mretv == MENU_OK && list[selected_line] != NULL ) {
if ( number_mode ) {
fprintf ( stdout, "%d", selected_line );
}
else {
fputs ( list[selected_line], stdout ); fputs ( list[selected_line], stdout );
}
fputc ( '\n', stdout ); fputc ( '\n', stdout );
fflush ( stdout ); fflush ( stdout );
if ( shift ) { if ( shift ) {
@ -93,9 +110,11 @@ int dmenu_switcher_dialog ( char **input )
retv = TRUE; retv = TRUE;
} }
else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) { else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) {
if ( !number_mode ) {
fputs ( *input, stdout ); fputs ( *input, stdout );
fputc ( '\n', stdout ); fputc ( '\n', stdout );
fflush ( stdout ); fflush ( stdout );
}
if ( shift ) { if ( shift ) {
restart = TRUE; restart = TRUE;
// Move to next line. // Move to next line.

View file

@ -1582,8 +1582,8 @@ static void setup_switchers ( void )
/** /**
* Keep a copy of arc, argv around, so we can use the same parsing method * Keep a copy of arc, argv around, so we can use the same parsing method
*/ */
static int stored_argc; int stored_argc;
static char **stored_argv; char **stored_argv;
/** /**
* @param display Pointer to the X connection to use. * @param display Pointer to the X connection to use.
@ -1739,9 +1739,6 @@ int main ( int argc, char *argv[] )
if ( dmenu_mode == TRUE ) { if ( dmenu_mode == TRUE ) {
// force off sidebar mode: // force off sidebar mode:
config.sidebar_mode = FALSE; 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 (); int retv = run_dmenu ();
// User canceled the operation. // User canceled the operation.