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-util.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
diff --git a/src/wayland-util.h b/src/wayland-util.h index fd32826..480a887 100644 --- a/src/wayland-util.h +++ b/src/wayland-util.h @@ -73,6 +73,18 @@ struct wl_interface { const struct wl_message *events; }; +/** + * Gets the opcode of a request from its interface struct + * + * Given the name of an interface struct an 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))) + /** \class wl_list * * \brief doubly-linked list -- 1.9.0 _______________________________________________ wayland-devel mailing list wayland-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/wayland-devel