summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorben <benjaminfranzke@googlemail.com>2010-07-20 04:11:34 +0200
committerben <benjaminfranzke@googlemail.com>2010-07-20 04:11:34 +0200
commit1d05c36d6c872fa2999f9e595bc3eaac31d8ee5a (patch)
tree3b7c2ce53836030becb9db13369a45755d069b1a
parentf23887c39d2b76adedc289123c6f5f3e49a7094b (diff)
downloadpa-sink-ctl-1d05c36d6c872fa2999f9e595bc3eaac31d8ee5a.tar.gz
pa-sink-ctl-1d05c36d6c872fa2999f9e595bc3eaac31d8ee5a.tar.bz2
pa-sink-ctl-1d05c36d6c872fa2999f9e595bc3eaac31d8ee5a.zip
resize support using resize_term and ioctl
-rw-r--r--src/interface.c47
1 files changed, 36 insertions, 11 deletions
diff --git a/src/interface.c b/src/interface.c
index f5862f9..5578376 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -1,11 +1,15 @@
#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+
#include <signal.h>
+#include <unistd.h>
+#include <sys/ioctl.h>
+
#include <glib.h>
#include <pulse/pulseaudio.h>
#include <ncurses.h>
-#include <string.h>
-#include <stdlib.h>
-#include <stdbool.h>
#include "interface.h"
#include "sink.h"
@@ -26,14 +30,29 @@ extern pa_context* context;
void resize(int signal);
-void foo(void)
+bool resize_running = false;
+bool resize_pending = false;
+
+static void set_resize_callback(void)
{
signal(SIGWINCH, resize);
}
+
void resize(int signal)
{
- foo();
- interface_resize();
+ set_resize_callback();
+
+ if (resize_running) {
+ resize_pending = true;
+ return;
+ }
+
+ resize_running = true;
+ do {
+ resize_pending = false;
+ interface_resize();
+ } while (resize_pending);
+ resize_running = false;
}
void interface_init(void)
@@ -52,18 +71,24 @@ void interface_init(void)
keypad(menu_win, TRUE);
curs_set(0); /* hide cursor */
mvprintw(0, 0, "Use arrow keys to go up and down, Press enter to select a choice");
- signal(SIGWINCH, resize);
+ set_resize_callback();
refresh();
}
void interface_resize(void)
{
- getmaxyx(stdscr, height, width);
+ struct winsize wsize = (struct winsize) { 0 };
+ if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &wsize) >= 0) {
+ height = wsize.ws_row;
+ width = wsize.ws_col;
+ }
+
+ resize_term(height, width);
+ clear();
+ refresh();
+
wresize(menu_win, height, width);
- wclear(stdscr);
- wclear(menu_win);
-
print_sink_list();
}