compositor: Split shell->attach into map and configure

The shell module only needs to deal with attach when it's either the initial
attach or when the attach changes the size of the surface.  In case of
initial attach, the shell needs to pick a position for the surface and a
place in the surface stack.  We split this case out as a new shell->map
callback.  The other case is split into the shell->configure callback,
where the shell may adjust the surface position or reject the new size.
This commit is contained in:
Kristian Høgsberg 2011-11-09 12:07:35 -05:00
parent 63ff706c0e
commit 32e24cc628
4 changed files with 56 additions and 31 deletions

View File

@ -1094,8 +1094,8 @@ surface_attach(struct wl_client *client,
struct wl_resource *buffer_resource, int32_t x, int32_t y) struct wl_resource *buffer_resource, int32_t x, int32_t y)
{ {
struct wlsc_surface *es = resource->data; struct wlsc_surface *es = resource->data;
struct wlsc_shell *shell = es->compositor->shell;
struct wl_buffer *buffer = buffer_resource->data; struct wl_buffer *buffer = buffer_resource->data;
int repick = 0;
if (es->buffer) { if (es->buffer) {
wlsc_buffer_post_release(es->buffer); wlsc_buffer_post_release(es->buffer);
@ -1108,23 +1108,15 @@ surface_attach(struct wl_client *client,
&es->buffer_destroy_listener.link); &es->buffer_destroy_listener.link);
if (es->visual == WLSC_NONE_VISUAL) { if (es->visual == WLSC_NONE_VISUAL) {
wl_list_insert(&es->compositor->surface_list, &es->link); shell->map(shell, es, buffer->width, buffer->height);
repick = 1; } else if (x != 0 || y != 0 ||
} es->width != buffer->width ||
es->height != buffer->height) {
if (x != 0 || y != 0 || shell->configure(shell, es, es->x + x, es->y + y,
es->width != buffer->width || es->height != buffer->height) {
wlsc_surface_configure(es, es->x + x, es->y + y,
buffer->width, buffer->height); buffer->width, buffer->height);
repick = 1;
} }
wlsc_buffer_attach(buffer, &es->surface); wlsc_buffer_attach(buffer, &es->surface);
es->compositor->shell->attach(es->compositor->shell, es);
if (repick)
wlsc_compositor_repick(es->compositor);
} }
static void static void

View File

@ -163,7 +163,11 @@ struct wlsc_shell {
struct wlsc_surface *es, struct wlsc_surface *es,
struct wlsc_input_device *device, uint32_t time); struct wlsc_input_device *device, uint32_t time);
void (*lock)(struct wlsc_shell *shell); void (*lock)(struct wlsc_shell *shell);
void (*attach)(struct wlsc_shell *shell, struct wlsc_surface *surface); void (*map)(struct wlsc_shell *shell, struct wlsc_surface *surface,
int32_t width, int32_t height);
void (*configure)(struct wlsc_shell *shell,
struct wlsc_surface *surface,
int32_t x, int32_t y, int32_t width, int32_t height);
void (*set_selection_focus)(struct wlsc_shell *shell, void (*set_selection_focus)(struct wlsc_shell *shell,
struct wl_selection *selection, struct wl_selection *selection,
struct wl_surface *surface, uint32_t time); struct wl_surface *surface, uint32_t time);

View File

