From 8a0d2c2dbe0910ac4d414d2a7a60cf6b97a21211 Mon Sep 17 00:00:00 2001 From: Gregor Kleen <20089782+gkleen@users.noreply.github.com> Date: Sat, 17 Aug 2024 21:11:07 +0200 Subject: [PATCH 1/3] privacy: introduce `ignore` option --- include/modules/privacy/privacy.hpp | 1 + src/modules/privacy/privacy.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/include/modules/privacy/privacy.hpp b/include/modules/privacy/privacy.hpp index d7656d312..0c4a3b0fb 100644 --- a/include/modules/privacy/privacy.hpp +++ b/include/modules/privacy/privacy.hpp @@ -31,6 +31,7 @@ class Privacy : public AModule { uint iconSpacing = 4; uint iconSize = 20; uint transition_duration = 250; + std::set> ignore; std::shared_ptr backend = nullptr; }; diff --git a/src/modules/privacy/privacy.cpp b/src/modules/privacy/privacy.cpp index 97996c336..1121bee2c 100644 --- a/src/modules/privacy/privacy.cpp +++ b/src/modules/privacy/privacy.cpp @@ -73,6 +73,18 @@ Privacy::Privacy(const std::string& id, const Json::Value& config, const std::st } } + for (const auto& ignore_item : config_["ignore"]) { + if (!ignore_item.isObject() || !ignore_item["type"].isString() || !ignore_item["name"].isString()) continue; + const std::string type = ignore_item["type"].asString(); + const std::string name = ignore_item["name"].asString(); + + auto iter = typeMap.find(type); + if (iter != typeMap.end()) { + auto& [_, nodeType] = iter->second; + ignore.emplace(nodeType, std::move(name)); + } + } + backend = util::PipewireBackend::PipewireBackend::getInstance(); backend->privacy_nodes_changed_signal_event.connect( sigc::mem_fun(*this, &Privacy::onPrivacyNodesChanged)); @@ -87,6 +99,10 @@ void Privacy::onPrivacyNodesChanged() { nodes_screenshare.clear(); for (auto& node : backend->privacy_nodes) { + auto iter = ignore.find(std::pair(node.second->type, node.second->node_name)); + if (iter != ignore.end()) + continue; + switch (node.second->state) { case PW_NODE_STATE_RUNNING: switch (node.second->type) { From e883333d19da8f577b0ad37d1c3a28784ff2539f Mon Sep 17 00:00:00 2001 From: Gregor Kleen <20089782+gkleen@users.noreply.github.com> Date: Tue, 20 Aug 2024 22:09:22 +0200 Subject: [PATCH 2/3] privacy: default to ignoring all stream.monitor pw nodes --- include/modules/privacy/privacy.hpp | 1 + include/util/pipewire/privacy_node_info.hpp | 1 + src/modules/privacy/privacy.cpp | 7 +++++++ src/util/pipewire/privacy_node_info.cpp | 2 ++ 4 files changed, 11 insertions(+) diff --git a/include/modules/privacy/privacy.hpp b/include/modules/privacy/privacy.hpp index 0c4a3b0fb..9c77f94a5 100644 --- a/include/modules/privacy/privacy.hpp +++ b/include/modules/privacy/privacy.hpp @@ -32,6 +32,7 @@ class Privacy : public AModule { uint iconSize = 20; uint transition_duration = 250; std::set> ignore; + bool ignore_monitor = true; std::shared_ptr backend = nullptr; }; diff --git a/include/util/pipewire/privacy_node_info.hpp b/include/util/pipewire/privacy_node_info.hpp index 7b8df0181..54da7d169 100644 --- a/include/util/pipewire/privacy_node_info.hpp +++ b/include/util/pipewire/privacy_node_info.hpp @@ -25,6 +25,7 @@ class PrivacyNodeInfo { std::string media_name; std::string node_name; std::string application_name; + bool is_monitor = false; std::string pipewire_access_portal_app_id; std::string application_icon_name; diff --git a/src/modules/privacy/privacy.cpp b/src/modules/privacy/privacy.cpp index 1121bee2c..d36c2d8c7 100644 --- a/src/modules/privacy/privacy.cpp +++ b/src/modules/privacy/privacy.cpp @@ -85,6 +85,10 @@ Privacy::Privacy(const std::string& id, const Json::Value& config, const std::st } } + if (config_["ignore-monitor"].isBool()) { + ignore_monitor = config_["ignore-monitor"].asBool(); + } + backend = util::PipewireBackend::PipewireBackend::getInstance(); backend->privacy_nodes_changed_signal_event.connect( sigc::mem_fun(*this, &Privacy::onPrivacyNodesChanged)); @@ -99,6 +103,9 @@ void Privacy::onPrivacyNodesChanged() { nodes_screenshare.clear(); for (auto& node : backend->privacy_nodes) { + if (ignore_monitor && node.second->is_monitor) + continue; + auto iter = ignore.find(std::pair(node.second->type, node.second->node_name)); if (iter != ignore.end()) continue; diff --git a/src/util/pipewire/privacy_node_info.cpp b/src/util/pipewire/privacy_node_info.cpp index 739dc528f..ec110b866 100644 --- a/src/util/pipewire/privacy_node_info.cpp +++ b/src/util/pipewire/privacy_node_info.cpp @@ -49,6 +49,8 @@ void PrivacyNodeInfo::handleNodeEventInfo(const struct pw_node_info *info) { pipewire_access_portal_app_id = item->value; } else if (strcmp(item->key, PW_KEY_APP_ICON_NAME) == 0) { application_icon_name = item->value; + } else if (strcmp(item->key, "stream.monitor") == 0) { + is_monitor = strcmp(item->value, "true") == 0; } } } From 7cedd9cd55e1b14f69e2889ccb66dd87b0ce57d1 Mon Sep 17 00:00:00 2001 From: Gregor Kleen <20089782+gkleen@users.noreply.github.com> Date: Fri, 13 Sep 2024 14:18:04 +0200 Subject: [PATCH 3/3] privacy: document ignore options --- man/waybar-privacy.5.scd | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/man/waybar-privacy.5.scd b/man/waybar-privacy.5.scd index d13d8ed39..c7e724956 100644 --- a/man/waybar-privacy.5.scd +++ b/man/waybar-privacy.5.scd @@ -32,6 +32,17 @@ the screen or playing audio. Which privacy modules to monitor. See *MODULES CONFIGURATION* for++ more information. +*ignore-monitor* ++ + typeof: bool ++ + default: true ++ + Ignore streams with *stream.monitor* property. + +*ignore* ++ + typeof: array of objects ++ + default: [] ++ + Additional streams to be ignored. See *IGNORE CONFIGURATION* for++ + more information. + # MODULES CONFIGURATION *type*: ++ @@ -49,6 +60,14 @@ the screen or playing audio. default: 24 ++ The size of each icon in the tooltip. +# IGNORE CONFIGURATION + +*type*: ++ + typeof: string + +*name*: ++ + typeof: string + # EXAMPLES ```