Support em format in padding

This commit is contained in:
Dave Davenport 2016-12-31 22:47:22 +01:00
parent 5f424fa598
commit 068592414e
6 changed files with 54 additions and 32 deletions

View File

@ -2,6 +2,17 @@
#define THEME_H
#include <glib.h>
#include <cairo.h>
typedef enum {
PW_PX,
PW_EM,
} PixelWidth;
typedef struct {
int distance;
PixelWidth type;
} Distance;
typedef enum {
P_INTEGER,
P_DOUBLE,
@ -26,11 +37,10 @@ typedef struct
typedef struct
{
int left;
int right;
int top;
int bottom;
gboolean percentual;
Distance left;
Distance right;
Distance top;
Distance bottom;
} Padding;
typedef struct {

View File

@ -25,6 +25,7 @@ STRING [[:print:]]+
HEX [[:xdigit:]]
NUMBER [[:digit:]]
PX (px)
EM (em)
NEWLINES (\r|\n)+
%x PROPERTIES
@ -106,7 +107,13 @@ if ( queue == NULL ){
<PROPERTIES>\"{STRING}\" { yytext[yyleng-1] = '\0'; yylval->sval = g_strdup(&yytext[1]); return T_STRING;}
<PROPERTIES>{NUMBER}+{PX} {
yylval->ival = (int)g_ascii_strtoll(yytext, NULL, 10);
yylval->distance.distance = (int)g_ascii_strtoll(yytext, NULL, 10);
yylval->distance.type = PW_PX;
return T_PIXEL;
}
<PROPERTIES>{NUMBER}+{EM} {
yylval->distance.distance = (int)g_ascii_strtoll(yytext, NULL, 10);
yylval->distance.type = PW_EM;
return T_PIXEL;
}
<PROPERTIES>#{HEX}{8} {

View File

@ -31,6 +31,7 @@ int yylex (YYSTYPE *, YYLTYPE *);
GList *name_path;
Property *property;
GHashTable *property_list;
Distance distance;
}
%token <ival> T_INT
@ -40,7 +41,7 @@ int yylex (YYSTYPE *, YYLTYPE *);
%token <sval> NAME_ELEMENT
%token <bval> T_BOOLEAN
%token <colorval> T_COLOR
%token <ival> T_PIXEL
%token <distance> T_PIXEL
%token <sval> CLASS_NAME
%token <sval> FIRST_NAME
@ -170,12 +171,12 @@ property
| pvalue PSEP T_PIXEL PCLOSE {
$$ = rofi_theme_property_create ( P_PADDING );
$$->name = $1;
$$->value.padding = (Padding){ $3, $3, $3, $3, FALSE };
$$->value.padding = (Padding){ $3, $3, $3, $3 };
}
| pvalue PSEP T_PIXEL T_PIXEL T_PIXEL T_PIXEL PCLOSE {
$$ = rofi_theme_property_create ( P_PADDING );
$$->name = $1;
$$->value.padding = (Padding){ $3, $4, $5, $6, FALSE };
$$->value.padding = (Padding){ $3, $4, $5, $6 };
}
;

View File

@ -87,6 +87,17 @@ static void rofi_theme_print_property_index ( int depth, Property *p )
(unsigned char)(p->value.color.green*255.0),
(unsigned char)(p->value.color.blue*255.0));
break;
case P_PADDING:
printf("%d%s %d%s %d%s %d%s",
p->value.padding.left.distance,
p->value.padding.left.type == PW_PX? "px":"em",
p->value.padding.right.distance,
p->value.padding.right.type == PW_PX? "px":"em",
p->value.padding.top.distance,
p->value.padding.top.type == PW_PX? "px":"em",
p->value.padding.bottom.distance,
p->value.padding.bottom.type == PW_PX? "px":"em"
);
}
putchar ( '\n' );
}

View File

