Skip to content

Commit

Permalink
Merge pull request #3404 from khaneliman/clang-tidy
Browse files Browse the repository at this point in the history
treewide: clang-tidy
  • Loading branch information
Alexays authored Jul 2, 2024
2 parents 034760e + d66685a commit 18e67af
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 107 deletions.
8 changes: 4 additions & 4 deletions include/AModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class AModule : public IModule {
public:
static constexpr const char *MODULE_CLASS = "module";

virtual ~AModule();
~AModule() override;
auto update() -> void override;
virtual auto refresh(int) -> void{};
virtual auto refresh(int shouldRefresh) -> void{};
operator Gtk::Widget &() override;
auto doAction(const std::string &name) -> void override;

Expand All @@ -32,13 +32,13 @@ class AModule : public IModule {
enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };

SCROLL_DIR getScrollDir(GdkEventScroll *e);
bool tooltipEnabled();
bool tooltipEnabled() const;

const std::string name_;
const Json::Value &config_;
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 handleMouseEnter(GdkEventCrossing *const &ev);
Expand Down
8 changes: 4 additions & 4 deletions include/util/backlight_backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ class BacklightBackend {

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);
int get_scaled_brightness(std::string preferred_device);
void set_scaled_brightness(const std::string &preferred_device, int brightness);
int get_scaled_brightness(const std::string &preferred_device);

bool is_login_proxy_initialized() const { return static_cast<bool>(login_proxy_); }

Expand All @@ -70,7 +70,7 @@ class BacklightBackend {
std::mutex udev_thread_mutex_;

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::chrono::milliseconds polling_interval_;
Expand Down
8 changes: 5 additions & 3 deletions include/util/regex_collection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <functional>
#include <regex>
#include <string>
#include <utility>

namespace waybar::util {

Expand All @@ -17,7 +18,7 @@ struct Rule {
// See https://en.cppreference.com/w/cpp/compiler_support/20 "Parenthesized initialization of
// aggregates"
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);
Expand All @@ -40,8 +41,9 @@ class RegexCollection {

public:
RegexCollection() = default;
RegexCollection(const Json::Value& map, std::string default_repr = "",
std::function<int(std::string&)> priority_function = default_priority_function);
RegexCollection(
const Json::Value& map, std::string default_repr = "",
const std::function<int(std::string&)>& priority_function = default_priority_function);
~RegexCollection() = default;

std::string& get(std::string& value, bool& matched_any);
Expand Down
8 changes: 4 additions & 4 deletions src/AAppIconLabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,22 @@ std::optional<Glib::ustring> getIconName(const std::string& 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)) {
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) {
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)) {
return first_word;
}
}

const auto first_dash = app_identifier.find_first_of('-');
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)) {
return first_word;
}
Expand Down
8 changes: 4 additions & 4 deletions src/ALabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
GtkBuilder* builder = gtk_builder_new();

// 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);
}

