From 9ed50c768c9169fd6b968a91edeb161694cf9fcf Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 19 Sep 2008 08:02:40 +0200 Subject: [PATCH] fix terminal resizing (SIGWINCH) When I replaced ncmpc's old main loop with g_main_loop from libglib, SIGWINCH (i.e. window resizing) stopped working. This regression was caused by the fact that ncurses' wgetch() function was only called when there was actually data on STDIN. wgetch() has several side effects besides reading data from STDIN, for example it checks whether there has been a window resize. Fix this with a custom SIGWINCH handler. --- src/main.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/main.c b/src/main.c index c8b22df..6f662f5 100644 --- a/src/main.c +++ b/src/main.c @@ -150,6 +150,31 @@ sigstop(void) kill(0, SIGSTOP); /* issue SIGSTOP */ } +static guint timer_sigwinch_id; + +static gboolean +timer_sigwinch(mpd_unused gpointer data) +{ + /* the following causes the screen to flicker. There might be + better solutions, but I believe it isn't all that + important. */ + + endwin(); + refresh(); + screen_resize(); + + return FALSE; +} + +static void +catch_sigwinch(mpd_unused int sig) +{ + if (timer_sigwinch_id != 0) + g_source_remove(timer_sigwinch_id); + + timer_sigwinch_id = g_timeout_add(100, timer_sigwinch, NULL); +} + #ifndef NDEBUG void D(const char *format, ...) @@ -383,6 +408,14 @@ main(int argc, const char *argv[]) exit(EXIT_FAILURE); } + /* setup SIGWINCH */ + + act.sa_handler = catch_sigwinch; + if (sigaction(SIGWINCH, &act, NULL) < 0) { + perror("sigaction(SIGWINCH)"); + exit(EXIT_FAILURE); + } + ncurses_init(); lyrics_init(); -- 2.30.2