[RFC wayland] scanner: provide convenience defines for NULL handlers
Peter Hutterer
peter.hutterer at who-t.net
Wed Sep 18 20:54:34 PDT 2013
Instead of NULL, a client that doesn't implement all callbacks of a listener
can use named defines to increase readability of the code. For example:
const struct wl_pointer_listener pointer_listener = {
WL_POINTER_ENTER_HANDLER_NONE,
WL_POINTER_LEAVE_HANDLER_NONE,
motion_handler,
button_handler,
axis_handler,
};
These are defined as typed NULL, so getting the order wrong will yield a
compiler warning in most cases - at least where neighbouring functions don't
have the same signature.
#define WL_POINTER_ENTER_HANDLER_NONE \
((void(*)(void *, struct wl_pointer *, uint32_t , struct wl_surface *, wl_fixed_t , wl_fixed_t )) NULL)
---
Just gathering interest in this, if we want this I'll polish it up and test
it a bit more.
src/scanner.c | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/src/scanner.c b/src/scanner.c
index d02d865..a41da11 100644
--- a/src/scanner.c
+++ b/src/scanner.c
@@ -872,6 +872,23 @@ emit_structs(struct wl_list *message_list, struct interface *interface)
printf("};\n\n");
if (!is_interface) {
+ wl_list_for_each(m, message_list, link) {
+ printf("#define %s_%s_HANDLER_NONE ((void(*)(",
+ interface->uppercase_name, m->uppercase_name);
+ printf("void *, "),
+ printf("struct %s *", interface->name);
+ wl_list_for_each(a, &m->arg_list, link) {
+ printf(", ");
+ if (a->type == OBJECT && a->interface_name == NULL)
+ printf("void *");
+ else if (a->type == NEW_ID)
+ printf("struct %s *", a->interface_name);
+ else
+ emit_type(a);
+ }
+ printf(")) NULL)\n");
+ }
+
printf("static inline int\n"
"%s_add_listener(struct %s *%s,\n"
"%sconst struct %s_listener *listener, void *data)\n"
--
1.8.3.1
More information about the wayland-devel
mailing list