clang-tidy improvements in privacy module

master
zjeffer 2024-05-11 15:58:12 +02:00
parent 1828a94b6c
commit e27488b48c
4 changed files with 12 additions and 21 deletions

View File

@ -1,10 +1,7 @@
#pragma once #pragma once
#include <iostream>
#include <map>
#include <string> #include <string>
#include "ALabel.hpp"
#include "gtkmm/box.h" #include "gtkmm/box.h"
#include "modules/privacy/privacy_item.hpp" #include "modules/privacy/privacy_item.hpp"
#include "util/pipewire/pipewire_backend.hpp" #include "util/pipewire/pipewire_backend.hpp"

View File

@ -2,9 +2,6 @@
#include <json/value.h> #include <json/value.h>
#include <iostream>
#include <map>
#include <mutex>
#include <string> #include <string>
#include "gtkmm/box.h" #include "gtkmm/box.h"

View File

@ -6,7 +6,6 @@
#include <string> #include <string>
#include "AModule.hpp" #include "AModule.hpp"
#include "gtkmm/image.h"
#include "modules/privacy/privacy_item.hpp" #include "modules/privacy/privacy_item.hpp"
namespace waybar::modules::privacy { namespace waybar::modules::privacy {
@ -46,30 +45,29 @@ Privacy::Privacy(const std::string& id, const Json::Value& config, const std::st
// Initialize each privacy module // Initialize each privacy module
Json::Value modules = config_["modules"]; Json::Value modules = config_["modules"];
// Add Screenshare and Mic usage as default modules if none are specified // Add Screenshare and Mic usage as default modules if none are specified
if (!modules.isArray() || modules.size() == 0) { if (!modules.isArray() || modules.empty()) {
modules = Json::Value(Json::arrayValue); modules = Json::Value(Json::arrayValue);
for (auto& type : {"screenshare", "audio-in"}) { for (const auto& type : {"screenshare", "audio-in"}) {
Json::Value obj = Json::Value(Json::objectValue); Json::Value obj = Json::Value(Json::objectValue);
obj["type"] = type; obj["type"] = type;
modules.append(obj); modules.append(obj);
} }
} }
for (uint i = 0; i < modules.size(); i++) { for (const auto& module_config : modules) {
const Json::Value& module_config = modules[i];
if (!module_config.isObject() || !module_config["type"].isString()) continue; if (!module_config.isObject() || !module_config["type"].isString()) continue;
const std::string type = module_config["type"].asString(); const std::string type = module_config["type"].asString();
if (type == "screenshare") { if (type == "screenshare") {
auto item = auto* item =
Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_VIDEO_INPUT, Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_VIDEO_INPUT,
&nodes_screenshare, pos, iconSize, transition_duration); &nodes_screenshare, pos, iconSize, transition_duration);
box_.add(*item); box_.add(*item);
} else if (type == "audio-in") { } else if (type == "audio-in") {
auto item = auto* item =
Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_AUDIO_INPUT, Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_AUDIO_INPUT,
&nodes_audio_in, pos, iconSize, transition_duration); &nodes_audio_in, pos, iconSize, transition_duration);
box_.add(*item); box_.add(*item);
} else if (type == "audio-out") { } else if (type == "audio-out") {
auto item = auto* item =
Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_AUDIO_OUTPUT, Gtk::make_managed<PrivacyItem>(module_config, PRIVACY_NODE_TYPE_AUDIO_OUTPUT,
&nodes_audio_out, pos, iconSize, transition_duration); &nodes_audio_out, pos, iconSize, transition_duration);
box_.add(*item); box_.add(*item);
@ -117,11 +115,13 @@ void Privacy::onPrivacyNodesChanged() {
auto Privacy::update() -> void { auto Privacy::update() -> void {
mutex_.lock(); mutex_.lock();
bool screenshare, audio_in, audio_out; bool screenshare = false;
bool audio_in = false;
bool audio_out = false;
for (Gtk::Widget* widget : box_.get_children()) { for (Gtk::Widget* widget : box_.get_children()) {
PrivacyItem* module = dynamic_cast<PrivacyItem*>(widget); auto* module = dynamic_cast<PrivacyItem*>(widget);
if (!module) 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(); screenshare = !nodes_screenshare.empty();

View File

@ -1,14 +1,11 @@
#include "modules/privacy/privacy_item.hpp" #include "modules/privacy/privacy_item.hpp"
#include <string> #include <string>
#include <thread>
#include "AModule.hpp"
#include "glibmm/main.h" #include "glibmm/main.h"
#include "gtkmm/label.h" #include "gtkmm/label.h"
#include "gtkmm/revealer.h" #include "gtkmm/revealer.h"
#include "gtkmm/tooltip.h" #include "gtkmm/tooltip.h"
#include "sigc++/adaptors/bind.h"
#include "util/pipewire/privacy_node_info.hpp" #include "util/pipewire/privacy_node_info.hpp"
namespace waybar::modules::privacy { namespace waybar::modules::privacy {
@ -89,7 +86,7 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac
void PrivacyItem::update_tooltip() { void PrivacyItem::update_tooltip() {
// Removes all old nodes // Removes all old nodes
for (auto child : tooltip_window.get_children()) { for (auto *child : tooltip_window.get_children()) {
delete child; delete child;
} }