From 9d2dc8447a64d0f402b309af5a655ce374dad808 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 12 Sep 2017 06:18:52 -0400 Subject: use wlr_surface on shell struct and listen to events --- examples/compositor.c | 2 +- include/wlr/types/wlr_xdg_shell_v6.h | 3 ++- types/wlr_xdg_shell_v6.c | 17 +++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/examples/compositor.c b/examples/compositor.c index 995c1b7d..9d96b053 100644 --- a/examples/compositor.c +++ b/examples/compositor.c @@ -102,7 +102,7 @@ static void handle_output_frame(struct output_state *output, struct wlr_xdg_surface_v6 *xdg_surface; wl_list_for_each(xdg_surface, &sample->xdg_shell->surfaces, link) { output_frame_handle_surface(sample, wlr_output, ts, - xdg_surface->surface); + xdg_surface->surface->resource); } struct wlr_x11_window *x11_window; wl_list_for_each(x11_window, &sample->xwayland->displayable_windows, link) { diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index 6bc37940..27fafd2d 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -18,11 +18,12 @@ enum wlr_xdg_surface_v6_role { struct wlr_xdg_surface_v6 { struct wl_resource *resource; - struct wl_resource *surface; + struct wlr_surface *surface; struct wl_list link; enum wlr_xdg_surface_v6_role role; struct wl_listener surface_destroy_listener; + struct wl_listener surface_commit_listener; void *data; }; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 2fff054d..70f22197 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -104,6 +104,7 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { wl_resource_set_user_data(surface->resource, NULL); wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); + wl_list_remove(&surface->surface_commit_listener.link); free(surface); } @@ -118,9 +119,8 @@ static void xdg_surface_get_toplevel(struct wl_client *client, struct wl_resource *resource, uint32_t id) { // TODO: Flesh out struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); - struct wlr_surface *wsurface = wl_resource_get_user_data(surface->surface); - if (wlr_surface_set_role(wsurface, wlr_desktop_xdg_toplevel_role, + if (wlr_surface_set_role(surface->surface, wlr_desktop_xdg_toplevel_role, resource, ZXDG_SHELL_V6_ERROR_ROLE)) { return; } @@ -173,6 +173,11 @@ static void handle_wlr_surface_destroyed(struct wl_listener *listener, xdg_surface_destroy(xdg_surface); } +static void handle_wlr_surface_committed(struct wl_listener *listener, + void *data) { + wlr_log(L_DEBUG, "TODO: handle wlr surface committed"); +} + static void xdg_shell_get_xdg_surface(struct wl_client *client, struct wl_resource *_xdg_shell, uint32_t id, struct wl_resource *_surface) { @@ -182,14 +187,18 @@ static void xdg_shell_get_xdg_surface(struct wl_client *client, return; } surface->role = WLR_XDG_SURFACE_V6_ROLE_NONE; - surface->surface = _surface; + surface->surface = wl_resource_get_user_data(_surface); surface->resource = wl_resource_create(client, &zxdg_surface_v6_interface, wl_resource_get_version(_xdg_shell), id); - wl_signal_add(&_surface->destroy_signal, + wl_signal_add(&surface->surface->signals.destroy, &surface->surface_destroy_listener); surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed; + wl_signal_add(&surface->surface->signals.commit, + &surface->surface_commit_listener); + surface->surface_commit_listener.notify = handle_wlr_surface_committed; + wlr_log(L_DEBUG, "new xdg_surface %p (res %p)", surface, surface->resource); wl_resource_set_implementation(surface->resource, &zxdg_surface_v6_implementation, surface, xdg_surface_resource_destroy); -- cgit v1.2.3