libweston: Add shell_private data

Shells need to find their own internal structures for weston_outputs.
Let's make that process trivial instead of a list walk.

Add a getter and setter for this private data and use it from the kiosk
shell.

Signed-off-by: Derek Foreman <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2025-02-27 11:01:15 -06:00 committed by Marius Vlad
parent 5ab5582981
commit 77dcbe381f
5 changed files with 59 additions and 23 deletions

View file

@ -558,6 +558,8 @@ struct weston_output {
uint32_t id;
char *name;
void *shell_private;
struct weston_backend *backend;
/** Matches the lifetime from the user perspective */

View file

@ -75,6 +75,13 @@ weston_shell_utils_curtain_destroy(struct weston_curtain *curtain);
enum weston_layer_position
weston_shell_utils_view_get_layer_position(struct weston_view *view);
void
weston_output_set_shell_private(struct weston_output *output,
void *private_data);
void *
weston_output_get_shell_private(struct weston_output *output);
#ifdef __cplusplus
}
#endif

View file

@ -147,9 +147,6 @@ kiosk_shell_output_set_active_surface_tree(struct kiosk_shell_output *shoutput,
static void
kiosk_shell_output_raise_surface_subtree(struct kiosk_shell_output *shoutput,
struct kiosk_shell_surface *shroot);
static struct kiosk_shell_output *
kiosk_shell_find_shell_output(struct kiosk_shell *shell,
struct weston_output *output);
static void
kiosk_shell_surface_notify_parent_destroy(struct wl_listener *listener, void *data)
@ -271,12 +268,11 @@ kiosk_shell_surface_find_best_output(struct kiosk_shell_surface *shsurf)
output = weston_shell_utils_get_focused_output(shsurf->shell->compositor);
if (output)
return kiosk_shell_find_shell_output(shsurf->shell,
output);
return weston_output_get_shell_private(output);
output = weston_shell_utils_get_default_output(shsurf->shell->compositor);
if (output)
return kiosk_shell_find_shell_output(shsurf->shell,
output);
return weston_output_get_shell_private(output);
return NULL;
}
@ -824,6 +820,8 @@ kiosk_shell_output_create(struct kiosk_shell *shell, struct weston_output *outpu
wl_list_insert(shell->output_list.prev, &shoutput->link);
weston_output_set_shell_private(output, shoutput);
kiosk_shell_output_recreate_background(shoutput);
kiosk_shell_output_configure(shoutput);
@ -1136,7 +1134,7 @@ desktop_surface_fullscreen_requested(struct weston_desktop_surface *desktop_surf
struct kiosk_shell_surface *shsurf =
weston_desktop_surface_get_user_data(desktop_surface);
struct kiosk_shell_output *shoutput =
kiosk_shell_find_shell_output(shsurf->shell, output);
weston_output_get_shell_private(output);
/* We should normally be able to ignore fullscreen requests for
* top-level surfaces, since we set them as fullscreen at creation
* time. However, xwayland surfaces set their internal WM state
@ -1234,20 +1232,6 @@ static const struct weston_desktop_api kiosk_shell_desktop_api = {
* kiosk_shell
*/
static struct kiosk_shell_output *
kiosk_shell_find_shell_output(struct kiosk_shell *shell,
struct weston_output *output)
{
struct kiosk_shell_output *shoutput;
wl_list_for_each(shoutput, &shell->output_list, link) {
if (shoutput->output == output)
return shoutput;
}
return NULL;
}
static void
kiosk_shell_activate_view(struct kiosk_shell *shell,
struct weston_view *view,
@ -1336,7 +1320,7 @@ kiosk_shell_handle_output_resized(struct wl_listener *listener, void *data)
container_of(listener, struct kiosk_shell, output_resized_listener);
struct weston_output *output = data;
struct kiosk_shell_output *shoutput =
kiosk_shell_find_shell_output(shell, output);
weston_output_get_shell_private(output);
struct weston_view *view;
kiosk_shell_output_recreate_background(shoutput);

View file

@ -8194,6 +8194,7 @@ weston_output_init(struct weston_output *output,
{
struct weston_color_manager *cm;
output->shell_private = NULL;
output->pos.c = weston_coord(0, 0);
output->compositor = compositor;
output->destroying = 0;

View file

@ -261,3 +261,45 @@ weston_shell_utils_view_get_layer_position(struct weston_view *view)
return view->layer_link.layer->position;
}
/** Assign shell private data to an output
*
* Shells will have their own private structures for output management.
* Some callbacks will provide a weston_output to the shell, and the
* shell will need to map that to its internal abstraction. Allow the
* shell to assign private data to an output to make this mapping easier.
*
* This can only be done once for an output.
*
* \param output The output to assign private data to
* \param private_data The shell private data
*
* \ingroup shell-utils
*/
WL_EXPORT void
weston_output_set_shell_private(struct weston_output *output,
void *private_data)
{
assert(!output->shell_private);
output->shell_private = private_data;
}
/** Get private data for an output
*
* Allows the shell to retreive the private data it set for an output.
* The shell must have set private data previously, or an assert() is
* generated.
*
* \param output The output to get private data for
* \return The private data
*
* \ingroup shell-utils
*/
WL_EXPORT void *
weston_output_get_shell_private(struct weston_output *output)
{
assert(output->shell_private);
return output->shell_private;
}