1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-25 13:55:34 -05:00

Scale down number of columns when not enough rows are available.

This commit is contained in:
QC 2014-05-24 10:35:09 +02:00
parent b1e6030c34
commit 326b562c29

View file

@ -976,6 +976,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
{ {
int retv = MENU_CANCEL; int retv = MENU_CANCEL;
unsigned int i, j; unsigned int i, j;
unsigned int columns = config.menu_columns;
workarea mon; workarea mon;
@ -988,21 +989,27 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
} }
unsigned int max_elements = MIN ( config.menu_lines * config.menu_columns, num_lines ); unsigned int max_elements = MIN ( config.menu_lines * columns, num_lines );
// TODO, clean this up. // TODO, clean this up.
// Calculate the number or rows. // Calculate the number or rows.
// we do this by getting the num_lines rounded up to X columns (num elements is better name) // we do this by getting the num_lines rounded up to X columns (num elements is better name)
// then dividing by columns. // then dividing by columns.
unsigned int max_rows = MIN ( config.menu_lines, unsigned int max_rows = MIN ( config.menu_lines,
(unsigned int) ( (unsigned int) (
( num_lines + ( config.menu_columns - num_lines % config.menu_columns ) % config.menu_columns ) / ( num_lines + ( columns - num_lines % columns ) ) /
( config.menu_columns ) ( columns )
) ); ) );
if ( config.fixed_num_lines == 1 ) if ( config.fixed_num_lines == TRUE )
{ {
max_elements = config.menu_lines * config.menu_columns; max_elements = config.menu_lines * columns;
max_rows = config.menu_lines; max_rows = config.menu_lines;
// If it would fit in one column, only use one column.
if ( num_lines < max_elements )
{
columns = ( num_lines + ( max_rows - num_lines % max_rows ) ) / max_rows;
max_elements = config.menu_lines * columns;
}
} }
// More hacks. // More hacks.
if ( config.hmode == TRUE ) if ( config.hmode == TRUE )
@ -1018,7 +1025,7 @@ MenuReturn menu ( char **lines, char **input, char *prompt, Time *time, int *shi
int x = mon.x + ( mon.w - w ) / 2; int x = mon.x + ( mon.w - w ) / 2;
int element_width = w - ( 2 * ( config.padding ) ); int element_width = w - ( 2 * ( config.padding ) );
// Divide by the # columns // Divide by the # columns
element_width /= config.menu_columns; element_width /= columns;
if ( config.hmode == TRUE ) if ( config.hmode == TRUE )
{ {
element_width = ( w - ( 2 * ( config.padding ) ) - max_elements * LINE_MARGIN ) / ( max_elements + 1 ); element_width = ( w - ( 2 * ( config.padding ) ) - max_elements * LINE_MARGIN ) / ( max_elements + 1 );