From 86790494d38c4f33f74875e1ab7a9dc1bdae1772 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Tue, 3 Apr 2012 08:13:12 +0200 Subject: OSX, input: implement wakeup in response to Cocoa events Add code to wake up the select() call in input.c when an OSX event is available and a Cocoa OpenGL backend is initialized. Fixes the slow response to input or other events in Cocoa-based VOs during long select() sleeps (e.g., when mplayer2 is paused) introduced by commit 7040968. --- input/input.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'input') diff --git a/input/input.c b/input/input.c index e422e9f1a2..191b378deb 100644 --- a/input/input.c +++ b/input/input.c @@ -59,6 +59,10 @@ #include "ar.h" +#ifdef CONFIG_COCOA +#include "osdep/cocoa_events.h" +#endif + #define MP_MAX_KEY_DOWN 32 struct cmd_bind { @@ -1436,7 +1440,7 @@ static void read_events(struct input_ctx *ictx, int time) * every source until it's known to be empty. Instead we use this wrapper * to run select() again. */ -static void read_all_events(struct input_ctx *ictx, int time) +static void read_all_fd_events(struct input_ctx *ictx, int time) { while (1) { read_events(ictx, time); @@ -1446,6 +1450,15 @@ static void read_all_events(struct input_ctx *ictx, int time) } } +static void read_all_events(struct input_ctx *ictx, int time) +{ +#ifdef CONFIG_COCOA + cocoa_events_read_all_events(ictx, time); +#else + read_all_fd_events(ictx, time); +#endif +} + int mp_input_queue_cmd(struct input_ctx *ictx, mp_cmd_t *cmd) { ictx->got_new_events = true; @@ -1743,6 +1756,10 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf) .wakeup_pipe = {-1, -1}, }; +#ifdef CONFIG_COCOA + cocoa_events_init(ictx, read_all_fd_events); +#endif + #ifndef __MINGW32__ long ret = pipe(ictx->wakeup_pipe); for (int i = 0; i < 2 && ret >= 0; i++) { @@ -1848,11 +1865,16 @@ struct input_ctx *mp_input_init(struct input_conf *input_conf) mp_tmsg(MSGT_INPUT, MSGL_ERR, "Can't open %s: %s\n", input_conf->in_file, strerror(errno)); } + return ictx; } void mp_input_uninit(struct input_ctx *ictx) { +#ifdef CONFIG_COCOA + cocoa_events_uninit(); +#endif + if (!ictx) return; -- cgit v1.2.3