From 9d75a88d3f275d10f0c17be4484db6a5ba6e1c9b Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Tue, 5 Jun 2018 17:38:44 -0700 Subject: [PATCH] Quick fix for ncurses buffering issue with inotify polling. Ncurses does its own buffering for some character sequences, notable Esc-prefixed input. Add a non-blocking check for getch() before performing the mutt_monitor_poll() call. This is a quick fix, which I'll clean up more later. --- curs_lib.c | 28 +++++++++++++++++++++++----- monitor.c | 5 +++++ monitor.h | 1 + 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/curs_lib.c b/curs_lib.c index 63ab60f38..f1c0943e7 100644 --- a/curs_lib.c +++ b/curs_lib.c @@ -132,6 +132,25 @@ void mutt_getch_timeout(int delay) #endif } +#ifdef USE_INOTIFY +static int mutt_monitor_getch(void) +{ + /* ncurses has its own internal buffer, so before we perform a poll, + * we need to make sure there isn't a character waiting */ + timeout(0); + int ch = getch(); + timeout(mutt_monitor_get_poll_timeout()); + if (ch == ERR) + { + if (mutt_monitor_poll() != 0) + ch = ERR; + else + ch = getch(); + } + return ch; +} +#endif /* USE_INOTIFY */ + /** * mutt_getch - Read a character from the input buffer * @retval obj Event to process @@ -166,11 +185,10 @@ struct Event mutt_getch(void) while (ch == KEY_RESIZE) #endif /* KEY_RESIZE */ #ifdef USE_INOTIFY - if (mutt_monitor_poll() != 0) - ch = ERR; - else -#endif - ch = getch(); + ch = mutt_monitor_getch(); +#else + ch = getch(); +#endif /* USE_INOTIFY */ mutt_sig_allow_interrupt(0); if (SigInt) diff --git a/monitor.c b/monitor.c index 30019cd6b..2e9d3c67b 100644 --- a/monitor.c +++ b/monitor.c @@ -219,6 +219,11 @@ void mutt_monitor_set_poll_timeout(int timeout) PollTimeout = timeout; } +int mutt_monitor_get_poll_timeout(void) +{ + return PollTimeout; +} + #define EVENT_BUFLEN MAX(4096, sizeof(struct inotify_event) + NAME_MAX + 1) /* mutt_monitor_poll: Waits for I/O ready file descriptors or signals. diff --git a/monitor.h b/monitor.h index d61550b05..4d76ca001 100644 --- a/monitor.h +++ b/monitor.h @@ -30,6 +30,7 @@ struct Mailbox; int mutt_monitor_add(struct Mailbox *b); int mutt_monitor_remove(struct Mailbox *b); void mutt_monitor_set_poll_timeout(int timeout); +int mutt_monitor_get_poll_timeout(void); int mutt_monitor_poll(void); #endif /* _MUTT_MONITOR_H */ -- 2.50.1