exposay: centralize surfaces of the last row when we don't have enough surfaces
authorLeandro Ribeiro <leandrohr@riseup.net>
Fri, 24 Jan 2020 22:57:39 +0000 (19:57 -0300)
committerDaniel Stone <daniels@collabora.com>
Wed, 26 Aug 2020 14:10:50 +0000 (14:10 +0000)
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 <leandrohr@riseup.net>
desktop-shell/exposay.c

index 09bc3f26b31c9a78ed406a065d93a40556ee056c..06b07ef1930f9e517979671c1c10035d0b03edba 100644 (file)
@@ -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;