1 #include <lirc/lirc_client.h>
2 #include "lirc.h"
3 #include "ncmpc.h"
5 static struct lirc_config *lc = NULL;
7 int ncmpc_lirc_open()
8 {
9 char prog[] = "ncmpc";
10 int lirc_socket = 0;
12 if ((lirc_socket = lirc_init(prog, 0)) == -1)
13 return -1;
15 if (lirc_readconfig(NULL, &lc, NULL)) {
16 lirc_deinit();
17 return -1;
18 }
20 return lirc_socket;
21 }
23 void ncmpc_lirc_close()
24 {
25 if (lc)
26 lirc_freeconfig(lc);
27 lirc_deinit();
28 }
30 gboolean
31 lirc_event(mpd_unused GIOChannel *source,
32 mpd_unused GIOCondition condition, mpd_unused gpointer data)
33 {
34 char *code, *txt;
35 command_t cmd;
37 begin_input_event();
39 if (lirc_nextcode(&code) == 0) {
40 while (lirc_code2char(lc, code, &txt) == 0 && txt != NULL) {
41 cmd = get_key_command_from_name(txt);
42 if (do_input_event(cmd) != 0)
43 return FALSE;
44 }
45 }
47 end_input_event();
48 return TRUE;
49 }