diff options
-rw-r--r-- | configure.ac | 4 | ||||
-rw-r--r-- | src/Makefile.am | 6 | ||||
-rw-r--r-- | src/pa-sink-ctl.c | 38 |
3 files changed, 31 insertions, 17 deletions
diff --git a/configure.ac b/configure.ac index 34d004b..8d61691 100644 --- a/configure.ac +++ b/configure.ac @@ -14,13 +14,15 @@ AC_PROG_MAKE_SET # Checks for libraries. AC_CHECK_LIB([ncurses], [newwin], [CURSES_LIBS=-lncurses], [echo "Error: you need ncurses!"; exit 1]) PKG_CHECK_MODULES(PULSE, [libpulse], [], [echo "Error: you need libpulse!"; exit 1]) +PKG_CHECK_MODULES(PULSE_MAINLOOP, [libpulse-mainloop-glib], [], [echo "Error: you need libpulse-mainloop-glib"; exit 1]) +PKG_CHECK_MODULES(GLIB, [glib-2.0], [], [echo "Error: you need glib!"; exit1]) AC_SUBST(CURSES_LIBS) AC_SUBST(PULSE_CFLAGS) AC_SUBST(PULSE_LIBS) # Checks for header files. -AC_CHECK_HEADERS([stdio.h stdlib.h string.h ncurses.h pulse/pulseaudio.h]) +AC_CHECK_HEADERS([stdio.h stdlib.h string.h ncurses.h glib.h pulse/pulseaudio.h pulse/glib-mainloop.h]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_UINT32_T diff --git a/src/Makefile.am b/src/Makefile.am index 8b4e688..1d800a5 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,7 @@ bin_PROGRAMS = pa_sink_ctl -pa_sink_ctl_SOURCES =interface.c pa-sink-ctl.c sink.c sink_input.c +pa_sink_ctl_SOURCES = interface.c pa-sink-ctl.c sink.c sink_input.c -AM_CFLAGS =-std=c99 -pedantic -Wall -Werror @PULSE_CFLAGS@ -pa_sink_ctl_LDADD =@PULSE_LIBS@ @CURSES_LIBS@ +AM_CFLAGS = -std=c99 -pedantic -Wall -Werror @PULSE_CFLAGS@ @PULSE_MAINLOOP_CFLAGS@ @GLIB_CFLAGS@ +pa_sink_ctl_LDADD = @PULSE_LIBS@ @PULSE_MAINLOOP_LIBS@ @GLIB_LIBS@ @CURSES_LIBS@ noinst_HEADERS = interface.h pa-sink-ctl.h sink.h sink_input.h diff --git a/src/pa-sink-ctl.c b/src/pa-sink-ctl.c index 0d3a5bc..44a6fcc 100644 --- a/src/pa-sink-ctl.c +++ b/src/pa-sink-ctl.c @@ -1,9 +1,14 @@ #define _XOPEN_SOURCE 500 -#include <string.h> #include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <glib.h> + #include <pulse/pulseaudio.h> +#include <pulse/glib-mainloop.h> + #include <ncurses.h> -#include <stdlib.h> #include "sink_input.h" #include "sink.h" @@ -20,7 +25,7 @@ uint32_t sink_counter; uint32_t sink_max; pa_mainloop_api *mainloop_api = NULL; -pa_context *context = NULL; +pa_context *context = NULL; // ncurses WINDOW *menu_win; @@ -30,20 +35,25 @@ int starty; int main(int argc, char** argv) { + GMainContext *g_context = NULL; + GMainLoop *g_loop = NULL; + pa_glib_mainloop *m = NULL; + sink_counter = 0; sink_max = 1; sink_list = sink_list_init(sink_max); interface_init(); - pa_mainloop *m = NULL; - int ret = 1; - if (!(m = pa_mainloop_new())) { - printf("error: pa_mainloop_new() failed.\n"); + g_context = g_main_context_new(); + g_loop = g_main_loop_new(g_context, false); + + if (!(m = pa_glib_mainloop_new(g_context))) { + printf("error: pa_glib_mainloop_new() failed.\n"); return -1; } - mainloop_api = pa_mainloop_get_api(m); + mainloop_api = pa_glib_mainloop_get_api(m); if (!(context = pa_context_new(mainloop_api, "pa-sink-ctl"))) { printf("error: pa_context_new() failed.\n"); @@ -56,12 +66,14 @@ int main(int argc, char** argv) printf("error: pa_context_connect() failed.\n"); } - if (pa_mainloop_run(m, &ret) < 0) { - printf("error: pa_mainloop_run() failed.\n"); - return -1; - } + g_main_loop_run(g_loop); + + pa_glib_mainloop_free(m); + + g_main_loop_unref(g_loop); + g_main_context_unref(g_context); - return ret; + return 0; } /* * is called after connection |