diff options
author | Simon Ser <contact@emersion.fr> | 2023-08-11 19:28:07 +0200 |
---|---|---|
committer | Isaac Freund <mail@isaacfreund.com> | 2023-11-23 11:15:07 +0000 |
commit | 63792b38e46ae1741a6492d3c0183cb9566e4c9f (patch) | |
tree | 17d21d15f1dc5145c03aa95e55a1b2bdf65c898f /backend/session/session.c | |
parent | f1762f428b0ef2989c81f57ea9e810403d34d946 (diff) |
backend/session: take wl_event_loop instead of wl_display
wl_display holds a lot more than wlr_session needs: wlr_session
only needs to wait for a FD to become readable, but wl_display
provides full access to the Wayland client and protocol objects.
Switch to wl_event_loop to better reflect the above.
Diffstat (limited to 'backend/session/session.c')
-rw-r--r-- | backend/session/session.c | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/backend/session/session.c b/backend/session/session.c index 7b8b0bc2..52b2654b 100644 --- a/backend/session/session.c +++ b/backend/session/session.c @@ -39,7 +39,7 @@ static int libseat_event(int fd, uint32_t mask, void *data) { struct wlr_session *session = data; if (libseat_dispatch(session->seat_handle, 0) == -1) { wlr_log_errno(WLR_ERROR, "Failed to dispatch libseat"); - wl_display_terminate(session->display); + wlr_session_destroy(session); } return 1; } @@ -71,7 +71,8 @@ static void log_libseat(enum libseat_log_level level, _wlr_vlog(importance, wlr_fmt, args); } -static int libseat_session_init(struct wlr_session *session, struct wl_display *disp) { +static int libseat_session_init(struct wlr_session *session, + struct wl_event_loop *event_loop) { libseat_set_log_handler(log_libseat); libseat_set_log_level(LIBSEAT_LOG_LEVEL_INFO); @@ -91,7 +92,6 @@ static int libseat_session_init(struct wlr_session *session, struct wl_display * } snprintf(session->seat, sizeof(session->seat), "%s", seat_name); - struct wl_event_loop *event_loop = wl_display_get_event_loop(disp); session->libseat_event = wl_event_loop_add_fd(event_loop, libseat_get_fd(session->seat_handle), WL_EVENT_READABLE, libseat_event, session); if (session->libseat_event == NULL) { @@ -226,25 +226,26 @@ out: return 1; } -static void handle_display_destroy(struct wl_listener *listener, void *data) { +static void handle_event_loop_destroy(struct wl_listener *listener, void *data) { struct wlr_session *session = - wl_container_of(listener, session, display_destroy); + wl_container_of(listener, session, event_loop_destroy); wlr_session_destroy(session); } -struct wlr_session *wlr_session_create(struct wl_display *disp) { +struct wlr_session *wlr_session_create(struct wl_event_loop *event_loop) { struct wlr_session *session = calloc(1, sizeof(*session)); if (!session) { wlr_log_errno(WLR_ERROR, "Allocation failed"); return NULL; } + session->event_loop = event_loop; wl_signal_init(&session->events.active); wl_signal_init(&session->events.add_drm_card); wl_signal_init(&session->events.destroy); wl_list_init(&session->devices); - if (libseat_session_init(session, disp) == -1) { + if (libseat_session_init(session, event_loop) == -1) { wlr_log(WLR_ERROR, "Failed to load session backend"); goto error_open; } @@ -264,7 +265,6 @@ struct wlr_session *wlr_session_create(struct wl_display *disp) { udev_monitor_filter_add_match_subsystem_devtype(session->mon, "drm", NULL); udev_monitor_enable_receiving(session->mon); - struct wl_event_loop *event_loop = wl_display_get_event_loop(disp); int fd = udev_monitor_get_fd(session->mon); session->udev_event = wl_event_loop_add_fd(event_loop, fd, @@ -274,10 +274,8 @@ struct wlr_session *wlr_session_create(struct wl_display *disp) { goto error_mon; } - session->display = disp; - - session->display_destroy.notify = handle_display_destroy; - wl_display_add_destroy_listener(disp, &session->display_destroy); + session->event_loop_destroy.notify = handle_event_loop_destroy; + wl_event_loop_add_destroy_listener(event_loop, &session->event_loop_destroy); return session; @@ -298,7 +296,7 @@ void wlr_session_destroy(struct wlr_session *session) { } wl_signal_emit_mutable(&session->events.destroy, session); - wl_list_remove(&session->display_destroy.link); + wl_list_remove(&session->event_loop_destroy.link); wl_event_source_remove(session->udev_event); udev_monitor_unref(session->mon); @@ -472,10 +470,8 @@ ssize_t wlr_session_find_gpus(struct wlr_session *session, int64_t started_at = get_current_time_msec(); int64_t timeout = WAIT_GPU_TIMEOUT; - struct wl_event_loop *event_loop = - wl_display_get_event_loop(session->display); while (!handler.added) { - int ret = wl_event_loop_dispatch(event_loop, (int)timeout); + int ret = wl_event_loop_dispatch(session->event_loop, (int)timeout); if (ret < 0) { wlr_log_errno(WLR_ERROR, "Failed to wait for DRM card device: " "wl_event_loop_dispatch failed"); |