1
0
Fork 0
mirror of https://github.com/davatorium/rofi.git synced 2024-11-18 13:54:36 -05:00

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 = "-5",
/** set line margin */
.line_margin = 2,
.line_margin = 2,
.line_padding = 1,
/** Set filter */
.filter = NULL,
/** Separator style: dash/solid */

View file

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

View file

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

View file

@ -36,9 +36,7 @@
#include "mode.h"
#include "view.h"
#define SIDE_MARGIN 1
#define DOT_OFFSET 15
#define DOT_OFFSET 15
/**
* 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 ) {
// Width determines height!
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 );
}
@ -237,7 +235,7 @@ void textbox_moveresize ( textbox *tb, int x, int y, int w, int h )
}
// 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;
}
@ -306,20 +304,20 @@ static void texbox_update ( textbox *tb )
}
// Skip the side MARGIN on the X axis.
int x = SIDE_MARGIN + offset;
int x = config.line_padding + offset;
int y = 0;
if ( tb->flags & TB_RIGHT ) {
int line_width = 0;
// Get actual width.
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 ) {
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
Color col = tb->color_bg;
@ -715,12 +713,12 @@ void textbox_cleanup ( void )
int textbox_get_width ( const textbox *tb )
{
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 )
{
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 )
@ -746,5 +744,5 @@ double textbox_get_estimated_char_width ( void )
int textbox_get_estimated_char_height ( void )
{
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 },
{ xrm_Number, "line-margin", { .num = &config.line_margin }, NULL,
"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,
"Pre-set filter", CONFIG_DEFAULT },
{ xrm_String, "separator-style", { .str = &config.separator_style }, NULL,