diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-01-26 08:37:40 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-01-26 08:38:07 +0100 |
commit | eab4e1438f173e7a1052a0fd81163d8ea79fe1e5 (patch) | |
tree | 288a6d0d1eaa211a1cdca5fbbb67a45f68510e9b /source | |
parent | 3da03c068de975ae44a3c02f932175f8cc95fd8d (diff) |
Make dmenu use glib mainloop.
Diffstat (limited to 'source')
-rw-r--r-- | source/dialogs/dmenu.c | 9 | ||||
-rw-r--r-- | source/rofi.c | 20 |
2 files changed, 16 insertions, 13 deletions
diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 37749b67..025ed788 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -404,15 +404,12 @@ int dmenu_switcher_dialog ( void ) menu_state_set_selected_line ( state, pd->selected_line ); retv = FALSE; + menu_state_set_active ( state ); // Enter main loop. while ( !menu_state_get_completed ( state ) ) { - // Wait for event. - XEvent ev; - // Get next event. (might block) - XNextEvent ( display, &ev ); - TICK_N ( "X Event" ); - menu_state_itterrate ( state, &ev ); + g_main_context_iteration ( NULL, TRUE ); } + menu_state_set_active ( NULL ); g_free ( input ); input = g_strdup ( menu_state_get_user_input ( state ) ); pd->selected_line = menu_state_get_selected_line ( state );; diff --git a/source/rofi.c b/source/rofi.c index 635b91e5..a184e924 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -239,6 +239,11 @@ void menu_state_restart ( MenuState *state ) state->quit = FALSE; state->retv = MENU_CANCEL; } +void menu_state_set_active ( MenuState *state ) +{ + g_assert ( ( current_active_menu == NULL && state != NULL ) || ( current_active_menu != NULL && state == NULL ) ); + current_active_menu = state; +} void menu_state_set_selected_line ( MenuState *state, unsigned int selected_line ) { state->selected_line = selected_line; @@ -1492,7 +1497,6 @@ MenuState *menu ( Mode *sw, state->cur_page = -1; state->border = config.padding + config.menu_bw; state->x11_event_loop = menu_mainloop_iter; - state->finalize = process_result; // Request the lines to show. state->num_lines = mode_get_num_entries ( sw ); @@ -1755,11 +1759,11 @@ void error_dialog ( const char *msg, int markup ) if ( sncontext != NULL ) { sn_launchee_context_complete ( sncontext ); } - current_active_menu = state; - while ( !state->quit ) { + menu_state_set_active ( state ); + while ( !menu_state_get_completed ( state ) ) { g_main_context_iteration ( NULL, TRUE ); } - current_active_menu = NULL; + menu_state_set_active ( NULL ); menu_state_free ( state ); } @@ -1852,7 +1856,8 @@ static void run_switcher ( ModeMode mode ) char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode].sw ) ); curr_switcher = mode; MenuState * state = menu ( modi[mode].sw, input, prompt, NULL, MENU_NORMAL ); - current_active_menu = state; + state->finalize = process_result; + menu_state_set_active ( state ); g_free ( prompt ); } static void process_result ( MenuState *state ) @@ -1860,8 +1865,8 @@ static void process_result ( MenuState *state ) unsigned int selected_line = menu_state_get_selected_line ( state );; MenuReturn mretv = menu_state_get_return_value ( state ); char *input = g_strdup ( menu_state_get_user_input ( state ) ); + menu_state_set_active ( NULL ); menu_state_free ( state ); - current_active_menu = NULL; ModeMode retv = mode_result ( modi[curr_switcher].sw, mretv, &input, selected_line ); ModeMode mode = curr_switcher; @@ -1890,10 +1895,11 @@ static void process_result ( MenuState *state ) char *prompt = g_strdup_printf ( "%s:", mode_get_name ( modi[mode].sw ) ); curr_switcher = mode; MenuState * state = menu ( modi[mode].sw, input, prompt, NULL, MENU_NORMAL ); + state->finalize = process_result; g_free ( prompt ); // TODO FIX //g_return_val_if_fail ( state != NULL, MODE_EXIT ); - current_active_menu = state; + menu_state_set_active ( state ); g_free ( input ); return; } |