From 5a18f62fee5f0a9c8abc1554222f3774179ff373 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 27 Dec 2017 06:06:29 -0500 Subject: [PATCH 1/5] add role-committed hook --- include/wlr/types/wlr_surface.h | 12 ++++++++++++ types/wlr_surface.c | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index c8e3761a..9f88d044 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -77,6 +77,10 @@ struct wlr_surface { struct wl_listener compositor_listener; void *compositor_data; + // surface commit callback for the role that runs before all others + void (*role_committed)(struct wlr_surface *surface, void *role_data); + void *role_data; + // subsurface properties struct wlr_subsurface *subsurface; struct wl_list subsurface_list; // wlr_subsurface::parent_link @@ -146,4 +150,12 @@ void wlr_surface_send_leave(struct wlr_surface *surface, void wlr_surface_send_frame_done(struct wlr_surface *surface, const struct timespec *when); +/** + * Set a callback for surface commit that runs before all the other callbacks. + * This is intended for use by the surface role. + */ +void wlr_surface_set_role_committed(struct wlr_surface *surface, + void (*role_committed)(struct wlr_surface *surface, void *role_data), + void *role_data); + #endif diff --git a/types/wlr_surface.c b/types/wlr_surface.c index ad0c6f68..8e024177 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -428,6 +428,10 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { } } + if (surface->role_committed) { + surface->role_committed(surface, surface->role_data); + } + // TODO: add the invalid bitfield to this callback wl_signal_emit(&surface->events.commit, surface); } @@ -943,3 +947,10 @@ void wlr_surface_send_frame_done(struct wlr_surface *surface, wl_resource_destroy(cb->resource); } } + +void wlr_surface_set_role_committed(struct wlr_surface *surface, + void (*role_committed)(struct wlr_surface *surface, void *role_data), + void *role_data) { + surface->role_committed = role_committed; + surface->role_data = role_data; +} From d5ffa26564289ac5c30337b358e0679960d4eef9 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 27 Dec 2017 06:15:25 -0500 Subject: [PATCH 2/5] xdg-shell: role-committed func --- include/wlr/types/wlr_xdg_shell_v6.h | 2 -- rootston/xdg_shell_v6.c | 2 +- types/wlr_xdg_shell_v6.c | 17 ++++++----------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index b723a950..280bea27 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -122,10 +122,8 @@ struct wlr_xdg_surface_v6 { struct wlr_box *geometry; struct wl_listener surface_destroy_listener; - struct wl_listener surface_commit_listener; struct { - struct wl_signal commit; struct wl_signal destroy; struct wl_signal ping_timeout; diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index a0503ad8..0515263b 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -253,7 +253,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { return; } roots_surface->commit.notify = handle_commit; - wl_signal_add(&surface->events.commit, &roots_surface->commit); + wl_signal_add(&surface->surface->events.commit, &roots_surface->commit); roots_surface->destroy.notify = handle_destroy; wl_signal_add(&surface->events.destroy, &roots_surface->destroy); roots_surface->request_move.notify = handle_request_move; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 23d36b6f..bb6c171c 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -209,7 +209,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); + wlr_surface_set_role_committed(surface->surface, NULL, NULL); free(surface->geometry); free(surface->next_geometry); free(surface->title); @@ -1047,10 +1047,9 @@ static void wlr_xdg_surface_v6_popup_committed( } } -static void handle_wlr_surface_committed(struct wl_listener *listener, - void *data) { - struct wlr_xdg_surface_v6 *surface = - wl_container_of(listener, surface, surface_commit_listener); +static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, + void *role_data) { + struct wlr_xdg_surface_v6 *surface = role_data; if (wlr_surface_has_buffer(surface->surface) && !surface->configured) { wl_resource_post_error(surface->resource, @@ -1085,8 +1084,6 @@ static void handle_wlr_surface_committed(struct wl_listener *listener, surface->added = true; wl_signal_emit(&surface->client->shell->events.new_surface, surface); } - - wl_signal_emit(&surface->events.commit, surface); } static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, @@ -1148,7 +1145,6 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, wl_signal_init(&surface->events.request_move); wl_signal_init(&surface->events.request_resize); wl_signal_init(&surface->events.request_show_window_menu); - wl_signal_init(&surface->events.commit); wl_signal_init(&surface->events.destroy); wl_signal_init(&surface->events.ping_timeout); @@ -1156,9 +1152,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client, &surface->surface_destroy_listener); surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed; - wl_signal_add(&surface->surface->events.commit, - &surface->surface_commit_listener); - surface->surface_commit_listener.notify = handle_wlr_surface_committed; + wlr_surface_set_role_committed(surface->surface, + handle_wlr_surface_committed, surface); wlr_log(L_DEBUG, "new xdg_surface %p (res %p)", surface, surface->resource); wl_resource_set_implementation(surface->resource, From 68328700c7171b53c70e61f78ed6fdfcf1e22bd5 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 27 Dec 2017 06:32:54 -0500 Subject: [PATCH 3/5] wl-shell: role committed --- include/wlr/types/wlr_wl_shell.h | 2 -- rootston/wl_shell.c | 2 +- types/wlr_wl_shell.c | 17 ++++++----------- 3 files changed, 7 insertions(+), 14 deletions(-) diff --git a/include/wlr/types/wlr_wl_shell.h b/include/wlr/types/wlr_wl_shell.h index 29446b04..375477c7 100644 --- a/include/wlr/types/wlr_wl_shell.h +++ b/include/wlr/types/wlr_wl_shell.h @@ -70,7 +70,6 @@ struct wlr_wl_shell_surface { char *class; struct wl_listener surface_destroy_listener; - struct wl_listener surface_commit_listener; struct wlr_wl_shell_surface *parent; struct wl_list popup_link; @@ -79,7 +78,6 @@ struct wlr_wl_shell_surface { struct { struct wl_signal destroy; - struct wl_signal commit; struct wl_signal ping_timeout; struct wl_signal request_move; diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index d0aad407..7f70acae 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -150,7 +150,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { roots_surface->set_state.notify = handle_set_state; wl_signal_add(&surface->events.set_state, &roots_surface->set_state); roots_surface->surface_commit.notify = handle_surface_commit; - wl_signal_add(&surface->events.commit, &roots_surface->surface_commit); + wl_signal_add(&surface->surface->events.commit, &roots_surface->surface_commit); struct roots_view *view = calloc(1, sizeof(struct roots_view)); if (!view) { diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index 5476ddb6..a13717c1 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -418,7 +418,7 @@ static void shell_surface_destroy(struct wlr_wl_shell_surface *surface) { wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); - wl_list_remove(&surface->surface_commit_listener.link); + wlr_surface_set_role_committed(surface->surface, NULL, NULL); wl_event_source_remove(surface->ping_timer); free(surface->transient_state); free(surface->title); @@ -439,10 +439,9 @@ static void handle_wlr_surface_destroyed(struct wl_listener *listener, wl_container_of(listener, surface, surface_destroy_listener); shell_surface_destroy(surface); } -static void handle_wlr_surface_committed(struct wl_listener *listener, - void *data) { - struct wlr_wl_shell_surface *surface = - wl_container_of(listener, surface, surface_commit_listener); +static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, + void *role_data) { + struct wlr_wl_shell_surface *surface = role_data; if (!surface->configured && wlr_surface_has_buffer(surface->surface) && surface->state != WLR_WL_SHELL_SURFACE_STATE_NONE) { @@ -459,8 +458,6 @@ static void handle_wlr_surface_committed(struct wl_listener *listener, surface->popup_state->seat); shell_pointer_grab_maybe_end(&grab->pointer_grab); } - - wl_signal_emit(&surface->events.commit, surface); } static int shell_surface_ping_timeout(void *user_data) { @@ -511,7 +508,6 @@ static void shell_protocol_get_shell_surface(struct wl_client *client, wl_surface->resource); wl_signal_init(&wl_surface->events.destroy); - wl_signal_init(&wl_surface->events.commit); wl_signal_init(&wl_surface->events.ping_timeout); wl_signal_init(&wl_surface->events.request_move); wl_signal_init(&wl_surface->events.request_resize); @@ -525,9 +521,8 @@ static void shell_protocol_get_shell_surface(struct wl_client *client, &wl_surface->surface_destroy_listener); wl_surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed; - wl_signal_add(&wl_surface->surface->events.commit, - &wl_surface->surface_commit_listener); - wl_surface->surface_commit_listener.notify = handle_wlr_surface_committed; + wlr_surface_set_role_committed(surface, handle_wlr_surface_committed, + wl_surface); struct wl_display *display = wl_client_get_display(client); struct wl_event_loop *loop = wl_display_get_event_loop(display); From e42d762a88dfa588eea336e5302a2653c81b61bd Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 27 Dec 2017 06:41:14 -0500 Subject: [PATCH 4/5] drag-icon: surface committed --- include/wlr/types/wlr_data_device.h | 1 - types/wlr_data_device.c | 13 ++++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/wlr/types/wlr_data_device.h b/include/wlr/types/wlr_data_device.h index 70d79a19..e0205101 100644 --- a/include/wlr/types/wlr_data_device.h +++ b/include/wlr/types/wlr_data_device.h @@ -72,7 +72,6 @@ struct wlr_drag_icon { } events; struct wl_listener surface_destroy; - struct wl_listener surface_commit; struct wl_listener seat_client_destroy; }; diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index c0399160..376c8304 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -651,7 +651,7 @@ static void wlr_drag_icon_destroy(struct wlr_drag_icon *icon) { return; } wl_signal_emit(&icon->events.destroy, icon); - wl_list_remove(&icon->surface_commit.link); + wlr_surface_set_role_committed(icon->surface, NULL, NULL); wl_list_remove(&icon->surface_destroy.link); wl_list_remove(&icon->seat_client_destroy.link); wl_list_remove(&icon->link); @@ -665,10 +665,9 @@ static void handle_drag_icon_surface_destroy(struct wl_listener *listener, wlr_drag_icon_destroy(icon); } -static void handle_drag_icon_surface_commit(struct wl_listener *listener, - void *data) { - struct wlr_drag_icon *icon = - wl_container_of(listener, icon, surface_commit); +static void handle_drag_icon_surface_commit(struct wlr_surface *surface, + void *role_data) { + struct wlr_drag_icon *icon = role_data; icon->sx += icon->surface->current->sx; icon->sy += icon->surface->current->sy; } @@ -701,8 +700,8 @@ static struct wlr_drag_icon *wlr_drag_icon_create( wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy); icon->surface_destroy.notify = handle_drag_icon_surface_destroy; - wl_signal_add(&icon->surface->events.commit, &icon->surface_commit); - icon->surface_commit.notify = handle_drag_icon_surface_commit; + wlr_surface_set_role_committed(icon->surface, + handle_drag_icon_surface_commit, icon); wl_signal_add(&client->events.destroy, &icon->seat_client_destroy); icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy; From 5c5f0611c418a39dc39e309679de25775caae030 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 27 Dec 2017 06:50:21 -0500 Subject: [PATCH 5/5] xwayland: role committed --- include/wlr/xwayland.h | 1 - xwayland/xwm.c | 14 +++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index acf04595..220b831c 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -133,7 +133,6 @@ struct wlr_xwayland_surface { } events; struct wl_listener surface_destroy; - struct wl_listener surface_commit; void *data; }; diff --git a/xwayland/xwm.c b/xwayland/xwm.c index 6cbe9bda..a642f164 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -220,7 +220,7 @@ static void wlr_xwayland_surface_destroy( if (xsurface->surface) { wl_list_remove(&xsurface->surface_destroy.link); - wl_list_remove(&xsurface->surface_commit.link); + wlr_surface_set_role_committed(xsurface->surface, NULL, NULL); } free(xsurface->title); @@ -515,9 +515,9 @@ static void read_surface_property(struct wlr_xwm *xwm, free(reply); } -static void handle_surface_commit(struct wl_listener *listener, void *data) { - struct wlr_xwayland_surface *xsurface = - wl_container_of(listener, xsurface, surface_commit); +static void handle_surface_commit(struct wlr_surface *wlr_surface, + void *role_data) { + struct wlr_xwayland_surface *xsurface = role_data; if (!xsurface->added && wlr_surface_has_buffer(xsurface->surface) && @@ -558,8 +558,8 @@ static void xwm_map_shell_surface(struct wlr_xwm *xwm, read_surface_property(xwm, xsurface, props[i]); } - xsurface->surface_commit.notify = handle_surface_commit; - wl_signal_add(&surface->events.commit, &xsurface->surface_commit); + wlr_surface_set_role_committed(xsurface->surface, handle_surface_commit, + xsurface); xsurface->surface_destroy.notify = handle_surface_destroy; wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy); @@ -690,7 +690,7 @@ static void xwm_handle_unmap_notify(struct wlr_xwm *xwm, } if (xsurface->surface) { - wl_list_remove(&xsurface->surface_commit.link); + wlr_surface_set_role_committed(xsurface->surface, NULL, NULL); wl_list_remove(&xsurface->surface_destroy.link); } xsurface->surface = NULL;