summaryrefslogtreecommitdiff
path: root/src/g_curses_input.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/g_curses_input.c')
-rw-r--r--src/g_curses_input.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/g_curses_input.c b/src/g_curses_input.c
index 9ab0f71..ece0213 100644
--- a/src/g_curses_input.c
+++ b/src/g_curses_input.c
@@ -12,9 +12,8 @@ static gboolean
check(GSource *source)
{
GCursesInput *curses_input = (GCursesInput*) source;
- static int i = 0;
- i++;
gint ch = wgetch(curses_input->win);
+
if (ch != ERR)
ungetch(ch);
return ch != ERR;
@@ -31,6 +30,7 @@ static gboolean
dispatch(GSource *source, GSourceFunc callback, gpointer user_data)
{
GCursesInput *curses_input = (GCursesInput*) source;
+
return callback((gpointer)curses_input->win) ? TRUE : FALSE;
}
@@ -47,26 +47,33 @@ 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_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);
- guint id = g_source_attach(source, NULL);
+ 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);
+ return g_curses_input_add_full(G_PRIORITY_DEFAULT,
+ win, function, data, NULL);
}