[PATCH weston v6 41/73] libweston: create/find output by name
Pekka Paalanen
ppaalanen at gmail.com
Fri Feb 16 14:57:26 UTC 2018
From: Pekka Paalanen <pekka.paalanen at collabora.co.uk>
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 at collabora.co.uk>
---
libweston/compositor.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++--
libweston/compositor.h | 8 ++++++++
2 files changed, 62 insertions(+), 2 deletions(-)
diff --git a/libweston/compositor.c b/libweston/compositor.c
index c41c7233..3bc7a352 100644
--- a/libweston/compositor.c
+++ b/libweston/compositor.c
@@ -5717,6 +5717,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.
@@ -5737,8 +5790,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;
diff --git a/libweston/compositor.h b/libweston/compositor.h
index b67f03fa..a7a5c56a 100644
--- a/libweston/compositor.h
+++ b/libweston/compositor.h
@@ -2072,6 +2072,14 @@ weston_compositor_set_heads_changed_cb(struct weston_compositor *compositor,
weston_heads_changed_func_t cb);
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);
--
2.13.6
More information about the wayland-devel
mailing list