From f2dfa150a50212e44247abba19de523e6ba927ce Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Sun, 19 Mar 2017 10:50:09 +0100 Subject: [PATCH] main: move LIRC GIOChannel setup to lirc.c --- src/lirc.c | 53 +++++++++++++++++++++++++++++------------------------ src/lirc.h | 9 ++------- src/main.c | 7 +------ 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/src/lirc.c b/src/lirc.c index 8644740..58b2cd7 100644 --- a/src/lirc.c +++ b/src/lirc.c @@ -23,32 +23,11 @@ #include -static struct lirc_config *lc = NULL; - -int ncmpc_lirc_open() -{ - char prog[] = "ncmpc"; - int lirc_socket = 0; - - if ((lirc_socket = lirc_init(prog, 0)) == -1) - return -1; - - if (lirc_readconfig(NULL, &lc, NULL)) { - lirc_deinit(); - return -1; - } - - return lirc_socket; -} +#include -void ncmpc_lirc_close() -{ - if (lc) - lirc_freeconfig(lc); - lirc_deinit(); -} +static struct lirc_config *lc = NULL; -gboolean +static gboolean lirc_event(gcc_unused GIOChannel *source, gcc_unused GIOCondition condition, gcc_unused gpointer data) { @@ -68,3 +47,29 @@ lirc_event(gcc_unused GIOChannel *source, end_input_event(); return TRUE; } + +void +ncmpc_lirc_open() +{ + char prog[] = "ncmpc"; + int lirc_socket = 0; + + if ((lirc_socket = lirc_init(prog, 0)) == -1) + return; + + if (lirc_readconfig(NULL, &lc, NULL)) { + lirc_deinit(); + return; + } + + GIOChannel *channel = g_io_channel_unix_new(lirc_socket); + g_io_add_watch(channel, G_IO_IN, lirc_event, NULL); + g_io_channel_unref(channel); +} + +void ncmpc_lirc_close() +{ + if (lc) + lirc_freeconfig(lc); + lirc_deinit(); +} diff --git a/src/lirc.h b/src/lirc.h index 0c7955c..1d7650b 100644 --- a/src/lirc.h +++ b/src/lirc.h @@ -20,13 +20,8 @@ #ifndef LIRC_H #define LIRC_H -#include "command.h" -#include - -int ncmpc_lirc_open(void); +void +ncmpc_lirc_open(void); void ncmpc_lirc_close(void); -gboolean -lirc_event(GIOChannel *source, GIOCondition condition, gpointer data); - #endif diff --git a/src/main.c b/src/main.c index c20dd6d..fd6cd7b 100644 --- a/src/main.c +++ b/src/main.c @@ -555,12 +555,7 @@ main(int argc, const char *argv[]) #ifdef ENABLE_LIRC /* watch out for lirc input */ - int lirc_socket = ncmpc_lirc_open(); - if (lirc_socket >= 0) { - GIOChannel *lirc_channel = g_io_channel_unix_new(lirc_socket); - g_io_add_watch(lirc_channel, G_IO_IN, lirc_event, NULL); - g_io_channel_unref(lirc_channel); - } + ncmpc_lirc_open(); #endif #ifndef WIN32 -- 2.30.2