surface: improve role precommit hook

Now the role precommit hook is called before the commit, not on
wl_surface.commit request, and takes a state which is to be applied.
master
Kirill Primak 3 years ago
parent 617eb4fb93
commit 50827ed7f5

@ -20,7 +20,8 @@ void unmap_xdg_surface(struct wlr_xdg_surface *surface);
void reset_xdg_surface(struct wlr_xdg_surface *xdg_surface);
void destroy_xdg_surface(struct wlr_xdg_surface *surface);
void handle_xdg_surface_commit(struct wlr_surface *wlr_surface);
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface);
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state);
void create_xdg_positioner(struct wlr_xdg_client *client, uint32_t id);
struct wlr_xdg_positioner_resource *get_xdg_positioner_from_resource(

@ -73,7 +73,8 @@ struct wlr_surface_state {
struct wlr_surface_role {
const char *name;
void (*commit)(struct wlr_surface *surface);
void (*precommit)(struct wlr_surface *surface);
void (*precommit)(struct wlr_surface *surface,
const struct wlr_surface_state *state);
};
struct wlr_surface_output {

@ -399,6 +399,10 @@ static void surface_commit_state(struct wlr_surface *surface,
struct wlr_surface_state *next) {
assert(next->cached_state_locks == 0);
if (surface->role && surface->role->precommit) {
surface->role->precommit(surface, next);
}
bool invalid_buffer = next->committed & WLR_SURFACE_STATE_BUFFER;
surface->sx += next->dx;
@ -509,10 +513,6 @@ static void surface_handle_commit(struct wl_client *client,
wlr_signal_emit_safe(&surface->events.client_commit, NULL);
if (surface->role && surface->role->precommit) {
surface->role->precommit(surface);
}
if (surface->pending.cached_state_locks > 0 || !wl_list_empty(&surface->cached)) {
surface_cache_pending(surface);
} else {

@ -375,15 +375,15 @@ static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
}
}
static void layer_surface_role_precommit(struct wlr_surface *wlr_surface) {
static void layer_surface_role_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state) {
struct wlr_layer_surface_v1 *surface =
wlr_layer_surface_v1_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer == NULL) {
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
if (surface->configured && surface->mapped) {
layer_surface_unmap(surface);

@ -280,15 +280,15 @@ static void subsurface_role_commit(struct wlr_surface *surface) {
subsurface_consider_map(subsurface, true);
}
static void subsurface_role_precommit(struct wlr_surface *surface) {
static void subsurface_role_precommit(struct wlr_surface *surface,
const struct wlr_surface_state *state) {
struct wlr_subsurface *subsurface =
wlr_subsurface_from_wlr_surface(surface);
if (subsurface == NULL) {
return;
}
if (surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
surface->pending.buffer == NULL) {
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
subsurface_unmap(subsurface);
}

@ -338,15 +338,15 @@ void handle_xdg_surface_commit(struct wlr_surface *wlr_surface) {
}
}
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface) {
void handle_xdg_surface_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state) {
struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer == NULL) {
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
if (surface->configured && surface->mapped) {
unmap_xdg_surface(surface);

@ -852,15 +852,15 @@ static void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {
}
}
static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface) {
static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface,
const struct wlr_surface_state *state) {
assert(wlr_surface->role == &xwayland_surface_role);
struct wlr_xwayland_surface *surface = wlr_surface->role_data;
if (surface == NULL) {
return;
}
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER &&
wlr_surface->pending.buffer == NULL) {
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
if (surface->mapped) {
wlr_signal_emit_safe(&surface->events.unmap, surface);

Loading…
Cancel
Save