diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-02-13 08:30:54 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-13 08:30:54 -0500 |
commit | 71cba94e73022d8cef8651055204a4706377ae11 (patch) | |
tree | 8ea1a2b6a0414fd7904824ffac330cd4e1e96ca2 | |
parent | 3497e53516d96ad67b26115e2e06218f68e1114d (diff) | |
parent | c2e147401048aa53aebd52f1851b1da8c91043a3 (diff) |
Merge pull request #627 from emersion/wlr-signal-emit-safe
Remove wlr_backend.events.{output_remove,device_remove}
143 files changed, 900 insertions, 944 deletions
diff --git a/backend/backend.c b/backend/backend.c index 98b94c5c..c67be617 100644 --- a/backend/backend.c +++ b/backend/backend.c @@ -1,17 +1,17 @@ -#include <wayland-server.h> -#include <unistd.h> -#include <stdlib.h> -#include <string.h> -#include <errno.h> #include <assert.h> +#include <errno.h> #include <libinput.h> -#include <wlr/backend/session.h> -#include <wlr/backend/interface.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <wayland-server.h> #include <wlr/backend/drm.h> +#include <wlr/backend/interface.h> #include <wlr/backend/libinput.h> +#include <wlr/backend/multi.h> +#include <wlr/backend/session.h> #include <wlr/backend/wayland.h> #include <wlr/backend/x11.h> -#include <wlr/backend/multi.h> #include <wlr/util/log.h> void wlr_backend_init(struct wlr_backend *backend, @@ -19,10 +19,8 @@ void wlr_backend_init(struct wlr_backend *backend, assert(backend); backend->impl = impl; wl_signal_init(&backend->events.destroy); - wl_signal_init(&backend->events.input_add); - wl_signal_init(&backend->events.input_remove); - wl_signal_init(&backend->events.output_add); - wl_signal_init(&backend->events.output_remove); + wl_signal_init(&backend->events.new_input); + wl_signal_init(&backend->events.new_output); } bool wlr_backend_start(struct wlr_backend *backend) { diff --git a/backend/drm/atomic.c b/backend/drm/atomic.c index 526b2731..29b5ccb1 100644 --- a/backend/drm/atomic.c +++ b/backend/drm/atomic.c @@ -1,8 +1,8 @@ -#include <stdlib.h> #include <gbm.h> +#include <stdlib.h> +#include <wlr/util/log.h> #include <xf86drm.h> #include <xf86drmMode.h> -#include <wlr/util/log.h> #include "backend/drm/drm.h" #include "backend/drm/iface.h" #include "backend/drm/util.h" diff --git a/backend/drm/backend.c b/backend/drm/backend.c index 3782817c..47dff227 100644 --- a/backend/drm/backend.c +++ b/backend/drm/backend.c @@ -1,18 +1,19 @@ -#include <unistd.h> -#include <stdlib.h> +#include <assert.h> +#include <errno.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> -#include <errno.h> -#include <assert.h> +#include <unistd.h> #include <wayland-server.h> -#include <xf86drm.h> -#include <wlr/backend/session.h> #include <wlr/backend/interface.h> +#include <wlr/backend/session.h> #include <wlr/interfaces/wlr_output.h> +#include <wlr/render/egl.h> #include <wlr/types/wlr_list.h> #include <wlr/util/log.h> -#include <wlr/render/egl.h> +#include <xf86drm.h> #include "backend/drm/drm.h" +#include "util/signal.h" static bool wlr_drm_backend_start(struct wlr_backend *backend) { struct wlr_drm_backend *drm = (struct wlr_drm_backend *)backend; @@ -34,7 +35,7 @@ static void wlr_drm_backend_destroy(struct wlr_backend *backend) { wlr_output_destroy(&conn->output); } - wl_signal_emit(&backend->events.destroy, backend); + wlr_signal_emit_safe(&backend->events.destroy, backend); wl_list_remove(&drm->display_destroy.link); wl_list_remove(&drm->session_signal.link); diff --git a/backend/drm/drm.c b/backend/drm/drm.c index 56a78851..e60b7e1c 100644 --- a/backend/drm/drm.c +++ b/backend/drm/drm.c @@ -1,29 +1,30 @@ #include <assert.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <inttypes.h> -#include <errno.h> -#include <time.h> -#include <xf86drm.h> -#include <xf86drmMode.h> #include <drm_mode.h> #include <EGL/egl.h> #include <EGL/eglext.h> +#include <errno.h> #include <gbm.h> #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> +#include <inttypes.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <time.h> #include <wayland-server.h> #include <wayland-util.h> #include <wlr/backend/interface.h> #include <wlr/interfaces/wlr_output.h> -#include <wlr/util/log.h> -#include <wlr/render/matrix.h> -#include <wlr/render/gles2.h> #include <wlr/render.h> +#include <wlr/render/gles2.h> +#include <wlr/render/matrix.h> +#include <wlr/util/log.h> +#include <xf86drm.h> +#include <xf86drmMode.h> #include "backend/drm/drm.h" #include "backend/drm/iface.h" #include "backend/drm/util.h" +#include "util/signal.h" bool wlr_drm_check_features(struct wlr_drm_backend *drm) { if (drmSetClientCap(drm->fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1)) { @@ -870,7 +871,8 @@ void wlr_drm_scan_connectors(struct wlr_drm_backend *drm) { wlr_conn->state = WLR_DRM_CONN_NEEDS_MODESET; wlr_log(L_INFO, "Sending modesetting signal for '%s'", wlr_conn->output.name); - wl_signal_emit(&drm->backend.events.output_add, &wlr_conn->output); + wlr_signal_emit_safe(&drm->backend.events.new_output, + &wlr_conn->output); } else if (wlr_conn->state == WLR_DRM_CONN_CONNECTED && drm_conn->connection != DRM_MODE_CONNECTED) { wlr_log(L_INFO, "'%s' disconnected", wlr_conn->output.name); @@ -978,8 +980,6 @@ void wlr_drm_connector_cleanup(struct wlr_drm_connector *conn) { return; } - struct wlr_drm_backend *drm = (struct wlr_drm_backend *)conn->output.backend; - switch (conn->state) { case WLR_DRM_CONN_CONNECTED: case WLR_DRM_CONN_CLEANUP:; @@ -1013,8 +1013,8 @@ void wlr_drm_connector_cleanup(struct wlr_drm_connector *conn) { /* Fallthrough */ case WLR_DRM_CONN_NEEDS_MODESET: wlr_log(L_INFO, "Emitting destruction signal for '%s'", - conn->output.name); - wl_signal_emit(&drm->backend.events.output_remove, &conn->output); + conn->output.name); + wlr_signal_emit_safe(&conn->output.events.destroy, &conn->output); break; case WLR_DRM_CONN_DISCONNECTED: break; diff --git a/backend/drm/legacy.c b/backend/drm/legacy.c index eec8c642..88a01b89 100644 --- a/backend/drm/legacy.c +++ b/backend/drm/legacy.c @@ -1,7 +1,7 @@ #include <gbm.h> +#include <wlr/util/log.h> #include <xf86drm.h> #include <xf86drmMode.h> -#include <wlr/util/log.h> #include "backend/drm/drm.h" #include "backend/drm/iface.h" #include "backend/drm/util.h" diff --git a/backend/drm/properties.c b/backend/drm/properties.c index 153e845e..3d35beb5 100644 --- a/backend/drm/properties.c +++ b/backend/drm/properties.c @@ -2,9 +2,9 @@ #include <stddef.h> #include <stdint.h> #include <stdlib.h> +#include <wlr/util/log.h> #include <xf86drm.h> #include <xf86drmMode.h> -#include <wlr/util/log.h> #include "backend/drm/properties.h" /* diff --git a/backend/drm/renderer.c b/backend/drm/renderer.c index 80d3bd9a..f3e570f7 100644 --- a/backend/drm/renderer.c +++ b/backend/drm/renderer.c @@ -1,18 +1,16 @@ +#include <EGL/egl.h> +#include <EGL/eglext.h> +#include <gbm.h> +#include <GLES2/gl2.h> #include <stdbool.h> #include <stdlib.h> #include <unistd.h> - -#include <gbm.h> -#include <GLES2/gl2.h> -#include <EGL/egl.h> -#include <EGL/eglext.h> #include <wayland-util.h> - -#include <wlr/util/log.h> +#include <wlr/render.h> #include <wlr/render/egl.h> -#include <wlr/render/matrix.h> #include <wlr/render/gles2.h> -#include <wlr/render.h> +#include <wlr/render/matrix.h> +#include <wlr/util/log.h> #include "backend/drm/drm.h" #include "glapi.h" diff --git a/backend/drm/util.c b/backend/drm/util.c index 37d99aa8..41ba47d1 100644 --- a/backend/drm/util.c +++ b/backend/drm/util.c @@ -1,10 +1,10 @@ -#include <stdio.h> -#include <string.h> -#include <drm.h> #include <drm_mode.h> +#include <drm.h> #include <gbm.h> -#include "backend/drm/util.h" +#include <stdio.h> +#include <string.h> #include <wlr/util/log.h> +#include "backend/drm/util.h" int32_t calculate_refresh_rate(drmModeModeInfo *mode) { int32_t refresh = (mode->clock * 1000000LL / mode->htotal + diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 0bf5ec28..663bc13b 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -1,9 +1,10 @@ +#include "util/signal.h" #include <stdlib.h> +#include <wlr/interfaces/wlr_input_device.h> +#include <wlr/interfaces/wlr_output.h> #include <wlr/render/egl.h> #include <wlr/render/gles2.h> #include <wlr/util/log.h> -#include <wlr/interfaces/wlr_output.h> -#include <wlr/interfaces/wlr_input_device.h> #include "backend/headless.h" #include "glapi.h" @@ -16,14 +17,14 @@ static bool backend_start(struct wlr_backend *wlr_backend) { wl_list_for_each(output, &backend->outputs, link) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); wlr_output_update_enabled(&output->wlr_output, true); - wl_signal_emit(&backend->backend.events.output_add, + wlr_signal_emit_safe(&backend->backend.events.new_output, &output->wlr_output); } struct wlr_headless_input_device *input_device; wl_list_for_each(input_device, &backend->input_devices, wlr_input_device.link) { - wl_signal_emit(&backend->backend.events.input_add, + wlr_signal_emit_safe(&backend->backend.events.new_input, &input_device->wlr_input_device); } @@ -51,7 +52,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) { wlr_input_device_destroy(&input_device->wlr_input_device); } - wl_signal_emit(&wlr_backend->events.destroy, backend); + wlr_signal_emit_safe(&wlr_backend->events.destroy, backend); wlr_egl_finish(&backend->egl); free(backend); diff --git a/backend/headless/input_device.c b/backend/headless/input_device.c index 5c62e87f..ea335aff 100644 --- a/backend/headless/input_device.c +++ b/backend/headless/input_device.c @@ -1,17 +1,17 @@ #include <stdlib.h> #include <wlr/interfaces/wlr_input_device.h> -#include <wlr/interfaces/wlr_pointer.h> #include <wlr/interfaces/wlr_keyboard.h> -#include <wlr/interfaces/wlr_touch.h> -#include <wlr/interfaces/wlr_tablet_tool.h> +#include <wlr/interfaces/wlr_pointer.h> #include <wlr/interfaces/wlr_tablet_pad.h> +#include <wlr/interfaces/wlr_tablet_tool.h> +#include <wlr/interfaces/wlr_touch.h> #include <wlr/util/log.h> #include "backend/headless.h" +#include "util/signal.h" static void input_device_destroy(struct wlr_input_device *wlr_dev) { struct wlr_headless_input_device *device = (struct wlr_headless_input_device *)wlr_dev; - wl_signal_emit(&device->backend->backend.events.input_remove, wlr_dev); free(device); } @@ -88,7 +88,7 @@ struct wlr_input_device *wlr_headless_add_input_device( wl_list_insert(&backend->input_devices, &wlr_device->link); if (backend->started) { - wl_signal_emit(&backend->backend.events.input_add, wlr_device); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_device); } return wlr_device; diff --git a/backend/headless/output.c b/backend/headless/output.c index 507595a5..ba4a094e 100644 --- a/backend/headless/output.c +++ b/backend/headless/output.c @@ -1,10 +1,11 @@ -#include <stdlib.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include <GLES2/gl2.h> +#include <stdlib.h> #include <wlr/interfaces/wlr_output.h> #include <wlr/util/log.h> #include "backend/headless.h" +#include "util/signal.h" static EGLSurface egl_create_surface(struct wlr_egl *egl, unsigned int width, unsigned int height) { @@ -136,7 +137,7 @@ struct wlr_output *wlr_headless_add_output(struct wlr_backend *wlr_backend, if (backend->started) { wl_event_source_timer_update(output->frame_timer, output->frame_delay); wlr_output_update_enabled(wlr_output, true); - wl_signal_emit(&backend->backend.events.output_add, wlr_output); + wlr_signal_emit_safe(&backend->backend.events.new_output, wlr_output); } return wlr_output; diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 86477947..71fe0d93 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -1,10 +1,11 @@ -#include <stdlib.h> #include <assert.h> #include <libinput.h> -#include <wlr/backend/session.h> +#include <stdlib.h> #include <wlr/backend/interface.h> +#include <wlr/backend/session.h> #include <wlr/util/log.h> #include "backend/libinput.h" +#include "util/signal.h" static int wlr_libinput_open_restricted(const char *path, int flags, void *_backend) { @@ -106,13 +107,12 @@ static void wlr_libinput_backend_destroy(struct wlr_backend *wlr_backend) { struct wl_list *wlr_devices = backend->wlr_device_lists.items[i]; struct wlr_input_device *wlr_dev, *next; wl_list_for_each_safe(wlr_dev, next, wlr_devices, link) { - wl_signal_emit(&backend->backend.events.input_remove, wlr_dev); wlr_input_device_destroy(wlr_dev); } free(wlr_devices); } - wl_signal_emit(&wlr_backend->events.destroy, wlr_backend); + wlr_signal_emit_safe(&wlr_backend->events.destroy, wlr_backend); wl_list_remove(&backend->display_destroy.link); wl_list_remove(&backend->session_signal.link); diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 758a9f25..603eed07 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -1,11 +1,12 @@ -#include <stdlib.h> #include <assert.h> #include <libinput.h> +#include <stdlib.h> +#include <wayland-util.h> #include <wlr/backend/session.h> #include <wlr/interfaces/wlr_input_device.h> #include <wlr/util/log.h> -#include <wayland-util.h> #include "backend/libinput.h" +#include "util/signal.h" struct wlr_input_device *get_appropriate_device( enum wlr_input_device_type desired_type, @@ -88,7 +89,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, free(wlr_dev); goto fail; } - wl_signal_emit(&backend->backend.events.input_add, wlr_dev); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); } if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_POINTER)) { struct wlr_input_device *wlr_dev = allocate_device(backend, @@ -101,7 +102,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, free(wlr_dev); goto fail; } - wl_signal_emit(&backend->backend.events.input_add, wlr_dev); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); } if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TOUCH)) { struct wlr_input_device *wlr_dev = allocate_device(backend, @@ -114,7 +115,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, free(wlr_dev); goto fail; } - wl_signal_emit(&backend->backend.events.input_add, wlr_dev); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); } if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_TOOL)) { struct wlr_input_device *wlr_dev = allocate_device(backend, @@ -127,7 +128,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, free(wlr_dev); goto fail; } - wl_signal_emit(&backend->backend.events.input_add, wlr_dev); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); } if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_TABLET_PAD)) { struct wlr_input_device *wlr_dev = allocate_device(backend, @@ -140,7 +141,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, free(wlr_dev); goto fail; } - wl_signal_emit(&backend->backend.events.input_add, wlr_dev); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_dev); } if (libinput_device_has_capability(libinput_dev, LIBINPUT_DEVICE_CAP_GESTURE)) { // TODO @@ -178,7 +179,6 @@ static void handle_device_removed(struct wlr_libinput_backend *backend, } struct wlr_input_device *dev, *tmp_dev; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) { - wl_signal_emit(&backend->backend.events.input_remove, dev); wlr_input_device_destroy(dev); } for (size_t i = 0; i < backend->wlr_device_lists.length; i++) { diff --git a/backend/libinput/keyboard.c b/backend/libinput/keyboard.c index 065d8ead..b44bc892 100644 --- a/backend/libinput/keyboard.c +++ b/backend/libinput/keyboard.c @@ -1,9 +1,9 @@ -#include <stdlib.h> #include <assert.h> #include <libinput.h> +#include <stdlib.h> #include <wlr/backend/session.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_keyboard.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "backend/libinput.h" @@ -57,7 +57,7 @@ void handle_keyboard_key(struct libinput_event *event, wlr_event.time_msec = usec_to_msec(libinput_event_keyboard_get_time_usec(kbevent)); wlr_event.keycode = libinput_event_keyboard_get_key(kbevent); - enum libinput_key_state state = + enum libinput_key_state state = libinput_event_keyboard_get_key_state(kbevent); switch (state) { case LIBINPUT_KEY_STATE_RELEASED: diff --git a/backend/libinput/pointer.c b/backend/libinput/pointer.c index 13402ac2..8a31d312 100644 --- a/backend/libinput/pointer.c +++ b/backend/libinput/pointer.c @@ -1,11 +1,12 @@ -#include <stdlib.h> #include <assert.h> #include <libinput.h> +#include <stdlib.h> #include <wlr/backend/session.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_pointer.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "backend/libinput.h" +#include "util/signal.h" struct wlr_pointer *wlr_libinput_pointer_create( struct libinput_device *libinput_dev) { @@ -35,7 +36,7 @@ void handle_pointer_motion(struct libinput_event *event, usec_to_msec(libinput_event_pointer_get_time_usec(pevent)); wlr_event.delta_x = libinput_event_pointer_get_dx(pevent); wlr_event.delta_y = libinput_event_pointer_get_dy(pevent); - wl_signal_emit(&wlr_dev->pointer->events.motion, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->pointer->events.motion, &wlr_event); } void handle_pointer_motion_abs(struct libinput_event *event, @@ -55,7 +56,7 @@ void handle_pointer_motion_abs(struct libinput_event *event, wlr_event.x_mm = libinput_event_pointer_get_absolute_x(pevent); wlr_event.y_mm = libinput_event_pointer_get_absolute_y(pevent); libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); - wl_signal_emit(&wlr_dev->pointer->events.motion_absolute, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->pointer->events.motion_absolute, &wlr_event); } void handle_pointer_button(struct libinput_event *event, @@ -81,7 +82,7 @@ void handle_pointer_button(struct libinput_event *event, wlr_event.state = WLR_BUTTON_RELEASED; break; } - wl_signal_emit(&wlr_dev->pointer->events.button, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->pointer->events.button, &wlr_event); } void handle_pointer_axis(struct libinput_event *event, @@ -128,7 +129,7 @@ void handle_pointer_axis(struct libinput_event *event, } wlr_event.delta = libinput_event_pointer_get_axis_value( pevent, axies[i]); - wl_signal_emit(&wlr_dev->pointer->events.axis, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->pointer->events.axis, &wlr_event); } } } diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 7dac3b7c..70e4c677 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -1,11 +1,12 @@ -#include <stdlib.h> #include <assert.h> #include <libinput.h> +#include <stdlib.h> #include <wlr/backend/session.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_tablet_pad.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "backend/libinput.h" +#include "util/signal.h" struct wlr_tablet_pad *wlr_libinput_tablet_pad_create( struct libinput_device *libinput_dev) { @@ -41,7 +42,7 @@ void handle_tablet_pad_button(struct libinput_event *event, wlr_event.state = WLR_BUTTON_RELEASED; break; } - wl_signal_emit(&wlr_dev->tablet_pad->events.button, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet_pad->events.button, &wlr_event); } void handle_tablet_pad_ring(struct libinput_event *event, @@ -67,7 +68,7 @@ void handle_tablet_pad_ring(struct libinput_event *event, wlr_event.source = WLR_TABLET_PAD_RING_SOURCE_FINGER; break; } - wl_signal_emit(&wlr_dev->tablet_pad->events.ring, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet_pad->events.ring, &wlr_event); } void handle_tablet_pad_strip(struct libinput_event *event, @@ -93,5 +94,5 @@ void handle_tablet_pad_strip(struct libinput_event *event, wlr_event.source = WLR_TABLET_PAD_STRIP_SOURCE_FINGER; break; } - wl_signal_emit(&wlr_dev->tablet_pad->events.strip, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet_pad->events.strip, &wlr_event); } diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index 3d5fafc3..4e60367f 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -1,11 +1,12 @@ -#include <stdlib.h> #include <assert.h> #include <libinput.h> +#include <stdlib.h> #include <wlr/backend/session.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_tablet_tool.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "backend/libinput.h" +#include "util/signal.h" struct wlr_tablet_tool *wlr_libinput_tablet_tool_create( struct libinput_device *libinput_dev) { @@ -72,7 +73,7 @@ void handle_tablet_tool_axis(struct libinput_event *event, } wlr_log(L_DEBUG, "Tablet tool axis event %d @ %f,%f", wlr_event.updated_axes, wlr_event.x_mm, wlr_event.y_mm); - wl_signal_emit(&wlr_dev->tablet_tool->events.axis, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.axis, &wlr_event); } void handle_tablet_tool_proximity(struct libinput_event *event, @@ -98,7 +99,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event, handle_tablet_tool_axis(event, libinput_dev); break; } - wl_signal_emit(&wlr_dev->tablet_tool->events.proximity, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.proximity, &wlr_event); } void handle_tablet_tool_tip(struct libinput_event *event, @@ -124,7 +125,7 @@ void handle_tablet_tool_tip(struct libinput_event *event, wlr_event.state = WLR_TABLET_TOOL_TIP_DOWN; break; } - wl_signal_emit(&wlr_dev->tablet_tool->events.tip, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.tip, &wlr_event); } void handle_tablet_tool_button(struct libinput_event *event, @@ -151,5 +152,5 @@ void handle_tablet_tool_button(struct libinput_event *event, wlr_event.state = WLR_BUTTON_PRESSED; break; } - wl_signal_emit(&wlr_dev->tablet_tool->events.button, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->tablet_tool->events.button, &wlr_event); } diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 0ba6ec86..2b87f9cd 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -1,11 +1,12 @@ -#include <stdlib.h> #include <assert.h> #include <libinput.h> +#include <stdlib.h> #include <wlr/backend/session.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_touch.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> #include "backend/libinput.h" +#include "util/signal.h" struct wlr_touch *wlr_libinput_touch_create( struct libinput_device *libinput_dev) { @@ -37,7 +38,7 @@ void handle_touch_down(struct libinput_event *event, wlr_event.x_mm = libinput_event_touch_get_x(tevent); wlr_event.y_mm = libinput_event_touch_get_y(tevent); libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); - wl_signal_emit(&wlr_dev->touch->events.down, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->touch->events.down, &wlr_event); } void handle_touch_up(struct libinput_event *event, @@ -55,7 +56,7 @@ void handle_touch_up(struct libinput_event *event, wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); wlr_event.touch_id = libinput_event_touch_get_slot(tevent); - wl_signal_emit(&wlr_dev->touch->events.up, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->touch->events.up, &wlr_event); } void handle_touch_motion(struct libinput_event *event, @@ -76,7 +77,7 @@ void handle_touch_motion(struct libinput_event *event, wlr_event.x_mm = libinput_event_touch_get_x(tevent); wlr_event.y_mm = libinput_event_touch_get_y(tevent); libinput_device_get_size(libinput_dev, &wlr_event.width_mm, &wlr_event.height_mm); - wl_signal_emit(&wlr_dev->touch->events.motion, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->touch->events.motion, &wlr_event); } void handle_touch_cancel(struct libinput_event *event, @@ -94,5 +95,5 @@ void handle_touch_cancel(struct libinput_event *event, wlr_event.time_msec = usec_to_msec(libinput_event_touch_get_time_usec(tevent)); wlr_event.touch_id = libinput_event_touch_get_slot(tevent); - wl_signal_emit(&wlr_dev->touch->events.cancel, &wlr_event); + wlr_signal_emit_safe(&wlr_dev->touch->events.cancel, &wlr_event); } diff --git a/backend/meson.build b/backend/meson.build index beb3841c..bac43063 100644 --- a/backend/meson.build +++ b/backend/meson.build @@ -1,7 +1,5 @@ backend_files = files( 'backend.c', - 'session/direct-ipc.c', - 'session/session.c', 'drm/atomic.c', 'drm/backend.c', 'drm/drm.c', @@ -10,8 +8,8 @@ backend_files = files( 'drm/renderer.c', 'drm/util.c', 'headless/backend.c', - 'headless/output.c', 'headless/input_device.c', + 'headless/output.c', 'libinput/backend.c', 'libinput/events.c', 'libinput/keyboard.c', @@ -20,6 +18,8 @@ backend_files = files( 'libinput/tablet_tool.c', 'libinput/touch.c', 'multi/backend.c', + 'session/direct-ipc.c', + 'session/session.c', 'wayland/backend.c', 'wayland/output.c', 'wayland/registry.c', diff --git a/backend/multi/backend.c b/backend/multi/backend.c index 78f5c63b..5cb3fbc5 100644 --- a/backend/multi/backend.c +++ b/backend/multi/backend.c @@ -4,17 +4,16 @@ #include <wlr/backend/interface.h> #include <wlr/backend/session.h> #include <wlr/util/log.h> -#include "backend/multi.h" #include "backend/drm/drm.h" +#include "backend/multi.h" +#include "util/signal.h" struct subbackend_state { struct wlr_backend *backend; struct wlr_backend *container; - struct wl_listener input_add; - struct wl_listener input_remove; - struct wl_listener output_add; - struct wl_listener output_remove; - struct wl_listener backend_destroy; + struct wl_listener new_input; + struct wl_listener new_output; + struct wl_listener destroy; struct wl_list link; }; @@ -31,11 +30,9 @@ static bool multi_backend_start(struct wlr_backend *wlr_backend) { } static void subbackend_state_destroy(struct subbackend_state *sub) { - wl_list_remove(&sub->input_add.link); - wl_list_remove(&sub->input_remove.link); - wl_list_remove(&sub->output_add.link); - wl_list_remove(&sub->output_remove.link); - wl_list_remove(&sub->backend_destroy.link); + wl_list_remove(&sub->new_input.link); + wl_list_remove(&sub->new_output.link); + wl_list_remove(&sub->destroy.link); wl_list_remove(&sub->link); free(sub); } @@ -51,7 +48,7 @@ static void multi_backend_destroy(struct wlr_backend *wlr_backend) { } // Destroy this backend only after removing all sub-backends - wl_signal_emit(&wlr_backend->events.destroy, backend); + wlr_signal_emit_safe(&wlr_backend->events.destroy, backend); free(backend); } @@ -117,34 +114,21 @@ bool wlr_backend_is_multi(struct wlr_backend *b) { return b->impl == &backend_impl; } -static void input_add_reemit(struct wl_listener *listener, void *data) { - struct subbackend_state *state = wl_container_of(listener, - state, input_add); - wl_signal_emit(&state->container->events.input_add, data); -} - -static void input_remove_reemit(struct wl_listener *listener, void *data) { +static void new_input_reemit(struct wl_listener *listener, void *data) { struct subbackend_state *state = wl_container_of(listener, - state, input_remove); - wl_signal_emit(&state->container->events.input_remove, data); + state, new_input); + wlr_signal_emit_safe(&state->container->events.new_input, data); } -static void output_add_reemit(struct wl_listener *listener, void *data) { +static void new_output_reemit(struct wl_listener *listener, void *data) { struct subbackend_state *state = wl_container_of(listener, - state, output_add); - wl_signal_emit(&state->container->events.output_add, data); -} - -static void output_remove_reemit(struct wl_listener *listener, void *data) { - struct subbackend_state *state = wl_container_of(listener, - state, output_remove); - wl_signal_emit(&state->container->events.output_remove, data); + state, new_output); + wlr_signal_emit_safe(&state->container->events.new_output, data); } static void handle_subbackend_destroy(struct wl_listener *listener, void *data) { - struct subbackend_state *state = wl_container_of(listener, - state, backend_destroy); + struct subbackend_state *state = wl_container_of(listener, state, destroy); subbackend_state_destroy(state); } @@ -179,22 +163,16 @@ void wlr_multi_backend_add(struct wlr_backend *_multi, sub->backend = backend; sub->container = &multi->backend; - wl_signal_add(&backend->events.destroy, &sub->backend_destroy); - sub->backend_destroy.notify = handle_subbackend_destroy; - - wl_signal_add(&backend->events.input_add, &sub->input_add); - sub->input_add.notify = input_add_reemit; - - wl_signal_add(&backend->events.input_remove, &sub->input_remove); - sub->input_remove.notify = input_remove_reemit; + wl_signal_add(&backend->events.destroy, &sub->destroy); + sub->destroy.notify = handle_subbackend_destroy; - wl_signal_add(&backend->events.output_add, &sub->output_add); - sub->output_add.notify = output_add_reemit; + wl_signal_add(&backend->events.new_input, &sub->new_input); + sub->new_input.notify = new_input_reemit; - wl_signal_add(&backend->events.output_remove, &sub->output_remove); - sub->output_remove.notify = output_remove_reemit; + wl_signal_add(&backend->events.new_output, &sub->new_output); + sub->new_output.notify = new_output_reemit; - wl_signal_emit(&multi->events.backend_add, backend); + wlr_signal_emit_safe(&multi->events.backend_add, backend); } void wlr_multi_backend_remove(struct wlr_backend *_multi, @@ -206,7 +184,7 @@ void wlr_multi_backend_remove(struct wlr_backend *_multi, multi_backend_get_subbackend(multi, backend); if (sub) { - wl_signal_emit(&multi->events.backend_remove, backend); + wlr_signal_emit_safe(&multi->events.backend_remove, backend); subbackend_state_destroy(sub); } } diff --git a/backend/session/direct-freebsd.c b/backend/session/direct-freebsd.c index c0621416..6e23bf1b 100644 --- a/backend/session/direct-freebsd.c +++ b/backend/session/direct-freebsd.c @@ -1,21 +1,22 @@ +#include <dev/evdev/input.h> #include <errno.h> -#include <stdlib.h> -#include <stdio.h> -#include <stdbool.h> -#include <unistd.h> +#include <fcntl.h> #include <signal.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <sys/consio.h> #include <sys/ioctl.h> +#include <sys/kbio.h> #include <sys/stat.h> -#include <termios.h> -#include <fcntl.h> #include <sys/types.h> -#include <dev/evdev/input.h> -#include <sys/kbio.h> -#include <sys/consio.h> +#include <termios.h> +#include <unistd.h> #include <wayland-server.h> #include <wlr/backend/session/interface.h> #include <wlr/util/log.h> #include "backend/session/direct-ipc.h" +#include "util/signal.h" const struct session_impl session_direct; @@ -95,12 +96,12 @@ static int vt_handler(int signo, void *data) { if (session->base.active) { session->base.active = false; - wl_signal_emit(&session->base.session_signal, session); + wlr_signal_emit_safe(&session->base.session_signal, session); ioctl(session->tty_fd, VT_RELDISP, 1); } else { ioctl(session->tty_fd, VT_RELDISP, VT_ACKACQ); session->base.active = true; - wl_signal_emit(&session->base.session_signal, session); + wlr_signal_emit_safe(&session->base.session_signal, session); } return 1; diff --git a/backend/session/direct-ipc.c b/backend/session/direct-ipc.c index e7a169fa..6c69b70a 100644 --- a/backend/session/direct-ipc.c +++ b/backend/session/direct-ipc.c @@ -4,22 +4,22 @@ #define INPUT_MAJOR 0 #endif #include <errno.h> +#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <fcntl.h> -#include <unistd.h> #include <sys/socket.h> #include <sys/stat.h> #include <sys/types.h> #include <sys/wait.h> +#include <unistd.h> +#include <wlr/config.h> +#include <wlr/util/log.h> +#include <xf86drm.h> #ifdef __linux__ #include <sys/sysmacros.h> #include <linux/major.h> #endif -#include <xf86drm.h> -#include <wlr/config.h> -#include <wlr/util/log.h> #include "backend/session/direct-ipc.h" enum { DRM_MAJOR = 226 }; diff --git a/backend/session/direct.c b/backend/session/direct.c index 9d6cd36d..13a26d99 100644 --- a/backend/session/direct.c +++ b/backend/session/direct.c @@ -1,21 +1,22 @@ #define _POSIX_C_SOURCE 200809L #include <errno.h> -#include <stdlib.h> -#include <stdio.h> -#include <stdbool.h> -#include <unistd.h> +#include <linux/input.h> +#include <linux/kd.h> +#include <linux/major.h> +#include <linux/vt.h> #include <signal.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/sysmacros.h> -#include <linux/kd.h> -#include <linux/major.h> -#include <linux/input.h> -#include <linux/vt.h> +#include <unistd.h> #include <wayland-server.h> #include <wlr/backend/session/interface.h> #include <wlr/util/log.h> #include "backend/session/direct-ipc.h" +#include "util/signal.h" enum { DRM_MAJOR = 226 }; @@ -107,7 +108,7 @@ static int vt_handler(int signo, void *data) { if (session->base.active) { session->base.active = false; - wl_signal_emit(&session->base.session_signal, session); + wlr_signal_emit_safe(&session->base.session_signal, session); struct wlr_device *dev; wl_list_for_each(dev, &session->base.devices, link) { @@ -130,7 +131,7 @@ static int vt_handler(int signo, void *data) { } session->base.active = true; - wl_signal_emit(&session->base.session_signal, session); + wlr_signal_emit_safe(&session->base.session_signal, session); } return 1; diff --git a/backend/session/logind.c b/backend/session/logind.c index 1ece051f..f0ac1e93 100644 --- a/backend/session/logind.c +++ b/backend/session/logind.c @@ -1,25 +1,26 @@ #define _POSIX_C_SOURCE 200809L #include <assert.h> -#include <stdio.h> +#include <errno.h> +#include <fcntl.h> #include <stdbool.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <errno.h> -#include <unistd.h> -#include <sys/sysmacros.h> #include <sys/stat.h> -#include <fcntl.h> +#include <sys/sysmacros.h> +#include <unistd.h> #include <wayland-server.h> -#include <wlr/config.h> #include <wlr/backend/session/interface.h> +#include <wlr/config.h> #include <wlr/util/log.h> +#include "util/signal.h" #ifdef WLR_HAS_SYSTEMD #include <systemd/sd-bus.h> #include <systemd/sd-login.h> #elif defined(WLR_HAS_ELOGIND) #include <elogind/sd-bus.h> - #include <elogind/sd-login.h> + #include <elogind/sd-login.h> #endif enum { DRM_MAJOR = 226 }; @@ -250,7 +251,7 @@ static int pause_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_e if (major == DRM_MAJOR) { session->base.active = false; - wl_signal_emit(&session->base.session_signal, session); + wlr_signal_emit_safe(&session->base.session_signal, session); } if (strcmp(type, "pause") == 0) { @@ -286,7 +287,7 @@ static int resume_device(sd_bus_message *msg, void *userdata, sd_bus_error *ret_ if (!session->base.active) { session->base.active = true; - wl_signal_emit(&session->base.session_signal, session); + wlr_signal_emit_safe(&session->base.session_signal, session); } } diff --git a/backend/session/session.c b/backend/session/session.c index 2bbbd4ef..2d5d9776 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -1,18 +1,19 @@ #define _POSIX_C_SOURCE 200809L #include <assert.h> +#include <libudev.h> #include <stddef.h> #include <stdlib.h> #include <string.h> #include <sys/stat.h> #include <sys/types.h> -#include <libudev.h> #include <wayland-server.h> -#include <xf86drm.h> -#include <xf86drmMode.h> -#include <wlr/config.h> #include <wlr/backend/session.h> #include <wlr/backend/session/interface.h> +#include <wlr/config.h> #include <wlr/util/log.h> +#include <xf86drm.h> +#include <xf86drmMode.h> +#include "util/signal.h" extern const struct session_impl session_logind; extern const struct session_impl session_direct; @@ -49,7 +50,7 @@ static int udev_event(int fd, uint32_t mask, void *data) { wl_list_for_each(dev, &session->devices, link) { if (dev->dev == devnum) { - wl_signal_emit(&dev->signal, session); + wlr_signal_emit_safe(&dev->signal, session); break; } } diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 458c9dd0..abb25df5 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -1,17 +1,18 @@ -#include <stdlib.h> -#include <stdint.h> #include <assert.h> -#include <limits.h> #include <EGL/egl.h> #include <EGL/eglext.h> +#include <limits.h> +#include <stdint.h> +#include <stdlib.h> #include <wayland-server.h> -#include <wlr/render/egl.h> -#include <wlr/render/gles2.h> #include <wlr/backend/interface.h> -#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_input_device.h> +#include <wlr/interfaces/wlr_output.h> +#include <wlr/render/egl.h> +#include <wlr/render/gles2.h> #include <wlr/util/log.h> #include "backend/wayland.h" +#include "util/signal.h" #include "xdg-shell-unstable-v6-client-protocol.h" static int dispatch_events(int fd, uint32_t mask, void *data) { @@ -80,7 +81,7 @@ static void wlr_wl_backend_destroy(struct wlr_backend *wlr_backend) { wlr_input_device_destroy(input_device); } - wl_signal_emit(&wlr_backend->events.destroy, wlr_backend); + wlr_signal_emit_safe(&wlr_backend->events.destroy, wlr_backend); wl_list_remove(&backend->local_display_destroy.link); diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 0bbf6d42..fc40dea0 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -1,16 +1,17 @@ -#include <stdio.h> #include <assert.h> +#include <GLES2/gl2.h> #include <stdint.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> -#include <sys/types.h> #include <sys/mman.h> +#include <sys/types.h> +#include <unistd.h> #include <wayland-client.h> -#include <GLES2/gl2.h> #include <wlr/interfaces/wlr_output.h> #include <wlr/util/log.h> #include "backend/wayland.h" +#include "util/signal.h" #include "xdg-shell-unstable-v6-client-protocol.h" int os_create_anonymous_file(off_t size); @@ -338,7 +339,7 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { wl_list_insert(&backend->outputs, &output->link); wlr_output_update_enabled(wlr_output, true); - wl_signal_emit(&backend->backend.events.output_add, wlr_output); + wlr_signal_emit_safe(&backend->backend.events.new_output, wlr_output); return wlr_output; error: diff --git a/backend/wayland/registry.c b/backend/wayland/registry.c index 0dec0ec5..4aa39f09 100644 --- a/backend/wayland/registry.c +++ b/backend/wayland/registry.c @@ -6,7 +6,6 @@ #include "backend/wayland.h" #include "xdg-shell-unstable-v6-client-protocol.h" - static void xdg_shell_handle_ping(void *data, struct zxdg_shell_v6 *shell, uint32_t serial) { zxdg_shell_v6_pong(shell, serial); diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 37489678..b1f7cff6 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -1,16 +1,17 @@ #define _XOPEN_SOURCE 500 #include <assert.h> -#include <stdlib.h> #include <stdint.h> +#include <stdlib.h> #include <string.h> #include <wayland-client.h> -#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_input_device.h> -#include <wlr/interfaces/wlr_pointer.h> #include <wlr/interfaces/wlr_keyboard.h> +#include <wlr/interfaces/wlr_output.h> +#include <wlr/interfaces/wlr_pointer.h> #include <wlr/interfaces/wlr_touch.h> #include <wlr/util/log.h> #include "backend/wayland.h" +#include "util/signal.h" static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial, struct wl_surface *surface, wl_fixed_t surface_x, @@ -78,7 +79,7 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, wlr_event.height_mm = layout_box.height; wlr_event.x_mm = transformed.x + wlr_output->lx - layout_box.x; wlr_event.y_mm = transformed.y + wlr_output->ly - layout_box.y; - wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event); + wlr_signal_emit_safe(&dev->pointer->events.motion_absolute, &wlr_event); } static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, @@ -91,7 +92,7 @@ static void pointer_handle_button(void *data, struct wl_pointer *wl_pointer, wlr_event.button = button; wlr_event.state = state; wlr_event.time_msec = time; - wl_signal_emit(&dev->pointer->events.button, &wlr_event); + wlr_signal_emit_safe(&dev->pointer->events.button, &wlr_event); } static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, @@ -106,7 +107,7 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, wlr_event.orientation = axis; wlr_event.time_msec = time; wlr_event.source = wlr_wl_pointer->axis_source; - wl_signal_emit(&dev->pointer->events.axis, &wlr_event); + wlr_signal_emit_safe(&dev->pointer->events.axis, &wlr_event); } static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { @@ -192,9 +193,8 @@ static struct wl_keyboard_listener keyboard_listener = { .repeat_info = keyboard_handle_repeat_info }; -static void input_device_destroy(struct wlr_input_device *_dev) { - struct wlr_wl_input_device *dev = (struct wlr_wl_input_device *)_dev; - wl_signal_emit(&dev->backend->backend.events.input_remove, &dev->wlr_input_device); +static void input_device_destroy(struct wlr_input_device *wlr_dev) { + struct wlr_wl_input_device *dev = (struct wlr_wl_input_device *)wlr_dev; if (dev->resource) { wl_proxy_destroy(dev->resource); } @@ -256,7 +256,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, wlr_device->pointer = &wlr_wl_pointer->wlr_pointer; wlr_pointer_init(wlr_device->pointer, NULL); wlr_wl_device->resource = wl_pointer; - wl_signal_emit(&backend->backend.events.input_add, wlr_device); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_device); backend->pointer = wl_pointer; } if ((caps & WL_SEAT_CAPABILITY_KEYBOARD)) { @@ -280,7 +280,7 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, struct wl_keyboard *wl_keyboard = wl_seat_get_keyboard(wl_seat); wl_keyboard_add_listener(wl_keyboard, &keyboard_listener, wlr_device); wlr_wl_device->resource = wl_keyboard; - wl_signal_emit(&backend->backend.events.input_add, wlr_device); + wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_device); } } diff --git a/backend/x11/backend.c b/backend/x11/backend.c index 411d0ef6..28a4fcac 100644 --- a/backend/x11/backend.c +++ b/backend/x11/backend.c @@ -1,28 +1,29 @@ #define _POSIX_C_SOURCE 200112L +#include <EGL/egl.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <time.h> -#include <EGL/egl.h> #include <wayland-server.h> -#include <xcb/xcb.h> -#include <xcb/glx.h> -#include <X11/Xlib-xcb.h> -#ifdef __linux__ -#include <linux/input-event-codes.h> -#elif __FreeBSD__ -#include <dev/evdev/input-event-codes.h> -#endif #include <wlr/backend/interface.h> #include <wlr/backend/x11.h> -#include <wlr/render/egl.h> -#include <wlr/render/gles2.h> -#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_keyboard.h> +#include <wlr/interfaces/wlr_output.h> #include <wlr/interfaces/wlr_pointer.h> +#include <wlr/render/egl.h> +#include <wlr/render/gles2.h> #include <wlr/util/log.h> +#include <X11/Xlib-xcb.h> +#include <xcb/glx.h> +#include <xcb/xcb.h> +#ifdef __linux__ +#include <linux/input-event-codes.h> +#elif __FreeBSD__ +#include <dev/evdev/input-event-codes.h> +#endif #include "backend/x11.h" +#include "util/signal.h" static struct wlr_backend_impl backend_impl; static struct wlr_output_impl output_impl; @@ -77,7 +78,7 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e .orientation = WLR_AXIS_ORIENTATION_VERTICAL, .delta = delta, }; - wl_signal_emit(&x11->pointer.events.axis, &axis); + wlr_signal_emit_safe(&x11->pointer.events.axis, &axis); x11->time = ev->time; break; } @@ -96,7 +97,7 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e WLR_BUTTON_PRESSED : WLR_BUTTON_RELEASED, }; - wl_signal_emit(&x11->pointer.events.button, &button); + wlr_signal_emit_safe(&x11->pointer.events.button, &button); } x11->time = ev->time; break; @@ -112,7 +113,7 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e .height_mm = output->wlr_output.height, }; - wl_signal_emit(&x11->pointer.events.motion_absolute, &abs); + wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); x11->time = ev->time; break; } @@ -140,7 +141,7 @@ static bool handle_x11_event(struct wlr_x11_backend *x11, xcb_generic_event_t *e .height_mm = output->wlr_output.height, }; - wl_signal_emit(&x11->pointer.events.motion_absolute, &abs); + wlr_signal_emit_safe(&x11->pointer.events.motion_absolute, &abs); break; } case XCB_GLX_DELETE_QUERIES_ARB: { @@ -229,9 +230,9 @@ static bool wlr_x11_backend_start(struct wlr_backend *backend) { xcb_flush(x11->xcb_conn); wlr_output_update_enabled(&output->wlr_output, true); - wl_signal_emit(&x11->backend.events.output_add, output); - wl_signal_emit(&x11->backend.events.input_add, &x11->keyboard_dev); - wl_signal_emit(&x11->backend.events.input_add, &x11->pointer_dev); + wlr_signal_emit_safe(&x11->backend.events.new_output, output); + wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->keyboard_dev); + wlr_signal_emit_safe(&x11->backend.events.new_input, &x11->pointer_dev); wl_event_source_timer_update(x11->frame_timer, 16); @@ -248,8 +249,8 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) { struct wlr_x11_output *output = &x11->output; wlr_output_destroy(&output->wlr_output); - wl_signal_emit(&backend->events.input_remove, &x11->pointer_dev); - wl_signal_emit(&backend->events.input_remove, &x11->keyboard_dev); + wlr_signal_emit_safe(&x11->pointer_dev.events.destroy, &x11->pointer_dev); + wlr_signal_emit_safe(&x11->keyboard_dev.events.destroy, &x11->keyboard_dev); // TODO probably need to use wlr_keyboard_destroy, but the devices need to // be malloced for that to work if (x11->keyboard_dev.keyboard->keymap) { @@ -259,7 +260,7 @@ static void wlr_x11_backend_destroy(struct wlr_backend *backend) { xkb_state_unref(x11->keyboard_dev.keyboard->xkb_state); } - wl_signal_emit(&backend->events.destroy, backend); + wlr_signal_emit_safe(&backend->events.destroy, backend); wl_list_remove(&x11->display_destroy.link); diff --git a/examples/support/shared.c b/examples/support/shared.c index 6cfaa6aa..c4f9288d 100644 --- a/examples/support/shared.c +++ b/examples/support/shared.c @@ -56,10 +56,24 @@ static void keyboard_key_notify(struct wl_listener *listener, void *data) { } } +static void keyboard_destroy_notify(struct wl_listener *listener, void *data) { + struct keyboard_state *kbstate = wl_container_of(listener, kbstate, destroy); + struct compositor_state *state = kbstate->compositor; + if (state->input_remove_cb) { + state->input_remove_cb(state, kbstate->device); + } + wl_list_remove(&kbstate->link); + wl_list_remove(&kbstate->destroy.link); + wl_list_remove(&kbstate->key.link); + free(kbstate); +} + static void keyboard_add(struct wlr_input_device *device, struct compositor_state *state) { struct keyboard_state *kbstate = calloc(sizeof(struct keyboard_state), 1); kbstate->device = device; kbstate->compositor = state; + kbstate->destroy.notify = keyboard_destroy_notify; + wl_signal_add(&device->events.destroy, &kbstate->destroy); kbstate->key.notify = keyboard_key_notify; wl_signal_add(&device->keyboard->events.key, &kbstate->key); wl_list_insert(&state->keyboards, &kbstate->link); @@ -117,17 +131,34 @@ static void pointer_axis_notify(struct wl_listener *listener, void *data) { } } +static void pointer_destroy_notify(struct wl_listener *listener, void *data) { + struct pointer_state *pstate = wl_container_of(listener, pstate, destroy); + struct compositor_state *state = pstate->compositor; + if (state->input_remove_cb) { + state->input_remove_cb(state, pstate->device); + } + wl_list_remove(&pstate->link); + wl_list_remove(&pstate->destroy.link); + wl_list_remove(&pstate->motion.link); + wl_list_remove(&pstate->motion_absolute.link); + wl_list_remove(&pstate->button.link); + wl_list_remove(&pstate->axis.link); + free(pstate); +} + static void pointer_add(struct wlr_input_device *device, struct compositor_state *state) { struct pointer_state *pstate = calloc(sizeof(struct pointer_state), 1); pstate->device = device; pstate->compositor = state; + pstate->destroy.notify = pointer_destroy_notify; + wl_signal_add(&device->events.destroy, &pstate->destroy); pstate->motion.notify = pointer_motion_notify; - pstate->motion_absolute.notify = pointer_motion_absolute_notify; - pstate->button.notify = pointer_button_notify; - pstate->axis.notify = pointer_axis_notify; wl_signal_add(&device->pointer->events.motion, &pstate->motion); + pstate->motion_absolute.notify = pointer_motion_absolute_notify; wl_signal_add(&device->pointer->events.motion_absolute, &pstate->motion_absolute); + pstate->button.notify = pointer_button_notify; wl_signal_add(&device->pointer->events.button, &pstate->button); + pstate->axis.notify = pointer_axis_notify; wl_signal_add(&device->pointer->events.axis, &pstate->axis); wl_list_insert(&state->pointers, &pstate->link); } @@ -166,17 +197,34 @@ static void touch_cancel_notify(struct wl_listener *listener, void *data) { } } +static void touch_destroy_notify(struct wl_listener *listener, void *data) { + struct touch_state *tstate = wl_container_of(listener, tstate, destroy); + struct compositor_state *state = tstate->compositor; + if (state->input_remove_cb) { + state->input_remove_cb(state, tstate->device); + } + wl_list_remove(&tstate->link); + wl_list_remove(&tstate->destroy.link); + wl_list_remove(&tstate->down.link); + wl_list_remove(&tstate->motion.link); + wl_list_remove(&tstate->up.link); + wl_list_remove(&tstate->cancel.link); + free(tstate); +} + static void touch_add(struct wlr_input_device *device, struct compositor_state *state) { struct touch_state *tstate = calloc(sizeof(struct touch_state), 1); tstate->device = device; tstate->compositor = state; + tstate->destroy.notify = touch_destroy_notify; + wl_signal_add(&device->events.destroy, &tstate->destroy); tstate->down.notify = touch_down_notify; - tstate->motion.notify = touch_motion_notify; - tstate->up.notify = touch_up_notify; - tstate->cancel.notify = touch_cancel_notify; wl_signal_add(&device->touch->events.down, &tstate->down); + tstate->motion.notify = touch_motion_notify; wl_signal_add(&device->touch->events.motion, &tstate->motion); + tstate->up.notify = touch_up_notify; wl_signal_add(&device->touch->events.up, &tstate->up); + tstate->cancel.notify = touch_cancel_notify; wl_signal_add(&device->touch->events.cancel, &tstate->cancel); wl_list_insert(&state->touch, &tstate->link); } @@ -205,18 +253,35 @@ static void tablet_tool_button_notify(struct wl_listener *listener, void *data) } } +static void tablet_tool_destroy_notify(struct wl_listener *listener, void *data) { + struct tablet_tool_state *tstate = wl_container_of(listener, tstate, destroy); + struct compositor_state *state = tstate->compositor; + if (state->input_remove_cb) { + state->input_remove_cb(state, tstate->device); + } + wl_list_remove(&tstate->link); + wl_list_remove(&tstate->destroy.link); + wl_list_remove(&tstate->axis.link); + wl_list_remove(&tstate->proximity.link); + //wl_list_remove(&tstate->tip.link); + wl_list_remove(&tstate->button.link); + free(tstate); +} + static void tablet_tool_add(struct wlr_input_device *device, struct compositor_state *state) { struct tablet_tool_state *tstate = calloc(sizeof(struct tablet_tool_state), 1); tstate->device = device; tstate->compositor = state; + tstate->destroy.notify = tablet_tool_destroy_notify; + wl_signal_add(&device->events.destroy, &tstate->destroy); tstate->axis.notify = tablet_tool_axis_notify; - tstate->proximity.notify = tablet_tool_proximity_notify; - //tstate->tip.notify = tablet_tool_tip_notify; - tstate->button.notify = tablet_tool_button_notify; wl_signal_add(&device->tablet_tool->events.axis, &tstate->axis); + tstate->proximity.notify = tablet_tool_proximity_notify; wl_signal_add(&device->tablet_tool->events.proximity, &tstate->proximity); + //tstate->tip.notify = tablet_tool_tip_notify; //wl_signal_add(&device->tablet_tool->events.tip, &tstate->tip); + tstate->button.notify = tablet_tool_button_notify; wl_signal_add(&device->tablet_tool->events.button, &tstate->button); wl_list_insert(&state->tablet_tools, &tstate->link); } @@ -229,19 +294,33 @@ static void tablet_pad_button_notify(struct wl_listener *listener, void *data) { } } +static void tablet_pad_destroy_notify(struct wl_listener *listener, void *data) { + struct tablet_pad_state *pstate = wl_container_of(listener, pstate, destroy); + struct compositor_state *state = pstate->compositor; + if (state->input_remove_cb) { + state->input_remove_cb(state, pstate->device); + } + wl_list_remove(&pstate->link); + wl_list_remove(&pstate->destroy.link); + wl_list_remove(&pstate->button.link); + free(pstate); +} + static void tablet_pad_add(struct wlr_input_device *device, struct compositor_state *state) { struct tablet_pad_state *pstate = calloc(sizeof(struct tablet_pad_state), 1); pstate->device = device; pstate->compositor = state; + pstate->destroy.notify = tablet_pad_destroy_notify; + wl_signal_add(&device->events.destroy, &pstate->destroy); pstate->button.notify = tablet_pad_button_notify; wl_signal_add(&device->tablet_pad->events.button, &pstate->button); wl_list_insert(&state->tablet_pads, &pstate->link); } -static void input_add_notify(struct wl_listener *listener, void *data) { +static void new_input_notify(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; - struct compositor_state *state = wl_container_of(listener, state, input_add); + struct compositor_state *state = wl_container_of(listener, state, new_input); switch (device->type) { case WLR_INPUT_DEVICE_KEYBOARD: keyboard_add(device, state); @@ -267,123 +346,6 @@ static void input_add_notify(struct wl_listener *listener, void *data) { } } -static void keyboard_remove(struct wlr_input_device *device, struct compositor_state *state) { - struct keyboard_state *kbstate = NULL, *_kbstate; - wl_list_for_each(_kbstate, &state->keyboards, link) { - if (_kbstate->device == device) { - kbstate = _kbstate; - break; - } - } - if (!kbstate) { - return; - } - wl_list_remove(&kbstate->link); - wl_list_remove(&kbstate->key.link); - free(kbstate); -} - -static void pointer_remove(struct wlr_input_device *device, struct compositor_state *state) { - struct pointer_state *pstate = NULL, *_pstate; - wl_list_for_each(_pstate, &state->pointers, link) { - if (_pstate->device == device) { - pstate = _pstate; - break; - } - } - if (!pstate) { - return; - } - wl_list_remove(&pstate->link); - wl_list_remove(&pstate->motion.link); - wl_list_remove(&pstate->motion_absolute.link); - wl_list_remove(&pstate->button.link); - wl_list_remove(&pstate->axis.link); - free(pstate); -} - -static void touch_remove(struct wlr_input_device *device, struct compositor_state *state) { - struct touch_state *tstate = NULL, *_tstate; - wl_list_for_each(_tstate, &state->touch, link) { - if (_tstate->device == device) { - tstate = _tstate; - break; - } - } - if (!tstate) { - return; - } - wl_list_remove(&tstate->link); - wl_list_remove(&tstate->down.link); - wl_list_remove(&tstate->motion.link); - wl_list_remove(&tstate->up.link); - wl_list_remove(&tstate->cancel.link); - free(tstate); -} - -static void tablet_tool_remove(struct wlr_input_device *device, struct compositor_state *state) { - struct tablet_tool_state *tstate = NULL, *_tstate; - wl_list_for_each(_tstate, &state->tablet_tools, link) { - if (_tstate->device == device) { - tstate = _tstate; - break; - } - } - if (!tstate) { - return; - } - wl_list_remove(&tstate->link); - wl_list_remove(&tstate->axis.link); - wl_list_remove(&tstate->proximity.link); - //wl_list_remove(&tstate->tip.link); - wl_list_remove(&tstate->button.link); - free(tstate); -} - -static void tablet_pad_remove(struct wlr_input_device *device, struct compositor_state *state) { - struct tablet_pad_state *pstate = NULL, *_pstate; - wl_list_for_each(_pstate, &state->tablet_pads, link) { - if (_pstate->device ==device) { - pstate = _pstate; - break; - } - } - if (!pstate) { - return; - } - wl_list_remove(&pstate->button.link); - free(pstate); -} - -static void input_remove_notify(struct wl_listener *listener, void *data) { - struct wlr_input_device *device = data; - struct compositor_state *state = wl_container_of(listener, state, input_remove); - - if (state->input_remove_cb) { - state->input_remove_cb(state, device); - } - - switch (device->type) { - case WLR_INPUT_DEVICE_KEYBOARD: - keyboard_remove(device, state); - break; - case WLR_INPUT_DEVICE_POINTER: - pointer_remove(device, state); - break; - case WLR_INPUT_DEVICE_TOUCH: - touch_remove(device, state); - break; - case WLR_INPUT_DEVICE_TABLET_TOOL: - tablet_tool_remove(device, state); - break; - case WLR_INPUT_DEVICE_TABLET_PAD: - tablet_pad_remove(device, state); - break; - default: - break; - } -} - static void output_frame_notify(struct wl_listener *listener, void *data) { struct output_state *output = wl_container_of(listener, output, frame); struct compositor_state *compositor = output->compositor; @@ -407,9 +369,21 @@ static void output_resolution_notify(struct wl_listener *listener, void *data) { } } -static void output_add_notify(struct wl_listener *listener, void *data) { +static void output_destroy_notify(struct wl_listener *listener, void *data) { + struct output_state *ostate = wl_container_of(listener, ostate, destroy); + struct compositor_state *state = ostate->compositor; + if (state->output_remove_cb) { + state->output_remove_cb(ostate); + } + wl_list_remove(&ostate->link); + wl_list_remove(&ostate->frame.link); + wl_list_remove(&ostate->resolution.link); + free(ostate); +} + +static void new_output_notify(struct wl_listener *listener, void *data) { struct wlr_output *output = data; - struct compositor_state *state = wl_container_of(listener, state, output_add); + struct compositor_state *state = wl_container_of(listener, state, new_output); wlr_log(L_DEBUG, "Output '%s' added", output->name); wlr_log(L_DEBUG, "%s %s %"PRId32"mm x %"PRId32"mm", output->make, output->model, output->phys_width, output->phys_height); @@ -422,9 +396,11 @@ static void output_add_notify(struct wl_listener *listener, void *data) { clock_gettime(CLOCK_MONOTONIC, &ostate->last_frame); ostate->output = output; ostate->compositor = state; + ostate->destroy.notify = output_destroy_notify; + wl_signal_add(&output->events.destroy, &ostate->destroy); ostate->frame.notify = output_frame_notify; - ostate->resolution.notify = output_resolution_notify; wl_signal_add(&output->events.frame, &ostate->frame); + ostate->resolution.notify = output_resolution_notify; wl_signal_add(&output->events.mode, &ostate->resolution); wl_list_insert(&state->outputs, &ostate->link); if (state->output_add_cb) { @@ -432,28 +408,6 @@ static void output_add_notify(struct wl_listener *listener, void *data) { } } -static void output_remove_notify(struct wl_listener *listener, void *data) { - struct wlr_output *output = data; - struct compositor_state *state = wl_container_of(listener, state, output_remove); - struct output_state *ostate = NULL, *_ostate; - wl_list_for_each(_ostate, &state->outputs, link) { - if (_ostate->output == output) { - ostate = _ostate; - break; - } - } - if (!ostate) { - return; // We are unfamiliar with this output - } - if (state->output_remove_cb) { - state->output_remove_cb(ostate); - } - wl_list_remove(&ostate->link); - wl_list_remove(&ostate->frame.link); - wl_list_remove(&ostate->resolution.link); - free(ostate); -} - void compositor_init(struct compositor_state *state) { state->display = wl_display_create(); state->event_loop = wl_display_get_event_loop(state->display); @@ -463,23 +417,19 @@ void compositor_init(struct compositor_state *state) { wl_list_init(&state->touch); wl_list_init(&state->tablet_tools); wl_list_init(&state->tablet_pads); - state->input_add.notify = input_add_notify; - state->input_remove.notify = input_remove_notify; - wl_list_init(&state->outputs); - state->output_add.notify = output_add_notify; - state->output_remove.notify = output_remove_notify; struct wlr_backend *wlr = wlr_backend_autocreate(state->display); if (!wlr) { exit(1); } - wl_signal_add(&wlr->events.input_add, &state->input_add); - wl_signal_add(&wlr->events.input_remove, &state->input_remove); - wl_signal_add(&wlr->events.output_add, &state->output_add); - wl_signal_add(&wlr->events.output_remove, &state->output_remove); state->backend = wlr; + wl_signal_add(&wlr->events.new_input, &state->new_input); + state->new_input.notify = new_input_notify; + wl_signal_add(&wlr->events.new_output, &state->new_output); + state->new_output.notify = new_output_notify; + clock_gettime(CLOCK_MONOTONIC, &state->last_frame); const char *socket = wl_display_add_socket_auto(state->display); diff --git a/examples/support/shared.h b/examples/support/shared.h index 014b709e..8cdea301 100644 --- a/examples/support/shared.h +++ b/examples/support/shared.h @@ -15,6 +15,7 @@ struct output_state { struct compositor_state *compositor; struct wlr_output *output; + struct wl_listener destroy; struct wl_listener frame; struct wl_listener resolution; struct timespec last_frame; @@ -25,6 +26,7 @@ struct output_state { struct keyboard_state { struct compositor_state *compositor; struct wlr_input_device *device; + struct wl_listener destroy; struct wl_listener key; struct wl_list link; void *data; @@ -33,6 +35,7 @@ struct keyboard_state { struct pointer_state { struct compositor_state *compositor; struct wlr_input_device *device; + struct wl_listener destroy; struct wl_listener motion; struct wl_listener motion_absolute; struct wl_listener button; @@ -44,6 +47,7 @@ struct pointer_state { struct touch_state { struct compositor_state *compositor; struct wlr_input_device *device; + struct wl_listener destroy; struct wl_listener down; struct wl_listener up; struct wl_listener motion; @@ -55,6 +59,7 @@ struct touch_state { struct tablet_tool_state { struct compositor_state *compositor; struct wlr_input_device *device; + struct wl_listener destroy; struct wl_listener axis; struct wl_listener proximity; struct wl_listener tip; @@ -66,6 +71,7 @@ struct tablet_tool_state { struct tablet_pad_state { struct compositor_state *compositor; struct wlr_input_device *device; + struct wl_listener destroy; struct wl_listener button; struct wl_list link; void *data; @@ -122,12 +128,10 @@ struct compositor_state { struct wl_list touch; struct wl_list tablet_tools; struct wl_list tablet_pads; - struct wl_listener input_add; - struct wl_listener input_remove; + struct wl_listener new_input; struct timespec last_frame; - struct wl_listener output_add; - struct wl_listener output_remove; + struct wl_listener new_output; struct wl_list outputs; void *data; diff --git a/include/backend/drm/drm.h b/include/backend/drm/drm.h index 12530da6..65db04ef 100644 --- a/include/backend/drm/drm.h +++ b/include/backend/drm/drm.h @@ -1,19 +1,17 @@ #ifndef BACKEND_DRM_DRM_H #define BACKEND_DRM_DRM_H +#include <EGL/egl.h> +#include <gbm.h> #include <stdbool.h> #include <stddef.h> #include <stdint.h> #include <wayland-server.h> -#include <xf86drmMode.h> -#include <EGL/egl.h> -#include <gbm.h> #include <wayland-util.h> - -#include <wlr/backend/session.h> #include <wlr/backend/drm.h> +#include <wlr/backend/session.h> #include <wlr/render/egl.h> - +#include <xf86drmMode.h> #include "iface.h" #include "properties.h" #include "renderer.h" diff --git a/include/backend/drm/iface.h b/include/backend/drm/iface.h index 15cdf1ab..ef0e7bf8 100644 --- a/include/backend/drm/iface.h +++ b/include/backend/drm/iface.h @@ -1,10 +1,9 @@ #ifndef BACKEND_DRM_IFACE_H #define BACKEND_DRM_IFACE_H +#include <gbm.h> #include <stdbool.h> #include <stdint.h> - -#include <gbm.h> #include <xf86drm.h> #include <xf86drmMode.h> diff --git a/include/backend/drm/renderer.h b/include/backend/drm/renderer.h index bf0165bc..a56a8673 100644 --- a/include/backend/drm/renderer.h +++ b/include/backend/drm/renderer.h @@ -1,12 +1,10 @@ #ifndef BACKEND_DRM_RENDERER_H #define BACKEND_DRM_RENDERER_H -#include <stdbool.h> -#include <stdint.h> - #include <EGL/egl.h> #include <gbm.h> - +#include <stdbool.h> +#include <stdint.h> #include <wlr/render.h> struct wlr_drm_backend; diff --git a/include/backend/drm/util.h b/include/backend/drm/util.h index 6818b4db..25da858f 100644 --- a/include/backend/drm/util.h +++ b/include/backend/drm/util.h @@ -2,9 +2,9 @@ #define BACKEND_DRM_UTIL_H #include <stdint.h> +#include <wlr/types/wlr_output.h> #include <xf86drm.h> #include <xf86drmMode.h> -#include <wlr/types/wlr_output.h> // Calculates a more accurate refresh rate (mHz) than what mode itself provides int32_t calculate_refresh_rate(drmModeModeInfo *mode); diff --git a/include/backend/headless.h b/include/backend/headless.h index f9805bcc..e130bae1 100644 --- a/include/backend/headless.h +++ b/include/backend/headless.h @@ -1,8 +1,8 @@ #ifndef BACKEND_HEADLESS_H #define BACKEND_HEADLESS_H -#include <wlr/backend/interface.h> #include <wlr/backend/headless.h> +#include <wlr/backend/interface.h> struct wlr_headless_backend { struct wlr_backend backend; diff --git a/include/backend/libinput.h b/include/backend/libinput.h index 6ec718c6..f828c310 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -1,10 +1,11 @@ #ifndef BACKEND_LIBINPUT_H #define BACKEND_LIBINPUT_H + #include <libinput.h> #include <wayland-server-core.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/backend/interface.h> #include <wlr/interfaces/wlr_input_device.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_list.h> struct wlr_libinput_backend { diff --git a/include/backend/multi.h b/include/backend/multi.h index 3363c608..c57c48f3 100644 --- a/include/backend/multi.h +++ b/include/backend/multi.h @@ -1,10 +1,10 @@ #ifndef BACKEND_MULTI_H #define BACKEND_MULTI_H +#include <wayland-util.h> #include <wlr/backend/interface.h> #include <wlr/backend/multi.h> #include <wlr/backend/session.h> -#include <wayland-util.h> struct wlr_multi_backend { struct wlr_backend backend; diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 78a88f29..16c8e13b 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -3,13 +3,13 @@ #include <stdbool.h> #include <wayland-client.h> -#include <wayland-server.h> #include <wayland-egl.h> -#include <wlr/render/egl.h> -#include <wlr/render.h> +#include <wayland-server.h> +#include <wayland-util.h> #include <wlr/backend/wayland.h> +#include <wlr/render.h> +#include <wlr/render/egl.h> #include <wlr/types/wlr_box.h> -#include <wayland-util.h> struct wlr_wl_backend { struct wlr_backend backend; diff --git a/include/backend/x11.h b/include/backend/x11.h index fee39eac..c5f258c0 100644 --- a/include/backend/x11.h +++ b/include/backend/x11.h @@ -1,11 +1,11 @@ -#ifndef WLR_X11_H -#define WLR_X11_H +#ifndef BACKEND_X11_H +#define BACKEND_X11_H #include <stdbool.h> -#include <xcb/xcb.h> -#include <X11/Xlib-xcb.h> #include <wayland-server.h> #include <wlr/render/egl.h> +#include <X11/Xlib-xcb.h> +#include <xcb/xcb.h> struct wlr_x11_backend; diff --git a/include/render/gles2.h b/include/render/gles2.h index 0b7032cc..797c5293 100644 --- a/include/render/gles2.h +++ b/include/render/gles2.h @@ -1,13 +1,13 @@ #ifndef RENDER_GLES2_H #define RENDER_GLES2_H -#include <stdint.h> -#include <string.h> -#include <stdbool.h> -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> #include <EGL/egl.h> #include <EGL/eglext.h> +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> +#include <stdbool.h> +#include <stdint.h> +#include <string.h> #include <wlr/backend.h> #include <wlr/render.h> #include <wlr/render/egl.h> diff --git a/include/rootston/config.h b/include/rootston/config.h index 05f23b75..9926d9c2 100644 --- a/include/rootston/config.h +++ b/include/rootston/config.h @@ -1,7 +1,8 @@ -#ifndef _ROOTSTON_CONFIG_H -#define _ROOTSTON_CONFIG_H -#include <wlr/types/wlr_output_layout.h> +#ifndef ROOTSTON_CONFIG_H +#define ROOTSTON_CONFIG_H + #include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_output_layout.h> #define ROOTS_CONFIG_DEFAULT_SEAT_NAME "seat0" diff --git a/include/rootston/cursor.h b/include/rootston/cursor.h index 90d54c12..a1a466c2 100644 --- a/include/rootston/cursor.h +++ b/include/rootston/cursor.h @@ -1,5 +1,5 @@ -#ifndef _ROOTSTON_CURSOR_H -#define _ROOTSTON_CURSOR_H +#ifndef ROOTSTON_CURSOR_H +#define ROOTSTON_CURSOR_H #include "rootston/seat.h" diff --git a/include/rootston/desktop.h b/include/rootston/desktop.h index 1232121a..6572b242 100644 --- a/include/rootston/desktop.h +++ b/include/rootston/desktop.h @@ -1,22 +1,23 @@ -#ifndef _ROOTSTON_DESKTOP_H -#define _ROOTSTON_DESKTOP_H +#ifndef ROOTSTON_DESKTOP_H +#define ROOTSTON_DESKTOP_H + #include <time.h> #include <wayland-server.h> #include <wlr/config.h> -#include <wlr/types/wlr_output.h> -#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_compositor.h> -#include <wlr/types/wlr_wl_shell.h> -#include <wlr/types/wlr_xdg_shell_v6.h> -#include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_gamma_control.h> +#include <wlr/types/wlr_idle.h> +#include <wlr/types/wlr_list.h> +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_screenshooter.h> -#include <wlr/types/wlr_list.h> -#include <wlr/types/wlr_idle.h> -#include "rootston/view.h" +#include <wlr/types/wlr_wl_shell.h> +#include <wlr/types/wlr_xcursor_manager.h> +#include <wlr/types/wlr_xdg_shell_v6.h> #include "rootston/config.h" #include "rootston/output.h" +#include "rootston/view.h" struct roots_desktop { struct wl_list views; // roots_view::link @@ -39,8 +40,7 @@ struct roots_desktop { struct wlr_primary_selection_device_manager *primary_selection_device_manager; struct wlr_idle *idle; - struct wl_listener output_add; - struct wl_listener output_remove; + struct wl_listener new_output; struct wl_listener layout_change; struct wl_listener xdg_shell_v6_surface; struct wl_listener wl_shell_surface; diff --git a/include/rootston/input.h b/include/rootston/input.h index 726dda24..4395a0f7 100644 --- a/include/rootston/input.h +++ b/include/rootston/input.h @@ -1,20 +1,20 @@ -#ifndef _ROOTSTON_INPUT_H -#define _ROOTSTON_INPUT_H +#ifndef ROOTSTON_INPUT_H +#define ROOTSTON_INPUT_H + #include <wayland-server.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_cursor.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_seat.h> -#include "rootston/cursor.h" #include "rootston/config.h" -#include "rootston/view.h" +#include "rootston/cursor.h" #include "rootston/server.h" +#include "rootston/view.h" struct roots_input { struct roots_config *config; struct roots_server *server; - struct wl_listener input_add; - struct wl_listener input_remove; + struct wl_listener new_input; struct wl_list seats; }; diff --git a/include/rootston/keyboard.h b/include/rootston/keyboard.h index 39650d7c..0140389a 100644 --- a/include/rootston/keyboard.h +++ b/include/rootston/keyboard.h @@ -1,5 +1,5 @@ -#ifndef _ROOTSTON_KEYBOARD_H -#define _ROOTSTON_KEYBOARD_H +#ifndef ROOTSTON_KEYBOARD_H +#define ROOTSTON_KEYBOARD_H #include <xkbcommon/xkbcommon.h> #include "rootston/input.h" @@ -13,6 +13,7 @@ struct roots_keyboard { struct roots_keyboard_config *config; struct wl_list link; + struct wl_listener device_destroy; struct wl_listener keyboard_key; struct wl_listener keyboard_modifiers; diff --git a/include/rootston/output.h b/include/rootston/output.h index 7f42904f..9682e4f5 100644 --- a/include/rootston/output.h +++ b/include/rootston/output.h @@ -1,8 +1,8 @@ -#ifndef _ROOTSTON_OUTPUT_H -#define _ROOTSTON_OUTPUT_H +#ifndef ROOTSTON_OUTPUT_H +#define ROOTSTON_OUTPUT_H -#include <time.h> #include <pixman.h> +#include <time.h> #include <wayland-server.h> #include <wlr/types/wlr_output_damage.h> @@ -18,11 +18,11 @@ struct roots_output { struct timespec last_frame; struct wlr_output_damage *damage; + struct wl_listener destroy; struct wl_listener frame; }; -void output_add_notify(struct wl_listener *listener, void *data); -void output_remove_notify(struct wl_listener *listener, void *data); +void handle_new_output(struct wl_listener *listener, void *data); struct roots_view; struct roots_drag_icon; diff --git a/include/rootston/seat.h b/include/rootston/seat.h index 0047522c..cc0293b5 100644 --- a/include/rootston/seat.h +++ b/include/rootston/seat.h @@ -1,5 +1,6 @@ -#ifndef _ROOTSTON_SEAT_H -#define _ROOTSTON_SEAT_H +#ifndef ROOTSTON_SEAT_H +#define ROOTSTON_SEAT_H + #include <wayland-server.h> #include "rootston/input.h" #include "rootston/keyboard.h" @@ -56,18 +57,21 @@ struct roots_drag_icon { struct roots_pointer { struct roots_seat *seat; struct wlr_input_device *device; + struct wl_listener device_destroy; struct wl_list link; }; struct roots_touch { struct roots_seat *seat; struct wlr_input_device *device; + struct wl_listener device_destroy; struct wl_list link; }; struct roots_tablet_tool { struct roots_seat *seat; struct wlr_input_device *device; + struct wl_listener device_destroy; struct wl_listener axis; struct wl_listener proximity; struct wl_listener tip; diff --git a/include/rootston/server.h b/include/rootston/server.h index 0c26ea92..5f35dd90 100644 --- a/include/rootston/server.h +++ b/include/rootston/server.h @@ -1,11 +1,12 @@ #ifndef _ROOTSTON_SERVER_H #define _ROOTSTON_SERVER_H + #include <wayland-server.h> -#include <wlr/config.h> #include <wlr/backend.h> #include <wlr/backend/session.h> -#include <wlr/types/wlr_data_device.h> +#include <wlr/config.h> #include <wlr/render.h> +#include <wlr/types/wlr_data_device.h> #ifdef WLR_HAS_XWAYLAND #include <wlr/xwayland.h> #endif diff --git a/include/rootston/view.h b/include/rootston/view.h index f6968c7a..b61ac330 100644 --- a/include/rootston/view.h +++ b/include/rootston/view.h @@ -1,5 +1,5 @@ -#ifndef _ROOTSTON_VIEW_H -#define _ROOTSTON_VIEW_H +#ifndef ROOTSTON_VIEW_H +#define ROOTSTON_VIEW_H #include <stdbool.h> #include <wlr/config.h> diff --git a/include/rootston/xcursor.h b/include/rootston/xcursor.h index a7d2b960..f78489a4 100644 --- a/include/rootston/xcursor.h +++ b/include/rootston/xcursor.h @@ -1,5 +1,5 @@ -#ifndef _ROOTSTON_XCURSOR_H -#define _ROOTSTON_XCURSOR_H +#ifndef ROOTSTON_XCURSOR_H +#define ROOTSTON_XCURSOR_H #include <stdint.h> diff --git a/include/util/os-compatibility.h b/include/util/os-compatibility.h index b2ec2db9..2038025e 100644 --- a/include/util/os-compatibility.h +++ b/include/util/os-compatibility.h @@ -1,12 +1,9 @@ -#ifndef _WLR_UTIL_OS_COMPATIBILITY_H -#define _WLR_UTIL_OS_COMPATIBILITY_H +#ifndef UTIL_OS_COMPATIBILITY_H +#define UTIL_OS_COMPATIBILITY_H int os_fd_set_cloexec(int fd); - int set_cloexec_or_close(int fd); - int create_tmpfile_cloexec(char *tmpname); - int os_create_anonymous_file(off_t size); #endif diff --git a/include/util/signal.h b/include/util/signal.h new file mode 100644 index 00000000..cc6cb525 --- /dev/null +++ b/include/util/signal.h @@ -0,0 +1,8 @@ +#ifndef UTIL_SIGNAL_H +#define UTIL_SIGNAL_H + +#include <wayland-server.h> + +void wlr_signal_emit_safe(struct wl_signal *signal, void *data); + +#endif diff --git a/include/wlr/backend.h b/include/wlr/backend.h index d4b1f773..00dc9fdc 100644 --- a/include/wlr/backend.h +++ b/include/wlr/backend.h @@ -12,10 +12,8 @@ struct wlr_backend { struct { struct wl_signal destroy; - struct wl_signal input_add; - struct wl_signal input_remove; - struct wl_signal output_add; - struct wl_signal output_remove; + struct wl_signal new_input; + struct wl_signal new_output; } events; }; diff --git a/include/wlr/backend/drm.h b/include/wlr/backend/drm.h index 133e4f69..90460647 100644 --- a/include/wlr/backend/drm.h +++ b/include/wlr/backend/drm.h @@ -2,8 +2,8 @@ #define WLR_BACKEND_DRM_H #include <wayland-server.h> -#include <wlr/backend/session.h> #include <wlr/backend.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_output.h> struct wlr_backend *wlr_drm_backend_create(struct wl_display *display, diff --git a/include/wlr/backend/libinput.h b/include/wlr/backend/libinput.h index af873628..c7cfe894 100644 --- a/include/wlr/backend/libinput.h +++ b/include/wlr/backend/libinput.h @@ -3,8 +3,8 @@ #include <libinput.h> #include <wayland-server.h> -#include <wlr/backend/session.h> #include <wlr/backend.h> +#include <wlr/backend/session.h> #include <wlr/types/wlr_input_device.h> struct wlr_backend *wlr_libinput_backend_create(struct wl_display *display, diff --git a/include/wlr/backend/multi.h b/include/wlr/backend/multi.h index d9914efc..2dee7403 100644 --- a/include/wlr/backend/multi.h +++ b/include/wlr/backend/multi.h @@ -5,17 +5,12 @@ #include <wlr/backend/session.h> struct wlr_backend *wlr_multi_backend_create(struct wl_display *display); - void wlr_multi_backend_add(struct wlr_backend *multi, struct wlr_backend *backend); - void wlr_multi_backend_remove(struct wlr_backend *multi, struct wlr_backend *backend); - bool wlr_backend_is_multi(struct wlr_backend *backend); - struct wlr_session *wlr_multi_get_session(struct wlr_backend *base); - bool wlr_multi_is_empty(struct wlr_backend *backend); #endif diff --git a/include/wlr/backend/session.h b/include/wlr/backend/session.h index 3242a13f..7ff9691f 100644 --- a/include/wlr/backend/session.h +++ b/include/wlr/backend/session.h @@ -1,10 +1,10 @@ #ifndef WLR_BACKEND_SESSION_H #define WLR_BACKEND_SESSION_H -#include <stdbool.h> -#include <wayland-server.h> #include <libudev.h> +#include <stdbool.h> #include <sys/types.h> +#include <wayland-server.h> struct session_impl; diff --git a/include/wlr/backend/wayland.h b/include/wlr/backend/wayland.h index f89a6383..e28ffff5 100644 --- a/include/wlr/backend/wayland.h +++ b/include/wlr/backend/wayland.h @@ -1,12 +1,12 @@ #ifndef WLR_BACKEND_WAYLAND_H #define WLR_BACKEND_WAYLAND_H +#include <stdbool.h> #include <wayland-client.h> #include <wayland-server.h> #include <wlr/backend.h> #include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_output.h> -#include <stdbool.h> /** * Creates a new wlr_wl_backend. This backend will be created with no outputs; diff --git a/include/wlr/interfaces/wlr_keyboard.h b/include/wlr/interfaces/wlr_keyboard.h index 570f5721..6960ea87 100644 --- a/include/wlr/interfaces/wlr_keyboard.h +++ b/include/wlr/interfaces/wlr_keyboard.h @@ -1,8 +1,8 @@ #ifndef WLR_INTERFACES_WLR_KEYBOARD_H #define WLR_INTERFACES_WLR_KEYBOARD_H -#include <wlr/types/wlr_keyboard.h> #include <stdint.h> +#include <wlr/types/wlr_keyboard.h> struct wlr_keyboard_impl { void (*destroy)(struct wlr_keyboard *keyboard); diff --git a/include/wlr/interfaces/wlr_output.h b/include/wlr/interfaces/wlr_output.h index a01f8901..5edd1ae1 100644 --- a/include/wlr/interfaces/wlr_output.h +++ b/include/wlr/interfaces/wlr_output.h @@ -2,9 +2,9 @@ #define WLR_INTERFACES_WLR_OUTPUT_H #include <stdbool.h> +#include <wlr/backend.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_output.h> -#include <wlr/backend.h> struct wlr_output_impl { void (*enable)(struct wlr_output *output, bool enable); diff --git a/include/wlr/render.h b/include/wlr/render.h index ccc66d36..3743482b 100644 --- a/include/wlr/render.h +++ b/include/wlr/render.h @@ -1,9 +1,9 @@ #ifndef WLR_RENDER_H #define WLR_RENDER_H -#include <stdint.h> #include <EGL/egl.h> #include <EGL/eglext.h> +#include <stdint.h> #include <wayland-server-protocol.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_output.h> diff --git a/include/wlr/render/egl.h b/include/wlr/render/egl.h index 1facc6b8..97a28016 100644 --- a/include/wlr/render/egl.h +++ b/include/wlr/render/egl.h @@ -1,10 +1,10 @@ -#ifndef WLR_EGL_H -#define WLR_EGL_H +#ifndef WLR_RENDER_EGL_H +#define WLR_RENDER_EGL_H -#include <stdbool.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include <pixman.h> +#include <stdbool.h> #include <wayland-server.h> struct wlr_egl { diff --git a/include/wlr/render/gles2.h b/include/wlr/render/gles2.h index 25e760d5..a924a065 100644 --- a/include/wlr/render/gles2.h +++ b/include/wlr/render/gles2.h @@ -1,8 +1,8 @@ #ifndef WLR_RENDER_GLES2_H #define WLR_RENDER_GLES2_H -#include <wlr/render.h> #include <wlr/backend.h> +#include <wlr/render.h> struct wlr_egl; struct wlr_renderer *wlr_gles2_renderer_create(struct wlr_backend *backend); diff --git a/include/wlr/render/interface.h b/include/wlr/render/interface.h index b8e99898..b989e399 100644 --- a/include/wlr/render/interface.h +++ b/include/wlr/render/interface.h @@ -1,10 +1,10 @@ #ifndef WLR_RENDER_INTERFACE_H #define WLR_RENDER_INTERFACE_H -#include <wayland-server-protocol.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include <stdbool.h> +#include <wayland-server-protocol.h> #include <wlr/render.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_output.h> diff --git a/include/wlr/types/wlr_cursor.h b/include/wlr/types/wlr_cursor.h index e072ca05..da010972 100644 --- a/include/wlr/types/wlr_cursor.h +++ b/include/wlr/types/wlr_cursor.h @@ -2,10 +2,10 @@ #define WLR_TYPES_WLR_CURSOR_H #include <wayland-server.h> -#include <wlr/types/wlr_output.h> -#include <wlr/types/wlr_output_layout.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_output.h> struct wlr_cursor_state; diff --git a/include/wlr/types/wlr_keyboard.h b/include/wlr/types/wlr_keyboard.h index c67cc4c2..ed0427e8 100644 --- a/include/wlr/types/wlr_keyboard.h +++ b/include/wlr/types/wlr_keyboard.h @@ -1,9 +1,9 @@ #ifndef WLR_TYPES_WLR_KEYBOARD_H #define WLR_TYPES_WLR_KEYBOARD_H -#include <wayland-server.h> -#include <stdint.h> #include <stdbool.h> +#include <stdint.h> +#include <wayland-server.h> #include <wayland-server.h> #include <xkbcommon/xkbcommon.h> diff --git a/include/wlr/types/wlr_list.h b/include/wlr/types/wlr_list.h index 78a30995..23bf53b7 100644 --- a/include/wlr/types/wlr_list.h +++ b/include/wlr/types/wlr_list.h @@ -1,8 +1,8 @@ -#ifndef WLR_UTIL_LIST_H -#define WLR_UTIL_LIST_H +#ifndef WLR_TYPES_WLR_LIST_H +#define WLR_TYPES_WLR_LIST_H -#include <stddef.h> #include <stdbool.h> +#include <stddef.h> struct wlr_list { size_t capacity; diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 8eed06fe..5c2ffee0 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -1,11 +1,11 @@ #ifndef WLR_TYPES_WLR_OUTPUT_H #define WLR_TYPES_WLR_OUTPUT_H +#include <pixman.h> #include <stdbool.h> #include <time.h> -#include <pixman.h> -#include <wayland-util.h> #include <wayland-server.h> +#include <wayland-util.h> struct wlr_output_mode { uint32_t flags; // enum wl_output_mode diff --git a/include/wlr/types/wlr_output_damage.h b/include/wlr/types/wlr_output_damage.h index 52cbce78..6682f942 100644 --- a/include/wlr/types/wlr_output_damage.h +++ b/include/wlr/types/wlr_output_damage.h @@ -1,8 +1,8 @@ #ifndef WLR_TYPES_WLR_OUTPUT_DAMAGE_H #define WLR_TYPES_WLR_OUTPUT_DAMAGE_H -#include <time.h> #include <pixman.h> +#include <time.h> #include <wlr/types/wlr_output.h> /** diff --git a/include/wlr/types/wlr_output_layout.h b/include/wlr/types/wlr_output_layout.h index 9187b377..7dd2b16a 100644 --- a/include/wlr/types/wlr_output_layout.h +++ b/include/wlr/types/wlr_output_layout.h @@ -1,10 +1,10 @@ #ifndef WLR_TYPES_WLR_OUTPUT_LAYOUT_H #define WLR_TYPES_WLR_OUTPUT_LAYOUT_H +#include <stdbool.h> +#include <wayland-util.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_output.h> -#include <wayland-util.h> -#include <stdbool.h> struct wlr_output_layout_state; diff --git a/include/wlr/types/wlr_pointer.h b/include/wlr/types/wlr_pointer.h index 3a6d2175..e7ac9b46 100644 --- a/include/wlr/types/wlr_pointer.h +++ b/include/wlr/types/wlr_pointer.h @@ -1,9 +1,9 @@ #ifndef WLR_TYPES_WLR_POINTER_H #define WLR_TYPES_WLR_POINTER_H -#include <wlr/types/wlr_input_device.h> -#include <wayland-server.h> #include <stdint.h> +#include <wayland-server.h> +#include <wlr/types/wlr_input_device.h> struct wlr_pointer_impl; diff --git a/include/wlr/types/wlr_primary_selection.h b/include/wlr/types/wlr_primary_selection.h index da3c096a..78f23ad6 100644 --- a/include/wlr/types/wlr_primary_selection.h +++ b/include/wlr/types/wlr_primary_selection.h @@ -1,8 +1,8 @@ #ifndef WLR_TYPES_WLR_PRIMARY_SELECTION_H #define WLR_TYPES_WLR_PRIMARY_SELECTION_H -#include <wlr/types/wlr_seat.h> #include <wayland-server.h> +#include <wlr/types/wlr_seat.h> struct wlr_primary_selection_device_manager { struct wl_global *global; diff --git a/include/wlr/types/wlr_screenshooter.h b/include/wlr/types/wlr_screenshooter.h index cfe7742d..680d86f0 100644 --- a/include/wlr/types/wlr_screenshooter.h +++ b/include/wlr/types/wlr_screenshooter.h @@ -1,5 +1,6 @@ -#ifndef _WLR_SCREENSHOOTER_H -#define _WLR_SCREENSHOOTER_H +#ifndef WLR_TYPES_WLR_SCREENSHOOTER_H +#define WLR_TYPES_WLR_SCREENSHOOTER_H + #include <wayland-server.h> struct wlr_screenshooter { diff --git a/include/wlr/types/wlr_seat.h b/include/wlr/types/wlr_seat.h index ffdabd98..b03cab6e 100644 --- a/include/wlr/types/wlr_seat.h +++ b/include/wlr/types/wlr_seat.h @@ -1,10 +1,11 @@ #ifndef WLR_TYPES_WLR_SEAT_H #define WLR_TYPES_WLR_SEAT_H + #include <time.h> -#include <wlr/types/wlr_surface.h> +#include <wayland-server.h> #include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_keyboard.h> -#include <wayland-server.h> +#include <wlr/types/wlr_surface.h> /** * Contains state for a single client's bound wl_seat resource and can be used diff --git a/include/wlr/types/wlr_surface.h b/include/wlr/types/wlr_surface.h index 50316abc..998b5ae5 100644 --- a/include/wlr/types/wlr_surface.h +++ b/include/wlr/types/wlr_surface.h @@ -1,9 +1,10 @@ #ifndef WLR_TYPES_WLR_SURFACE_H #define WLR_TYPES_WLR_SURFACE_H -#include <stdint.h> + +#include <pixman.h> #include <stdbool.h> +#include <stdint.h> #include <time.h> -#include <pixman.h> #include <wayland-server.h> #include <wlr/types/wlr_output.h> diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index 51a65dd1..e70db516 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -1,9 +1,9 @@ #ifndef WLR_TYPES_WLR_TABLET_PAD_H #define WLR_TYPES_WLR_TABLET_PAD_H -#include <wlr/types/wlr_input_device.h> -#include <wayland-server.h> #include <stdint.h> +#include <wayland-server.h> +#include <wlr/types/wlr_input_device.h> /* * NOTE: the wlr tablet pad implementation does not currently support tablets diff --git a/include/wlr/types/wlr_tablet_tool.h b/include/wlr/types/wlr_tablet_tool.h index c6984d4d..59e49ef8 100644 --- a/include/wlr/types/wlr_tablet_tool.h +++ b/include/wlr/types/wlr_tablet_tool.h @@ -1,9 +1,9 @@ #ifndef WLR_TYPES_TABLET_TOOL_H #define WLR_TYPES_TABLET_TOOL_H -#include <wlr/types/wlr_input_device.h> -#include <wayland-server.h> #include <stdint.h> +#include <wayland-server.h> +#include <wlr/types/wlr_input_device.h> struct wlr_tablet_tool_impl; diff --git a/include/wlr/types/wlr_touch.h b/include/wlr/types/wlr_touch.h index 2925fd01..8ea293eb 100644 --- a/include/wlr/types/wlr_touch.h +++ b/include/wlr/types/wlr_touch.h @@ -1,8 +1,8 @@ #ifndef WLR_TYPES_WLR_TOUCH_H #define WLR_TYPES_WLR_TOUCH_H -#include <wayland-server.h> #include <stdint.h> +#include <wayland-server.h> struct wlr_touch_impl; diff --git a/include/wlr/types/wlr_xdg_shell_v6.h b/include/wlr/types/wlr_xdg_shell_v6.h index c7b1a24b..7dc746ce 100644 --- a/include/wlr/types/wlr_xdg_shell_v6.h +++ b/include/wlr/types/wlr_xdg_shell_v6.h @@ -1,9 +1,9 @@ #ifndef WLR_TYPES_WLR_XDG_SHELL_V6_H #define WLR_TYPES_WLR_XDG_SHELL_V6_H +#include <wayland-server.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_seat.h> -#include <wayland-server.h> struct wlr_xdg_shell_v6 { struct wl_global *wl_global; diff --git a/include/wlr/xwayland.h b/include/wlr/xwayland.h index c0135943..ad7ceb83 100644 --- a/include/wlr/xwayland.h +++ b/include/wlr/xwayland.h @@ -1,8 +1,8 @@ #ifndef WLR_XWAYLAND_H #define WLR_XWAYLAND_H -#include <time.h> #include <stdbool.h> +#include <time.h> #include <wlr/config.h> #include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_seat.h> diff --git a/include/wlr/xwm.h b/include/wlr/xwm.h index 35c43b18..242ff9cc 100644 --- a/include/wlr/xwm.h +++ b/include/wlr/xwm.h @@ -1,9 +1,9 @@ -#ifndef XWAYLAND_INTERNALS_H -#define XWAYLAND_INTERNALS_H +#ifndef WLR_XWM_H +#define WLR_XWM_H -#include <xcb/render.h> #include <wayland-server-core.h> #include <wlr/xwayland.h> +#include <xcb/render.h> enum atom_name { WL_SURFACE_ID, diff --git a/meson.build b/meson.build index 6c8a3a8b..1cf7781a 100644 --- a/meson.build +++ b/meson.build @@ -157,16 +157,16 @@ wlroots = declare_dependency( summary = [ - '', - '----------------', - 'wlroots @0@'.format(meson.project_version()), - '', - ' libcap: @0@'.format(conf_data.get('WLR_HAS_LIBCAP', false)), - ' systemd: @0@'.format(conf_data.get('WLR_HAS_SYSTEMD', false)), - ' elogind: @0@'.format(conf_data.get('WLR_HAS_ELOGIND', false)), - ' xwayland: @0@'.format(conf_data.get('WLR_HAS_XWAYLAND', false)), - '----------------', - '' + '', + '----------------', + 'wlroots @0@'.format(meson.project_version()), + '', + ' libcap: @0@'.format(conf_data.get('WLR_HAS_LIBCAP', false)), + ' systemd: @0@'.format(conf_data.get('WLR_HAS_SYSTEMD', false)), + ' elogind: @0@'.format(conf_data.get('WLR_HAS_ELOGIND', false)), + ' xwayland: @0@'.format(conf_data.get('WLR_HAS_XWAYLAND', false)), + '----------------', + '' ] message('\n'.join(summary)) @@ -195,18 +195,18 @@ if git.found() etags = find_program('etags', required: false) if etags.found() and all_files.length() > 0 custom_target('etags', - build_by_default: true, - input: all_files, - output: 'TAGS', - command: [etags.path(), '-o', 'TAGS'] + all_files) + build_by_default: true, + input: all_files, + output: 'TAGS', + command: [etags.path(), '-o', 'TAGS'] + all_files) endif ctags = find_program('ctags', required: false) if ctags.found() and all_files.length() > 0 custom_target('ctags', - build_by_default: true, - input: all_files, - output: 'tags', - command: [ctags.path(), '-o', 'tags'] + all_files) + build_by_default: true, + input: all_files, + output: 'tags', + command: [ctags.path(), '-o', 'tags'] + all_files) endif endif diff --git a/protocol/meson.build b/protocol/meson.build index 6e9f4125..0db7c03c 100644 --- a/protocol/meson.build +++ b/protocol/meson.build @@ -24,18 +24,18 @@ protocols = [ [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], 'gamma-control.xml', 'gtk-primary-selection.xml', + 'idle.xml', 'screenshooter.xml', 'server-decoration.xml', - 'idle.xml', ] client_protocols = [ [wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml'], 'gamma-control.xml', 'gtk-primary-selection.xml', + 'idle.xml', 'screenshooter.xml', 'server-decoration.xml', - 'idle.xml', ] wl_protos_src = [] diff --git a/render/egl.c b/render/egl.c index 328726ba..f1208a72 100644 --- a/render/egl.c +++ b/render/egl.c @@ -1,10 +1,10 @@ #include <assert.h> -#include <stdlib.h> #include <EGL/egl.h> #include <EGL/eglext.h> #include <GLES2/gl2.h> -#include <wlr/util/log.h> +#include <stdlib.h> #include <wlr/render/egl.h> +#include <wlr/util/log.h> #include "glapi.h" // Extension documentation diff --git a/render/gles2/renderer.c b/render/gles2/renderer.c index f57e9dae..81a932e6 100644 --- a/render/gles2/renderer.c +++ b/render/gles2/renderer.c @@ -1,10 +1,10 @@ -#include <stdint.h> -#include <stdlib.h> #include <assert.h> #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> -#include <wayland-util.h> +#include <stdint.h> +#include <stdlib.h> #include <wayland-server-protocol.h> +#include <wayland-util.h> #include <wlr/backend.h> #include <wlr/render.h> #include <wlr/render/egl.h> diff --git a/render/gles2/shaders.c b/render/gles2/shaders.c index ff6fba9c..46a10248 100644 --- a/render/gles2/shaders.c +++ b/render/gles2/shaders.c @@ -1,5 +1,5 @@ -#include "render/gles2.h" #include <GLES2/gl2.h> +#include "render/gles2.h" // Colored quads const GLchar quad_vertex_src[] = diff --git a/render/gles2/texture.c b/render/gles2/texture.c index ff71cb08..688a51d8 100644 --- a/render/gles2/texture.c +++ b/render/gles2/texture.c @@ -1,16 +1,17 @@ -#include <stdint.h> -#include <stdlib.h> #include <assert.h> #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> -#include <wayland-util.h> +#include <stdint.h> +#include <stdlib.h> #include <wayland-server-protocol.h> +#include <wayland-util.h> #include <wlr/render.h> #include <wlr/render/egl.h> #include <wlr/render/interface.h> #include <wlr/render/matrix.h> #include <wlr/util/log.h> #include "render/gles2.h" +#include "util/signal.h" static struct pixel_format external_pixel_format = { .wl_format = 0, @@ -271,7 +272,7 @@ static void gles2_texture_bind(struct wlr_texture *_texture) { static void gles2_texture_destroy(struct wlr_texture *_texture) { struct wlr_gles2_texture *texture = (struct wlr_gles2_texture *)_texture; - wl_signal_emit(&texture->wlr_texture.destroy_signal, &texture->wlr_texture); + wlr_signal_emit_safe(&texture->wlr_texture.destroy_signal, &texture->wlr_texture); if (texture->tex_id) { GL_CALL(glDeleteTextures(1, &texture->tex_id)); } diff --git a/render/gles2/util.c b/render/gles2/util.c index 9498a1cd..c291f533 100644 --- a/render/gles2/util.c +++ b/render/gles2/util.c @@ -1,6 +1,6 @@ -#include <stdlib.h> -#include <stdbool.h> #include <GLES2/gl2.h> +#include <stdbool.h> +#include <stdlib.h> #include <wlr/util/log.h> #include "render/gles2.h" diff --git a/render/matrix.c b/render/matrix.c index fa45dd04..d5d7f49d 100644 --- a/render/matrix.c +++ b/render/matrix.c @@ -1,9 +1,9 @@ -#include <string.h> #include <math.h> +#include <string.h> #include <wayland-server-protocol.h> +#include <wlr/render/matrix.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_output.h> -#include <wlr/render/matrix.h> /* Obtains the index for the given row/column */ static inline int mind(int row, int col) { diff --git a/render/meson.build b/render/meson.build index 309e83cd..1a5a85b8 100644 --- a/render/meson.build +++ b/render/meson.build @@ -10,12 +10,12 @@ lib_wlr_render = static_library( 'wlr_render', files( 'egl.c', - 'matrix.c', 'gles2/pixel_format.c', 'gles2/renderer.c', 'gles2/shaders.c', 'gles2/texture.c', 'gles2/util.c', + 'matrix.c', 'wlr_renderer.c', 'wlr_texture.c', ), diff --git a/render/wlr_renderer.c b/render/wlr_renderer.c index c8f06a64..fa6c6fc3 100644 --- a/render/wlr_renderer.c +++ b/render/wlr_renderer.c @@ -1,5 +1,5 @@ -#include <stdlib.h> #include <stdbool.h> +#include <stdlib.h> #include <wlr/render/interface.h> void wlr_renderer_init(struct wlr_renderer *renderer, diff --git a/render/wlr_texture.c b/render/wlr_texture.c index 4ce86bdd..a82a16b2 100644 --- a/render/wlr_texture.c +++ b/render/wlr_texture.c @@ -1,5 +1,5 @@ -#include <stdlib.h> #include <stdbool.h> +#include <stdlib.h> #include <wlr/render/interface.h> void wlr_texture_init(struct wlr_texture *texture, diff --git a/rootston/config.c b/rootston/config.c index 26cbd12d..e63efc0b 100644 --- a/rootston/config.c +++ b/rootston/config.c @@ -2,20 +2,20 @@ #define _POSIX_C_SOURCE 200809L #endif #include <assert.h> -#include <stdlib.h> -#include <limits.h> #include <getopt.h> +#include <limits.h> +#include <stdlib.h> #include <string.h> #include <strings.h> -#include <unistd.h> #include <sys/param.h> +#include <unistd.h> #include <wlr/config.h> -#include <wlr/util/log.h> #include <wlr/types/wlr_box.h> +#include <wlr/util/log.h> #include "rootston/config.h" +#include "rootston/ini.h" #include "rootston/input.h" #include "rootston/keyboard.h" -#include "rootston/ini.h" static void usage(const char *name, int ret) { fprintf(stderr, diff --git a/rootston/cursor.c b/rootston/cursor.c index ab32a5de..aa94daeb 100644 --- a/rootston/cursor.c +++ b/rootston/cursor.c @@ -1,16 +1,16 @@ #define _XOPEN_SOURCE 700 -#include <stdlib.h> #include <math.h> +#include <stdlib.h> +#include <wlr/types/wlr_xcursor_manager.h> +#include <wlr/util/edges.h> +#include <wlr/util/log.h> #ifdef __linux__ #include <linux/input-event-codes.h> #elif __FreeBSD__ #include <dev/evdev/input-event-codes.h> #endif -#include <wlr/types/wlr_xcursor_manager.h> -#include <wlr/util/log.h> -#include <wlr/util/edges.h> -#include "rootston/xcursor.h" #include "rootston/cursor.h" +#include "rootston/xcursor.h" struct roots_cursor *roots_cursor_create(struct roots_seat *seat) { struct roots_cursor *cursor = calloc(1, sizeof(struct roots_cursor)); diff --git a/rootston/desktop.c b/rootston/desktop.c index 91661c05..80ccbc25 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -1,25 +1,25 @@ #define _POSIX_C_SOURCE 199309L #include <assert.h> -#include <time.h> -#include <stdlib.h> #include <math.h> +#include <stdlib.h> +#include <time.h> #include <wlr/config.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_compositor.h> #include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_gamma_control.h> #include <wlr/types/wlr_idle.h> +#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_server_decoration.h> -#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_xcursor_manager.h> #include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/util/log.h> -#include "rootston/server.h" #include "rootston/seat.h" -#include "rootston/xcursor.h" +#include "rootston/server.h" #include "rootston/view.h" +#include "rootston/xcursor.h" void view_get_box(const struct roots_view *view, struct wlr_box *box) { box->x = view->x; @@ -621,11 +621,8 @@ struct roots_desktop *desktop_create(struct roots_server *server, wl_list_init(&desktop->views); wl_list_init(&desktop->outputs); - desktop->output_add.notify = output_add_notify; - wl_signal_add(&server->backend->events.output_add, &desktop->output_add); - desktop->output_remove.notify = output_remove_notify; - wl_signal_add(&server->backend->events.output_remove, - &desktop->output_remove); + desktop->new_output.notify = handle_new_output; + wl_signal_add(&server->backend->events.new_output, &desktop->new_output); desktop->server = server; desktop->config = config; diff --git a/rootston/input.c b/rootston/input.c index 74ce59d0..657b0946 100644 --- a/rootston/input.c +++ b/rootston/input.c @@ -1,16 +1,16 @@ #include <assert.h> #include <stdlib.h> #include <wayland-server.h> +#include <wlr/backend/libinput.h> #include <wlr/types/wlr_cursor.h> #include <wlr/util/log.h> #include <wlr/xcursor.h> #include <wlr/xwayland.h> -#include <wlr/backend/libinput.h> -#include "rootston/server.h" #include "rootston/config.h" #include "rootston/input.h" #include "rootston/keyboard.h" #include "rootston/seat.h" +#include "rootston/server.h" static const char *device_type(enum wlr_input_device_type type) { switch (type) { @@ -40,9 +40,9 @@ struct roots_seat *input_get_seat(struct roots_input *input, char *name) { return seat; } -static void input_add_notify(struct wl_listener *listener, void *data) { +static void handle_new_input(struct wl_listener *listener, void *data) { struct wlr_input_device *device = data; - struct roots_input *input = wl_container_of(listener, input, input_add); + struct roots_input *input = wl_container_of(listener, input, new_input); char *seat_name = ROOTS_CONFIG_DEFAULT_SEAT_NAME; struct roots_device_config *dc = @@ -74,16 +74,6 @@ static void input_add_notify(struct wl_listener *listener, void *data) { } } -static void input_remove_notify(struct wl_listener *listener, void *data) { - struct wlr_input_device *device = data; - struct roots_input *input = wl_container_of(listener, input, input_remove); - - struct roots_seat *seat; - wl_list_for_each(seat, &input->seats, link) { - roots_seat_remove_device(seat, device); - } -} - struct roots_input *input_create(struct roots_server *server, struct roots_config *config) { wlr_log(L_DEBUG, "Initializing roots input"); @@ -99,10 +89,8 @@ struct roots_input *input_create(struct roots_server *server, wl_list_init(&input->seats); - input->input_add.notify = input_add_notify; - wl_signal_add(&server->backend->events.input_add, &input->input_add); - input->input_remove.notify = input_remove_notify; - wl_signal_add(&server->backend->events.input_remove, &input->input_remove); + input->new_input.notify = handle_new_input; + wl_signal_add(&server->backend->events.new_input, &input->new_input); return input; } diff --git a/rootston/keyboard.c b/rootston/keyboard.c index ddf541b4..6ec90c31 100644 --- a/rootston/keyboard.c +++ b/rootston/keyboard.c @@ -1,18 +1,18 @@ #include <assert.h> +#include <stdbool.h> #include <stdint.h> #include <stdlib.h> #include <unistd.h> -#include <stdbool.h> #include <wayland-server.h> -#include <wlr/types/wlr_input_device.h> -#include <wlr/types/wlr_pointer.h> #include <wlr/backend/multi.h> #include <wlr/backend/session.h> +#include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_pointer.h> #include <wlr/util/log.h> #include <xkbcommon/xkbcommon.h> #include "rootston/input.h" -#include "rootston/seat.h" #include "rootston/keyboard.h" +#include "rootston/seat.h" static ssize_t pressed_keysyms_index(xkb_keysym_t *pressed_keysyms, xkb_keysym_t keysym) { diff --git a/rootston/main.c b/rootston/main.c index 3273c53f..5450ade2 100644 --- a/rootston/main.c +++ b/rootston/main.c @@ -3,10 +3,10 @@ #include <stdlib.h> #include <unistd.h> #include <wayland-server.h> -#include <wlr/config.h> #include <wlr/backend.h> #include <wlr/backend/headless.h> #include <wlr/backend/multi.h> +#include <wlr/config.h> #include <wlr/render.h> #include <wlr/util/log.h> #include "rootston/config.h" diff --git a/rootston/meson.build b/rootston/meson.build index 973f93a4..a53812e3 100644 --- a/rootston/meson.build +++ b/rootston/meson.build @@ -8,8 +8,8 @@ sources = [ 'main.c', 'output.c', 'seat.c', - 'xdg_shell_v6.c', 'wl_shell.c', + 'xdg_shell_v6.c', ] if get_option('enable_xwayland') sources += ['xwayland.c'] diff --git a/rootston/output.c b/rootston/output.c index fce875da..1ea4412e 100644 --- a/rootston/output.c +++ b/rootston/output.c @@ -1,18 +1,18 @@ #define _POSIX_C_SOURCE 200809L -#include <time.h> -#include <stdlib.h> -#include <stdbool.h> #include <assert.h> -#include <wlr/types/wlr_output_layout.h> +#include <stdbool.h> +#include <stdlib.h> +#include <time.h> +#include <wlr/render/matrix.h> #include <wlr/types/wlr_compositor.h> +#include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_wl_shell.h> #include <wlr/types/wlr_xdg_shell_v6.h> -#include <wlr/render/matrix.h> #include <wlr/util/log.h> #include <wlr/util/region.h> -#include "rootston/server.h" -#include "rootston/output.h" #include "rootston/config.h" +#include "rootston/output.h" +#include "rootston/server.h" typedef void (*surface_iterator_func_t)(struct wlr_surface *surface, double lx, double ly, float rotation, void *data); @@ -644,9 +644,22 @@ static void set_mode(struct wlr_output *output, } } -void output_add_notify(struct wl_listener *listener, void *data) { +static void output_handle_destroy(struct wl_listener *listener, void *data) { + struct roots_output *output = wl_container_of(listener, output, destroy); + + // TODO: cursor + //example_config_configure_cursor(sample->config, sample->cursor, + // sample->compositor); + + wl_list_remove(&output->link); + wl_list_remove(&output->destroy.link); + wl_list_remove(&output->frame.link); + free(output); +} + +void handle_new_output(struct wl_listener *listener, void *data) { struct roots_desktop *desktop = wl_container_of(listener, desktop, - output_add); + new_output); struct wlr_output *wlr_output = data; struct roots_input *input = desktop->server->input; struct roots_config *config = desktop->config; @@ -670,6 +683,8 @@ void output_add_notify(struct wl_listener *listener, void *data) { output->damage = wlr_output_damage_create(wlr_output); + output->destroy.notify = output_handle_destroy; + wl_signal_add(&wlr_output->events.destroy, &output->destroy); output->frame.notify = output_damage_handle_frame; wl_signal_add(&output->damage->events.frame, &output->frame); @@ -699,31 +714,3 @@ void output_add_notify(struct wl_listener *listener, void *data) { output_damage_whole(output); } - -void output_remove_notify(struct wl_listener *listener, void *data) { - struct wlr_output *wlr_output = data; - struct roots_desktop *desktop = - wl_container_of(listener, desktop, output_remove); - - struct roots_output *output = NULL, *_output; - wl_list_for_each(_output, &desktop->outputs, link) { - if (_output->wlr_output == wlr_output) { - output = _output; - break; - } - } - if (!output) { - return; // We are unfamiliar with this output - } - - wlr_output_layout_remove(desktop->layout, output->wlr_output); - - // TODO: cursor - //example_config_configure_cursor(sample->config, sample->cursor, - // sample->compositor); - - wl_list_remove(&output->link); - wl_list_remove(&output->frame.link); - wlr_output_damage_destroy(output->damage); - free(output); -} diff --git a/rootston/seat.c b/rootston/seat.c index 45e42d7d..38c26628 100644 --- a/rootston/seat.c +++ b/rootston/seat.c @@ -3,14 +3,14 @@ #include <string.h> #include <wayland-server.h> #include <wlr/config.h> +#include <wlr/types/wlr_idle.h> #include <wlr/types/wlr_xcursor_manager.h> #include <wlr/util/log.h> -#include <wlr/types/wlr_idle.h> -#include "rootston/xcursor.h" +#include "rootston/cursor.h" #include "rootston/input.h" -#include "rootston/seat.h" #include "rootston/keyboard.h" -#include "rootston/cursor.h" +#include "rootston/seat.h" +#include "rootston/xcursor.h" static void handle_keyboard_key(struct wl_listener *listener, void *data) { struct roots_keyboard *keyboard = @@ -404,6 +404,17 @@ static void seat_update_capabilities(struct roots_seat *seat) { } } +static void handle_keyboard_destroy(struct wl_listener *listener, void *data) { + struct roots_keyboard *keyboard = + wl_container_of(listener, keyboard, device_destroy); + struct roots_seat *seat = keyboard->seat; + roots_keyboard_destroy(keyboard); + wl_list_remove(&keyboard->device_destroy.link); + wl_list_remove(&keyboard->keyboard_key.link); + wl_list_remove(&keyboard->keyboard_modifiers.link); + seat_update_capabilities(seat); +} + static void seat_add_keyboard(struct roots_seat *seat, struct wlr_input_device *device) { assert(device->type == WLR_INPUT_DEVICE_KEYBOARD); @@ -418,10 +429,11 @@ static void seat_add_keyboard(struct roots_seat *seat, wl_list_insert(&seat->keyboards, &keyboard->link); + keyboard->device_destroy.notify = handle_keyboard_destroy; + wl_signal_add(&keyboard->device->events.destroy, &keyboard->device_destroy); keyboard->keyboard_key.notify = handle_keyboard_key; wl_signal_add(&keyboard->device->keyboard->events.key, &keyboard->keyboard_key); - keyboard->keyboard_modifiers.notify = handle_keyboard_modifiers; wl_signal_add(&keyboard->device->keyboard->events.modifiers, &keyboard->keyboard_modifiers); @@ -429,6 +441,19 @@ static void seat_add_keyboard(struct roots_seat *seat, wlr_seat_set_keyboard(seat->seat, device); } +static void handle_pointer_destroy(struct wl_listener *listener, void *data) { + struct roots_pointer *pointer = + wl_container_of(listener, pointer, device_destroy); + struct roots_seat *seat = pointer->seat; + + wl_list_remove(&pointer->link); + wlr_cursor_detach_input_device(seat->cursor->cursor, pointer->device); + wl_list_remove(&pointer->device_destroy.link); + free(pointer); + + seat_update_capabilities(seat); +} + static void seat_add_pointer(struct roots_seat *seat, struct wlr_input_device *device) { struct roots_pointer *pointer = calloc(sizeof(struct roots_pointer), 1); @@ -441,10 +466,27 @@ static void seat_add_pointer(struct roots_seat *seat, pointer->device = device; pointer->seat = seat; wl_list_insert(&seat->pointers, &pointer->link); + + pointer->device_destroy.notify = handle_pointer_destroy; + wl_signal_add(&pointer->device->events.destroy, &pointer->device_destroy); + wlr_cursor_attach_input_device(seat->cursor->cursor, device); roots_seat_configure_cursor(seat); } +static void handle_touch_destroy(struct wl_listener *listener, void *data) { + struct roots_pointer *touch = + wl_container_of(listener, touch, device_destroy); + struct roots_seat *seat = touch->seat; + + wl_list_remove(&touch->link); + wlr_cursor_detach_input_device(seat->cursor->cursor, touch->device); + wl_list_remove(&touch->device_destroy.link); + free(touch); + + seat_update_capabilities(seat); +} + static void seat_add_touch(struct roots_seat *seat, struct wlr_input_device *device) { struct roots_touch *touch = calloc(sizeof(struct roots_touch), 1); @@ -457,6 +499,10 @@ static void seat_add_touch(struct roots_seat *seat, touch->device = device; touch->seat = seat; wl_list_insert(&seat->touch, &touch->link); + + touch->device_destroy.notify = handle_touch_destroy; + wl_signal_add(&touch->device->events.destroy, &touch->device_destroy); + wlr_cursor_attach_input_device(seat->cursor->cursor, device); roots_seat_configure_cursor(seat); } @@ -466,6 +512,20 @@ static void seat_add_tablet_pad(struct roots_seat *seat, // TODO } +static void handle_tablet_tool_destroy(struct wl_listener *listener, + void *data) { + struct roots_pointer *tablet_tool = + wl_container_of(listener, tablet_tool, device_destroy); + struct roots_seat *seat = tablet_tool->seat; + + wl_list_remove(&tablet_tool->link); + wlr_cursor_detach_input_device(seat->cursor->cursor, tablet_tool->device); + wl_list_remove(&tablet_tool->device_destroy.link); + free(tablet_tool); + + seat_update_capabilities(seat); +} + static void seat_add_tablet_tool(struct roots_seat *seat, struct wlr_input_device *device) { struct roots_tablet_tool *tablet_tool = @@ -479,6 +539,11 @@ static void seat_add_tablet_tool(struct roots_seat *seat, tablet_tool->device = device; tablet_tool->seat = seat; wl_list_insert(&seat->tablet_tools, &tablet_tool->link); + + tablet_tool->device_destroy.notify = handle_tablet_tool_destroy; + wl_signal_add(&tablet_tool->device->events.destroy, + &tablet_tool->device_destroy); + wlr_cursor_attach_input_device(seat->cursor->cursor, device); roots_seat_configure_cursor(seat); } @@ -506,84 +571,6 @@ void roots_seat_add_device(struct roots_seat *seat, seat_update_capabilities(seat); } -static void seat_remove_keyboard(struct roots_seat *seat, - struct wlr_input_device *device) { - struct roots_keyboard *keyboard; - wl_list_for_each(keyboard, &seat->keyboards, link) { - if (keyboard->device == device) { - roots_keyboard_destroy(keyboard); - return; - } - } -} - -static void seat_remove_pointer(struct roots_seat *seat, - struct wlr_input_device *device) { - struct roots_pointer *pointer; - wl_list_for_each(pointer, &seat->pointers, link) { - if (pointer->device == device) { - wl_list_remove(&pointer->link); - wlr_cursor_detach_input_device(seat->cursor->cursor, device); - free(pointer); - return; - } - } -} - -static void seat_remove_touch(struct roots_seat *seat, - struct wlr_input_device *device) { - struct roots_touch *touch; - wl_list_for_each(touch, &seat->touch, link) { - if (touch->device == device) { - wl_list_remove(&touch->link); - wlr_cursor_detach_input_device(seat->cursor->cursor, device); - free(touch); - return; - } - } -} - -static void seat_remove_tablet_pad(struct roots_seat *seat, - struct wlr_input_device *device) { - // TODO -} - -static void seat_remove_tablet_tool(struct roots_seat *seat, - struct wlr_input_device *device) { - struct roots_tablet_tool *tablet_tool; - wl_list_for_each(tablet_tool, &seat->tablet_tools, link) { - if (tablet_tool->device == device) { - wl_list_remove(&tablet_tool->link); - wlr_cursor_detach_input_device(seat->cursor->cursor, device); - free(tablet_tool); - return; - } - } -} - -void roots_seat_remove_device(struct roots_seat *seat, - struct wlr_input_device *device) { - switch (device->type) { - case WLR_INPUT_DEVICE_KEYBOARD: - seat_remove_keyboard(seat, device); - break; - case WLR_INPUT_DEVICE_POINTER: - seat_remove_pointer(seat, device); - break; - case WLR_INPUT_DEVICE_TOUCH: - seat_remove_touch(seat, device); - break; - case WLR_INPUT_DEVICE_TABLET_PAD: - seat_remove_tablet_pad(seat, device); - break; - case WLR_INPUT_DEVICE_TABLET_TOOL: - seat_remove_tablet_tool(seat, device); - break; - } - - seat_update_capabilities(seat); -} - void roots_seat_configure_xcursor(struct roots_seat *seat) { const char *cursor_theme = NULL; struct roots_cursor_config *cc = diff --git a/rootston/wl_shell.c b/rootston/wl_shell.c index 267e2cf5..44a65cf5 100644 --- a/rootston/wl_shell.c +++ b/rootston/wl_shell.c @@ -1,14 +1,14 @@ #include <assert.h> -#include <stdlib.h> #include <stdbool.h> +#include <stdlib.h> #include <wayland-server.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_wl_shell.h> #include <wlr/util/log.h> #include "rootston/desktop.h" -#include "rootston/server.h" #include "rootston/input.h" +#include "rootston/server.h" static void popup_destroy(struct roots_view_child *child) { assert(child->destroy == popup_destroy); diff --git a/rootston/xdg_shell_v6.c b/rootston/xdg_shell_v6.c index 9bd6f76a..8e6674ab 100644 --- a/rootston/xdg_shell_v6.c +++ b/rootston/xdg_shell_v6.c @@ -1,14 +1,14 @@ #include <assert.h> -#include <stdlib.h> #include <stdbool.h> +#include <stdlib.h> #include <wayland-server.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/util/log.h> #include "rootston/desktop.h" -#include "rootston/server.h" #include "rootston/input.h" +#include "rootston/server.h" static void popup_destroy(struct roots_view_child *child) { assert(child->destroy == popup_destroy); diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 36be9793..e9e0d5e0 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -1,12 +1,12 @@ #include <assert.h> -#include <stdlib.h> #include <stdbool.h> +#include <stdlib.h> #include <wayland-server.h> #include <wlr/config.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_surface.h> -#include <wlr/xwayland.h> #include <wlr/util/log.h> +#include <wlr/xwayland.h> #include "rootston/server.h" #include "rootston/server.h" diff --git a/types/meson.build b/types/meson.build index 9f37cc86..2731f9bc 100644 --- a/types/meson.build +++ b/types/meson.build @@ -1,18 +1,18 @@ lib_wlr_types = static_library( 'wlr_types', files( - 'wlr_data_device.c', 'wlr_box.c', 'wlr_compositor.c', 'wlr_cursor.c', + 'wlr_data_device.c', 'wlr_gamma_control.c', 'wlr_idle.c', 'wlr_input_device.c', 'wlr_keyboard.c', 'wlr_list.c', - 'wlr_output.c', 'wlr_output_damage.c', 'wlr_output_layout.c', + 'wlr_output.c', 'wlr_pointer.c', 'wlr_primary_selection.c', 'wlr_region.c', diff --git a/types/wlr_box.c b/types/wlr_box.c index 33031858..2ea743d0 100644 --- a/types/wlr_box.c +++ b/types/wlr_box.c @@ -1,7 +1,7 @@ #include <limits.h> -#include <stdlib.h> #include <math.h> #include <stdbool.h> +#include <stdlib.h> #include <wayland-server-protocol.h> #include <wlr/types/wlr_box.h> #include <wlr/util/log.h> diff --git a/types/wlr_compositor.c b/types/wlr_compositor.c index a4bd7a16..925e0019 100644 --- a/types/wlr_compositor.c +++ b/types/wlr_compositor.c @@ -1,10 +1,11 @@ #include <assert.h> #include <stdlib.h> #include <wayland-server.h> -#include <wlr/util/log.h> -#include <wlr/types/wlr_surface.h> -#include <wlr/types/wlr_region.h> #include <wlr/types/wlr_compositor.h> +#include <wlr/types/wlr_region.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/util/log.h> +#include "util/signal.h" static void destroy_surface_listener(struct wl_listener *listener, void *data) { wl_list_remove(wl_resource_get_link(data)); @@ -35,7 +36,7 @@ static void wl_compositor_create_surface(struct wl_client *client, wl_list_insert(&compositor->surfaces, wl_resource_get_link(surface_resource)); - wl_signal_emit(&compositor->events.new_surface, surface); + wlr_signal_emit_safe(&compositor->events.new_surface, surface); } static void wl_compositor_create_region(struct wl_client *client, diff --git a/types/wlr_cursor.c b/types/wlr_cursor.c index fd48c1b6..20acebf1 100644 --- a/types/wlr_cursor.c +++ b/types/wlr_cursor.c @@ -1,12 +1,13 @@ -#include <wlr/types/wlr_cursor.h> -#include <stdlib.h> #include <assert.h> #include <limits.h> -#include <wlr/util/log.h> +#include <stdlib.h> #include <wayland-server.h> -#include <wlr/types/wlr_output.h> -#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_cursor.h> #include <wlr/types/wlr_input_device.h> +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_output.h> +#include <wlr/util/log.h> +#include "util/signal.h" struct wlr_cursor_device { struct wlr_cursor *cursor; @@ -325,7 +326,7 @@ static void handle_pointer_motion(struct wl_listener *listener, void *data) { struct wlr_event_pointer_motion *event = data; struct wlr_cursor_device *device = wl_container_of(listener, device, motion); - wl_signal_emit(&device->cursor->events.motion, event); + wlr_signal_emit_safe(&device->cursor->events.motion, event); } static void handle_pointer_motion_absolute(struct wl_listener *listener, @@ -333,62 +334,62 @@ static void handle_pointer_motion_absolute(struct wl_listener *listener, struct wlr_event_pointer_motion_absolute *event = data; struct wlr_cursor_device *device = wl_container_of(listener, device, motion_absolute); - wl_signal_emit(&device->cursor->events.motion_absolute, event); + wlr_signal_emit_safe(&device->cursor->events.motion_absolute, event); } static void handle_pointer_button(struct wl_listener *listener, void *data) { struct wlr_event_pointer_button *event = data; struct wlr_cursor_device *device = wl_container_of(listener, device, button); - wl_signal_emit(&device->cursor->events.button, event); + wlr_signal_emit_safe(&device->cursor->events.button, event); } static void handle_pointer_axis(struct wl_listener *listener, void *data) { struct wlr_event_pointer_axis *event = data; struct wlr_cursor_device *device = wl_container_of(listener, device, axis); - wl_signal_emit(&device->cursor->events.axis, event); + wlr_signal_emit_safe(&device->cursor->events.axis, event); } static void handle_touch_up(struct wl_listener *listener, void *data) { struct wlr_event_touch_up *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, touch_up); - wl_signal_emit(&device->cursor->events.touch_up, event); + wlr_signal_emit_safe(&device->cursor->events.touch_up, event); } static void handle_touch_down(struct wl_listener *listener, void *data) { struct wlr_event_touch_down *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, touch_down); - wl_signal_emit(&device->cursor->events.touch_down, event); + wlr_signal_emit_safe(&device->cursor->events.touch_down, event); } static void handle_touch_motion(struct wl_listener *listener, void *data) { struct wlr_event_touch_motion *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, touch_motion); - wl_signal_emit(&device->cursor->events.touch_motion, event); + wlr_signal_emit_safe(&device->cursor->events.touch_motion, event); } static void handle_touch_cancel(struct wl_listener *listener, void *data) { struct wlr_event_touch_cancel *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, touch_cancel); - wl_signal_emit(&device->cursor->events.touch_cancel, event); + wlr_signal_emit_safe(&device->cursor->events.touch_cancel, event); } static void handle_tablet_tool_tip(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_tip *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, tablet_tool_tip); - wl_signal_emit(&device->cursor->events.tablet_tool_tip, event); + wlr_signal_emit_safe(&device->cursor->events.tablet_tool_tip, event); } static void handle_tablet_tool_axis(struct wl_listener *listener, void *data) { struct wlr_event_tablet_tool_axis *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, tablet_tool_axis); - wl_signal_emit(&device->cursor->events.tablet_tool_axis, event); + wlr_signal_emit_safe(&device->cursor->events.tablet_tool_axis, event); } static void handle_tablet_tool_button(struct wl_listener *listener, @@ -396,7 +397,7 @@ static void handle_tablet_tool_button(struct wl_listener *listener, struct wlr_event_tablet_tool_button *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, tablet_tool_button); - wl_signal_emit(&device->cursor->events.tablet_tool_button, event); + wlr_signal_emit_safe(&device->cursor->events.tablet_tool_button, event); } static void handle_tablet_tool_proximity(struct wl_listener *listener, @@ -404,7 +405,7 @@ static void handle_tablet_tool_proximity(struct wl_listener *listener, struct wlr_event_tablet_tool_proximity *event = data; struct wlr_cursor_device *device; device = wl_container_of(listener, device, tablet_tool_proximity); - wl_signal_emit(&device->cursor->events.tablet_tool_proximity, event); + wlr_signal_emit_safe(&device->cursor->events.tablet_tool_proximity, event); } static void handle_device_destroy(struct wl_listener *listener, void *data) { diff --git a/types/wlr_data_device.c b/types/wlr_data_device.c index d7e4aa14..b8ef820b 100644 --- a/types/wlr_data_device.c +++ b/types/wlr_data_device.c @@ -1,13 +1,14 @@ #define _XOPEN_SOURCE 700 +#include <assert.h> #include <stdlib.h> #include <string.h> #include <strings.h> -#include <assert.h> #include <unistd.h> #include <wayland-server.h> -#include <wlr/util/log.h> -#include <wlr/types/wlr_seat.h> #include <wlr/types/wlr_data_device.h> +#include <wlr/types/wlr_seat.h> +#include <wlr/util/log.h> +#include "util/signal.h" #define ALL_ACTIONS (WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY | \ WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE | \ @@ -290,7 +291,7 @@ static void seat_client_selection_data_source_destroy( seat->selection_data_source = NULL; - wl_signal_emit(&seat->events.selection, seat); + wlr_signal_emit_safe(&seat->events.selection, seat); } void wlr_seat_set_selection(struct wlr_seat *seat, @@ -321,7 +322,7 @@ void wlr_seat_set_selection(struct wlr_seat *seat, wlr_seat_client_send_selection(focused_client); } - wl_signal_emit(&seat->events.selection, seat); + wlr_signal_emit_safe(&seat->events.selection, seat); if (source) { seat->selection_data_source_destroy.notify = @@ -457,7 +458,7 @@ static void wlr_drag_end(struct wlr_drag *drag) { if (drag->icon) { drag->icon->mapped = false; wl_list_remove(&drag->icon_destroy.link); - wl_signal_emit(&drag->icon->events.map, drag->icon); + wlr_signal_emit_safe(&drag->icon->events.map, drag->icon); } free(drag); @@ -634,7 +635,7 @@ static void wlr_drag_icon_destroy(struct wlr_drag_icon *icon) { if (!icon) { return; } - wl_signal_emit(&icon->events.destroy, icon); + wlr_signal_emit_safe(&icon->events.destroy, icon); wlr_surface_set_role_committed(icon->surface, NULL, NULL); wl_list_remove(&icon->surface_destroy.link); wl_list_remove(&icon->seat_client_destroy.link); @@ -691,7 +692,7 @@ static struct wlr_drag_icon *wlr_drag_icon_create( icon->seat_client_destroy.notify = handle_drag_icon_seat_client_destroy; wl_list_insert(&client->seat->drag_icons, &icon->link); - wl_signal_emit(&client->seat->events.new_drag_icon, icon); + wlr_signal_emit_safe(&client->seat->events.new_drag_icon, icon); return icon; } @@ -941,7 +942,7 @@ void wlr_data_source_finish(struct wlr_data_source *source) { return; } - wl_signal_emit(&source->events.destroy, source); + wlr_signal_emit_safe(&source->events.destroy, source); char **p; wl_array_for_each(p, &source->mime_types) { diff --git a/types/wlr_gamma_control.c b/types/wlr_gamma_control.c index eb154b6b..861427bd 100644 --- a/types/wlr_gamma_control.c +++ b/types/wlr_gamma_control.c @@ -5,6 +5,7 @@ #include <wlr/types/wlr_output.h> #include <wlr/util/log.h> #include "gamma-control-protocol.h" +#include "util/signal.h" static void resource_destroy(struct wl_client *client, struct wl_resource *resource) { @@ -15,7 +16,7 @@ static void gamma_control_destroy(struct wlr_gamma_control *gamma_control) { if (gamma_control == NULL) { return; } - wl_signal_emit(&gamma_control->events.destroy, gamma_control); + wlr_signal_emit_safe(&gamma_control->events.destroy, gamma_control); wl_list_remove(&gamma_control->output_destroy_listener.link); wl_resource_set_user_data(gamma_control->resource, NULL); wl_list_remove(&gamma_control->link); diff --git a/types/wlr_idle.c b/types/wlr_idle.c index f2cad42b..9eddc42b 100644 --- a/types/wlr_idle.c +++ b/types/wlr_idle.c @@ -5,6 +5,7 @@ #include <wlr/types/wlr_idle.h> #include <wlr/util/log.h> #include "idle-protocol.h" +#include "util/signal.h" static void idle_timeout_destroy(struct wlr_idle_timeout *timer) { wl_list_remove(&timer->input_listener.link); @@ -186,5 +187,5 @@ struct wlr_idle *wlr_idle_create(struct wl_display *display) { } void wlr_idle_notify_activity(struct wlr_idle *idle, struct wlr_seat *seat) { - wl_signal_emit(&idle->activity_notify, seat); + wlr_signal_emit_safe(&idle->activity_notify, seat); } diff --git a/types/wlr_input_device.c b/types/wlr_input_device.c index 7015dcba..65d4b1d6 100644 --- a/types/wlr_input_device.c +++ b/types/wlr_input_device.c @@ -2,14 +2,15 @@ #include <stdlib.h> #include <string.h> #include <wayland-server.h> -#include <wlr/types/wlr_input_device.h> #include <wlr/interfaces/wlr_input_device.h> #include <wlr/interfaces/wlr_keyboard.h> #include <wlr/interfaces/wlr_pointer.h> -#include <wlr/interfaces/wlr_touch.h> -#include <wlr/interfaces/wlr_tablet_tool.h> #include <wlr/interfaces/wlr_tablet_pad.h> +#include <wlr/interfaces/wlr_tablet_tool.h> +#include <wlr/interfaces/wlr_touch.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/util/log.h> +#include "util/signal.h" void wlr_input_device_init(struct wlr_input_device *dev, enum wlr_input_device_type type, @@ -29,7 +30,7 @@ void wlr_input_device_destroy(struct wlr_input_device *dev) { return; } - wl_signal_emit(&dev->events.destroy, dev); + wlr_signal_emit_safe(&dev->events.destroy, dev); if (dev->_device) { switch (dev->type) { @@ -58,7 +59,6 @@ void wlr_input_device_destroy(struct wlr_input_device *dev) { if (dev->impl && dev->impl->destroy) { dev->impl->destroy(dev); } else { - wl_list_remove(&dev->events.destroy.listener_list); free(dev); } } diff --git a/types/wlr_keyboard.c b/types/wlr_keyboard.c index 29552eb4..5c0699ff 100644 --- a/types/wlr_keyboard.c +++ b/types/wlr_keyboard.c @@ -1,12 +1,13 @@ +#include <assert.h> #include <stdlib.h> #include <string.h> #include <sys/mman.h> #include <unistd.h> -#include <assert.h> #include <wayland-server.h> -#include <wlr/types/wlr_keyboard.h> #include <wlr/interfaces/wlr_keyboard.h> +#include <wlr/types/wlr_keyboard.h> #include <wlr/util/log.h> +#include "util/signal.h" int os_create_anonymous_file(off_t size); @@ -110,7 +111,7 @@ void wlr_keyboard_notify_modifiers(struct wlr_keyboard *keyboard, bool updated = keyboard_modifier_update(keyboard); if (updated) { - wl_signal_emit(&keyboard->events.modifiers, keyboard); + wlr_signal_emit_safe(&keyboard->events.modifiers, keyboard); } } @@ -128,11 +129,11 @@ void wlr_keyboard_notify_key(struct wlr_keyboard *keyboard, bool updated = keyboard_modifier_update(keyboard); if (updated) { - wl_signal_emit(&keyboard->events.modifiers, keyboard); + wlr_signal_emit_safe(&keyboard->events.modifiers, keyboard); } keyboard_key_update(keyboard, event); - wl_signal_emit(&keyboard->events.key, event); + wlr_signal_emit_safe(&keyboard->events.key, event); } void wlr_keyboard_init(struct wlr_keyboard *kb, @@ -234,7 +235,7 @@ void wlr_keyboard_set_keymap(struct wlr_keyboard *kb, keyboard_modifier_update(kb); - wl_signal_emit(&kb->events.keymap, kb); + wlr_signal_emit_safe(&kb->events.keymap, kb); return; err: @@ -253,7 +254,7 @@ void wlr_keyboard_set_repeat_info(struct wlr_keyboard *kb, int32_t rate, } kb->repeat_info.rate = rate; kb->repeat_info.delay = delay; - wl_signal_emit(&kb->events.repeat_info, kb); + wlr_signal_emit_safe(&kb->events.repeat_info, kb); } uint32_t wlr_keyboard_get_modifiers(struct wlr_keyboard *kb) { diff --git a/types/wlr_list.c b/types/wlr_list.c index 565a155b..2be0912a 100644 --- a/types/wlr_list.c +++ b/types/wlr_list.c @@ -1,8 +1,8 @@ +#include <stdbool.h> +#include <stddef.h> #include <stdio.h> #include <stdlib.h> -#include <stdbool.h> #include <string.h> -#include <stddef.h> #include <sys/types.h> #include <wlr/types/wlr_list.h> diff --git a/types/wlr_output.c b/types/wlr_output.c index 5f7dca28..504d0209 100644 --- a/types/wlr_output.c +++ b/types/wlr_output.c @@ -5,14 +5,15 @@ #include <tgmath.h> #include <time.h> #include <wayland-server.h> +#include <wlr/interfaces/wlr_output.h> +#include <wlr/render.h> +#include <wlr/render/matrix.h> #include <wlr/types/wlr_box.h> #include <wlr/types/wlr_output.h> #include <wlr/types/wlr_surface.h> -#include <wlr/interfaces/wlr_output.h> #include <wlr/util/log.h> -#include <wlr/render/matrix.h> -#include <wlr/render.h> #include <wlr/util/region.h> +#include "util/signal.h" static void wl_output_send_to_resource(struct wl_resource *resource) { assert(resource); @@ -139,7 +140,7 @@ void wlr_output_update_enabled(struct wlr_output *output, bool enabled) { } output->enabled = enabled; - wl_signal_emit(&output->events.enable, output); + wlr_signal_emit_safe(&output->events.enable, output); } static void wlr_output_update_matrix(struct wlr_output *output) { @@ -193,7 +194,7 @@ void wlr_output_update_custom_mode(struct wlr_output *output, int32_t width, wlr_output_send_current_mode_to_resource(resource); } - wl_signal_emit(&output->events.mode, output); + wlr_signal_emit_safe(&output->events.mode, output); } void wlr_output_set_transform(struct wlr_output *output, @@ -207,7 +208,7 @@ void wlr_output_set_transform(struct wlr_output *output, wl_output_send_to_resource(resource); } - wl_signal_emit(&output->events.transform, output); + wlr_signal_emit_safe(&output->events.transform, output); } void wlr_output_set_position(struct wlr_output *output, int32_t lx, @@ -239,7 +240,7 @@ void wlr_output_set_scale(struct wlr_output *output, float scale) { wl_output_send_to_resource(resource); } - wl_signal_emit(&output->events.scale, output); + wlr_signal_emit_safe(&output->events.scale, output); } static void handle_display_destroy(struct wl_listener *listener, void *data) { @@ -284,8 +285,7 @@ void wlr_output_destroy(struct wlr_output *output) { wlr_output_destroy_global(output); wlr_output_set_fullscreen_surface(output, NULL); - wl_signal_emit(&output->backend->events.output_remove, output); - wl_signal_emit(&output->events.destroy, output); + wlr_signal_emit_safe(&output->events.destroy, output); struct wlr_output_mode *mode, *tmp_mode; wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) { @@ -471,7 +471,7 @@ bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, output->idle_frame = NULL; } - wl_signal_emit(&output->events.swap_buffers, damage); + wlr_signal_emit_safe(&output->events.swap_buffers, damage); int width, height; wlr_output_transformed_resolution(output, &width, &height); @@ -528,7 +528,7 @@ bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when, void wlr_output_send_frame(struct wlr_output *output) { output->frame_pending = false; - wl_signal_emit(&output->events.frame, output); + wlr_signal_emit_safe(&output->events.frame, output); } static void schedule_frame_handle_idle_timer(void *data) { @@ -566,7 +566,7 @@ uint32_t wlr_output_get_gamma_size(struct wlr_output *output) { void wlr_output_update_needs_swap(struct wlr_output *output) { output->needs_swap = true; - wl_signal_emit(&output->events.needs_swap, output); + wlr_signal_emit_safe(&output->events.needs_swap, output); } static void output_damage_whole(struct wlr_output *output) { @@ -883,7 +883,7 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { return; } output_cursor_reset(cursor); - wl_signal_emit(&cursor->events.destroy, cursor); + wlr_signal_emit_safe(&cursor->events.destroy, cursor); if (cursor->output->hardware_cursor == cursor) { // If this cursor was the hardware cursor, disable it if (cursor->output->impl->set_cursor) { diff --git a/types/wlr_output_damage.c b/types/wlr_output_damage.c index 354314b6..b3636c37 100644 --- a/types/wlr_output_damage.c +++ b/types/wlr_output_damage.c @@ -1,10 +1,11 @@ -#include <stdlib.h> #include <stddef.h> +#include <stdlib.h> #include <time.h> #include <wayland-server.h> #include <wlr/types/wlr_box.h> -#include <wlr/types/wlr_output.h> #include <wlr/types/wlr_output_damage.h> +#include <wlr/types/wlr_output.h> +#include "util/signal.h" static void output_handle_destroy(struct wl_listener *listener, void *data) { struct wlr_output_damage *output_damage = @@ -46,7 +47,7 @@ static void output_handle_frame(struct wl_listener *listener, void *data) { return; } - wl_signal_emit(&output_damage->events.frame, output_damage); + wlr_signal_emit_safe(&output_damage->events.frame, output_damage); } struct wlr_output_damage *wlr_output_damage_create(struct wlr_output *output) { @@ -85,7 +86,7 @@ void wlr_output_damage_destroy(struct wlr_output_damage *output_damage) { if (output_damage == NULL) { return; } - wl_signal_emit(&output_damage->events.destroy, output_damage); + wlr_signal_emit_safe(&output_damage->events.destroy, output_damage); wl_list_remove(&output_damage->output_destroy.link); wl_list_remove(&output_damage->output_mode.link); wl_list_remove(&output_damage->output_transform.link); diff --git a/types/wlr_output_layout.c b/types/wlr_output_layout.c index 46b0bd2a..db0389bd 100644 --- a/types/wlr_output_layout.c +++ b/types/wlr_output_layout.c @@ -1,11 +1,12 @@ -#include <wlr/util/log.h> -#include <wlr/types/wlr_output.h> -#include <wlr/types/wlr_output_layout.h> -#include <wlr/types/wlr_box.h> -#include <limits.h> +#include <assert.h> #include <float.h> +#include <limits.h> #include <stdlib.h> -#include <assert.h> +#include <wlr/types/wlr_box.h> +#include <wlr/types/wlr_output_layout.h> +#include <wlr/types/wlr_output.h> +#include <wlr/util/log.h> +#include "util/signal.h" struct wlr_output_layout_state { struct wlr_box _box; // should never be read directly, use the getter @@ -46,7 +47,7 @@ struct wlr_output_layout *wlr_output_layout_create() { static void wlr_output_layout_output_destroy( struct wlr_output_layout_output *l_output) { - wl_signal_emit(&l_output->events.destroy, l_output); + wlr_signal_emit_safe(&l_output->events.destroy, l_output); wl_list_remove(&l_output->state->mode.link); wl_list_remove(&l_output->state->scale.link); wl_list_remove(&l_output->state->transform.link); @@ -61,7 +62,7 @@ void wlr_output_layout_destroy(struct wlr_output_layout *layout) { return; } - wl_signal_emit(&layout->events.destroy, layout); + wlr_signal_emit_safe(&layout->events.destroy, layout); struct wlr_output_layout_output *l_output, *temp = NULL; wl_list_for_each_safe(l_output, temp, &layout->outputs, link) { @@ -129,7 +130,7 @@ static void wlr_output_layout_reconfigure(struct wlr_output_layout *layout) { wlr_output_set_position(l_output->output, l_output->x, l_output->y); } - wl_signal_emit(&layout->events.change, layout); + wlr_signal_emit_safe(&layout->events.change, layout); } static void handle_output_mode(struct wl_listener *listener, void *data) { @@ -204,7 +205,7 @@ void wlr_output_layout_add(struct wlr_output_layout *layout, l_output->state->auto_configured = false; wlr_output_layout_reconfigure(layout); wlr_output_create_global(output); - wl_signal_emit(&layout->events.add, l_output); + wlr_signal_emit_safe(&layout->events.add, l_output); } struct wlr_output_layout_output *wlr_output_layout_get( @@ -401,7 +402,7 @@ void wlr_output_layout_add_auto(struct wlr_output_layout *layout, l_output->state->auto_configured = true; wlr_output_layout_reconfigure(layout); wlr_output_create_global(output); - wl_signal_emit(&layout->events.add, l_output); + wlr_signal_emit_safe(&layout->events.add, l_output); } struct wlr_output *wlr_output_layout_get_center_output( diff --git a/types/wlr_pointer.c b/types/wlr_pointer.c index 04100e56..bc9efd8c 100644 --- a/types/wlr_pointer.c +++ b/types/wlr_pointer.c @@ -1,8 +1,8 @@ #include <stdlib.h> #include <string.h> #include <wayland-server.h> -#include <wlr/types/wlr_pointer.h> #include <wlr/interfaces/wlr_pointer.h> +#include <wlr/types/wlr_pointer.h> void wlr_pointer_init(struct wlr_pointer *pointer, struct wlr_pointer_impl *impl) { diff --git a/types/wlr_primary_selection.c b/types/wlr_primary_selection.c index fafde669..28fe63c1 100644 --- a/types/wlr_primary_selection.c +++ b/types/wlr_primary_selection.c @@ -1,12 +1,13 @@ #define _XOPEN_SOURCE 700 -#include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <assert.h> #include <gtk-primary-selection-protocol.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> #include <wlr/types/wlr_primary_selection.h> #include <wlr/types/wlr_seat.h> #include <wlr/util/log.h> +#include "util/signal.h" static void offer_handle_receive(struct wl_client *client, struct wl_resource *resource, const char *mime_type, int32_t fd) { @@ -195,7 +196,7 @@ static void seat_client_primary_selection_source_destroy( seat->primary_selection_source = NULL; - wl_signal_emit(&seat->events.primary_selection, seat); + wlr_signal_emit_safe(&seat->events.primary_selection, seat); } void wlr_seat_set_primary_selection(struct wlr_seat *seat, @@ -225,7 +226,7 @@ void wlr_seat_set_primary_selection(struct wlr_seat *seat, wlr_seat_client_send_primary_selection(focused_client); } - wl_signal_emit(&seat->events.primary_selection, seat); + wlr_signal_emit_safe(&seat->events.primary_selection, seat); if (source) { seat->primary_selection_source_destroy.notify = @@ -278,7 +279,7 @@ void wlr_primary_selection_source_finish( return; } - wl_signal_emit(&source->events.destroy, source); + wlr_signal_emit_safe(&source->events.destroy, source); char **p; wl_array_for_each(p, &source->mime_types) { diff --git a/types/wlr_region.c b/types/wlr_region.c index fdf23ad2..322088b5 100644 --- a/types/wlr_region.c +++ b/types/wlr_region.c @@ -1,8 +1,8 @@ -#include <stdlib.h> -#include <stdio.h> #include <assert.h> -#include <wayland-server.h> #include <pixman.h> +#include <stdio.h> +#include <stdlib.h> +#include <wayland-server.h> static void region_add(struct wl_client *client, struct wl_resource *resource, int32_t x, int32_t y, int32_t width, int32_t height) { diff --git a/types/wlr_screenshooter.c b/types/wlr_screenshooter.c index 74f9f602..04757fb6 100644 --- a/types/wlr_screenshooter.c +++ b/types/wlr_screenshooter.c @@ -2,10 +2,10 @@ #include <stdlib.h> #include <string.h> #include <wayland-server.h> -#include <wlr/render.h> #include <wlr/backend.h> -#include <wlr/types/wlr_screenshooter.h> +#include <wlr/render.h> #include <wlr/types/wlr_output.h> +#include <wlr/types/wlr_screenshooter.h> #include <wlr/util/log.h> #include "screenshooter-protocol.h" diff --git a/types/wlr_seat.c b/types/wlr_seat.c index 79c4f6f6..d60e0e0d 100644 --- a/types/wlr_seat.c +++ b/types/wlr_seat.c @@ -4,11 +4,12 @@ #include <string.h> #include <time.h> #include <wayland-server.h> -#include <wlr/types/wlr_seat.h> -#include <wlr/types/wlr_input_device.h> -#include <wlr/util/log.h> #include <wlr/types/wlr_data_device.h> +#include <wlr/types/wlr_input_device.h> #include <wlr/types/wlr_primary_selection.h> +#include <wlr/types/wlr_seat.h> +#include <wlr/util/log.h> +#include "util/signal.h" static void resource_destroy(struct wl_client *client, struct wl_resource *resource) { @@ -49,7 +50,7 @@ static void wl_pointer_set_cursor(struct wl_client *client, event->hotspot_x = hotspot_x; event->hotspot_y = hotspot_y; - wl_signal_emit(&seat_client->seat->events.request_set_cursor, event); + wlr_signal_emit_safe(&seat_client->seat->events.request_set_cursor, event); free(event); } @@ -177,7 +178,7 @@ static void wl_seat_get_touch(struct wl_client *client, static void wlr_seat_client_resource_destroy(struct wl_resource *seat_resource) { struct wlr_seat_client *client = wl_resource_get_user_data(seat_resource); - wl_signal_emit(&client->events.destroy, client); + wlr_signal_emit_safe(&client->events.destroy, client); if (client == client->seat->pointer_state.focused_client) { client->seat->pointer_state.focused_client = NULL; @@ -350,7 +351,7 @@ void wlr_seat_destroy(struct wlr_seat *seat) { return; } - wl_signal_emit(&seat->events.destroy, seat); + wlr_signal_emit_safe(&seat->events.destroy, seat); wl_list_remove(&seat->display_destroy.link); @@ -656,14 +657,14 @@ void wlr_seat_pointer_start_grab(struct wlr_seat *wlr_seat, assert(grab->seat); wlr_seat->pointer_state.grab = grab; - wl_signal_emit(&wlr_seat->events.pointer_grab_begin, grab); + wlr_signal_emit_safe(&wlr_seat->events.pointer_grab_begin, grab); } void wlr_seat_pointer_end_grab(struct wlr_seat *wlr_seat) { struct wlr_seat_pointer_grab *grab = wlr_seat->pointer_state.grab; if (grab != wlr_seat->pointer_state.default_grab) { wlr_seat->pointer_state.grab = wlr_seat->pointer_state.default_grab; - wl_signal_emit(&wlr_seat->events.pointer_grab_end, grab); + wlr_signal_emit_safe(&wlr_seat->events.pointer_grab_end, grab); if (grab->interface->cancel) { grab->interface->cancel(grab); } @@ -812,7 +813,7 @@ void wlr_seat_keyboard_start_grab(struct wlr_seat *wlr_seat, grab->seat = wlr_seat; wlr_seat->keyboard_state.grab = grab; - wl_signal_emit(&wlr_seat->events.keyboard_grab_begin, grab); + wlr_signal_emit_safe(&wlr_seat->events.keyboard_grab_begin, grab); } void wlr_seat_keyboard_end_grab(struct wlr_seat *wlr_seat) { @@ -820,7 +821,7 @@ void wlr_seat_keyboard_end_grab(struct wlr_seat *wlr_seat) { if (grab != wlr_seat->keyboard_state.default_grab) { wlr_seat->keyboard_state.grab = wlr_seat->keyboard_state.default_grab; - wl_signal_emit(&wlr_seat->events.keyboard_grab_end, grab); + wlr_signal_emit_safe(&wlr_seat->events.keyboard_grab_end, grab); if (grab->interface->cancel) { grab->interface->cancel(grab); } @@ -979,7 +980,7 @@ void wlr_seat_touch_start_grab(struct wlr_seat *wlr_seat, grab->seat = wlr_seat; wlr_seat->touch_state.grab = grab; - wl_signal_emit(&wlr_seat->events.touch_grab_begin, grab); + wlr_signal_emit_safe(&wlr_seat->events.touch_grab_begin, grab); } void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) { @@ -987,7 +988,7 @@ void wlr_seat_touch_end_grab(struct wlr_seat *wlr_seat) { if (grab != wlr_seat->touch_state.default_grab) { wlr_seat->touch_state.grab = wlr_seat->touch_state.default_grab; - wl_signal_emit(&wlr_seat->events.touch_grab_end, grab); + wlr_signal_emit_safe(&wlr_seat->events.touch_grab_end, grab); if (grab->interface->cancel) { grab->interface->cancel(grab); } @@ -1003,7 +1004,7 @@ static void touch_point_clear_focus(struct wlr_touch_point *point) { } static void touch_point_destroy(struct wlr_touch_point *point) { - wl_signal_emit(&point->events.destroy, point); + wlr_signal_emit_safe(&point->events.destroy, point); touch_point_clear_focus(point); wl_list_remove(&point->surface_destroy.link); diff --git a/types/wlr_server_decoration.c b/types/wlr_server_decoration.c index 09909bb6..556193e2 100644 --- a/types/wlr_server_decoration.c +++ b/types/wlr_server_decoration.c @@ -1,9 +1,10 @@ #include <assert.h> -#include <stdlib.h> #include <server-decoration-protocol.h> -#include <wlr/types/wlr_surface.h> +#include <stdlib.h> #include <wlr/types/wlr_server_decoration.h> +#include <wlr/types/wlr_surface.h> #include <wlr/util/log.h> +#include "util/signal.h" static void server_decoration_handle_release(struct wl_client *client, struct wl_resource *resource) { @@ -18,14 +19,14 @@ static void server_decoration_handle_request_mode(struct wl_client *client, return; } decoration->mode = mode; - wl_signal_emit(&decoration->events.mode, decoration); + wlr_signal_emit_safe(&decoration->events.mode, decoration); org_kde_kwin_server_decoration_send_mode(decoration->resource, decoration->mode); } static void server_decoration_destroy( struct wlr_server_decoration *decoration) { - wl_signal_emit(&decoration->events.destroy, decoration); + wlr_signal_emit_safe(&decoration->events.destroy, decoration); wl_list_remove(&decoration->surface_destroy_listener.link); wl_resource_set_user_data(decoration->resource, NULL); wl_list_remove(&decoration->link); @@ -97,7 +98,7 @@ static void server_decoration_manager_handle_create(struct wl_client *client, org_kde_kwin_server_decoration_send_mode(decoration->resource, decoration->mode); - wl_signal_emit(&manager->events.new_decoration, decoration); + wlr_signal_emit_safe(&manager->events.new_decoration, decoration); } static const struct org_kde_kwin_server_decoration_manager_interface diff --git a/types/wlr_surface.c b/types/wlr_surface.c index 045e3670..c47565c4 100644 --- a/types/wlr_surface.c +++ b/types/wlr_surface.c @@ -1,12 +1,13 @@ #include <assert.h> #include <stdlib.h> #include <wayland-server.h> -#include <wlr/util/log.h> -#include <wlr/util/region.h> -#include <wlr/render/interface.h> -#include <wlr/types/wlr_surface.h> #include <wlr/render/egl.h> +#include <wlr/render/interface.h> #include <wlr/render/matrix.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/util/log.h> +#include <wlr/util/region.h> +#include "util/signal.h" static void wlr_surface_state_reset_buffer(struct wlr_surface_state *state) { if (state->buffer) { @@ -395,7 +396,7 @@ static void wlr_surface_commit_pending(struct wlr_surface *surface) { } // TODO: add the invalid bitfield to this callback - wl_signal_emit(&surface->events.commit, surface); + wlr_signal_emit_safe(&surface->events.commit, surface); pixman_region32_clear(&surface->current->surface_damage); pixman_region32_clear(&surface->current->buffer_damage); @@ -559,7 +560,7 @@ static void wlr_surface_state_destroy(struct wlr_surface_state *state) { } void wlr_subsurface_destroy(struct wlr_subsurface *subsurface) { - wl_signal_emit(&subsurface->events.destroy, subsurface); + wlr_signal_emit_safe(&subsurface->events.destroy, subsurface); wlr_surface_state_destroy(subsurface->cached); @@ -578,7 +579,7 @@ void wlr_subsurface_destroy(struct wlr_subsurface *subsurface) { static void destroy_surface(struct wl_resource *resource) { struct wlr_surface *surface = wl_resource_get_user_data(resource); - wl_signal_emit(&surface->events.destroy, surface); + wlr_signal_emit_safe(&surface->events.destroy, surface); if (surface->subsurface) { wlr_subsurface_destroy(surface->subsurface); @@ -831,7 +832,7 @@ void wlr_surface_make_subsurface(struct wlr_surface *surface, surface->subsurface = subsurface; - wl_signal_emit(&parent->events.new_subsurface, subsurface); + wlr_signal_emit_safe(&parent->events.new_subsurface, subsurface); } diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c index 07f9da10..3d25d685 100644 --- a/types/wlr_tablet_pad.c +++ b/types/wlr_tablet_pad.c @@ -1,8 +1,8 @@ #include <stdlib.h> #include <string.h> #include <wayland-server.h> -#include <wlr/types/wlr_tablet_pad.h> #include <wlr/interfaces/wlr_tablet_pad.h> +#include <wlr/types/wlr_tablet_pad.h> void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, struct wlr_tablet_pad_impl *impl) { diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c index a396bb02..f46a5434 100644 --- a/types/wlr_tablet_tool.c +++ b/types/wlr_tablet_tool.c @@ -1,8 +1,8 @@ #include <stdlib.h> #include <string.h> #include <wayland-server.h> -#include <wlr/types/wlr_tablet_tool.h> #include <wlr/interfaces/wlr_tablet_tool.h> +#include <wlr/types/wlr_tablet_tool.h> void wlr_tablet_tool_init(struct wlr_tablet_tool *tool, struct wlr_tablet_tool_impl *impl) { diff --git a/types/wlr_touch.c b/types/wlr_touch.c index 5db653e7..ba7ffac7 100644 --- a/types/wlr_touch.c +++ b/types/wlr_touch.c @@ -1,8 +1,8 @@ #include <stdlib.h> #include <string.h> #include <wayland-server.h> -#include <wlr/types/wlr_touch.h> #include <wlr/interfaces/wlr_touch.h> +#include <wlr/types/wlr_touch.h> void wlr_touch_init(struct wlr_touch *touch, struct wlr_touch_impl *impl) { diff --git a/types/wlr_wl_shell.c b/types/wlr_wl_shell.c index dd6514df..85749ddd 100644 --- a/types/wlr_wl_shell.c +++ b/types/wlr_wl_shell.c @@ -2,12 +2,13 @@ #define _POSIX_C_SOURCE 200809L #endif #include <assert.h> +#include <stdlib.h> +#include <wayland-server-protocol.h> #include <wayland-server.h> -#include <wlr/util/log.h> #include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_wl_shell.h> -#include <stdlib.h> -#include <wayland-server-protocol.h> +#include <wlr/util/log.h> +#include "util/signal.h" static const char *wlr_wl_shell_surface_role = "wl-shell-surface"; @@ -123,7 +124,7 @@ static void shell_surface_protocol_move(struct wl_client *client, .serial = serial, }; - wl_signal_emit(&surface->events.request_move, &event); + wlr_signal_emit_safe(&surface->events.request_move, &event); } static struct wlr_wl_shell_popup_grab *shell_popup_grab_from_seat( @@ -187,7 +188,7 @@ static void shell_surface_protocol_resize(struct wl_client *client, .edges = edges, }; - wl_signal_emit(&surface->events.request_resize, &event); + wlr_signal_emit_safe(&surface->events.request_resize, &event); } static void shell_surface_set_state(struct wlr_wl_shell_surface *surface, @@ -200,7 +201,7 @@ static void shell_surface_set_state(struct wlr_wl_shell_surface *surface, shell_surface_destroy_popup_state(surface); surface->popup_state = popup_state; - wl_signal_emit(&surface->events.set_state, surface); + wlr_signal_emit_safe(&surface->events.set_state, surface); } static void shell_surface_protocol_set_toplevel(struct wl_client *client, @@ -221,7 +222,7 @@ static void shell_surface_popup_set_parent(struct wlr_wl_shell_surface *surface, if (parent) { wl_list_remove(&surface->popup_link); wl_list_insert(&parent->popups, &surface->popup_link); - wl_signal_emit(&parent->events.new_popup, surface); + wlr_signal_emit_safe(&parent->events.new_popup, surface); } } @@ -290,7 +291,7 @@ static void shell_surface_protocol_set_fullscreen(struct wl_client *client, .output = output, }; - wl_signal_emit(&surface->events.request_fullscreen, &event); + wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } static void shell_surface_protocol_set_popup(struct wl_client *client, @@ -368,7 +369,7 @@ static void shell_surface_protocol_set_maximized(struct wl_client *client, .output = output, }; - wl_signal_emit(&surface->events.request_maximize, &event); + wlr_signal_emit_safe(&surface->events.request_maximize, &event); } static void shell_surface_protocol_set_title(struct wl_client *client, @@ -384,7 +385,7 @@ static void shell_surface_protocol_set_title(struct wl_client *client, free(surface->title); surface->title = tmp; - wl_signal_emit(&surface->events.set_title, surface); + wlr_signal_emit_safe(&surface->events.set_title, surface); } static void shell_surface_protocol_set_class(struct wl_client *client, @@ -400,7 +401,7 @@ static void shell_surface_protocol_set_class(struct wl_client *client, free(surface->class); surface->class = tmp; - wl_signal_emit(&surface->events.set_class, surface); + wlr_signal_emit_safe(&surface->events.set_class, surface); } static const struct wl_shell_surface_interface shell_surface_impl = { @@ -417,7 +418,7 @@ static const struct wl_shell_surface_interface shell_surface_impl = { }; static void shell_surface_destroy(struct wlr_wl_shell_surface *surface) { - wl_signal_emit(&surface->events.destroy, surface); + wlr_signal_emit_safe(&surface->events.destroy, surface); shell_surface_destroy_popup_state(surface); wl_resource_set_user_data(surface->resource, NULL); @@ -457,7 +458,7 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, wlr_surface_has_buffer(surface->surface) && surface->state != WLR_WL_SHELL_SURFACE_STATE_NONE) { surface->configured = true; - wl_signal_emit(&surface->shell->events.new_surface, surface); + wlr_signal_emit_safe(&surface->shell->events.new_surface, surface); } if (surface->popup_mapped && @@ -473,7 +474,7 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, static int shell_surface_ping_timeout(void *user_data) { struct wlr_wl_shell_surface *surface = user_data; - wl_signal_emit(&surface->events.ping_timeout, surface); + wlr_signal_emit_safe(&surface->events.ping_timeout, surface); surface->ping_serial = 0; return 1; diff --git a/types/wlr_xdg_shell_v6.c b/types/wlr_xdg_shell_v6.c index 5c820edc..eb18f022 100644 --- a/types/wlr_xdg_shell_v6.c +++ b/types/wlr_xdg_shell_v6.c @@ -6,10 +6,11 @@ #include <string.h> #include <wayland-server.h> #include <wlr/config.h> -#include <wlr/types/wlr_xdg_shell_v6.h> -#include <wlr/types/wlr_surface.h> #include <wlr/types/wlr_seat.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/types/wlr_xdg_shell_v6.h> #include <wlr/util/log.h> +#include "util/signal.h" #include "xdg-shell-unstable-v6-protocol.h" static const char *wlr_desktop_xdg_toplevel_role = "xdg_toplevel"; @@ -160,7 +161,7 @@ static struct wlr_xdg_popup_grab_v6 *xdg_shell_popup_grab_from_seat( static void xdg_surface_destroy(struct wlr_xdg_surface_v6 *surface) { // TODO: probably need to ungrab before this event - wl_signal_emit(&surface->events.destroy, surface); + wlr_signal_emit_safe(&surface->events.destroy, surface); if (surface->configure_idle) { wl_event_source_remove(surface->configure_idle); @@ -511,7 +512,7 @@ static void xdg_surface_get_popup(struct wl_client *client, &zxdg_popup_v6_implementation, surface, xdg_popup_resource_destroy); - wl_signal_emit(&parent->events.new_popup, surface->popup_state); + wlr_signal_emit_safe(&parent->events.new_popup, surface->popup_state); } @@ -582,7 +583,7 @@ static void xdg_toplevel_protocol_show_window_menu(struct wl_client *client, .y = y, }; - wl_signal_emit(&surface->events.request_show_window_menu, &event); + wlr_signal_emit_safe(&surface->events.request_show_window_menu, &event); } static void xdg_toplevel_protocol_move(struct wl_client *client, @@ -610,7 +611,7 @@ static void xdg_toplevel_protocol_move(struct wl_client *client, .serial = serial, }; - wl_signal_emit(&surface->events.request_move, &event); + wlr_signal_emit_safe(&surface->events.request_move, &event); } static void xdg_toplevel_protocol_resize(struct wl_client *client, @@ -639,7 +640,7 @@ static void xdg_toplevel_protocol_resize(struct wl_client *client, .edges = edges, }; - wl_signal_emit(&surface->events.request_resize, &event); + wlr_signal_emit_safe(&surface->events.request_resize, &event); } static void xdg_toplevel_protocol_set_max_size(struct wl_client *client, @@ -660,14 +661,14 @@ static void xdg_toplevel_protocol_set_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); surface->toplevel_state->next.maximized = true; - wl_signal_emit(&surface->events.request_maximize, surface); + wlr_signal_emit_safe(&surface->events.request_maximize, surface); } static void xdg_toplevel_protocol_unset_maximized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); surface->toplevel_state->next.maximized = false; - wl_signal_emit(&surface->events.request_maximize, surface); + wlr_signal_emit_safe(&surface->events.request_maximize, surface); } static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, @@ -687,7 +688,7 @@ static void xdg_toplevel_protocol_set_fullscreen(struct wl_client *client, .output = output, }; - wl_signal_emit(&surface->events.request_fullscreen, &event); + wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, @@ -702,13 +703,13 @@ static void xdg_toplevel_protocol_unset_fullscreen(struct wl_client *client, .output = NULL, }; - wl_signal_emit(&surface->events.request_fullscreen, &event); + wlr_signal_emit_safe(&surface->events.request_fullscreen, &event); } static void xdg_toplevel_protocol_set_minimized(struct wl_client *client, struct wl_resource *resource) { struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource); - wl_signal_emit(&surface->events.request_minimize, surface); + wlr_signal_emit_safe(&surface->events.request_minimize, surface); } static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation = @@ -1123,7 +1124,7 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, if (surface->configured && !surface->added) { surface->added = true; - wl_signal_emit(&surface->client->shell->events.new_surface, surface); + wlr_signal_emit_safe(&surface->client->shell->events.new_surface, surface); } } @@ -1243,7 +1244,7 @@ static int wlr_xdg_client_v6_ping_timeout(void *user_data) { struct wlr_xdg_surface_v6 *surface; wl_list_for_each(surface, &client->surfaces, link) { - wl_signal_emit(&surface->events.ping_timeout, surface); + wlr_signal_emit_safe(&surface->events.ping_timeout, surface); } client->ping_serial = 0; @@ -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); +} diff --git a/xcursor/meson.build b/xcursor/meson.build index afaab915..31040a92 100644 --- a/xcursor/meson.build +++ b/xcursor/meson.build @@ -1,8 +1,8 @@ lib_wlr_xcursor = static_library( 'wlr_xcursor', files( - 'xcursor.c', 'wlr_xcursor.c', + 'xcursor.c', ), include_directories: wlr_inc, dependencies: [egl] # header required via include/wlr/render.h diff --git a/xcursor/wlr_xcursor.c b/xcursor/wlr_xcursor.c index 2d1a38b5..7fcdbb6f 100644 --- a/xcursor/wlr_xcursor.c +++ b/xcursor/wlr_xcursor.c @@ -24,12 +24,12 @@ */ #define _XOPEN_SOURCE 500 -#include <wlr/xcursor.h> -#include <wlr/util/log.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> -#include <stdint.h> #include <string.h> +#include <wlr/util/log.h> +#include <wlr/xcursor.h> #include "xcursor/xcursor.h" static void wlr_xcursor_destroy(struct wlr_xcursor *cursor) { diff --git a/xcursor/xcursor.c b/xcursor/xcursor.c index 8dc35a7c..32711105 100644 --- a/xcursor/xcursor.c +++ b/xcursor/xcursor.c @@ -24,11 +24,11 @@ */ #define _DEFAULT_SOURCE -#include "xcursor/xcursor.h" +#include <dirent.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <dirent.h> +#include "xcursor/xcursor.h" /* * From libXcursor/include/X11/extensions/Xcursor.h diff --git a/xwayland/selection.c b/xwayland/selection.c index 060c0baf..ffcde4d0 100644 --- a/xwayland/selection.c +++ b/xwayland/selection.c @@ -1,14 +1,14 @@ #define _XOPEN_SOURCE 700 +#include <assert.h> +#include <fcntl.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> -#include <assert.h> +#include <unistd.h> +#include <wlr/types/wlr_data_device.h> +#include <wlr/types/wlr_primary_selection.h> +#include <wlr/util/log.h> +#include <wlr/xwm.h> #include <xcb/xfixes.h> -#include <fcntl.h> -#include "wlr/util/log.h" -#include "wlr/types/wlr_data_device.h" -#include "wlr/types/wlr_primary_selection.h" -#include "wlr/xwm.h" static const size_t incr_chunk_size = 64 * 1024; diff --git a/xwayland/sockets.c b/xwayland/sockets.c index 2119056d..1e943b1d 100644 --- a/xwayland/sockets.c +++ b/xwayland/sockets.c @@ -3,19 +3,19 @@ // for SOCK_CLOEXEC #define __BSD_VISIBLE 1 #endif -#include <stdlib.h> +#include <errno.h> +#include <fcntl.h> +#include <signal.h> #include <stddef.h> #include <stdint.h> #include <stdio.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <signal.h> -#include <unistd.h> +#include <stdlib.h> #include <sys/socket.h> +#include <sys/stat.h> +#include <sys/types.h> #include <sys/un.h> -#include <errno.h> -#include "wlr/util/log.h" +#include <unistd.h> +#include <wlr/util/log.h> #include "sockets.h" static const char *lock_fmt = "/tmp/.X%d-lock"; diff --git a/xwayland/xwayland.c b/xwayland/xwayland.c index 6c700cc5..1d935180 100644 --- a/xwayland/xwayland.c +++ b/xwayland/xwayland.c @@ -4,22 +4,23 @@ // for SOCK_CLOEXEC #define __BSD_VISIBLE 1 #endif -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> +#include <errno.h> #include <fcntl.h> #include <signal.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdlib.h> #include <sys/socket.h> #include <sys/types.h> #include <sys/wait.h> #include <time.h> -#include <stdlib.h> -#include <errno.h> +#include <unistd.h> #include <wayland-server.h> -#include "wlr/util/log.h" -#include "wlr/xwayland.h" +#include <wlr/util/log.h> +#include <wlr/xwayland.h> +#include <wlr/xwm.h> #include "sockets.h" -#include "wlr/xwm.h" +#include "util/signal.h" #ifdef __FreeBSD__ static inline int clearenv(void) { @@ -237,7 +238,7 @@ static int xserver_handle_ready(int signal_number, void *data) { snprintf(display_name, sizeof(display_name), ":%d", wlr_xwayland->display); setenv("DISPLAY", display_name, true); - wl_signal_emit(&wlr_xwayland->events.ready, wlr_xwayland); + wlr_signal_emit_safe(&wlr_xwayland->events.ready, wlr_xwayland); /* ready is a one-shot signal, fire and forget */ wl_signal_init(&wlr_xwayland->events.ready); diff --git a/xwayland/xwm.c b/xwayland/xwm.c index e59c6e66..10bc2e30 100644 --- a/xwayland/xwm.c +++ b/xwayland/xwm.c @@ -3,17 +3,18 @@ #endif #include <stdlib.h> #include <unistd.h> +#include <wlr/config.h> +#include <wlr/types/wlr_surface.h> +#include <wlr/util/edges.h> +#include <wlr/util/log.h> +#include <wlr/xcursor.h> +#include <wlr/xwayland.h> +#include <wlr/xwm.h> #include <xcb/composite.h> -#include <xcb/xfixes.h> -#include <xcb/xcb_image.h> #include <xcb/render.h> -#include <wlr/config.h> -#include "wlr/util/log.h" -#include "wlr/util/edges.h" -#include "wlr/types/wlr_surface.h" -#include "wlr/xwayland.h" -#include "wlr/xcursor.h" -#include "wlr/xwm.h" +#include <xcb/xcb_image.h> +#include <xcb/xfixes.h> +#include "util/signal.h" #ifdef WLR_HAS_XCB_ICCCM #include <xcb/xcb_icccm.h> @@ -210,7 +211,7 @@ static void xsurface_set_net_wm_state(struct wlr_xwayland_surface *xsurface) { static void wlr_xwayland_surface_destroy( struct wlr_xwayland_surface *xsurface) { - wl_signal_emit(&xsurface->events.destroy, xsurface); + wlr_signal_emit_safe(&xsurface->events.destroy, xsurface); if (xsurface == xsurface->xwm->focus_surface) { xwm_surface_activate(xsurface->xwm, NULL); @@ -266,7 +267,7 @@ static void read_surface_class(struct wlr_xwm *xwm, wlr_log(L_DEBUG, "XCB_ATOM_WM_CLASS: %s %s", surface->instance, surface->class); - wl_signal_emit(&surface->events.set_class, surface); + wlr_signal_emit_safe(&surface->events.set_class, surface); } static void read_surface_title(struct wlr_xwm *xwm, @@ -291,7 +292,7 @@ static void read_surface_title(struct wlr_xwm *xwm, } wlr_log(L_DEBUG, "XCB_ATOM_WM_NAME: %s", xsurface->title); - wl_signal_emit(&xsurface->events.set_title, xsurface); + wlr_signal_emit_safe(&xsurface->events.set_title, xsurface); } static void read_surface_parent(struct wlr_xwm *xwm, @@ -316,7 +317,7 @@ static void read_surface_parent(struct wlr_xwm *xwm, } wlr_log(L_DEBUG, "XCB_ATOM_WM_TRANSIENT_FOR: %p", xsurface->parent); - wl_signal_emit(&xsurface->events.set_parent, xsurface); + wlr_signal_emit_safe(&xsurface->events.set_parent, xsurface); } static void read_surface_pid(struct wlr_xwm *xwm, @@ -329,7 +330,7 @@ static void read_surface_pid(struct wlr_xwm *xwm, pid_t *pid = xcb_get_property_value(reply); xsurface->pid = *pid; wlr_log(L_DEBUG, "NET_WM_PID %d", xsurface->pid); - wl_signal_emit(&xsurface->events.set_pid, xsurface); + wlr_signal_emit_safe(&xsurface->events.set_pid, xsurface); } static void read_surface_window_type(struct wlr_xwm *xwm, @@ -352,7 +353,7 @@ static void read_surface_window_type(struct wlr_xwm *xwm, xsurface->window_type_len = atoms_len; wlr_log(L_DEBUG, "NET_WM_WINDOW_TYPE (%zu)", atoms_len); - wl_signal_emit(&xsurface->events.set_window_type, xsurface); + wlr_signal_emit_safe(&xsurface->events.set_window_type, xsurface); } static void read_surface_protocols(struct wlr_xwm *xwm, @@ -535,7 +536,7 @@ static void handle_surface_commit(struct wlr_surface *wlr_surface, if (!xsurface->added && wlr_surface_has_buffer(xsurface->surface) && xsurface->mapped) { - wl_signal_emit(&xsurface->xwm->xwayland->events.new_surface, xsurface); + wlr_signal_emit_safe(&xsurface->xwm->xwayland->events.new_surface, xsurface); xsurface->added = true; } } @@ -578,7 +579,7 @@ static void xwm_map_shell_surface(struct wlr_xwm *xwm, wl_signal_add(&surface->events.destroy, &xsurface->surface_destroy); xsurface->mapped = true; - wl_signal_emit(&xsurface->events.map_notify, xsurface); + wlr_signal_emit_safe(&xsurface->events.map_notify, xsurface); } static void xwm_handle_create_notify(struct wlr_xwm *xwm, @@ -626,7 +627,7 @@ static void xwm_handle_configure_request(struct wlr_xwm *xwm, wlr_event->width = ev->width; wlr_event->height = ev->height; - wl_signal_emit(&xsurface->events.request_configure, wlr_event); + wlr_signal_emit_safe(&xsurface->events.request_configure, wlr_event); free(wlr_event); } @@ -710,7 +711,7 @@ static void xwm_handle_unmap_notify(struct wlr_xwm *xwm, if (xsurface->mapped) { xsurface->mapped = false; - wl_signal_emit(&xsurface->events.unmap_notify, xsurface); + wlr_signal_emit_safe(&xsurface->events.unmap_notify, xsurface); } xsurface_set_wm_state(xsurface, ICCCM_WITHDRAWN_STATE); @@ -814,7 +815,7 @@ static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm, switch (detail) { case _NET_WM_MOVERESIZE_MOVE: move_event.surface = xsurface; - wl_signal_emit(&xsurface->events.request_move, &move_event); + wlr_signal_emit_safe(&xsurface->events.request_move, &move_event); break; case _NET_WM_MOVERESIZE_SIZE_TOPLEFT: case _NET_WM_MOVERESIZE_SIZE_TOP: @@ -826,7 +827,7 @@ static void xwm_handle_net_wm_moveresize_message(struct wlr_xwm *xwm, case _NET_WM_MOVERESIZE_SIZE_LEFT: resize_event.surface = xsurface; resize_event.edges = net_wm_edges_to_wlr(detail); - wl_signal_emit(&xsurface->events.request_resize, &resize_event); + wlr_signal_emit_safe(&xsurface->events.request_resize, &resize_event); break; case _NET_WM_MOVERESIZE_CANCEL: // handled by the compositor @@ -904,7 +905,7 @@ static void xwm_handle_net_wm_state_message(struct wlr_xwm *xwm, xsurface->saved_height = xsurface->height; } - wl_signal_emit(&xsurface->events.request_fullscreen, xsurface); + wlr_signal_emit_safe(&xsurface->events.request_fullscreen, xsurface); } if (maximized != xsurface_is_maximized(xsurface)) { @@ -913,7 +914,7 @@ static void xwm_handle_net_wm_state_message(struct wlr_xwm *xwm, xsurface->saved_height = xsurface->height; } - wl_signal_emit(&xsurface->events.request_maximize, xsurface); + wlr_signal_emit_safe(&xsurface->events.request_maximize, xsurface); } } |