mirror of
https://github.com/davatorium/rofi.git
synced 2024-11-25 13:55:34 -05:00
Fix #76: DMENU returns 1 on cancel.
* Pull out dmenu, separate it from normal modi. * Give dmenu a return value (1 on cancel)
This commit is contained in:
parent
da69111a20
commit
b196649f10
4 changed files with 36 additions and 17 deletions
|
@ -2,6 +2,9 @@
|
||||||
#define __DMENU_DIALOG_H__
|
#define __DMENU_DIALOG_H__
|
||||||
|
|
||||||
extern char *dmenu_prompt;
|
extern char *dmenu_prompt;
|
||||||
SwitcherMode dmenu_switcher_dialog ( char **input, void *data );
|
/**
|
||||||
|
* Returns TRUE when success, FALSE when canceled.
|
||||||
|
*/
|
||||||
|
int dmenu_switcher_dialog ( char **input );
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -25,8 +25,6 @@ extern const char *cache_dir;
|
||||||
*/
|
*/
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
/** Dmenu mode */
|
|
||||||
DMENU_DIALOG = 999,
|
|
||||||
/** Exit. */
|
/** Exit. */
|
||||||
MODE_EXIT = 1000,
|
MODE_EXIT = 1000,
|
||||||
/** Skip to the next cycle-able dialog. */
|
/** Skip to the next cycle-able dialog. */
|
||||||
|
|
|
@ -65,10 +65,10 @@ static char **get_dmenu ( unsigned int *length )
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
|
int dmenu_switcher_dialog ( char **input )
|
||||||
{
|
{
|
||||||
int selected_line = 0;
|
int selected_line = 0;
|
||||||
SwitcherMode retv = MODE_EXIT;
|
int retv = FALSE;
|
||||||
unsigned int length = 0;
|
unsigned int length = 0;
|
||||||
char **list = get_dmenu ( &length );
|
char **list = get_dmenu ( &length );
|
||||||
int restart = FALSE;
|
int restart = FALSE;
|
||||||
|
@ -80,10 +80,7 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
|
||||||
|
|
||||||
// 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_NEXT ) {
|
if ( mretv == MENU_OK && list[selected_line] != NULL ) {
|
||||||
retv = RELOAD_DIALOG;
|
|
||||||
}
|
|
||||||
else if ( mretv == MENU_OK && list[selected_line] != NULL ) {
|
|
||||||
fputs ( list[selected_line], stdout );
|
fputs ( list[selected_line], stdout );
|
||||||
fputc ( '\n', stdout );
|
fputc ( '\n', stdout );
|
||||||
fflush ( stdout );
|
fflush ( stdout );
|
||||||
|
@ -92,6 +89,7 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
|
||||||
// Move to next line.
|
// Move to next line.
|
||||||
selected_line = MIN ( selected_line + 1, length - 1 );
|
selected_line = MIN ( selected_line + 1, length - 1 );
|
||||||
}
|
}
|
||||||
|
retv = TRUE;
|
||||||
}
|
}
|
||||||
else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) {
|
else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) {
|
||||||
fputs ( *input, stdout );
|
fputs ( *input, stdout );
|
||||||
|
@ -102,6 +100,7 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
|
||||||
// Move to next line.
|
// Move to next line.
|
||||||
selected_line = MIN ( selected_line + 1, length - 1 );
|
selected_line = MIN ( selected_line + 1, length - 1 );
|
||||||
}
|
}
|
||||||
|
retv = TRUE;
|
||||||
}
|
}
|
||||||
} while ( restart );
|
} while ( restart );
|
||||||
for ( unsigned int i = 0; i < length; i++ ) {
|
for ( unsigned int i = 0; i < length; i++ ) {
|
||||||
|
|
|
@ -1711,6 +1711,25 @@ SwitcherMode run_switcher_window ( char **input, void *data )
|
||||||
return retv;
|
return retv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int run_dmenu ()
|
||||||
|
{
|
||||||
|
int ret_state = TRUE;
|
||||||
|
textbox_setup (
|
||||||
|
config.menu_bg, config.menu_fg,
|
||||||
|
config.menu_hlbg,
|
||||||
|
config.menu_hlfg );
|
||||||
|
char *input = NULL;
|
||||||
|
|
||||||
|
// Dmenu modi has a return state.
|
||||||
|
ret_state = dmenu_switcher_dialog ( &input );
|
||||||
|
|
||||||
|
free ( input );
|
||||||
|
|
||||||
|
// Cleanup font setup.
|
||||||
|
textbox_cleanup ();
|
||||||
|
return ret_state;
|
||||||
|
}
|
||||||
|
|
||||||
static void run_switcher ( int do_fork, SwitcherMode mode )
|
static void run_switcher ( int do_fork, SwitcherMode mode )
|
||||||
{
|
{
|
||||||
// we fork because it's technically possible to have multiple window
|
// we fork because it's technically possible to have multiple window
|
||||||
|
@ -1720,7 +1739,7 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
|
||||||
// strangeness...
|
// strangeness...
|
||||||
if ( do_fork == TRUE ) {
|
if ( do_fork == TRUE ) {
|
||||||
if ( fork () ) {
|
if ( fork () ) {
|
||||||
return;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
display = XOpenDisplay ( 0 );
|
display = XOpenDisplay ( 0 );
|
||||||
|
@ -1733,12 +1752,8 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
|
||||||
config.menu_hlbg,
|
config.menu_hlbg,
|
||||||
config.menu_hlfg );
|
config.menu_hlfg );
|
||||||
char *input = NULL;
|
char *input = NULL;
|
||||||
// Dmenu is a special mode. You can cycle away from it.
|
|
||||||
if ( mode == DMENU_DIALOG ) {
|
|
||||||
dmenu_switcher_dialog ( &input, NULL );
|
|
||||||
}
|
|
||||||
// Otherwise check if requested mode is enabled.
|
// Otherwise check if requested mode is enabled.
|
||||||
else if ( switchers[mode].cb != NULL ) {
|
if ( switchers[mode].cb != NULL ) {
|
||||||
do {
|
do {
|
||||||
SwitcherMode retv = MODE_EXIT;
|
SwitcherMode retv = MODE_EXIT;
|
||||||
|
|
||||||
|
@ -1751,7 +1766,7 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
|
||||||
else if ( retv == RELOAD_DIALOG ) {
|
else if ( retv == RELOAD_DIALOG ) {
|
||||||
// do nothing.
|
// do nothing.
|
||||||
}
|
}
|
||||||
else if ( retv < DMENU_DIALOG ) {
|
else if ( retv < MODE_EXIT ) {
|
||||||
mode = ( retv ) % num_switchers;
|
mode = ( retv ) % num_switchers;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2216,7 +2231,11 @@ int main ( int argc, char *argv[] )
|
||||||
}
|
}
|
||||||
else if ( find_arg ( argc, argv, "-dmenu" ) >= 0 ) {
|
else if ( find_arg ( argc, argv, "-dmenu" ) >= 0 ) {
|
||||||
find_arg_str ( argc, argv, "-p", &dmenu_prompt );
|
find_arg_str ( argc, argv, "-p", &dmenu_prompt );
|
||||||
run_switcher ( FALSE, DMENU_DIALOG );
|
int retv = run_dmenu();
|
||||||
|
// User cancelled the operation.
|
||||||
|
if(retv == FALSE) {
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
// Daemon mode, Listen to key presses..
|
// Daemon mode, Listen to key presses..
|
||||||
|
|
Loading…
Reference in a new issue