From a125f6d515a205f2ca4bc16f4a31311aedb540af Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Thu, 18 Feb 2016 19:23:41 +0100 Subject: Try to fix crash with new scrolling method. --- source/view.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/view.c b/source/view.c index 873ee9c8..4abcafc5 100644 --- a/source/view.c +++ b/source/view.c @@ -696,7 +696,8 @@ static unsigned int rofi_scroll_continious ( RofiViewState * state ) if ( state->selected < ( state->filtered_lines - (state->menu_lines -middle) ) ) { offset = state->selected - middle; } - else { + // Don't go below zero. + else if ( state->filtered_lines > state->menu_lines){ offset = state->filtered_lines - state->menu_lines; } } @@ -723,6 +724,9 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) columns = MIN ( columns, state->columns ); // Update the handle length. + // Calculate number of visible rows. + unsigned int max_elements = MIN ( a_lines, state->max_rows * columns ); + scrollbar_set_handle_length ( state->scrollbar, columns * state->max_rows ); scrollbar_draw ( state->scrollbar, d ); // Element width. @@ -737,12 +741,10 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) int element_height = state->line_height * config.element_height; int y_offset = state->top_offset; int x_offset = state->border; - // Calculate number of visible rows. - unsigned int max_elements = MIN ( a_lines, state->max_rows * columns ); if ( state->rchanged ) { // Move, resize visible boxes and show them. - for ( i = 0; i < max_elements; i++ ) { + for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin ); unsigned int ey = ( ( i ) % state->max_rows ) * ( element_height + config.line_margin ); // Move it around. @@ -762,7 +764,7 @@ static void rofi_view_draw ( RofiViewState *state, cairo_t *d ) } else{ // Only do basic redrawing + highlight of row. - for ( i = 0; i < max_elements; i++ ) { + for ( i = 0; i < max_elements && (i+offset) < state->filtered_lines; i++ ) { TextBoxFontType type = ( ( ( i % state->max_rows ) & 1 ) == 0 ) ? NORMAL : ALT; int fstate = 0; mode_get_display_value ( state->sw, state->line_map[i + offset], &fstate, FALSE ); -- cgit v1.2.3