summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/rofi.h3
-rw-r--r--source/dialogs/dmenu.c6
-rw-r--r--source/rofi.c43
3 files changed, 26 insertions, 26 deletions
diff --git a/include/rofi.h b/include/rofi.h
index c1824090..95fd06c6 100644
--- a/include/rofi.h
+++ b/include/rofi.h
@@ -52,7 +52,6 @@ typedef enum
*/
MenuState *menu ( Mode *sw,
char *input, char *prompt,
- unsigned int selected_line,
const char *message, MenuFlags flags )
__attribute__ ( ( nonnull ( 1, 2, 3 ) ) );
@@ -92,5 +91,7 @@ void menu_state_itterrate ( MenuState *state, XEvent *event );
unsigned int menu_state_get_completed ( const MenuState *state );
const char * menu_state_get_user_input ( const MenuState *state );
void menu_state_free ( MenuState *state );
+void menu_state_restart ( MenuState *state );
+void menu_state_set_selected_line ( MenuState *state, unsigned int selected_line );
/*@}*/
#endif
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c
index ecb12fa2..37749b67 100644
--- a/source/dialogs/dmenu.c
+++ b/source/dialogs/dmenu.c
@@ -398,9 +398,11 @@ int dmenu_switcher_dialog ( void )
return TRUE;
}
+ MenuState *state = menu ( &dmenu_mode, input, pd->prompt, pd->message, menu_flags );
do {
+ menu_state_restart ( state );
+ menu_state_set_selected_line ( state, pd->selected_line );
retv = FALSE;
- MenuState *state = menu ( &dmenu_mode, input, pd->prompt, ( pd->selected_line ), pd->message, menu_flags );
// Enter main loop.
while ( !menu_state_get_completed ( state ) ) {
@@ -416,7 +418,6 @@ int dmenu_switcher_dialog ( void )
pd->selected_line = menu_state_get_selected_line ( state );;
MenuReturn mretv = menu_state_get_return_value ( state );
unsigned int next_pos = menu_state_get_next_position ( state );
- menu_state_free ( state );
// Special behavior.
// TODO clean this up!
@@ -494,6 +495,7 @@ int dmenu_switcher_dialog ( void )
}
} while ( restart );
+ menu_state_free ( state );
g_free ( input );
mode_destroy ( &dmenu_mode );
return retv;
diff --git a/source/rofi.c b/source/rofi.c
index 58396c64..546f6c97 100644
--- a/source/rofi.c
+++ b/source/rofi.c
@@ -235,7 +235,25 @@ static MenuState *menu_state_create ( void )
{
return g_malloc0 ( sizeof ( MenuState ) );
}
+void menu_state_restart ( MenuState *state )
+{
+ state->quit = FALSE;
+ state->retv = MENU_CANCEL;
+}
+void menu_state_set_selected_line ( MenuState *state, unsigned int selected_line )
+{
+ state->selected_line = selected_line;
+ // Find the line.
+ state->selected = 0;
+ for ( unsigned int i = 0; ( ( state->selected_line ) ) < UINT32_MAX && !state->selected && i < state->filtered_lines; i++ ) {
+ if ( state->line_map[i] == ( state->selected_line ) ) {
+ state->selected = i;
+ break;
+ }
+ }
+ state->update = TRUE;
+}
void menu_state_free ( MenuState *state )
{
// Do this here?
@@ -1457,14 +1475,13 @@ static void menu_mainloop_iter ( MenuState *state, XEvent *ev )
MenuState *menu ( Mode *sw,
char *input,
char *prompt,
- unsigned int selected_line,
const char *message,
MenuFlags menu_flags )
{
TICK ();
MenuState *state = menu_state_create ();
state->sw = sw;
- state->selected_line = selected_line;
+ state->selected_line = UINT32_MAX;
state->retv = MENU_CANCEL;
state->distance = NULL;
state->quit = FALSE;
@@ -1656,31 +1673,11 @@ MenuState *menu ( Mode *sw,
state->update = TRUE;
menu_refilter ( state );
- for ( unsigned int i = 0; ( ( state->selected_line ) ) < UINT32_MAX && !state->selected && i < state->filtered_lines; i++ ) {
- if ( state->line_map[i] == ( state->selected_line ) ) {
- state->selected = i;
- break;
- }
- }
-
menu_update ( state );
if ( sncontext != NULL ) {
sn_launchee_context_complete ( sncontext );
}
return state;
-/*
- if ( next_pos ) {
- if ( ( state->selected + 1 ) < state->num_lines ) {
- *( next_pos ) = state->line_map[state->selected + 1];
- }
- }
-
- int retv = state->retv;
- menu_state_free ( state );
-
-
- return retv;
- */
}
void error_dialog ( const char *msg, int markup )
@@ -2268,7 +2265,7 @@ static int main_loop_signal_handler ( char command, int quiet )
ModeMode switcher_run ( char **input, Mode *sw )
{
char *prompt = g_strdup_printf ( "%s:", mode_get_name ( sw ) );
- MenuState * state = menu ( sw, *input, prompt, UINT32_MAX, NULL, MENU_NORMAL );
+ MenuState * state = menu ( sw, *input, prompt, NULL, MENU_NORMAL );
g_free ( prompt );
g_return_val_if_fail ( state != NULL, MODE_EXIT );