From 4cbd894803f239af3e320aece24521aeb325cbd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Sat, 4 Jan 2020 23:27:59 +0100 Subject: [PATCH] wayland: use a low priority FDM hook to flush the wayland socket This way, we don't have to manually insert flushes in code paths that may execute outside of a wl_display_dispatch_pending(). (Those that execute inside a wl_display_dispatch_pending() are subject to the flush performed at the end of the normal wayland FDM handler). --- render.c | 2 -- wayland.c | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/render.c b/render.c index 023b904c..1bbe2853 100644 --- a/render.c +++ b/render.c @@ -852,7 +852,6 @@ grid_render(struct terminal *term) } wl_surface_commit(term->window->surface); - wayl_flush(term->wl); #if TIME_FRAME_RENDERING struct timeval end_time; @@ -1141,7 +1140,6 @@ render_xcursor_update(struct wayland *wayl, const struct terminal *term) wl_callback_add_listener(wayl->pointer.xcursor_callback, &xcursor_listener, wayl); wl_surface_commit(wayl->pointer.surface); - wayl_flush(wayl); } static void diff --git a/wayland.c b/wayland.c index b8edd505..ee304bd3 100644 --- a/wayland.c +++ b/wayland.c @@ -556,6 +556,13 @@ static const struct wl_registry_listener registry_listener = { .global_remove = &handle_global_remove, }; +static void +fdm_hook(struct fdm *fdm, void *data) +{ + struct wayland *wayl = data; + wayl_flush(wayl); +} + static bool fdm_wayl(struct fdm *fdm, int fd, int events, void *data) { @@ -574,7 +581,6 @@ fdm_wayl(struct fdm *fdm, int fd, int events, void *data) return false; } - wayl_flush(wayl); return event_count != -1; } @@ -730,6 +736,11 @@ wayl_init(const struct config *conf, struct fdm *fdm) goto out; } + if (!fdm_hook_add(fdm, &fdm_hook, wayl, FDM_HOOK_PRIORITY_LOW)) { + LOG_ERR("failed to add FDM hook"); + goto out; + } + return wayl; out: @@ -755,6 +766,8 @@ wayl_destroy(struct wayland *wayl) tll_free(wayl->terms); + fdm_hook_del(wayl->fdm, &fdm_hook, FDM_HOOK_PRIORITY_LOW); + if (wayl->kbd.repeat.fd != -1) fdm_del(wayl->fdm, wayl->kbd.repeat.fd);