diff options
author | Dave Davenport <qball@gmpclient.org> | 2016-12-27 22:19:15 +0100 |
---|---|---|
committer | Dave Davenport <qball@gmpclient.org> | 2016-12-27 22:19:15 +0100 |
commit | 1c611b0eecff798c576771a72c58504579e581c8 (patch) | |
tree | 42d36af10625184a0e09b2556624a836fd77d04b /source | |
parent | c5439118a70a8c8370ff3730962752356b3dd466 (diff) |
First start at adding 4 sided padding
Diffstat (limited to 'source')
-rw-r--r-- | source/theme.c | 35 | ||||
-rw-r--r-- | source/view.c | 43 | ||||
-rw-r--r-- | source/widgets/box.c | 95 | ||||
-rw-r--r-- | source/widgets/listview.c | 16 | ||||
-rw-r--r-- | source/widgets/separator.c | 22 | ||||
-rw-r--r-- | source/widgets/widget.c | 13 |
6 files changed, 148 insertions, 76 deletions
diff --git a/source/theme.c b/source/theme.c index f2492428..bc5bfe25 100644 --- a/source/theme.c +++ b/source/theme.c @@ -278,3 +278,38 @@ void rofi_theme_get_color ( const char *wclass, const char *name, const char *s } } +Padding rofi_theme_get_padding ( const char *wclass, const char *name, const char *state, const char *property, Padding pad ) +{ + Widget *widget = rofi_theme_find_widget ( wclass, name, state ); + Property *p = rofi_theme_find_property ( widget, P_INTEGER, property ); + if ( p ){ + pad.left = pad.top = pad.bottom = pad.right = p->value.i; + } + + char *s = g_strdup_printf("%s-top", property); + p = rofi_theme_find_property ( widget, P_INTEGER, s ); + if ( p ){ + pad.top = p->value.i; + } + g_free(s); + s = g_strdup_printf("%s-left", property); + p = rofi_theme_find_property ( widget, P_INTEGER, s ); + if ( p ){ + pad.left = p->value.i; + } + g_free(s); + s = g_strdup_printf("%s-bottom", property); + p = rofi_theme_find_property ( widget, P_INTEGER, s ); + if ( p ){ + pad.bottom = p->value.i; + } + g_free(s); + s = g_strdup_printf("%s-right", property); + p = rofi_theme_find_property ( widget, P_INTEGER, s ); + if ( p ){ + pad.right = p->value.i; + } + g_free(s); + + return pad; +} diff --git a/source/view.c b/source/view.c index 69792ec4..24c84c49 100644 --- a/source/view.c +++ b/source/view.c @@ -296,7 +296,11 @@ static void rofi_view_window_update_size ( RofiViewState * state ) CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height ); CacheState.edit_draw = cairo_create ( CacheState.edit_surf ); - widget_resize ( WIDGET ( state->main_box ), state->width - 2 * state->border, state->height - 2 * state->border ); + + // Should wrap main window in a widget. + int width = state->width - 2*state->border - state->pad.left - state->pad.right; + int height = state->height - 2*state->border - state->pad.top- state->pad.bottom; + widget_resize ( WIDGET ( state->main_box ), width, height ); } static gboolean rofi_view_reload_idle ( G_GNUC_UNUSED gpointer data ) @@ -1274,7 +1278,9 @@ void rofi_view_itterrate ( RofiViewState *state, xcb_generic_event_t *ev, xkb_st CacheState.edit_surf = cairo_xcb_surface_create ( xcb->connection, CacheState.edit_pixmap, visual, state->width, state->height ); CacheState.edit_draw = cairo_create ( CacheState.edit_surf ); - widget_resize ( WIDGET ( state->main_box ), state->width - 2 * state->border, state->height - 2 * state->border ); + int width = state->width - 2*state->border - state->pad.left - state->pad.right; + int height = state->height - 2*state->border - state->pad.top- state->pad.bottom; + widget_resize ( WIDGET ( state->main_box ), width, height ); } } break; @@ -1377,7 +1383,7 @@ static int rofi_view_calculate_height ( RofiViewState *state ) } height = listview_get_desired_height ( state->list_view ); height += box_get_fixed_pixels ( state->main_box ); - height += 2 * state->border; + height += 2 * state->border +state->pad.top+state->pad.bottom; return height; } @@ -1430,7 +1436,9 @@ RofiViewState *rofi_view_create ( Mode *sw, state->finalize = finalize; state->mouse_seen = FALSE; - state->border = rofi_theme_get_integer ("@window", "window", NULL, "padding" , config.padding ); + 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, "padding" , config.padding ); state->border += rofi_theme_get_integer ("@window", "window", NULL, "border-width" , config.menu_bw); // Request the lines to show. @@ -1441,20 +1449,22 @@ RofiViewState *rofi_view_create ( Mode *sw, // Get active monitor size. TICK_N ( "Get active monitor" ); + int total_width = state->width - 2*state->border - state->pad.left - state->pad.right; + int total_height = state->height - 2*state->border - state->pad.top- state->pad.bottom; state->main_box = box_create ( "mainbox.box", BOX_VERTICAL, - state->border, state->border, - state->width - 2 * state->border, state->height - 2 * state->border ); + state->border+state->pad.left, state->border+state->pad.top, + total_width, total_height); // we need this at this point so we can get height. unsigned int line_height = textbox_get_estimated_char_height (); rofi_view_calculate_window_and_element_width ( state ); - state->input_bar = box_create ( "inputbar.box", BOX_HORIZONTAL, 0, 0, state->width - state->border, line_height ); + state->input_bar = box_create ( "inputbar.box", BOX_HORIZONTAL, 0, 0, total_width, line_height ); state->input_bar_separator = separator_create ( "inputbar.separator", S_HORIZONTAL, 2 ); // Only enable widget when sidebar is enabled. if ( config.sidebar_mode ) { - state->sidebar_bar = box_create ( "sidebar.box", BOX_HORIZONTAL, 0, 0, state->width - 2 * state->border, line_height ); + state->sidebar_bar = box_create ( "sidebar.box", BOX_HORIZONTAL, 0, 0, total_width, line_height ); separator *sep = separator_create ( "sidebar.separator", S_HORIZONTAL, 2 ); box_add ( state->main_box, WIDGET ( state->sidebar_bar ), FALSE, TRUE ); box_add ( state->main_box, WIDGET ( sep ), FALSE, TRUE ); @@ -1491,7 +1501,7 @@ RofiViewState *rofi_view_create ( Mode *sw, textbox_text ( state->case_indicator, get_matching_state () ); if ( message ) { textbox *message_tb = textbox_create ( "message.textbox", TB_AUTOHEIGHT | TB_MARKUP | TB_WRAP, 0, 0, - state->width - ( 2 * ( state->border ) ), -1, NORMAL, message ); + total_width, -1, NORMAL, message ); separator *sep = separator_create ( "message.separator", S_HORIZONTAL, 2 ); box_add ( state->main_box, WIDGET ( sep ), FALSE, end); box_add ( state->main_box, WIDGET ( message_tb ), FALSE, end); @@ -1550,21 +1560,26 @@ 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->border = rofi_theme_get_integer ( "@window", "window", NULL, "padding" , config.padding ); + 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, "padding" , config.padding ); state->border += rofi_theme_get_integer ( "@window", "window", NULL, "border-width" , config.menu_bw); + int total_width = state->width - 2*state->border - state->pad.left - state->pad.right; + int total_height = state->height - 2*state->border - state->pad.top- state->pad.bottom; + rofi_view_calculate_window_and_element_width ( state ); state->main_box = box_create ( "mainbox.box", BOX_VERTICAL, state->border, state->border, - state->width - 2 * state->border, state->height - 2 * state->border ); + total_width, total_height ); state->text = textbox_create ( "message", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ), - ( state->border ), ( state->border ), - ( state->width - ( 2 * ( state->border ) ) ), 1, NORMAL, ( msg != NULL ) ? msg : "" ); + ( state->border+state->pad.left ), ( state->border+state->pad.top ), + total_width, 1, NORMAL, ( msg != NULL ) ? msg : "" ); box_add ( state->main_box, WIDGET ( state->text ), TRUE, FALSE ); unsigned int line_height = textbox_get_height ( state->text ); // resize window vertically to suit - state->height = line_height + ( state->border ) * 2; + state->height = line_height + ( state->border ) * 2+state->pad.top+state->pad.bottom; // Calculte window position. rofi_view_calculate_window_position ( state ); diff --git a/source/widgets/box.c b/source/widgets/box.c index 32680696..97d3c52d 100644 --- a/source/widgets/box.c +++ b/source/widgets/box.c @@ -33,14 +33,15 @@ #include "settings.h" #define LOG_DOMAIN "Widgets.Box" +const char *BOX_CLASS_NAME = "@box"; /** * @param box Handle to the box widget. - * @param padding The padding to apply. + * @param spacing The spacing to apply. * - * Set the padding to apply between the children in pixels. + * Set the spacing to apply between the children in pixels. */ -void box_set_padding ( box * box, unsigned int padding ); +void box_set_spacing ( box * box, unsigned int spacing ); struct _box { @@ -48,7 +49,7 @@ struct _box boxType type; int max_size; // Padding between elements - int padding; + int spacing; GList *children; }; @@ -72,15 +73,17 @@ static void vert_calculate_size ( box *b ) } b->max_size += child->h; } - b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->padding ) ); - if ( b->max_size > b->widget.h ) { + int rem_width = b->widget.w - b->widget.pad.left-b->widget.pad.right; + int rem_height = b->widget.h - b->widget.pad.top-b->widget.pad.bottom; + b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) ); + if ( b->max_size > rem_height ) { g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (height) for box: %d %d", b->max_size, b->widget.h ); return; } if ( active_widgets > 0 ) { - int bottom = b->widget.h; - int top = 0; - double rem = b->widget.h - b->max_size; + int bottom = b->widget.h - b->widget.pad.bottom; + int top = b->widget.pad.top; + double rem = rem_height - b->max_size; int index = 0; for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) { widget * child = (widget *) iter->data; @@ -92,30 +95,30 @@ static void vert_calculate_size ( box *b ) int expanding_widgets_size = ( rem ) / ( expanding_widgets - index ); if ( child->end ) { bottom -= expanding_widgets_size; - widget_move ( child, child->x, bottom ); - widget_resize ( child, b->widget.w, expanding_widgets_size ); - bottom -= b->padding; + widget_move ( child, b->widget.pad.left, bottom ); + widget_resize ( child, rem_width, expanding_widgets_size ); + bottom -= b->spacing; } else { - widget_move ( child, child->x, top ); + widget_move ( child, b->widget.pad.left, top ); top += expanding_widgets_size; - widget_resize ( child, b->widget.w, expanding_widgets_size ); - top += b->padding; + widget_resize ( child, rem_width, expanding_widgets_size ); + top += b->spacing; } rem -= expanding_widgets_size; index++; } else if ( child->end ) { bottom -= widget_get_height ( child ); - widget_move ( child, child->x, bottom ); - widget_resize ( child, b->widget.w, child->h ); - bottom -= b->padding; + widget_move ( child, b->widget.pad.left, bottom ); + widget_resize ( child, rem_width, child->h ); + bottom -= b->spacing; } else { - widget_move ( child, child->x, top ); + widget_move ( child, b->widget.pad.left, top ); top += widget_get_height ( child ); - widget_resize ( child, b->widget.w, child->h ); - top += b->padding; + widget_resize ( child, rem_width, child->h ); + top += b->spacing; } } } @@ -138,15 +141,17 @@ static void hori_calculate_size ( box *b ) // Size used by fixed width widgets. b->max_size += child->w; } - b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->padding ) ); - if ( b->max_size > b->widget.w ) { + int rem_height = b->widget.h - b->widget.pad.top-b->widget.pad.bottom; + int rem_width = b->widget.w - b->widget.pad.left-b->widget.pad.right; + b->max_size += MAX ( 0, ( ( active_widgets - 1 ) * b->spacing ) ); + if ( b->max_size > (rem_width)) { g_log ( LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "Widgets to large (width) for box: %d %d", b->max_size, b->widget.w ); return; } if ( active_widgets > 0 ) { - int right = b->widget.w; - int left = 0; - double rem = b->widget.w - b->max_size; + int right = b->widget.w-b->widget.pad.right; + int left = b->widget.pad.left; + double rem = rem_width - b->max_size; int index = 0; for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) { widget * child = (widget *) iter->data; @@ -158,30 +163,30 @@ static void hori_calculate_size ( box *b ) int expanding_widgets_size = ( rem ) / ( expanding_widgets - index ); if ( child->end ) { right -= expanding_widgets_size; - widget_move ( child, right, child->y ); - widget_resize ( child, expanding_widgets_size, b->widget.h ); - right -= b->padding; + widget_move ( child, right, b->widget.pad.top); + widget_resize ( child, expanding_widgets_size, rem_height ); + right -= b->spacing; } else { - widget_move ( child, left, child->y ); + widget_move ( child, left, b->widget.pad.top ); left += expanding_widgets_size; - widget_resize ( child, expanding_widgets_size, b->widget.h ); - left += b->padding; + widget_resize ( child, expanding_widgets_size, rem_height ); + left += b->spacing; } rem -= expanding_widgets_size; index++; } else if ( child->end ) { right -= widget_get_width ( child ); - widget_move ( child, right, child->y ); - widget_resize ( child, child->w, b->widget.h ); - right -= b->padding; + widget_move ( child, right, b->widget.pad.top ); + widget_resize ( child, child->w, rem_height ); + right -= b->spacing; } else { - widget_move ( child, left, child->y ); + widget_move ( child, left, b->widget.pad.top ); left += widget_get_width ( child ); - widget_resize ( child, child->w, b->widget.h ); - left += b->padding; + widget_resize ( child, child->w, rem_height ); + left += b->spacing; } } } @@ -276,12 +281,11 @@ static gboolean box_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme box * box_create ( const char *name, boxType type, short x, short y, short w, short h ) { box *b = g_malloc0 ( sizeof ( box ) ); + // Initialize widget. + widget_init ( WIDGET(b), name, BOX_CLASS_NAME); b->type = type; - b->widget.name = g_strdup (name); - b->widget.x = x; b->widget.y = y; b->widget.w = w; - b->widget.h = h; b->widget.draw = box_draw; b->widget.free = box_free; b->widget.resize = box_resize; @@ -290,7 +294,10 @@ box * box_create ( const char *name, boxType type, short x, short y, short w, sh b->widget.motion_notify = box_motion_notify; b->widget.enabled = TRUE; - box_set_padding ( b, rofi_theme_get_integer ( "@box", b->widget.name, NULL, "padding",config.line_margin )); + box_set_spacing ( b, rofi_theme_get_integer ( b->widget.class_name, b->widget.name, NULL, "spacing",config.line_margin )); + // Do this dynamically + b->widget.h = h+b->widget.pad.top+b->widget.pad.bottom; + b->widget.x = x+b->widget.pad.left+b->widget.pad.right; return b; } @@ -315,10 +322,10 @@ int box_get_fixed_pixels ( box *box ) return 0; } -void box_set_padding ( box * box, unsigned int padding ) +void box_set_spacing ( box * box, unsigned int spacing ) { if ( box != NULL ) { - box->padding = padding; + box->spacing = spacing; widget_queue_redraw ( WIDGET ( box ) ); } } diff --git a/source/widgets/listview.c b/source/widgets/listview.c index 5d663ac6..489a1250 100644 --- a/source/widgets/listview.c +++ b/source/widgets/listview.c @@ -54,7 +54,7 @@ struct _listview unsigned int req_elements; unsigned int cur_elements; - unsigned int padding; + unsigned int spacing; unsigned int menu_lines; unsigned int menu_columns; unsigned int fixed_num_lines; @@ -163,15 +163,15 @@ static void listview_draw ( widget *wid, cairo_t *draw ) cairo_translate ( draw, wid->x, wid->y ); unsigned int max = MIN ( lv->cur_elements, lv->req_elements - offset ); if ( lv->rchanged ) { - unsigned int width = lv->widget.w - lv->padding * ( lv->cur_columns - 1 ); + unsigned int width = lv->widget.w - lv->spacing * ( lv->cur_columns - 1 ); if ( widget_enabled ( WIDGET ( lv->scrollbar ) ) ) { - width -= lv->padding; + width -= lv->spacing; width -= widget_get_width ( WIDGET ( lv->scrollbar ) ); } unsigned int element_width = ( width ) / lv->cur_columns; for ( unsigned int i = 0; i < max; i++ ) { - unsigned int ex = ( ( i ) / lv->max_rows ) * ( element_width + lv->padding ); - unsigned int ey = ( ( i ) % lv->max_rows ) * ( lv->element_height + lv->padding ); + unsigned int ex = ( ( i ) / lv->max_rows ) * ( element_width + lv->spacing ); + unsigned int ey = ( ( i ) % lv->max_rows ) * ( lv->element_height + lv->spacing ); textbox_moveresize ( lv->boxes[i], ex, ey, element_width, lv->element_height ); update_element ( lv, i, i + offset, TRUE ); @@ -249,7 +249,7 @@ static void listview_resize ( widget *wid, short w, short h ) listview *lv = (listview *) wid; lv->widget.w = MAX ( 0, w ); lv->widget.h = MAX ( 0, h ); - lv->max_rows = ( lv->padding + lv->widget.h ) / ( lv->element_height + lv->padding ); + lv->max_rows = ( lv->spacing + lv->widget.h ) / ( lv->element_height + lv->spacing ); lv->max_elements = lv->max_rows * lv->menu_columns; widget_move ( WIDGET ( lv->scrollbar ), lv->widget.w - widget_get_width ( WIDGET ( lv->scrollbar ) ), 0 ); @@ -338,7 +338,7 @@ listview *listview_create ( const char *name, listview_update_callback cb, void lv->udata = udata; // Some settings. - lv->padding = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "padding", config.line_margin ); + lv->spacing = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "spacing", config.line_margin ); lv->menu_lines = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "lines", config.menu_lines ); lv->menu_columns = rofi_theme_get_integer ("@listview", lv->widget.name, NULL, "columns", config.menu_columns); lv->fixed_num_lines = rofi_theme_get_boolean ("@listview", lv->widget.name, NULL, "fixed-height", config.fixed_num_lines ); @@ -455,7 +455,7 @@ unsigned int listview_get_desired_height ( listview *lv ) if ( h == 0 ) { return 0; } - return h * lv->element_height + ( h - 1 ) * lv->padding; + return h * lv->element_height + ( h - 1 ) * lv->spacing; } void listview_set_show_scrollbar ( listview *lv, gboolean enabled ) diff --git a/source/widgets/separator.c b/source/widgets/separator.c index c04cecec..7aad0eee 100644 --- a/source/widgets/separator.c +++ b/source/widgets/separator.c @@ -33,6 +33,7 @@ #include "settings.h" #include "theme.h" +const char *SEPARATOR_CLASS_NAME = "@separator"; /** * @param sp The separator widget handle. * @param style_str String representation of the style. @@ -69,17 +70,17 @@ static void separator_free ( widget * ); separator *separator_create ( const char *name, separator_type type, short sw ) { separator *sb = g_malloc0 ( sizeof ( separator ) ); + widget_init ( WIDGET (sb), name, SEPARATOR_CLASS_NAME ); sb->type = type; - sb->widget.name = g_strdup ( name ); sb->widget.x = 0; sb->widget.y = 0; if ( sb->type == S_HORIZONTAL ) { sb->widget.w = 1; - sb->widget.h = MAX ( 1, sw ); + sb->widget.h = MAX ( 1, sw )+sb->widget.pad.top+sb->widget.pad.bottom; } else { sb->widget.h = 1; - sb->widget.w = MAX ( 1, sw ); + sb->widget.w = MAX ( 1, sw )+sb->widget.pad.left+sb->widget.pad.right; } sb->widget.draw = separator_draw; @@ -88,7 +89,7 @@ separator *separator_create ( const char *name, separator_type type, short sw ) // Enabled by default sb->widget.enabled = TRUE; - const char *line_style = rofi_theme_get_string ( "@separator", sb->widget.name, NULL, "line-style", "solid"); + const char *line_style = rofi_theme_get_string ( sb->widget.class_name, sb->widget.name, NULL, "line-style", "solid"); separator_set_line_style_from_string ( sb, line_style ); return sb; } @@ -129,22 +130,23 @@ static void separator_draw ( widget *wid, cairo_t *draw ) return; } color_separator ( draw ); - rofi_theme_get_color ( "@separator", wid->name, NULL, "foreground", draw ); + rofi_theme_get_color ( wid->class_name, wid->name, NULL, "foreground", draw ); if ( sep->line_style == S_LINE_DASH ) { const double dashes[1] = { 4 }; cairo_set_dash ( draw, dashes, 1, 0.0 ); } if ( sep->type == S_HORIZONTAL ) { cairo_set_line_width ( draw, wid->h ); - double half = wid->h / 2.0; - cairo_move_to ( draw, wid->x, wid->y + half ); - cairo_line_to ( draw, wid->x + wid->w, wid->y + half ); + int height= wid->h-wid->pad.top-wid->pad.bottom; + double half = height / 2.0; + cairo_move_to ( draw, wid->x+wid->pad.left, wid->y + wid->pad.top +half ); + cairo_line_to ( draw, wid->x+wid->w-wid->pad.right, wid->y +wid->pad.top + half ); } else { cairo_set_line_width ( draw, wid->w ); double half = wid->w / 2.0; - cairo_move_to ( draw, wid->x + half, wid->y ); - cairo_line_to ( draw, wid->x + half, wid->y + wid->h ); + cairo_move_to ( draw, wid->x + wid->pad.left + half, wid->y +wid->pad.top); + cairo_line_to ( draw, wid->x + wid->pad.left + half, wid->y + wid->h-wid->pad.bottom ); } cairo_stroke ( draw ); } diff --git a/source/widgets/widget.c b/source/widgets/widget.c index 93c14cff..04f52008 100644 --- a/source/widgets/widget.c +++ b/source/widgets/widget.c @@ -1,6 +1,16 @@ #include <glib.h> #include "widgets/widget.h" #include "widgets/widget-internal.h" +#include "theme.h" + + +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}); + +} int widget_intersect ( const widget *widget, int x, int y ) { @@ -72,6 +82,9 @@ void widget_free ( widget *wid ) if ( wid->name ) { g_free ( wid->name ); } + if ( wid->class_name ) { + g_free( wid->class_name ); + } if ( wid->free ) { wid->free ( wid ); } |