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.
This commit is contained in:
Kirill Primak 2022-01-13 14:08:54 +03:00
parent 617eb4fb93
commit 50827ed7f5
7 changed files with 20 additions and 18 deletions

View file

@ -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(

View file

@ -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 {

View file

@ -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 {

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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);