compositor: drop role object NULL checks in handlers

Instead, move the check to the caller.
This commit is contained in:
Kirill Primak 2022-11-06 13:54:24 +03:00
parent 32daa43a45
commit 099b9de752
8 changed files with 6 additions and 62 deletions

View file

@ -360,9 +360,6 @@ static void drag_handle_drag_source_destroy(struct wl_listener *listener,
static void drag_icon_surface_role_commit(struct wlr_surface *surface) {
assert(surface->role == &drag_icon_surface_role);
struct wlr_drag_icon *icon = surface->role_data;
if (icon == NULL) {
return;
}
drag_icon_set_mapped(icon, wlr_surface_has_buffer(surface));
}
@ -370,9 +367,7 @@ static void drag_icon_surface_role_commit(struct wlr_surface *surface) {
static void drag_icon_surface_role_destroy(struct wlr_surface *surface) {
assert(surface->role == &drag_icon_surface_role);
struct wlr_drag_icon *icon = surface->role_data;
if (icon == NULL) {
return;
}
drag_icon_set_mapped(icon, false);
wl_signal_emit_mutable(&icon->events.destroy, icon);
free(icon);

View file

@ -425,7 +425,7 @@ 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) {
if (surface->role_data != NULL && surface->role->precommit != NULL) {
surface->role->precommit(surface, next);
}
@ -484,7 +484,7 @@ static void surface_commit_state(struct wlr_surface *surface,
surface->pending.seq++;
}
if (surface->role && surface->role->commit) {
if (surface->role_data != NULL && surface->role->commit != NULL) {
surface->role->commit(surface);
}

View file

@ -149,9 +149,7 @@ static void popup_surface_set_mapped(
static void popup_surface_surface_role_commit(struct wlr_surface *surface) {
struct wlr_input_popup_surface_v2 *popup_surface = surface->role_data;
if (popup_surface == NULL) {
return;
}
popup_surface_set_mapped(popup_surface, wlr_surface_has_buffer(surface)
&& popup_surface->input_method->client_active);
}
@ -159,9 +157,7 @@ static void popup_surface_surface_role_commit(struct wlr_surface *surface) {
static void popup_surface_surface_role_precommit(struct wlr_surface *surface,
const struct wlr_surface_state *state) {
struct wlr_input_popup_surface_v2 *popup_surface = surface->role_data;
if (popup_surface == NULL) {
return;
}
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
popup_surface_set_mapped(popup_surface, false);
@ -170,9 +166,7 @@ static void popup_surface_surface_role_precommit(struct wlr_surface *surface,
static void popup_surface_surface_role_destroy(struct wlr_surface *surface) {
struct wlr_input_popup_surface_v2 *popup_surface = surface->role_data;
if (popup_surface == NULL) {
return;
}
popup_surface_set_mapped(popup_surface, false);
wl_signal_emit_mutable(&popup_surface->events.destroy, NULL);
wl_list_remove(&popup_surface->link);

View file

@ -315,9 +315,6 @@ void wlr_layer_surface_v1_destroy(struct wlr_layer_surface_v1 *surface) {
static void layer_surface_role_commit(struct wlr_surface *wlr_surface) {
struct wlr_layer_surface_v1 *surface =
wlr_layer_surface_v1_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
const uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT |
ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
@ -370,9 +367,6 @@ 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 (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
@ -385,9 +379,6 @@ static void layer_surface_role_precommit(struct wlr_surface *wlr_surface,
static void layer_surface_role_destroy(struct wlr_surface *wlr_surface) {
struct wlr_layer_surface_v1 *surface =
wlr_layer_surface_v1_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
if (surface->configured && surface->mapped) {
layer_surface_unmap(surface);

View file

@ -135,9 +135,6 @@ static const struct ext_session_lock_surface_v1_interface lock_surface_implement
static void lock_surface_role_commit(struct wlr_surface *surface) {
struct wlr_session_lock_surface_v1 *lock_surface =
wlr_session_lock_surface_v1_from_wlr_surface(surface);
if (lock_surface == NULL) {
return;
}
if (!lock_surface->configured) {
wl_resource_post_error(lock_surface->resource,
@ -167,9 +164,6 @@ static void lock_surface_role_precommit(struct wlr_surface *surface,
const struct wlr_surface_state *state) {
struct wlr_session_lock_surface_v1 *lock_surface =
wlr_session_lock_surface_v1_from_wlr_surface(surface);
if (lock_surface == NULL) {
return;
}
if (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
wl_resource_post_error(lock_surface->resource,
@ -182,9 +176,6 @@ static void lock_surface_role_precommit(struct wlr_surface *surface,
static void lock_surface_role_destroy(struct wlr_surface *surface) {
struct wlr_session_lock_surface_v1 *lock_surface =
wlr_session_lock_surface_v1_from_wlr_surface(surface);
if (lock_surface == NULL) {
return;
}
wl_signal_emit_mutable(&lock_surface->events.destroy, NULL);

View file

@ -244,9 +244,6 @@ static void subsurface_unmap(struct wlr_subsurface *subsurface) {
static void subsurface_role_commit(struct wlr_surface *surface) {
struct wlr_subsurface *subsurface =
wlr_subsurface_from_wlr_surface(surface);
if (subsurface == NULL) {
return;
}
subsurface_consider_map(subsurface, true);
}
@ -255,9 +252,6 @@ 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 (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
@ -268,9 +262,6 @@ static void subsurface_role_precommit(struct wlr_surface *surface,
static void subsurface_role_destroy(struct wlr_surface *surface) {
struct wlr_subsurface *subsurface =
wlr_subsurface_from_wlr_surface(surface);
if (subsurface == NULL) {
return;
}
if (subsurface->has_cache) {
wlr_surface_unlock_cached(subsurface->surface,

View file

@ -285,9 +285,6 @@ static void xdg_surface_handle_surface_commit(struct wl_listener *listener,
void xdg_surface_role_commit(struct wlr_surface *wlr_surface) {
struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
surface->current = surface->pending;
@ -319,9 +316,6 @@ void xdg_surface_role_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 (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
@ -334,9 +328,6 @@ void xdg_surface_role_precommit(struct wlr_surface *wlr_surface,
void xdg_surface_role_destroy(struct wlr_surface *wlr_surface) {
struct wlr_xdg_surface *surface =
wlr_xdg_surface_from_wlr_surface(wlr_surface);
if (surface == NULL) {
return;
}
reset_xdg_surface(surface);

View file

@ -824,9 +824,6 @@ static void read_surface_property(struct wlr_xwm *xwm,
static void xwayland_surface_role_commit(struct wlr_surface *wlr_surface) {
assert(wlr_surface->role == &xwayland_surface_role);
struct wlr_xwayland_surface *surface = wlr_surface->role_data;
if (surface == NULL) {
return;
}
if (!surface->mapped && wlr_surface_has_buffer(surface->surface)) {
surface->mapped = true;
@ -839,9 +836,6 @@ 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 (state->committed & WLR_SURFACE_STATE_BUFFER && state->buffer == NULL) {
// This is a NULL commit
@ -856,9 +850,6 @@ static void xwayland_surface_role_precommit(struct wlr_surface *wlr_surface,
static void xwayland_surface_role_destroy(struct wlr_surface *wlr_surface) {
assert(wlr_surface->role == &xwayland_surface_role);
struct wlr_xwayland_surface *surface = wlr_surface->role_data;
if (surface == NULL) {
return;
}
if (surface->mapped) {
wl_signal_emit_mutable(&surface->events.unmap, surface);