diff --git a/config/config.def.c b/config/config.def.c index 28fe0ed1..e8aac238 100644 --- a/config/config.def.c +++ b/config/config.def.c @@ -131,6 +131,7 @@ Settings config = { /** Fuzzy matching. */ .fuzzy = FALSE, /** Monitor */ - .monitor = -1, + .monitor = -1, + .line_margin = 3, }; diff --git a/doc/rofi-manpage.markdown b/doc/rofi-manpage.markdown index 034a4f9c..d5ab23a2 100644 --- a/doc/rofi-manpage.markdown +++ b/doc/rofi-manpage.markdown @@ -318,6 +318,14 @@ The following options are further explained in the theming section: Specify the colors used in a row per state (normal, active, urgent). +`-line-margin` + + Set the spacing between the rows. + + Default: *3* + Min: *3* + Max: *50* + ### Layout `-lines` diff --git a/doc/rofi.1 b/doc/rofi.1 index afc3377c..e53dddbe 100644 --- a/doc/rofi.1 +++ b/doc/rofi.1 @@ -559,6 +559,23 @@ Specify the colors used in a row per state (normal, active, urgent)\. . .IP "" 0 . +.P +\fB\-line\-margin\fR +. +.IP "" 4 +. +.nf + +Set the spacing between the rows\. + +Default: *3* +Min: *3* +Max: *50* +. +.fi +. +.IP "" 0 +. .SS "Layout" \fB\-lines\fR . @@ -871,13 +888,13 @@ Default: *dmenu* .IP "" 0 . .P -\fB\-row\fR \fIselected line\fR +\fB\-selected\-row\fR \fIselected row\fR . .IP "" 4 . .nf -Select a certain line\. +Select a certain row\. Default: *0* . diff --git a/include/rofi.h b/include/rofi.h index b626785f..062a8187 100644 --- a/include/rofi.h +++ b/include/rofi.h @@ -230,6 +230,8 @@ typedef struct _Settings unsigned int fuzzy; /** Monitors */ int monitor; + /** Line margin */ + unsigned int line_margin; } Settings; /** Global Settings structure. */ diff --git a/source/dialogs/dmenu.c b/source/dialogs/dmenu.c index 0d8d3e3b..a440f871 100644 --- a/source/dialogs/dmenu.c +++ b/source/dialogs/dmenu.c @@ -234,7 +234,7 @@ int dmenu_switcher_dialog ( char **input ) g_strfreev ( tokens ); } - find_arg_uint ( "-l", &(config.menu_lines)); + find_arg_uint ( "-l", &( config.menu_lines ) ); /** * Dmenu compatibility. diff --git a/source/helper.c b/source/helper.c index 3e7db9ad..225f89bf 100644 --- a/source/helper.c +++ b/source/helper.c @@ -448,7 +448,7 @@ void remove_pid_file ( int fd ) { if ( fd >= 0 ) { if ( close ( fd ) ) { - fprintf(stderr, "Failed to close pidfile: '%s'\n", strerror(errno)); + fprintf ( stderr, "Failed to close pidfile: '%s'\n", strerror ( errno ) ); } } } @@ -486,6 +486,12 @@ void config_sanity_check ( ) config.location = WL_CENTER; found_error = 1; } + if ( !( config.line_margin >= 3 && config.line_margin <= 50 ) ) { + g_string_append_printf ( msg, "\tconfig.line_margin=%d is invalid. Value should be between %d and %d.\n", + config.line_margin, 3, 50 ); + config.line_margin = 3; + found_error = 1; + } if ( found_error ) { g_string_append ( msg, "Please update your configuration." ); show_error_message ( msg->str, TRUE ); diff --git a/source/rofi.c b/source/rofi.c index e2aa0777..c472fa3f 100644 --- a/source/rofi.c +++ b/source/rofi.c @@ -57,7 +57,6 @@ #include "dialogs/window.h" #include "dialogs/combi.h" -#define LINE_MARGIN 3 // TEMP @@ -455,7 +454,7 @@ static void menu_calculate_window_and_element_width ( MenuState *state, workarea if ( state->columns > 0 ) { state->element_width = state->w - ( 2 * ( config.padding ) ); // Divide by the # columns - state->element_width = ( state->element_width - ( state->columns - 1 ) * LINE_MARGIN ) / state->columns; + state->element_width = ( state->element_width - ( state->columns - 1 ) * config.line_margin ) / state->columns; } } @@ -795,7 +794,7 @@ static void menu_draw ( MenuState *state ) // Element width. unsigned int element_width = state->w - ( 2 * ( config.padding ) ); if ( columns > 0 ) { - element_width = ( element_width - ( columns - 1 ) * LINE_MARGIN ) / columns; + element_width = ( element_width - ( columns - 1 ) * config.line_margin ) / columns; } int element_height = state->line_height * config.element_height; @@ -811,8 +810,8 @@ static void menu_draw ( MenuState *state ) if ( state->rchanged ) { // Move, resize visible boxes and show them. for ( i = 0; i < max_elements; i++ ) { - unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + LINE_MARGIN ); - unsigned int ey = ( ( i ) % state->max_rows ) * element_height + LINE_MARGIN; + unsigned int ex = ( ( i ) / state->max_rows ) * ( element_width + config.line_margin ); + unsigned int ey = ( ( i ) % state->max_rows ) * ( element_height + config.line_margin ) + config.line_margin; // Move it around. textbox_moveresize ( state->boxes[i], ex + x_offset, ey + y_offset, @@ -860,23 +859,23 @@ static void menu_update ( MenuState *state ) state->arrowbox_bottom ); // Why do we need the special -1? XDrawLine ( display, main_window, gc, ( config.padding ), - state->line_height + ( config.padding ) + ( LINE_MARGIN ) / 2, + state->line_height + ( config.padding ) + ( config.line_margin ) / 2, state->w - ( ( config.padding ) ) - 1, - state->line_height + ( config.padding ) + ( LINE_MARGIN ) / 2 ); + state->line_height + ( config.padding ) + ( config.line_margin ) / 2 ); if ( state->message_tb ) { XDrawLine ( display, main_window, gc, ( config.padding ), - state->top_offset + ( LINE_MARGIN ) / 2, + state->top_offset + ( config.line_margin ) / 2, state->w - ( ( config.padding ) ) - 1, - state->top_offset + ( LINE_MARGIN ) / 2 ); + state->top_offset + ( config.line_margin ) / 2 ); } if ( config.sidebar_mode == TRUE ) { XDrawLine ( display, main_window, gc, ( config.padding ), - state->h - state->line_height - ( config.padding ) - LINE_MARGIN, + state->h - state->line_height - ( config.padding ) - config.line_margin / 2, state->w - ( ( config.padding ) ) - 1, - state->h - state->line_height - ( config.padding ) - LINE_MARGIN ); + state->h - state->line_height - ( config.padding ) - config.line_margin / 2 ); for ( unsigned int j = 0; j < num_switchers; j++ ) { textbox_draw ( switchers[j]->tb ); } @@ -973,7 +972,7 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom // Height of a row. if ( config.menu_lines == 0 ) { // Autosize it. - int h = mon.h - config.padding * 2 - LINE_MARGIN - config.menu_bw * 2; + int h = mon.h - config.padding * 2 - config.line_margin - config.menu_bw * 2; int r = ( h ) / ( state.line_height * config.element_height ) - 1 - config.sidebar_mode; state.menu_lines = r; } @@ -1054,10 +1053,10 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom "↓" ); textbox_move ( state.arrowbox_top, state.w - config.padding - state.arrowbox_top->w, - state.top_offset + LINE_MARGIN ); + state.top_offset + config.line_margin ); textbox_move ( state.arrowbox_bottom, state.w - config.padding - state.arrowbox_bottom->w, - state.top_offset + ( state.max_rows - 1 ) * element_height + LINE_MARGIN ); + state.top_offset + ( state.max_rows - 1 ) * ( element_height + config.line_margin ) + config.line_margin ); // filtered list state.line_map = g_malloc0_n ( state.num_lines, sizeof ( int ) ); @@ -1067,11 +1066,11 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom // resize window vertically to suit // Subtract the margin of the last row. - state.h = state.top_offset + element_height * state.max_rows + ( config.padding ) + LINE_MARGIN; + state.h = state.top_offset + ( element_height + config.line_margin ) * state.max_rows + ( config.padding ) + config.line_margin; // Add entry if ( config.sidebar_mode == TRUE ) { - state.h += state.line_height + LINE_MARGIN * 2; + state.h += state.line_height + config.line_margin * 0; } // Sidebar mode. @@ -1083,10 +1082,10 @@ MenuReturn menu ( char **lines, unsigned int num_lines, char **input, char *prom calculate_window_position ( &state, &mon ); if ( config.sidebar_mode == TRUE ) { - int width = ( state.w - ( 2 * ( config.padding ) + ( num_switchers - 1 ) * LINE_MARGIN ) ) / num_switchers; + int width = ( state.w - ( 2 * ( config.padding ) + ( num_switchers - 1 ) * config.line_margin ) ) / num_switchers; for ( unsigned int j = 0; j < num_switchers; j++ ) { switchers[j]->tb = textbox_create ( main_window, &vinfo, map, TB_CENTER, - config.padding + j * ( width + LINE_MARGIN ), + config.padding + j * ( width + config.line_margin ), state.h - state.line_height - config.padding, width, state.line_height, ( j == curr_switcher ) ? HIGHLIGHT : NORMAL, switchers[j]->name ); textbox_show ( switchers[j]->tb ); diff --git a/source/xrmoptions.c b/source/xrmoptions.c index 67b3b43f..1a931def 100644 --- a/source/xrmoptions.c +++ b/source/xrmoptions.c @@ -126,7 +126,8 @@ static XrmOption xrmOptions[] = { { xrm_Boolean, "fuzzy", { .num = &config.fuzzy }, NULL }, { xrm_Number, "monitor", { .snum = &config.monitor }, NULL }, /* Alias for dmenu compatibility. */ - { xrm_Number, "m", { .snum = &config.monitor }, NULL } + { xrm_SNumber, "m", { .snum = &config.monitor }, NULL }, + { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL } }; // Dynamic options.