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 reset_xdg_surface(struct wlr_xdg_surface *xdg_surface);
void destroy_xdg_surface(struct wlr_xdg_surface *surface); void destroy_xdg_surface(struct wlr_xdg_surface *surface);
void handle_xdg_surface_commit(struct wlr_surface *wlr_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); void create_xdg_positioner(struct wlr_xdg_client *client, uint32_t id);
struct wlr_xdg_positioner_resource *get_xdg_positioner_from_resource( struct wlr_xdg_positioner_resource *get_xdg_positioner_from_resource(

View File

@ -73,7 +73,8 @@ struct wlr_surface_state {
struct wlr_surface_role { struct wlr_surface_role {
const char *name; const char *name;
void (*commit)(struct wlr_surface *surface); 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 { struct wlr_surface_output {

View File

@ -399,6 +399,10 @@ static void surface_commit_state(struct wlr_surface *surface,
struct wlr_surface_state *next) { struct wlr_surface_state *next) {
assert(next->cached_state_locks == 0); 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; bool invalid_buffer = next->committed & WLR_SURFACE_STATE_BUFFER;
surface->sx += next->dx; 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); 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)) { if (surface->pending.cached_state_locks > 0 || !wl_list_empty(&surface->cached)) {
surface_cache_pending(surface); surface_cache_pending(surface);
} else { } 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 = struct wlr_layer_surface_v1 *surface =
wlr_layer_surface_v1_from_wlr_surface(wlr_surface); wlr_layer_surface_v1_from_wlr_surface(wlr_surface);
if (surface == NULL) { if (surface == NULL) {
return; return;
} }
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER && if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
wlr_surface->pending.buffer == NULL) {
// This is a NULL commit // This is a NULL commit
if (surface->configured && surface->mapped) { if (surface->configured && surface->mapped) {
layer_surface_unmap(surface); layer_surface_unmap(surface);

View File

@ -280,15 +280,15 @@ static void subsurface_role_commit(struct wlr_surface *surface) {
subsurface_consider_map(subsurface, true); 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 = struct wlr_subsurface *subsurface =
wlr_subsurface_from_wlr_surface(surface); wlr_subsurface_from_wlr_surface(surface);
if (subsurface == NULL) { if (subsurface == NULL) {
return; return;
} }
if (surface->pending.committed & WLR_SURFACE_STATE_BUFFER && if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
surface->pending.buffer == NULL) {
// This is a NULL commit // This is a NULL commit
subsurface_unmap(subsurface); 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 = struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_wlr_surface(wlr_surface); wlr_xdg_surface_from_wlr_surface(wlr_surface);
if (surface == NULL) { if (surface == NULL) {
return; return;
} }
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER && if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
wlr_surface->pending.buffer == NULL) {
// This is a NULL commit // This is a NULL commit
if (surface->configured && surface->mapped) { if (surface->configured && surface->mapped) {
unmap_xdg_surface(surface); 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); assert(wlr_surface->role == &xwayland_surface_role);
struct wlr_xwayland_surface *surface = wlr_surface->role_data; struct wlr_xwayland_surface *surface = wlr_surface->role_data;
if (surface == NULL) { if (surface == NULL) {
return; return;
} }
if (wlr_surface->pending.committed & WLR_SURFACE_STATE_BUFFER && if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
wlr_surface->pending.buffer == NULL) {
// This is a NULL commit // This is a NULL commit
if (surface->mapped) { if (surface->mapped) {
wlr_signal_emit_safe(&surface->events.unmap, surface); wlr_signal_emit_safe(&surface->events.unmap, surface);