Add option to set padding within a line.

Fixes: #449
This commit is contained in:
Dave Davenport 2016-08-30 18:07:34 +02:00
parent 0d9d4d6c55
commit 5646adc34d
5 changed files with 17 additions and 13 deletions

View File

@ -114,7 +114,8 @@ Settings config = {
/** Monitor */ /** Monitor */
.monitor = "-5", .monitor = "-5",
/** set line margin */ /** set line margin */
.line_margin = 2, .line_margin = 2,
.line_padding = 1,
/** Set filter */ /** Set filter */
.filter = NULL, .filter = NULL,
/** Separator style: dash/solid */ /** Separator style: dash/solid */

View File

@ -72,6 +72,8 @@ rofi.tokenize: true
rofi.m: -1 rofi.m: -1
! "Margin between rows" Set from: File ! "Margin between rows" Set from: File
rofi.line-margin: 3 rofi.line-margin: 3
! "Padding within rows" Set from: Default
! rofi.line-padding: 1
! "Pre-set filter" Set from: Default ! "Pre-set filter" Set from: Default
! rofi.filter: ! rofi.filter:
! "Separator style (none, dash, solid)" Set from: File ! "Separator style (none, dash, solid)" Set from: File

View File

@ -125,6 +125,7 @@ typedef struct
char *monitor; char *monitor;
/** Line margin */ /** Line margin */
unsigned int line_margin; unsigned int line_margin;
unsigned int line_padding;
/** filter */ /** filter */
char *filter; char *filter;
/** style */ /** style */

View File

@ -36,9 +36,7 @@
#include "mode.h" #include "mode.h"
#include "view.h" #include "view.h"
#define SIDE_MARGIN 1 #define DOT_OFFSET 15
#define DOT_OFFSET 15
/** /**
* Font + font color cache. * Font + font color cache.
@ -225,7 +223,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
if ( tb->flags & TB_AUTOHEIGHT ) { if ( tb->flags & TB_AUTOHEIGHT ) {
// Width determines height! // Width determines height!
int tw = MAX ( 1, w ); int tw = MAX ( 1, w );
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - 2 * SIDE_MARGIN - offset ) ); pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tw - 2 * config.line_padding - offset ) );
h = textbox_get_height ( tb ); h = textbox_get_height ( tb );
} }
@ -237,7 +235,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
} }
// We always want to update this // We always want to update this
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - 2 * SIDE_MARGIN - offset ) ); pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - 2 * config.line_padding - offset ) );
tb->update = TRUE; tb->update = TRUE;
} }
@ -306,20 +304,20 @@ static void texbox_update ( textbox *tb )
} }
// Skip the side MARGIN on the X axis. // Skip the side MARGIN on the X axis.
int x = SIDE_MARGIN + offset; int x = config.line_padding + offset;
int y = 0; int y = 0;
if ( tb->flags & TB_RIGHT ) { if ( tb->flags & TB_RIGHT ) {
int line_width = 0; int line_width = 0;
// Get actual width. // Get actual width.
pango_layout_get_pixel_size ( tb->layout, &line_width, NULL ); pango_layout_get_pixel_size ( tb->layout, &line_width, NULL );
x = ( tb->widget.w - line_width - SIDE_MARGIN - offset ); x = ( tb->widget.w - line_width - config.line_padding - offset );
} }
else if ( tb->flags & TB_CENTER ) { else if ( tb->flags & TB_CENTER ) {
int tw = textbox_get_font_width ( tb ); int tw = textbox_get_font_width ( tb );
x = ( ( tb->widget.w - tw - 2 * SIDE_MARGIN - offset ) ) / 2; x = ( ( tb->widget.w - tw - 2 * config.line_padding - offset ) ) / 2;
} }
y = SIDE_MARGIN + ( pango_font_metrics_get_ascent ( p_metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE; y = config.line_padding + ( pango_font_metrics_get_ascent ( p_metrics ) - pango_layout_get_baseline ( tb->layout ) ) / PANGO_SCALE;
// Set ARGB // Set ARGB
Color col = tb->color_bg; Color col = tb->color_bg;
@ -715,12 +713,12 @@ void textbox_cleanup ( void )
int textbox_get_width ( const textbox *tb ) int textbox_get_width ( const textbox *tb )
{ {
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0; unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
return textbox_get_font_width ( tb ) + 2 * SIDE_MARGIN + offset; return textbox_get_font_width ( tb ) + 2 * config.line_padding + offset;
} }
int textbox_get_height ( const textbox *tb ) int textbox_get_height ( const textbox *tb )
{ {
return textbox_get_font_height ( tb ) + 2 * SIDE_MARGIN; return textbox_get_font_height ( tb ) + 2 * config.line_padding;
} }
int textbox_get_font_height ( const textbox *tb ) int textbox_get_font_height ( const textbox *tb )
@ -746,5 +744,5 @@ double textbox_get_estimated_char_width ( void )
int textbox_get_estimated_char_height ( void ) int textbox_get_estimated_char_height ( void )
{ {
int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics ); int height = pango_font_metrics_get_ascent ( p_metrics ) + pango_font_metrics_get_descent ( p_metrics );
return ( height ) / PANGO_SCALE + 2 * SIDE_MARGIN; return ( height ) / PANGO_SCALE + 2 * config.line_padding;
} }

View File

@ -166,6 +166,8 @@ static XrmOption xrmOptions[] = {
"Monitor id to show on", CONFIG_DEFAULT }, "Monitor id to show on", CONFIG_DEFAULT },
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL, { xrm_Number, "line-margin", { .num = &config.line_margin }, NULL,
"Margin between rows", CONFIG_DEFAULT }, "Margin between rows", CONFIG_DEFAULT },
{ xrm_Number, "line-padding", { .num = &config.line_padding }, NULL,
"Padding within rows", CONFIG_DEFAULT },
{ xrm_String, "filter", { .str = &config.filter }, NULL, { xrm_String, "filter", { .str = &config.filter }, NULL,
"Pre-set filter", CONFIG_DEFAULT }, "Pre-set filter", CONFIG_DEFAULT },
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL, { xrm_String, "separator-style", { .str = &config.separator_style }, NULL,