From: Yuri Bochkarev Date: Wed, 27 Mar 2013 17:26:53 +0000 (-0600) Subject: sample-task-align.patch, src-task-align.patch X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=c0f91cbbb76989eb2e6a7a2185509573b0c3b0cb;p=chaz%2Ftint2 sample-task-align.patch, src-task-align.patch http://code.google.com/p/tint2/issues/detail?id=359 --- diff --git a/sample/icon_and_text_1.tint2rc b/sample/icon_and_text_1.tint2rc index e866de4..6368136 100644 --- a/sample/icon_and_text_1.tint2rc +++ b/sample/icon_and_text_1.tint2rc @@ -23,7 +23,8 @@ border_color = #FFFFFF 69 # Panel panel_monitor = all -panel_position = bottom center horizontal +#panel_position = bottom center horizontal +panel_position = top center horizontal panel_size = 94% 30 panel_margin = 0 0 panel_padding = 7 0 7 @@ -57,6 +58,7 @@ task_active_background_id = 2 task_urgent_background_id = 2 task_iconified_background_id = 3 task_tooltip = 0 +task_align = right # Task Icons task_icon_asb = 70 0 0 @@ -115,4 +117,4 @@ battery_font_color = #FFFFFF 75 battery_padding = 1 0 battery_background_id = 0 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_and_text_2.tint2rc b/sample/icon_and_text_2.tint2rc index c30f43d..8b522e6 100644 --- a/sample/icon_and_text_2.tint2rc +++ b/sample/icon_and_text_2.tint2rc @@ -23,7 +23,8 @@ border_color = #FFFFFF 69 # Panel panel_monitor = all -panel_position = bottom center horizontal +#panel_position = bottom center horizontal +panel_position = top center horizontal panel_size = 98% 28 panel_margin = 0 5 panel_padding = 3 0 3 @@ -57,6 +58,7 @@ task_active_background_id = 2 task_urgent_background_id = 2 task_iconified_background_id = 3 task_tooltip = 0 +task_align = right # Task Icons task_icon_asb = 80 0 0 @@ -114,4 +116,4 @@ battery_font_color = #FFFFFF 75 battery_padding = 1 0 battery_background_id = 0 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_and_text_4.tint2rc b/sample/icon_and_text_4.tint2rc index 0dcabd7..95c054e 100644 --- a/sample/icon_and_text_4.tint2rc +++ b/sample/icon_and_text_4.tint2rc @@ -29,7 +29,8 @@ border_color = #FFFFFF 20 # Panel panel_monitor = all -panel_position = bottom center horizontal +#panel_position = bottom center horizontal +panel_position = top center horizontal panel_size = 92% 28 panel_margin = 0 0 panel_padding = 7 0 7 @@ -120,4 +121,4 @@ battery_font_color = #FFFFFF 75 battery_padding = 1 0 battery_background_id = 1 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_only_1.tint2rc b/sample/icon_only_1.tint2rc index 7708b58..6d7bcd5 100644 --- a/sample/icon_only_1.tint2rc +++ b/sample/icon_only_1.tint2rc @@ -75,6 +75,8 @@ task_active_background_id = 5 task_urgent_background_id = 6 task_iconified_background_id = 0 task_tooltip = 1 +#task_align = center +task_align = right # Task Icons task_icon_asb = 100 -25 -8 @@ -134,4 +136,4 @@ battery_font_color = #FFFFFF 75 battery_padding = 2 0 battery_background_id = 0 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_only_2.tint2rc b/sample/icon_only_2.tint2rc index 4d1c41f..7eac6db 100644 --- a/sample/icon_only_2.tint2rc +++ b/sample/icon_only_2.tint2rc @@ -63,6 +63,8 @@ task_active_background_id = 3 task_urgent_background_id = 3 task_iconified_background_id = 0 task_tooltip = 1 +#task_align = center +task_align = right # Task Icons task_icon_asb = 90 -100 -20 @@ -122,4 +124,4 @@ battery_font_color = #FFFFFF 75 battery_padding = 1 0 battery_background_id = 0 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_only_3.tint2rc b/sample/icon_only_3.tint2rc index 0069fbe..13f441a 100644 --- a/sample/icon_only_3.tint2rc +++ b/sample/icon_only_3.tint2rc @@ -29,7 +29,8 @@ border_color = #FFFFFF 60 # Panel panel_monitor = all -panel_position = bottom left horizontal +#panel_position = bottom left horizontal +panel_position = top left horizontal panel_size = 100% 38 panel_margin = 0 0 panel_padding = 7 3 7 @@ -63,6 +64,7 @@ task_active_background_id = 2 task_urgent_background_id = 4 task_iconified_background_id = 0 task_tooltip = 0 +task_align = right # Task Icons task_icon_asb = 70 0 0 @@ -111,4 +113,4 @@ battery_font_color = #FFFFFF 75 battery_padding = 1 0 battery_background_id = 0 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_only_4.tint2rc b/sample/icon_only_4.tint2rc index fbbc760..1d8bf82 100644 --- a/sample/icon_only_4.tint2rc +++ b/sample/icon_only_4.tint2rc @@ -29,7 +29,8 @@ border_color = #ED2323 60 # Panel panel_monitor = all -panel_position = bottom center horizontal +#panel_position = bottom center horizontal +panel_position = top center horizontal panel_size = 100% 40 panel_margin = 0 0 panel_padding = 0 0 0 @@ -63,6 +64,7 @@ task_active_background_id = 2 task_urgent_background_id = 4 task_iconified_background_id = 3 task_tooltip = 1 +task_align = right # Task Icons task_icon_asb = 90 0 0 @@ -111,4 +113,4 @@ battery_font_color = #FFFFFF 100 battery_padding = 0 0 battery_background_id = 0 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_only_6.tint2rc b/sample/icon_only_6.tint2rc index 75a59d7..0613898 100644 --- a/sample/icon_only_6.tint2rc +++ b/sample/icon_only_6.tint2rc @@ -63,6 +63,8 @@ task_active_background_id = 2 task_urgent_background_id = 2 task_iconified_background_id = 3 task_tooltip = 1 +task_align = center +#task_align = right # Task Icons task_icon_asb = 100 0 0 @@ -122,4 +124,4 @@ battery_font_color = #FFFFFF 75 battery_padding = 4 2 battery_background_id = 1 -# End of config \ No newline at end of file +# End of config diff --git a/sample/icon_only_7.tint2rc b/sample/icon_only_7.tint2rc index f60de10..aca7047 100644 --- a/sample/icon_only_7.tint2rc +++ b/sample/icon_only_7.tint2rc @@ -23,7 +23,9 @@ border_color = #CCCCCC 40 # Panel panel_monitor = all -panel_position = bottom center horizontal +#panel_position = bottom center horizontal +#panel_position = top center horizontal +panel_position = top center vertical panel_size = 95% 30 panel_margin = 0 0 panel_padding = 7 3 7 @@ -41,6 +43,7 @@ strut_policy = follow_size # Taskbar taskbar_mode = multi_desktop +#taskbar_mode = single_desktop taskbar_padding = 0 0 0 taskbar_background_id = 2 taskbar_active_background_id = 2 @@ -57,6 +60,9 @@ task_active_background_id = 3 task_urgent_background_id = 0 task_iconified_background_id = 0 task_tooltip = 1 +#task_align = left +#task_align = center +task_align = right # Task Icons task_icon_asb = 100 0 0 @@ -118,4 +124,4 @@ battery_font_color = #FFFFFF 100 battery_padding = 1 0 battery_background_id = 0 -# End of config \ No newline at end of file +# End of config diff --git a/src/config.c b/src/config.c index bf86b10..e38e087 100644 --- a/src/config.c +++ b/src/config.c @@ -484,6 +484,14 @@ void add_entry (char *key, char *value) 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); } diff --git a/src/panel.h b/src/panel.h index a2b7f14..86e7e1a 100644 --- a/src/panel.h +++ b/src/panel.h @@ -61,6 +61,9 @@ extern int panel_autohide_height; // for vertical panels this is of course the 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; diff --git a/src/taskbar/task.h b/src/taskbar/task.h index 50eed31..1dbaa97 100644 --- a/src/taskbar/task.h +++ b/src/taskbar/task.h @@ -26,6 +26,7 @@ typedef struct { int text; int icon; int centered; + int align; int icon_posy; int icon_size1; diff --git a/src/util/area.c b/src/util/area.c index 22dbe71..f6e1a1b 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -130,6 +130,54 @@ void size_by_content (Area *a) } +// 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 @@ void size_by_layout (Area *a, int pos, int level) 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;