Description: new fetaure: allow task alignment
 This patch adds support for task alignment similar to the
 panel_position control option.
Origin: https://code.google.com/p/tint2/issues/detail?id=359&sort=-id
Last-Update: 2014-06-05

--- a/src/panel.h
+++ b/src/panel.h
@@ -62,6 +62,9 @@
 extern int panel_strut_policy;
 extern char *panel_items_order;
 
+// tasks alignment
+enum { ALIGN_LEFT, ALIGN_CENTER, ALIGN_RIGHT };
+
 extern int  max_tick_urgent;
 
 extern GArray* backgrounds;
--- a/src/config.c
+++ b/src/config.c
@@ -484,6 +484,14 @@
 		if (value2) panel_config.g_task.area.paddingy = atoi (value2);
 		if (value3) panel_config.g_task.area.paddingx = atoi (value3);
 	}
+	else if (strcmp (key, "task_align") == 0) {
+		extract_values(value, &value1, &value2, &value3);
+		printf("task_align: %s\n", value1);
+		if (strcmp (value1, "left") == 0) panel_config.g_task.align = ALIGN_LEFT;
+		else if (strcmp (value1, "center") == 0) panel_config.g_task.align = ALIGN_CENTER;
+		else if (strcmp (value1, "right") == 0) panel_config.g_task.align = ALIGN_RIGHT;
+		else fprintf(stderr, "Unknown value for task_align: %s\n", value1);
+	}
 	else if (strcmp (key, "task_font") == 0) {
 		panel_config.g_task.font_desc = pango_font_description_from_string (value);
 	}
--- a/src/taskbar/task.h
+++ b/src/taskbar/task.h
@@ -26,6 +26,7 @@
 	int text;
 	int icon;
 	int centered;
+	int align;
 
 	int icon_posy;
 	int icon_size1;
--- a/src/util/area.c
+++ b/src/util/area.c
@@ -130,6 +130,54 @@
 }
 
 
+// calculate total size of all children including
+// parent's padding
+int children_size(Area *a, int horizontal)
+{
+	int size = 0;
+	GSList *l;
+
+	for (l = a->list; l; l = l->next) {
+		Area *child = ((Area*)l->data);
+		if (!child->on_screen) continue;
+
+		if (horizontal)
+			size += child->width + a->paddingx;
+		else
+			size += child->height + a->paddingy;
+	}
+
+	return size;
+}
+
+
+// calculate chilren's align offset depending on the align type
+int align_offset(Area *a, int align, int horizontal)
+{
+	int size = 0;
+	int child_size = children_size(a, horizontal);
+
+	if (horizontal)
+		size = a->width;
+	else
+		size = a->height;
+
+	switch (align) {
+	case ALIGN_LEFT:
+		return 0;
+
+	case ALIGN_CENTER:
+		return (size - child_size) / 2;
+
+	case ALIGN_RIGHT:
+		return size - child_size;
+
+	default:
+		return 0;
+	}
+}
+
+
 void size_by_layout (Area *a, int pos, int level)
 {
 	// don't resize hiden objects
@@ -179,7 +227,9 @@
 		int k;
 		for (k=0 ; k < level ; k++) printf("  ");
 		printf("tree level %d, object %d, pos %d, %s\n", level, i, pos, (child->size_mode == SIZE_BY_LAYOUT) ? "SIZE_BY_LAYOUT" : "SIZE_BY_CONTENT");*/
-		size_by_layout(child, pos, level+1);
+
+		int offset = align_offset(child, panel_config.g_task.align, panel_horizontal);
+		size_by_layout(child, pos + offset, level + 1);
 		
 		if (panel_horizontal)
 			pos += child->width + a->paddingx;