menu_ = gtk_builder_get_object(builder, "menu");
if (!menu_) {
if (menu_ == nullptr) {
throw std::runtime_error("Failed to get 'menu' object from GtkBuilder");
}
submenus_ = std::map<std::string, GtkMenuItem*>();
Expand Down Expand Up @@ -121,7 +121,7 @@ std::string ALabel::getIcon(uint16_t percentage, const std::string& alt, uint16_
}
if (format_icons.isArray()) {
auto size = format_icons.size();
if (size) {
if (size != 0U) {
auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1);
format_icons = format_icons[idx];
}
Expand All @@ -147,7 +147,7 @@ std::string ALabel::getIcon(uint16_t percentage, const std::vector<std::string>&
}
if (format_icons.isArray()) {
auto size = format_icons.size();
if (size) {
if (size != 0U) {
auto idx = std::clamp(percentage / ((max == 0 ? 100 : max) / size), 0U, size - 1);
format_icons = format_icons[idx];
}
Expand Down
14 changes: 7 additions & 7 deletions src/AModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace waybar {

AModule::AModule(const Json::Value& config, const std::string& name, const std::string& id,
bool enable_click, bool enable_scroll)
: name_(std::move(name)),
config_(std::move(config)),
: name_(name),
config_(config),
isTooltip{config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true},
distance_scrolled_y_(0.0),
distance_scrolled_x_(0.0) {
Expand All @@ -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) {
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()});
enable_click = true;
enable_scroll = true;
} else
spdlog::warn("Dublicate action is ignored: {0}", it.key().asString());
spdlog::warn("Duplicate action is ignored: {0}", it.key().asString());
else
spdlog::warn("Wrong actions section configuration. See config by index: {}", it.index());
}
Expand Down Expand Up @@ -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 gdk_window = event_box_.get_window();
gdk_window->set_cursor(cursor);
Expand Down Expand Up @@ -164,7 +164,7 @@ AModule::SCROLL_DIR AModule::getScrollDir(GdkEventScroll* e) {

// ignore reverse-scrolling if event comes from a mouse wheel
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;
}

Expand Down Expand Up @@ -242,7 +242,7 @@ bool AModule::handleScroll(GdkEventScroll* e) {
return true;
}

bool AModule::tooltipEnabled() { return isTooltip; }
bool AModule::tooltipEnabled() const { return isTooltip; }

AModule::operator Gtk::Widget&() { return event_box_; }

Expand Down
27 changes: 13 additions & 14 deletions src/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,16 @@ void from_json(const Json::Value& j, std::optional<bar_layer>& l) {
/* Deserializer for struct bar_mode */
void from_json(const Json::Value& j, bar_mode& m) {
if (j.isObject()) {
if (auto v = j["layer"]; v.isString()) {
if (const auto& v = j["layer"]; v.isString()) {
from_json(v, m.layer);
}
if (auto v = j["exclusive"]; v.isBool()) {
if (const auto& v = j["exclusive"]; v.isBool()) {
m.exclusive = v.asBool();
}
if (auto v = j["passthrough"]; v.isBool()) {
if (const auto& v = j["passthrough"]; v.isBool()) {
m.passthrough = v.asBool();
}
if (auto v = j["visible"]; v.isBool()) {
if (const auto& v = j["visible"]; v.isBool()) {
m.visible = v.asBool();
}
}
Expand Down Expand Up @@ -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.
*/
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) {
if (j.isObject()) {
for (auto it = j.begin(); it != j.end(); ++it) {
Expand Down Expand Up @@ -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).
*/
auto gdk_window = window.get_window()->gobj();
auto* gdk_window = window.get_window()->gobj();
surface = gdk_wayland_window_get_wl_surface(gdk_window);
configureGlobalOffset(gdk_window_get_width(gdk_window), gdk_window_get_height(gdk_window));

setPassThrough(passthrough_);
}

void waybar::Bar::setVisible(bool value) {
visible = value;
void waybar::Bar::setVisible(bool visible) {
if (auto mode = config.get("mode", {}); mode.isString()) {
setMode(visible ? config["mode"].asString() : MODE_INVISIBLE);
} else {
Expand Down Expand Up @@ -473,7 +472,7 @@ void waybar::Bar::handleSignal(int signal) {

void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
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()) {
for (const auto& name : module_list) {
try {
Expand All @@ -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 class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : "";

auto vertical = (group ? group->getBox().get_orientation() : box_.get_orientation()) ==
Gtk::ORIENTATION_VERTICAL;
auto vertical = (group != nullptr ? group->getBox().get_orientation()
: 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);
module = group_module;
} else {
Expand All @@ -497,7 +496,7 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,

std::shared_ptr<AModule> module_sp(module);
modules_all_.emplace_back(module_sp);
if (group) {
if (group != nullptr) {
group->addWidget(*module);
} else {
if (pos == "modules-left") {
Expand Down
Loading

0 comments on commit 18e67af

Please sign in to comment.