From 043874de9e2fc95c745563e00f9086e65dfa9fd1 Mon Sep 17 00:00:00 2001 From: Erik Reider Date: Mon, 30 Aug 2021 00:24:48 +0200 Subject: [PATCH] For loop now waits until subscription gets called --- meson.build | 3 ++- src/main.cpp | 22 +++++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/meson.build b/meson.build index dad7d06..42eaee0 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,8 @@ project( 'SwayAudioIdleInhibit', 'c', 'cpp', - default_options: ['warning_level=2'], + version: '0.1', + default_options: ['warning_level=3', 'cpp_std=c++14'], ) wayland_protos = dependency('wayland-protocols') diff --git a/src/main.cpp b/src/main.cpp index 48b2805..d9f2bd8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,7 +57,6 @@ struct Data { void handleAction() { switch (subscriptionType) { case SUBSCRIPTION_TYPE_IDLE: - if (!idle) idle = new Idle(); idle->update(activeSink || activeSource); break; case SUBSCRIPTION_TYPE_DRY_BOTH: @@ -107,9 +106,15 @@ void getRunning(EventType eventType, Data *data, pa_context *context) { context, source_output_info_callback, data); break; default: + fprintf(stderr, "Operation Default!\n"); + pa_threaded_mainloop_unlock(data->mainloop); return; } - if (!op) return; + if (!op) { + pa_threaded_mainloop_unlock(data->mainloop); + fprintf(stderr, "Operation failed!\n"); + return; + } while (pa_operation_get_state(op) == PA_OPERATION_RUNNING) { pa_threaded_mainloop_wait(data->mainloop); } @@ -124,9 +129,11 @@ void subscribe_callback(pa_context *, pa_subscription_event_type_t type, switch (type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK) { case PA_SUBSCRIPTION_EVENT_SINK: data->eventCalled = isBoth ? EVENT_TYPE_IDLE : EVENT_TYPE_DRY_SINK; + pa_threaded_mainloop_signal(data->mainloop, 0); break; case PA_SUBSCRIPTION_EVENT_SOURCE: data->eventCalled = isBoth ? EVENT_TYPE_IDLE : EVENT_TYPE_DRY_SOURCE; + pa_threaded_mainloop_signal(data->mainloop, 0); break; default: return; @@ -208,19 +215,24 @@ void connect(pa_threaded_mainloop *mainloop, pa_mainloop_api *mainloop_api, getRunning(EVENT_TYPE_DRY_SINK, data, context); getRunning(EVENT_TYPE_DRY_SOURCE, data, context); data->handleAction(); + data->eventCalled = EVENT_TYPE_NONE; break; case EVENT_TYPE_DRY_SINK: getRunning(data->eventCalled, data, context); data->handleAction(); + data->eventCalled = EVENT_TYPE_NONE; break; case EVENT_TYPE_DRY_SOURCE: getRunning(data->eventCalled, data, context); data->handleAction(); + data->eventCalled = EVENT_TYPE_NONE; + break; + case EVENT_TYPE_NONE: + pa_threaded_mainloop_lock(mainloop); + pa_threaded_mainloop_wait(mainloop); + pa_threaded_mainloop_unlock(mainloop); break; - default: - continue; } - data->eventCalled = EVENT_TYPE_NONE; } }