view: unconditionally center views in output layout

Whatever type or dimensions of a view, position it at center of the
output layout. Then, if it is a primary view or if it extends the output
layout, send request to maximize it.
The client may or may not change the view dimensions after that.
If not, e.g. weston-flower, the view will be kept displayed at center
instead of to left.
If so, the view will expand from center to fill the whole output layout.

In order to update the view position, XDG shell surface commit is now
handled to check for dimension change.
This commit is contained in:
Jonathan GUILLOT 2024-02-05 17:35:51 +01:00
parent e7d8780f46
commit 560e9ff3ef
4 changed files with 33 additions and 31 deletions

View file

@ -183,15 +183,34 @@ handle_xdg_shell_surface_unmap(struct wl_listener *listener, void *data)
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, unmap);
struct cg_view *view = &xdg_shell_view->view;
wl_list_remove(&xdg_shell_view->commit.link);
view_unmap(view);
}
static void
handle_xdg_shell_surface_commit(struct wl_listener *listener, void *data)
{
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, commit);
struct cg_view *view = &xdg_shell_view->view;
// Check if view dimensions have changed
int width, height;
get_geometry(view, &width, &height);
if (width != view->width || height != view->height) {
view_position(view);
}
}
static void
handle_xdg_shell_surface_map(struct wl_listener *listener, void *data)
{
struct cg_xdg_shell_view *xdg_shell_view = wl_container_of(listener, xdg_shell_view, map);
struct cg_view *view = &xdg_shell_view->view;
xdg_shell_view->commit.notify = handle_xdg_shell_surface_commit;
wl_signal_add(&xdg_shell_view->xdg_toplevel->base->surface->events.commit, &xdg_shell_view->commit);
view_map(view, xdg_shell_view->xdg_toplevel->base->surface);
}