[Xfce4-commits] <xfce4-panel:andrzejr/deskbar-github> tasklist-widget: cleaning up the code and fixing the layout.
Andrzej
noreply at xfce.org
Mon Dec 12 11:40:54 CET 2011
Updating branch refs/heads/andrzejr/deskbar-github
to 538f824051976053b17e306fa3f77295458ba6a0 (commit)
from a131692213b2a0b59bff468d8435fe17923ee977 (commit)
commit 538f824051976053b17e306fa3f77295458ba6a0
Author: Andrzej <ndrwrdck at gmail.com>
Date: Mon Dec 12 02:19:36 2011 +0900
tasklist-widget: cleaning up the code and fixing the layout.
In modes using fixed-length buttons (deskbar or no labels) occasionally an unused
area left at the end of the widget (allocation_width - n * columns - arrow_size).
AFAIK there is no way to give an unused part of allocation area back to the container.
plugins/tasklist/tasklist-widget.c | 134 ++++++++++++++++++------------------
1 files changed, 66 insertions(+), 68 deletions(-)
diff --git a/plugins/tasklist/tasklist-widget.c b/plugins/tasklist/tasklist-widget.c
index 740524b..ab0818b 100644
--- a/plugins/tasklist/tasklist-widget.c
+++ b/plugins/tasklist/tasklist-widget.c
@@ -68,7 +68,9 @@
#define xfce_taskbar_is_locked(tasklist) (XFCE_TASKLIST (tasklist)->locked > 0)
#define xfce_tasklist_get_panel_plugin(tasklist) gtk_widget_get_ancestor (GTK_WIDGET (tasklist), XFCE_TYPE_PANEL_PLUGIN)
-#define xfce_tasklist_horizontal(tasklist) ((tasklist)->horizontal || ((tasklist)->deskbar_mode && (tasklist)->show_labels))
+#define xfce_tasklist_horizontal(tasklist) ((tasklist)->mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL)
+#define xfce_tasklist_vertical(tasklist) ((tasklist)->mode == XFCE_PANEL_PLUGIN_MODE_VERTICAL)
+#define xfce_tasklist_deskbar(tasklist) ((tasklist)->mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR)
#define xfce_tasklist_filter_monitors(tasklist) (!(tasklist)->all_monitors && (tasklist)->monitor_geometry.width != -1)
#define xfce_tasklist_geometry_set_invalid(tasklist) ((tasklist)->monitor_geometry.width = -1)
#define xfce_tasklist_geometry_has_point(tasklist, x, y) ( \
@@ -133,9 +135,6 @@ struct _XfceTasklist
/* mode (orientation) of the tasklist */
XfcePanelPluginMode mode;
- /* orientation of the tasklist */
- guint horizontal : 1;
-
/* relief of the tasklist buttons */
GtkReliefStyle button_relief;
@@ -157,9 +156,6 @@ struct _XfceTasklist
/* number of rows of window buttons */
guint nrows;
- /* is panel in vertical deskbar mode? */
- gboolean deskbar_mode : 1;
-
/* switch window with the mouse wheel */
guint window_scrolling : 1;
@@ -543,9 +539,7 @@ xfce_tasklist_init (XfceTasklist *tasklist)
tasklist->windows = NULL;
tasklist->skipped_windows = NULL;
tasklist->mode = XFCE_PANEL_PLUGIN_MODE_HORIZONTAL;
- tasklist->horizontal = TRUE;
tasklist->nrows = 1;
- tasklist->deskbar_mode = FALSE;
tasklist->all_workspaces = FALSE;
tasklist->button_relief = GTK_RELIEF_NORMAL;
tasklist->switch_workspace = TRUE;
@@ -801,11 +795,7 @@ xfce_tasklist_size_request (GtkWidget *widget,
}
else
{
- /* rows = tasklist->size / tasklist->max_button_size; */
- rows = tasklist->nrows;
- /* rows = CLAMP (rows, 1, n_windows); */
- if (rows < 1)
- rows = 1;
+ rows = MAX (tasklist->nrows, 1);
cols = n_windows / rows;
if (cols * rows < n_windows)
@@ -820,16 +810,21 @@ xfce_tasklist_size_request (GtkWidget *widget,
}
/* set the requested sizes */
- if (tasklist->horizontal) {
- requisition->width = length;
- requisition->height = tasklist->size;
- } else if (tasklist->deskbar_mode) {
- requisition->height = child_height * n_windows;
- requisition->width = tasklist->size;
- } else {
- requisition->width = tasklist->size;
- requisition->height = length;
- }
+ if (xfce_tasklist_deskbar (tasklist) && tasklist->show_labels)
+ {
+ requisition->height = child_height * n_windows;
+ requisition->width = tasklist->size;
+ }
+ else if (xfce_tasklist_horizontal (tasklist))
+ {
+ requisition->width = length;
+ requisition->height = tasklist->size;
+ }
+ else
+ {
+ requisition->width = tasklist->size;
+ requisition->height = length;
+ }
}
@@ -857,7 +852,7 @@ xfce_tasklist_size_layout (XfceTasklist *tasklist,
GtkAllocation *alloc,
gint *n_rows,
gint *n_cols,
- gboolean *arrow_visible)
+ gint *arrow_position)
{
gint rows;
gint min_button_length;
@@ -870,8 +865,9 @@ xfce_tasklist_size_layout (XfceTasklist *tasklist,
gint n_buttons_target;
/* if we're in deskbar mode, there are no columns */
- if (!tasklist->horizontal && tasklist->deskbar_mode && tasklist->show_labels)
- rows = tasklist->n_windows;
+ if (xfce_tasklist_deskbar (tasklist) && tasklist->show_labels)
+ //rows = tasklist->n_windows;
+ rows = 1;
else
/* rows = alloc->height / tasklist->max_button_size; */
rows = tasklist->nrows;
@@ -883,12 +879,12 @@ xfce_tasklist_size_layout (XfceTasklist *tasklist,
if (cols * rows < tasklist->n_windows)
cols++;
- if (tasklist->show_labels)
- min_button_length = tasklist->min_button_length;
+ if (xfce_tasklist_deskbar (tasklist) || !tasklist->show_labels)
+ min_button_length = alloc->height / tasklist->nrows;
else
- min_button_length = alloc->height / rows;
+ min_button_length = tasklist->min_button_length;
- *arrow_visible = FALSE;
+ *arrow_position = -1; /* not visible */
if (min_button_length * cols <= alloc->width)
{
@@ -909,7 +905,7 @@ xfce_tasklist_size_layout (XfceTasklist *tasklist,
xfce_tasklist_size_sort_window);
}
- if (!tasklist->show_labels)
+ if (xfce_tasklist_deskbar (tasklist) || !tasklist->show_labels)
max_button_length = min_button_length;
else if (tasklist->max_button_length != -1)
max_button_length = tasklist->max_button_length;
@@ -917,7 +913,13 @@ xfce_tasklist_size_layout (XfceTasklist *tasklist,
max_button_length = DEFAULT_MAX_BUTTON_LENGTH;
n_buttons = tasklist->n_windows;
- n_buttons_target = ((alloc->width / max_button_length) + 1) * rows;
+ /* Matches the existing behavior (with a bug fix) */
+ /* n_buttons_target = MIN ((alloc->width - ARROW_BUTTON_SIZE) / min_button_length * rows, *
+ * (((alloc->width - ARROW_BUTTON_SIZE) / max_button_length) + 1) * rows); */
+
+ /* Perhaps a better behavior (tries to display more buttons on the panel, */
+ /* yet still within the specified limits) */
+ n_buttons_target = (alloc->width - ARROW_BUTTON_SIZE) / min_button_length * rows;
#if 0
if (tasklist->grouping == XFCE_TASKLIST_GROUPING_AUTO)
@@ -944,7 +946,11 @@ xfce_tasklist_size_layout (XfceTasklist *tasklist,
child->type = CHILD_TYPE_OVERFLOW_MENU;
}
- *arrow_visible = TRUE;
+ /* Try to position the arrow widget at the end of the allocation area *
+ * if that's impossible (because buttons cannot be expanded enough) *
+ * position it just after the buttons. */
+ *arrow_position = MIN (alloc->width - ARROW_BUTTON_SIZE,
+ n_buttons_target * max_button_length / rows);
}
g_slist_free (windows_scored);
@@ -975,7 +981,7 @@ xfce_tasklist_size_allocate (GtkWidget *widget,
gboolean direction_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL;
gint w, x, y, h;
gint area_x, area_width;
- gboolean arrow_visible;
+ gint arrow_position;
GtkRequisition child_req;
panel_return_if_fail (GTK_WIDGET_VISIBLE (tasklist->arrow_button));
@@ -985,11 +991,8 @@ xfce_tasklist_size_allocate (GtkWidget *widget,
/* swap integers with vertical orientation */
if (!xfce_tasklist_horizontal (tasklist))
- {
- TRANSPOSE_AREA (area);
- direction_rtl = !direction_rtl;
- }
- /*panel_return_if_fail (area.height == tasklist->size);*/
+ TRANSPOSE_AREA (area);
+ panel_return_if_fail (area.height == tasklist->size);
/* TODO if we compare the allocation with the requisition we can
* do a fast path to the child allocation, i think */
@@ -997,23 +1000,23 @@ xfce_tasklist_size_allocate (GtkWidget *widget,
/* useless but hides compiler warning */
w = h = x = y = rows = cols = 0;
- xfce_tasklist_size_layout (tasklist, &area, &rows, &cols, &arrow_visible);
+ xfce_tasklist_size_layout (tasklist, &area, &rows, &cols, &arrow_position);
/* allocate the arrow button for the overflow menu */
child_alloc.width = ARROW_BUTTON_SIZE;
child_alloc.height = area.height;
- if (arrow_visible)
+ if (arrow_position != -1)
{
child_alloc.x = area.x;
child_alloc.y = area.y;
if (!direction_rtl)
- child_alloc.x += area.width - ARROW_BUTTON_SIZE;
+ child_alloc.x += arrow_position;
else
- area.x += ARROW_BUTTON_SIZE;
+ child_alloc.x += (area.width - arrow_position);
- area.width -= ARROW_BUTTON_SIZE;
+ area.width = arrow_position;
/* position the arrow in the correct position */
if (!xfce_tasklist_horizontal (tasklist))
@@ -1028,6 +1031,7 @@ xfce_tasklist_size_allocate (GtkWidget *widget,
area_x = area.x;
area_width = area.width;
+ h = area.height / rows;
/* allocate all the children */
for (li = tasklist->windows, i = 0; li != NULL; li = li->next)
@@ -1042,16 +1046,15 @@ xfce_tasklist_size_allocate (GtkWidget *widget,
|| child->type == CHILD_TYPE_GROUP))
{
row = (i % rows);
-
if (row == 0)
{
x = area_x;
y = area.y;
- h = area.height;
- if (!tasklist->horizontal && tasklist->deskbar_mode && tasklist->show_labels)
+ if (xfce_tasklist_deskbar (tasklist) && tasklist->show_labels)
{
- w = area_width;
+ /* fixed width is OK because area.width==w*cols */
+ w = area.height / tasklist->nrows;
}
else if (tasklist->show_labels)
{
@@ -1064,27 +1067,25 @@ xfce_tasklist_size_allocate (GtkWidget *widget,
&& w > tasklist->max_button_length)
w = tasklist->max_button_length;
}
- else
+ else /* buttons without labels */
{
- w = h / (rows - row);
+ w = h;
}
area_width -= w;
area_x += w;
}
- child_alloc.y = y;
+ if (xfce_tasklist_vertical (tasklist))
+ /* lay out buttons right to left in the vertical mode */
+ child_alloc.y = area.height - y - h;
+ else
+ child_alloc.y = y;
child_alloc.x = x;
child_alloc.width = MAX (w, 1); /* TODO this is a workaround */
- child_alloc.height = h / (rows - row);
-
- if (!tasklist->horizontal && tasklist->deskbar_mode && tasklist->show_labels)
- {
- child_alloc.height = tasklist->size / tasklist->nrows;
- }
+ child_alloc.height = h;
- h -= child_alloc.height;
- y += child_alloc.height;
+ y += h;
if (direction_rtl)
child_alloc.x = area.x + area.width - (child_alloc.x - area.x) - child_alloc.width;
@@ -2033,7 +2034,7 @@ xfce_tasklist_child_new (XfceTasklist *tasklist)
gtk_button_set_relief (GTK_BUTTON (child->button),
tasklist->button_relief);
- child->box = xfce_hvbox_new (xfce_tasklist_horizontal (tasklist) ?
+ child->box = xfce_hvbox_new (!xfce_tasklist_vertical (tasklist) ?
GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL, FALSE, 6);
gtk_container_add (GTK_CONTAINER (child->button), child->box);
gtk_widget_show (child->box);
@@ -2048,7 +2049,7 @@ xfce_tasklist_child_new (XfceTasklist *tasklist)
child->label = gtk_label_new (NULL);
gtk_box_pack_start (GTK_BOX (child->box), child->label, TRUE, TRUE, 0);
- if (xfce_tasklist_horizontal (tasklist))
+ if (!xfce_tasklist_vertical (tasklist))
{
/* gtk_box_reorder_child (GTK_BOX (child->box), child->icon, 0); */
gtk_misc_set_alignment (GTK_MISC (child->label), 0.0, 0.5);
@@ -2961,8 +2962,8 @@ xfce_tasklist_button_drag_data_received (GtkWidget *button,
sibling = g_list_find (tasklist->windows, child2);
panel_return_if_fail (sibling != NULL);
- if ((tasklist->horizontal && x >= button->allocation.width / 2)
- || (!tasklist->horizontal && y >= button->allocation.height / 2))
+ if ((!xfce_tasklist_vertical (tasklist) && x >= button->allocation.width / 2)
+ || (xfce_tasklist_vertical (tasklist) && y >= button->allocation.height / 2))
sibling = g_list_next (sibling);
xid = *((gulong *) gtk_selection_data_get_data (selection_data));
@@ -3799,7 +3800,7 @@ xfce_tasklist_update_orientation (XfceTasklist *tasklist)
GList *li;
XfceTasklistChild *child;
- horizontal = xfce_tasklist_horizontal (tasklist);
+ horizontal = !xfce_tasklist_vertical (tasklist);
/* update the tasklist */
for (li = tasklist->windows; li != NULL; li = li->next)
@@ -3872,9 +3873,6 @@ xfce_tasklist_set_mode (XfceTasklist *tasklist,
if (tasklist->mode != mode)
{
tasklist->mode = mode;
- /* transitional variables, to be removed */
- tasklist->horizontal = !!(mode == XFCE_PANEL_PLUGIN_MODE_HORIZONTAL);
- tasklist->deskbar_mode = !!(mode == XFCE_PANEL_PLUGIN_MODE_DESKBAR);
xfce_tasklist_update_orientation (tasklist);
}
}
More information about the Xfce4-commits
mailing list