summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Davenport <qball@gmpclient.org>2014-08-05 09:07:41 +0200
committerDave Davenport <qball@gmpclient.org>2014-08-05 09:07:41 +0200
commitb196649f1053d509c4b9668de0fcb414127b0f6f (patch)
treec2402b41ce0642d623ca2de0599b7d91d2b59046
parentda69111a20358169de4e0dae6c54c696008f4928 (diff)
Fix #76: DMENU returns 1 on cancel.
* Pull out dmenu, separate it from normal modi. * Give dmenu a return value (1 on cancel)
-rw-r--r--include/dmenu-dialog.h5
-rw-r--r--include/rofi.h2
-rw-r--r--source/dmenu-dialog.c11
-rw-r--r--source/rofi.c35
4 files changed, 36 insertions, 17 deletions
diff --git a/include/dmenu-dialog.h b/include/dmenu-dialog.h
index 4c22a2e0..8c2da41f 100644
--- a/include/dmenu-dialog.h
+++ b/include/dmenu-dialog.h
@@ -2,6 +2,9 @@
#define __DMENU_DIALOG_H__
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
diff --git a/include/rofi.h b/include/rofi.h
index b639eb21..ad8c5a34 100644
--- a/include/rofi.h
+++ b/include/rofi.h
@@ -25,8 +25,6 @@ extern const char *cache_dir;
*/
typedef enum
{
- /** Dmenu mode */
- DMENU_DIALOG = 999,
/** Exit. */
MODE_EXIT = 1000,
/** Skip to the next cycle-able dialog. */
diff --git a/source/dmenu-dialog.c b/source/dmenu-dialog.c
index 8fd77311..7048bf33 100644
--- a/source/dmenu-dialog.c
+++ b/source/dmenu-dialog.c
@@ -65,10 +65,10 @@ static char **get_dmenu ( unsigned int *length )
return retv;
}
-SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
+int dmenu_switcher_dialog ( char **input )
{
int selected_line = 0;
- SwitcherMode retv = MODE_EXIT;
+ int retv = FALSE;
unsigned int length = 0;
char **list = get_dmenu ( &length );
int restart = FALSE;
@@ -80,10 +80,7 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
// We normally do not want to restart the loop.
restart = FALSE;
- if ( mretv == MENU_NEXT ) {
- retv = RELOAD_DIALOG;
- }
- else if ( mretv == MENU_OK && list[selected_line] != NULL ) {
+ if ( mretv == MENU_OK && list[selected_line] != NULL ) {
fputs ( list[selected_line], stdout );
fputc ( '\n', stdout );
fflush ( stdout );
@@ -92,6 +89,7 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
// Move to next line.
selected_line = MIN ( selected_line + 1, length - 1 );
}
+ retv = TRUE;
}
else if ( mretv == MENU_CUSTOM_INPUT && *input != NULL && *input[0] != '\0' ) {
fputs ( *input, stdout );
@@ -102,6 +100,7 @@ SwitcherMode dmenu_switcher_dialog ( char **input, void *data )
// Move to next line.
selected_line = MIN ( selected_line + 1, length - 1 );
}
+ retv = TRUE;
}
} while ( restart );
for ( unsigned int i = 0; i < length; i++ ) {
diff --git a/source/rofi.c b/source/rofi.c
index 07959c4e..957cbe2f 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -1711,6 +1711,25 @@ SwitcherMode run_switcher_window ( char **input, void *data )
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 )
{
// 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...
if ( do_fork == TRUE ) {
if ( fork () ) {
- return;
+ return ;
}
display = XOpenDisplay ( 0 );
@@ -1733,12 +1752,8 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
config.menu_hlbg,
config.menu_hlfg );
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.
- else if ( switchers[mode].cb != NULL ) {
+ if ( switchers[mode].cb != NULL ) {
do {
SwitcherMode retv = MODE_EXIT;
@@ -1751,7 +1766,7 @@ static void run_switcher ( int do_fork, SwitcherMode mode )
else if ( retv == RELOAD_DIALOG ) {
// do nothing.
}
- else if ( retv < DMENU_DIALOG ) {
+ else if ( retv < MODE_EXIT ) {
mode = ( retv ) % num_switchers;
}
else {
@@ -2216,7 +2231,11 @@ int main ( int argc, char *argv[] )
}
else if ( find_arg ( argc, argv, "-dmenu" ) >= 0 ) {
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{
// Daemon mode, Listen to key presses..