aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-03-16 01:03:56 +0100
committerFederico Angelilli <code@fedang.net>2024-03-16 01:03:56 +0100
commit9dcc07bdc6360b2ebbd618bb864024f62bf98918 (patch)
treeb083e6bd2126565d450d83785cdd8b35809a2be0 /src
parent58476d9c85a427141fdee2d3d74c162ff40aecca (diff)
Fix center and right layout offset calculation
Diffstat (limited to 'src')
-rw-r--r--src/draw.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/draw.c b/src/draw.c
index abdbb8e..609d96a 100644
--- a/src/draw.c
+++ b/src/draw.c
@@ -219,7 +219,8 @@ static GList *compute_group_layout(Drawer *draw, Window *win, GList *btns, int b
layout->width = last->x + last->width - bx;
layout->height = draw->height;
- // FIXME: Temporary solution to make the antialiasing (or the circles not overlapping correctly) problem less noticeable
+ // FIXME: Temporary solution to make the antialiasing (or the circles not
+ // overlapping correctly) problem less noticeable
bool fix_left = CAST(layout->children->data, Layout)->x_pad == 0;
if (fix_left) {
layout->x += 1;
@@ -271,6 +272,8 @@ static GList *compute_group_layout(Drawer *draw, Window *win, GList *btns, int b
void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
{
compute_width(draw, win);
+ memset(draw->layout_end, 0, sizeof(draw->layout_end));
+ memset(draw->layout_bx, 0, sizeof(draw->layout_bx));
g_list_free_full(draw->layouts, (GDestroyNotify)layout_destroy);
draw->layouts = compute_group_layout(draw, win, btns, 0, true);
@@ -283,13 +286,14 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
log_error("Layout is bigger than the window (%d vs %d)", draw->layout_bx[PANGO_ALIGN_RIGHT], draw->width);
}
- bool has_center = draw->layout_end[PANGO_ALIGN_LEFT] && draw->layout_end[PANGO_ALIGN_LEFT]->next;
- bool has_right = draw->layout_end[PANGO_ALIGN_LEFT] && draw->layout_end[PANGO_ALIGN_CENTER]->next;
+ bool has_left = draw->layout_end[PANGO_ALIGN_LEFT] != NULL;
+ bool has_center = draw->layout_end[PANGO_ALIGN_CENTER] != NULL;
- GList *center_start = has_center ? draw->layout_end[PANGO_ALIGN_LEFT]->next : NULL;
- GList *right_start = has_right ? draw->layout_end[PANGO_ALIGN_CENTER]->next : NULL;
+ GList *center_start = has_left ? draw->layout_end[PANGO_ALIGN_LEFT]->next : draw->layouts;
+ GList *right_start = has_center ? draw->layout_end[PANGO_ALIGN_CENTER]->next :
+ has_left ? draw->layout_end[PANGO_ALIGN_LEFT]->next : draw->layouts;
- if (has_center) {
+ if (center_start != NULL) {
int center = round(draw->width / 2);
int center_off = center - draw->layout_width[PANGO_ALIGN_CENTER] / 2 - draw->layout_bx[PANGO_ALIGN_LEFT];
@@ -297,7 +301,7 @@ void draw_compute_layout(Drawer *draw, Window *win, GList *btns)
layout_adjust(center_start, right_start, center_off);
}
- if (has_right) {
+ if (right_start != NULL) {
int right = draw->width - draw->layout_width[PANGO_ALIGN_RIGHT];
int right_off = right - MAX(draw->layout_bx[PANGO_ALIGN_LEFT], draw->layout_bx[PANGO_ALIGN_CENTER]);