@ -863,8 +863,6 @@ static void rofi_view_mouse_navigation ( RofiViewState *state, xcb_button_press_
}
else {
xcb_button_press_event_t rel = *xbe;
rel.event_x -= state->pad.left;
rel.event_y -= state->pad.top;
if ( widget_clicked ( WIDGET ( state->main_window ), &rel ) ) {
return;
}
@ -1279,8 +1277,6 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *ev, xkb_st
state->mouse_seen = TRUE;
}
xcb_motion_notify_event_t xme = *( (xcb_motion_notify_event_t *) ev );
xme.event_x -= state->pad.left;
xme.event_y -= state->pad.top;
if ( widget_motion_notify ( WIDGET ( state->main_window ), &xme ) ) {
return;
}
@ -1417,9 +1413,6 @@ RofiViewState *rofi_view_create ( Mode *sw,
state->finalize = finalize;
state->mouse_seen = FALSE;
state->pad = (Padding){config.padding,config.padding, config.padding, config.padding, FALSE};
state->pad = rofi_theme_get_padding ( "@window", "window", NULL, "padding", state->pad);
// Request the lines to show.
state->num_lines = mode_get_num_entries ( sw );
@ -1539,15 +1532,12 @@ int rofi_view_error_dialog ( const char *msg, int markup )
state->retv = MENU_CANCEL;
state->menu_flags = MENU_ERROR_DIALOG;
state->finalize = process_result;
state->pad = (Padding){config.padding,config.padding, config.padding, config.padding, FALSE};
state->pad = rofi_theme_get_padding ( "@window", "window", NULL, "padding", state->pad);
state->border += rofi_theme_get_integer ( "@window", "window", NULL, "border-width" , config.menu_bw);
rofi_view_calculate_window_and_element_width ( state );
state->main_window = window_create ( "window" );
state->main_box = box_create ( "mainbox.box", BOX_VERTICAL);
window_add ( state->main_window, WIDGET ( state->main_box ) );
widget_move ( WIDGET ( state->main_box ), state->border+state->pad.left, state->border+state->pad.top );
state->text = textbox_create ( "message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ),
NORMAL, ( msg != NULL ) ? msg : "" );
box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE );

View File

@ -8,7 +8,8 @@ void widget_init ( widget *widget , const char *name, const char *class_name )
{
widget->name = g_strdup(name);
widget->class_name = g_strdup(class_name);
widget->pad = rofi_theme_get_padding (widget->class_name, widget->name, NULL, "padding", (Padding){0,0,0,0,FALSE});
widget->pad = (Padding){ {0, PW_PX}, {0, PW_PX}, {0, PW_PX}, {0, PW_PX}};
widget->pad = rofi_theme_get_padding (widget->class_name, widget->name, NULL, "padding", widget->pad);
}
@ -210,33 +211,35 @@ void widget_set_name ( widget *wid, const char *name )
wid->name = g_strdup ( name );
}
// External
double textbox_get_estimated_char_width ( void );
int widget_padding_get_left ( const widget *wid )
{
if ( wid->pad.left < 0 ){
return (wid->w*-wid->pad.left)/100;
if ( wid->pad.left.type == PW_EM ){
return wid->pad.left.distance*textbox_get_estimated_char_width();
}
return wid->pad.left;
return wid->pad.left.distance;
}
int widget_padding_get_right ( const widget *wid )
{
if ( wid->pad.right < 0 ){
return (wid->w*-wid->pad.right)/100;
if ( wid->pad.right.type == PW_EM ){
return wid->pad.right.distance*textbox_get_estimated_char_width();
}
return wid->pad.right;
return wid->pad.right.distance;
}
int widget_padding_get_top ( const widget *wid )
{
if ( wid->pad.top < 0 ){
return (wid->h*-wid->pad.top)/100;
if ( wid->pad.top.type == PW_EM ){
return wid->pad.top.distance*textbox_get_estimated_char_width();
}
return wid->pad.top;
return wid->pad.top.distance;
}
int widget_padding_get_bottom ( const widget *wid )
{
if ( wid->pad.bottom < 0 ){
return (wid->h*-wid->pad.bottom)/100;
if ( wid->pad.bottom.type == PW_EM ){
return wid->pad.bottom.distance*textbox_get_estimated_char_width();
}
return wid->pad.bottom;
return wid->pad.bottom.distance;
}
int widget_padding_get_remaining_width ( const widget *wid )