Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

privacy: ignore some streams #3526

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/modules/privacy/privacy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class Privacy : public AModule {
uint iconSpacing = 4;
uint iconSize = 20;
uint transition_duration = 250;
std::set<std::pair<PrivacyNodeType, std::string>> ignore;
bool ignore_monitor = true;

std::shared_ptr<util::PipewireBackend::PipewireBackend> backend = nullptr;
};
Expand Down
1 change: 1 addition & 0 deletions include/util/pipewire/privacy_node_info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
19 changes: 19 additions & 0 deletions man/waybar-privacy.5.scd
Original file line number Diff line number Diff line change
Expand Up @@ -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*: ++
Expand All @@ -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

```
Expand Down
23 changes: 23 additions & 0 deletions src/modules/privacy/privacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,22 @@ 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));
}
}

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));
Expand All @@ -87,6 +103,13 @@ 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;

switch (node.second->state) {
case PW_NODE_STATE_RUNNING:
switch (node.second->type) {
Expand Down
2 changes: 2 additions & 0 deletions src/util/pipewire/privacy_node_info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Loading