diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/log.c | 2 | ||||
-rw-r--r-- | util/meson.build | 1 | ||||
-rw-r--r-- | util/os-compatibility.c | 10 | ||||
-rw-r--r-- | util/region.c | 2 | ||||
-rw-r--r-- | util/signal.c | 34 |
5 files changed, 42 insertions, 7 deletions
@@ -3,9 +3,9 @@ #include <stdarg.h> #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> #include <time.h> +#include <unistd.h> #include <wlr/util/log.h> static bool colored = true; diff --git a/util/meson.build b/util/meson.build index 34aa428b..adc52a53 100644 --- a/util/meson.build +++ b/util/meson.build @@ -4,6 +4,7 @@ lib_wlr_util = static_library( 'log.c', 'os-compatibility.c', 'region.c', + 'signal.c', ), include_directories: wlr_inc, dependencies: [wayland_server, pixman], diff --git a/util/os-compatibility.c b/util/os-compatibility.c index 98aeab3d..bd3067d2 100644 --- a/util/os-compatibility.c +++ b/util/os-compatibility.c @@ -24,13 +24,13 @@ */ #define _XOPEN_SOURCE 700 -#include <sys/types.h> -#include <sys/socket.h> -#include <unistd.h> -#include <fcntl.h> #include <errno.h> -#include <string.h> +#include <fcntl.h> #include <stdlib.h> +#include <string.h> +#include <sys/socket.h> +#include <sys/types.h> +#include <unistd.h> #include "util/os-compatibility.h" int os_fd_set_cloexec(int fd) { diff --git a/util/region.c b/util/region.c index 1bde0cb8..88e38fd2 100644 --- a/util/region.c +++ b/util/region.c @@ -1,5 +1,5 @@ -#include <stdlib.h> #include <math.h> +#include <stdlib.h> #include <wlr/util/region.h> void wlr_region_scale(pixman_region32_t *dst, pixman_region32_t *src, diff --git a/util/signal.c b/util/signal.c new file mode 100644 index 00000000..39618465 --- /dev/null +++ b/util/signal.c @@ -0,0 +1,34 @@ +#include "util/signal.h" + +static void handle_noop(struct wl_listener *listener, void *data) { + // Do nothing +} + +void wlr_signal_emit_safe(struct wl_signal *signal, void *data) { + struct wl_listener cursor; + struct wl_listener end; + + /* Add two special markers: one cursor and one end marker. This way, we know + * that we've already called listeners on the left of the cursor and that we + * don't want to call listeners on the right of the end marker. The 'it' + * function can remove any element it wants from the list without troubles. + * wl_list_for_each_safe tries to be safe but it fails: it works fine + * if the current item is removed, but not if the next one is. */ + wl_list_insert(&signal->listener_list, &cursor.link); + cursor.notify = handle_noop; + wl_list_insert(signal->listener_list.prev, &end.link); + end.notify = handle_noop; + + while (cursor.link.next != &end.link) { + struct wl_list *pos = cursor.link.next; + struct wl_listener *l = wl_container_of(pos, l, link); + + wl_list_remove(&cursor.link); + wl_list_insert(pos, &cursor.link); + + l->notify(l, data); + } + + wl_list_remove(&cursor.link); + wl_list_remove(&end.link); +} |