Compute layouts correctly with partial borders (issue #580)

This commit is contained in:
o9000 2016-05-21 15:14:57 +02:00
parent 77d2a74865
commit ed802d7602
13 changed files with 450 additions and 365 deletions

View file

@ -326,7 +326,7 @@ gboolean resize_battery(void *obj)
if (panel_horizontal) { if (panel_horizontal) {
int new_size = (bat_percentage_width > bat_time_width) ? bat_percentage_width : bat_time_width; int new_size = (bat_percentage_width > bat_time_width) ? bat_percentage_width : bat_time_width;
new_size += 2 * battery->area.paddingxlr + 2 * battery->area.bg->border.width; new_size += 2 * battery->area.paddingxlr + left_right_border_width(&battery->area);
if (new_size > battery->area.width || new_size < battery->area.width - 2) { if (new_size > battery->area.width || new_size < battery->area.width - 2) {
// we try to limit the number of resize // we try to limit the number of resize
battery->area.width = new_size; battery->area.width = new_size;
@ -335,8 +335,8 @@ gboolean resize_battery(void *obj)
ret = 1; ret = 1;
} }
} else { } else {
int new_size = int new_size = bat_percentage_height + bat_time_height + 2 * battery->area.paddingxlr +
bat_percentage_height + bat_time_height + (2 * (battery->area.paddingxlr + battery->area.bg->border.width)); top_bottom_border_width(&battery->area);
if (new_size > battery->area.height || new_size < battery->area.height - 2) { if (new_size > battery->area.height || new_size < battery->area.height - 2) {
battery->area.height = new_size; battery->area.height = new_size;
battery->bat1_posy = (battery->area.height - bat_percentage_height - bat_time_height - 2) / 2; battery->bat1_posy = (battery->area.height - bat_percentage_height - bat_time_height - 2) / 2;

View file

@ -276,7 +276,7 @@ gboolean resize_clock(void *obj)
if (panel_horizontal) { if (panel_horizontal) {
int new_size = (time_width > date_width) ? time_width : date_width; int new_size = (time_width > date_width) ? time_width : date_width;
new_size += (2 * clock->area.paddingxlr) + (2 * clock->area.bg->border.width); new_size += 2 * clock->area.paddingxlr + left_right_border_width(&clock->area);
if (new_size > clock->area.width || new_size < (clock->area.width - 6)) { if (new_size > clock->area.width || new_size < (clock->area.width - 6)) {
// we try to limit the number of resizes // we try to limit the number of resizes
clock->area.width = new_size + 1; clock->area.width = new_size + 1;
@ -288,7 +288,7 @@ gboolean resize_clock(void *obj)
result = TRUE; result = TRUE;
} }
} else { } else {
int new_size = time_height + date_height + (2 * (clock->area.paddingxlr + clock->area.bg->border.width)); int new_size = time_height + date_height + 2 * clock->area.paddingxlr + top_bottom_border_width(&clock->area);
if (new_size != clock->area.height) { if (new_size != clock->area.height) {
// we try to limit the number of resizes // we try to limit the number of resizes
clock->area.height = new_size; clock->area.height = new_size;

View file

@ -322,8 +322,8 @@ gboolean resize_execp(void *obj)
panel->area.height, panel->area.height,
!text_next_line !text_next_line
? execp->area.width - icon_w - (icon_w ? interior_padding : 0) - ? execp->area.width - icon_w - (icon_w ? interior_padding : 0) -
2 * (horiz_padding + execp->area.bg->border.width) 2 * horiz_padding - left_right_border_width(&execp->area)
: execp->area.width - 2 * (horiz_padding + execp->area.bg->border.width), : execp->area.width - 2 * horiz_padding - left_right_border_width(&execp->area),
execp->backend->text, execp->backend->text,
strlen(execp->backend->text), strlen(execp->backend->text),
PANGO_WRAP_WORD_CHAR, PANGO_WRAP_WORD_CHAR,
@ -336,7 +336,7 @@ gboolean resize_execp(void *obj)
int new_size = txt_width; int new_size = txt_width;
if (icon_w) if (icon_w)
new_size += interior_padding + icon_w; new_size += interior_padding + icon_w;
new_size += 2 * (horiz_padding + execp->area.bg->border.width); new_size += 2 * horiz_padding + left_right_border_width(&execp->area);
if (new_size > execp->area.width || new_size < (execp->area.width - 6)) { if (new_size > execp->area.width || new_size < (execp->area.width - 6)) {
// we try to limit the number of resize // we try to limit the number of resize
execp->area.width = new_size + 1; execp->area.width = new_size + 1;
@ -345,12 +345,10 @@ gboolean resize_execp(void *obj)
} else { } else {
int new_size; int new_size;
if (!text_next_line) { if (!text_next_line) {
new_size = txt_height + (2 * (vert_padding + execp->area.bg->border.width)); new_size = txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area);
if (new_size < icon_h + (2 * (vert_padding + execp->area.bg->border.width))) { new_size = MAX(new_size, icon_h + 2 * vert_padding + top_bottom_border_width(&execp->area));
new_size = icon_h + (2 * (vert_padding + execp->area.bg->border.width));
}
} else { } else {
new_size = icon_h + interior_padding + txt_height + (2 * (vert_padding + execp->area.bg->border.width)); new_size = icon_h + interior_padding + txt_height + 2 * vert_padding + top_bottom_border_width(&execp->area);
} }
if (new_size != execp->area.height) { if (new_size != execp->area.height) {
execp->area.height = new_size; execp->area.height = new_size;
@ -380,18 +378,18 @@ gboolean resize_execp(void *obj)
if (icon_w) { if (icon_w) {
if (!text_next_line) { if (!text_next_line) {
execp->frontend->icony = (execp->area.height - icon_h) / 2; execp->frontend->icony = (execp->area.height - icon_h) / 2;
execp->frontend->iconx = execp->area.bg->border.width + horiz_padding; execp->frontend->iconx = left_border_width(&execp->area) + horiz_padding;
execp->frontend->texty = (execp->area.height - txt_height) / 2; execp->frontend->texty = (execp->area.height - txt_height) / 2;
execp->frontend->textx = execp->frontend->iconx + icon_w + interior_padding; execp->frontend->textx = execp->frontend->iconx + icon_w + interior_padding;
} else { } else {
execp->frontend->icony = (execp->area.height - icon_h - interior_padding - txt_height) / 2; execp->frontend->icony = (execp->area.height - icon_h - interior_padding - txt_height) / 2;
execp->frontend->iconx = execp->area.bg->border.width + horiz_padding; execp->frontend->iconx = left_border_width(&execp->area) + horiz_padding;
execp->frontend->texty = execp->frontend->icony + icon_h + interior_padding; execp->frontend->texty = execp->frontend->icony + icon_h + interior_padding;
execp->frontend->textx = execp->frontend->iconx; execp->frontend->textx = execp->frontend->iconx;
} }
} else { } else {
execp->frontend->texty = (execp->area.height - txt_height) / 2; execp->frontend->texty = (execp->area.height - txt_height) / 2;
execp->frontend->textx = execp->area.bg->border.width + horiz_padding; execp->frontend->textx = left_border_width(&execp->area) + horiz_padding;
} }
} }

View file

@ -57,15 +57,15 @@ int freespace_get_max_size(Panel *p)
continue; continue;
if (panel_horizontal) if (panel_horizontal)
size += a->width + (a->bg->border.width * 2) + p->area.paddingx; size += a->width + p->area.paddingx;
else else
size += a->height + (a->bg->border.width * 2) + p->area.paddingy; size += a->height + p->area.paddingy;
} }
if (panel_horizontal) if (panel_horizontal)
size = p->area.width - size - (p->area.bg->border.width * 2) - p->area.paddingxlr; size = p->area.width - size - left_right_border_width(&p->area) - p->area.paddingxlr;
else else
size = p->area.height - size - (p->area.bg->border.width * 2) - p->area.paddingxlr; size = p->area.height - size - top_bottom_border_width(&p->area) - p->area.paddingxlr;
return size; return size;
} }

View file

@ -163,7 +163,8 @@ gboolean resize_launcher(void *obj)
} else { } else {
icon_size = launcher->area.width; icon_size = launcher->area.width;
} }
icon_size = icon_size - (2 * launcher->area.bg->border.width) - (2 * launcher->area.paddingy); icon_size = icon_size - MAX(left_right_border_width(&launcher->area), top_bottom_border_width(&launcher->area)) -
(2 * launcher->area.paddingy);
if (launcher_max_icon_size > 0 && icon_size > launcher_max_icon_size) if (launcher_max_icon_size > 0 && icon_size > launcher_max_icon_size)
icon_size = launcher_max_icon_size; icon_size = launcher_max_icon_size;
@ -234,36 +235,36 @@ gboolean resize_launcher(void *obj)
if (!count) { if (!count) {
launcher->area.width = 0; launcher->area.width = 0;
} else { } else {
int height = launcher->area.height - 2 * launcher->area.bg->border.width - 2 * launcher->area.paddingy; int height = launcher->area.height - top_bottom_border_width(&launcher->area) - 2 * launcher->area.paddingy;
// here icons_per_column always higher than 0 // here icons_per_column always higher than 0
icons_per_column = (height + launcher->area.paddingx) / (icon_size + launcher->area.paddingx); icons_per_column = (height + launcher->area.paddingx) / (icon_size + launcher->area.paddingx);
margin = height - (icons_per_column - 1) * (icon_size + launcher->area.paddingx) - icon_size; margin = height - (icons_per_column - 1) * (icon_size + launcher->area.paddingx) - icon_size;
icons_per_row = count / icons_per_column + (count % icons_per_column != 0); icons_per_row = count / icons_per_column + (count % icons_per_column != 0);
launcher->area.width = (2 * launcher->area.bg->border.width) + (2 * launcher->area.paddingxlr) + launcher->area.width = left_right_border_width(&launcher->area) + 2 * launcher->area.paddingxlr +
(icon_size * icons_per_row) + ((icons_per_row - 1) * launcher->area.paddingx); (icon_size * icons_per_row) + ((icons_per_row - 1) * launcher->area.paddingx);
} }
} else { } else {
if (!count) { if (!count) {
launcher->area.height = 0; launcher->area.height = 0;
} else { } else {
int width = launcher->area.width - 2 * launcher->area.bg->border.width - 2 * launcher->area.paddingy; int width = launcher->area.width - top_bottom_border_width(&launcher->area) - 2 * launcher->area.paddingy;
// here icons_per_row always higher than 0 // here icons_per_row always higher than 0
icons_per_row = (width + launcher->area.paddingx) / (icon_size + launcher->area.paddingx); icons_per_row = (width + launcher->area.paddingx) / (icon_size + launcher->area.paddingx);
margin = width - (icons_per_row - 1) * (icon_size + launcher->area.paddingx) - icon_size; margin = width - (icons_per_row - 1) * (icon_size + launcher->area.paddingx) - icon_size;
icons_per_column = count / icons_per_row + (count % icons_per_row != 0); icons_per_column = count / icons_per_row + (count % icons_per_row != 0);
launcher->area.height = (2 * launcher->area.bg->border.width) + (2 * launcher->area.paddingxlr) + launcher->area.height = top_bottom_border_width(&launcher->area) + 2 * launcher->area.paddingxlr +
(icon_size * icons_per_column) + ((icons_per_column - 1) * launcher->area.paddingx); (icon_size * icons_per_column) + ((icons_per_column - 1) * launcher->area.paddingx);
} }
} }
int posx, posy; int posx, posy;
int start = launcher->area.bg->border.width + launcher->area.paddingy + margin / 2; int start;
if (panel_horizontal) { if (panel_horizontal) {
posy = start; posy = start = top_border_width(&launcher->area) + launcher->area.paddingy + margin / 2;
posx = launcher->area.bg->border.width + launcher->area.paddingxlr; posx = left_border_width(&launcher->area) + launcher->area.paddingxlr;
} else { } else {
posx = start; posx = start = left_border_width(&launcher->area) + launcher->area.paddingy + margin / 2;
posy = launcher->area.bg->border.width + launcher->area.paddingxlr; posy = top_border_width(&launcher->area) + launcher->area.paddingxlr;
} }
int i; int i;
@ -453,7 +454,10 @@ void launcher_load_icons(Launcher *launcher)
if (entry.exec) { if (entry.exec) {
LauncherIcon *launcherIcon = calloc(1, sizeof(LauncherIcon)); LauncherIcon *launcherIcon = calloc(1, sizeof(LauncherIcon));
launcherIcon->area.panel = launcher->area.panel; launcherIcon->area.panel = launcher->area.panel;
snprintf(launcherIcon->area.name, sizeof(launcherIcon->area.name), "LauncherIcon %s", entry.name ? entry.name : "null"); snprintf(launcherIcon->area.name,
sizeof(launcherIcon->area.name),
"LauncherIcon %s",
entry.name ? entry.name : "null");
launcherIcon->area._draw_foreground = draw_launcher_icon; launcherIcon->area._draw_foreground = draw_launcher_icon;
launcherIcon->area.size_mode = LAYOUT_FIXED; launcherIcon->area.size_mode = LAYOUT_FIXED;
launcherIcon->area._resize = NULL; launcherIcon->area._resize = NULL;

View file

@ -435,7 +435,9 @@ gboolean resize_panel(void *obj)
for (int i = 0; i < panel->num_desktops; i++) { for (int i = 0; i < panel->num_desktops; i++) {
Taskbar *taskbar = &panel->taskbar[i]; Taskbar *taskbar = &panel->taskbar[i];
int requested_size = (2 * taskbar->area.bg->border.width) + (2 * taskbar->area.paddingxlr); int requested_size = (panel_horizontal ? left_right_border_width(&taskbar->area)
: top_bottom_border_width(&taskbar->area)) +
2 * taskbar->area.paddingxlr;
int items = 0; int items = 0;
GList *l = taskbar->area.children; GList *l = taskbar->area.children;
if (taskbarname_enabled) if (taskbarname_enabled)

View file

@ -131,7 +131,8 @@ gboolean resize_systray(void *obj)
systray.icon_size = systray.area.height; systray.icon_size = systray.area.height;
else else
systray.icon_size = systray.area.width; systray.icon_size = systray.area.width;
systray.icon_size -= (2 * systray.area.bg->border.width) + (2 * systray.area.paddingy); systray.icon_size -= MAX(left_right_border_width(&systray.area), top_bottom_border_width(&systray.area)) +
2 * systray.area.paddingy;
if (systray_max_icon_size > 0) if (systray_max_icon_size > 0)
systray.icon_size = MIN(systray.icon_size, systray_max_icon_size); systray.icon_size = MIN(systray.icon_size, systray_max_icon_size);
@ -155,23 +156,23 @@ gboolean resize_systray(void *obj)
fprintf(stderr, BLUE "%s:%d number of icons = %d" RESET "\n", __FUNCTION__, __LINE__, count); fprintf(stderr, BLUE "%s:%d number of icons = %d" RESET "\n", __FUNCTION__, __LINE__, count);
if (panel_horizontal) { if (panel_horizontal) {
int height = systray.area.height - 2 * systray.area.bg->border.width - 2 * systray.area.paddingy; int height = systray.area.height - top_bottom_border_width(&systray.area) - 2 * systray.area.paddingy;
// here icons_per_column always higher than 0 // here icons_per_column always higher than 0
systray.icons_per_column = (height + systray.area.paddingx) / (systray.icon_size + systray.area.paddingx); systray.icons_per_column = (height + systray.area.paddingx) / (systray.icon_size + systray.area.paddingx);
systray.margin = systray.margin =
height - (systray.icons_per_column - 1) * (systray.icon_size + systray.area.paddingx) - systray.icon_size; height - (systray.icons_per_column - 1) * (systray.icon_size + systray.area.paddingx) - systray.icon_size;
systray.icons_per_row = count / systray.icons_per_column + (count % systray.icons_per_column != 0); systray.icons_per_row = count / systray.icons_per_column + (count % systray.icons_per_column != 0);
systray.area.width = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + systray.area.width = left_right_border_width(&systray.area) + 2 * systray.area.paddingxlr +
(systray.icon_size * systray.icons_per_row) + (systray.icon_size * systray.icons_per_row) +
((systray.icons_per_row - 1) * systray.area.paddingx); ((systray.icons_per_row - 1) * systray.area.paddingx);
} else { } else {
int width = systray.area.width - 2 * systray.area.bg->border.width - 2 * systray.area.paddingy; int width = systray.area.width - left_right_border_width(&systray.area) - 2 * systray.area.paddingy;
// here icons_per_row always higher than 0 // here icons_per_row always higher than 0
systray.icons_per_row = (width + systray.area.paddingx) / (systray.icon_size + systray.area.paddingx); systray.icons_per_row = (width + systray.area.paddingx) / (systray.icon_size + systray.area.paddingx);
systray.margin = systray.margin =
width - (systray.icons_per_row - 1) * (systray.icon_size + systray.area.paddingx) - systray.icon_size; width - (systray.icons_per_row - 1) * (systray.icon_size + systray.area.paddingx) - systray.icon_size;
systray.icons_per_column = count / systray.icons_per_row + (count % systray.icons_per_row != 0); systray.icons_per_column = count / systray.icons_per_row + (count % systray.icons_per_row != 0);
systray.area.height = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + systray.area.height = top_bottom_border_width(&systray.area) + (2 * systray.area.paddingxlr) +
(systray.icon_size * systray.icons_per_column) + (systray.icon_size * systray.icons_per_column) +
((systray.icons_per_column - 1) * systray.area.paddingx); ((systray.icons_per_column - 1) * systray.area.paddingx);
} }
@ -218,14 +219,15 @@ void on_change_systray(void *obj)
// Based on this we calculate the positions of the tray icons. // Based on this we calculate the positions of the tray icons.
Panel *panel = systray.area.panel; Panel *panel = systray.area.panel;
int posx, posy; int posx, posy;
int start = panel->area.bg->border.width + panel->area.paddingy + systray.area.bg->border.width + int start;
systray.area.paddingy + systray.margin / 2;
if (panel_horizontal) { if (panel_horizontal) {
posy = start; posy = start = top_border_width(&panel->area) + panel->area.paddingy + top_border_width(&systray.area) +
posx = systray.area.posx + systray.area.bg->border.width + systray.area.paddingxlr; systray.area.paddingy + systray.margin / 2;
posx = systray.area.posx + left_border_width(&systray.area) + systray.area.paddingxlr;
} else { } else {
posx = start; posx = start = left_border_width(&panel->area) + panel->area.paddingy + left_border_width(&systray.area) +
posy = systray.area.posy + systray.area.bg->border.width + systray.area.paddingxlr; systray.area.paddingy + systray.margin / 2;
posy = systray.area.posy + top_border_width(&systray.area) + systray.area.paddingxlr;
} }
TrayWindow *traywin; TrayWindow *traywin;

View file

@ -369,7 +369,7 @@ void draw_task_icon(Task *task, int text_width)
else else
pos_x = (task->area.width - panel->g_task.icon_size1) / 2; pos_x = (task->area.width - panel->g_task.icon_size1) / 2;
} else { } else {
pos_x = task->area.bg->border.width + task->area.paddingxlr; pos_x = left_border_width(&task->area) + task->area.paddingxlr;
} }
// Render // Render
@ -393,7 +393,7 @@ void draw_task_icon(Task *task, int text_width)
fprintf(stderr, "Task icon size: %d %d pos %d %d\n", imlib_image_get_width(), imlib_image_get_height(), pos_x, panel->g_task.icon_posy); fprintf(stderr, "Task icon size: %d %d pos %d %d\n", imlib_image_get_width(), imlib_image_get_height(), pos_x, panel->g_task.icon_posy);
fprintf(stderr, "Task max size : %d %d\n", panel->g_task.maximum_width, panel->g_task.maximum_height); fprintf(stderr, "Task max size : %d %d\n", panel->g_task.maximum_width, panel->g_task.maximum_height);
fprintf(stderr, "Task area size: %d %d\n", task->area.width, task->area.height); fprintf(stderr, "Task area size: %d %d\n", task->area.width, task->area.height);
fprintf(stderr, "Task border : %d\n", task->area.bg->border.width); fprintf(stderr, "Task border : %d\n", left_border_width(&task->area));
fprintf(stderr, "\n"); fprintf(stderr, "\n");
} }
} }

