Whenever a shell surface is created, a corresponding managed_surface object will be created and tracked down down at the shell client level.
Every valid call to xdg_surface_set_title(), xdg_surface_present() or xdg_surface_present_from_event() will now fire the corresponding events ; managed_surface _activate() is also implemented but unused for now. Signed-off-by: Manuel Bachmann <[email protected]> --- clients/desktop-shell.c | 33 +++++++++++++++++++++++++++++++++ desktop-shell/shell.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/clients/desktop-shell.c b/clients/desktop-shell.c index c5baf52..3c63c28 100644 --- a/clients/desktop-shell.c +++ b/clients/desktop-shell.c @@ -56,6 +56,7 @@ struct desktop { struct unlock_dialog *unlock_dialog; struct task unlock_task; struct wl_list outputs; + struct wl_list managed_surfaces; struct window *grab_window; struct widget *grab_widget; @@ -68,6 +69,12 @@ struct desktop { int painted; }; +struct desktop_managed_surface { + struct managed_surface *managed_surface; + char *title; + struct wl_list link; +}; + struct surface { void (*configure)(void *data, struct desktop_shell *desktop_shell, @@ -952,12 +959,25 @@ managed_surface_title_changed(void *data, struct managed_surface *managed_surface, const char *title) { + struct desktop_managed_surface *mgsurf = data; + + if (mgsurf->title) + free(mgsurf->title); + + mgsurf->title = (title) ? xstrdup(title) : NULL; } static void managed_surface_removed(void *data, struct managed_surface *managed_surface) { + struct desktop_managed_surface *mgsurf = data; + + if (mgsurf->title) + free(mgsurf->title); + wl_list_remove(&mgsurf->link); + free(mgsurf); + managed_surface_destroy(managed_surface); } @@ -1050,6 +1070,18 @@ desktop_shell_add_managed_surface(void *data, struct managed_surface *managed_surface, const char *title) { + struct desktop *desktop = data; + struct desktop_managed_surface *mgsurf; + + mgsurf = xzalloc(sizeof *mgsurf); + mgsurf->managed_surface = managed_surface; + mgsurf->title = (title) ? xstrdup(title) : NULL; + + wl_list_insert(desktop->managed_surfaces.prev, &mgsurf->link); + + managed_surface_add_listener(managed_surface, + &managed_surface_listener, + mgsurf); } static const struct desktop_shell_listener listener = { @@ -1367,6 +1399,7 @@ int main(int argc, char *argv[]) desktop.unlock_task.run = unlock_dialog_finish; wl_list_init(&desktop.outputs); + wl_list_init(&desktop.managed_surfaces); config_file = weston_config_get_name_from_env(); desktop.config = weston_config_parse(config_file); diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c index e48d63d..7263044 100644 --- a/desktop-shell/shell.c +++ b/desktop-shell/shell.c @@ -105,6 +105,7 @@ struct shell_client; struct shell_surface { struct wl_resource *resource; + struct wl_resource *managed_surface; struct wl_signal destroy_signal; struct shell_client *owner; @@ -2249,6 +2250,8 @@ set_title(struct shell_surface *shsurf, const char *title) free(shsurf->title); shsurf->title = strdup(title); shsurf->surface->timeline.force_refresh = 1; + + managed_surface_send_title_changed(shsurf->managed_surface, title); } static void @@ -2681,6 +2684,16 @@ set_minimized(struct weston_surface *surface) } static void +present(struct shell_surface *shsurf, + bool from_event, uint32_t serial) +{ + if (shsurf->type == SHELL_SURFACE_TOPLEVEL) + managed_surface_send_presented(shsurf->managed_surface); + + /* TODO: handle the "from_event()"-with-serial case */ +} + +static void shell_surface_set_maximized(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) @@ -3512,6 +3525,13 @@ static void managed_surface_activate(struct wl_client *client, struct wl_resource *resource) { + struct shell_surface *shsurf = wl_resource_get_user_data(resource); + struct desktop_shell *shell = shell_surface_get_shell(shsurf); + struct weston_compositor *compositor = shell->compositor; + struct weston_seat *seat; + + wl_list_for_each(seat, &compositor->seat_list, link) + activate(shell, shsurf->surface, seat, true); } static void @@ -3533,6 +3553,8 @@ destroy_shell_surface(struct shell_surface *shsurf) wl_signal_emit(&shsurf->destroy_signal, shsurf); + managed_surface_send_removed(shsurf->managed_surface); + if (!wl_list_empty(&shsurf->popup.grab_link)) { remove_popup_grab(shsurf); } @@ -3635,6 +3657,7 @@ create_common_surface(struct shell_client *owner, void *shell, const struct weston_shell_client *client) { struct shell_surface *shsurf; + struct wl_client *shell_client; assert(surface->configure == NULL); @@ -3673,6 +3696,16 @@ create_common_surface(struct shell_client *owner, void *shell, shsurf->output = get_default_output(shsurf->shell->compositor); + shell_client = wl_resource_get_client(shsurf->shell->child.desktop_shell); + shsurf->managed_surface = wl_resource_create(shell_client, + &managed_surface_interface, 1, 0); + wl_resource_set_implementation(shsurf->managed_surface, + &managed_surface_implementation, + shsurf, NULL); + desktop_shell_send_add_managed_surface(shsurf->shell->child.desktop_shell, + shsurf->managed_surface, + shsurf->title); + wl_signal_init(&shsurf->destroy_signal); shsurf->surface_destroy_listener.notify = shell_handle_surface_destroy; wl_signal_add(&surface->destroy_signal, @@ -3945,6 +3978,9 @@ static void xdg_surface_present(struct wl_client *client, struct wl_resource *resource) { + struct shell_surface *shsurf = wl_resource_get_user_data(resource); + + present(shsurf, false, 0); } static void @@ -3952,6 +3988,9 @@ xdg_surface_present_from_event(struct wl_client *client, struct wl_resource *resource, uint32_t serial) { + struct shell_surface *shsurf = wl_resource_get_user_data(resource); + + present(shsurf, true, serial); } static const struct xdg_surface_interface xdg_surface_implementation = { -- 1.8.3.1 _______________________________________________ wayland-devel mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/wayland-devel
