Merge pull request #524 from acrisci/role-committed

[wip] Role committed
This commit is contained in:
emersion 2017-12-27 13:02:49 +01:00 committed by GitHub
commit a79dc7df51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 50 additions and 44 deletions

View File

@ -73,7 +73,6 @@ struct wlr_drag_icon {
} events; } events;
struct wl_listener surface_destroy; struct wl_listener surface_destroy;
struct wl_listener surface_commit;
struct wl_listener seat_client_destroy; struct wl_listener seat_client_destroy;
}; };

View File

@ -77,6 +77,10 @@ struct wlr_surface {
struct wl_listener compositor_listener; struct wl_listener compositor_listener;
void *compositor_data; 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 // subsurface properties
struct wlr_subsurface *subsurface; struct wlr_subsurface *subsurface;
struct wl_list subsurface_list; // wlr_subsurface::parent_link 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, void wlr_surface_send_frame_done(struct wlr_surface *surface,
const struct timespec *when); 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 #endif

View File

@ -70,7 +70,6 @@ struct wlr_wl_shell_surface {
char *class; char *class;
struct wl_listener surface_destroy_listener; struct wl_listener surface_destroy_listener;
struct wl_listener surface_commit_listener;
struct wlr_wl_shell_surface *parent; struct wlr_wl_shell_surface *parent;
struct wl_list popup_link; struct wl_list popup_link;
@ -79,7 +78,6 @@ struct wlr_wl_shell_surface {
struct { struct {
struct wl_signal destroy; struct wl_signal destroy;
struct wl_signal commit;
struct wl_signal ping_timeout; struct wl_signal ping_timeout;
struct wl_signal request_move; struct wl_signal request_move;

View File

@ -122,10 +122,8 @@ struct wlr_xdg_surface_v6 {
struct wlr_box *geometry; struct wlr_box *geometry;
struct wl_listener surface_destroy_listener; struct wl_listener surface_destroy_listener;
struct wl_listener surface_commit_listener;
struct { struct {
struct wl_signal commit;
struct wl_signal destroy; struct wl_signal destroy;
struct wl_signal ping_timeout; struct wl_signal ping_timeout;

View File

@ -134,7 +134,6 @@ struct wlr_xwayland_surface {
} events; } events;
struct wl_listener surface_destroy; struct wl_listener surface_destroy;
struct wl_listener surface_commit;
void *data; void *data;
}; };

View File

@ -150,7 +150,7 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) {
roots_surface->set_state.notify = handle_set_state; roots_surface->set_state.notify = handle_set_state;
wl_signal_add(&surface->events.set_state, &roots_surface->set_state); wl_signal_add(&surface->events.set_state, &roots_surface->set_state);
roots_surface->surface_commit.notify = handle_surface_commit; 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)); struct roots_view *view = calloc(1, sizeof(struct roots_view));
if (!view) { if (!view) {

View File

@ -253,7 +253,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
return; return;
} }
roots_surface->commit.notify = handle_commit; 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; roots_surface->destroy.notify = handle_destroy;
wl_signal_add(&surface->events.destroy, &roots_surface->destroy); wl_signal_add(&surface->events.destroy, &roots_surface->destroy);
roots_surface->request_move.notify = handle_request_move; roots_surface->request_move.notify = handle_request_move;

View File

@ -651,7 +651,7 @@ static void wlr_drag_icon_destroy(struct wlr_drag_icon *icon) {
return; return;
} }
wl_signal_emit(&icon->events.destroy, icon); 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->surface_destroy.link);
wl_list_remove(&icon->seat_client_destroy.link); wl_list_remove(&icon->seat_client_destroy.link);
wl_list_remove(&icon->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); wlr_drag_icon_destroy(icon);
} }
static void handle_drag_icon_surface_commit(struct wl_listener *listener, static void handle_drag_icon_surface_commit(struct wlr_surface *surface,
void *data) { void *role_data) {
struct wlr_drag_icon *icon = struct wlr_drag_icon *icon = role_data;
wl_container_of(listener, icon, surface_commit);
icon->sx += icon->surface->current->sx; icon->sx += icon->surface->current->sx;
icon->sy += icon->surface->current->sy; 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); wl_signal_add(&icon->surface->events.destroy, &icon->surface_destroy);
icon->surface_destroy.notify = handle_drag_icon_surface_destroy; icon->surface_destroy.notify = handle_drag_icon_surface_destroy;
wl_signal_add(&icon->surface->events.commit, &icon->surface_commit); wlr_surface_set_role_committed(icon->surface,
icon->surface_commit.notify = handle_drag_icon_surface_commit; handle_drag_icon_surface_commit, icon);
wl_signal_add(&client->events.destroy, &icon->seat_client_destroy); wl_signal_add(&client->events.destroy, &icon->seat_client_destroy);
icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy; icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy;

View File

@ -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 // TODO: add the invalid bitfield to this callback
wl_signal_emit(&surface->events.commit, surface); 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); 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;
}

View File