View file

@ -167,13 +167,15 @@ void init_taskbar_panel(void *p)
panel->g_taskbar.area.resize_needed = 1; panel->g_taskbar.area.resize_needed = 1;
panel->g_taskbar.area.on_screen = TRUE; panel->g_taskbar.area.on_screen = TRUE;
if (panel_horizontal) { if (panel_horizontal) {
panel->g_taskbar.area.posy = panel->area.bg->border.width + panel->area.paddingy; panel->g_taskbar.area.posy = top_border_width(&panel->area) + panel->area.paddingy;
panel->g_taskbar.area.height = panel->area.height - (2 * panel->g_taskbar.area.posy); panel->g_taskbar.area.height =
panel->area.height - top_bottom_border_width(&panel->area) - 2 * panel->area.paddingy;
panel->g_taskbar.area_name.posy = panel->g_taskbar.area.posy; panel->g_taskbar.area_name.posy = panel->g_taskbar.area.posy;
panel->g_taskbar.area_name.height = panel->g_taskbar.area.height; panel->g_taskbar.area_name.height = panel->g_taskbar.area.height;
} else { } else {
panel->g_taskbar.area.posx = panel->area.bg->border.width + panel->area.paddingy; panel->g_taskbar.area.posx = left_border_width(&panel->area) + panel->area.paddingy;
panel->g_taskbar.area.width = panel->area.width - (2 * panel->g_taskbar.area.posx); panel->g_taskbar.area.width =
panel->area.width - left_right_border_width(&panel->area) - 2 * panel->area.paddingy;
panel->g_taskbar.area_name.posx = panel->g_taskbar.area.posx; panel->g_taskbar.area_name.posx = panel->g_taskbar.area.posx;
panel->g_taskbar.area_name.width = panel->g_taskbar.area.width; panel->g_taskbar.area_name.width = panel->g_taskbar.area.width;
} }
@ -230,15 +232,19 @@ void init_taskbar_panel(void *p)
if (panel_horizontal) { if (panel_horizontal) {
panel->g_task.area.posy = panel->g_taskbar.area.posy + panel->g_task.area.posy = panel->g_taskbar.area.posy +
panel->g_taskbar.background[TASKBAR_NORMAL]->border.width + top_bg_border_width(panel->g_taskbar.background[TASKBAR_NORMAL]) +
panel->g_taskbar.area.paddingy; panel->g_taskbar.area.paddingy;
panel->g_task.area.width = panel->g_task.maximum_width; panel->g_task.area.width = panel->g_task.maximum_width;
panel->g_task.area.height = panel->area.height - (2 * panel->g_task.area.posy); panel->g_task.area.height = panel->g_taskbar.area.height -
top_bottom_bg_border_width(panel->g_taskbar.background[TASKBAR_NORMAL]) -
2 * panel->g_taskbar.area.paddingy;
} else { } else {
panel->g_task.area.posx = panel->g_taskbar.area.posx + panel->g_task.area.posx = panel->g_taskbar.area.posx +
panel->g_taskbar.background[TASKBAR_NORMAL]->border.width + left_bg_border_width(panel->g_taskbar.background[TASKBAR_NORMAL]) +
panel->g_taskbar.area.paddingy; panel->g_taskbar.area.paddingy;
panel->g_task.area.width = panel->area.width - (2 * panel->g_task.area.posx); panel->g_task.area.width = panel->g_taskbar.area.width -
left_right_bg_border_width(panel->g_taskbar.background[TASKBAR_NORMAL]) -
2 * panel->g_taskbar.area.paddingy;
panel->g_task.area.height = panel->g_task.maximum_height; panel->g_task.area.height = panel->g_task.maximum_height;
} }
@ -268,13 +274,13 @@ void init_taskbar_panel(void *p)
PANGO_ELLIPSIZE_END, PANGO_ELLIPSIZE_END,
FALSE); FALSE);
panel->g_task.text_posx = panel->g_task.background[0]->border.width + panel->g_task.area.paddingxlr; panel->g_task.text_posx = left_bg_border_width(panel->g_task.background[0]) + panel->g_task.area.paddingxlr;
panel->g_task.text_height = panel->g_task.area.height - (2 * panel->g_task.area.paddingy); panel->g_task.text_height = panel->g_task.area.height - (2 * panel->g_task.area.paddingy);
if (panel->g_task.has_icon) { if (panel->g_task.has_icon) {
panel->g_task.icon_size1 = panel->g_task.icon_size1 = MIN(MIN(panel->g_task.maximum_width, panel->g_task.maximum_height),
MIN(MIN(panel->g_task.maximum_width, panel->g_task.maximum_height),
MIN(panel->g_task.area.width, panel->g_task.area.height)) - MIN(panel->g_task.area.width, panel->g_task.area.height)) -
(2 * panel->g_task.area.paddingy) - 2 * panel->g_task.area.bg->border.width; 2 * panel->g_task.area.paddingy - MAX(left_right_border_width(&panel->g_task.area),
top_bottom_border_width(&panel->g_task.area));
panel->g_task.text_posx += panel->g_task.icon_size1 + panel->g_task.area.paddingx; panel->g_task.text_posx += panel->g_task.icon_size1 + panel->g_task.area.paddingx;
panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2; panel->g_task.icon_posy = (panel->g_task.area.height - panel->g_task.icon_size1) / 2;
if (0) if (0)
@ -413,13 +419,13 @@ gboolean resize_taskbar(void *obj)
break; break;
} }
} }
taskbar->text_width = taskbar->text_width = text_width - panel->g_task.text_posx - right_border_width(&panel->g_task.area) -
text_width - panel->g_task.text_posx - panel->g_task.area.bg->border.width - panel->g_task.area.paddingxlr; panel->g_task.area.paddingxlr;
} else { } else {
relayout_with_constraint(&taskbar->area, panel->g_task.maximum_height); relayout_with_constraint(&taskbar->area, panel->g_task.maximum_height);
taskbar->text_width = taskbar->area.width - (2 * panel->g_taskbar.area.paddingy) - panel->g_task.text_posx - taskbar->text_width = taskbar->area.width - (2 * panel->g_taskbar.area.paddingy) - panel->g_task.text_posx -
panel->g_task.area.bg->border.width - panel->g_task.area.paddingxlr; right_border_width(&panel->g_task.area) - panel->g_task.area.paddingxlr;
} }
return FALSE; return FALSE;
} }

