libweston: create/find output by name

To let users pick an arbitrary name for an output, to be used as e.g. a
configuration key, add API to create an output with a given name. For
the same configuration purpose, add a search function as well.

For the search function to be predictable, forbid creating multiple
outputs with the same name. Previously, creating multiple outputs with
the same name would have needed detatching to create outputs from the
same head, now that is forbidden.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Daniel Stone <daniels@collabora.com>
Acked-by: Derek Foreman <derekf@osg.samsung.com>
dev
Pekka Paalanen 7 years ago
parent 3e8f201878
commit 1ae9d08477
  1. 56
      libweston/compositor.c
  2. 8
      libweston/compositor.h

@ -5720,6 +5720,59 @@ weston_output_release(struct weston_output *output)
free(output->name);
}
/** Find an output by its given name
*
* \param compositor The compositor to search in.
* \param name The output name to search for.
* \return An existing output with the given name, or NULL if not found.
*
* \memberof weston_compositor
*/
WL_EXPORT struct weston_output *
weston_compositor_find_output_by_name(struct weston_compositor *compositor,
const char *name)
{
struct weston_output *output;
wl_list_for_each(output, &compositor->output_list, link)
if (strcmp(output->name, name) == 0)
return output;
wl_list_for_each(output, &compositor->pending_output_list, link)
if (strcmp(output->name, name) == 0)
return output;
return NULL;
}
/** Create a named output
*
* \param compositor The compositor.
* \param name The name for the output.
* \return A new \c weston_output, or NULL on failure.
*
* This creates a new weston_output that starts with no heads attached.
*
* An output must be configured and it must have at least one head before
* it can be enabled.
*
* \memberof weston_compositor
*/
WL_EXPORT struct weston_output *
weston_compositor_create_output(struct weston_compositor *compositor,
const char *name)
{
assert(compositor->backend->create_output);
if (weston_compositor_find_output_by_name(compositor, name)) {
weston_log("Warning: attempted to create an output with a "
"duplicate name '%s'.\n", name);
return NULL;
}
return compositor->backend->create_output(compositor, name);
}
/** Create an output for an unused head
*
* \param compositor The compositor.
@ -5740,8 +5793,7 @@ weston_compositor_create_output_with_head(struct weston_compositor *compositor,
{
struct weston_output *output;
assert(compositor->backend->create_output);
output = compositor->backend->create_output(compositor, head->name);
output = weston_compositor_create_output(compositor, head->name);
if (!output)
return NULL;

@ -2075,6 +2075,14 @@ void
weston_compositor_add_heads_changed_listener(struct weston_compositor *compositor,
struct wl_listener *listener);
struct weston_output *
weston_compositor_find_output_by_name(struct weston_compositor *compositor,
const char *name);
struct weston_output *
weston_compositor_create_output(struct weston_compositor *compositor,
const char *name);
struct weston_output *
weston_compositor_create_output_with_head(struct weston_compositor *compositor,
struct weston_head *head);

Loading…
Cancel
Save