@ -418,7 +418,7 @@ static void shell_surface_destroy(struct wlr_wl_shell_surface *surface) {
wl_list_remove(&surface->link); wl_list_remove(&surface->link);
wl_list_remove(&surface->surface_destroy_listener.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); wl_event_source_remove(surface->ping_timer);
free(surface->transient_state); free(surface->transient_state);
free(surface->title); 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); wl_container_of(listener, surface, surface_destroy_listener);
shell_surface_destroy(surface); shell_surface_destroy(surface);
} }
static void handle_wlr_surface_committed(struct wl_listener *listener, static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
void *data) { void *role_data) {
struct wlr_wl_shell_surface *surface = struct wlr_wl_shell_surface *surface = role_data;
wl_container_of(listener, surface, surface_commit_listener);
if (!surface->configured && if (!surface->configured &&
wlr_surface_has_buffer(surface->surface) && wlr_surface_has_buffer(surface->surface) &&
surface->state != WLR_WL_SHELL_SURFACE_STATE_NONE) { 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); surface->popup_state->seat);
shell_pointer_grab_maybe_end(&grab->pointer_grab); shell_pointer_grab_maybe_end(&grab->pointer_grab);
} }
wl_signal_emit(&surface->events.commit, surface);
} }
static int shell_surface_ping_timeout(void *user_data) { 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_surface->resource);
wl_signal_init(&wl_surface->events.destroy); 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.ping_timeout);
wl_signal_init(&wl_surface->events.request_move); wl_signal_init(&wl_surface->events.request_move);
wl_signal_init(&wl_surface->events.request_resize); 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);
wl_surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed; wl_surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed;
wl_signal_add(&wl_surface->surface->events.commit, wlr_surface_set_role_committed(surface, handle_wlr_surface_committed,
&wl_surface->surface_commit_listener); wl_surface);
wl_surface->surface_commit_listener.notify = handle_wlr_surface_committed;
struct wl_display *display = wl_client_get_display(client); struct wl_display *display = wl_client_get_display(client);
struct wl_event_loop *loop = wl_display_get_event_loop(display); struct wl_event_loop *loop = wl_display_get_event_loop(display);

View File

@ -210,7 +210,7 @@ static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) {
wl_resource_set_user_data(surface->resource, NULL); wl_resource_set_user_data(surface->resource, NULL);
wl_list_remove(&surface->link); wl_list_remove(&surface->link);
wl_list_remove(&surface->surface_destroy_listener.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->geometry);
free(surface->next_geometry); free(surface->next_geometry);
free(surface->title); free(surface->title);
@ -1048,10 +1048,9 @@ static void wlr_xdg_surface_v6_popup_committed(
} }
} }
static void handle_wlr_surface_committed(struct wl_listener *listener, static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface,
void *data) { void *role_data) {
struct wlr_xdg_surface_v6 *surface = struct wlr_xdg_surface_v6 *surface = role_data;
wl_container_of(listener, surface, surface_commit_listener);
if (wlr_surface_has_buffer(surface->surface) && !surface->configured) { if (wlr_surface_has_buffer(surface->surface) && !surface->configured) {
wl_resource_post_error(surface->resource, wl_resource_post_error(surface->resource,
@ -1086,8 +1085,6 @@ static void handle_wlr_surface_committed(struct wl_listener *listener,
surface->added = true; surface->added = true;
wl_signal_emit(&surface->client->shell->events.new_surface, surface); 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, static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
@ -1149,7 +1146,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_move);
wl_signal_init(&surface->events.request_resize); wl_signal_init(&surface->events.request_resize);
wl_signal_init(&surface->events.request_show_window_menu); 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.destroy);
wl_signal_init(&surface->events.ping_timeout); wl_signal_init(&surface->events.ping_timeout);
@ -1157,9 +1153,8 @@ static void xdg_shell_get_xdg_surface(struct wl_client *wl_client,
&surface->surface_destroy_listener); &surface->surface_destroy_listener);
surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed; surface->surface_destroy_listener.notify = handle_wlr_surface_destroyed;
wl_signal_add(&surface->surface->events.commit, wlr_surface_set_role_committed(surface->surface,
&surface->surface_commit_listener); handle_wlr_surface_committed, surface);
surface->surface_commit_listener.notify = handle_wlr_surface_committed;
wlr_log(L_DEBUG, "new xdg_surface %p (res %p)", surface, surface->resource); wlr_log(L_DEBUG, "new xdg_surface %p (res %p)", surface, surface->resource);
wl_resource_set_implementation(surface->resource, wl_resource_set_implementation(surface->resource,

View File

@ -222,7 +222,7 @@ static void wlr_xwayland_surface_destroy(
if (xsurface->surface) { if (xsurface->surface) {
wl_list_remove(&xsurface->surface_destroy.link); 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); free(xsurface->title);
@ -517,9 +517,9 @@ static void read_surface_property(struct wlr_xwm *xwm,
free(reply); free(reply);
} }
static void handle_surface_commit(struct wl_listener *listener, void *data) { static void handle_surface_commit(struct wlr_surface *wlr_surface,
struct wlr_xwayland_surface *xsurface = void *role_data) {
wl_container_of(listener, xsurface, surface_commit); struct wlr_xwayland_surface *xsurface = role_data;
if (!xsurface->added && if (!xsurface->added &&
wlr_surface_has_buffer(xsurface->surface) && wlr_surface_has_buffer(xsurface->surface) &&
@ -560,8 +560,8 @@ static void xwm_map_shell_surface(struct wlr_xwm *xwm,
read_surface_property(xwm, xsurface, props[i]); read_surface_property(xwm, xsurface, props[i]);
} }
xsurface->surface_commit.notify = handle_surface_commit; wlr_surface_set_role_committed(xsurface->surface, handle_surface_commit,
wl_signal_add(&surface->events.commit, &xsurface->surface_commit); xsurface);
xsurface->surface_destroy.notify = handle_surface_destroy; xsurface->surface_destroy.notify = handle_surface_destroy;
wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy); wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy);
@ -692,7 +692,7 @@ static void xwm_handle_unmap_notify(struct wlr_xwm *xwm,
} }
if (xsurface->surface) { 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); wl_list_remove(&xsurface->surface_destroy.link);
} }
xsurface->surface = NULL; xsurface->surface = NULL;