After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 782213 - xdg-shell client's window geometry can be wrong
xdg-shell client's window geometry can be wrong
Status: RESOLVED FIXED
Product: mutter
Classification: Core
Component: wayland
3.24.x
Other Linux
: Normal normal
: ---
Assigned To: mutter-maint
mutter-maint
Depends on:
Blocks:
 
 
Reported: 2017-05-05 11:23 UTC by Sergi Granell
Modified: 2017-05-10 08:53 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Mutter log (7.09 KB, text/plain)
2017-05-05 11:27 UTC, Sergi Granell
  Details
[PATCH] wayland: Make sure we have a pending geometry (1.21 KB, patch)
2017-05-05 11:59 UTC, Olivier Fourdan
none Details | Review
[PATCH 1/2] wayland: Make sure we have a pending geometry (1.70 KB, patch)
2017-05-10 07:08 UTC, Olivier Fourdan
committed Details | Review
[PATCH 2/2] wayland: Apply size hints regardless of geometry (2.23 KB, patch)
2017-05-10 07:08 UTC, Olivier Fourdan
none Details | Review
[PATCH 2/2 v2] wayland: Apply size hints regardless of geometry (2.23 KB, patch)
2017-05-10 08:17 UTC, Olivier Fourdan
committed Details | Review

Description Sergi Granell 2017-05-05 11:23:19 UTC
When a xdg-shell client doesn't set the window geometry explicitly (xdg_surface.set_window_geometry) mutter doesn't calculate a valid geometry for it.
According to the xdg-shell-unstable-v6 spec [0], set_window_geometry "If never set, the value is the full bounds of the surface".

This bug can be reproduced very easily by launching an xdg-shell client that doesn't call set_window_geometry (like weston-simple-egl or weston-simple-shm for example).

Here are some screenshots showing this bug:
https://i.imgur.com/qps0PM5.png
https://i.imgur.com/AFyAG8c.png

0: https://cgit.freedesktop.org/wayland/wayland-protocols/tree/unstable/xdg-shell/xdg-shell-unstable-v6.xml#n449
Comment 1 Sergi Granell 2017-05-05 11:27:35 UTC
Created attachment 351187 [details]
Mutter log
Comment 2 Olivier Fourdan 2017-05-05 11:59:35 UTC
Created attachment 351190 [details] [review]
[PATCH] wayland: Make sure we have a pending geometry

If the client doesn't set a geometry using xdg_shell, we'll compute its
geometry based on its surface and subsurfaces.

Yet, we translate that as a window (re)size only when there is a pending
geometry, that we don't have when we computed the geometry by ourself.

Make sure we set the pending new geometry flag when computing the
geometry.
Comment 3 Armin Krezović 2017-05-05 12:28:35 UTC
(In reply to Olivier Fourdan from comment #2)
> Created attachment 351190 [details] [review] [review]
> [PATCH] wayland: Make sure we have a pending geometry
> 
> If the client doesn't set a geometry using xdg_shell, we'll compute its
> geometry based on its surface and subsurfaces.
> 
> Yet, we translate that as a window (re)size only when there is a pending
> geometry, that we don't have when we computed the geometry by ourself.
> 
> Make sure we set the pending new geometry flag when computing the
> geometry.

Works fine. Push it (and backport it to 3.24, please)!
Comment 4 Olivier Fourdan 2017-05-09 07:23:30 UTC
Thanks for the feedback, however "working fine" is not sufficient as a criteria for landing a patch, I'd rather see a review of the patch itself (even though it looks trivial).
Comment 5 Jonas Ådahl 2017-05-09 08:17:43 UTC
Review of attachment 351190 [details] [review]:

::: src/wayland/meta-wayland-xdg-shell.c
@@ +1280,3 @@
                                                       &priv->geometry,
                                                       0, 0);
+      pending->has_new_geometry = TRUE;

This means that for every commit on a surface that doesn't ever set the geometry we'll go through the move/resize code, which might be a bit costly, so I'd rather see we only set this state if priv->geometry actually changed (or the size only really).

