summaryrefslogtreecommitdiffstats
path: root/source/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'source/widgets')
-rw-r--r--source/widgets/box.c6
-rw-r--r--source/widgets/container.c6
-rw-r--r--source/widgets/listview.c15
-rw-r--r--source/widgets/scrollbar.c4
-rw-r--r--source/widgets/textbox.c4
-rw-r--r--source/widgets/widget.c33
6 files changed, 32 insertions, 36 deletions
diff --git a/source/widgets/box.c b/source/widgets/box.c
index f2c8b92f..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;
diff --git a/source/widgets/container.c b/source/widgets/container.c
index 4ceaa694..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,11 +100,11 @@ 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;
diff --git a/source/widgets/listview.c b/source/widgets/listview.c
index 5d1fd01a..40537af4 100644
--- a/source/widgets/listview.c
+++ b/source/widgets/listview.c
@@ -371,7 +371,7 @@ static void listview_recompute_elements ( listview *lv )
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, "element", 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 );
}
}
@@ -511,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,13 +524,10 @@ listview *listview_create ( const char *name, listview_update_callback cb, void
lv->widget.get_desired_height = listview_get_desired_height;
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.
//
- textbox *tb = textbox_create ( WIDGET_TYPE_LISTVIEW_ELEMENT, "element", 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 );
widget_free ( WIDGET ( tb ) );
diff --git a/source/widgets/scrollbar.c b/source/widgets/scrollbar.c
index 7149cc44..32f92716 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 );
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index 2df91c7f..0fed9d38 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -162,11 +162,11 @@ static void textbox_initialize_font ( textbox *tb )
}
}
-textbox* textbox_create ( WidgetType type, const char *name, TextboxFlags flags, TextBoxFontType tbft, const char *text, double xalign, double yalign )
+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 ), type, name );
+ widget_init ( WIDGET ( tb ), parent, type, name );
tb->widget.draw = textbox_draw;
tb->widget.free = textbox_free;
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index 7e951aad..774ab502 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -34,22 +34,23 @@
/** Default padding. */
#define WIDGET_DEFAULT_PADDING 0
-void widget_init ( widget *widget, 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 } };
-
- 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 );
-
- // Enabled by default
- widget->enabled = rofi_theme_get_boolean ( widget, "enabled", TRUE );
+void widget_init ( widget *wid, widget *parent, WidgetType type, const char *name )
+{
+ 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 } };
+
+ 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 )