summaryrefslogtreecommitdiffstats
path: root/source/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'source/widgets')
-rw-r--r--source/widgets/box.c7
-rw-r--r--source/widgets/container.c7
-rw-r--r--source/widgets/listview.c20
-rw-r--r--source/widgets/scrollbar.c7
-rw-r--r--source/widgets/textbox.c51
-rw-r--r--source/widgets/widget.c30
6 files changed, 57 insertions, 65 deletions
diff --git a/source/widgets/box.c b/source/widgets/box.c
index bd1e1cc8..8ebd9257 100644
--- a/source/widgets/box.c
+++ b/source/widgets/box.c
@@ -289,7 +289,7 @@ void box_add ( box *box, widget *child, gboolean expand )
box->widget.h = height;
}
child->expand = rofi_theme_get_boolean ( child, "expand", expand );
- child->parent = WIDGET ( box );
+ g_assert ( child->parent == WIDGET ( box ) );
box->children = g_list_append ( box->children, (void *) child );
widget_update ( WIDGET ( box ) );
}
@@ -324,11 +324,11 @@ static widget *box_find_mouse_target ( widget *wid, WidgetType type, gint x, gin
return NULL;
}
-box * box_create ( const char *name, RofiOrientation type )
+box * box_create ( widget *parent, const char *name, RofiOrientation type )
{
box *b = g_malloc0 ( sizeof ( box ) );
// Initialize widget.
- widget_init ( WIDGET ( b ), WIDGET_TYPE_UNKNOWN, name );
+ widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
b->type = type;
b->widget.draw = box_draw;
b->widget.free = box_free;
@@ -337,7 +337,6 @@ box * box_create ( const char *name, RofiOrientation type )
b->widget.find_mouse_target = box_find_mouse_target;
b->widget.get_desired_height = box_get_desired_height;
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_orientation ( WIDGET ( b ), "orientation", b->type );
diff --git a/source/widgets/container.c b/source/widgets/container.c
index 6807ce15..9791dd21 100644
--- a/source/widgets/container.c
+++ b/source/widgets/container.c
@@ -74,7 +74,7 @@ void container_add ( container *container, widget *child )
return;
}
container->child = child;
- child->parent = WIDGET ( container );
+ g_assert ( child->parent == WIDGET ( container ));
widget_update ( WIDGET ( container ) );
}
@@ -100,18 +100,17 @@ static widget *container_find_mouse_target ( widget *wid, WidgetType type, gint
return widget_find_mouse_target ( b->child, type, x, y );
}
-container * container_create ( const char *name )
+container * container_create ( widget *parent, const char *name )
{
container *b = g_malloc0 ( sizeof ( container ) );
// Initialize widget.
- widget_init ( WIDGET ( b ), WIDGET_TYPE_UNKNOWN, name );
+ widget_init ( WIDGET ( b ), parent, WIDGET_TYPE_UNKNOWN, name );
b->widget.draw = container_draw;
b->widget.free = container_free;
b->widget.resize = container_resize;
b->widget.update = container_update;
b->widget.find_mouse_target = container_find_mouse_target;
b->widget.get_desired_height = container_get_desired_height;
- b->widget.enabled = rofi_theme_get_boolean ( WIDGET ( b ), "enabled", TRUE );
return b;
}
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index ee69add2..40537af4 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -368,14 +368,12 @@ static void listview_recompute_elements ( listview *lv )
}
lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( textbox* ) );
if ( newne > 0 ) {
- char *name = g_strjoin ( ".", lv->listview_name, "element", NULL );
for ( unsigned int i = lv->cur_elements; i < newne; i++ ) {
TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0;
flags |= ( ( config.show_icons ) ? TB_ICON : 0 );
- lv->boxes[i] = textbox_create ( WIDGET_TYPE_LISTVIEW_ELEMENT, name, flags, NORMAL, "", 0, 0 );
+ lv->boxes[i] = textbox_create ( WIDGET (lv), WIDGET_TYPE_LISTVIEW_ELEMENT, "element", flags, NORMAL, "", 0, 0 );
widget_set_trigger_action_handler ( WIDGET ( lv->boxes[i] ), listview_element_trigger_action, lv );
}
- g_free ( name );
}
lv->rchanged = TRUE;
lv->cur_elements = newne;
@@ -513,12 +511,10 @@ static WidgetTriggerActionResult listview_element_trigger_action ( widget *wid,
return WIDGET_TRIGGER_ACTION_RESULT_HANDLED;
}
-listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse )
+listview *listview_create ( widget *parent, const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse )
{
listview *lv = g_malloc0 ( sizeof ( listview ) );
- gchar *box = g_strjoin ( ".", name, "box", NULL );
- widget_init ( WIDGET ( lv ), WIDGET_TYPE_LISTVIEW, box );
- g_free ( box );
+ widget_init ( WIDGET ( lv ), parent, WIDGET_TYPE_LISTVIEW, name );
lv->listview_name = g_strdup ( name );
lv->widget.free = listview_free;
lv->widget.resize = listview_resize;
@@ -526,19 +522,13 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->widget.find_mouse_target = listview_find_mouse_target;
lv->widget.trigger_action = listview_trigger_action;
lv->widget.get_desired_height = listview_get_desired_height;
- lv->widget.enabled = rofi_theme_get_boolean ( WIDGET ( lv ), "enabled", TRUE );
lv->eh = eh;
- char *n = g_strjoin ( ".", lv->listview_name, "scrollbar", NULL );
- lv->scrollbar = scrollbar_create ( n );
- g_free ( n );
- lv->scrollbar->widget.parent = WIDGET ( lv );
+ lv->scrollbar = scrollbar_create ( WIDGET ( lv ) , "scrollbar" );
// Calculate height of an element.
//
- char *tb_name = g_strjoin ( ".", lv->listview_name, "element", NULL );
- textbox *tb = textbox_create ( WIDGET_TYPE_LISTVIEW_ELEMENT, tb_name, 0, NORMAL, "", 0, 0 );
+ textbox *tb = textbox_create ( WIDGET (lv), WIDGET_TYPE_LISTVIEW_ELEMENT, "element", 0, NORMAL, "", 0, 0 );
lv->element_height = textbox_get_estimated_height ( tb, lv->eh );
- g_free ( tb_name );
widget_free ( WIDGET ( tb ) );
lv->callback = cb;
diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c
index 04dd0e40..80fcbf7f 100644
--- a/source/widgets/scrollbar.c
+++ b/source/widgets/scrollbar.c
@@ -98,10 +98,10 @@ static gboolean scrollbar_motion_notify ( widget *wid, G_GNUC_UNUSED gint x, gin
return TRUE;
}
-scrollbar *scrollbar_create ( const char *name )
+scrollbar *scrollbar_create ( widget *parent, const char *name )
{
scrollbar *sb = g_malloc0 ( sizeof ( scrollbar ) );
- widget_init ( WIDGET ( sb ), WIDGET_TYPE_SCROLLBAR, name );
+ widget_init ( WIDGET ( sb ), parent, WIDGET_TYPE_SCROLLBAR, name );
sb->widget.x = 0;
sb->widget.y = 0;
sb->width = rofi_theme_get_distance ( WIDGET ( sb ), "handle-width", DEFAULT_SCROLLBAR_WIDTH );
@@ -119,8 +119,6 @@ scrollbar *scrollbar_create ( const char *name )
sb->pos = 0;
sb->pos_length = 4;
- // Enabled by default
- sb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( sb ), "enabled", TRUE );
return sb;
}
@@ -178,7 +176,6 @@ static void scrollbar_draw ( widget *wid, cairo_t *draw )
// Never go out of bar.
height = MAX ( 2, height );
// Cap length;
- rofi_theme_get_color ( WIDGET ( sb ), "foreground", draw );
rofi_theme_get_color ( WIDGET ( sb ), "handle-color", draw );
cairo_rectangle ( draw,
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index aeca0722..0fed9d38 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -130,26 +130,8 @@ static WidgetTriggerActionResult textbox_editable_trigger_action ( widget *wid,
return WIDGET_TRIGGER_ACTION_RESULT_IGNORED;
}
-textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign )
+static void textbox_initialize_font ( textbox *tb )
{
- textbox *tb = g_slice_new0 ( textbox );
-
- widget_init ( WIDGET ( tb ), type, name );
-
- tb->widget.draw = textbox_draw;
- tb->widget.free = textbox_free;
- tb->widget.resize = textbox_resize;
- tb->widget.get_width = textbox_get_width;
- tb->widget.get_height = _textbox_get_height;
- tb->widget.get_desired_height = textbox_get_desired_height;
- tb->widget.get_desired_width = textbox_get_desired_width;
- tb->flags = flags;
-
- tb->changed = FALSE;
-
- tb->layout = pango_layout_new ( p_context );
- textbox_font ( tb, tbft );
-
tb->metrics = p_metrics;
const char * font = rofi_theme_get_string ( WIDGET ( tb ), "font", NULL );
tb->left_offset = textbox_get_estimated_char_height ();
@@ -178,6 +160,31 @@ textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags,
tb->left_offset = ( tbfc->height ) / (double) PANGO_SCALE;
}
}
+}
+
+textbox* textbox_create ( widget *parent, WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign )
+{
+ textbox *tb = g_slice_new0 ( textbox );
+
+ widget_init ( WIDGET ( tb ), parent, type, name );
+
+ tb->widget.draw = textbox_draw;
+ tb->widget.free = textbox_free;
+ tb->widget.resize = textbox_resize;
+ tb->widget.get_width = textbox_get_width;
+ tb->widget.get_height = _textbox_get_height;
+ tb->widget.get_desired_height = textbox_get_desired_height;
+ tb->widget.get_desired_width = textbox_get_desired_width;
+ tb->flags = flags;
+
+ tb->changed = FALSE;
+
+ tb->layout = pango_layout_new ( p_context );
+ textbox_font ( tb, tbft );
+
+
+ textbox_initialize_font ( tb );
+
if ( ( tb->flags & TB_ICON ) != TB_ICON ) {
tb->left_offset = 0;
}
@@ -204,8 +211,6 @@ textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags,
tb->yalign = MAX ( 0, MIN ( 1.0, tb->yalign ) );
tb->xalign = rofi_theme_get_double ( WIDGET ( tb ), "horizontal-align", yalign );
tb->xalign = MAX ( 0, MIN ( 1.0, tb->xalign ) );
- // Enabled by default
- tb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( tb ), "enabled", TRUE );
return tb;
}
@@ -442,9 +447,7 @@ static void textbox_draw ( widget *wid, cairo_t *draw )
// TODO check if this is still needed after flatning.
cairo_set_operator ( draw, CAIRO_OPERATOR_OVER );
cairo_set_source_rgb ( draw, 0.0, 0.0, 0.0 );
- rofi_theme_get_color ( WIDGET ( tb ), "foreground", draw );
- // Text
- rofi_theme_get_color ( WIDGET ( tb ), "text", draw );
+ rofi_theme_get_color ( WIDGET ( tb ), "text-color", draw );
// draw the cursor
if ( tb->flags & TB_EDITABLE && tb->blink ) {
// We want to place the cursor based on the text shown.
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index 5325762b..774ab502 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -34,19 +34,23 @@
/** Default padding. */
#define WIDGET_DEFAULT_PADDING 0
-void widget_init ( widget *widget, WidgetType type, const char *name )
+void widget_init ( widget *wid, widget *parent, WidgetType type, const char *name )
{
- widget->type = type;
- widget->name = g_strdup ( name );
- widget->def_padding = (RofiPadding){ { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID }, { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID }, { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID }, { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID } };
- widget->def_border = (RofiPadding){ { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID } };
- widget->def_border_radius = (RofiPadding){ { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID } };
- widget->def_margin = (RofiPadding){ { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID } };
+ wid->type = type;
+ wid->parent = parent;
+ wid->name = g_strdup ( name );
+ wid->def_padding = (RofiPadding){ { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID }, { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID }, { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID }, { WIDGET_DEFAULT_PADDING, ROFI_PU_PX, ROFI_HL_SOLID } };
+ wid->def_border = (RofiPadding){ { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID } };
+ wid->def_border_radius = (RofiPadding){ { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID } };
+ wid->def_margin = (RofiPadding){ { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID }, { 0, ROFI_PU_PX, ROFI_HL_SOLID } };
- widget->padding = rofi_theme_get_padding ( widget, "padding", widget->def_padding );
- widget->border = rofi_theme_get_padding ( widget, "border", widget->def_border );
- widget->border_radius = rofi_theme_get_padding ( widget, "border-radius", widget->def_border_radius );
- widget->margin = rofi_theme_get_padding ( widget, "margin", widget->def_margin );
+ wid->padding = rofi_theme_get_padding ( wid, "padding", wid->def_padding );
+ wid->border = rofi_theme_get_padding ( wid, "border", wid->def_border );
+ wid->border_radius = rofi_theme_get_padding ( wid, "border-radius", wid->def_border_radius );
+ wid->margin = rofi_theme_get_padding ( wid, "margin", wid->def_margin );
+
+ // bled by default
+ wid->enabled = rofi_theme_get_boolean ( wid, "enabled", TRUE );
}
void widget_set_state ( widget *widget, const char *state )
@@ -205,7 +209,7 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_close_path ( d );
cairo_set_source_rgba ( d, 1.0, 1.0, 1.0, 1.0 );
- rofi_theme_get_color ( widget, "background", d );
+ rofi_theme_get_color ( widget, "background-color", d );
cairo_fill_preserve ( d );
cairo_clip ( d );
@@ -218,7 +222,7 @@ void widget_draw ( widget *widget, cairo_t *d )
cairo_save ( d );
cairo_translate ( d, widget->x, widget->y );
cairo_new_path ( d );
- rofi_theme_get_color ( widget, "foreground", d );
+ rofi_theme_get_color ( widget, "border-color", d );
if ( left > 0 ) {
double offset = ( radius_tl > 0 ) ? floor ( top / 2.0 ) : 0;
cairo_set_line_width ( d, left );