From fde784129f4b94b6fa8b2293127c41dc140b7d3a Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 20 Jul 2016 20:52:08 +0200 Subject: x11: stop using vo.event_fd Instead let it do its own event loop wakeup handling. --- video/out/x11_common.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'video/out/x11_common.c') diff --git a/video/out/x11_common.c b/video/out/x11_common.c index 33c588a808..2f35b6a4b8 100644 --- a/video/out/x11_common.c +++ b/video/out/x11_common.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include #include "config.h" #include "misc/bstr.h" @@ -38,6 +40,7 @@ #include "vo.h" #include "win_state.h" #include "osdep/atomics.h" +#include "osdep/io.h" #include "osdep/timer.h" #include "osdep/subprocess.h" @@ -593,7 +596,8 @@ int vo_x11_init(struct vo *vo) x11->wm_type = vo_wm_detect(vo); - vo->event_fd = ConnectionNumber(x11->display); + x11->event_fd = ConnectionNumber(x11->display); + mp_make_wakeup_pipe(x11->wakeup_pipe); xrandr_read(x11); @@ -761,6 +765,9 @@ void vo_x11_uninit(struct vo *vo) sem_destroy(&x11->screensaver_sem); } + for (int n = 0; n < 2; n++) + close(x11->wakeup_pipe[n]); + talloc_free(x11); vo->x11 = NULL; } @@ -1907,6 +1914,32 @@ int vo_x11_control(struct vo *vo, int *events, int request, void *arg) return VO_NOTIMPL; } +void vo_x11_wakeup(struct vo *vo) +{ + struct vo_x11_state *x11 = vo->x11; + + (void)write(x11->wakeup_pipe[1], &(char){0}, 1); +} + +void vo_x11_wait_events(struct vo *vo, int64_t until_time_us) +{ + struct vo_x11_state *x11 = vo->x11; + + struct pollfd fds[2] = { + { .fd = x11->event_fd, .events = POLLIN }, + { .fd = x11->wakeup_pipe[0], .events = POLLIN }, + }; + int64_t wait_us = until_time_us - mp_time_us(); + int timeout_ms = MPCLAMP((wait_us + 500) / 1000, 0, 10000); + + poll(fds, 2, timeout_ms); + + if (fds[1].revents & POLLIN) { + char buf[100]; + (void)read(x11->wakeup_pipe[0], buf, sizeof(buf)); // flush + } +} + static void xscreensaver_heartbeat(struct vo_x11_state *x11) { double time = mp_time_sec(); -- cgit v1.2.3