View file

@ -147,14 +147,14 @@ gboolean resize_taskbarname(void *obj)
FALSE); FALSE);
if (panel_horizontal) { if (panel_horizontal) {
int new_size = name_width + (2 * (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width)); int new_size = name_width + 2 * taskbar_name->area.paddingxlr + left_right_border_width(&taskbar_name->area);
if (new_size != taskbar_name->area.width) { if (new_size != taskbar_name->area.width) {
taskbar_name->area.width = new_size; taskbar_name->area.width = new_size;
taskbar_name->posy = (taskbar_name->area.height - name_height) / 2; taskbar_name->posy = (taskbar_name->area.height - name_height) / 2;
result = TRUE; result = TRUE;
} }
} else { } else {
int new_size = name_height + (2 * (taskbar_name->area.paddingxlr + taskbar_name->area.bg->border.width)); int new_size = name_height + 2 * taskbar_name->area.paddingxlr + top_bottom_border_width(&taskbar_name->area);
if (new_size != taskbar_name->area.height) { if (new_size != taskbar_name->area.height) {
taskbar_name->area.height = new_size; taskbar_name->area.height = new_size;
taskbar_name->posy = (taskbar_name->area.height - name_height) / 2; taskbar_name->posy = (taskbar_name->area.height - name_height) / 2;

View file

@ -160,8 +160,8 @@ void tooltip_update_geometry()
pango_layout_set_text(layout, g_tooltip.tooltip_text, -1); pango_layout_set_text(layout, g_tooltip.tooltip_text, -1);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD); pango_layout_set_wrap(layout, PANGO_WRAP_WORD);
pango_layout_get_pixel_extents(layout, &r1, &r2); pango_layout_get_pixel_extents(layout, &r1, &r2);
width = 2 * g_tooltip.bg->border.width + 2 * g_tooltip.paddingx + r2.width; width = left_right_bg_border_width(g_tooltip.bg) + 2 * g_tooltip.paddingx + r2.width;
height = 2 * g_tooltip.bg->border.width + 2 * g_tooltip.paddingy + r2.height; height = top_bottom_bg_border_width(g_tooltip.bg) + 2 * g_tooltip.paddingy + r2.height;
if (panel_horizontal && panel_position & BOTTOM) if (panel_horizontal && panel_position & BOTTOM)
y = panel->posy - height; y = panel->posy - height;
@ -275,8 +275,8 @@ void tooltip_update()
// I do not know why this is the right way, but with the below cairo_move_to it seems to be centered (horiz. and // I do not know why this is the right way, but with the below cairo_move_to it seems to be centered (horiz. and
// vert.) // vert.)
cairo_move_to(c, cairo_move_to(c,
-r1.x / 2 + g_tooltip.bg->border.width + g_tooltip.paddingx, -r1.x / 2 + left_bg_border_width(g_tooltip.bg) + g_tooltip.paddingx,
-r1.y / 2 + 1 + g_tooltip.bg->border.width + g_tooltip.paddingy); -r1.y / 2 + 1 + top_bg_border_width(g_tooltip.bg) + g_tooltip.paddingy);
pango_cairo_show_layout(c, layout); pango_cairo_show_layout(c, layout);
g_object_unref(layout); g_object_unref(layout);

View file

@ -45,14 +45,14 @@ void initialize_positions(void *obj, int offset)
for (GList *l = a->children; l; l = l->next) { for (GList *l = a->children; l; l = l->next) {
Area *child = ((Area *)l->data); Area *child = ((Area *)l->data);
if (panel_horizontal) { if (panel_horizontal) {
child->posy = offset + a->bg->border.width + a->paddingy; child->posy = offset + top_border_width(a) + a->paddingy;
child->height = a->height - (2 * (a->bg->border.width + a->paddingy)); child->height = a->height - 2 * a->paddingy - top_bottom_border_width(a);
if (child->_on_change_layout) if (child->_on_change_layout)
child->_on_change_layout(child); child->_on_change_layout(child);
initialize_positions(child, child->posy); initialize_positions(child, child->posy);
} else { } else {
child->posx = offset + a->bg->border.width + a->paddingy; child->posx = offset + left_border_width(a) + a->paddingy;
child->width = a->width - (2 * (a->bg->border.width + a->paddingy)); child->width = a->width - 2 * a->paddingy - left_right_border_width(a);
if (child->_on_change_layout) if (child->_on_change_layout)
child->_on_change_layout(child); child->_on_change_layout(child);
initialize_positions(child, child->posx); initialize_positions(child, child->posx);
@ -108,7 +108,8 @@ void relayout_dynamic(Area *a, int level)
// Layout children // Layout children
if (a->children) { if (a->children) {
if (a->alignment == ALIGN_LEFT) { if (a->alignment == ALIGN_LEFT) {
int pos = (panel_horizontal ? a->posx : a->posy) + a->bg->border.width + a->paddingxlr; int pos =
(panel_horizontal ? a->posx + left_border_width(a) : a->posy + top_border_width(a)) + a->paddingxlr;
for (GList *l = a->children; l; l = l->next) { for (GList *l = a->children; l; l = l->next) {
Area *child = ((Area *)l->data); Area *child = ((Area *)l->data);
@ -134,8 +135,9 @@ void relayout_dynamic(Area *a, int level)
pos += panel_horizontal ? child->width + a->paddingx : child->height + a->paddingx; pos += panel_horizontal ? child->width + a->paddingx : child->height + a->paddingx;
} }
} else if (a->alignment == ALIGN_RIGHT) { } else if (a->alignment == ALIGN_RIGHT) {
int pos = int pos = (panel_horizontal ? a->posx + a->width - right_border_width(a)
(panel_horizontal ? a->posx + a->width : a->posy + a->height) - a->bg->border.width - a->paddingxlr; : a->posy + a->height - bottom_border_width(a)) -
a->paddingxlr;
for (GList *l = g_list_last(a->children); l; l = l->prev) { for (GList *l = g_list_last(a->children); l; l = l->prev) {
Area *child = ((Area *)l->data); Area *child = ((Area *)l->data);
@ -175,7 +177,7 @@ void relayout_dynamic(Area *a, int level)
children_size += (l == a->children) ? 0 : a->paddingx; children_size += (l == a->children) ? 0 : a->paddingx;
} }
int pos = (panel_horizontal ? a->posx : a->posy) + a->bg->border.width + a->paddingxlr; int pos = (panel_horizontal ? a->posx + left_border_width(a) : a->posy + top_border_width(a)) + a->paddingxlr;
pos += ((panel_horizontal ? a->width : a->height) - children_size) / 2; pos += ((panel_horizontal ? a->width : a->height) - children_size) / 2;
for (GList *l = a->children; l; l = l->next) { for (GList *l = a->children; l; l = l->next) {
@ -251,7 +253,7 @@ int relayout_with_constraint(Area *a, int maximum_size)
if (panel_horizontal) { if (panel_horizontal) {
// detect free size for LAYOUT_DYNAMIC Areas // detect free size for LAYOUT_DYNAMIC Areas
int size = a->width - (2 * (a->paddingxlr + a->bg->border.width)); int size = a->width - 2 * a->paddingxlr - left_right_border_width(a);
for (GList *l = a->children; l; l = l->next) { for (GList *l = a->children; l; l = l->next) {
Area *child = (Area *)l->data; Area *child = (Area *)l->data;
if (child->on_screen && child->size_mode == LAYOUT_FIXED) { if (child->on_screen && child->size_mode == LAYOUT_FIXED) {
@ -291,7 +293,7 @@ int relayout_with_constraint(Area *a, int maximum_size)
} }
} else { } else {
// detect free size for LAYOUT_DYNAMIC's Area // detect free size for LAYOUT_DYNAMIC's Area
int size = a->height - (2 * (a->paddingxlr + a->bg->border.width)); int size = a->height - 2 * a->paddingxlr - top_bottom_border_width(a);
for (GList *l = a->children; l; l = l->next) { for (GList *l = a->children; l; l = l->next) {
Area *child = (Area *)l->data; Area *child = (Area *)l->data;
if (child->on_screen && child->size_mode == LAYOUT_FIXED) { if (child->on_screen && child->size_mode == LAYOUT_FIXED) {
@ -457,14 +459,10 @@ void draw_background(Area *a, cairo_t *c)
a->bg->fill_color.alpha); a->bg->fill_color.alpha);
// Not sure about this // Not sure about this
draw_rect(c, draw_rect(c,
a->bg->border.mask & BORDER_LEFT ? a->bg->border.width : 0, left_border_width(a),
a->bg->border.mask & BORDER_TOP ? a->bg->border.width : 0, top_border_width(a),
a->width a->width - left_right_border_width(a),
- (a->bg->border.mask & BORDER_LEFT ? a->bg->border.width : 0) a->height - top_bottom_border_width(a),
- (a->bg->border.mask & BORDER_RIGHT ? a->bg->border.width : 0),
a->height
- (a->bg->border.mask & BORDER_TOP ? a->bg->border.width : 0)
- (a->bg->border.mask & BORDER_BOTTOM ? a->bg->border.width : 0),
a->bg->border.radius - a->bg->border.width / 1.571); a->bg->border.radius - a->bg->border.width / 1.571);
cairo_fill(c); cairo_fill(c);
@ -493,14 +491,10 @@ void draw_background(Area *a, cairo_t *c)
a->bg->border.color.rgb[2], a->bg->border.color.rgb[2],
a->bg->border.color.alpha); a->bg->border.color.alpha);
draw_rect_on_sides(c, draw_rect_on_sides(c,
a->bg->border.mask & BORDER_LEFT ? a->bg->border.width / 2. : 0, left_border_width(a) / 2.,
a->bg->border.mask & BORDER_TOP ? a->bg->border.width / 2.0 : 0, top_border_width(a) / 2.,
a->width a->width - left_right_border_width(a) / 2.,
- (a->bg->border.mask & BORDER_LEFT ? a->bg->border.width / 2. : 0) a->height - top_bottom_border_width(a) / 2.,
- (a->bg->border.mask & BORDER_RIGHT ? a->bg->border.width / 2. : 0),
a->height
- (a->bg->border.mask & BORDER_TOP ? a->bg->border.width / 2. : 0)
- (a->bg->border.mask & BORDER_BOTTOM ? a->bg->border.width / 2. : 0),
a->bg->border.radius, a->bg->border.radius,
a->bg->border.mask); a->bg->border.mask);
@ -713,3 +707,68 @@ Area *find_area_under_mouse(void *root, int x, int y)
} while (new_result != result); } while (new_result != result);
return result; return result;
} }
int left_border_width(Area *a)
{
return left_bg_border_width(a->bg);
}
int right_border_width(Area *a)
{
return right_bg_border_width(a->bg);
}
int top_border_width(Area *a)
{
return top_bg_border_width(a->bg);
}
int bottom_border_width(Area *a)
{
return bottom_bg_border_width(a->bg);
}
int left_right_border_width(Area *a)
{
return left_right_bg_border_width(a->bg);
}
int top_bottom_border_width(Area *a)
{
return top_bottom_bg_border_width(a->bg);
}
int bg_border_width(Background *bg, int mask)
{
return bg->border.mask & mask ? bg->border.width : 0;
}
int left_bg_border_width(Background *bg)
{
return bg_border_width(bg, BORDER_LEFT);
}
int top_bg_border_width(Background *bg)
{
return bg_border_width(bg, BORDER_TOP);
}
int right_bg_border_width(Background *bg)
{
return bg_border_width(bg, BORDER_RIGHT);
}
int bottom_bg_border_width(Background *bg)
{
return bg_border_width(bg, BORDER_BOTTOM);
}
int left_right_bg_border_width(Background *bg)
{
return left_bg_border_width(bg) + right_bg_border_width(bg);
}
int top_bottom_bg_border_width(Background *bg)
{
return top_bg_border_width(bg) + bottom_bg_border_width(bg);
}

View file

@ -250,6 +250,20 @@ void relayout(Area *a);
// If maximum_size > 0, it is an upper limit for the child size. // If maximum_size > 0, it is an upper limit for the child size.
int relayout_with_constraint(Area *a, int maximum_size); int relayout_with_constraint(Area *a, int maximum_size);
int left_border_width(Area *a);
int right_border_width(Area *a);
int left_right_border_width(Area *a);
int top_border_width(Area *a);
int bottom_border_width(Area *a);
int top_bottom_border_width(Area *a);
int left_bg_border_width(Background *bg);
int right_bg_border_width(Background *bg);
int top_bg_border_width(Background *bg);
int bottom_bg_border_width(Background *bg);
int left_right_bg_border_width(Background *bg);
int top_bottom_bg_border_width(Background *bg);
// Rendering // Rendering
// Sets the redraw_needed flag on the area and its descendants // Sets the redraw_needed flag on the area and its descendants