From c8f802659a6954ee0f28297076125442595e7e6b Mon Sep 17 00:00:00 2001 From: Benjamin Franzke Date: Wed, 19 Oct 2011 22:48:50 +0200 Subject: g_curses_input: Fix coding style --- src/g_curses_input.c | 17 ++++++++++++----- src/g_curses_input.h | 11 +++++++---- 2 files changed, 19 insertions(+), 9 deletions(-) (limited to 'src') 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); } diff --git a/src/g_curses_input.h b/src/g_curses_input.h index 23eb550..b1de86e 100644 --- a/src/g_curses_input.h +++ b/src/g_curses_input.h @@ -4,9 +4,12 @@ #include #include -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); +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 */ -- cgit