compositor: add weston_surface_set_label_func()
When printing out logs from Weston's actions, mainly for debugging, it
can be very difficult to identify the different surfaces. Inspecting
the configure function pointer is not useful, as the configure functions
may live in modules.
Add vfunc get_label to weston_surface, which will produce a short,
human-readable description of the surface, which allows identifying it
better, rather than just looking at the surface size, for instance.
Set the label function from most parts of Weston, to identify cursors and
drag icons, and panels, backgrounds, screensavers and lock surfaces, and
the desktop shell's application surfaces.
v2: renamed 'description' to 'label', so we get
weston_surface_set_label_func().
Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
diff --git a/src/compositor.c b/src/compositor.c
index 53f6220..af9022c 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -2724,6 +2724,12 @@
weston_subsurface_synchronized_commit(sub);
}
+static int
+subsurface_get_label(struct weston_surface *surface, char *buf, size_t len)
+{
+ return snprintf(buf, len, "sub-surface");
+}
+
static void
subsurface_configure(struct weston_surface *surface, int32_t dx, int32_t dy)
{
@@ -2807,6 +2813,14 @@
return -1;
}
+WL_EXPORT void
+weston_surface_set_label_func(struct weston_surface *surface,
+ int (*desc)(struct weston_surface *,
+ char *, size_t))
+{
+ surface->get_label = desc;
+}
+
static void
subsurface_set_position(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y)
@@ -3039,6 +3053,7 @@
sub->surface->configure = NULL;
sub->surface->configure_private = NULL;
+ weston_surface_set_label_func(sub->surface, NULL);
} else {
/* the dummy weston_subsurface for the parent itself */
assert(sub->parent_destroy_listener.notify == NULL);
@@ -3170,6 +3185,7 @@
surface->configure = subsurface_configure;
surface->configure_private = sub;
+ weston_surface_set_label_func(surface, subsurface_get_label);
}
static void