summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/widgets/widget-internal.h1
-rw-r--r--include/widgets/widget.h8
-rw-r--r--source/widgets/box.c41
-rw-r--r--source/widgets/textbox.c21
-rw-r--r--source/widgets/widget.c7
5 files changed, 67 insertions, 11 deletions
diff --git a/include/widgets/widget-internal.h b/include/widgets/widget-internal.h
index 0ac497d5..762c4794 100644
--- a/include/widgets/widget-internal.h
+++ b/include/widgets/widget-internal.h
@@ -79,6 +79,7 @@ struct _widget
gboolean ( *motion_notify )( struct _widget *, xcb_motion_notify_event_t * );
int ( *get_desired_height )( struct _widget * );
+ int ( *get_desired_width )( struct _widget * );
/** widget clicked callback */
widget_clicked_cb clicked;
diff --git a/include/widgets/widget.h b/include/widgets/widget.h
index 990e50b4..36eecf90 100644
--- a/include/widgets/widget.h
+++ b/include/widgets/widget.h
@@ -210,5 +210,13 @@ gboolean widget_motion_notify ( widget *wid, xcb_motion_notify_event_t *xme );
*/
int widget_get_desired_height ( widget *wid );
+/**
+ * @param wid The widget handle
+ *
+ * Get the desired width of this widget recursively.
+ *
+ * @returns the desired width of the widget in pixels.
+ */
+int widget_get_desired_width ( widget *wid );
/*@}*/
#endif // ROFI_WIDGET_H
diff --git a/source/widgets/box.c b/source/widgets/box.c
index 47452ad9..ace5f591 100644
--- a/source/widgets/box.c
+++ b/source/widgets/box.c
@@ -50,6 +50,42 @@ struct _box
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 width = 0;
+ if ( b->type == BOX_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;
+ if ( !child->enabled ) {
+ continue;
+ }
+ active_widgets++;
+ if ( child->expand == TRUE ) {
+ width += widget_get_desired_width ( child );
+ continue;
+ }
+ width += widget_get_desired_width ( child );
+ }
+ if ( active_widgets > 0 ) {
+ width += ( active_widgets - 1 ) * spacing;
+ }
+ }
+ else {
+ for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
+ widget * child = (widget *) iter->data;
+ if ( !child->enabled ) {
+ continue;
+ }
+ width = MAX ( widget_get_desired_width ( child ), width );
+ }
+ }
+ width += widget_padding_get_padding_width ( wid );
+ return width;
+}
static int box_get_desired_height ( widget *wid )
{
box *b = (box *) wid;
@@ -160,7 +196,9 @@ static void hori_calculate_size ( box *b )
for ( GList *iter = g_list_first ( b->children ); iter != NULL; iter = g_list_next ( iter ) ) {
widget * child = (widget *) iter->data;
if ( child->enabled && child->expand == FALSE ) {
- widget_resize ( child, child->w, rem_height );
+ widget_resize ( child,
+ widget_get_desired_width ( child ), //child->w,
+ rem_height );
}
}
b->max_size = 0;
@@ -325,6 +363,7 @@ box * box_create ( const char *name, boxType type )
b->widget.clicked = box_clicked;
b->widget.motion_notify = box_motion_notify;
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_boolean ( WIDGET (b), "vertical",b->type );
diff --git a/source/widgets/textbox.c b/source/widgets/textbox.c
index 3f267915..a581c529 100644
--- a/source/widgets/textbox.c
+++ b/source/widgets/textbox.c
@@ -118,6 +118,7 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
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;
@@ -170,14 +171,6 @@ textbox* textbox_create ( const char *name, TextboxFlags flags, TextBoxFontType
// Enabled by default
tb->widget.enabled = rofi_theme_get_boolean ( WIDGET ( tb ), "enabled", TRUE );
- Distance w = rofi_theme_get_distance ( WIDGET ( tb ), "width", 0 );
- int wi = distance_get_pixel ( w, ORIENTATION_HORIZONTAL );
- if ( wi > 0 )
- {
- tb->widget.w = wi;
- textbox_moveresize ( tb, tb->widget.x, tb->widget.y, tb->widget.w, tb->widget.h );
- }
-
return tb;
}
@@ -818,13 +811,21 @@ int textbox_get_desired_width ( widget *wid )
{
textbox *tb = (textbox *) wid;
unsigned int offset = ( tb->flags & TB_INDICATOR ) ? DOT_OFFSET : 0;
- if ( tb->flags & TB_AUTOWIDTH ) {
+ if ( wid->expand && tb->flags & TB_AUTOWIDTH ) {
return textbox_get_font_width ( tb ) + widget_padding_get_padding_width ( wid ) + offset;
}
+ Distance w = rofi_theme_get_distance ( WIDGET ( tb ), "width", 0 );
+ int wi = distance_get_pixel ( w, ORIENTATION_HORIZONTAL );
+ if ( wi > 0 )
+ {
+ return wi;
+ }
int width = 0;
pango_layout_set_width ( tb->layout, -1);
width = textbox_get_font_width ( tb );
// Restore.
pango_layout_set_width ( tb->layout, PANGO_SCALE * ( tb->widget.w - widget_padding_get_padding_width ( WIDGET ( tb ) ) - offset ) );
- return width + widget_padding_get_padding_width ( wid ) + offset;
+ width = width + widget_padding_get_padding_width ( wid ) + offset;
+
+ return width;
}
diff --git a/source/widgets/widget.c b/source/widgets/widget.c
index d74c541a..13875e58 100644
--- a/source/widgets/widget.c
+++ b/source/widgets/widget.c
@@ -505,3 +505,10 @@ int widget_get_desired_height ( widget *wid )
}
return 0;
}
+int widget_get_desired_width ( widget *wid )
+{
+ if ( wid && wid->get_desired_width ) {
+ return wid->get_desired_width ( wid );
+ }
+ return 0;
+}