aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-09-19 08:02:40 +0200
committerMax Kellermann <max@duempel.org>2008-09-19 08:02:40 +0200
commit9ed50c768c9169fd6b968a91edeb161694cf9fcf (patch)
tree2c97b11bbe5f3500f7b33a37ec2e86586e05c6d7
parent5fa6d11cc8b1a22456ec90416089e2f40a9f1763 (diff)
downloadmpd-9ed50c768c9169fd6b968a91edeb161694cf9fcf.tar.gz
mpd-9ed50c768c9169fd6b968a91edeb161694cf9fcf.tar.xz
mpd-9ed50c768c9169fd6b968a91edeb161694cf9fcf.zip
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.
Diffstat (limited to '')
-rw-r--r--src/main.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index c8b22df5f..6f662f53c 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();