]> git.mdlowis.com Git - proto/labwc.git/commitdiff
don't set view->w and view->h when mapping xdg views
authorbi4k8 <bi4k8@github>
Sat, 17 Dec 2022 20:47:46 +0000 (20:47 +0000)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 19 Dec 2022 17:21:07 +0000 (18:21 +0100)
these should only be set on commit. doing so before then confuses
code that expects these fields to be in sync with the scene tree,
such as `handle_commit`.

these were only being set so that `view_center` could read them to
compute a centered position, so instead we can simply forward the
values directly to `view_compute_centered_position` and `view_move`.

include/view.h
src/view.c
src/xdg.c

index 1cbe8b22492631dc24cd1e745eaf1f9f54a203e8..f65f7f90a5c3006a527772a980f45fa72bafb136 100644 (file)
@@ -159,6 +159,9 @@ void view_reload_ssd(struct view *view);
 void view_impl_map(struct view *view);
 void view_adjust_size(struct view *view, int *w, int *h);
 
+bool view_compute_centered_position(struct view *view, int w, int h,
+       int *x, int *y);
+
 void view_on_output_destroy(struct view *view);
 void view_destroy(struct view *view);
 
index b7a87a95fccdf8529b0292f89fd8040b218ac3ab..b367045eba86ecd5ed37a847f0fa7270c79b78db 100644 (file)
@@ -267,7 +267,7 @@ view_output(struct view *view)
        return output_from_wlr_output(view->server, wlr_output);
 }
 
-static bool
+bool
 view_compute_centered_position(struct view *view, int w, int h, int *x, int *y)
 {
        struct output *output = view_output(view);
index 6ae53993f1a34484b0fc869b80890e0beceff77b..0f5e8b527a0a48e5e97decc36c8542574639844a 100644 (file)
--- a/src/xdg.c
+++ b/src/xdg.c
@@ -285,10 +285,19 @@ position_xdg_toplevel_view(struct view *view)
                        output_usable_area_from_cursor_coords(view->server);
                view->x = box.x;
                view->y = box.y;
-               view->w = xdg_surface->current.geometry.width;
-               view->h = xdg_surface->current.geometry.height;
-               if (view->w && view->h) {
-                       view_center(view);
+
+               /* Center the view without touching its w and h fields. This means we
+                * can't simply set w/h and call view_center().  w and h fields should
+                * only be modified at commit, or they will not be in sync with the
+                * scene tree
+                */
+               int w = xdg_surface->current.geometry.width;
+               int h = xdg_surface->current.geometry.height;
+               if (w && h) {
+                       int x, y;
+                       if (view_compute_centered_position(view, w, h, &x, &y)) {
+                               view_move(view, x, y);
+                       }
                }
        } else {
                /*