common: add and use CONNECT_SIGNAL macro

This makes the code a bit more readable IMHO (and forces us to be
consistent with event handler function names).

Adjust scripts/checkpatch.pl to not complain.
This commit is contained in:
John Lindgren 2023-10-16 02:01:35 -04:00 committed by Johan Malm
parent a036d985d7
commit 5cb1d0e83f
6 changed files with 73 additions and 101 deletions

View file

@ -16,4 +16,20 @@
*/
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
/**
* CONNECT_SIGNAL() - Connect a signal handler function to a wl_signal.
*
* @param src Signal emitter (struct containing wl_signal)
* @param dest Signal receiver (struct containing wl_listener)
* @param name Signal name
*
* This assumes that the common pattern is followed where:
* - the wl_signal is (*src).events.<name>
* - the wl_listener is (*dest).<name>
* - the signal handler function is named handle_<name>
*/
#define CONNECT_SIGNAL(src, dest, name) \
(dest)->name.notify = handle_##name; \
wl_signal_add(&(src)->events.name, &(dest)->name)
#endif /* LABWC_MACROS_H */