aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.c
diff options
context:
space:
mode:
authorThomas Jansen <mithi@mithi.net>2008-11-07 08:16:41 +0100
committerMax Kellermann <max@duempel.org>2008-11-07 08:16:41 +0100
commitd88a1718bbca660e13ad60f8f1aec6084fcf7788 (patch)
tree808e721f1fffeafa4a9fa6e169e5467ae3dd28f3 /src/main.c
parent8221502e87f6c1a652b7c3148467248f538970bd (diff)
downloadmpd-d88a1718bbca660e13ad60f8f1aec6084fcf7788.tar.gz
mpd-d88a1718bbca660e13ad60f8f1aec6084fcf7788.tar.xz
mpd-d88a1718bbca660e13ad60f8f1aec6084fcf7788.zip
native LIRC support for ncmpc
The attachment includes the patch and a sample .lircrc config for testing purposes (i. e. only a few commands are mapped to IR events). The config is rather simple to write: For each button add a block like this to ~/.lircrc: begin button = <button name from /etc/lircd.conf> prog = ncmpc config = <command name from src/command.c> end The patch is not finished, there are several problems that still need to be solved: 1. the configure.ac modifications are just for testing purposes and should be made optional with a parameter like --enable-lirc for ./configure. Unfortunately I'm not an expert on autoconfig tools. 2. LIRC example code [1] suggests looping over lirc_code2char, probably to have multiple actions that can be triggered from one button. Perhaps lirc_event(...) should be moved to lirc.c and be heavily modified, no longer being a mere copy of keyboard_event(...).
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
index 5f55c490d..49c813a7a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -34,6 +34,10 @@
#include "lyrics.h"
#endif
+#ifdef ENABLE_LIRC
+#include "lirc.h"
+#endif
+
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
@@ -292,6 +296,40 @@ keyboard_event(mpd_unused GIOChannel *source,
return TRUE;
}
+#ifdef ENABLE_LIRC
+static gboolean
+lirc_event(mpd_unused GIOChannel *source,
+ mpd_unused GIOCondition condition, mpd_unused gpointer data)
+{
+ command_t cmd;
+
+ /* remove the idle timeout; add it later with fresh interval */
+ g_source_remove(idle_source_id);
+
+ if ((cmd = ncmpc_lirc_get_command()) != CMD_NONE) {
+ if (cmd == CMD_QUIT) {
+ g_main_loop_quit(main_loop);
+ return FALSE;
+ }
+
+ screen_cmd(mpd, cmd);
+
+ if (cmd == CMD_VOLUME_UP || cmd == CMD_VOLUME_DOWN) {
+ /* make sure we dont update the volume yet */
+ g_source_remove(update_source_id);
+ update_source_id = g_timeout_add(update_interval,
+ timer_mpd_update,
+ GINT_TO_POINTER(TRUE));
+ }
+ }
+
+ screen_update(mpd);
+
+ idle_source_id = g_timeout_add(idle_interval, timer_idle, NULL);
+ return TRUE;
+}
+#endif
+
/**
* Check the configured key bindings for errors, and display a status
* message every 10 seconds.
@@ -321,6 +359,10 @@ main(int argc, const char *argv[])
const char *charset = NULL;
#endif
GIOChannel *keyboard_channel;
+#ifdef ENABLE_LIRC
+ int lirc_socket;
+ GIOChannel *lirc_channel = NULL;
+#endif
#ifdef HAVE_LOCALE_H
/* time and date formatting */
@@ -426,6 +468,15 @@ main(int argc, const char *argv[])
keyboard_channel = g_io_channel_unix_new(STDIN_FILENO);
g_io_add_watch(keyboard_channel, G_IO_IN, keyboard_event, NULL);
+#ifdef ENABLE_LIRC
+ /* watch out for lirc input */
+ lirc_socket = ncmpc_lirc_open();
+ if (lirc_socket >= 0) {
+ lirc_channel = g_io_channel_unix_new(lirc_socket);
+ g_io_add_watch(lirc_channel, G_IO_IN, lirc_event, NULL);
+ }
+#endif
+
/* attempt to connect */
reconnect_source_id = g_timeout_add(1, timer_reconnect, NULL);
@@ -444,6 +495,12 @@ main(int argc, const char *argv[])
g_main_loop_unref(main_loop);
g_io_channel_unref(keyboard_channel);
+#ifdef ENABLE_LIRC
+ if (lirc_socket >= 0)
+ g_io_channel_unref(lirc_channel);
+ ncmpc_lirc_close();
+#endif
+
exit_and_cleanup();
ncu_deinit();