From 9b415e60a0c7f94af52a2a2a718b82e0f0e54beb Mon Sep 17 00:00:00 2001 From: QC Date: Sun, 5 Apr 2015 13:36:39 +0200 Subject: [PATCH] Fix crasher with fixed-lines off and 0 visible rows --- include/rofi.h | 1 + source/dialogs/window.c | 4 ++++ source/rofi.c | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/include/rofi.h b/include/rofi.h index 387bbe92..40e4ace1 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -261,4 +261,5 @@ struct _Switcher switcher_free free; }; +void menu_unmap ( void ); #endif diff --git a/source/dialogs/window.c b/source/dialogs/window.c index 44f84757..2a399d6b 100644 --- a/source/dialogs/window.c +++ b/source/dialogs/window.c @@ -482,6 +482,10 @@ static SwitcherMode window_mode_result ( int mretv, G_GNUC_UNUSED char **input, retv = selected_line; } else if ( ( mretv & ( MENU_OK | MENU_CUSTOM_INPUT ) ) && rmpd->cmd_list[selected_line] ) { + // Window is going to be removed later (retv == MODE_EXIT). + // Unmap it first, so (not so)awesomewm does not get confused and give application beneath + // rofi focus on destory. + menu_unmap (); if ( rmpd->config_i3_mode ) { // Hack for i3. i3_support_focus_window ( rmpd->ids->array[selected_line] ); diff --git a/source/rofi.c b/source/rofi.c index f8e322d4..3acad4ed 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -115,6 +115,17 @@ GC gc = NULL; Colormap map = None; XVisualInfo vinfo; + +void menu_unmap ( void ) +{ + if ( main_window != None ) { + release_keyboard(display); + XUnmapWindow(display, main_window); + + } +} + + /** * @param display Connection to the X server. * @param x11_fd File descriptor from the X server to listen on. @@ -410,6 +421,8 @@ static void menu_calculate_rows_columns ( MenuState *state ) ( state->num_lines + ( state->columns - state->num_lines % state->columns ) % state->columns ) / ( state->columns ) ) ); + // Always have at least one row. + state->max_rows = MAX( 1, state->max_rows); if ( config.fixed_num_lines == TRUE ) { state->max_elements = state->menu_lines * state->columns;