Merge pull request #3404 from khaneliman/clang-tidy

treewide: clang-tidy
This commit is contained in:
Alexis Rouillard 2024-07-02 22:33:52 +02:00 committed by GitHub
commit 18e67afe09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
18 changed files with 116 additions and 107 deletions

View File

@ -14,9 +14,9 @@ class AModule : public IModule {
public: public:
static constexpr const char *MODULE_CLASS = "module"; static constexpr const char *MODULE_CLASS = "module";
virtual ~AModule(); ~AModule() override;
auto update() -> void override; auto update() -> void override;
virtual auto refresh(int) -> void{}; virtual auto refresh(int shouldRefresh) -> void{};
operator Gtk::Widget &() override; operator Gtk::Widget &() override;
auto doAction(const std::string &name) -> void override; auto doAction(const std::string &name) -> void override;
@ -32,13 +32,13 @@ class AModule : public IModule {
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT }; enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };
SCROLL_DIR getScrollDir(GdkEventScroll *e); SCROLL_DIR getScrollDir(GdkEventScroll *e);
bool tooltipEnabled(); bool tooltipEnabled() const;
const std::string name_; const std::string name_;
const Json::Value &config_; const Json::Value &config_;
Gtk::EventBox event_box_; Gtk::EventBox event_box_;
virtual void setCursor(Gdk::CursorType const c); virtual void setCursor(Gdk::CursorType const &c);
virtual bool handleToggle(GdkEventButton *const &ev); virtual bool handleToggle(GdkEventButton *const &ev);
virtual bool handleMouseEnter(GdkEventCrossing *const &ev); virtual bool handleMouseEnter(GdkEventCrossing *const &ev);

View File

