summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenjamin Franzke <benjaminfranzke@googlemail.com>2011-10-20 08:45:01 +0200
committerBenjamin Franzke <benjaminfranzke@googlemail.com>2011-10-20 08:54:57 +0200
commitaf293d4059ff1e0873d452d871d41b501ed1636a (patch)
treebd1bedd07106057981ff939715ee58d0d731f733 /src
parent2d9ad6d33aabafa51f05598cce3eda72bf815da8 (diff)
downloadpa-sink-ctl-af293d4059ff1e0873d452d871d41b501ed1636a.tar.gz
pa-sink-ctl-af293d4059ff1e0873d452d871d41b501ed1636a.tar.bz2
pa-sink-ctl-af293d4059ff1e0873d452d871d41b501ed1636a.zip
Kill off g_curses_input
Use a g_io_channel that listens to STDIN_FILENO instead.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/g_curses_input.c79
-rw-r--r--src/g_curses_input.h15
-rw-r--r--src/interface.c16
4 files changed, 13 insertions, 101 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 78e47d7..690ed8d 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,8 +1,8 @@
bin_PROGRAMS = pa-sink-ctl
-pa_sink_ctl_SOURCES = interface.c pa-sink-ctl.c sink.c sink_input.c g_unix_signal.c g_curses_input.c
+pa_sink_ctl_SOURCES = interface.c pa-sink-ctl.c sink.c sink_input.c g_unix_signal.c
AM_CFLAGS = $(GCC_CFLAGS)
AM_CPPFLAGS = $(PULSE_CFLAGS) $(PULSE_MAINLOOP_CFLAGS) $(GLIB_CFLAGS)
pa_sink_ctl_LDADD = $(GLIB_LIBS) $(PULSE_LIBS) $(PULSE_MAINLOOP_LIBS) $(CURSES_LIBS)
-noinst_HEADERS = interface.h pa-sink-ctl.h sink.h sink_input.h g_unix_signal.h g_curses_input.h
+noinst_HEADERS = interface.h pa-sink-ctl.h sink.h sink_input.h g_unix_signal.h
diff --git a/src/g_curses_input.c b/src/g_curses_input.c
deleted file mode 100644
index ece0213..0000000
--- a/src/g_curses_input.c
+++ /dev/null
@@ -1,79 +0,0 @@
-#include <curses.h>
-#include <glib.h>
-#include "interface.h"
-#include "g_curses_input.h"
-
-typedef struct _GCursesInput {
- GSource source;
- WINDOW *win;
-} GCursesInput;
-
-static gboolean
-check(GSource *source)
-{
- GCursesInput *curses_input = (GCursesInput*) source;
- gint ch = wgetch(curses_input->win);
-
- if (ch != ERR)
- ungetch(ch);
- return ch != ERR;
-}
-
-static gboolean
-prepare(GSource *source, gint *timeout_)
-{
- *timeout_ = 2;
- return check(source);
-}
-
-static gboolean
-dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
-{
- GCursesInput *curses_input = (GCursesInput*) source;
-
- return callback((gpointer)curses_input->win) ? TRUE : FALSE;
-}
-
-static GSourceFuncs SourceFuncs =
-{
- .prepare = prepare,
- .check = check,
- .dispatch = dispatch,
- .finalize = NULL,
- .closure_callback = NULL, .closure_marshal = NULL
-};
-
-GSource *
-g_curses_input_source_new(WINDOW *win) {
- GSource *source = g_source_new(&SourceFuncs, sizeof(GCursesInput));
- GCursesInput *curses_input = (GCursesInput*) source;
-
- curses_input->win = win;
- nodelay(win, TRUE); /* important! make wgetch non-blocking */
-
- return source;
-}
-
-guint
-g_curses_input_add_full(gint priority, WINDOW *win, GSourceFunc function,
- gpointer data, GDestroyNotify notify)
-{
- g_return_val_if_fail(function != NULL, 0);
- GSource *source = g_curses_input_source_new(win);
- guint id;
-
- if (priority != G_PRIORITY_DEFAULT)
- g_source_set_priority (source, priority);
- g_source_set_callback(source, function, data, notify);
- id = g_source_attach(source, NULL);
- g_source_unref(source);
-
- return id;
-}
-
-guint
-g_curses_input_add(WINDOW *win, GSourceFunc function, gpointer data)
-{
- return g_curses_input_add_full(G_PRIORITY_DEFAULT,
- win, function, data, NULL);
-}
diff --git a/src/g_curses_input.h b/src/g_curses_input.h
deleted file mode 100644
index b1de86e..0000000
--- a/src/g_curses_input.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef G_CURESES_INPUT_H
-#define G_CURESES_INPUT_H
-
-#include <ncurses.h>
-#include <glib.h>
-
-GSource *
-g_curses_input_source_new(WINDOW *screen);
-guint
-g_curses_input_add_full(gint priority, WINDOW *win, GSourceFunc function,
- gpointer data, GDestroyNotify notify);
-guint
-g_curses_input_add(WINDOW *win, GSourceFunc function, gpointer data);
-
-#endif /* G_CURESES_INPUT_H */
diff --git a/src/interface.c b/src/interface.c
index b0f221c..0513687 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -11,7 +11,6 @@
#include "pa-sink-ctl.h"
#include "g_unix_signal.h"
-#include "g_curses_input.h"
#define H_MSG_BOX 3
@@ -182,13 +181,13 @@ print_sink_list(void)
}
static gboolean
-interface_get_input(gpointer data)
+interface_get_input(GIOChannel *source, GIOCondition condition, gpointer data)
{
gint c;
gboolean volume_increment = TRUE;
if (!context_ready)
- return FALSE;
+ return TRUE;
c = wgetch(menu_win);
switch (c) {
@@ -321,6 +320,7 @@ interface_get_input(gpointer data)
quit();
break;
}
+
return TRUE;
}
@@ -354,6 +354,8 @@ interface_set_status(const gchar *msg)
void
interface_init(void)
{
+ GIOChannel *input_channel;
+
chooser_sink = 0; /* Selected sink-device. 0 is the first device */
chooser_input = SELECTED_SINK; /* Selected input of the current sink-device. */
/* SELECTED_SINK refers to sink-device itself */
@@ -378,8 +380,12 @@ interface_init(void)
/* register event handler for resize and input */
resize_source_id = g_unix_signal_add(SIGWINCH, interface_resize, NULL);
- input_source_id = g_curses_input_add(menu_win, interface_get_input,
- NULL);
+ input_channel = g_io_channel_unix_new(STDIN_FILENO);
+ if (!input_channel)
+ exit(EXIT_FAILURE);
+ input_source_id = g_io_add_watch(input_channel, G_IO_IN,
+ interface_get_input, NULL);
+ g_io_channel_unref(input_channel);
refresh();
}