From 899843978ebd7161a9659a24eff1d694f3a8e74e Mon Sep 17 00:00:00 2001 From: Erik Reider Date: Tue, 11 Jan 2022 15:21:59 +0100 Subject: [PATCH] Added dry-print-both with waybar friendly output --- include/data.hpp | 2 ++ src/data.cpp | 17 +++++++++++++++++ src/main.cpp | 45 +++++++++++++++++++++++---------------------- src/pulse.cpp | 5 ++++- 4 files changed, 46 insertions(+), 23 deletions(-) diff --git a/include/data.hpp b/include/data.hpp index 6a2bc51..30534ea 100644 --- a/include/data.hpp +++ b/include/data.hpp @@ -12,6 +12,7 @@ using namespace std; enum SubscriptionType { SUBSCRIPTION_TYPE_IDLE, SUBSCRIPTION_TYPE_DRY_BOTH, + SUBSCRIPTION_TYPE_DRY_BOTH_WAYBAR, SUBSCRIPTION_TYPE_DRY_SINK, SUBSCRIPTION_TYPE_DRY_SOURCE, }; @@ -49,4 +50,5 @@ struct Data { private: void print(bool isRunning); + void printWayBar(bool activeSink, bool activeSource); }; diff --git a/src/data.cpp b/src/data.cpp index fb67004..8dbeda2 100644 --- a/src/data.cpp +++ b/src/data.cpp @@ -26,6 +26,9 @@ void Data::handleAction() { case SUBSCRIPTION_TYPE_DRY_BOTH: this->print(activeSink || activeSource); break; + case SUBSCRIPTION_TYPE_DRY_BOTH_WAYBAR: + this->printWayBar(activeSink, activeSource); + break; case SUBSCRIPTION_TYPE_DRY_SINK: this->print(activeSink); break; @@ -38,3 +41,17 @@ void Data::handleAction() { void Data::print(bool isRunning) { cout << (isRunning ? "RUNNING" : "NOT RUNNING") << endl; } + +void Data::printWayBar(bool activeSink, bool activeSource) { + string result[2] = {activeSink ? "output" : "", activeSource ? "input" : ""}; + string text = ""; + for (const auto &str : result) { + if (!text.empty() && !str.empty()) text += "-"; + text += str; + } + if (text.empty()) text = "none"; + printf( + "{\"text\": \"\", \"alt\": \"%s\", \"tooltip\": \"\", \"class\": " + "\"%s\"}\n", + text.c_str(), text.c_str()); +} diff --git a/src/main.cpp b/src/main.cpp index ea351ea..391865e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,33 +1,29 @@ #include +#include "data.hpp" #include "pulse.hpp" void showHelp(char **argv) { - cout << "Usage:" << endl; - cout << "\t" << argv[0] << "