From ccb75867acd93fa41392b3d77e749e523a9cf15f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Tue, 10 Aug 2010 10:53:44 -0400 Subject: [PATCH] Generate the wl_*_add_listener() stubs as well --- scanner.c | 68 ++++++++++++++++++++++++++++++++++++++++++++------------ wayland-client.c | 67 +------------------------------------------------------ 2 files changed, 55 insertions(+), 80 deletions(-) diff --git a/scanner.c b/scanner.c index 9493f14..1c56d7d 100644 --- a/scanner.c +++ b/scanner.c @@ -293,7 +293,8 @@ emit_stubs(struct wl_list *message_list, struct interface *interface) if (ret) printf("\tstruct wl_proxy *%s;\n\n" "\t%s = wl_proxy_create(" - "(struct wl_proxy *) %s, &wl_%s_interface);\n" + "(struct wl_proxy *) %s,\n" + "\t\t\t &wl_%s_interface);\n" "\tif (!%s)\n" "\t\treturn NULL;\n\n", ret->name, @@ -301,7 +302,8 @@ emit_stubs(struct wl_list *message_list, struct interface *interface) interface->name, ret->interface_name, ret->name); - printf("\twl_proxy_marshal((struct wl_proxy *) %s, WL_%s_%s", + printf("\twl_proxy_marshal((struct wl_proxy *) %s,\n" + "\t\t\t WL_%s_%s", interface->name, interface->uppercase_name, m->uppercase_name); @@ -320,12 +322,28 @@ emit_stubs(struct wl_list *message_list, struct interface *interface) } } +static const char *indent(int n) +{ + const char *whitespace[] = { + "\t\t\t\t\t\t\t\t\t\t\t\t", + "\t\t\t\t\t\t\t\t\t\t\t\t ", + "\t\t\t\t\t\t\t\t\t\t\t\t ", + "\t\t\t\t\t\t\t\t\t\t\t\t ", + "\t\t\t\t\t\t\t\t\t\t\t\t ", + "\t\t\t\t\t\t\t\t\t\t\t\t ", + "\t\t\t\t\t\t\t\t\t\t\t\t ", + "\t\t\t\t\t\t\t\t\t\t\t\t " + }; + + return whitespace[n % 8] + 12 - n / 8; +} + static void emit_structs(struct wl_list *message_list, struct interface *interface) { struct message *m; struct arg *a; - int is_interface; + int is_interface, n; if (wl_list_empty(message_list)) return; @@ -337,28 +355,44 @@ emit_structs(struct wl_list *message_list, struct interface *interface) wl_list_for_each(m, message_list, link) { printf("\tvoid (*%s)(", m->name); + n = strlen(m->name) + 17; if (is_interface) { - printf("struct wl_client *client, struct wl_%s *%s", + printf("struct wl_client *client,\n" + "%sstruct wl_%s *%s", + indent(n), interface->name, interface->name); } else { - printf("void *data, struct wl_%s *%s", - interface->name, interface->name); + printf("void *data,\n"), + printf("%sstruct wl_%s *%s", + indent(n), interface->name, interface->name); } - if (!wl_list_empty(&m->arg_list)) - printf(", "); - wl_list_for_each(a, &m->arg_list, link) { + printf(",\n%s", indent(n)); + emit_type(a); - printf("%s%s", - a->name, - a->link.next == &m->arg_list ? "" : ", "); + printf("%s", a->name); } printf(");\n"); } printf("};\n\n"); + + if (!is_interface) { + printf("static inline int\n" + "wl_%s_add_listener(struct wl_%s *%s,\n" + "%sconst struct wl_%s_listener *listener, void *data)\n" + "{\n" + "\treturn wl_proxy_add_listener((struct wl_proxy *) %s,\n" + "%s(void (**)(void)) listener, data);\n" + "}\n\n", + interface->name, interface->name, interface->name, + indent(17 + strlen(interface->name)), + interface->name, + interface->name, + indent(37)); + } } static void @@ -387,9 +421,15 @@ emit_header(struct protocol *protocol, int server) "extern void\n" "wl_proxy_marshal(struct wl_proxy *p, " "uint32_t opcode, ...);\n" + "extern struct wl_proxy *\n" - "wl_proxy_create(struct wl_proxy *factory, " - "const struct wl_interface *interface);\n\n"); + "wl_proxy_create(struct wl_proxy *factory,\n" + "\t\tconst struct wl_interface *interface);\n" + + "extern int\n" + "wl_proxy_add_listener(struct wl_proxy *proxy,\n" + "\t\t void (**implementation)(void), " + "void *data);\n\n"); wl_list_for_each(i, &protocol->interface_list, link) { printf("extern const struct wl_interface " diff --git a/wayland-client.c b/wayland-client.c index f2cf7a0..9b1f01f 100644 --- a/wayland-client.c +++ b/wayland-client.c @@ -79,26 +79,6 @@ struct wl_visual { struct wl_proxy proxy; }; -struct wl_output { - struct wl_proxy proxy; -}; - -struct wl_shell { - struct wl_proxy proxy; -}; - -struct wl_drm { - struct wl_proxy proxy; -}; - -struct wl_buffer { - struct wl_proxy proxy; -}; - -struct wl_input_device { - struct wl_proxy proxy; -}; - struct wl_display { struct wl_proxy proxy; struct wl_connection *connection; @@ -219,7 +199,7 @@ wl_proxy_create(struct wl_proxy *factory, const struct wl_interface *interface) return proxy; } -static int +WL_EXPORT int wl_proxy_add_listener(struct wl_proxy *proxy, void (**implementation)(void), void *data) { struct wl_listener *listener; @@ -247,33 +227,6 @@ wl_proxy_marshal(struct wl_proxy *proxy, uint32_t opcode, ...) va_end(ap); } -WL_EXPORT int -wl_output_add_listener(struct wl_output *output, - const struct wl_output_listener *listener, - void *data) -{ - return wl_proxy_add_listener(&output->proxy, - (void (**)(void)) listener, data); -} - -WL_EXPORT int -wl_shell_add_listener(struct wl_shell *shell, - const struct wl_shell_listener *listener, - void *data) -{ - return wl_proxy_add_listener(&shell->proxy, - (void (**)(void)) listener, data); -} - -WL_EXPORT int -wl_drm_add_listener(struct wl_drm *drm, - const struct wl_drm_listener *listener, - void *data) -{ - return wl_proxy_add_listener(&drm->proxy, - (void (**)(void)) listener, data); -} - static void add_visual(struct wl_display *display, struct wl_global *global) { @@ -308,15 +261,6 @@ wl_display_get_rgb_visual(struct wl_display *display) return display->rgb_visual; } -WL_EXPORT int -wl_input_device_add_listener(struct wl_input_device *input_device, - const struct wl_input_device_listener *listener, - void *data) -{ - return wl_proxy_add_listener(&input_device->proxy, - (void (**)(void)) listener, data); -} - static void display_handle_invalid_object(void *data, struct wl_display *display, uint32_t id) @@ -566,15 +510,6 @@ wl_display_get_compositor(struct wl_display *display) return display->compositor; } -WL_EXPORT int -wl_compositor_add_listener(struct wl_compositor *compositor, - const struct wl_compositor_listener *listener, - void *data) -{ - return wl_proxy_add_listener(&compositor->proxy, - (void (**)(void)) listener, data); -} - WL_EXPORT void wl_surface_set_user_data(struct wl_surface *surface, void *user_data) { -- 2.7.4