Here is a version two of the patch which moves the macro to wayland-server.h and fixes a typo in the docs.
- Neil ------- >8 --------------- (use git am --scissors to automatically chop here) This adds a macro called WL_REQUEST_OPCODE which takes the name of the struct for the interface and the name of one of its members. It then calculates the opcode number by dividing the offsetof the member by the size of a function pointer. This assumes the interface struct only contains function pointers and that they are in order of the opcodes. --- src/wayland-server.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/wayland-server.h b/src/wayland-server.h index 7fc5b47..24cd53f 100644 --- a/src/wayland-server.h +++ b/src/wayland-server.h @@ -39,6 +39,18 @@ enum { WL_EVENT_ERROR = 0x08 }; +/** + * Gets the opcode of a request from its interface struct + * + * Given the name of an interface struct and a request within it this + * will return the opcode number. For example it can be used like + * this: + * + * int opcode = WL_REQUEST_OPCODE(wl_region_interface, subtract); + */ +#define WL_REQUEST_OPCODE(interface, member) \ + (offsetof(struct interface, member) / sizeof (void (*) (void))) + struct wl_event_loop; struct wl_event_source; typedef int (*wl_event_loop_fd_func_t)(int fd, uint32_t mask, void *data); -- 1.9.0 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel