From 82b4d4294319075938ad5cdfedaa19ccc57aa9ec Mon Sep 17 00:00:00 2001 From: Leandro Ribeiro Date: Fri, 24 Jan 2020 19:57:39 -0300 Subject: [PATCH] exposay: centralize surfaces of the last row when we don't have enough surfaces The exposay grid is square, but we don't always have enough surfaces to fill all the columns of the last row. The code to centralize the surfaces of the last row is not working. Fix the code that centralizes the surfaces in the last row, making it more visually pleasant. Signed-off-by: Leandro Ribeiro --- desktop-shell/exposay.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/desktop-shell/exposay.c b/desktop-shell/exposay.c index 09bc3f26..06b07ef1 100644 --- a/desktop-shell/exposay.c +++ b/desktop-shell/exposay.c @@ -262,9 +262,9 @@ exposay_layout(struct desktop_shell *shell, struct shell_output *shell_output) struct exposay_surface *esurface, *highlight = NULL; pixman_rectangle32_t exposay_area; int pad, row_size, column_size, left_margin, top_margin; + int last_row_size, last_row_margin_increase; int populated_rows; int i; - int last_row_removed = 0; eoutput->num_surfaces = 0; wl_list_for_each(view, &workspace->layer.view_list.link, layer_link.link) { @@ -292,7 +292,6 @@ exposay_layout(struct desktop_shell *shell, struct shell_output *shell_output) eoutput->grid_size = floor(sqrtf(eoutput->num_surfaces)); if (pow(eoutput->grid_size, 2) != eoutput->num_surfaces) eoutput->grid_size++; - last_row_removed = pow(eoutput->grid_size, 2) - eoutput->num_surfaces; /* Fixed outer padding of 10% the size of the screen */ eoutput->hpadding_outer = (exposay_area.width / 10); @@ -309,6 +308,15 @@ exposay_layout(struct desktop_shell *shell, struct shell_output *shell_output) populated_rows = ceil(eoutput->num_surfaces / (float) eoutput->grid_size); column_size = (pad * populated_rows) - eoutput->padding_inner; + /* The last row size can be different, since it may have less surfaces + * than the grid size. Also, its margin may be increased to centralize + * its surfaces, in the case where we don't have a perfect grid. */ + last_row_size = ((eoutput->num_surfaces % eoutput->grid_size) * pad) - eoutput->padding_inner; + if (eoutput->num_surfaces % eoutput->grid_size) + last_row_margin_increase = (row_size - last_row_size) / 2; + else + last_row_margin_increase = 0; + /* Compute a top/left margin to centralize the exposay */ exposay_margin_size(shell, exposay_area, row_size, column_size, &left_margin, &top_margin); @@ -338,8 +346,10 @@ exposay_layout(struct desktop_shell *shell, struct shell_output *shell_output) esurface->x = left_margin + (pad * esurface->column); esurface->y = top_margin + (pad * esurface->row); - if (esurface->row == eoutput->grid_size - 1) - esurface->x += (eoutput->surface_size + eoutput->padding_inner) * last_row_removed / 2; + /* If this is the last row, increase left margin (it sums 0 if + * we have a perfect square) to centralize the surfaces */ + if (eoutput->num_surfaces / eoutput->grid_size == esurface->row) + esurface->x += last_row_margin_increase; if (view->surface->width > view->surface->height) esurface->scale = eoutput->surface_size / (float) view->surface->width;