[PATCH 2/6] src/shell.c: register output->destroy_signal handler
Kristian Høgsberg
hoegsberg at gmail.com
Tue Oct 22 06:33:39 CEST 2013
On Thu, Oct 17, 2013 at 10:10:49AM +0800, Xiong Zhang wrote:
> setup_output_destroy_handler() deal with output created at
> drm backend initialize time.
> handle_output_create() deal with output created by hot plug handler
> output_destroy_handler is removed when output was unplugged or shell is
> destroyed.
This looks good, but I think we want to just call it struct
shell_output instead of struct output_destroy_listener. Once we start
adding fields to this struct it will be the shell_output object,
similar to how we have shell_surface for wl_surface.
Kristian
> Signed-off-by: Xiong Zhang <xiong.y.zhang at intel.com>
> ---
> src/shell.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 75 insertions(+)
>
> diff --git a/src/shell.c b/src/shell.c
> index f033e8c..5ff27e7 100644
> --- a/src/shell.c
> +++ b/src/shell.c
> @@ -85,6 +85,13 @@ struct input_panel_surface {
> uint32_t panel;
> };
>
> +struct output_destroy_listener {
> + struct desktop_shell *shell;
> + struct weston_output *output;
> + struct wl_listener destroy_listener;
> + struct wl_list link;
> +};
> +
> struct desktop_shell {
> struct weston_compositor *compositor;
>
> @@ -163,6 +170,9 @@ struct desktop_shell {
>
> uint32_t binding_modifier;
> enum animation_type win_animation_type;
> +
> + struct wl_listener output_create_listener;
> + struct wl_list output_destroy_listener_list;
> };
>
> enum shell_surface_type {
> @@ -4461,11 +4471,65 @@ workspace_move_surface_down_binding(struct weston_seat *seat, uint32_t time,
> }
>
> static void
> +handle_output_destroy(struct wl_listener *listener, void *data)
> +{
> + struct output_destroy_listener *output_listener =
> + container_of(listener, struct output_destroy_listener, destroy_listener);
> +
> + wl_list_remove(&output_listener->destroy_listener.link);
> + wl_list_remove(&output_listener->link);
> + free(output_listener);
> +}
> +
> +static void
> +create_output_destroy_listener(struct desktop_shell *shell,
> + struct weston_output *output)
> +{
> + struct output_destroy_listener *output_listener;
> +
> + output_listener = malloc(sizeof(*output_listener));
> + memset(output_listener, 0, sizeof(*output_listener));
> + output_listener->output = output;
> + output_listener->shell = shell;
> + output_listener->destroy_listener.notify = handle_output_destroy;
> + wl_signal_add(&output->destroy_signal,
> + &output_listener->destroy_listener);
> + wl_list_insert(shell->output_destroy_listener_list.prev,
> + &output_listener->link);
> +}
> +
> +static void
> +handle_output_create(struct wl_listener *listener, void *data)
> +{
> + struct desktop_shell *shell =
> + container_of(listener, struct desktop_shell, output_create_listener);
> + struct weston_output *output = (struct weston_output *)data;
> +
> + create_output_destroy_listener(shell, output);
> +}
> +
> +static void
> +setup_output_destroy_handler(struct weston_compositor *ec,
> + struct desktop_shell *shell)
> +{
> + struct weston_output *output;
> +
> + wl_list_init(&shell->output_destroy_listener_list);
> + wl_list_for_each(output, &ec->output_list, link)
> + create_output_destroy_listener(shell, output);
> +
> + shell->output_create_listener.notify = handle_output_create;
> + wl_signal_add(&ec->output_created_signal,
> + &shell->output_create_listener);
> +}
> +
> +static void
> shell_destroy(struct wl_listener *listener, void *data)
> {
> struct desktop_shell *shell =
> container_of(listener, struct desktop_shell, destroy_listener);
> struct workspace **ws;
> + struct output_destroy_listener *output_listener, *tmp;
>
> if (shell->child.client)
> wl_client_destroy(shell->child.client);
> @@ -4475,6 +4539,15 @@ shell_destroy(struct wl_listener *listener, void *data)
> wl_list_remove(&shell->show_input_panel_listener.link);
> wl_list_remove(&shell->hide_input_panel_listener.link);
>
> + wl_list_for_each_safe(output_listener, tmp, &shell->output_destroy_listener_list,
> + link) {
> + wl_list_remove(&output_listener->destroy_listener.link);
> + wl_list_remove(&output_listener->link);
> + free(output_listener);
> + }
> +
> + wl_list_remove(&shell->output_create_listener.link);
> +
> wl_array_for_each(ws, &shell->workspaces.array)
> workspace_destroy(*ws);
> wl_array_release(&shell->workspaces.array);
> @@ -4647,6 +4720,8 @@ module_init(struct weston_compositor *ec,
>
> shell->child.deathstamp = weston_compositor_get_time();
>
> + setup_output_destroy_handler(ec, shell);
> +
> loop = wl_display_get_event_loop(ec->wl_display);
> wl_event_loop_add_idle(loop, launch_desktop_shell_process, shell);
>
> --
> 1.8.3.2
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list