@ -56,10 +56,10 @@ class BacklightBackend {
void set_previous_best_device(const BacklightDevice *device); void set_previous_best_device(const BacklightDevice *device);
void set_brightness(std::string preferred_device, ChangeType change_type, double step); void set_brightness(const std::string &preferred_device, ChangeType change_type, double step);
void set_scaled_brightness(std::string preferred_device, int brightness); void set_scaled_brightness(const std::string &preferred_device, int brightness);
int get_scaled_brightness(std::string preferred_device); int get_scaled_brightness(const std::string &preferred_device);
bool is_login_proxy_initialized() const { return static_cast<bool>(login_proxy_); } bool is_login_proxy_initialized() const { return static_cast<bool>(login_proxy_); }
@ -70,7 +70,7 @@ class BacklightBackend {
std::mutex udev_thread_mutex_; std::mutex udev_thread_mutex_;
private: private:
void set_brightness_internal(std::string device_name, int brightness, int max_brightness); void set_brightness_internal(const std::string &device_name, int brightness, int max_brightness);
std::function<void()> on_updated_cb_; std::function<void()> on_updated_cb_;
std::chrono::milliseconds polling_interval_; std::chrono::milliseconds polling_interval_;

View File

@ -5,6 +5,7 @@
#include <functional> #include <functional>
#include <regex> #include <regex>
#include <string> #include <string>
#include <utility>
namespace waybar::util { namespace waybar::util {
@ -17,7 +18,7 @@ struct Rule {
// See https://en.cppreference.com/w/cpp/compiler_support/20 "Parenthesized initialization of // See https://en.cppreference.com/w/cpp/compiler_support/20 "Parenthesized initialization of
// aggregates" // aggregates"
Rule(std::regex rule, std::string repr, int priority) Rule(std::regex rule, std::string repr, int priority)
: rule(rule), repr(repr), priority(priority) {} : rule(std::move(rule)), repr(std::move(repr)), priority(priority) {}
}; };
int default_priority_function(std::string& key); int default_priority_function(std::string& key);
@ -40,8 +41,9 @@ class RegexCollection {
public: public:
RegexCollection() = default; RegexCollection() = default;
RegexCollection(const Json::Value& map, std::string default_repr = "", RegexCollection(
std::function<int(std::string&)> priority_function = default_priority_function); const Json::Value& map, std::string default_repr = "",
const std::function<int(std::string&)>& priority_function = default_priority_function);
~RegexCollection() = default; ~RegexCollection() = default;
std::string& get(std::string& value, bool& matched_any); std::string& get(std::string& value, bool& matched_any);

View File

@ -96,14 +96,14 @@ std::optional<Glib::ustring> getIconName(const std::string& app_identifier,
return app_identifier; return app_identifier;
} }
const auto app_identifier_desktop = app_identifier + "-desktop"; auto app_identifier_desktop = app_identifier + "-desktop";
if (DefaultGtkIconThemeWrapper::has_icon(app_identifier_desktop)) { if (DefaultGtkIconThemeWrapper::has_icon(app_identifier_desktop)) {
return app_identifier_desktop; return app_identifier_desktop;
} }
const auto first_space = app_identifier.find_first_of(' '); auto first_space = app_identifier.find_first_of(' ');
if (first_space != std::string::npos) { if (first_space != std::string::npos) {
const auto first_word = toLowerCase(app_identifier.substr(0, first_space)); auto first_word = toLowerCase(app_identifier.substr(0, first_space));
if (DefaultGtkIconThemeWrapper::has_icon(first_word)) { if (DefaultGtkIconThemeWrapper::has_icon(first_word)) {
return first_word; return first_word;
} }
@ -111,7 +111,7 @@ std::optional<Glib::ustring> getIconName(const std::string& app_identifier,
const auto first_dash = app_identifier.find_first_of('-'); const auto first_dash = app_identifier.find_first_of('-');
if (first_dash != std::string::npos) { if (first_dash != std::string::npos) {
const auto first_word = toLowerCase(app_identifier.substr(0, first_dash)); auto first_word = toLowerCase(app_identifier.substr(0, first_dash));
if (DefaultGtkIconThemeWrapper::has_icon(first_word)) { if (DefaultGtkIconThemeWrapper::has_icon(first_word)) {
return first_word; return first_word;
} }

View File

@ -71,12 +71,12 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
GtkBuilder* builder = gtk_builder_new(); GtkBuilder* builder = gtk_builder_new();
// Make the GtkBuilder and check for errors in his parsing // Make the GtkBuilder and check for errors in his parsing
if (!gtk_builder_add_from_string(builder, fileContent.str().c_str(), -1, nullptr)) { if (gtk_builder_add_from_string(builder, fileContent.str().c_str(), -1, nullptr) == 0U) {
throw std::runtime_error("Error found in the file " + menuFile); throw std::runtime_error("Error found in the file " + menuFile);
} }
menu_ = gtk_builder_get_object(builder, "menu"); menu_ = gtk_builder_get_object(builder, "menu");
if (!menu_) { if (menu_ == nullptr) {
throw std::runtime_error("Failed to get 'menu' object from GtkBuilder"); throw std::runtime_error("Failed to get 'menu' object from GtkBuilder");
} }
submenus_ = std::map<std::string, GtkMenuItem*>(); submenus_ = std::map<std::string, GtkMenuItem*>();
@ -121,7 +121,7 @@ std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_
} }
if (format_icons.isArray()) { if (format_icons.isArray()) {
auto size = format_icons.size(); auto size = format_icons.size();
if (size) { if (size != 0U) {
auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1); auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1);
format_icons = format_icons[idx]; format_icons = format_icons[idx];
} }
@ -147,7 +147,7 @@ std::string ALabel::getIcon(uint16_t percentage, const std::vector<std::string>&
} }
if (format_icons.isArray()) { if (format_icons.isArray()) {
auto size = format_icons.size(); auto size = format_icons.size();
if (size) { if (size != 0U) {
auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1); auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1);
format_icons = format_icons[idx]; format_icons = format_icons[idx];
} }

View File

@ -8,8 +8,8 @@ namespace waybar {
AModule::AModule(const Json::Value& config, const std::string& name, const std::string& id, AModule::AModule(const Json::Value& config, const std::string& name, const std::string& id,
bool enable_click, bool enable_scroll) bool enable_click, bool enable_scroll)
: name_(std::move(name)), : name_(name),
config_(std::move(config)), config_(config),
isTooltip{config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true}, isTooltip{config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true},
distance_scrolled_y_(0.0), distance_scrolled_y_(0.0),
distance_scrolled_x_(0.0) { distance_scrolled_x_(0.0) {
@ -18,12 +18,12 @@ AModule::AModule(const Json::Value& config, const std::string& name, const std::
for (Json::Value::const_iterator it = actions.begin(); it != actions.end(); ++it) { for (Json::Value::const_iterator it = actions.begin(); it != actions.end(); ++it) {
if (it.key().isString() && it->isString()) if (it.key().isString() && it->isString())
if (eventActionMap_.count(it.key().asString()) == 0) { if (!eventActionMap_.contains(it.key().asString())) {
eventActionMap_.insert({it.key().asString(), it->asString()}); eventActionMap_.insert({it.key().asString(), it->asString()});
enable_click = true; enable_click = true;
enable_scroll = true; enable_scroll = true;
} else } else
spdlog::warn("Dublicate action is ignored: {0}", it.key().asString()); spdlog::warn("Duplicate action is ignored: {0}", it.key().asString());
else else
spdlog::warn("Wrong actions section configuration. See config by index: {}", it.index()); spdlog::warn("Wrong actions section configuration. See config by index: {}", it.index());
} }
@ -90,7 +90,7 @@ auto AModule::doAction(const std::string& name) -> void {
} }
} }
void AModule::setCursor(Gdk::CursorType c) { void AModule::setCursor(Gdk::CursorType const& c) {
auto cursor = Gdk::Cursor::create(c); auto cursor = Gdk::Cursor::create(c);
auto gdk_window = event_box_.get_window(); auto gdk_window = event_box_.get_window();
gdk_window->set_cursor(cursor); gdk_window->set_cursor(cursor);
@ -164,7 +164,7 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {
// ignore reverse-scrolling if event comes from a mouse wheel // ignore reverse-scrolling if event comes from a mouse wheel
GdkDevice* device = gdk_event_get_source_device((GdkEvent*)e); GdkDevice* device = gdk_event_get_source_device((GdkEvent*)e);
if (device != NULL && gdk_device_get_source(device) == GDK_SOURCE_MOUSE) { if (device != nullptr && gdk_device_get_source(device) == GDK_SOURCE_MOUSE) {
reverse = reverse_mouse; reverse = reverse_mouse;
} }
@ -242,7 +242,7 @@ bool AModule::handleScroll(GdkEventScroll* e) {
return true; return true;
} }
bool AModule::tooltipEnabled() { return isTooltip; } bool AModule::tooltipEnabled() const { return isTooltip; }
AModule::operator Gtk::Widget&() { return event_box_; } AModule::operator Gtk::Widget&() { return event_box_; }

View File

@ -72,16 +72,16 @@ void from_json(const Json::Value& j, std::optional<bar_layer>& l) {
/* Deserializer for struct bar_mode */ /* Deserializer for struct bar_mode */
void from_json(const Json::Value& j, bar_mode& m) { void from_json(const Json::Value& j, bar_mode& m) {
if (j.isObject()) { if (j.isObject()) {
if (auto v = j["layer"]; v.isString()) { if (const auto& v = j["layer"]; v.isString()) {
from_json(v, m.layer); from_json(v, m.layer);
} }
if (auto v = j["exclusive"]; v.isBool()) { if (const auto& v = j["exclusive"]; v.isBool()) {
m.exclusive = v.asBool(); m.exclusive = v.asBool();
} }
if (auto v = j["passthrough"]; v.isBool()) { if (const auto& v = j["passthrough"]; v.isBool()) {
m.passthrough = v.asBool(); m.passthrough = v.asBool();
} }
if (auto v = j["visible"]; v.isBool()) { if (const auto& v = j["visible"]; v.isBool()) {
m.visible = v.asBool(); m.visible = v.asBool();
} }
} }
@ -118,7 +118,7 @@ Glib::ustring to_string(Gtk::PositionType pos) {
* Assumes that all the values in the object are deserializable to the same type. * Assumes that all the values in the object are deserializable to the same type.
*/ */
template <typename Key, typename Value, template <typename Key, typename Value,
typename = std::enable_if_t<std::is_convertible<std::string, Key>::value>> typename = std::enable_if_t<std::is_convertible_v<std::string, Key>>>
void from_json(const Json::Value& j, std::map<Key, Value>& m) { void from_json(const Json::Value& j, std::map<Key, Value>& m) {
if (j.isObject()) { if (j.isObject()) {
for (auto it = j.begin(); it != j.end(); ++it) { for (auto it = j.begin(); it != j.end(); ++it) {
@ -393,19 +393,18 @@ void waybar::Bar::setPosition(Gtk::PositionType position) {
} }
} }
void waybar::Bar::onMap(GdkEventAny*) { void waybar::Bar::onMap(GdkEventAny* /*unused*/) {
/* /*
* Obtain a pointer to the custom layer surface for modules that require it (idle_inhibitor). * Obtain a pointer to the custom layer surface for modules that require it (idle_inhibitor).
*/ */
auto gdk_window = window.get_window()->gobj(); auto* gdk_window = window.get_window()->gobj();
surface = gdk_wayland_window_get_wl_surface(gdk_window); surface = gdk_wayland_window_get_wl_surface(gdk_window);
configureGlobalOffset(gdk_window_get_width(gdk_window), gdk_window_get_height(gdk_window)); configureGlobalOffset(gdk_window_get_width(gdk_window), gdk_window_get_height(gdk_window));
setPassThrough(passthrough_); setPassThrough(passthrough_);
} }
void waybar::Bar::setVisible(bool value) { void waybar::Bar::setVisible(bool visible) {
visible = value;
if (auto mode = config.get("mode", {}); mode.isString()) { if (auto mode = config.get("mode", {}); mode.isString()) {
setMode(visible ? config["mode"].asString() : MODE_INVISIBLE); setMode(visible ? config["mode"].asString() : MODE_INVISIBLE);
} else { } else {
@ -473,7 +472,7 @@ void waybar::Bar::handleSignal(int signal) {
void waybar::Bar::getModules(const Factory& factory, const std::string& pos, void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
waybar::Group* group = nullptr) { waybar::Group* group = nullptr) {
auto module_list = group ? config[pos]["modules"] : config[pos]; auto module_list = group != nullptr ? config[pos]["modules"] : config[pos];
if (module_list.isArray()) { if (module_list.isArray()) {
for (const auto& name : module_list) { for (const auto& name : module_list) {
try { try {
@ -485,10 +484,10 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
auto id_name = ref.substr(6, hash_pos - 6); auto id_name = ref.substr(6, hash_pos - 6);
auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : ""; auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : "";
auto vertical = (group ? group->getBox().get_orientation() : box_.get_orientation()) == auto vertical = (group != nullptr ? group->getBox().get_orientation()
Gtk::ORIENTATION_VERTICAL; : box_.get_orientation()) == Gtk::ORIENTATION_VERTICAL;
auto group_module = new waybar::Group(id_name, class_name, config[ref], vertical); auto* group_module = new waybar::Group(id_name, class_name, config[ref], vertical);
getModules(factory, ref, group_module); getModules(factory, ref, group_module);
module = group_module; module = group_module;
} else { } else {
@ -497,7 +496,7 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
std::shared_ptr<AModule> module_sp(module); std::shared_ptr<AModule> module_sp(module);
modules_all_.emplace_back(module_sp); modules_all_.emplace_back(module_sp);
if (group) { if (group != nullptr) {
group->addWidget(*module); group->addWidget(*module);
} else { } else {
if (pos == "modules-left") { if (pos == "modules-left") {

View File

@ -4,6 +4,7 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <iostream> #include <iostream>
#include <utility>
#include "gtkmm/icontheme.h" #include "gtkmm/icontheme.h"
#include "idle-inhibit-unstable-v1-client-protocol.h" #include "idle-inhibit-unstable-v1-client-protocol.h"
@ -11,13 +12,13 @@
#include "util/format.hpp" #include "util/format.hpp"
waybar::Client *waybar::Client::inst() { waybar::Client *waybar::Client::inst() {
static auto c = new Client(); static auto *c = new Client();
return c; return c;
} }
void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint32_t name, void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version) { const char *interface, uint32_t version) {
auto client = static_cast<Client *>(data); auto *client = static_cast<Client *>(data);
if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 && if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 &&
version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) {
client->xdg_output_manager = static_cast<struct zxdg_output_manager_v1 *>(wl_registry_bind( client->xdg_output_manager = static_cast<struct zxdg_output_manager_v1 *>(wl_registry_bind(
@ -42,7 +43,7 @@ void waybar::Client::handleOutput(struct waybar_output &output) {
.description = &handleOutputDescription, .description = &handleOutputDescription,
}; };
// owned by output->monitor; no need to destroy // owned by output->monitor; no need to destroy
auto wl_output = gdk_wayland_monitor_get_wl_output(output.monitor->gobj()); auto *wl_output = gdk_wayland_monitor_get_wl_output(output.monitor->gobj());
output.xdg_output.reset(zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, wl_output)); output.xdg_output.reset(zxdg_output_manager_v1_get_xdg_output(xdg_output_manager, wl_output));
zxdg_output_v1_add_listener(output.xdg_output.get(), &xdgOutputListener, &output); zxdg_output_v1_add_listener(output.xdg_output.get(), &xdgOutputListener, &output);
} }
@ -61,7 +62,7 @@ std::vector<Json::Value> waybar::Client::getOutputConfigs(struct waybar_output &
} }
void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_output*/) { void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_output*/) {
auto client = waybar::Client::inst(); auto *client = waybar::Client::inst();
try { try {
auto &output = client->getOutput(data); auto &output = client->getOutput(data);
/** /**
@ -85,24 +86,24 @@ void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_
} }
} }
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << '\n';
} }
} }
void waybar::Client::handleOutputName(void *data, struct zxdg_output_v1 * /*xdg_output*/, void waybar::Client::handleOutputName(void *data, struct zxdg_output_v1 * /*xdg_output*/,
const char *name) { const char *name) {
auto client = waybar::Client::inst(); auto *client = waybar::Client::inst();
try { try {
auto &output = client->getOutput(data); auto &output = client->getOutput(data);
output.name = name; output.name = name;
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << '\n';
} }
} }
void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 * /*xdg_output*/, void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 * /*xdg_output*/,
const char *description) { const char *description) {
auto client = waybar::Client::inst(); auto *client = waybar::Client::inst();
try { try {
auto &output = client->getOutput(data); auto &output = client->getOutput(data);
const char *open_paren = strrchr(description, '('); const char *open_paren = strrchr(description, '(');
@ -111,13 +112,13 @@ void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 *
size_t identifier_length = open_paren - description; size_t identifier_length = open_paren - description;
output.identifier = std::string(description, identifier_length - 1); output.identifier = std::string(description, identifier_length - 1);
} catch (const std::exception &e) { } catch (const std::exception &e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << '\n';
} }
} }
void waybar::Client::handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor) { void waybar::Client::handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor) {
auto &output = outputs_.emplace_back(); auto &output = outputs_.emplace_back();
output.monitor = monitor; output.monitor = std::move(monitor);
handleOutput(output); handleOutput(output);
} }
@ -154,15 +155,15 @@ const std::string waybar::Client::getStyle(const std::string &style,
std::vector<std::string> search_files; std::vector<std::string> search_files;
switch (appearance.value_or(portal->getAppearance())) { switch (appearance.value_or(portal->getAppearance())) {
case waybar::Appearance::LIGHT: case waybar::Appearance::LIGHT:
search_files.push_back("style-light.css"); search_files.emplace_back("style-light.css");
break; break;
case waybar::Appearance::DARK: case waybar::Appearance::DARK:
search_files.push_back("style-dark.css"); search_files.emplace_back("style-dark.css");
break; break;
case waybar::Appearance::UNKNOWN: case waybar::Appearance::UNKNOWN:
break; break;
} }
search_files.push_back("style.css"); search_files.emplace_back("style.css");
css_file = Config::findConfigPath(search_files); css_file = Config::findConfigPath(search_files);
} else { } else {
css_file = style; css_file = style;
@ -196,7 +197,7 @@ void waybar::Client::bindInterfaces() {
wl_registry_add_listener(registry, &registry_listener, this); wl_registry_add_listener(registry, &registry_listener, this);
wl_display_roundtrip(wl_display); wl_display_roundtrip(wl_display);
if (!gtk_layer_is_supported()) { if (gtk_layer_is_supported() == 0) {
throw std::runtime_error("The Wayland compositor does not support wlr-layer-shell protocol"); throw std::runtime_error("The Wayland compositor does not support wlr-layer-shell protocol");
} }
@ -233,11 +234,11 @@ int waybar::Client::main(int argc, char *argv[]) {
return 1; return 1;
} }
if (show_help) { if (show_help) {
std::cout << cli << std::endl; std::cout << cli << '\n';
return 0; return 0;
} }
if (show_version) { if (show_version) {
std::cout << "Waybar v" << VERSION << std::endl; std::cout << "Waybar v" << VERSION << '\n';
return 0; return 0;
} }
if (!log_level.empty()) { if (!log_level.empty()) {

View File

@ -21,10 +21,10 @@ const std::vector<std::string> Config::CONFIG_DIRS = {
const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR"; const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR";
std::optional<std::string> tryExpandPath(const std::string base, const std::string filename) { std::optional<std::string> tryExpandPath(const std::string &base, const std::string &filename) {
fs::path path; fs::path path;
if (filename != "") { if (!filename.empty()) {
path = fs::path(base) / fs::path(filename); path = fs::path(base) / fs::path(filename);
} else { } else {
path = fs::path(base); path = fs::path(base);
@ -129,9 +129,9 @@ bool isValidOutput(const Json::Value &config, const std::string &name,
if (config_output.substr(0, 1) == "!") { if (config_output.substr(0, 1) == "!") {
if (config_output.substr(1) == name || config_output.substr(1) == identifier) { if (config_output.substr(1) == name || config_output.substr(1) == identifier) {
return false; return false;
} else {
continue;
} }
continue;
} }
if (config_output == name || config_output == identifier) { if (config_output == name || config_output == identifier) {
return true; return true;
@ -142,7 +142,9 @@ bool isValidOutput(const Json::Value &config, const std::string &name,
} }
} }
return false; return false;
} else if (config["output"].isString()) { }
if (config["output"].isString()) {
auto config_output = config["output"].asString(); auto config_output = config["output"].asString();
if (!config_output.empty()) { if (!config_output.empty()) {
if (config_output.substr(0, 1) == "!") { if (config_output.substr(0, 1) == "!") {

View File

@ -19,9 +19,9 @@ const Gtk::RevealerTransitionType getPreferredTransitionType(bool is_vertical) {
if (is_vertical) { if (is_vertical) {
return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_UP; return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_UP;
} else {
return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_LEFT;
} }
return Gtk::RevealerTransitionType::REVEALER_TRANSITION_TYPE_SLIDE_LEFT;
} }
Group::Group(const std::string& name, const std::string& id, const Json::Value& config, Group::Group(const std::string& name, const std::string& id, const Json::Value& config,

View File

@ -13,7 +13,8 @@ std::list<pid_t> reap;
volatile bool reload; volatile bool reload;
void* signalThread(void* args) { void* signalThread(void* args) {
int err, signum; int err;
int signum;
sigset_t mask; sigset_t mask;
sigemptyset(&mask); sigemptyset(&mask);
sigaddset(&mask, SIGCHLD); sigaddset(&mask, SIGCHLD);
@ -46,7 +47,7 @@ void* signalThread(void* args) {
} }
} }
void startSignalThread(void) { void startSignalThread() {
int err; int err;
sigset_t mask; sigset_t mask;
sigemptyset(&mask); sigemptyset(&mask);
@ -71,7 +72,7 @@ void startSignalThread(void) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
try { try {
auto client = waybar::Client::inst(); auto* client = waybar::Client::inst();
std::signal(SIGUSR1, [](int /*signal*/) { std::signal(SIGUSR1, [](int /*signal*/) {
for (auto& bar : waybar::Client::inst()->bars) { for (auto& bar : waybar::Client::inst()->bars) {

View File

@ -8,6 +8,7 @@
#include <algorithm> #include <algorithm>
#include <cmath> #include <cmath>
#include <stdexcept> #include <stdexcept>
#include <utility>
namespace waybar::util { namespace waybar::util {
@ -15,13 +16,11 @@ AudioBackend::AudioBackend(std::function<void()> on_updated_cb, private_construc
: mainloop_(nullptr), : mainloop_(nullptr),
mainloop_api_(nullptr), mainloop_api_(nullptr),
context_(nullptr), context_(nullptr),
sink_idx_(0),
volume_(0), volume_(0),
muted_(false), muted_(false),
source_idx_(0),
source_volume_(0), source_volume_(0),
source_muted_(false), source_muted_(false),
on_updated_cb_(on_updated_cb) { on_updated_cb_(std::move(on_updated_cb)) {
mainloop_ = pa_threaded_mainloop_new(); mainloop_ = pa_threaded_mainloop_new();
if (mainloop_ == nullptr) { if (mainloop_ == nullptr) {
throw std::runtime_error("pa_mainloop_new() failed."); throw std::runtime_error("pa_mainloop_new() failed.");
@ -66,7 +65,7 @@ void AudioBackend::connectContext() {
} }
void AudioBackend::contextStateCb(pa_context *c, void *data) { void AudioBackend::contextStateCb(pa_context *c, void *data) {
auto backend = static_cast<AudioBackend *>(data); auto *backend = static_cast<AudioBackend *>(data);
switch (pa_context_get_state(c)) { switch (pa_context_get_state(c)) {
case PA_CONTEXT_TERMINATED: case PA_CONTEXT_TERMINATED:
backend->mainloop_api_->quit(backend->mainloop_api_, 0); backend->mainloop_api_->quit(backend->mainloop_api_, 0);
@ -127,7 +126,7 @@ void AudioBackend::subscribeCb(pa_context *context, pa_subscription_event_type_t
* Called in response to a volume change request * Called in response to a volume change request
*/ */
void AudioBackend::volumeModifyCb(pa_context *c, int success, void *data) { void AudioBackend::volumeModifyCb(pa_context *c, int success, void *data) {
auto backend = static_cast<AudioBackend *>(data); auto *backend = static_cast<AudioBackend *>(data);
if (success != 0) { if (success != 0) {
pa_context_get_sink_info_by_index(backend->context_, backend->sink_idx_, sinkInfoCb, data); pa_context_get_sink_info_by_index(backend->context_, backend->sink_idx_, sinkInfoCb, data);
} }
@ -140,7 +139,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
void *data) { void *data) {
if (i == nullptr) return; if (i == nullptr) return;
auto backend = static_cast<AudioBackend *>(data); auto *backend = static_cast<AudioBackend *>(data);
if (!backend->ignored_sinks_.empty()) { if (!backend->ignored_sinks_.empty()) {
for (const auto &ignored_sink : backend->ignored_sinks_) { for (const auto &ignored_sink : backend->ignored_sinks_) {
@ -151,11 +150,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
} }
if (backend->current_sink_name_ == i->name) { if (backend->current_sink_name_ == i->name) {
if (i->state != PA_SINK_RUNNING) { backend->current_sink_running_ = i->state == PA_SINK_RUNNING;
backend->current_sink_running_ = false;
} else {
backend->current_sink_running_ = true;
}
} }
if (!backend->current_sink_running_ && i->state == PA_SINK_RUNNING) { if (!backend->current_sink_running_ && i->state == PA_SINK_RUNNING) {
@ -173,7 +168,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
backend->desc_ = i->description; backend->desc_ = i->description;
backend->monitor_ = i->monitor_source_name; backend->monitor_ = i->monitor_source_name;
backend->port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown"; backend->port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown";
if (auto ff = pa_proplist_gets(i->proplist, PA_PROP_DEVICE_FORM_FACTOR)) { if (const auto *ff = pa_proplist_gets(i->proplist, PA_PROP_DEVICE_FORM_FACTOR)) {
backend->form_factor_ = ff; backend->form_factor_ = ff;
} else { } else {
backend->form_factor_ = ""; backend->form_factor_ = "";
@ -187,7 +182,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i
*/ */
void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *i, int /*eol*/, void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *i, int /*eol*/,
void *data) { void *data) {
auto backend = static_cast<AudioBackend *>(data); auto *backend = static_cast<AudioBackend *>(data);
if (i != nullptr && backend->default_source_name_ == i->name) { if (i != nullptr && backend->default_source_name_ == i->name) {
auto source_volume = static_cast<float>(pa_cvolume_avg(&(i->volume))) / float{PA_VOLUME_NORM}; auto source_volume = static_cast<float>(pa_cvolume_avg(&(i->volume))) / float{PA_VOLUME_NORM};
backend->source_volume_ = std::round(source_volume * 100.0F); backend->source_volume_ = std::round(source_volume * 100.0F);
@ -204,7 +199,7 @@ void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *
* used to find the default PulseAudio sink. * used to find the default PulseAudio sink.
*/ */
void AudioBackend::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) { void AudioBackend::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) {
auto backend = static_cast<AudioBackend *>(data); auto *backend = static_cast<AudioBackend *>(data);
backend->current_sink_name_ = i->default_sink_name; backend->current_sink_name_ = i->default_sink_name;
backend->default_source_name_ = i->default_source_name; backend->default_source_name_ = i->default_source_name;
@ -253,22 +248,26 @@ void AudioBackend::changeVolume(ChangeType change_type, double step, uint16_t ma
void AudioBackend::toggleSinkMute() { void AudioBackend::toggleSinkMute() {
muted_ = !muted_; muted_ = !muted_;
pa_context_set_sink_mute_by_index(context_, sink_idx_, muted_, nullptr, nullptr); pa_context_set_sink_mute_by_index(context_, sink_idx_, static_cast<int>(muted_), nullptr,
nullptr);
} }
void AudioBackend::toggleSinkMute(bool mute) { void AudioBackend::toggleSinkMute(bool mute) {
muted_ = mute; muted_ = mute;
pa_context_set_sink_mute_by_index(context_, sink_idx_, muted_, nullptr, nullptr); pa_context_set_sink_mute_by_index(context_, sink_idx_, static_cast<int>(muted_), nullptr,
nullptr);
} }
void AudioBackend::toggleSourceMute() { void AudioBackend::toggleSourceMute() {
source_muted_ = !muted_; source_muted_ = !muted_;
pa_context_set_source_mute_by_index(context_, source_idx_, source_muted_, nullptr, nullptr); pa_context_set_source_mute_by_index(context_, source_idx_, static_cast<int>(source_muted_),
nullptr, nullptr);
} }
void AudioBackend::toggleSourceMute(bool mute) { void AudioBackend::toggleSourceMute(bool mute) {
source_muted_ = mute; source_muted_ = mute;
pa_context_set_source_mute_by_index(context_, source_idx_, source_muted_, nullptr, nullptr); pa_context_set_source_mute_by_index(context_, source_idx_, static_cast<int>(source_muted_),
nullptr, nullptr);
} }
bool AudioBackend::isBluetooth() { bool AudioBackend::isBluetooth() {
@ -287,4 +286,4 @@ void AudioBackend::setIgnoredSinks(const Json::Value &config) {
} }
} }
} // namespace waybar::util } // namespace waybar::util

View File

@ -4,7 +4,9 @@
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <sys/epoll.h> #include <sys/epoll.h>
#include <cmath>
#include <optional> #include <optional>
#include <utility>
namespace { namespace {
class FileDescriptor { class FileDescriptor {
@ -122,7 +124,7 @@ static void enumerate_devices(std::vector<BacklightDevice> &devices, udev *udev)
} }
BacklightDevice::BacklightDevice(std::string name, int actual, int max, bool powered) BacklightDevice::BacklightDevice(std::string name, int actual, int max, bool powered)
: name_(name), actual_(actual), max_(max), powered_(powered) {} : name_(std::move(name)), actual_(actual), max_(max), powered_(powered) {}
std::string BacklightDevice::name() const { return name_; } std::string BacklightDevice::name() const { return name_; }
@ -140,7 +142,7 @@ void BacklightDevice::set_powered(bool powered) { powered_ = powered; }
BacklightBackend::BacklightBackend(std::chrono::milliseconds interval, BacklightBackend::BacklightBackend(std::chrono::milliseconds interval,
std::function<void()> on_updated_cb) std::function<void()> on_updated_cb)
: on_updated_cb_(on_updated_cb), polling_interval_(interval), previous_best_({}) { : on_updated_cb_(std::move(on_updated_cb)), polling_interval_(interval), previous_best_({}) {
std::unique_ptr<udev, UdevDeleter> udev_check{udev_new()}; std::unique_ptr<udev, UdevDeleter> udev_check{udev_new()};
check_nn(udev_check.get(), "Udev check new failed"); check_nn(udev_check.get(), "Udev check new failed");
enumerate_devices(devices_, udev_check.get()); enumerate_devices(devices_, udev_check.get());
@ -236,24 +238,24 @@ void BacklightBackend::set_previous_best_device(const BacklightDevice *device) {
} }
} }
void BacklightBackend::set_scaled_brightness(std::string preferred_device, int brightness) { void BacklightBackend::set_scaled_brightness(const std::string &preferred_device, int brightness) {
GET_BEST_DEVICE(best, (*this), preferred_device); GET_BEST_DEVICE(best, (*this), preferred_device);
if (best != nullptr) { if (best != nullptr) {
const auto max = best->get_max(); const auto max = best->get_max();
const auto abs_val = static_cast<int>(round(brightness * max / 100.0f)); const auto abs_val = static_cast<int>(std::round(brightness * max / 100.0F));
set_brightness_internal(best->name(), abs_val, best->get_max()); set_brightness_internal(best->name(), abs_val, best->get_max());
} }
} }
void BacklightBackend::set_brightness(std::string preferred_device, ChangeType change_type, void BacklightBackend::set_brightness(const std::string &preferred_device, ChangeType change_type,
double step) { double step) {
GET_BEST_DEVICE(best, (*this), preferred_device); GET_BEST_DEVICE(best, (*this), preferred_device);
if (best != nullptr) { if (best != nullptr) {
const auto max = best->get_max(); const auto max = best->get_max();
const auto abs_step = static_cast<int>(round(step * max / 100.0f)); const auto abs_step = static_cast<int>(round(step * max / 100.0F));
const int new_brightness = change_type == ChangeType::Increase ? best->get_actual() + abs_step const int new_brightness = change_type == ChangeType::Increase ? best->get_actual() + abs_step
: best->get_actual() - abs_step; : best->get_actual() - abs_step;
@ -261,7 +263,7 @@ void BacklightBackend::set_brightness(std::string preferred_device, ChangeType c
} }
} }
void BacklightBackend::set_brightness_internal(std::string device_name, int brightness, void BacklightBackend::set_brightness_internal(const std::string &device_name, int brightness,
int max_brightness) { int max_brightness) {
brightness = std::clamp(brightness, 0, max_brightness); brightness = std::clamp(brightness, 0, max_brightness);
@ -271,7 +273,7 @@ void BacklightBackend::set_brightness_internal(std::string device_name, int brig
login_proxy_->call_sync("SetBrightness", call_args); login_proxy_->call_sync("SetBrightness", call_args);
} }
int BacklightBackend::get_scaled_brightness(std::string preferred_device) { int BacklightBackend::get_scaled_brightness(const std::string &preferred_device) {
GET_BEST_DEVICE(best, (*this), preferred_device); GET_BEST_DEVICE(best, (*this), preferred_device);
if (best != nullptr) { if (best != nullptr) {

View File

@ -85,7 +85,9 @@ void waybar::Portal::on_signal(const Glib::ustring& sender_name, const Glib::ust
if (signal_name != "SettingChanged" || parameters.get_n_children() != 3) { if (signal_name != "SettingChanged" || parameters.get_n_children() != 3) {
return; return;
} }
Glib::VariantBase nspcv, keyv, valuev; Glib::VariantBase nspcv;
Glib::VariantBase keyv;
Glib::VariantBase valuev;
parameters.get_child(nspcv, 0); parameters.get_child(nspcv, 0);
parameters.get_child(keyv, 1); parameters.get_child(keyv, 1);
parameters.get_child(valuev, 2); parameters.get_child(valuev, 2);

View File

@ -7,14 +7,14 @@ namespace {
class PrepareForSleep { class PrepareForSleep {
private: private:
PrepareForSleep() { PrepareForSleep() {
login1_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); login1_connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr);
if (!login1_connection) { if (login1_connection == nullptr) {
spdlog::warn("Unable to connect to the SYSTEM Bus!..."); spdlog::warn("Unable to connect to the SYSTEM Bus!...");
} else { } else {
login1_id = g_dbus_connection_signal_subscribe( login1_id = g_dbus_connection_signal_subscribe(
login1_connection, "org.freedesktop.login1", "org.freedesktop.login1.Manager", login1_connection, "org.freedesktop.login1", "org.freedesktop.login1.Manager",
"PrepareForSleep", "/org/freedesktop/login1", NULL, G_DBUS_SIGNAL_FLAGS_NONE, "PrepareForSleep", "/org/freedesktop/login1", nullptr, G_DBUS_SIGNAL_FLAGS_NONE,
prepareForSleep_cb, this, NULL); prepareForSleep_cb, this, nullptr);
} }
} }
@ -22,11 +22,11 @@ class PrepareForSleep {
const gchar *object_path, const gchar *interface_name, const gchar *object_path, const gchar *interface_name,
const gchar *signal_name, GVariant *parameters, const gchar *signal_name, GVariant *parameters,
gpointer user_data) { gpointer user_data) {
if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(b)"))) { if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(b)")) != 0) {
gboolean sleeping; gboolean sleeping;
g_variant_get(parameters, "(b)", &sleeping); g_variant_get(parameters, "(b)", &sleeping);
PrepareForSleep *self = static_cast<PrepareForSleep *>(user_data); auto *self = static_cast<PrepareForSleep *>(user_data);
self->signal.emit(sleeping); self->signal.emit(sleeping);
} }
} }

View File

@ -3,13 +3,15 @@
#include <json/value.h> #include <json/value.h>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <utility>
namespace waybar::util { namespace waybar::util {
int default_priority_function(std::string& key) { return 0; } int default_priority_function(std::string& key) { return 0; }
RegexCollection::RegexCollection(const Json::Value& map, std::string default_repr, RegexCollection::RegexCollection(const Json::Value& map, std::string default_repr,
std::function<int(std::string&)> priority_function) const std::function<int(std::string&)>& priority_function)
: default_repr(default_repr) { : default_repr(std::move(default_repr)) {
if (!map.isObject()) { if (!map.isObject()) {
spdlog::warn("Mapping is not an object"); spdlog::warn("Mapping is not an object");
return; return;

View File

@ -10,9 +10,8 @@ std::string sanitize_string(std::string str) {
const std::pair<char, std::string> replacement_table[] = { const std::pair<char, std::string> replacement_table[] = {
{'&', "&amp;"}, {'<', "&lt;"}, {'>', "&gt;"}, {'"', "&quot;"}, {'\'', "&apos;"}}; {'&', "&amp;"}, {'<', "&lt;"}, {'>', "&gt;"}, {'"', "&quot;"}, {'\'', "&apos;"}};
size_t startpoint; size_t startpoint;
for (size_t i = 0; i < (sizeof(replacement_table) / sizeof(replacement_table[0])); ++i) { for (const auto& pair : replacement_table) {
startpoint = 0; startpoint = 0;
std::pair pair = replacement_table[i];
while ((startpoint = str.find(pair.first, startpoint)) != std::string::npos) { while ((startpoint = str.find(pair.first, startpoint)) != std::string::npos) {
str.replace(startpoint, 1, pair.second); str.replace(startpoint, 1, pair.second);
startpoint += pair.second.length(); startpoint += pair.second.length();

View File

@ -2,8 +2,8 @@
int ustring_clen(const Glib::ustring &str) { int ustring_clen(const Glib::ustring &str) {
int total = 0; int total = 0;
for (auto i = str.begin(); i != str.end(); ++i) { for (unsigned int i : str) {
total += g_unichar_iswide(*i) + 1; total += g_unichar_iswide(i) + 1;
} }
return total; return total;
} }