privacy: consider only configured modules
along with the local clang-tidy warning fixes
This commit is contained in:
parent
f4da203915
commit
0773786766
|
@ -53,23 +53,22 @@ Privacy::Privacy(const std::string& id, const Json::Value& config, const std::st
|
||||||
modules.append(obj);
|
modules.append(obj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (const auto& module_config : modules) {
|
|
||||||
if (!module_config.isObject() || !module_config["type"].isString()) continue;
|
std::map<std::string, std::tuple<decltype(&nodes_audio_in), PrivacyNodeType> > typeMap = {
|
||||||
const std::string type = module_config["type"].asString();
|
{"screenshare", {&nodes_screenshare, PRIVACY_NODE_TYPE_VIDEO_INPUT}},
|
||||||
if (type == "screenshare") {
|
{"audio-in", {&nodes_audio_in, PRIVACY_NODE_TYPE_AUDIO_INPUT}},
|
||||||
auto* item =
|
{"audio-out", {&nodes_audio_out, PRIVACY_NODE_TYPE_AUDIO_OUTPUT}},
|
||||||
Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_VIDEO_INPUT,
|
};
|
||||||
&nodes_screenshare, pos, iconSize, transition_duration);
|
|
||||||
box_.add(*item);
|
for (const auto& module : modules) {
|
||||||
} else if (type == "audio-in") {
|
if (!module.isObject() || !module["type"].isString()) continue;
|
||||||
auto* item =
|
const std::string type = module["type"].asString();
|
||||||
Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_AUDIO_INPUT,
|
|
||||||
&nodes_audio_in, pos, iconSize, transition_duration);
|
auto iter = typeMap.find(type);
|
||||||
box_.add(*item);
|
if (iter != typeMap.end()) {
|
||||||
} else if (type == "audio-out") {
|
auto& [nodePtr, nodeType] = iter->second;
|
||||||
auto* item =
|
auto* item = Gtk::make_managed<PrivacyItem>(module, nodeType, nodePtr, pos, iconSize,
|
||||||
Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_AUDIO_OUTPUT,
|
transition_duration);
|
||||||
&nodes_audio_out, pos, iconSize, transition_duration);
|
|
||||||
box_.add(*item);
|
box_.add(*item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,26 +113,35 @@ void Privacy::onPrivacyNodesChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
auto Privacy::update() -> void {
|
auto Privacy::update() -> void {
|
||||||
mutex_.lock();
|
// set in modules or not
|
||||||
bool screenshare = false;
|
bool setScreenshare = false;
|
||||||
bool audio_in = false;
|
bool setAudioIn = false;
|
||||||
bool audio_out = false;
|
bool setAudioOut = false;
|
||||||
|
|
||||||
|
// used or not
|
||||||
|
bool useScreenshare = false;
|
||||||
|
bool useAudioIn = false;
|
||||||
|
bool useAudioOut = false;
|
||||||
|
|
||||||
|
mutex_.lock();
|
||||||
for (Gtk::Widget* widget : box_.get_children()) {
|
for (Gtk::Widget* widget : box_.get_children()) {
|
||||||
auto* module = dynamic_cast<PrivacyItem*>(widget);
|
auto* module = dynamic_cast<PrivacyItem*>(widget);
|
||||||
if (module == nullptr) continue;
|
if (module == nullptr) continue;
|
||||||
switch (module->privacy_type) {
|
switch (module->privacy_type) {
|
||||||
case util::PipewireBackend::PRIVACY_NODE_TYPE_VIDEO_INPUT:
|
case util::PipewireBackend::PRIVACY_NODE_TYPE_VIDEO_INPUT:
|
||||||
screenshare = !nodes_screenshare.empty();
|
setScreenshare = true;
|
||||||
module->set_in_use(screenshare);
|
useScreenshare = !nodes_screenshare.empty();
|
||||||
|
module->set_in_use(useScreenshare);
|
||||||
break;
|
break;
|
||||||
case util::PipewireBackend::PRIVACY_NODE_TYPE_AUDIO_INPUT:
|
case util::PipewireBackend::PRIVACY_NODE_TYPE_AUDIO_INPUT:
|
||||||
audio_in = !nodes_audio_in.empty();
|
setAudioIn = true;
|
||||||
module->set_in_use(audio_in);
|
useAudioIn = !nodes_audio_in.empty();
|
||||||
|
module->set_in_use(useAudioIn);
|
||||||
break;
|
break;
|
||||||
case util::PipewireBackend::PRIVACY_NODE_TYPE_AUDIO_OUTPUT:
|
case util::PipewireBackend::PRIVACY_NODE_TYPE_AUDIO_OUTPUT:
|
||||||
audio_out = !nodes_audio_out.empty();
|
setAudioOut = true;
|
||||||
module->set_in_use(audio_out);
|
useAudioOut = !nodes_audio_out.empty();
|
||||||
|
module->set_in_use(useAudioOut);
|
||||||
break;
|
break;
|
||||||
case util::PipewireBackend::PRIVACY_NODE_TYPE_NONE:
|
case util::PipewireBackend::PRIVACY_NODE_TYPE_NONE:
|
||||||
break;
|
break;
|
||||||
|
@ -142,25 +150,28 @@ auto Privacy::update() -> void {
|
||||||
mutex_.unlock();
|
mutex_.unlock();
|
||||||
|
|
||||||
// Hide the whole widget if none are in use
|
// Hide the whole widget if none are in use
|
||||||
bool is_visible = screenshare || audio_in || audio_out;
|
bool isVisible = (setScreenshare && useScreenshare) || (setAudioIn && useAudioIn) ||
|
||||||
if (is_visible != event_box_.get_visible()) {
|
(setAudioOut && useAudioOut);
|
||||||
|
|
||||||
|
if (isVisible != event_box_.get_visible()) {
|
||||||
// Disconnect any previous connection so that it doesn't get activated in
|
// Disconnect any previous connection so that it doesn't get activated in
|
||||||
// the future, hiding the module when it should be visible
|
// the future, hiding the module when it should be visible
|
||||||
visibility_conn.disconnect();
|
visibility_conn.disconnect();
|
||||||
if (is_visible) {
|
if (isVisible) {
|
||||||
event_box_.set_visible(true);
|
event_box_.set_visible(true);
|
||||||
} else {
|
} else {
|
||||||
// Hides the widget when all of the privacy_item revealers animations
|
// Hides the widget when all of the privacy_item revealers animations
|
||||||
// have finished animating
|
// have finished animating
|
||||||
visibility_conn = Glib::signal_timeout().connect(
|
visibility_conn = Glib::signal_timeout().connect(
|
||||||
sigc::track_obj(
|
sigc::track_obj(
|
||||||
[this] {
|
[this, setScreenshare, setAudioOut, setAudioIn]() {
|
||||||
mutex_.lock();
|
mutex_.lock();
|
||||||
bool screenshare = !nodes_screenshare.empty();
|
bool visible = false;
|
||||||
bool audio_in = !nodes_audio_in.empty();
|
visible |= setScreenshare && !nodes_screenshare.empty();
|
||||||
bool audio_out = !nodes_audio_out.empty();
|
visible |= setAudioIn && !nodes_audio_in.empty();
|
||||||
|
visible |= setAudioOut && !nodes_audio_out.empty();
|
||||||
mutex_.unlock();
|
mutex_.unlock();
|
||||||
event_box_.set_visible(screenshare || audio_in || audio_out);
|
event_box_.set_visible(visible);
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
*this),
|
*this),
|
||||||
|
|
Loading…
Reference in New Issue