compositor: introduce wlr_surface_set_role_object()

master
Kirill Primak 1 year ago committed by Simon Ser
parent 0040c78c0b
commit 0f67580aab

@ -230,17 +230,22 @@ typedef void (*wlr_surface_iterator_func_t)(struct wlr_surface *surface,
int sx, int sy, void *data); int sx, int sy, void *data);
/** /**
* Set the lifetime role for this surface. Returns true on success or false if * Set the lifetime role for this surface.
* the role cannot be set.
* *
* If the role is represented by an object, role_data must be non-NULL. * If the surface already has a different role and/or has a role object set,
* Alternatively, if the role isn't represented by any object, role_data must * the function fails and sends an error to the client.
* be NULL. *
* Returns true on success, false otherwise.
*/ */
bool wlr_surface_set_role(struct wlr_surface *surface, bool wlr_surface_set_role(struct wlr_surface *surface, const struct wlr_surface_role *role,
const struct wlr_surface_role *role, void *role_data,
struct wl_resource *error_resource, uint32_t error_code); struct wl_resource *error_resource, uint32_t error_code);
/**
* Set the role object for this surface. The surface must have a role and
* no already set role object.
*/
void wlr_surface_set_role_object(struct wlr_surface *surface, void *role_data);
/** /**
* Destroy the object representing the surface's role. If it doesn't exist, * Destroy the object representing the surface's role. If it doesn't exist,
* this function is no-op. * this function is no-op.

@ -65,7 +65,7 @@ static void data_device_start_drag(struct wl_client *client,
struct wlr_surface *icon = NULL; struct wlr_surface *icon = NULL;
if (icon_resource) { if (icon_resource) {
icon = wlr_surface_from_resource(icon_resource); icon = wlr_surface_from_resource(icon_resource);
if (!wlr_surface_set_role(icon, &drag_icon_surface_role, NULL, if (!wlr_surface_set_role(icon, &drag_icon_surface_role,
icon_resource, WL_DATA_DEVICE_ERROR_ROLE)) { icon_resource, WL_DATA_DEVICE_ERROR_ROLE)) {
return; return;
} }
@ -102,7 +102,6 @@ static void data_device_handle_resource_destroy(struct wl_resource *resource) {
wl_list_init(wl_resource_get_link(resource)); wl_list_init(wl_resource_get_link(resource));
} }
static void device_resource_send_selection(struct wl_resource *device_resource) { static void device_resource_send_selection(struct wl_resource *device_resource) {
struct wlr_seat_client *seat_client = struct wlr_seat_client *seat_client =
seat_client_from_data_device_resource(device_resource); seat_client_from_data_device_resource(device_resource);

@ -96,7 +96,7 @@ static void pointer_set_cursor(struct wl_client *client,
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
if (surface_resource != NULL) { if (surface_resource != NULL) {
surface = wlr_surface_from_resource(surface_resource); surface = wlr_surface_from_resource(surface_resource);
if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role, NULL, if (!wlr_surface_set_role(surface, &pointer_cursor_surface_role,
surface_resource, WL_POINTER_ERROR_ROLE)) { surface_resource, WL_POINTER_ERROR_ROLE)) {
return; return;
} }

@ -41,7 +41,7 @@ static void handle_tablet_tool_v2_set_cursor(struct wl_client *client,
struct wlr_surface *surface = NULL; struct wlr_surface *surface = NULL;
if (surface_resource != NULL) { if (surface_resource != NULL) {
surface = wlr_surface_from_resource(surface_resource); surface = wlr_surface_from_resource(surface_resource);
if (!wlr_surface_set_role(surface, &tablet_tool_cursor_surface_role, NULL, if (!wlr_surface_set_role(surface, &tablet_tool_cursor_surface_role,
surface_resource, ZWP_TABLET_TOOL_V2_ERROR_ROLE)) { surface_resource, ZWP_TABLET_TOOL_V2_ERROR_ROLE)) {
return; return;
} }

@ -765,11 +765,9 @@ void wlr_surface_unmap(struct wlr_surface *surface) {
} }
} }
bool wlr_surface_set_role(struct wlr_surface *surface, bool wlr_surface_set_role(struct wlr_surface *surface, const struct wlr_surface_role *role,
const struct wlr_surface_role *role, void *role_data,
struct wl_resource *error_resource, uint32_t error_code) { struct wl_resource *error_resource, uint32_t error_code) {
assert(role != NULL); assert(role != NULL);
assert((role_data == NULL) == role->no_object);
if (surface->role != NULL && surface->role != role) { if (surface->role != NULL && surface->role != role) {
if (error_resource != NULL) { if (error_resource != NULL) {
@ -780,7 +778,7 @@ bool wlr_surface_set_role(struct wlr_surface *surface,
} }
return false; return false;
} }
if (surface->role_data != NULL && surface->role_data != role_data) { if (surface->role_data != NULL) {
wl_resource_post_error(error_resource, error_code, wl_resource_post_error(error_resource, error_code,
"Cannot reassign role %s to wl_surface@%" PRIu32 ", role object still exists", "Cannot reassign role %s to wl_surface@%" PRIu32 ", role object still exists",
role->name, wl_resource_get_id(surface->resource)); role->name, wl_resource_get_id(surface->resource));
@ -788,10 +786,17 @@ bool wlr_surface_set_role(struct wlr_surface *surface,
} }
surface->role = role; surface->role = role;
surface->role_data = role_data;
return true; return true;
} }
void wlr_surface_set_role_object(struct wlr_surface *surface, void *role_data) {
assert(surface->role != NULL);
assert(!surface->role->no_object);
assert(surface->role_data == NULL);
assert(role_data != NULL);
surface->role_data = role_data;
}
void wlr_surface_destroy_role_object(struct wlr_surface *surface) { void wlr_surface_destroy_role_object(struct wlr_surface *surface) {
if (surface->role_data == NULL) { if (surface->role_data == NULL) {
return; return;

@ -191,30 +191,34 @@ static void im_get_input_popup_surface(struct wl_client *client,
return; return;
} }
struct wl_resource *popup_resource = wl_resource_create(
client, &zwp_input_popup_surface_v2_interface,
wl_resource_get_version(resource), id);
if (!popup_resource) {
wl_client_post_no_memory(client);
return;
}
struct wlr_input_popup_surface_v2 *popup_surface = struct wlr_input_popup_surface_v2 *popup_surface =
calloc(1, sizeof(struct wlr_input_popup_surface_v2)); calloc(1, sizeof(struct wlr_input_popup_surface_v2));
if (!popup_surface) { if (!popup_surface) {
wl_client_post_no_memory(client); wl_client_post_no_memory(client);
return; return;
} }
wl_resource_set_implementation(popup_resource, &input_popup_impl,
popup_surface, popup_resource_destroy);
struct wlr_surface *surface = wlr_surface_from_resource(surface_resource); struct wlr_surface *surface = wlr_surface_from_resource(surface_resource);
if (!wlr_surface_set_role(surface, &input_popup_surface_v2_role, if (!wlr_surface_set_role(surface, &input_popup_surface_v2_role,
popup_surface, resource, ZWP_INPUT_METHOD_V2_ERROR_ROLE)) { resource, ZWP_INPUT_METHOD_V2_ERROR_ROLE)) {
free(popup_surface); free(popup_surface);
return; return;
} }
struct wl_resource *popup_resource = wl_resource_create(
client, &zwp_input_popup_surface_v2_interface,
wl_resource_get_version(resource), id);
if (!popup_resource) {
free(popup_surface);
wl_client_post_no_memory(client);
return;
}
wl_resource_set_implementation(popup_resource, &input_popup_impl,
popup_surface, popup_resource_destroy);
wlr_surface_set_role_object(surface, popup_surface);
popup_surface->resource = popup_resource; popup_surface->resource = popup_resource;
popup_surface->input_method = input_method; popup_surface->input_method = input_method;
popup_surface->surface = surface; popup_surface->surface = surface;

@ -398,7 +398,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client,
return; return;
} }
if (!wlr_surface_set_role(wlr_surface, &layer_surface_role, surface, if (!wlr_surface_set_role(wlr_surface, &layer_surface_role,
client_resource, ZWLR_LAYER_SHELL_V1_ERROR_ROLE)) { client_resource, ZWLR_LAYER_SHELL_V1_ERROR_ROLE)) {
free(surface); free(surface);
return; return;
@ -444,6 +444,8 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client,
surface, surface->resource); surface, surface->resource);
wl_resource_set_implementation(surface->resource, wl_resource_set_implementation(surface->resource,
&layer_surface_implementation, surface, layer_surface_resource_destroy); &layer_surface_implementation, surface, layer_surface_resource_destroy);
wlr_surface_set_role_object(wlr_surface, surface);
} }
static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = { static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = {

@ -265,7 +265,7 @@ static void lock_handle_get_lock_surface(struct wl_client *client,
return; return;
} }
if (!wlr_surface_set_role(surface, &lock_surface_role, lock_surface, if (!wlr_surface_set_role(surface, &lock_surface_role,
lock_resource, EXT_SESSION_LOCK_V1_ERROR_ROLE)) { lock_resource, EXT_SESSION_LOCK_V1_ERROR_ROLE)) {
free(lock_surface); free(lock_surface);
return; return;
@ -274,6 +274,8 @@ static void lock_handle_get_lock_surface(struct wl_client *client,
lock_surface->resource = lock_surface_resource; lock_surface->resource = lock_surface_resource;
wl_resource_set_user_data(lock_surface_resource, lock_surface); wl_resource_set_user_data(lock_surface_resource, lock_surface);
wlr_surface_set_role_object(surface, lock_surface);
wl_list_insert(&lock->surfaces, &lock_surface->link); wl_list_insert(&lock->surfaces, &lock_surface->link);
lock_surface->output = output; lock_surface->output = output;

@ -317,7 +317,7 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
return; return;
} }
if (!wlr_surface_set_role(surface, &subsurface_role, subsurface, if (!wlr_surface_set_role(surface, &subsurface_role,
resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE)) { resource, WL_SUBCOMPOSITOR_ERROR_BAD_SURFACE)) {
free(subsurface); free(subsurface);
return; return;
@ -344,6 +344,8 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
wl_resource_set_implementation(subsurface->resource, wl_resource_set_implementation(subsurface->resource,
&subsurface_implementation, subsurface, subsurface_resource_destroy); &subsurface_implementation, subsurface, subsurface_resource_destroy);
wlr_surface_set_role_object(surface, subsurface);
wl_signal_init(&subsurface->events.destroy); wl_signal_init(&subsurface->events.destroy);
wl_signal_add(&surface->events.client_commit, wl_signal_add(&surface->events.client_commit,

@ -387,7 +387,7 @@ void create_xdg_popup(struct wlr_xdg_surface *surface,
} }
if (!wlr_surface_set_role(surface->surface, &xdg_popup_surface_role, if (!wlr_surface_set_role(surface->surface, &xdg_popup_surface_role,
surface, surface->resource, XDG_WM_BASE_ERROR_ROLE)) { surface->resource, XDG_WM_BASE_ERROR_ROLE)) {
return; return;
} }
@ -412,6 +412,8 @@ void create_xdg_popup(struct wlr_xdg_surface *surface,
&xdg_popup_implementation, surface->popup, &xdg_popup_implementation, surface->popup,
xdg_popup_handle_resource_destroy); xdg_popup_handle_resource_destroy);
wlr_surface_set_role_object(surface->surface, surface);
surface->role = WLR_XDG_SURFACE_ROLE_POPUP; surface->role = WLR_XDG_SURFACE_ROLE_POPUP;
wlr_xdg_positioner_rules_get_geometry( wlr_xdg_positioner_rules_get_geometry(

@ -482,7 +482,7 @@ const struct wlr_surface_role xdg_toplevel_surface_role = {
void create_xdg_toplevel(struct wlr_xdg_surface *surface, void create_xdg_toplevel(struct wlr_xdg_surface *surface,
uint32_t id) { uint32_t id) {
if (!wlr_surface_set_role(surface->surface, &xdg_toplevel_surface_role, if (!wlr_surface_set_role(surface->surface, &xdg_toplevel_surface_role,
surface, surface->resource, XDG_WM_BASE_ERROR_ROLE)) { surface->resource, XDG_WM_BASE_ERROR_ROLE)) {
return; return;
} }
@ -524,6 +524,8 @@ void create_xdg_toplevel(struct wlr_xdg_surface *surface,
&xdg_toplevel_implementation, surface->toplevel, &xdg_toplevel_implementation, surface->toplevel,
xdg_toplevel_handle_resource_destroy); xdg_toplevel_handle_resource_destroy);
wlr_surface_set_role_object(surface->surface, surface);
surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL; surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL;
} }

@ -111,7 +111,7 @@ static void shell_handle_get_xwayland_surface(struct wl_client *client,
return; return;
} }
if (!wlr_surface_set_role(surface, &xwl_surface_role, xwl_surface, if (!wlr_surface_set_role(surface, &xwl_surface_role,
shell_resource, XWAYLAND_SHELL_V1_ERROR_ROLE)) { shell_resource, XWAYLAND_SHELL_V1_ERROR_ROLE)) {
free(xwl_surface); free(xwl_surface);
return; return;
@ -131,6 +131,8 @@ static void shell_handle_get_xwayland_surface(struct wl_client *client,
wl_resource_set_implementation(xwl_surface->resource, &xwl_surface_impl, wl_resource_set_implementation(xwl_surface->resource, &xwl_surface_impl,
xwl_surface, xwl_surface_handle_resource_destroy); xwl_surface, xwl_surface_handle_resource_destroy);
wlr_surface_set_role_object(surface, xwl_surface);
wl_list_insert(&shell->surfaces, &xwl_surface->link); wl_list_insert(&shell->surfaces, &xwl_surface->link);
xwl_surface->surface_destroy.notify = xwl_surface_handle_surface_destroy; xwl_surface->surface_destroy.notify = xwl_surface_handle_surface_destroy;

Loading…
Cancel
Save