BTW, I spot a bug here. In this case here, it looks like the geometry can never ever shrink, only become larger, as calculate_window_geometry() takes geometry passed, and unions it with the current state. If the surface at first is 100x100, then resized to 50x50, the union of 50x50 and 100x100 will still be 100x100. So we should actually pass an empty rectangle to calculate_window_geometry(). That'll be convienient, since we can then compare that with priv->geometry and determine whether to set has_new_geometry or not.
Comment 6 Jonas Ådahl 2017-05-09 08:20:20 UTC
BTW, another bug I spotted when reviewing this: if we set the min/max size while not also setting a new geometry, we'll ignore the min/max in xdg_toplevel_commit(). So, maybe the early out should be changed to if (pending->has_new_geometry) { move_resize(...); }
Comment 7 Olivier Fourdan 2017-05-10 07:08:14 UTC
Created attachment 351509 [details] [review]
[PATCH 1/2] wayland: Make sure we have a pending geometry

If the client doesn't set a geometry using xdg_shell, we'll compute its
geometry based on its surface and subsurfaces.

Yet, we translate that as a window (re)size only when there is a pending
geometry, that we don't have when we computed the geometry by ourself.

Make sure we set the pending new geometry flag when computing the
geometry when it actually changed.
Comment 8 Olivier Fourdan 2017-05-10 07:08:50 UTC
Created attachment 351511 [details] [review]
[PATCH 2/2] wayland: Apply size hints regardless of geometry

Previously we would bail out early in xdg_toplevel_role_commit() if no
geometry change was set, ignoring the possible min/max size hints
changes.

But setting a min/max size hint without changing the geometry is
perfectly valid, so we ought to apply the min/max changes regardless of
a geometry change.
Comment 9 Jonas Ådahl 2017-05-10 08:06:15 UTC
Review of attachment 351509 [details] [review]:

With the style nit fixed, this lgtm.

::: src/wayland/meta-wayland-xdg-shell.c
@@ +1284,2 @@
                                                       0, 0);
+      if (!meta_rectangle_equal(&new_geometry, &priv->geometry))

style nit: space between _equal and (
Comment 10 Jonas Ådahl 2017-05-10 08:08:18 UTC
Review of attachment 351511 [details] [review]:

::: src/wayland/meta-wayland-xdg-shell.c
@@ +638,1 @@
       return;

Don't think we should return here; we'll still ignore the new min/max. The comment about dx/dy is that we don't handle the resize, which is handled in the other if branch already, so no need to early out.
Comment 11 Olivier Fourdan 2017-05-10 08:17:43 UTC
Created attachment 351513 [details] [review]
[PATCH 2/2 v2] wayland: Apply size hints regardless of geometry

v2: don't return
Comment 12 Jonas Ådahl 2017-05-10 08:18:19 UTC
Review of attachment 351513 [details] [review]:

lgtm.
Comment 13 Olivier Fourdan 2017-05-10 08:33:14 UTC
Thanks for the reviews!

I guess those are fine to backport in gnome-3-22 branch as well, right?
Comment 14 Jonas Ådahl 2017-05-10 08:41:15 UTC
(In reply to Olivier Fourdan from comment #13)
> Thanks for the reviews!
> 
> I guess those are fine to backport in gnome-3-22 branch as well, right?

Sounds reasonable.
Comment 15 Olivier Fourdan 2017-05-10 08:52:38 UTC
Comment on attachment 351509 [details] [review]
[PATCH 1/2] wayland: Make sure we have a pending geometry

attachment 351509 [details] [review] pushed to git master as commit 410d66c - wayland: Make sure we have a pending geometry

attachment 351509 [details] [review] pushed to branch gnome-3-22 as commit ca31a94 - wayland: Make sure we have a pending geometry
Comment 16 Olivier Fourdan 2017-05-10 08:53:29 UTC
Comment on attachment 351513 [details] [review]
[PATCH 2/2 v2] wayland: Apply size hints regardless of geometry

attachment 351513 [details] [review] pushed to git master as commit f241bdb - wayland: Apply size hints regardless of geometry

attachment 351513 [details] [review] pushed to branch gnome-3-22 as commit 40a3d67 - wayland: Apply size hints regardless of geometry