diff --git a/include/scrollbar.h b/include/scrollbar.h index df6992a5..fde8c994 100644 --- a/include/scrollbar.h +++ b/include/scrollbar.h @@ -90,4 +90,12 @@ void scrollbar_draw ( scrollbar *sb ); */ unsigned int scrollbar_clicked ( scrollbar *sb, int y ); +/** + * @param sb scrollbar object + * @param w new width in pixels + * @param h new height in pixels + * + * Resize the scrollbar. + */ +void scrollbar_resize ( scrollbar *sb, int w, int h ); #endif // ROFI_SCROLLBAR_H diff --git a/source/rofi.c b/source/rofi.c index e1433079..39912d00 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -926,6 +926,40 @@ static void menu_resize ( MenuState *state ) textbox_draw ( switchers[j].tb ); } } + /** + * Resize in Height + */ + { + unsigned int last_length = state->max_elements; + int element_height = state->line_height * config.element_height + config.line_margin; + // Calculated new number of boxes. + unsigned int h = ( state->h - state->top_offset ); + if ( config.sidebar_mode == TRUE ) { + h -= state->line_height + config.padding; + } + state->max_rows = ( h / element_height ); + state->max_elements = state->max_rows * config.menu_columns; + // Free boxes no longer needed. + for ( unsigned int i = state->max_elements; i < last_length; i++ ) { + textbox_free ( state->boxes[i] ); + } + // resize array. + state->boxes = g_realloc ( state->boxes, state->max_elements * sizeof ( textbox* ) ); + + int y_offset = state->top_offset; + int x_offset = config.padding; + // Add newly added boxes. + for ( unsigned int i = last_length; i < state->max_elements; i++ ) { + state->boxes[i] = textbox_create ( main_window, &vinfo, map, 0, + x_offset, y_offset, + state->element_width, element_height, NORMAL, "" ); + } + scrollbar_resize ( state->scrollbar, -1, + ( state->max_rows ) * ( element_height ) - config.line_margin ); + } + + + state->rchanged = TRUE; state->update = TRUE; } @@ -1173,8 +1207,10 @@ MenuReturn menu ( Switcher *sw, char **input, char *prompt, else if ( ev.type == ConfigureNotify ) { XConfigureEvent xce = ev.xconfigure; if ( xce.window == main_window ) { - if ( state.w != (unsigned int) xce.width ) { + if ( state.w != (unsigned int) xce.width || + state.h != (unsigned int ) xce.height ) { state.w = xce.width; + state.h = xce.height; menu_resize ( &state ); } } diff --git a/source/scrollbar.c b/source/scrollbar.c index 24660985..3396af72 100644 --- a/source/scrollbar.c +++ b/source/scrollbar.c @@ -131,6 +131,18 @@ void scrollbar_draw ( scrollbar *sb ) XFillRectangle ( display, sb->window, sb->gc, config.line_margin, y, sb->w - config.line_margin, height ); } } +void scrollbar_resize ( scrollbar *sb, int w, int h ) +{ + if ( sb != NULL ) { + if(h > 0 ) { + sb->h = h; + } + if(w > 0 ) { + sb->w = w; + } + XResizeWindow ( display, sb->window, sb->w, sb->h ); + } +} unsigned int scrollbar_clicked ( scrollbar *sb, int y ) {