From eec5c6eadcc5de3c5285a5240db6da2e439d287a Mon Sep 17 00:00:00 2001 From: Dave Davenport Date: Fri, 2 Jun 2017 14:05:19 +0200 Subject: Add orientation property. --- source/theme.c | 10 ++++++++++ source/view.c | 16 ++++++++-------- source/widgets/box.c | 20 ++++++++++---------- 3 files changed, 28 insertions(+), 18 deletions(-) (limited to 'source') diff --git a/source/theme.c b/source/theme.c index cebe29e3..fc72307a 100644 --- a/source/theme.c +++ b/source/theme.c @@ -541,6 +541,16 @@ int rofi_theme_get_boolean ( const widget *widget, const char *property, int def g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); return def; } +Orientation rofi_theme_get_orientation ( const widget *widget, const char *property, Orientation def ) +{ + ThemeWidget *wid = rofi_theme_find_widget ( widget->name, widget->state, FALSE ); + Property *p = rofi_theme_find_property ( wid, P_ORIENTATION, property, FALSE ); + if ( p ) { + return p->value.b; + } + g_debug ( "Theme entry: #%s %s property %s unset.", widget->name, widget->state ? widget->state : "", property ); + return def; +} const char *rofi_theme_get_string ( const widget *widget, const char *property, char *def ) { diff --git a/source/view.c b/source/view.c index 3ea8962d..4d636191 100644 --- a/source/view.c +++ b/source/view.c @@ -709,7 +709,7 @@ void __create_window ( MenuFlags menu_flags ) } // Setup font. // Dummy widget. - box *win = box_create ( "window.box_window", BOX_HORIZONTAL ); + box *win = box_create ( "window.box_window", ORIENTATION_HORIZONTAL); const char *font = rofi_theme_get_string ( WIDGET ( win ), "font", config.menu_font ); if ( font ) { PangoFontDescription *pfd = pango_font_description_from_string ( font ); @@ -1497,7 +1497,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, * MAINBOX */ if ( strcmp ( name, "mainbox") == 0 ){ - wid = (widget *)box_create ( strbox, BOX_VERTICAL ); + wid = (widget *)box_create ( strbox, ORIENTATION_VERTICAL ); box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE, 0 ); defaults = "inputbar,message,listview"; } @@ -1505,7 +1505,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, * INPUTBAR */ else if ( strcmp ( name, "inputbar" ) == 0 ){ - wid = (widget *)box_create ( strbox, BOX_HORIZONTAL ); + wid = (widget *)box_create ( strbox, ORIENTATION_HORIZONTAL ); defaults = "prompt,entry,case-indicator"; box_add ( (box *)parent_widget, WIDGET ( wid ), FALSE, 0 ); @@ -1571,7 +1571,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, */ else if ( strcmp( name, "sidebar" ) == 0 ) { if ( config.sidebar_mode ){ - state->sidebar_bar = box_create ( strbox, BOX_HORIZONTAL ); + state->sidebar_bar = box_create ( strbox, ORIENTATION_HORIZONTAL ); box_add ( (box*)parent_widget, WIDGET ( state->sidebar_bar ), FALSE, 10 ); state->num_modi = rofi_get_num_enabled_modi (); state->modi = g_malloc0 ( state->num_modi * sizeof ( textbox * ) ); @@ -1589,7 +1589,7 @@ static void rofi_view_add_widget ( RofiViewState *state, widget *parent_widget, textbox *t = textbox_create ( str, TB_WRAP, NORMAL, ""); box_add ( (box *)parent_widget, WIDGET(t), TRUE, 0); } else { - wid = box_create ( strbox, BOX_VERTICAL ); + wid = box_create ( strbox, ORIENTATION_VERTICAL ); box_add ( (box *)parent_widget, WIDGET ( wid ), TRUE, 0 ); //g_error("The widget %s does not exists. Invalid layout.", name); } @@ -1632,7 +1632,7 @@ RofiViewState *rofi_view_create ( Mode *sw, TICK_N ( "Get active monitor" ); - state->main_window = box_create ( "window.box", BOX_VERTICAL ); + state->main_window = box_create ( "window.box", ORIENTATION_VERTICAL ); // Get children. GList *list = rofi_theme_get_list ( WIDGET(state->main_window), "children", "mainbox"); for ( const GList *iter = list; iter != NULL; iter = g_list_next ( iter )){ @@ -1683,8 +1683,8 @@ int rofi_view_error_dialog ( const char *msg, int markup ) state->menu_flags = MENU_ERROR_DIALOG; state->finalize = process_result; - state->main_window = box_create ( "window.box", BOX_VERTICAL ); - box *box = box_create ( "window.mainbox.message.box", BOX_VERTICAL ); + state->main_window = box_create ( "window.box", ORIENTATION_VERTICAL ); + box *box = box_create ( "window.mainbox.message.box", ORIENTATION_VERTICAL ); box_add ( state->main_window, WIDGET ( box ), TRUE, 0 ); state->text = textbox_create ( "window.mainbox.message.textbox", ( TB_AUTOHEIGHT | TB_WRAP ) + ( ( markup ) ? TB_MARKUP : 0 ), NORMAL, ( msg != NULL ) ? msg : "" ); diff --git a/source/widgets/box.c b/source/widgets/box.c index f781f3db..1063625d 100644 --- a/source/widgets/box.c +++ b/source/widgets/box.c @@ -40,7 +40,7 @@ struct _box { widget widget; - boxType type; + Orientation type; int max_size; // Padding between elements Distance spacing; @@ -54,9 +54,9 @@ static void box_update ( widget *wid ); static int box_get_desired_width ( widget *wid ) { box *b = (box *) wid; - int spacing = distance_get_pixel ( b->spacing, b->type == BOX_VERTICAL ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL ); + int spacing = distance_get_pixel ( b->spacing, b->type ); int width = 0; - if ( b->type == BOX_HORIZONTAL ) { + if ( b->type == ORIENTATION_HORIZONTAL ) { int active_widgets = 0; for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) { widget * child = (widget *) iter->data; @@ -89,9 +89,9 @@ static int box_get_desired_width ( widget *wid ) static int box_get_desired_height ( widget *wid ) { box *b = (box *) wid; - int spacing = distance_get_pixel ( b->spacing, b->type == BOX_VERTICAL ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL ); + int spacing = distance_get_pixel ( b->spacing, b->type ); int height = 0; - if ( b->type == BOX_VERTICAL ) { + if ( b->type == ORIENTATION_VERTICAL) { int active_widgets = 0; for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) { widget * child = (widget *) iter->data; @@ -287,7 +287,7 @@ void box_add ( box *box, widget *child, gboolean expand, int index ) return; } // Make sure box is width/heigh enough. - if ( box->type == BOX_VERTICAL ) { + if ( box->type == ORIENTATION_VERTICAL ) { int width = box->widget.w; width = MAX ( width, child->w + widget_padding_get_padding_width ( WIDGET ( box ) ) ); box->widget.w = width; @@ -335,7 +335,7 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gin return NULL; } -box * box_create ( const char *name, boxType type ) +box * box_create ( const char *name, Orientation type ) { box *b = g_malloc0 ( sizeof ( box ) ); // Initialize widget. @@ -350,7 +350,7 @@ box * box_create ( const char *name, boxType type ) b->widget.get_desired_width = box_get_desired_width; b->widget.enabled = rofi_theme_get_boolean ( WIDGET ( b ), "enabled", TRUE ); - b->type = rofi_theme_get_boolean ( WIDGET (b), "vertical",b->type ); + b->type = rofi_theme_get_orientation ( WIDGET (b), "orientation",b->type ); b->spacing = rofi_theme_get_distance ( WIDGET ( b ), "spacing", DEFAULT_SPACING ); return b; @@ -361,10 +361,10 @@ static void box_update ( widget *wid ) box *b = (box *) wid; switch ( b->type ) { - case BOX_VERTICAL: + case ORIENTATION_VERTICAL: vert_calculate_size ( b ); break; - case BOX_HORIZONTAL: + case ORIENTATION_HORIZONTAL: default: hori_calculate_size ( b ); } -- cgit v1.2.3