src: clang-tidy
This commit is contained in:
		
							parent
							
								
									9997155617
								
							
						
					
					
						commit
						14c3235c12
					
				|  | @ -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; | ||||
| 
 | ||||
|  | @ -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); | ||||
|  |  | |||
|  | @ -96,14 +96,14 @@ 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; | ||||
|       } | ||||
|  | @ -111,7 +111,7 @@ std::optional<Glib::ustring> getIconName(const std::string& app_identifier, | |||
| 
 | ||||
|     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; | ||||
|       } | ||||
|  |  | |||
|  | @ -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*>(); | ||||
|  | @ -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]; | ||||
|     } | ||||
|  | @ -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]; | ||||
|     } | ||||
|  |  | |||
|  | @ -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) { | ||||
|  | @ -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()); | ||||
|   } | ||||
|  | @ -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); | ||||
|  | @ -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; | ||||
|   } | ||||
| 
 | ||||
|  | @ -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_; } | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										27
									
								
								src/bar.cpp
								
								
								
								
							
							
						
						
									
										27
									
								
								src/bar.cpp
								
								
								
								
							|  | @ -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(); | ||||
|     } | ||||
|   } | ||||
|  | @ -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) { | ||||
|  | @ -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 { | ||||
|  | @ -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 { | ||||
|  | @ -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 { | ||||
|  | @ -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") { | ||||
|  |  | |||
|  | @ -4,6 +4,7 @@ | |||
| #include <spdlog/spdlog.h> | ||||
| 
 | ||||
| #include <iostream> | ||||
| #include <utility> | ||||
| 
 | ||||
| #include "gtkmm/icontheme.h" | ||||
| #include "idle-inhibit-unstable-v1-client-protocol.h" | ||||
|  | @ -11,13 +12,13 @@ | |||
| #include "util/format.hpp" | ||||
| 
 | ||||
| waybar::Client *waybar::Client::inst() { | ||||
|   static auto c = new Client(); | ||||
|   static auto *c = new Client(); | ||||
|   return c; | ||||
| } | ||||
| 
 | ||||
| void waybar::Client::handleGlobal(void *data, struct wl_registry *registry, uint32_t name, | ||||
|                                   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 && | ||||
|       version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { | ||||
|     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, | ||||
|   }; | ||||
|   // 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)); | ||||
|   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*/) { | ||||
|   auto client = waybar::Client::inst(); | ||||
|   auto *client = waybar::Client::inst(); | ||||
|   try { | ||||
|     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) { | ||||
|     std::cerr << e.what() << std::endl; | ||||
|     std::cerr << e.what() << '\n'; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| void waybar::Client::handleOutputName(void *data, struct zxdg_output_v1 * /*xdg_output*/, | ||||
|                                       const char *name) { | ||||
|   auto client = waybar::Client::inst(); | ||||
|   auto *client = waybar::Client::inst(); | ||||
|   try { | ||||
|     auto &output = client->getOutput(data); | ||||
|     output.name = name; | ||||
|   } 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*/, | ||||
|                                              const char *description) { | ||||
|   auto client = waybar::Client::inst(); | ||||
|   auto *client = waybar::Client::inst(); | ||||
|   try { | ||||
|     auto &output = client->getOutput(data); | ||||
|     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; | ||||
|     output.identifier = std::string(description, identifier_length - 1); | ||||
|   } 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) { | ||||
|   auto &output = outputs_.emplace_back(); | ||||
|   output.monitor = monitor; | ||||
|   output.monitor = std::move(monitor); | ||||
|   handleOutput(output); | ||||
| } | ||||
| 
 | ||||
|  | @ -154,15 +155,15 @@ const std::string waybar::Client::getStyle(const std::string &style, | |||
|     std::vector<std::string> search_files; | ||||
|     switch (appearance.value_or(portal->getAppearance())) { | ||||
|       case waybar::Appearance::LIGHT: | ||||
|         search_files.push_back("style-light.css"); | ||||
|         search_files.emplace_back("style-light.css"); | ||||
|         break; | ||||
|       case waybar::Appearance::DARK: | ||||
|         search_files.push_back("style-dark.css"); | ||||
|         search_files.emplace_back("style-dark.css"); | ||||
|         break; | ||||
|       case waybar::Appearance::UNKNOWN: | ||||
|         break; | ||||
|     } | ||||
|     search_files.push_back("style.css"); | ||||
|     search_files.emplace_back("style.css"); | ||||
|     css_file = Config::findConfigPath(search_files); | ||||
|   } else { | ||||
|     css_file = style; | ||||
|  | @ -196,7 +197,7 @@ void waybar::Client::bindInterfaces() { | |||
|   wl_registry_add_listener(registry, ®istry_listener, this); | ||||
|   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"); | ||||
|   } | ||||
| 
 | ||||
|  | @ -233,11 +234,11 @@ int waybar::Client::main(int argc, char *argv[]) { | |||
|     return 1; | ||||
|   } | ||||
|   if (show_help) { | ||||
|     std::cout << cli << std::endl; | ||||
|     std::cout << cli << '\n'; | ||||
|     return 0; | ||||
|   } | ||||
|   if (show_version) { | ||||
|     std::cout << "Waybar v" << VERSION << std::endl; | ||||
|     std::cout << "Waybar v" << VERSION << '\n'; | ||||
|     return 0; | ||||
|   } | ||||
|   if (!log_level.empty()) { | ||||
|  |  | |||
|  | @ -21,10 +21,10 @@ const std::vector<std::string> Config::CONFIG_DIRS = { | |||
| 
 | ||||
| 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; | ||||
| 
 | ||||
|   if (filename != "") { | ||||
|   if (!filename.empty()) { | ||||
|     path = fs::path(base) / fs::path(filename); | ||||
|   } else { | ||||
|     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(1) == name || config_output.substr(1) == identifier) { | ||||
|             return false; | ||||
|           } else { | ||||
|             continue; | ||||
|           } | ||||
| 
 | ||||
|           continue; | ||||
|         } | ||||
|         if (config_output == name || config_output == identifier) { | ||||
|           return true; | ||||
|  | @ -142,7 +142,9 @@ bool isValidOutput(const Json::Value &config, const std::string &name, | |||
|       } | ||||
|     } | ||||
|     return false; | ||||
|   } else if (config["output"].isString()) { | ||||
|   } | ||||
| 
 | ||||
|   if (config["output"].isString()) { | ||||
|     auto config_output = config["output"].asString(); | ||||
|     if (!config_output.empty()) { | ||||
|       if (config_output.substr(0, 1) == "!") { | ||||
|  |  | |||
|  | @ -19,9 +19,9 @@ const Gtk::RevealerTransitionType getPreferredTransitionType(bool is_vertical) { | |||
| 
 | ||||
|   if (is_vertical) { | ||||
|     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, | ||||
|  |  | |||
|  | @ -13,7 +13,8 @@ std::list<pid_t> reap; | |||
| volatile bool reload; | ||||
| 
 | ||||
| void* signalThread(void* args) { | ||||
|   int err, signum; | ||||
|   int err; | ||||
|   int signum; | ||||
|   sigset_t mask; | ||||
|   sigemptyset(&mask); | ||||
|   sigaddset(&mask, SIGCHLD); | ||||
|  | @ -46,7 +47,7 @@ void* signalThread(void* args) { | |||
|   } | ||||
| } | ||||
| 
 | ||||
| void startSignalThread(void) { | ||||
| void startSignalThread() { | ||||
|   int err; | ||||
|   sigset_t mask; | ||||
|   sigemptyset(&mask); | ||||
|  | @ -71,7 +72,7 @@ void startSignalThread(void) { | |||
| 
 | ||||
| int main(int argc, char* argv[]) { | ||||
|   try { | ||||
|     auto client = waybar::Client::inst(); | ||||
|     auto* client = waybar::Client::inst(); | ||||
| 
 | ||||
|     std::signal(SIGUSR1, [](int /*signal*/) { | ||||
|       for (auto& bar : waybar::Client::inst()->bars) { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue