Skip to content
This repository has been archived by the owner on Nov 1, 2021. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
rootston: xdg-shell*: Fix get_size() for newly-mapped views
The user-visible issue is that newly-mapped xdg-shell* windows would
sometimes start with their top-left-corner, rather than their center, in
the center of the screen. This is because get_size() would
conservatively fall back on (width, height) == (0, 0) if both
set_window_geometry() had not been called, and it found
view->wlr_surface to be NULL.

But, view->wlr_surface is only set to non-NULL in view_map(). We call
get_size() before this. Fortunately, the wlr_surface in question is
accessible via view->xdg_shell{,_v6}->surface, so always fall back on
that. We can assert its presence instead of further falling back on
(width, height) == (0, 0).

Signed-off-by: Genki Sky <sky@genki.is>
  • Loading branch information
Genki Sky authored and ddevault committed May 31, 2018
1 parent d1cf9ac commit 32013ab
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions rootston/xdg_shell.c
Expand Up @@ -135,11 +135,10 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) {
if (surface->geometry.width > 0 && surface->geometry.height > 0) {
box->width = surface->geometry.width;
box->height = surface->geometry.height;
} else if (view->wlr_surface != NULL) {
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
} else {
box->width = box->height = 0;
assert(surface->surface);
box->width = surface->surface->current->width;
box->height = surface->surface->current->height;
}
}

Expand Down
7 changes: 3 additions & 4 deletions rootston/xdg_shell_v6.c
Expand Up @@ -136,11 +136,10 @@ static void get_size(const struct roots_view *view, struct wlr_box *box) {
if (surface->geometry.width > 0 && surface->geometry.height > 0) {
box->width = surface->geometry.width;
box->height = surface->geometry.height;
} else if (view->wlr_surface != NULL) {
box->width = view->wlr_surface->current->width;
box->height = view->wlr_surface->current->height;
} else {
box->width = box->height = 0;
assert(surface->surface);
box->width = surface->surface->current->width;
box->height = surface->surface->current->height;
}
}

Expand Down

3 comments on commit 32013ab

@emersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We call get_size() before this.

Since we now assert, it means we crash instead?

@ddevault
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that it's obtaining the surface reference through a different mechanism, which should always be set here.

@emersion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then this doesn't change anything, this commit is a no-op. If the wlr_surface is unmapped, width == height == 0.

Please sign in to comment.