Code

main: move keyboard_event() to keyboard.c
authorMax Kellermann <max.kellermann@gmail.com>
Sun, 19 Mar 2017 09:59:16 +0000 (10:59 +0100)
committerMax Kellermann <max.kellermann@gmail.com>
Sun, 19 Mar 2017 09:59:16 +0000 (10:59 +0100)
Makefile.am
src/keyboard.c [new file with mode: 0644]
src/keyboard.h [new file with mode: 0644]
src/main.c

index cf10d00ce431b3b9722bc8b0c90b4a77bbdd21bf..26cd3edccae522a147ff324e07e6243b4dba476a 100644 (file)
@@ -33,6 +33,7 @@ src_ncmpc_SOURCES = \
        src/filelist.c src/filelist.h \
        src/options.c src/options.h \
        src/command.c src/command.h \
+       src/keyboard.c src/keyboard.h \
        src/ncfix.h \
        src/ncu.c src/ncu.h \
        src/player_command.c src/player_command.h \
diff --git a/src/keyboard.c b/src/keyboard.c
new file mode 100644 (file)
index 0000000..226306c
--- /dev/null
@@ -0,0 +1,51 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "keyboard.h"
+#include "command.h"
+#include "ncmpc.h"
+#include "Compiler.h"
+
+#include <glib.h>
+
+#include <unistd.h>
+
+static gboolean
+keyboard_event(gcc_unused GIOChannel *source,
+              gcc_unused GIOCondition condition,
+              gcc_unused gpointer data)
+{
+       begin_input_event();
+
+       command_t cmd = get_keyboard_command();
+       if (cmd != CMD_NONE)
+               if (do_input_event(cmd) != 0)
+                       return FALSE;
+
+       end_input_event();
+       return TRUE;
+}
+
+void
+keyboard_init(void)
+{
+       GIOChannel *channel = g_io_channel_unix_new(STDIN_FILENO);
+       g_io_add_watch(channel, G_IO_IN, keyboard_event, NULL);
+       g_io_channel_unref(channel);
+}
diff --git a/src/keyboard.h b/src/keyboard.h
new file mode 100644 (file)
index 0000000..dfafa92
--- /dev/null
@@ -0,0 +1,26 @@
+/* ncmpc (Ncurses MPD Client)
+ * (c) 2004-2017 The Music Player Daemon Project
+ * Project homepage: http://musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef KEYBOARD_H
+#define KEYBOARD_H
+
+void
+keyboard_init(void);
+
+#endif
index 85548bec1ebaa6376f01f52dd228713bfc08abda..fe696c400ce61d5e91d79f5283335b2fc1f04001 100644 (file)
@@ -31,6 +31,7 @@
 #include "strfsong.h"
 #include "i18n.h"
 #include "player_command.h"
+#include "keyboard.h"
 #include "lirc.h"
 
 #ifndef NCMPC_MINI
@@ -377,22 +378,6 @@ int do_input_event(command_t cmd)
        return 0;
 }
 
-static gboolean
-keyboard_event(gcc_unused GIOChannel *source,
-              gcc_unused GIOCondition condition,
-              gcc_unused gpointer data)
-{
-       begin_input_event();
-
-       command_t cmd = get_keyboard_command();
-       if (cmd != CMD_NONE)
-               if (do_input_event(cmd) != 0)
-                       return FALSE;
-
-       end_input_event();
-       return TRUE;
-}
-
 #ifndef NCMPC_MINI
 /**
  * Check the configured key bindings for errors, and display a status
@@ -545,9 +530,7 @@ main(int argc, const char *argv[])
        main_loop = g_main_loop_new(NULL, FALSE);
 
        /* watch out for keyboard input */
-       GIOChannel *keyboard_channel = g_io_channel_unix_new(STDIN_FILENO);
-       g_io_add_watch(keyboard_channel, G_IO_IN, keyboard_event, NULL);
-       g_io_channel_unref(keyboard_channel);
+       keyboard_init();
 
        /* watch out for lirc input */
        ncmpc_lirc_init();