mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-18 13:54:36 -05:00
Add number mode for dmenu (Request from Taharqa)
* option -i.
This commit is contained in:
parent
51ac73b7b8
commit
c89a272d4d
6 changed files with 45 additions and 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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue