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,
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);
}
}
+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;
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
"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 "
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;
return proxy;
}
-static int
+WL_EXPORT int
wl_proxy_add_listener(struct wl_proxy *proxy, void (**implementation)(void), void *data)
{
struct wl_listener *listener;
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)
{
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)
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)
{