[PATCH 2/3] Add an id field to outputs

cdahlin at redhat.com cdahlin at redhat.com
Thu Apr 19 19:50:08 PDT 2012


From: Casey Dahlin <cdahlin at redhat.com>

All outputs now have a unique integer ID, allocated from a bitfield pool in the
compositor.

Signed-off-by: Casey Dahlin <cdahlin at redhat.com>
---
 src/compositor.c |   15 +++++++++++++++
 src/compositor.h |    4 ++++
 2 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/src/compositor.c b/src/compositor.c
index 3065f81..798b1e1 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2303,6 +2303,17 @@ weston_output_move(struct weston_output *output, int x, int y)
 				  output->current->height);
 }
 
+static void
+output_allocate_id(struct weston_output *output)
+{
+	output->id = 0;
+
+	while ((1 << output->id) & output->compositor->output_id_pool)
+		output->id++;
+
+	output->compositor->output_id_pool |= 1 << output->id;
+}
+
 WL_EXPORT void
 weston_output_init(struct weston_output *output, struct weston_compositor *c,
 		   int x, int y, int width, int height, uint32_t flags)
@@ -2331,6 +2342,8 @@ weston_output_init(struct weston_output *output, struct weston_compositor *c,
 
 	wl_list_init(&output->frame_callback_list);
 
+	output_allocate_id(output);
+
 	output->global =
 		wl_display_add_global(c->wl_display, &wl_output_interface,
 				      output, bind_output);
@@ -2359,6 +2372,8 @@ weston_compositor_init(struct weston_compositor *ec, struct wl_display *display)
 	wl_signal_init(&ec->unlock_signal);
 	ec->launcher_sock = weston_environment_get_fd("WESTON_LAUNCHER_SOCK");
 
+	ec->output_id_pool = 0;
+
 	if (!wl_display_add_global(display, &wl_compositor_interface,
 				   ec, compositor_bind))
 		return -1;
diff --git a/src/compositor.h b/src/compositor.h
index 93284c5..183c4e7 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -73,6 +73,8 @@ enum dpms_enum {
 };
 
 struct weston_output {
+	uint32_t id;
+
 	struct wl_list link;
 	struct wl_global *global;
 	struct weston_compositor *compositor;
@@ -234,6 +236,8 @@ struct weston_compositor {
 
 	struct screenshooter *screenshooter;
 	int launcher_sock;
+
+	uint32_t output_id_pool;
 };
 
 #define MODIFIER_CTRL	(1 << 8)
-- 
1.7.7.6



More information about the wayland-devel mailing list