From c325dd6798ea86bdc4016b3e9357cb0be991f130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malte=20J=C3=BCrgens?= Date: Thu, 4 Aug 2022 15:27:39 +0200 Subject: [PATCH] allow sharing all desktop audio --- src/streamdialog.cpp | 4 +++- src/virtmic.cpp | 20 +++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/streamdialog.cpp b/src/streamdialog.cpp index c8c6bca..89316e9 100644 --- a/src/streamdialog.cpp +++ b/src/streamdialog.cpp @@ -71,8 +71,10 @@ void StreamDialog::startStream() { void StreamDialog::updateTargets() { m_targetComboBox->clear(); - m_targetComboBox->addItem("None"); + m_targetComboBox->addItem("[None]"); + m_targetComboBox->addItem("[All Desktop Audio]"); for (auto target : Virtmic::getTargets()) { m_targetComboBox->addItem(target); } + m_targetComboBox->setCurrentText("[All Desktop Audio]"); } diff --git a/src/virtmic.cpp b/src/virtmic.cpp index 8acb165..ba6d1fc 100644 --- a/src/virtmic.cpp +++ b/src/virtmic.cpp @@ -6,6 +6,8 @@ namespace Virtmic { +const QStringList EXCLUDE_TARGETS{"Chromium input", "discord-screenaudio"}; + QVector getTargets() { auto main_loop = pipewire::main_loop(); auto context = pipewire::context(main_loop); @@ -20,11 +22,11 @@ QVector getTargets() { if (global.type == pipewire::node::type) { auto node = reg.bind(global.id); auto info = node.info(); + auto name = QString::fromStdString(info.props["application.name"]); - if (info.props.count("application.name")) { - auto name = QString::fromStdString(info.props["application.name"]); - if (!targets.contains(name)) - targets.append(name); + if (name != "" && !EXCLUDE_TARGETS.contains(name) && + !targets.contains(name)) { + targets.append(name); } } }); @@ -65,15 +67,19 @@ void start(QString _target) { continue; auto &parent = nodes.at(parent_id); + auto name = parent.props["application.name"]; - if (parent.props["application.name"].find(target) != std::string::npos) { + if (name == target || + (target == "[All Desktop Audio]" && + !EXCLUDE_TARGETS.contains(QString::fromStdString(name)))) { auto fl = port.info().props["audio.channel"] == "FL"; links.emplace( port_id, core.create( {fl ? virt_fl->info().id : virt_fr->info().id, port_id})); qDebug(virtmicLog) << QString("Link: %1:%2 -> %3") - .arg(QString::fromStdString(target)) + .arg(QString::fromStdString( + parent.props["application.name"])) .arg(port_id) .arg(fl ? virt_fl->info().id : virt_fr->info().id) @@ -94,7 +100,7 @@ void start(QString _target) { pipewire::node::type, pipewire::node::version, pipewire::update_strategy::none); - if (target == "None") { + if (target == "[None]") { while (true) { main_loop.run(); }