@ -201,13 +201,9 @@ meego_tablet_zoom_run(struct meego_tablet_shell *shell,
return zoom; return zoom;
} }
/* FIXME: We should be handling map, not attach... Map is when the
* surface becomes visible, which is what we want to catch. Attach
* will happen whenever the surface changes. */
static void static void
meego_tablet_shell_attach(struct wlsc_shell *base, meego_tablet_shell_map(struct wlsc_shell *base, struct wlsc_surface *surface,
struct wlsc_surface *surface) int32_t width, int32_t height)
{ {
struct meego_tablet_shell *shell = struct meego_tablet_shell *shell =
container_of(base, struct meego_tablet_shell, shell); container_of(base, struct meego_tablet_shell, shell);
@ -234,6 +230,18 @@ meego_tablet_shell_attach(struct wlsc_shell *base,
shell->current_client->surface = surface; shell->current_client->surface = surface;
meego_tablet_zoom_run(shell, surface, 0.3, 1.0); meego_tablet_zoom_run(shell, surface, 0.3, 1.0);
} }
wl_list_insert(&shell->compositor->surface_list, &surface->link);
wlsc_surface_configure(surface, surface->x, surface->y, width, height);
}
static void
meego_tablet_shell_configure(struct wlsc_shell *base,
struct wlsc_surface *surface,
int32_t x, int32_t y,
int32_t width, int32_t height)
{
wlsc_surface_configure(surface, x, y, width, height);
} }
static void static void
@ -679,7 +687,8 @@ shell_init(struct wlsc_compositor *compositor)
compositor->shell = &shell->shell; compositor->shell = &shell->shell;
shell->shell.lock = meego_tablet_shell_lock; shell->shell.lock = meego_tablet_shell_lock;
shell->shell.attach = meego_tablet_shell_attach; shell->shell.map = meego_tablet_shell_map;
shell->shell.configure = meego_tablet_shell_configure;
shell->shell.set_selection_focus = shell->shell.set_selection_focus =
meego_tablet_shell_set_selection_focus; meego_tablet_shell_set_selection_focus;
launch_ux_daemon(shell); launch_ux_daemon(shell);

View File

@ -919,18 +919,37 @@ lock(struct wlsc_shell *shell)
} }
static void static void
attach(struct wlsc_shell *base, struct wlsc_surface *es) map(struct wlsc_shell *base,
struct wlsc_surface *surface, int32_t width, int32_t height)
{ {
struct wl_shell *shell = container_of(base, struct wl_shell, shell); struct wl_shell *shell = container_of(base, struct wl_shell, shell);
struct wlsc_compositor *compositor = shell->compositor; struct wlsc_compositor *compositor = shell->compositor;
if (es == shell->background) { /* Map background at the bottom of the stack, panel on top,
wl_list_remove(&es->link); everything else just below panel. */
wl_list_insert(compositor->surface_list.prev, &es->link); if (surface == shell->background)
} else if (es->map_type == WLSC_SURFACE_MAP_FULLSCREEN) { wl_list_insert(compositor->surface_list.prev, &surface->link);
es->x = (es->fullscreen_output->current->width - es->width) / 2; else if (surface == shell->panel)
es->y = (es->fullscreen_output->current->height - es->height) / 2; wl_list_insert(&compositor->surface_list, &surface->link);
else
wl_list_insert(&shell->panel->link, &surface->link);
wlsc_surface_configure(surface, surface->x, surface->y, width, height);
} }
static void
configure(struct wlsc_shell *shell, struct wlsc_surface *surface,
int32_t x, int32_t y, int32_t width, int32_t height)
{
struct wlsc_mode *current;
if (surface->map_type == WLSC_SURFACE_MAP_FULLSCREEN) {
current = surface->fullscreen_output->current;
x = (current->width - surface->width) / 2;
y = (current->height - surface->height) / 2;
}
wlsc_surface_configure(surface, x, y, width, height);
} }
static void static void
@ -1032,7 +1051,8 @@ shell_init(struct wlsc_compositor *ec)
shell->compositor = ec; shell->compositor = ec;
shell->shell.activate = activate; shell->shell.activate = activate;
shell->shell.lock = lock; shell->shell.lock = lock;
shell->shell.attach = attach; shell->shell.map = map;
shell->shell.configure = configure;
shell->shell.set_selection_focus = wlsc_selection_set_focus; shell->shell.set_selection_focus = wlsc_selection_set_focus;
if (wl_display_add_global(ec->wl_display, &wl_shell_interface, if (wl_display_add_global(ec->wl_display, &wl_shell_interface,