diff --git a/include/AAppIconLabel.hpp b/include/AAppIconLabel.hpp index d09ab14a6..65f930363 100644 --- a/include/AAppIconLabel.hpp +++ b/include/AAppIconLabel.hpp @@ -9,15 +9,16 @@ namespace waybar { class AAppIconLabel : public AIconLabel { public: - AAppIconLabel(const Json::Value &config, const std::string &name, const std::string &id, - const std::string &format, uint16_t interval = 0, bool ellipsize = false, - bool enable_click = false, bool enable_scroll = false); + AAppIconLabel(const Json::Value& config, const std::string& name, const std::string& id, + const std::string& format, std::mutex& reap_mtx, std::list& reap, + uint16_t interval = 0, bool ellipsize = false, bool enable_click = false, + bool enable_scroll = false); virtual ~AAppIconLabel() = default; auto update() -> void override; protected: - void updateAppIconName(const std::string &app_identifier, - const std::string &alternative_app_identifier); + void updateAppIconName(const std::string& app_identifier, + const std::string& alternative_app_identifier); void updateAppIcon(); unsigned app_icon_size_{24}; bool update_app_icon_{true}; diff --git a/include/AIconLabel.hpp b/include/AIconLabel.hpp index 054d031a3..b9d4c5cf3 100644 --- a/include/AIconLabel.hpp +++ b/include/AIconLabel.hpp @@ -9,9 +9,10 @@ namespace waybar { class AIconLabel : public ALabel { public: - AIconLabel(const Json::Value &config, const std::string &name, const std::string &id, - const std::string &format, uint16_t interval = 0, bool ellipsize = false, - bool enable_click = false, bool enable_scroll = false); + AIconLabel(const Json::Value& config, const std::string& name, const std::string& id, + const std::string& format, std::mutex& reap_mtx, std::list& reap, + uint16_t interval = 0, bool ellipsize = false, bool enable_click = false, + bool enable_scroll = false); virtual ~AIconLabel() = default; auto update() -> void override; diff --git a/include/ALabel.hpp b/include/ALabel.hpp index 92fc2e0f9..fbc537e8d 100644 --- a/include/ALabel.hpp +++ b/include/ALabel.hpp @@ -10,13 +10,13 @@ namespace waybar { class ALabel : public AModule { public: - ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format, - uint16_t interval = 0, bool ellipsize = false, bool enable_click = false, - bool enable_scroll = false); + ALabel(const Json::Value&, const std::string&, const std::string&, const std::string& format, + std::mutex& reap_mtx, std::list& reap, uint16_t interval = 0, + bool ellipsize = false, bool enable_click = false, bool enable_scroll = false); virtual ~ALabel() = default; auto update() -> void override; - virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0); - virtual std::string getIcon(uint16_t, const std::vector &alts, uint16_t max = 0); + virtual std::string getIcon(uint16_t, const std::string& alt = "", uint16_t max = 0); + virtual std::string getIcon(uint16_t, const std::vector& alts, uint16_t max = 0); protected: Gtk::Label label_; @@ -25,12 +25,12 @@ class ALabel : public AModule { bool alt_ = false; std::string default_format_; - bool handleToggle(GdkEventButton *const &e) override; + bool handleToggle(GdkEventButton* const& e) override; virtual std::string getState(uint8_t value, bool lesser = false); - std::map submenus_; + std::map submenus_; std::map menuActionsMap_; - static void handleGtkMenuEvent(GtkMenuItem *menuitem, gpointer data); + static void handleGtkMenuEvent(GtkMenuItem* menuitem, gpointer data); }; } // namespace waybar diff --git a/include/AModule.hpp b/include/AModule.hpp index 2fcbfc23d..3bb3b0bba 100644 --- a/include/AModule.hpp +++ b/include/AModule.hpp @@ -12,46 +12,49 @@ namespace waybar { class AModule : public IModule { public: - static constexpr const char *MODULE_CLASS = "module"; + static constexpr const char* MODULE_CLASS = "module"; ~AModule() override; auto update() -> void override; virtual auto refresh(int shouldRefresh) -> void {}; - operator Gtk::Widget &() override; - auto doAction(const std::string &name) -> void override; + operator Gtk::Widget&() override; + auto doAction(const std::string& name) -> void override; /// Emitting on this dispatcher triggers a update() call Glib::Dispatcher dp; bool expandEnabled() const; + std::mutex& reap_mtx; + std::list& reap; + protected: // Don't need to make an object directly // Derived classes are able to use it - AModule(const Json::Value &, const std::string &, const std::string &, bool enable_click = false, - bool enable_scroll = false); + AModule(const Json::Value&, const std::string&, const std::string&, std::mutex& reap_mtx, + std::list& reap, bool enable_click = false, bool enable_scroll = false); enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT }; - SCROLL_DIR getScrollDir(GdkEventScroll *e); + SCROLL_DIR getScrollDir(GdkEventScroll* e); bool tooltipEnabled() const; std::vector pid_children_; const std::string name_; - const Json::Value &config_; + 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); - virtual bool handleMouseLeave(GdkEventCrossing *const &ev); - virtual bool handleScroll(GdkEventScroll *); - virtual bool handleRelease(GdkEventButton *const &ev); - GObject *menu_; + virtual bool handleToggle(GdkEventButton* const& ev); + virtual bool handleMouseEnter(GdkEventCrossing* const& ev); + virtual bool handleMouseLeave(GdkEventCrossing* const& ev); + virtual bool handleScroll(GdkEventScroll*); + virtual bool handleRelease(GdkEventButton* const& ev); + GObject* menu_; private: - bool handleUserEvent(GdkEventButton *const &ev); + bool handleUserEvent(GdkEventButton* const& ev); const bool isTooltip; const bool isExpand; bool hasUserEvents_; diff --git a/include/ASlider.hpp b/include/ASlider.hpp index 44cde5077..658802fa0 100644 --- a/include/ASlider.hpp +++ b/include/ASlider.hpp @@ -7,7 +7,8 @@ namespace waybar { class ASlider : public AModule { public: - ASlider(const Json::Value& config, const std::string& name, const std::string& id); + ASlider(const Json::Value& config, const std::string& name, const std::string& id, + std::mutex& reap_mtx, std::list& reap); virtual void onValueChanged(); protected: @@ -16,4 +17,4 @@ class ASlider : public AModule { Gtk::Scale scale_; }; -} // namespace waybar \ No newline at end of file +} // namespace waybar diff --git a/include/IModule.hpp b/include/IModule.hpp index b76c33e3a..5974f9e2c 100644 --- a/include/IModule.hpp +++ b/include/IModule.hpp @@ -1,6 +1,10 @@ #pragma once #include +#include + +#include +#include namespace waybar { diff --git a/include/bar.hpp b/include/bar.hpp index 9953b1f51..54b332bfd 100644 --- a/include/bar.hpp +++ b/include/bar.hpp @@ -62,11 +62,11 @@ class Bar : public sigc::trackable { static const std::string MODE_DEFAULT; static const std::string MODE_INVISIBLE; - Bar(struct waybar_output *w_output, const Json::Value &); - Bar(const Bar &) = delete; + Bar(struct waybar_output* w_output, const Json::Value&); + Bar(const Bar&) = delete; ~Bar(); - void setMode(const std::string &mode); + void setMode(const std::string& mode); void setVisible(bool value); void toggle(); void show(); @@ -75,9 +75,9 @@ class Bar : public sigc::trackable { util::KillSignalAction getOnSigusr1Action(); util::KillSignalAction getOnSigusr2Action(); - struct waybar_output *output; + struct waybar_output* output; Json::Value config; - struct wl_surface *surface; + struct wl_surface* surface; bool visible = true; Gtk::Window window; Gtk::Orientation orientation = Gtk::ORIENTATION_HORIZONTAL; @@ -91,15 +91,15 @@ class Bar : public sigc::trackable { #endif private: - void onMap(GdkEventAny *); + void onMap(GdkEventAny*); auto setupWidgets() -> void; - void getModules(const Factory &, const std::string &, waybar::Group *); - void setupAltFormatKeyForModule(const std::string &module_name); - void setupAltFormatKeyForModuleList(const char *module_list_name); - void setMode(const bar_mode &); + void getModules(const Factory&, const std::string&, waybar::Group*); + void setupAltFormatKeyForModule(const std::string& module_name); + void setupAltFormatKeyForModuleList(const char* module_list_name); + void setMode(const bar_mode&); void setPassThrough(bool passthrough); void setPosition(Gtk::PositionType position); - void onConfigure(GdkEventConfigure *ev); + void onConfigure(GdkEventConfigure* ev); void configureGlobalOffset(int width, int height); void onOutputGeometryChanged(); diff --git a/include/client.hpp b/include/client.hpp index 9dd093554..c3df3f218 100644 --- a/include/client.hpp +++ b/include/client.hpp @@ -17,35 +17,35 @@ namespace waybar { class Client { public: - static Client *inst(); - int main(int argc, char *argv[]); + static Client* inst(); + int main(int argc, char* argv[]); void reset(); Glib::RefPtr gtk_app; Glib::RefPtr gdk_display; - struct wl_display *wl_display = nullptr; - struct wl_registry *registry = nullptr; - struct zxdg_output_manager_v1 *xdg_output_manager = nullptr; - struct zwp_idle_inhibit_manager_v1 *idle_inhibit_manager = nullptr; + struct wl_display* wl_display = nullptr; + struct wl_registry* registry = nullptr; + struct zxdg_output_manager_v1* xdg_output_manager = nullptr; + struct zwp_idle_inhibit_manager_v1* idle_inhibit_manager = nullptr; std::vector> bars; Config config; std::string bar_id; private: Client() = default; - const std::string getStyle(const std::string &style, std::optional appearance); + const std::string getStyle(const std::string& style, std::optional appearance); void bindInterfaces(); - void handleOutput(struct waybar_output &output); - auto setupCss(const std::string &css_file) -> void; - struct waybar_output &getOutput(void *); - std::vector getOutputConfigs(struct waybar_output &output); - - static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version); - static void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name); - static void handleOutputDone(void *, struct zxdg_output_v1 *); - static void handleOutputName(void *, struct zxdg_output_v1 *, const char *); - static void handleOutputDescription(void *, struct zxdg_output_v1 *, const char *); + void handleOutput(struct waybar_output& output); + auto setupCss(const std::string& css_file) -> void; + struct waybar_output& getOutput(void*); + std::vector getOutputConfigs(struct waybar_output& output); + + static void handleGlobal(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version); + static void handleGlobalRemove(void* data, struct wl_registry* registry, uint32_t name); + static void handleOutputDone(void*, struct zxdg_output_v1*); + static void handleOutputName(void*, struct zxdg_output_v1*, const char*); + static void handleOutputDescription(void*, struct zxdg_output_v1*, const char*); void handleMonitorAdded(Glib::RefPtr monitor); void handleMonitorRemoved(Glib::RefPtr monitor); void handleDeferredMonitorRemoval(Glib::RefPtr monitor); diff --git a/include/config.hpp b/include/config.hpp index bf653c2a0..1ef9ef5fd 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -14,29 +14,29 @@ namespace waybar { class Config { public: static const std::vector CONFIG_DIRS; - static const char *CONFIG_PATH_ENV; + static const char* CONFIG_PATH_ENV; /* Try to find any of provided names in the supported set of config directories */ static std::optional findConfigPath( - const std::vector &names, const std::vector &dirs = CONFIG_DIRS); + const std::vector& names, const std::vector& dirs = CONFIG_DIRS); - static std::vector tryExpandPath(const std::string &base, - const std::string &filename); + static std::vector tryExpandPath(const std::string& base, + const std::string& filename); Config() = default; - void load(const std::string &config); + void load(const std::string& config); - Json::Value &getConfig() { return config_; } + Json::Value& getConfig() { return config_; } - std::vector getOutputConfigs(const std::string &name, const std::string &identifier); + std::vector getOutputConfigs(const std::string& name, const std::string& identifier); private: - void setupConfig(Json::Value &dst, const std::string &config_file, int depth); - void resolveConfigIncludes(Json::Value &config, int depth); - void mergeConfig(Json::Value &a_config_, Json::Value &b_config_); + void setupConfig(Json::Value& dst, const std::string& config_file, int depth); + void resolveConfigIncludes(Json::Value& config, int depth); + void mergeConfig(Json::Value& a_config_, Json::Value& b_config_); static std::vector findIncludePath( - const std::string &name, const std::vector &dirs = CONFIG_DIRS); + const std::string& name, const std::vector& dirs = CONFIG_DIRS); std::string config_file_; diff --git a/include/factory.hpp b/include/factory.hpp index f805aab5e..5563f4132 100644 --- a/include/factory.hpp +++ b/include/factory.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include #include diff --git a/include/group.hpp b/include/group.hpp index 5ce331a8d..41cb5ee0b 100644 --- a/include/group.hpp +++ b/include/group.hpp @@ -11,13 +11,13 @@ namespace waybar { class Group : public AModule { public: - Group(const std::string &, const std::string &, const Json::Value &, bool); + Group(const std::string&, const std::string&, const Json::Value&, bool); ~Group() override = default; auto update() -> void override; - operator Gtk::Widget &() override; + operator Gtk::Widget&() override; - virtual Gtk::Box &getBox(); - void addWidget(Gtk::Widget &widget); + virtual Gtk::Box& getBox(); + void addWidget(Gtk::Widget& widget); protected: Gtk::Box box; @@ -27,9 +27,9 @@ class Group : public AModule { bool is_drawer = false; bool click_to_reveal = false; std::string add_class_to_drawer_children; - bool handleMouseEnter(GdkEventCrossing *const &ev) override; - bool handleMouseLeave(GdkEventCrossing *const &ev) override; - bool handleToggle(GdkEventButton *const &ev) override; + bool handleMouseEnter(GdkEventCrossing* const& ev) override; + bool handleMouseLeave(GdkEventCrossing* const& ev) override; + bool handleToggle(GdkEventButton* const& ev) override; void show_group(); void hide_group(); }; diff --git a/include/modules/backlight.hpp b/include/modules/backlight.hpp index 110cd434b..8b44ffb6a 100644 --- a/include/modules/backlight.hpp +++ b/include/modules/backlight.hpp @@ -17,11 +17,11 @@ namespace waybar::modules { class Backlight : public ALabel { public: - Backlight(const std::string &, const Json::Value &); + Backlight(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Backlight() = default; auto update() -> void override; - bool handleScroll(GdkEventScroll *e) override; + bool handleScroll(GdkEventScroll* e) override; const std::string preferred_device_; diff --git a/include/modules/backlight_slider.hpp b/include/modules/backlight_slider.hpp index 437c53c45..97983603b 100644 --- a/include/modules/backlight_slider.hpp +++ b/include/modules/backlight_slider.hpp @@ -9,7 +9,7 @@ namespace waybar::modules { class BacklightSlider : public ASlider { public: - BacklightSlider(const std::string&, const Json::Value&); + BacklightSlider(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~BacklightSlider() = default; void update() override; @@ -21,4 +21,4 @@ class BacklightSlider : public ASlider { util::BacklightBackend backend; }; -} // namespace waybar::modules \ No newline at end of file +} // namespace waybar::modules diff --git a/include/modules/battery.hpp b/include/modules/battery.hpp index ffc82abae..58e5b24cd 100644 --- a/include/modules/battery.hpp +++ b/include/modules/battery.hpp @@ -24,7 +24,8 @@ namespace fs = std::filesystem; class Battery : public ALabel { public: - Battery(const std::string&, const waybar::Bar&, const Json::Value&); + Battery(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~Battery(); auto update() -> void override; diff --git a/include/modules/bluetooth.hpp b/include/modules/bluetooth.hpp index b89383a04..31ae19779 100644 --- a/include/modules/bluetooth.hpp +++ b/include/modules/bluetooth.hpp @@ -44,7 +44,7 @@ class Bluetooth : public ALabel { }; public: - Bluetooth(const std::string&, const Json::Value&); + Bluetooth(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Bluetooth() = default; auto update() -> void override; diff --git a/include/modules/cava/cavaGLSL.hpp b/include/modules/cava/cavaGLSL.hpp index d2632affa..994a6d87b 100644 --- a/include/modules/cava/cavaGLSL.hpp +++ b/include/modules/cava/cavaGLSL.hpp @@ -9,7 +9,7 @@ namespace waybar::modules::cava { class CavaGLSL final : public AModule, public Gtk::GLArea { public: - CavaGLSL(const std::string&, const Json::Value&); + CavaGLSL(const std::string&, const Json::Value&, std::mutex&, std::list&); ~CavaGLSL() = default; private: diff --git a/include/modules/cava/cavaRaw.hpp b/include/modules/cava/cavaRaw.hpp index f4ceb603d..5e2ee3519 100644 --- a/include/modules/cava/cavaRaw.hpp +++ b/include/modules/cava/cavaRaw.hpp @@ -7,7 +7,7 @@ namespace waybar::modules::cava { class Cava final : public ALabel, public sigc::trackable { public: - Cava(const std::string&, const Json::Value&); + Cava(const std::string&, const Json::Value&, std::mutex&, std::list&); ~Cava() = default; auto doAction(const std::string& name) -> void override; diff --git a/include/modules/cava/cava_frontend.hpp b/include/modules/cava/cava_frontend.hpp deleted file mode 100644 index 5a73f62fd..000000000 --- a/include/modules/cava/cava_frontend.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once - -#ifdef HAVE_LIBCAVA -#include "cavaRaw.hpp" -#include "cava_backend.hpp" -#ifdef HAVE_LIBCAVAGLSL -#include "cavaGLSL.hpp" -#endif -#endif - -namespace waybar::modules::cava { -AModule* getModule(const std::string& id, const Json::Value& config) { -#ifdef HAVE_LIBCAVA - const std::shared_ptr backend_{waybar::modules::cava::CavaBackend::inst(config)}; - switch (backend_->getPrm()->output) { - case ::cava::output_method::OUTPUT_RAW: - return new waybar::modules::cava::Cava(id, config); - break; -#ifdef HAVE_LIBCAVAGLSL - case ::cava::output_method::OUTPUT_SDL_GLSL: - return new waybar::modules::cava::CavaGLSL(id, config); - break; -#endif - default: - break; - } -#endif - throw std::runtime_error("Unknown module"); -}; -} // namespace waybar::modules::cava diff --git a/include/modules/cffi.hpp b/include/modules/cffi.hpp index 85f129896..f56c04948 100644 --- a/include/modules/cffi.hpp +++ b/include/modules/cffi.hpp @@ -29,7 +29,7 @@ struct wbcffi_config_entry { class CFFI : public AModule { public: - CFFI(const std::string&, const std::string&, const Json::Value&); + CFFI(const std::string&, const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~CFFI(); virtual auto refresh(int signal) -> void override; diff --git a/include/modules/clock.hpp b/include/modules/clock.hpp index c35480634..a9de4e73e 100644 --- a/include/modules/clock.hpp +++ b/include/modules/clock.hpp @@ -15,7 +15,7 @@ enum class WS { LEFT, RIGHT, HIDDEN }; class Clock final : public ALabel { public: - Clock(const std::string&, const Json::Value&); + Clock(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Clock() = default; auto update() -> void override; auto doAction(const std::string&) -> void override; diff --git a/include/modules/cpu.hpp b/include/modules/cpu.hpp index 7f78c1650..16ff67785 100644 --- a/include/modules/cpu.hpp +++ b/include/modules/cpu.hpp @@ -16,7 +16,7 @@ namespace waybar::modules { class Cpu : public ALabel { public: - Cpu(const std::string&, const Json::Value&); + Cpu(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Cpu() = default; auto update() -> void override; diff --git a/include/modules/cpu_frequency.hpp b/include/modules/cpu_frequency.hpp index 49ca1b86a..831665d98 100644 --- a/include/modules/cpu_frequency.hpp +++ b/include/modules/cpu_frequency.hpp @@ -16,7 +16,7 @@ namespace waybar::modules { class CpuFrequency : public ALabel { public: - CpuFrequency(const std::string&, const Json::Value&); + CpuFrequency(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~CpuFrequency() = default; auto update() -> void override; diff --git a/include/modules/cpu_usage.hpp b/include/modules/cpu_usage.hpp index c93a1734f..c28b6aab3 100644 --- a/include/modules/cpu_usage.hpp +++ b/include/modules/cpu_usage.hpp @@ -16,7 +16,7 @@ namespace waybar::modules { class CpuUsage : public ALabel { public: - CpuUsage(const std::string&, const Json::Value&); + CpuUsage(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~CpuUsage() = default; auto update() -> void override; diff --git a/include/modules/custom.hpp b/include/modules/custom.hpp index 6c17c6e45..1ee93879a 100644 --- a/include/modules/custom.hpp +++ b/include/modules/custom.hpp @@ -14,7 +14,8 @@ namespace waybar::modules { class Custom : public ALabel { public: - Custom(const std::string&, const std::string&, const Json::Value&, const std::string&); + Custom(const std::string&, const std::string&, const Json::Value&, const std::string&, + std::mutex&, std::list&); virtual ~Custom(); auto update() -> void override; void refresh(int /*signal*/) override; diff --git a/include/modules/disk.hpp b/include/modules/disk.hpp index 1b4f31761..fe5ac738e 100644 --- a/include/modules/disk.hpp +++ b/include/modules/disk.hpp @@ -13,7 +13,7 @@ namespace waybar::modules { class Disk : public ALabel { public: - Disk(const std::string&, const Json::Value&); + Disk(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Disk() = default; auto update() -> void override; diff --git a/include/modules/dwl/tags.hpp b/include/modules/dwl/tags.hpp index 53dff9899..73bfd3b3a 100644 --- a/include/modules/dwl/tags.hpp +++ b/include/modules/dwl/tags.hpp @@ -12,23 +12,23 @@ namespace waybar::modules::dwl { class Tags : public waybar::AModule { public: - Tags(const std::string &, const waybar::Bar &, const Json::Value &); + Tags(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, std::list&); virtual ~Tags(); // Handlers for wayland events void handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused); void handle_primary_clicked(uint32_t tag); - bool handle_button_press(GdkEventButton *event_button, uint32_t tag); + bool handle_button_press(GdkEventButton* event_button, uint32_t tag); - struct zdwl_ipc_manager_v2 *status_manager_; - struct wl_seat *seat_; + struct zdwl_ipc_manager_v2* status_manager_; + struct wl_seat* seat_; private: - const waybar::Bar &bar_; + const waybar::Bar& bar_; Gtk::Box box_; std::vector buttons_; - struct zdwl_ipc_output_v2 *output_status_; + struct zdwl_ipc_output_v2* output_status_; }; } /* namespace waybar::modules::dwl */ diff --git a/include/modules/dwl/window.hpp b/include/modules/dwl/window.hpp index 435863999..58923e636 100644 --- a/include/modules/dwl/window.hpp +++ b/include/modules/dwl/window.hpp @@ -13,26 +13,27 @@ namespace waybar::modules::dwl { class Window : public AAppIconLabel, public sigc::trackable { public: - Window(const std::string &, const waybar::Bar &, const Json::Value &); + Window(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); ~Window(); void handle_layout(const uint32_t layout); - void handle_title(const char *title); - void handle_appid(const char *ppid); - void handle_layout_symbol(const char *layout_symbol); + void handle_title(const char* title); + void handle_appid(const char* ppid); + void handle_layout_symbol(const char* layout_symbol); void handle_frame(); - struct zdwl_ipc_manager_v2 *status_manager_; + struct zdwl_ipc_manager_v2* status_manager_; private: - const Bar &bar_; + const Bar& bar_; std::string title_; std::string appid_; std::string layout_symbol_; uint32_t layout_; - struct zdwl_ipc_output_v2 *output_status_; + struct zdwl_ipc_output_v2* output_status_; }; } // namespace waybar::modules::dwl diff --git a/include/modules/ext/workspace_manager.hpp b/include/modules/ext/workspace_manager.hpp index 686c7fc73..2e57b390d 100644 --- a/include/modules/ext/workspace_manager.hpp +++ b/include/modules/ext/workspace_manager.hpp @@ -20,16 +20,17 @@ class Workspace; class WorkspaceManager final : public AModule { public: - WorkspaceManager(const std::string &id, const waybar::Bar &bar, const Json::Value &config); + WorkspaceManager(const std::string& id, const waybar::Bar& bar, const Json::Value& config, + std::mutex&, std::list&); ~WorkspaceManager() override; - void register_manager(wl_registry *registry, uint32_t name, uint32_t version); + void register_manager(wl_registry* registry, uint32_t name, uint32_t version); void remove_workspace_group(uint32_t id); void remove_workspace(uint32_t id); void set_needs_sorting() { needs_sorting_ = true; } // wl events - void handle_workspace_group(ext_workspace_group_handle_v1 *handle); - void handle_workspace(ext_workspace_handle_v1 *handle); + void handle_workspace_group(ext_workspace_group_handle_v1* handle); + void handle_workspace(ext_workspace_handle_v1* handle); void handle_done(); void handle_finished(); @@ -38,7 +39,7 @@ class WorkspaceManager final : public AModule { private: void update() override; - bool has_button(const Gtk::Button *button); + bool has_button(const Gtk::Button* button); void sort_workspaces(); void clear_buttons(); void update_buttons(); @@ -52,10 +53,10 @@ class WorkspaceManager final : public AModule { bool sort_by_coordinates_ = false; bool all_outputs_ = false; - const waybar::Bar &bar_; + const waybar::Bar& bar_; Gtk::Box box_; - ext_workspace_manager_v1 *ext_manager_ = nullptr; + ext_workspace_manager_v1* ext_manager_ = nullptr; std::vector> groups_; std::vector> workspaces_; @@ -64,60 +65,60 @@ class WorkspaceManager final : public AModule { class WorkspaceGroup { public: - WorkspaceGroup(WorkspaceManager &manager, ext_workspace_group_handle_v1 *handle, uint32_t id); + WorkspaceGroup(WorkspaceManager& manager, ext_workspace_group_handle_v1* handle, uint32_t id); ~WorkspaceGroup(); u_int32_t id() const { return id_; } - bool has_output(const wl_output *output); - bool has_workspace(const ext_workspace_handle_v1 *workspace); + bool has_output(const wl_output* output); + bool has_workspace(const ext_workspace_handle_v1* workspace); // wl events void handle_capabilities(uint32_t capabilities); - void handle_output_enter(wl_output *output); - void handle_output_leave(wl_output *output); - void handle_workspace_enter(ext_workspace_handle_v1 *handle); - void handle_workspace_leave(ext_workspace_handle_v1 *handle); + void handle_output_enter(wl_output* output); + void handle_output_leave(wl_output* output); + void handle_workspace_enter(ext_workspace_handle_v1* handle); + void handle_workspace_leave(ext_workspace_handle_v1* handle); void handle_removed(); private: - WorkspaceManager &workspaces_manager_; - ext_workspace_group_handle_v1 *ext_handle_; + WorkspaceManager& workspaces_manager_; + ext_workspace_group_handle_v1* ext_handle_; uint32_t id_; - std::vector outputs_; - std::vector workspaces_; + std::vector outputs_; + std::vector workspaces_; }; class Workspace { public: - Workspace(const Json::Value &config, WorkspaceManager &manager, ext_workspace_handle_v1 *handle, - uint32_t id, const std::string &name); + Workspace(const Json::Value& config, WorkspaceManager& manager, ext_workspace_handle_v1* handle, + uint32_t id, const std::string& name); ~Workspace(); - ext_workspace_handle_v1 *handle() const { return ext_handle_; } + ext_workspace_handle_v1* handle() const { return ext_handle_; } u_int32_t id() const { return id_; } - std::string &workspace_id() { return workspace_id_; } - std::string &name() { return name_; } - std::vector &coordinates() { return coordinates_; } - Gtk::Button &button() { return button_; } + std::string& workspace_id() { return workspace_id_; } + std::string& name() { return name_; } + std::vector& coordinates() { return coordinates_; } + Gtk::Button& button() { return button_; } void update(); // wl events - void handle_id(const std::string &id); - void handle_name(const std::string &name); - void handle_coordinates(const std::vector &coordinates); + void handle_id(const std::string& id); + void handle_name(const std::string& name); + void handle_coordinates(const std::vector& coordinates); void handle_state(uint32_t state); void handle_capabilities(uint32_t capabilities); void handle_removed(); // gdk events - bool handle_clicked(const GdkEventButton *button) const; + bool handle_clicked(const GdkEventButton* button) const; private: bool has_state(uint32_t state) const { return (state_ & state) == state; } std::string icon(); - WorkspaceManager &workspace_manager_; - ext_workspace_handle_v1 *ext_handle_ = nullptr; + WorkspaceManager& workspace_manager_; + ext_workspace_handle_v1* ext_handle_ = nullptr; uint32_t id_; uint32_t state_ = 0; std::string workspace_id_; diff --git a/include/modules/ext/workspace_manager_binding.hpp b/include/modules/ext/workspace_manager_binding.hpp index b41f207c7..202329706 100644 --- a/include/modules/ext/workspace_manager_binding.hpp +++ b/include/modules/ext/workspace_manager_binding.hpp @@ -1,10 +1,10 @@ #include "ext-workspace-v1-client-protocol.h" namespace waybar::modules::ext { -void add_registry_listener(void *data); -void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data); -void add_workspace_group_listener(ext_workspace_group_handle_v1 *workspace_group_handle, - void *data); -ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name, - uint32_t version, void *data); +void add_registry_listener(void* data); +void add_workspace_listener(ext_workspace_handle_v1* workspace_handle, void* data); +void add_workspace_group_listener(ext_workspace_group_handle_v1* workspace_group_handle, + void* data); +ext_workspace_manager_v1* workspace_manager_bind(wl_registry* registry, uint32_t name, + uint32_t version, void* data); } // namespace waybar::modules::ext diff --git a/include/modules/gamemode.hpp b/include/modules/gamemode.hpp index 69c0c3aeb..d24a74e07 100644 --- a/include/modules/gamemode.hpp +++ b/include/modules/gamemode.hpp @@ -17,7 +17,7 @@ namespace waybar::modules { class Gamemode : public AModule { public: - Gamemode(const std::string &, const Json::Value &); + Gamemode(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Gamemode(); auto update() -> void override; @@ -28,18 +28,18 @@ class Gamemode : public AModule { const std::string DEFAULT_TOOLTIP_FORMAT = "Games running: {count}"; const std::string DEFAULT_GLYPH = ""; - void appear(const Glib::RefPtr &connection, const Glib::ustring &name, - const Glib::ustring &name_owner); - void disappear(const Glib::RefPtr &connection, const Glib::ustring &name); - void prepareForSleep_cb(const Glib::RefPtr &connection, - const Glib::ustring &sender_name, const Glib::ustring &object_path, - const Glib::ustring &interface_name, const Glib::ustring &signal_name, - const Glib::VariantContainerBase ¶meters); - void notify_cb(const Glib::ustring &sender_name, const Glib::ustring &signal_name, - const Glib::VariantContainerBase &arguments); + void appear(const Glib::RefPtr& connection, const Glib::ustring& name, + const Glib::ustring& name_owner); + void disappear(const Glib::RefPtr& connection, const Glib::ustring& name); + void prepareForSleep_cb(const Glib::RefPtr& connection, + const Glib::ustring& sender_name, const Glib::ustring& object_path, + const Glib::ustring& interface_name, const Glib::ustring& signal_name, + const Glib::VariantContainerBase& parameters); + void notify_cb(const Glib::ustring& sender_name, const Glib::ustring& signal_name, + const Glib::VariantContainerBase& arguments); void getData(); - bool handleToggle(GdkEventButton *const &) override; + bool handleToggle(GdkEventButton* const&) override; // Config std::string format = DEFAULT_FORMAT; diff --git a/include/modules/gps.hpp b/include/modules/gps.hpp index 80df12ba9..9c5519f1d 100644 --- a/include/modules/gps.hpp +++ b/include/modules/gps.hpp @@ -16,7 +16,7 @@ namespace waybar::modules { class Gps : public ALabel { public: - Gps(const std::string&, const Json::Value&); + Gps(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Gps(); auto update() -> void override; diff --git a/include/modules/hyprland/language.hpp b/include/modules/hyprland/language.hpp index ec59e5c3a..1acc01b23 100644 --- a/include/modules/hyprland/language.hpp +++ b/include/modules/hyprland/language.hpp @@ -13,7 +13,8 @@ namespace waybar::modules::hyprland { class Language : public waybar::ALabel, public EventHandler { public: - Language(const std::string&, const waybar::Bar&, const Json::Value&); + Language(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~Language(); auto update() -> void override; diff --git a/include/modules/hyprland/submap.hpp b/include/modules/hyprland/submap.hpp index 7e3425ef7..e2597f812 100644 --- a/include/modules/hyprland/submap.hpp +++ b/include/modules/hyprland/submap.hpp @@ -13,7 +13,8 @@ namespace waybar::modules::hyprland { class Submap : public waybar::ALabel, public EventHandler { public: - Submap(const std::string&, const waybar::Bar&, const Json::Value&); + Submap(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); ~Submap() override; auto update() -> void override; diff --git a/include/modules/hyprland/window.hpp b/include/modules/hyprland/window.hpp index 2be645942..d43c4cc6e 100644 --- a/include/modules/hyprland/window.hpp +++ b/include/modules/hyprland/window.hpp @@ -13,7 +13,8 @@ namespace waybar::modules::hyprland { class Window : public waybar::AAppIconLabel, public EventHandler { public: - Window(const std::string&, const waybar::Bar&, const Json::Value&); + Window(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); ~Window() override; auto update() -> void override; diff --git a/include/modules/hyprland/windowcount.hpp b/include/modules/hyprland/windowcount.hpp index 7c86fb3ec..aa63fab2d 100644 --- a/include/modules/hyprland/windowcount.hpp +++ b/include/modules/hyprland/windowcount.hpp @@ -12,7 +12,8 @@ namespace waybar::modules::hyprland { class WindowCount : public waybar::AAppIconLabel, public EventHandler { public: - WindowCount(const std::string&, const waybar::Bar&, const Json::Value&); + WindowCount(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); ~WindowCount() override; auto update() -> void override; diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index a5d94bbf7..16867ac60 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -30,7 +30,8 @@ class Workspaces; class Workspaces : public AModule, public EventHandler { public: - Workspaces(const std::string&, const waybar::Bar&, const Json::Value&); + Workspaces(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); ~Workspaces() override; void update() override; void init(); diff --git a/include/modules/idle_inhibitor.hpp b/include/modules/idle_inhibitor.hpp index 22bd808fc..56cc2da09 100644 --- a/include/modules/idle_inhibitor.hpp +++ b/include/modules/idle_inhibitor.hpp @@ -12,7 +12,8 @@ class IdleInhibitor : public ALabel { sigc::connection timeout_; public: - IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&); + IdleInhibitor(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~IdleInhibitor(); auto update() -> void override; static std::list modules; diff --git a/include/modules/image.hpp b/include/modules/image.hpp index 510dad940..ee2570f14 100644 --- a/include/modules/image.hpp +++ b/include/modules/image.hpp @@ -16,7 +16,7 @@ namespace waybar::modules { class Image : public AModule { public: - Image(const std::string&, const Json::Value&); + Image(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Image() = default; auto update() -> void override; void refresh(int /*signal*/) override; diff --git a/include/modules/inhibitor.hpp b/include/modules/inhibitor.hpp index 43cb6cab1..109439b68 100644 --- a/include/modules/inhibitor.hpp +++ b/include/modules/inhibitor.hpp @@ -11,7 +11,8 @@ namespace waybar::modules { class Inhibitor : public ALabel { public: - Inhibitor(const std::string&, const waybar::Bar&, const Json::Value&); + Inhibitor(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~Inhibitor(); auto update() -> void override; auto activated() -> bool; diff --git a/include/modules/jack.hpp b/include/modules/jack.hpp index 452c43a3b..20459e011 100644 --- a/include/modules/jack.hpp +++ b/include/modules/jack.hpp @@ -13,7 +13,7 @@ namespace waybar::modules { class JACK : public ALabel { public: - JACK(const std::string &, const Json::Value &); + JACK(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~JACK() = default; auto update() -> void override; @@ -25,7 +25,7 @@ class JACK : public ALabel { private: std::string JACKState(); - jack_client_t *client_; + jack_client_t* client_; jack_nframes_t bufsize_; jack_nframes_t samplerate_; unsigned int xruns_; @@ -38,7 +38,7 @@ class JACK : public ALabel { } // namespace waybar::modules -int bufSizeCallback(jack_nframes_t size, void *obj); -int sampleRateCallback(jack_nframes_t rate, void *obj); -int xrunCallback(void *obj); -void shutdownCallback(void *obj); +int bufSizeCallback(jack_nframes_t size, void* obj); +int sampleRateCallback(jack_nframes_t rate, void* obj); +int xrunCallback(void* obj); +void shutdownCallback(void* obj); diff --git a/include/modules/keyboard_state.hpp b/include/modules/keyboard_state.hpp index be90eee4d..58f46a95d 100644 --- a/include/modules/keyboard_state.hpp +++ b/include/modules/keyboard_state.hpp @@ -19,7 +19,8 @@ namespace waybar::modules { class KeyboardState : public AModule { public: - KeyboardState(const std::string&, const waybar::Bar&, const Json::Value&); + KeyboardState(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~KeyboardState(); auto update() -> void override; diff --git a/include/modules/load.hpp b/include/modules/load.hpp index c4c06d264..a8dcad4c2 100644 --- a/include/modules/load.hpp +++ b/include/modules/load.hpp @@ -16,7 +16,7 @@ namespace waybar::modules { class Load : public ALabel { public: - Load(const std::string&, const Json::Value&); + Load(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Load() = default; auto update() -> void override; diff --git a/include/modules/memory.hpp b/include/modules/memory.hpp index 3b6342b34..9fe195a08 100644 --- a/include/modules/memory.hpp +++ b/include/modules/memory.hpp @@ -12,7 +12,7 @@ namespace waybar::modules { class Memory : public ALabel { public: - Memory(const std::string&, const Json::Value&); + Memory(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Memory() = default; auto update() -> void override; diff --git a/include/modules/mpd/mpd.hpp b/include/modules/mpd/mpd.hpp index 32d526e93..b71741893 100644 --- a/include/modules/mpd/mpd.hpp +++ b/include/modules/mpd/mpd.hpp @@ -35,7 +35,7 @@ class MPD : public ALabel { detail::unique_song song_; public: - MPD(const std::string&, const Json::Value&); + MPD(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~MPD() noexcept = default; auto update() -> void override; diff --git a/include/modules/mpris/mpris.hpp b/include/modules/mpris/mpris.hpp index ad4dac1e1..123b6c87c 100644 --- a/include/modules/mpris/mpris.hpp +++ b/include/modules/mpris/mpris.hpp @@ -18,7 +18,7 @@ namespace waybar::modules::mpris { class Mpris : public ALabel { public: - Mpris(const std::string&, const Json::Value&); + Mpris(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Mpris(); auto update() -> void override; bool handleToggle(GdkEventButton* const&) override; diff --git a/include/modules/network.hpp b/include/modules/network.hpp index 4abe26bd1..1d7918eed 100644 --- a/include/modules/network.hpp +++ b/include/modules/network.hpp @@ -23,7 +23,7 @@ namespace waybar::modules { class Network : public ALabel { public: - Network(const std::string&, const Json::Value&); + Network(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Network(); auto update() -> void override; diff --git a/include/modules/niri/language.hpp b/include/modules/niri/language.hpp index 77f0a6246..e9f2ec4e3 100644 --- a/include/modules/niri/language.hpp +++ b/include/modules/niri/language.hpp @@ -10,13 +10,13 @@ namespace waybar::modules::niri { class Language : public ALabel, public EventHandler { public: - Language(const std::string &, const Bar &, const Json::Value &); + Language(const std::string&, const Bar&, const Json::Value&, std::mutex&, std::list&); ~Language() override; void update() override; private: void updateFromIPC(); - void onEvent(const Json::Value &ev) override; + void onEvent(const Json::Value& ev) override; void doUpdate(); struct Layout { @@ -26,10 +26,10 @@ class Language : public ALabel, public EventHandler { std::string short_description; }; - static Layout getLayout(const std::string &fullName); + static Layout getLayout(const std::string& fullName); std::mutex mutex_; - const Bar &bar_; + const Bar& bar_; std::vector layouts_; unsigned current_idx_; diff --git a/include/modules/niri/window.hpp b/include/modules/niri/window.hpp index 909ae6f0e..a2326cf3f 100644 --- a/include/modules/niri/window.hpp +++ b/include/modules/niri/window.hpp @@ -11,16 +11,16 @@ namespace waybar::modules::niri { class Window : public AAppIconLabel, public EventHandler { public: - Window(const std::string &, const Bar &, const Json::Value &); + Window(const std::string&, const Bar&, const Json::Value&, std::mutex&, std::list&); ~Window() override; void update() override; private: - void onEvent(const Json::Value &ev) override; + void onEvent(const Json::Value& ev) override; void doUpdate(); - void setClass(const std::string &className, bool enable); + void setClass(const std::string& className, bool enable); - const Bar &bar_; + const Bar& bar_; std::string oldAppId_; }; diff --git a/include/modules/niri/workspaces.hpp b/include/modules/niri/workspaces.hpp index a6850ed10..1e139fbc2 100644 --- a/include/modules/niri/workspaces.hpp +++ b/include/modules/niri/workspaces.hpp @@ -11,17 +11,17 @@ namespace waybar::modules::niri { class Workspaces : public AModule, public EventHandler { public: - Workspaces(const std::string &, const Bar &, const Json::Value &); + Workspaces(const std::string&, const Bar&, const Json::Value&, std::mutex&, std::list&); ~Workspaces() override; void update() override; private: - void onEvent(const Json::Value &ev) override; + void onEvent(const Json::Value& ev) override; void doUpdate(); - Gtk::Button &addButton(const Json::Value &ws); - std::string getIcon(const std::string &value, const Json::Value &ws); + Gtk::Button& addButton(const Json::Value& ws); + std::string getIcon(const std::string& value, const Json::Value& ws); - const Bar &bar_; + const Bar& bar_; Gtk::Box box_; // Map from niri workspace id to button. std::unordered_map buttons_; diff --git a/include/modules/power_profiles_daemon.hpp b/include/modules/power_profiles_daemon.hpp index a2bd38587..ff40053b7 100644 --- a/include/modules/power_profiles_daemon.hpp +++ b/include/modules/power_profiles_daemon.hpp @@ -16,15 +16,15 @@ struct Profile { class PowerProfilesDaemon : public ALabel { public: - PowerProfilesDaemon(const std::string &, const Json::Value &); + PowerProfilesDaemon(const std::string&, const Json::Value&, std::mutex&, std::list&); auto update() -> void override; - void profileChangedCb(const Gio::DBus::Proxy::MapChangedProperties &, - const std::vector &); - void busConnectedCb(Glib::RefPtr &r); - void getAllPropsCb(Glib::RefPtr &r); - void setPropCb(Glib::RefPtr &r); + void profileChangedCb(const Gio::DBus::Proxy::MapChangedProperties&, + const std::vector&); + void busConnectedCb(Glib::RefPtr& r); + void getAllPropsCb(Glib::RefPtr& r); + void setPropCb(Glib::RefPtr& r); void populateInitState(); - bool handleToggle(GdkEventButton *const &e) override; + bool handleToggle(GdkEventButton* const& e) override; private: // True if we're connected to the dbug interface. False if we're @@ -32,7 +32,7 @@ class PowerProfilesDaemon : public ALabel { bool connected_; // Look for a profile name in the list of available profiles and // switch activeProfile_ to it. - void switchToProfile(std::string const &); + void switchToProfile(std::string const&); // Used to toggle/display the profiles std::vector availableProfiles_; // Points to the active profile in the profiles list diff --git a/include/modules/privacy/privacy.hpp b/include/modules/privacy/privacy.hpp index cb6a34da4..de9eaf365 100644 --- a/include/modules/privacy/privacy.hpp +++ b/include/modules/privacy/privacy.hpp @@ -13,15 +13,16 @@ namespace waybar::modules::privacy { class Privacy : public AModule { public: - Privacy(const std::string &, const Json::Value &, Gtk::Orientation, const std::string &pos); + Privacy(const std::string&, const Json::Value&, Gtk::Orientation, const std::string& pos, + std::mutex&, std::list&); auto update() -> void override; void onPrivacyNodesChanged(); private: - std::list nodes_screenshare; // Screen is being shared - std::list nodes_audio_in; // Application is using the microphone - std::list nodes_audio_out; // Application is outputting audio + std::list nodes_screenshare; // Screen is being shared + std::list nodes_audio_in; // Application is using the microphone + std::list nodes_audio_out; // Application is outputting audio std::mutex mutex_; sigc::connection visibility_conn; diff --git a/include/modules/privacy/privacy_item.hpp b/include/modules/privacy/privacy_item.hpp index f5f572c03..31e200e3c 100644 --- a/include/modules/privacy/privacy_item.hpp +++ b/include/modules/privacy/privacy_item.hpp @@ -16,16 +16,16 @@ namespace waybar::modules::privacy { class PrivacyItem : public Gtk::Revealer { public: - PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privacy_type_, - std::list *nodes, Gtk::Orientation orientation, - const std::string &pos, const uint icon_size, const uint transition_duration); + PrivacyItem(const Json::Value& config_, enum PrivacyNodeType privacy_type_, + std::list* nodes, Gtk::Orientation orientation, + const std::string& pos, const uint icon_size, const uint transition_duration); enum PrivacyNodeType privacy_type; void set_in_use(bool in_use); private: - std::list *nodes; + std::list* nodes; sigc::connection signal_conn; diff --git a/include/modules/pulseaudio.hpp b/include/modules/pulseaudio.hpp index eead664f1..c4c69e331 100644 --- a/include/modules/pulseaudio.hpp +++ b/include/modules/pulseaudio.hpp @@ -13,7 +13,7 @@ namespace waybar::modules { class Pulseaudio : public ALabel { public: - Pulseaudio(const std::string&, const Json::Value&); + Pulseaudio(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Pulseaudio() = default; auto update() -> void override; diff --git a/include/modules/pulseaudio_slider.hpp b/include/modules/pulseaudio_slider.hpp index 3ef446847..41fdc4d4c 100644 --- a/include/modules/pulseaudio_slider.hpp +++ b/include/modules/pulseaudio_slider.hpp @@ -13,7 +13,7 @@ enum class PulseaudioSliderTarget { class PulseaudioSlider : public ASlider { public: - PulseaudioSlider(const std::string&, const Json::Value&); + PulseaudioSlider(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~PulseaudioSlider() = default; void update() override; @@ -24,4 +24,4 @@ class PulseaudioSlider : public ASlider { PulseaudioSliderTarget target = PulseaudioSliderTarget::Sink; }; -} // namespace waybar::modules \ No newline at end of file +} // namespace waybar::modules diff --git a/include/modules/river/layout.hpp b/include/modules/river/layout.hpp index 89f0c7d98..c0f11d0d0 100644 --- a/include/modules/river/layout.hpp +++ b/include/modules/river/layout.hpp @@ -10,25 +10,26 @@ namespace waybar::modules::river { class Layout : public waybar::ALabel { public: - Layout(const std::string &, const waybar::Bar &, const Json::Value &); + Layout(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~Layout(); // Handlers for wayland events - void handle_name(const char *name); + void handle_name(const char* name); void handle_clear(); - void handle_focused_output(struct wl_output *output); - void handle_unfocused_output(struct wl_output *output); + void handle_focused_output(struct wl_output* output); + void handle_unfocused_output(struct wl_output* output); - struct zriver_status_manager_v1 *status_manager_; - struct wl_seat *seat_; + struct zriver_status_manager_v1* status_manager_; + struct wl_seat* seat_; private: - const waybar::Bar &bar_; + const waybar::Bar& bar_; std::string name_; - struct wl_output *output_; // stores the output this module belongs to - struct wl_output *focused_output_; // stores the currently focused output - struct zriver_output_status_v1 *output_status_; - struct zriver_seat_status_v1 *seat_status_; + struct wl_output* output_; // stores the output this module belongs to + struct wl_output* focused_output_; // stores the currently focused output + struct zriver_output_status_v1* output_status_; + struct zriver_seat_status_v1* seat_status_; }; } /* namespace waybar::modules::river */ diff --git a/include/modules/river/mode.hpp b/include/modules/river/mode.hpp index 246cecae2..ed9ca752a 100644 --- a/include/modules/river/mode.hpp +++ b/include/modules/river/mode.hpp @@ -10,19 +10,19 @@ namespace waybar::modules::river { class Mode : public waybar::ALabel { public: - Mode(const std::string &, const waybar::Bar &, const Json::Value &); + Mode(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, std::list&); virtual ~Mode(); // Handlers for wayland events - void handle_mode(const char *mode); + void handle_mode(const char* mode); - struct zriver_status_manager_v1 *status_manager_; - struct wl_seat *seat_; + struct zriver_status_manager_v1* status_manager_; + struct wl_seat* seat_; private: - const waybar::Bar &bar_; + const waybar::Bar& bar_; std::string mode_; - struct zriver_seat_status_v1 *seat_status_; + struct zriver_seat_status_v1* seat_status_; }; } /* namespace waybar::modules::river */ diff --git a/include/modules/river/tags.hpp b/include/modules/river/tags.hpp index fd8673461..6979742e2 100644 --- a/include/modules/river/tags.hpp +++ b/include/modules/river/tags.hpp @@ -13,27 +13,27 @@ namespace waybar::modules::river { class Tags : public waybar::AModule { public: - Tags(const std::string &, const waybar::Bar &, const Json::Value &); + Tags(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, std::list&); virtual ~Tags(); // Handlers for wayland events void handle_focused_tags(uint32_t tags); - void handle_view_tags(struct wl_array *tags); + void handle_view_tags(struct wl_array* tags); void handle_urgent_tags(uint32_t tags); void handle_show(); void handle_primary_clicked(uint32_t tag); - bool handle_button_press(GdkEventButton *event_button, uint32_t tag); + bool handle_button_press(GdkEventButton* event_button, uint32_t tag); - struct zriver_status_manager_v1 *status_manager_; - struct zriver_control_v1 *control_; - struct wl_seat *seat_; + struct zriver_status_manager_v1* status_manager_; + struct zriver_control_v1* control_; + struct wl_seat* seat_; private: - const waybar::Bar &bar_; + const waybar::Bar& bar_; Gtk::Box box_; std::vector buttons_; - struct zriver_output_status_v1 *output_status_; + struct zriver_output_status_v1* output_status_; }; } /* namespace waybar::modules::river */ diff --git a/include/modules/river/window.hpp b/include/modules/river/window.hpp index bf29ebbf1..7b7f8d782 100644 --- a/include/modules/river/window.hpp +++ b/include/modules/river/window.hpp @@ -12,22 +12,23 @@ namespace waybar::modules::river { class Window : public waybar::ALabel { public: - Window(const std::string &, const waybar::Bar &, const Json::Value &); + Window(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~Window(); // Handlers for wayland events - void handle_focused_view(const char *title); - void handle_focused_output(struct wl_output *output); - void handle_unfocused_output(struct wl_output *output); + void handle_focused_view(const char* title); + void handle_focused_output(struct wl_output* output); + void handle_unfocused_output(struct wl_output* output); - struct zriver_status_manager_v1 *status_manager_; - struct wl_seat *seat_; + struct zriver_status_manager_v1* status_manager_; + struct wl_seat* seat_; private: - const waybar::Bar &bar_; - struct wl_output *output_; // stores the output this module belongs to - struct wl_output *focused_output_; // stores the currently focused output - struct zriver_seat_status_v1 *seat_status_; + const waybar::Bar& bar_; + struct wl_output* output_; // stores the output this module belongs to + struct wl_output* focused_output_; // stores the currently focused output + struct zriver_seat_status_v1* seat_status_; }; } /* namespace waybar::modules::river */ diff --git a/include/modules/sndio.hpp b/include/modules/sndio.hpp index 3fe36fadf..7f30e761e 100644 --- a/include/modules/sndio.hpp +++ b/include/modules/sndio.hpp @@ -11,18 +11,18 @@ namespace waybar::modules { class Sndio : public ALabel { public: - Sndio(const std::string &, const Json::Value &); + Sndio(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Sndio(); auto update() -> void override; - auto set_desc(struct sioctl_desc *, unsigned int) -> void; + auto set_desc(struct sioctl_desc*, unsigned int) -> void; auto put_val(unsigned int, unsigned int) -> void; - bool handleScroll(GdkEventScroll *) override; - bool handleToggle(GdkEventButton *const &) override; + bool handleScroll(GdkEventScroll*) override; + bool handleToggle(GdkEventButton* const&) override; private: auto connect_to_sndio() -> void; util::SleeperThread thread_; - struct sioctl_hdl *hdl_; + struct sioctl_hdl* hdl_; std::vector pfds_; unsigned int addr_; unsigned int volume_, old_volume_, maxval_; diff --git a/include/modules/sni/tray.hpp b/include/modules/sni/tray.hpp index 5f12d7f21..64ef3e45d 100644 --- a/include/modules/sni/tray.hpp +++ b/include/modules/sni/tray.hpp @@ -12,7 +12,7 @@ namespace waybar::modules::SNI { class Tray : public AModule { public: - Tray(const std::string&, const Bar&, const Json::Value&); + Tray(const std::string&, const Bar&, const Json::Value&, std::mutex&, std::list&); virtual ~Tray() = default; auto update() -> void override; diff --git a/include/modules/sni/watcher.hpp b/include/modules/sni/watcher.hpp index 5cb0f19e4..49d2dae5f 100644 --- a/include/modules/sni/watcher.hpp +++ b/include/modules/sni/watcher.hpp @@ -30,27 +30,27 @@ class Watcher { typedef struct { GfWatchType type; - Watcher *watcher; - gchar *service; - gchar *bus_name; - gchar *object_path; + Watcher* watcher; + gchar* service; + gchar* bus_name; + gchar* object_path; guint watch_id; } GfWatch; - void busAcquired(const Glib::RefPtr &, Glib::ustring); - static gboolean handleRegisterHost(Watcher *, GDBusMethodInvocation *, const gchar *); - static gboolean handleRegisterItem(Watcher *, GDBusMethodInvocation *, const gchar *); - static GfWatch *gfWatchFind(GSList *list, const gchar *bus_name, const gchar *object_path); - static GfWatch *gfWatchNew(GfWatchType, const gchar *, const gchar *, const gchar *, Watcher *); - static void nameVanished(GDBusConnection *connection, const char *name, gpointer data); + void busAcquired(const Glib::RefPtr&, Glib::ustring); + static gboolean handleRegisterHost(Watcher*, GDBusMethodInvocation*, const gchar*); + static gboolean handleRegisterItem(Watcher*, GDBusMethodInvocation*, const gchar*); + static GfWatch* gfWatchFind(GSList* list, const gchar* bus_name, const gchar* object_path); + static GfWatch* gfWatchNew(GfWatchType, const gchar*, const gchar*, const gchar*, Watcher*); + static void nameVanished(GDBusConnection* connection, const char* name, gpointer data); static void gfWatchFree(gpointer data); - void updateRegisteredItems(SnWatcher *obj); + void updateRegisteredItems(SnWatcher* obj); uint32_t bus_name_id_; - GSList *hosts_ = nullptr; - GSList *items_ = nullptr; - SnWatcher *watcher_ = nullptr; + GSList* hosts_ = nullptr; + GSList* items_ = nullptr; + SnWatcher* watcher_ = nullptr; }; } // namespace waybar::modules::SNI diff --git a/include/modules/sway/ipc/client.hpp b/include/modules/sway/ipc/client.hpp index a9a3e4e9d..9033a688c 100644 --- a/include/modules/sway/ipc/client.hpp +++ b/include/modules/sway/ipc/client.hpp @@ -27,21 +27,21 @@ class Ipc { std::string payload; }; - sigc::signal signal_event; - sigc::signal signal_cmd; + sigc::signal signal_event; + sigc::signal signal_cmd; - void sendCmd(uint32_t type, const std::string &payload = ""); - void subscribe(const std::string &payload); + void sendCmd(uint32_t type, const std::string& payload = ""); + void subscribe(const std::string& payload); void handleEvent(); - void setWorker(std::function &&func); + void setWorker(std::function&& func); protected: static inline const std::string ipc_magic_ = "i3-ipc"; static inline const size_t ipc_header_size_ = ipc_magic_.size() + 8; const std::string getSocketPath() const; - int open(const std::string &) const; - struct ipc_response send(int fd, uint32_t type, const std::string &payload = ""); + int open(const std::string&) const; + struct ipc_response send(int fd, uint32_t type, const std::string& payload = ""); struct ipc_response recv(int fd); int fd_; diff --git a/include/modules/sway/language.hpp b/include/modules/sway/language.hpp index 91aa181d9..a9ed8b083 100644 --- a/include/modules/sway/language.hpp +++ b/include/modules/sway/language.hpp @@ -16,7 +16,7 @@ namespace waybar::modules::sway { class Language : public ALabel, public sigc::trackable { public: - Language(const std::string& id, const Json::Value& config); + Language(const std::string& id, const Json::Value& config, std::mutex&, std::list&); virtual ~Language() = default; auto update() -> void override; diff --git a/include/modules/sway/mode.hpp b/include/modules/sway/mode.hpp index 44585355c..ed2fbd244 100644 --- a/include/modules/sway/mode.hpp +++ b/include/modules/sway/mode.hpp @@ -12,7 +12,7 @@ namespace waybar::modules::sway { class Mode : public ALabel, public sigc::trackable { public: - Mode(const std::string&, const Json::Value&); + Mode(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Mode() = default; auto update() -> void override; diff --git a/include/modules/sway/scratchpad.hpp b/include/modules/sway/scratchpad.hpp index 551cc8c8e..06169ba0b 100644 --- a/include/modules/sway/scratchpad.hpp +++ b/include/modules/sway/scratchpad.hpp @@ -14,7 +14,7 @@ namespace waybar::modules::sway { class Scratchpad : public ALabel { public: - Scratchpad(const std::string&, const Json::Value&); + Scratchpad(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Scratchpad() = default; auto update() -> void override; diff --git a/include/modules/sway/window.hpp b/include/modules/sway/window.hpp index 60cd26796..1887c58b7 100644 --- a/include/modules/sway/window.hpp +++ b/include/modules/sway/window.hpp @@ -14,7 +14,8 @@ namespace waybar::modules::sway { class Window : public AAppIconLabel, public sigc::trackable { public: - Window(const std::string&, const waybar::Bar&, const Json::Value&); + Window(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); virtual ~Window() = default; auto update() -> void override; diff --git a/include/modules/sway/workspaces.hpp b/include/modules/sway/workspaces.hpp index d8a9e18a8..a6d036b5a 100644 --- a/include/modules/sway/workspaces.hpp +++ b/include/modules/sway/workspaces.hpp @@ -18,7 +18,8 @@ namespace waybar::modules::sway { class Workspaces : public AModule, public sigc::trackable { public: - Workspaces(const std::string&, const waybar::Bar&, const Json::Value&); + Workspaces(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); ~Workspaces() override = default; auto update() -> void override; diff --git a/include/modules/systemd_failed_units.hpp b/include/modules/systemd_failed_units.hpp index 48b0074e9..6b1037190 100644 --- a/include/modules/systemd_failed_units.hpp +++ b/include/modules/systemd_failed_units.hpp @@ -10,7 +10,7 @@ namespace waybar::modules { class SystemdFailedUnits : public ALabel { public: - SystemdFailedUnits(const std::string &, const Json::Value &); + SystemdFailedUnits(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~SystemdFailedUnits(); auto update() -> void override; @@ -24,8 +24,8 @@ class SystemdFailedUnits : public ALabel { std::string last_status; Glib::RefPtr system_proxy, user_proxy; - void notify_cb(const Glib::ustring &sender_name, const Glib::ustring &signal_name, - const Glib::VariantContainerBase &arguments); + void notify_cb(const Glib::ustring& sender_name, const Glib::ustring& signal_name, + const Glib::VariantContainerBase& arguments); void RequestFailedUnits(); void RequestSystemState(); void updateData(); diff --git a/include/modules/temperature.hpp b/include/modules/temperature.hpp index 918281be5..71f978663 100644 --- a/include/modules/temperature.hpp +++ b/include/modules/temperature.hpp @@ -11,7 +11,7 @@ namespace waybar::modules { class Temperature : public ALabel { public: - Temperature(const std::string&, const Json::Value&); + Temperature(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Temperature() = default; auto update() -> void override; diff --git a/include/modules/upower.hpp b/include/modules/upower.hpp index 60a276dbf..7caa64fe3 100644 --- a/include/modules/upower.hpp +++ b/include/modules/upower.hpp @@ -12,7 +12,7 @@ namespace waybar::modules { class UPower final : public AIconLabel { public: - UPower(const std::string &, const Json::Value &); + UPower(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~UPower(); auto update() -> void override; @@ -30,17 +30,17 @@ class UPower final : public AIconLabel { // UPower device info struct upDevice_output { - UpDevice *upDevice{NULL}; + UpDevice* upDevice{NULL}; double percentage{0.0}; double temperature{0.0}; guint64 time_full{0u}; guint64 time_empty{0u}; - gchar *icon_name{(char *)'\0'}; + gchar* icon_name{(char*)'\0'}; bool upDeviceValid{false}; UpDeviceState state; UpDeviceKind kind; - char *nativePath{(char *)'\0'}; - char *model{(char *)'\0'}; + char* nativePath{(char*)'\0'}; + char* model{(char*)'\0'}; }; // Technical variables @@ -53,13 +53,13 @@ class UPower final : public AIconLabel { bool sleeping_; // Technical functions - void addDevice(UpDevice *); - void removeDevice(const gchar *); + void addDevice(UpDevice*); + void removeDevice(const gchar*); void removeDevices(); void resetDevices(); void setDisplayDevice(); - const Glib::ustring getText(const upDevice_output &upDevice_, const std::string &format); - bool queryTooltipCb(int, int, bool, const Glib::RefPtr &); + const Glib::ustring getText(const upDevice_output& upDevice_, const std::string& format); + bool queryTooltipCb(int, int, bool, const Glib::RefPtr&); // DBUS variables guint watcherID_; @@ -67,28 +67,28 @@ class UPower final : public AIconLabel { guint subscrID_{0u}; // UPower variables - UpClient *upClient_; + UpClient* upClient_; upDevice_output upDevice_; // Device to display typedef std::unordered_map Devices; Devices devices_; bool upRunning_{true}; // DBus callbacks - void getConn_cb(Glib::RefPtr &result); - void onAppear(const Glib::RefPtr &, const Glib::ustring &, - const Glib::ustring &); - void onVanished(const Glib::RefPtr &, const Glib::ustring &); - void prepareForSleep_cb(const Glib::RefPtr &connection, - const Glib::ustring &sender_name, const Glib::ustring &object_path, - const Glib::ustring &interface_name, const Glib::ustring &signal_name, - const Glib::VariantContainerBase ¶meters); + void getConn_cb(Glib::RefPtr& result); + void onAppear(const Glib::RefPtr&, const Glib::ustring&, + const Glib::ustring&); + void onVanished(const Glib::RefPtr&, const Glib::ustring&); + void prepareForSleep_cb(const Glib::RefPtr& connection, + const Glib::ustring& sender_name, const Glib::ustring& object_path, + const Glib::ustring& interface_name, const Glib::ustring& signal_name, + const Glib::VariantContainerBase& parameters); // UPower callbacks - static void deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data); - static void deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data); - static void deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer user_data); + static void deviceAdded_cb(UpClient* client, UpDevice* device, gpointer data); + static void deviceRemoved_cb(UpClient* client, const gchar* objectPath, gpointer data); + static void deviceNotify_cb(UpDevice* device, GParamSpec* pspec, gpointer user_data); // UPower secondary functions - void getUpDeviceInfo(upDevice_output &upDevice_); + void getUpDeviceInfo(upDevice_output& upDevice_); }; } // namespace waybar::modules diff --git a/include/modules/user.hpp b/include/modules/user.hpp index bcb03da47..11ff5c731 100644 --- a/include/modules/user.hpp +++ b/include/modules/user.hpp @@ -10,7 +10,7 @@ namespace waybar::modules { class User : public AIconLabel { public: - User(const std::string&, const Json::Value&); + User(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~User() = default; auto update() -> void override; diff --git a/include/modules/wayfire/window.hpp b/include/modules/wayfire/window.hpp index 3e8cb2918..7a15bdbf8 100644 --- a/include/modules/wayfire/window.hpp +++ b/include/modules/wayfire/window.hpp @@ -14,7 +14,8 @@ class Window : public AAppIconLabel { std::string old_app_id_; public: - Window(const std::string& id, const Bar& bar, const Json::Value& config); + Window(const std::string& id, const Bar& bar, const Json::Value& config, std::mutex&, + std::list&); ~Window() override; auto update() -> void override; diff --git a/include/modules/wayfire/workspaces.hpp b/include/modules/wayfire/workspaces.hpp index ab7cac441..c13a476b0 100644 --- a/include/modules/wayfire/workspaces.hpp +++ b/include/modules/wayfire/workspaces.hpp @@ -25,7 +25,8 @@ class Workspaces : public AModule { auto update_box() -> void; public: - Workspaces(const std::string& id, const Bar& bar, const Json::Value& config); + Workspaces(const std::string& id, const Bar& bar, const Json::Value& config, std::mutex&, + std::list&); ~Workspaces() override; }; diff --git a/include/modules/wireplumber.hpp b/include/modules/wireplumber.hpp index 0565704fb..2856542fc 100644 --- a/include/modules/wireplumber.hpp +++ b/include/modules/wireplumber.hpp @@ -12,7 +12,7 @@ namespace waybar::modules { class Wireplumber : public ALabel { public: - Wireplumber(const std::string&, const Json::Value&); + Wireplumber(const std::string&, const Json::Value&, std::mutex&, std::list&); virtual ~Wireplumber(); auto update() -> void override; diff --git a/include/modules/wlr/taskbar.hpp b/include/modules/wlr/taskbar.hpp index 8dc4dadd3..74c101480 100644 --- a/include/modules/wlr/taskbar.hpp +++ b/include/modules/wlr/taskbar.hpp @@ -33,8 +33,8 @@ class Taskbar; class Task { public: - Task(const waybar::Bar &, const Json::Value &, Taskbar *, - struct zwlr_foreign_toplevel_handle_v1 *, struct wl_seat *); + Task(const waybar::Bar&, const Json::Value&, Taskbar*, struct zwlr_foreign_toplevel_handle_v1*, + struct wl_seat*); ~Task(); public: @@ -53,11 +53,11 @@ class Task { static uint32_t global_id; private: - const waybar::Bar &bar_; - const Json::Value &config_; - Taskbar *tbar_; - struct zwlr_foreign_toplevel_handle_v1 *handle_; - struct wl_seat *seat_; + const waybar::Bar& bar_; + const Json::Value& config_; + Taskbar* tbar_; + struct zwlr_foreign_toplevel_handle_v1* handle_; + struct wl_seat* seat_; uint32_t id_; @@ -89,7 +89,7 @@ class Task { std::string repr() const; std::string state_string(bool = false) const; void set_minimize_hint(); - void on_button_size_allocated(Gtk::Allocation &alloc); + void on_button_size_allocated(Gtk::Allocation& alloc); void hide_if_ignored(); public: @@ -105,26 +105,26 @@ class Task { public: /* Callbacks for the wlr protocol */ - void handle_title(const char *); - void handle_app_id(const char *); - void handle_output_enter(struct wl_output *); - void handle_output_leave(struct wl_output *); - void handle_state(struct wl_array *); + void handle_title(const char*); + void handle_app_id(const char*); + void handle_output_enter(struct wl_output*); + void handle_output_leave(struct wl_output*); + void handle_state(struct wl_array*); void handle_done(); void handle_closed(); /* Callbacks for Gtk events */ - bool handle_clicked(GdkEventButton *); - bool handle_button_release(GdkEventButton *); - bool handle_motion_notify(GdkEventMotion *); - void handle_drag_data_get(const Glib::RefPtr &context, - Gtk::SelectionData &selection_data, guint info, guint time); - void handle_drag_data_received(const Glib::RefPtr &context, int x, int y, + bool handle_clicked(GdkEventButton*); + bool handle_button_release(GdkEventButton*); + bool handle_motion_notify(GdkEventMotion*); + void handle_drag_data_get(const Glib::RefPtr& context, + Gtk::SelectionData& selection_data, guint info, guint time); + void handle_drag_data_received(const Glib::RefPtr& context, int x, int y, Gtk::SelectionData selection_data, guint info, guint time); public: - bool operator==(const Task &) const; - bool operator!=(const Task &) const; + bool operator==(const Task&) const; + bool operator!=(const Task&) const; public: void update(); @@ -142,12 +142,13 @@ using TaskPtr = std::unique_ptr; class Taskbar : public waybar::AModule { public: - Taskbar(const std::string &, const waybar::Bar &, const Json::Value &); + Taskbar(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&, + std::list&); ~Taskbar(); void update(); private: - const waybar::Bar &bar_; + const waybar::Bar& bar_; Gtk::Box box_; std::vector tasks_; @@ -155,30 +156,30 @@ class Taskbar : public waybar::AModule { std::unordered_set ignore_list_; std::map app_ids_replace_map_; - struct zwlr_foreign_toplevel_manager_v1 *manager_; - struct wl_seat *seat_; + struct zwlr_foreign_toplevel_manager_v1* manager_; + struct wl_seat* seat_; public: /* Callbacks for global registration */ - void register_manager(struct wl_registry *, uint32_t name, uint32_t version); - void register_seat(struct wl_registry *, uint32_t name, uint32_t version); + void register_manager(struct wl_registry*, uint32_t name, uint32_t version); + void register_seat(struct wl_registry*, uint32_t name, uint32_t version); /* Callbacks for the wlr protocol */ - void handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1 *); + void handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1*); void handle_finished(); public: - void add_button(Gtk::Button &); - void move_button(Gtk::Button &, int); - void remove_button(Gtk::Button &); + void add_button(Gtk::Button&); + void move_button(Gtk::Button&, int); + void remove_button(Gtk::Button&); void remove_task(uint32_t); - bool show_output(struct wl_output *) const; + bool show_output(struct wl_output*) const; bool all_outputs() const; - const IconLoader &icon_loader() const; - const std::unordered_set &ignore_list() const; - const std::map &app_ids_replace_map() const; + const IconLoader& icon_loader() const; + const std::unordered_set& ignore_list() const; + const std::map& app_ids_replace_map() const; }; } /* namespace waybar::modules::wlr */ diff --git a/include/util/backlight_backend.hpp b/include/util/backlight_backend.hpp index eb42d3ccf..ba3ccca7a 100644 --- a/include/util/backlight_backend.hpp +++ b/include/util/backlight_backend.hpp @@ -36,7 +36,7 @@ class BacklightDevice { void set_max(int max); bool get_powered() const; void set_powered(bool powered); - friend inline bool operator==(const BacklightDevice &lhs, const BacklightDevice &rhs) { + friend inline bool operator==(const BacklightDevice& lhs, const BacklightDevice& rhs) { return lhs.name_ == rhs.name_ && lhs.actual_ == rhs.actual_ && lhs.max_ == rhs.max_; } @@ -52,25 +52,25 @@ class BacklightBackend { BacklightBackend(std::chrono::milliseconds interval, std::function on_updated_cb = NOOP); // const inline BacklightDevice *get_best_device(std::string_view preferred_device); - const BacklightDevice *get_previous_best_device(); + const BacklightDevice* get_previous_best_device(); - void set_previous_best_device(const BacklightDevice *device); + void set_previous_best_device(const BacklightDevice* device); - void set_brightness(const 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(const std::string &preferred_device, int brightness); - int get_scaled_brightness(const 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(login_proxy_); } - static const BacklightDevice *best_device(const std::vector &devices, + static const BacklightDevice* best_device(const std::vector& devices, std::string_view); std::vector devices_; std::mutex udev_thread_mutex_; private: - void set_brightness_internal(const 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 on_updated_cb_; std::chrono::milliseconds polling_interval_; diff --git a/include/util/clara.hpp b/include/util/clara.hpp index 73fa5415d..481235495 100644 --- a/include/util/clara.hpp +++ b/include/util/clara.hpp @@ -78,7 +78,7 @@ class Column { class iterator { friend Column; - Column const &m_column; + Column const& m_column; size_t m_stringIndex = 0; size_t m_pos = 0; @@ -86,10 +86,10 @@ class Column { size_t m_end = 0; bool m_suffix = false; - iterator(Column const &column, size_t stringIndex) + iterator(Column const& column, size_t stringIndex) : m_column(column), m_stringIndex(stringIndex) {} - auto line() const -> std::string const & { return m_column.m_strings[m_stringIndex]; } + auto line() const -> std::string const& { return m_column.m_strings[m_stringIndex]; } auto isBoundary(size_t at) const -> bool { assert(at > 0); @@ -129,18 +129,18 @@ class Column { return initial == std::string::npos ? m_column.m_indent : initial; } - auto addIndentAndSuffix(std::string const &plain) const -> std::string { + auto addIndentAndSuffix(std::string const& plain) const -> std::string { return std::string(indent(), ' ') + (m_suffix ? plain + "-" : plain); } public: using difference_type = std::ptrdiff_t; using value_type = std::string; - using pointer = value_type *; - using reference = value_type &; + using pointer = value_type*; + using reference = value_type&; using iterator_category = std::forward_iterator_tag; - explicit iterator(Column const &column) : m_column(column) { + explicit iterator(Column const& column) : m_column(column) { assert(m_column.m_width > m_column.m_indent); assert(m_column.m_initialIndent == std::string::npos || m_column.m_width > m_column.m_initialIndent); @@ -154,7 +154,7 @@ class Column { return addIndentAndSuffix(line().substr(m_pos, m_len)); } - auto operator++() -> iterator & { + auto operator++() -> iterator& { m_pos += m_len; if (m_pos < line().size() && line()[m_pos] == '\n') m_pos += 1; @@ -174,26 +174,26 @@ class Column { return prev; } - auto operator==(iterator const &other) const -> bool { + auto operator==(iterator const& other) const -> bool { return m_pos == other.m_pos && m_stringIndex == other.m_stringIndex && &m_column == &other.m_column; } - auto operator!=(iterator const &other) const -> bool { return !operator==(other); } + auto operator!=(iterator const& other) const -> bool { return !operator==(other); } }; using const_iterator = iterator; - explicit Column(std::string const &text) { m_strings.push_back(text); } + explicit Column(std::string const& text) { m_strings.push_back(text); } - auto width(size_t newWidth) -> Column & { + auto width(size_t newWidth) -> Column& { assert(newWidth > 0); m_width = newWidth; return *this; } - auto indent(size_t newIndent) -> Column & { + auto indent(size_t newIndent) -> Column& { m_indent = newIndent; return *this; } - auto initialIndent(size_t newIndent) -> Column & { + auto initialIndent(size_t newIndent) -> Column& { m_initialIndent = newIndent; return *this; } @@ -202,7 +202,7 @@ class Column { auto begin() const -> iterator { return iterator(*this); } auto end() const -> iterator { return {*this, m_strings.size()}; } - inline friend std::ostream &operator<<(std::ostream &os, Column const &col) { + inline friend std::ostream& operator<<(std::ostream& os, Column const& col) { bool first = true; for (auto line : col) { if (first) @@ -214,7 +214,7 @@ class Column { return os; } - auto operator+(Column const &other) -> Columns; + auto operator+(Column const& other) -> Columns; auto toString() const -> std::string { std::ostringstream oss; @@ -236,34 +236,34 @@ class Columns { friend Columns; struct EndTag {}; - std::vector const &m_columns; + std::vector const& m_columns; std::vector m_iterators; size_t m_activeIterators; - iterator(Columns const &columns, EndTag) : m_columns(columns.m_columns), m_activeIterators(0) { + iterator(Columns const& columns, EndTag) : m_columns(columns.m_columns), m_activeIterators(0) { m_iterators.reserve(m_columns.size()); - for (auto const &col : m_columns) m_iterators.push_back(col.end()); + for (auto const& col : m_columns) m_iterators.push_back(col.end()); } public: using difference_type = std::ptrdiff_t; using value_type = std::string; - using pointer = value_type *; - using reference = value_type &; + using pointer = value_type*; + using reference = value_type&; using iterator_category = std::forward_iterator_tag; - explicit iterator(Columns const &columns) + explicit iterator(Columns const& columns) : m_columns(columns.m_columns), m_activeIterators(m_columns.size()) { m_iterators.reserve(m_columns.size()); - for (auto const &col : m_columns) m_iterators.push_back(col.begin()); + for (auto const& col : m_columns) m_iterators.push_back(col.begin()); } - auto operator==(iterator const &other) const -> bool { + auto operator==(iterator const& other) const -> bool { return m_iterators == other.m_iterators; } - auto operator!=(iterator const &other) const -> bool { + auto operator!=(iterator const& other) const -> bool { return m_iterators != other.m_iterators; } auto operator*() const -> std::string { @@ -284,7 +284,7 @@ class Columns { } return row; } - auto operator++() -> iterator & { + auto operator++() -> iterator& { for (size_t i = 0; i < m_columns.size(); ++i) { if (m_iterators[i] != m_columns[i].end()) ++m_iterators[i]; } @@ -301,17 +301,17 @@ class Columns { auto begin() const -> iterator { return iterator(*this); } auto end() const -> iterator { return {*this, iterator::EndTag()}; } - auto operator+=(Column const &col) -> Columns & { + auto operator+=(Column const& col) -> Columns& { m_columns.push_back(col); return *this; } - auto operator+(Column const &col) -> Columns { + auto operator+(Column const& col) -> Columns { Columns combined = *this; combined += col; return combined; } - inline friend std::ostream &operator<<(std::ostream &os, Columns const &cols) { + inline friend std::ostream& operator<<(std::ostream& os, Columns const& cols) { bool first = true; for (auto line : cols) { if (first) @@ -330,7 +330,7 @@ class Columns { } }; -inline auto Column::operator+(Column const &other) -> Columns { +inline auto Column::operator+(Column const& other) -> Columns { Columns cols; cols += *this; cols += other; @@ -381,7 +381,7 @@ class Args { std::vector m_args; public: - Args(int argc, char const *const *argv) : m_exeName(argv[0]), m_args(argv + 1, argv + argc) {} + Args(int argc, char const* const* argv) : m_exeName(argv[0]), m_args(argv + 1, argv + argc) {} Args(std::initializer_list args) : m_exeName(*args.begin()), m_args(args.begin() + 1, args.end()) {} @@ -419,7 +419,7 @@ class TokenStream { while (it != itEnd && it->empty()) ++it; if (it != itEnd) { - auto const &next = *it; + auto const& next = *it; if (isOptPrefix(next[0])) { auto delimiterPos = next.find_first_of(" :="); if (delimiterPos != std::string::npos) { @@ -443,7 +443,7 @@ class TokenStream { } public: - explicit TokenStream(Args const &args) : TokenStream(args.m_args.begin(), args.m_args.end()) {} + explicit TokenStream(Args const& args) : TokenStream(args.m_args.begin(), args.m_args.end()) {} TokenStream(Iterator it, Iterator itEnd) : it(it), itEnd(itEnd) { loadBuffer(); } @@ -456,12 +456,12 @@ class TokenStream { return m_tokenBuffer.front(); } - auto operator->() const -> Token const * { + auto operator->() const -> Token const* { assert(!m_tokenBuffer.empty()); return &m_tokenBuffer.front(); } - auto operator++() -> TokenStream & { + auto operator++() -> TokenStream& { if (m_tokenBuffer.size() >= 2) { m_tokenBuffer.erase(m_tokenBuffer.begin()); } else { @@ -488,7 +488,7 @@ class ResultBase { template class ResultValueBase : public ResultBase { public: - auto value() const -> T const & { + auto value() const -> T const& { enforceOk(); return m_value; } @@ -496,13 +496,13 @@ class ResultValueBase : public ResultBase { protected: ResultValueBase(Type type) : ResultBase(type) {} - ResultValueBase(ResultValueBase const &other) : ResultBase(other) { + ResultValueBase(ResultValueBase const& other) : ResultBase(other) { if (m_type == ResultBase::Ok) new (&m_value) T(other.m_value); } - ResultValueBase(Type, T const &value) : ResultBase(Ok) { new (&m_value) T(value); } + ResultValueBase(Type, T const& value) : ResultBase(Ok) { new (&m_value) T(value); } - auto operator=(ResultValueBase const &other) -> ResultValueBase & { + auto operator=(ResultValueBase const& other) -> ResultValueBase& { if (m_type == ResultBase::Ok) m_value.~T(); ResultBase::operator=(other); if (m_type == ResultBase::Ok) new (&m_value) T(other.m_value); @@ -528,20 +528,20 @@ template class BasicResult : public ResultValueBase { public: template - explicit BasicResult(BasicResult const &other) + explicit BasicResult(BasicResult const& other) : ResultValueBase(other.type()), m_errorMessage(other.errorMessage()) { assert(type() != ResultBase::Ok); } template - static auto ok(U const &value) -> BasicResult { + static auto ok(U const& value) -> BasicResult { return {ResultBase::Ok, value}; } static auto ok() -> BasicResult { return {ResultBase::Ok}; } - static auto logicError(std::string const &message) -> BasicResult { + static auto logicError(std::string const& message) -> BasicResult { return {ResultBase::LogicError, message}; } - static auto runtimeError(std::string const &message) -> BasicResult { + static auto runtimeError(std::string const& message) -> BasicResult { return {ResultBase::RuntimeError, message}; } @@ -560,7 +560,7 @@ class BasicResult : public ResultValueBase { std::string m_errorMessage; // Only populated if resultType is an error - BasicResult(ResultBase::Type type, std::string const &message) + BasicResult(ResultBase::Type type, std::string const& message) : ResultValueBase(type), m_errorMessage(message) { assert(m_type != ResultBase::Ok); } @@ -573,7 +573,7 @@ enum class ParseResultType { Matched, NoMatch, ShortCircuitAll, ShortCircuitSame class ParseState { public: - ParseState(ParseResultType type, TokenStream const &remainingTokens) + ParseState(ParseResultType type, TokenStream const& remainingTokens) : m_type(type), m_remainingTokens(remainingTokens) {} auto type() const -> ParseResultType { return m_type; } @@ -594,7 +594,7 @@ struct HelpColumns { }; template -inline auto convertInto(std::string const &source, T &target) -> ParserResult { +inline auto convertInto(std::string const& source, T& target) -> ParserResult { std::stringstream ss; ss << source; ss >> target; @@ -603,11 +603,11 @@ inline auto convertInto(std::string const &source, T &target) -> ParserResult { else return ParserResult::ok(ParseResultType::Matched); } -inline auto convertInto(std::string const &source, std::string &target) -> ParserResult { +inline auto convertInto(std::string const& source, std::string& target) -> ParserResult { target = source; return ParserResult::ok(ParseResultType::Matched); } -inline auto convertInto(std::string const &source, bool &target) -> ParserResult { +inline auto convertInto(std::string const& source, bool& target) -> ParserResult { std::string srcLC = source; std::transform(srcLC.begin(), srcLC.end(), srcLC.begin(), [](char c) { return static_cast(::tolower(c)); }); @@ -622,7 +622,7 @@ inline auto convertInto(std::string const &source, bool &target) -> ParserResult } #ifdef CLARA_CONFIG_OPTIONAL_TYPE template -inline auto convertInto(std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE &target) +inline auto convertInto(std::string const& source, CLARA_CONFIG_OPTIONAL_TYPE& target) -> ParserResult { T temp; auto result = convertInto(source, temp); @@ -633,10 +633,10 @@ inline auto convertInto(std::string const &source, CLARA_CONFIG_OPTIONAL_TYPE struct NonCopyable { NonCopyable() = default; - NonCopyable(NonCopyable const &) = delete; - NonCopyable(NonCopyable &&) = delete; - NonCopyable &operator=(NonCopyable const &) = delete; - NonCopyable &operator=(NonCopyable &&) = delete; + NonCopyable(NonCopyable const&) = delete; + NonCopyable(NonCopyable&&) = delete; + NonCopyable& operator=(NonCopyable const&) = delete; + NonCopyable& operator=(NonCopyable&&) = delete; }; struct BoundRef : NonCopyable { @@ -645,7 +645,7 @@ struct BoundRef : NonCopyable { virtual auto isFlag() const -> bool { return false; } }; struct BoundValueRefBase : BoundRef { - virtual auto setValue(std::string const &arg) -> ParserResult = 0; + virtual auto setValue(std::string const& arg) -> ParserResult = 0; }; struct BoundFlagRefBase : BoundRef { virtual auto setFlag(bool flag) -> ParserResult = 0; @@ -654,22 +654,22 @@ struct BoundFlagRefBase : BoundRef { template struct BoundValueRef : BoundValueRefBase { - T &m_ref; + T& m_ref; - explicit BoundValueRef(T &ref) : m_ref(ref) {} + explicit BoundValueRef(T& ref) : m_ref(ref) {} - auto setValue(std::string const &arg) -> ParserResult override { return convertInto(arg, m_ref); } + auto setValue(std::string const& arg) -> ParserResult override { return convertInto(arg, m_ref); } }; template struct BoundValueRef> : BoundValueRefBase { - std::vector &m_ref; + std::vector& m_ref; - explicit BoundValueRef(std::vector &ref) : m_ref(ref) {} + explicit BoundValueRef(std::vector& ref) : m_ref(ref) {} auto isContainer() const -> bool override { return true; } - auto setValue(std::string const &arg) -> ParserResult override { + auto setValue(std::string const& arg) -> ParserResult override { T temp; auto result = convertInto(arg, temp); if (result) m_ref.push_back(temp); @@ -678,9 +678,9 @@ struct BoundValueRef> : BoundValueRefBase { }; struct BoundFlagRef : BoundFlagRefBase { - bool &m_ref; + bool& m_ref; - explicit BoundFlagRef(bool &ref) : m_ref(ref) {} + explicit BoundFlagRef(bool& ref) : m_ref(ref) {} auto setFlag(bool flag) -> ParserResult override { m_ref = flag; @@ -694,7 +694,7 @@ struct LambdaInvoker { "Lambda must return void or clara::ParserResult"); template - static auto invoke(L const &lambda, ArgType const &arg) -> ParserResult { + static auto invoke(L const& lambda, ArgType const& arg) -> ParserResult { return lambda(arg); } }; @@ -702,14 +702,14 @@ struct LambdaInvoker { template <> struct LambdaInvoker { template - static auto invoke(L const &lambda, ArgType const &arg) -> ParserResult { + static auto invoke(L const& lambda, ArgType const& arg) -> ParserResult { lambda(arg); return ParserResult::ok(ParseResultType::Matched); } }; template -inline auto invokeLambda(L const &lambda, std::string const &arg) -> ParserResult { +inline auto invokeLambda(L const& lambda, std::string const& arg) -> ParserResult { ArgType temp{}; auto result = convertInto(arg, temp); return !result ? result @@ -721,9 +721,9 @@ struct BoundLambda : BoundValueRefBase { L m_lambda; static_assert(UnaryLambdaTraits::isValid, "Supplied lambda must take exactly one argument"); - explicit BoundLambda(L const &lambda) : m_lambda(lambda) {} + explicit BoundLambda(L const& lambda) : m_lambda(lambda) {} - auto setValue(std::string const &arg) -> ParserResult override { + auto setValue(std::string const& arg) -> ParserResult override { return invokeLambda::ArgType>(m_lambda, arg); } }; @@ -736,7 +736,7 @@ struct BoundFlagLambda : BoundFlagRefBase { static_assert(std::is_same::ArgType, bool>::value, "flags must be boolean"); - explicit BoundFlagLambda(L const &lambda) : m_lambda(lambda) {} + explicit BoundFlagLambda(L const& lambda) : m_lambda(lambda) {} auto setFlag(bool flag) -> ParserResult override { return LambdaInvoker::ReturnType>::invoke(m_lambda, flag); @@ -751,11 +751,11 @@ class ParserBase { public: virtual ~ParserBase() = default; virtual auto validate() const -> Result { return Result::ok(); } - virtual auto parse(std::string const &exeName, TokenStream const &tokens) const + virtual auto parse(std::string const& exeName, TokenStream const& tokens) const -> InternalParseResult = 0; virtual auto cardinality() const -> size_t { return 1; } - auto parse(Args const &args) const -> InternalParseResult { + auto parse(Args const& args) const -> InternalParseResult { return parse(args.exeName(), TokenStream(args)); } }; @@ -764,10 +764,10 @@ template class ComposableParserImpl : public ParserBase { public: template - auto operator|(T const &other) const -> Parser; + auto operator|(T const& other) const -> Parser; template - auto operator+(T const &other) const -> Parser; + auto operator+(T const& other) const -> Parser; }; // Common code and state for Args and Opts @@ -779,30 +779,30 @@ class ParserRefImpl : public ComposableParserImpl { std::string m_hint; std::string m_description; - explicit ParserRefImpl(std::shared_ptr const &ref) : m_ref(ref) {} + explicit ParserRefImpl(std::shared_ptr const& ref) : m_ref(ref) {} public: template - ParserRefImpl(T &ref, std::string const &hint) + ParserRefImpl(T& ref, std::string const& hint) : m_ref(std::make_shared>(ref)), m_hint(hint) {} template - ParserRefImpl(LambdaT const &ref, std::string const &hint) + ParserRefImpl(LambdaT const& ref, std::string const& hint) : m_ref(std::make_shared>(ref)), m_hint(hint) {} - auto operator()(std::string const &description) -> DerivedT & { + auto operator()(std::string const& description) -> DerivedT& { m_description = description; - return static_cast(*this); + return static_cast(*this); } - auto optional() -> DerivedT & { + auto optional() -> DerivedT& { m_optionality = Optionality::Optional; - return static_cast(*this); + return static_cast(*this); }; - auto required() -> DerivedT & { + auto required() -> DerivedT& { m_optionality = Optionality::Required; - return static_cast(*this); + return static_cast(*this); }; auto isOptional() const -> bool { return m_optionality == Optionality::Optional; } @@ -822,29 +822,29 @@ class ExeName : public ComposableParserImpl { std::shared_ptr m_ref; template - static auto makeRef(LambdaT const &lambda) -> std::shared_ptr { + static auto makeRef(LambdaT const& lambda) -> std::shared_ptr { return std::make_shared>(lambda); } public: ExeName() : m_name(std::make_shared("")) {} - explicit ExeName(std::string &ref) : ExeName() { + explicit ExeName(std::string& ref) : ExeName() { m_ref = std::make_shared>(ref); } template - explicit ExeName(LambdaT const &lambda) : ExeName() { + explicit ExeName(LambdaT const& lambda) : ExeName() { m_ref = std::make_shared>(lambda); } // The exe name is not parsed out of the normal tokens, but is handled specially - auto parse(std::string const &, TokenStream const &tokens) const -> InternalParseResult override { + auto parse(std::string const&, TokenStream const& tokens) const -> InternalParseResult override { return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, tokens)); } auto name() const -> std::string { return *m_name; } - auto set(std::string const &newName) -> ParserResult { + auto set(std::string const& newName) -> ParserResult { auto lastSlash = newName.find_last_of("\\/"); auto filename = (lastSlash == std::string::npos) ? newName : newName.substr(lastSlash + 1); @@ -860,17 +860,17 @@ class Arg : public ParserRefImpl { public: using ParserRefImpl::ParserRefImpl; - auto parse(std::string const &, TokenStream const &tokens) const -> InternalParseResult override { + auto parse(std::string const&, TokenStream const& tokens) const -> InternalParseResult override { auto validationResult = validate(); if (!validationResult) return InternalParseResult(validationResult); auto remainingTokens = tokens; - auto const &token = *remainingTokens; + auto const& token = *remainingTokens; if (token.type != TokenType::Argument) return InternalParseResult::ok(ParseState(ParseResultType::NoMatch, remainingTokens)); assert(!m_ref->isFlag()); - auto valueRef = static_cast(m_ref.get()); + auto valueRef = static_cast(m_ref.get()); auto result = valueRef->setValue(remainingTokens->token); if (!result) @@ -880,7 +880,7 @@ class Arg : public ParserRefImpl { } }; -inline auto normaliseOpt(std::string const &optName) -> std::string { +inline auto normaliseOpt(std::string const& optName) -> std::string { #ifdef CLARA_PLATFORM_WINDOWS if (optName[0] == '/') return "-" + optName.substr(1); @@ -895,18 +895,18 @@ class Opt : public ParserRefImpl { public: template - explicit Opt(LambdaT const &ref) + explicit Opt(LambdaT const& ref) : ParserRefImpl(std::make_shared>(ref)) {} - explicit Opt(bool &ref) : ParserRefImpl(std::make_shared(ref)) {} + explicit Opt(bool& ref) : ParserRefImpl(std::make_shared(ref)) {} template - Opt(LambdaT const &ref, std::string const &hint) : ParserRefImpl(ref, hint) {} + Opt(LambdaT const& ref, std::string const& hint) : ParserRefImpl(ref, hint) {} template - Opt(T &ref, std::string const &hint) : ParserRefImpl(ref, hint) {} + Opt(T& ref, std::string const& hint) : ParserRefImpl(ref, hint) {} - auto operator[](std::string const &optName) -> Opt & { + auto operator[](std::string const& optName) -> Opt& { m_optNames.push_back(optName); return *this; } @@ -914,7 +914,7 @@ class Opt : public ParserRefImpl { auto getHelpColumns() const -> std::vector { std::ostringstream oss; bool first = true; - for (auto const &opt : m_optNames) { + for (auto const& opt : m_optNames) { if (first) first = false; else @@ -925,9 +925,9 @@ class Opt : public ParserRefImpl { return {{oss.str(), m_description}}; } - auto isMatch(std::string const &optToken) const -> bool { + auto isMatch(std::string const& optToken) const -> bool { auto normalisedToken = normaliseOpt(optToken); - for (auto const &name : m_optNames) { + for (auto const& name : m_optNames) { if (normaliseOpt(name) == normalisedToken) return true; } return false; @@ -935,26 +935,26 @@ class Opt : public ParserRefImpl { using ParserBase::parse; - auto parse(std::string const &, TokenStream const &tokens) const -> InternalParseResult override { + auto parse(std::string const&, TokenStream const& tokens) const -> InternalParseResult override { auto validationResult = validate(); if (!validationResult) return InternalParseResult(validationResult); auto remainingTokens = tokens; if (remainingTokens && remainingTokens->type == TokenType::Option) { - auto const &token = *remainingTokens; + auto const& token = *remainingTokens; if (isMatch(token.token)) { if (m_ref->isFlag()) { - auto flagRef = static_cast(m_ref.get()); + auto flagRef = static_cast(m_ref.get()); auto result = flagRef->setFlag(true); if (!result) return InternalParseResult(result); if (result.value() == ParseResultType::ShortCircuitAll) return InternalParseResult::ok(ParseState(result.value(), remainingTokens)); } else { - auto valueRef = static_cast(m_ref.get()); + auto valueRef = static_cast(m_ref.get()); ++remainingTokens; if (!remainingTokens) return InternalParseResult::runtimeError("Expected argument following " + token.token); - auto const &argToken = *remainingTokens; + auto const& argToken = *remainingTokens; if (argToken.type != TokenType::Argument) return InternalParseResult::runtimeError("Expected argument following " + token.token); auto result = valueRef->setValue(argToken.token); @@ -970,7 +970,7 @@ class Opt : public ParserRefImpl { auto validate() const -> Result override { if (m_optNames.empty()) return Result::logicError("No options supplied to Opt"); - for (auto const &name : m_optNames) { + for (auto const& name : m_optNames) { if (name.empty()) return Result::logicError("Option name cannot be empty"); #ifdef CLARA_PLATFORM_WINDOWS if (name[0] != '-' && name[0] != '/') @@ -984,12 +984,12 @@ class Opt : public ParserRefImpl { }; struct Help : Opt { - Help(bool &showHelpFlag) + Help(bool& showHelpFlag) : Opt([&](bool flag) { showHelpFlag = flag; return ParserResult::ok(ParseResultType::ShortCircuitAll); }) { - static_cast(*this)("display usage information")["-?"]["-h"]["--help"].optional(); + static_cast(*this)("display usage information")["-?"]["-h"]["--help"].optional(); } }; @@ -998,57 +998,57 @@ struct Parser : ParserBase { std::vector m_options; std::vector m_args; - auto operator|=(ExeName const &exeName) -> Parser & { + auto operator|=(ExeName const& exeName) -> Parser& { m_exeName = exeName; return *this; } - auto operator|=(Arg const &arg) -> Parser & { + auto operator|=(Arg const& arg) -> Parser& { m_args.push_back(arg); return *this; } - auto operator|=(Opt const &opt) -> Parser & { + auto operator|=(Opt const& opt) -> Parser& { m_options.push_back(opt); return *this; } - auto operator|=(Parser const &other) -> Parser & { + auto operator|=(Parser const& other) -> Parser& { m_options.insert(m_options.end(), other.m_options.begin(), other.m_options.end()); m_args.insert(m_args.end(), other.m_args.begin(), other.m_args.end()); return *this; } template - auto operator|(T const &other) const -> Parser { + auto operator|(T const& other) const -> Parser { return Parser(*this) |= other; } // Forward deprecated interface with '+' instead of '|' template - auto operator+=(T const &other) -> Parser & { + auto operator+=(T const& other) -> Parser& { return operator|=(other); } template - auto operator+(T const &other) const -> Parser { + auto operator+(T const& other) const -> Parser { return operator|(other); } auto getHelpColumns() const -> std::vector { std::vector cols; - for (auto const &o : m_options) { + for (auto const& o : m_options) { auto childCols = o.getHelpColumns(); cols.insert(cols.end(), childCols.begin(), childCols.end()); } return cols; } - void writeToStream(std::ostream &os) const { + void writeToStream(std::ostream& os) const { if (!m_exeName.name().empty()) { os << "usage:\n" << " " << m_exeName.name() << " "; bool required = true, first = true; - for (auto const &arg : m_args) { + for (auto const& arg : m_args) { if (first) first = false; else @@ -1068,28 +1068,28 @@ struct Parser : ParserBase { auto rows = getHelpColumns(); size_t consoleWidth = CLARA_CONFIG_CONSOLE_WIDTH; size_t optWidth = 0; - for (auto const &cols : rows) optWidth = (std::max)(optWidth, cols.left.size() + 2); + for (auto const& cols : rows) optWidth = (std::max)(optWidth, cols.left.size() + 2); optWidth = (std::min)(optWidth, consoleWidth / 2); - for (auto const &cols : rows) { + for (auto const& cols : rows) { auto row = TextFlow::Column(cols.left).width(optWidth).indent(2) + TextFlow::Spacer(4) + TextFlow::Column(cols.right).width(consoleWidth - 7 - optWidth); os << row << std::endl; } } - friend auto operator<<(std::ostream &os, Parser const &parser) -> std::ostream & { + friend auto operator<<(std::ostream& os, Parser const& parser) -> std::ostream& { parser.writeToStream(os); return os; } auto validate() const -> Result override { - for (auto const &opt : m_options) { + for (auto const& opt : m_options) { auto result = opt.validate(); if (!result) return result; } - for (auto const &arg : m_args) { + for (auto const& arg : m_args) { auto result = arg.validate(); if (!result) return result; } @@ -1098,10 +1098,10 @@ struct Parser : ParserBase { using ParserBase::parse; - auto parse(std::string const &exeName, TokenStream const &tokens) const + auto parse(std::string const& exeName, TokenStream const& tokens) const -> InternalParseResult override { struct ParserInfo { - ParserBase const *parser = nullptr; + ParserBase const* parser = nullptr; size_t count = 0; }; const size_t totalParsers = m_options.size() + m_args.size(); @@ -1111,8 +1111,8 @@ struct Parser : ParserBase { { size_t i = 0; - for (auto const &opt : m_options) parseInfos[i++].parser = &opt; - for (auto const &arg : m_args) parseInfos[i++].parser = &arg; + for (auto const& opt : m_options) parseInfos[i++].parser = &opt; + for (auto const& arg : m_args) parseInfos[i++].parser = &arg; } m_exeName.set(exeName); @@ -1122,7 +1122,7 @@ struct Parser : ParserBase { bool tokenParsed = false; for (size_t i = 0; i < totalParsers; ++i) { - auto &parseInfo = parseInfos[i]; + auto& parseInfo = parseInfos[i]; if (parseInfo.parser->cardinality() == 0 || parseInfo.count < parseInfo.parser->cardinality()) { result = parseInfo.parser->parse(exeName, result.value().remainingTokens()); @@ -1147,8 +1147,8 @@ struct Parser : ParserBase { template template -auto ComposableParserImpl::operator|(T const &other) const -> Parser { - return Parser() | static_cast(*this) | other; +auto ComposableParserImpl::operator|(T const& other) const -> Parser { + return Parser() | static_cast(*this) | other; } } // namespace detail diff --git a/include/util/command.hpp b/include/util/command.hpp index 4b9decaa8..3e0d4231a 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -13,10 +13,11 @@ #include #endif -#include +#include -extern std::mutex reap_mtx; -extern std::list reap; +#include +#include +#include namespace waybar::util::command { @@ -138,7 +139,7 @@ inline struct res execNoRead(const std::string& cmd) { return {WEXITSTATUS(stat), ""}; } -inline int32_t forkExec(const std::string& cmd) { +inline int32_t forkExec(const std::string& cmd, std::mutex& reap_mtx, std::list& reap) { if (cmd == "") return -1; pid_t pid = fork(); diff --git a/include/util/icon_loader.hpp b/include/util/icon_loader.hpp index 664e510c2..f9256eb59 100644 --- a/include/util/icon_loader.hpp +++ b/include/util/icon_loader.hpp @@ -17,18 +17,18 @@ class IconLoader { std::vector> custom_icon_themes_; Glib::RefPtr default_icon_theme_ = Gtk::IconTheme::get_default(); static std::vector search_prefix(); - static Glib::RefPtr get_app_info_by_name(const std::string &app_id); - static Glib::RefPtr get_desktop_app_info(const std::string &app_id); - static Glib::RefPtr load_icon_from_file(std::string const &icon_path, int size); - static std::string get_icon_name_from_icon_theme(const Glib::RefPtr &icon_theme, - const std::string &app_id); - static bool image_load_icon(Gtk::Image &image, const Glib::RefPtr &icon_theme, + static Glib::RefPtr get_app_info_by_name(const std::string& app_id); + static Glib::RefPtr get_desktop_app_info(const std::string& app_id); + static Glib::RefPtr load_icon_from_file(std::string const& icon_path, int size); + static std::string get_icon_name_from_icon_theme(const Glib::RefPtr& icon_theme, + const std::string& app_id); + static bool image_load_icon(Gtk::Image& image, const Glib::RefPtr& icon_theme, Glib::RefPtr app_info, int size); public: - void add_custom_icon_theme(const std::string &theme_name); - bool image_load_icon(Gtk::Image &image, Glib::RefPtr app_info, + void add_custom_icon_theme(const std::string& theme_name); + bool image_load_icon(Gtk::Image& image, Glib::RefPtr app_info, int size) const; static Glib::RefPtr get_app_info_from_app_id_list( - const std::string &app_id_list); + const std::string& app_id_list); }; diff --git a/include/util/pipewire/privacy_node_info.hpp b/include/util/pipewire/privacy_node_info.hpp index 54da7d169..54acad424 100644 --- a/include/util/pipewire/privacy_node_info.hpp +++ b/include/util/pipewire/privacy_node_info.hpp @@ -33,14 +33,14 @@ class PrivacyNodeInfo { struct spa_hook object_listener; struct spa_hook proxy_listener; - void *data; + void* data; std::string getName(); std::string getIconName(); // Handlers for PipeWire events void handleProxyEventDestroy(); - void handleNodeEventInfo(const struct pw_node_info *info); + void handleNodeEventInfo(const struct pw_node_info* info); }; } // namespace waybar::util::PipewireBackend diff --git a/include/util/ustring_clen.hpp b/include/util/ustring_clen.hpp index cddd2e1ae..63311d53f 100644 --- a/include/util/ustring_clen.hpp +++ b/include/util/ustring_clen.hpp @@ -2,4 +2,4 @@ #include // calculate column width of ustring -int ustring_clen(const Glib::ustring &str); \ No newline at end of file +int ustring_clen(const Glib::ustring& str); \ No newline at end of file diff --git a/meson.build b/meson.build index c6b7f90a4..421a1eefa 100644 --- a/meson.build +++ b/meson.build @@ -188,6 +188,20 @@ src_files = files( 'src/util/css_reload_helper.cpp' ) +gps_src_files = files( + 'src/AModule.cpp', + 'src/ALabel.cpp', + 'src/config.cpp', + 'src/util/prepare_for_sleep.cpp', +) + +cava_src_files = files( + 'src/AModule.cpp', + 'src/ALabel.cpp', + 'src/config.cpp', + 'src/util/prepare_for_sleep.cpp', +) + man_files = files( 'man/waybar-custom.5.scd', 'man/waybar-disk.5.scd', @@ -482,6 +496,9 @@ if get_option('rfkill').enabled() and is_linux src_files += files( 'src/util/rfkill.cpp' ) + gps_src_files += files( + 'src/util/rfkill.cpp' + ) endif if have_chrono_timezones @@ -503,24 +520,60 @@ cava = dependency('libcava', fallback : ['libcava', 'cava_dep'], not_found_message: 'cava is not found. Building waybar without cava') -eproxy = dependency('epoxy', required: false) +epoxy = dependency('epoxy', required: false) if cava.found() add_project_arguments('-DHAVE_LIBCAVA', language: 'cpp') - src_files += files('src/modules/cava/cavaRaw.cpp', - 'src/modules/cava/cava_backend.cpp') + cava_src_files += files('src/modules/cava/cavaRaw.cpp', + 'src/modules/cava/cava_backend.cpp', + 'src/modules/cava/cava_frontend.cpp') man_files += files('man/waybar-cava.5.scd') - if eproxy.found() + if epoxy.found() add_project_arguments('-DHAVE_LIBCAVAGLSL', language: 'cpp') - src_files += files('src/modules/cava/cavaGLSL.cpp') + cava_src_files += files('src/modules/cava/cavaGLSL.cpp') endif endif if libgps.found() - add_project_arguments('-DHAVE_LIBGPS', language: 'cpp') - src_files += files('src/modules/gps.cpp') - man_files += files('man/waybar-gps.5.scd') + add_project_arguments('-DHAVE_LIBGPS', language: 'cpp') + gps_src_files += files('src/modules/gps.cpp') + man_files += files('man/waybar-gps.5.scd') +endif + +if cava.found() + shared_library( + 'waybar-module-cava', + [cava_src_files], + name_prefix: '', + dependencies: [ + fmt, + gtkmm, + jsoncpp, + spdlog, + epoxy, + cava + ], + include_directories: inc_dirs, + install: true, + ) +endif + +if libgps.found() + shared_library( + 'waybar-module-gps', + [gps_src_files], + name_prefix: '', + dependencies: [ + fmt, + gtkmm, + jsoncpp, + spdlog, + libgps + ], + include_directories: inc_dirs, + install: true, + ) endif subdir('protocol') @@ -560,10 +613,7 @@ executable( gtk_layer_shell, libsndio, tz_dep, - xkbregistry, - cava, - eproxy, - libgps + xkbregistry, ], include_directories: inc_dirs, install: true, diff --git a/src/AAppIconLabel.cpp b/src/AAppIconLabel.cpp index a309a6e0c..441a58403 100644 --- a/src/AAppIconLabel.cpp +++ b/src/AAppIconLabel.cpp @@ -14,9 +14,11 @@ namespace waybar { AAppIconLabel::AAppIconLabel(const Json::Value& config, const std::string& name, - const std::string& id, const std::string& format, uint16_t interval, - bool ellipsize, bool enable_click, bool enable_scroll) - : AIconLabel(config, name, id, format, interval, ellipsize, enable_click, enable_scroll) { + const std::string& id, const std::string& format, std::mutex& reap_mtx, + std::list& reap, uint16_t interval, bool ellipsize, + bool enable_click, bool enable_scroll) + : AIconLabel(config, name, id, format, reap_mtx, reap, interval, ellipsize, enable_click, + enable_scroll) { // Icon size if (config["icon-size"].isUInt()) { app_icon_size_ = config["icon-size"].asUInt(); diff --git a/src/AIconLabel.cpp b/src/AIconLabel.cpp index a20c22e90..502387cca 100644 --- a/src/AIconLabel.cpp +++ b/src/AIconLabel.cpp @@ -5,10 +5,11 @@ namespace waybar { -AIconLabel::AIconLabel(const Json::Value &config, const std::string &name, const std::string &id, - const std::string &format, uint16_t interval, bool ellipsize, - bool enable_click, bool enable_scroll) - : ALabel(config, name, id, format, interval, ellipsize, enable_click, enable_scroll) { +AIconLabel::AIconLabel(const Json::Value& config, const std::string& name, const std::string& id, + const std::string& format, std::mutex& reap_mtx, std::list& reap, + uint16_t interval, bool ellipsize, bool enable_click, bool enable_scroll) + : ALabel(config, name, id, format, reap_mtx, reap, interval, ellipsize, enable_click, + enable_scroll) { event_box_.remove(); label_.unset_name(); label_.get_style_context()->remove_class(MODULE_CLASS); diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 4e6d33498..0e6f36269 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -11,9 +11,9 @@ namespace waybar { ALabel::ALabel(const Json::Value& config, const std::string& name, const std::string& id, - const std::string& format, uint16_t interval, bool ellipsize, bool enable_click, - bool enable_scroll) - : AModule(config, name, id, + const std::string& format, std::mutex& reap_mtx, std::list& reap, + uint16_t interval, bool ellipsize, bool enable_click, bool enable_scroll) + : AModule(config, name, id, reap_mtx, reap, config["format-alt"].isString() || config["menu"].isString() || enable_click, enable_scroll), format_(config_["format"].isString() ? config_["format"].asString() : format), diff --git a/src/AModule.cpp b/src/AModule.cpp index c6fdff3ea..bf3ed59f2 100644 --- a/src/AModule.cpp +++ b/src/AModule.cpp @@ -11,9 +11,12 @@ namespace waybar { AModule::AModule(const Json::Value& config, const std::string& name, const std::string& id, - bool enable_click, bool enable_scroll) + std::mutex& reap_mtx, std::list& reap, bool enable_click, + bool enable_scroll) : name_(name), config_(config), + reap_mtx(reap_mtx), + reap(reap), isTooltip{config_["tooltip"].isBool() ? config_["tooltip"].asBool() : true}, isExpand{config_["expand"].isBool() ? config_["expand"].asBool() : false}, distance_scrolled_y_(0.0), @@ -93,7 +96,8 @@ AModule::~AModule() { auto AModule::update() -> void { // Run user-provided update handler if configured if (config_["on-update"].isString()) { - pid_children_.push_back(util::command::forkExec(config_["on-update"].asString())); + pid_children_.push_back( + util::command::forkExec(config_["on-update"].asString(), this->reap_mtx, this->reap)); } } // Get mapping between event name and module action name @@ -186,7 +190,7 @@ bool AModule::handleUserEvent(GdkEventButton* const& e) { format.clear(); } if (!format.empty()) { - pid_children_.push_back(util::command::forkExec(format)); + pid_children_.push_back(util::command::forkExec(format, this->reap_mtx, this->reap)); } dp.emit(); return true; @@ -271,7 +275,8 @@ bool AModule::handleScroll(GdkEventScroll* e) { this->AModule::doAction(eventName); // Second call user scripts if (config_[eventName].isString()) - pid_children_.push_back(util::command::forkExec(config_[eventName].asString())); + pid_children_.push_back( + util::command::forkExec(config_[eventName].asString(), this->reap_mtx, this->reap)); dp.emit(); return true; diff --git a/src/ASlider.cpp b/src/ASlider.cpp index b434be301..aee51e22d 100644 --- a/src/ASlider.cpp +++ b/src/ASlider.cpp @@ -5,8 +5,9 @@ namespace waybar { -ASlider::ASlider(const Json::Value& config, const std::string& name, const std::string& id) - : AModule(config, name, id, false, false), +ASlider::ASlider(const Json::Value& config, const std::string& name, const std::string& id, + std::mutex& reap_mtx, std::list& reap) + : AModule(config, name, id, reap_mtx, reap, false, false), vertical_(config_["orientation"].asString() == "vertical"), scale_(vertical_ ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL) { scale_.set_name(name); @@ -32,4 +33,4 @@ ASlider::ASlider(const Json::Value& config, const std::string& name, const std:: void ASlider::onValueChanged() {} -} // namespace waybar \ No newline at end of file +} // namespace waybar diff --git a/src/client.cpp b/src/client.cpp index f60e01a30..103b093f5 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -11,60 +11,60 @@ #include "util/clara.hpp" #include "util/format.hpp" -waybar::Client *waybar::Client::inst() { - static auto *c = new Client(); +waybar::Client* waybar::Client::inst() { + 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(data); +void waybar::Client::handleGlobal(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { + auto* client = static_cast(data); if (strcmp(interface, zxdg_output_manager_v1_interface.name) == 0 && version >= ZXDG_OUTPUT_V1_NAME_SINCE_VERSION) { - client->xdg_output_manager = static_cast(wl_registry_bind( + client->xdg_output_manager = static_cast(wl_registry_bind( registry, name, &zxdg_output_manager_v1_interface, ZXDG_OUTPUT_V1_NAME_SINCE_VERSION)); } else if (strcmp(interface, zwp_idle_inhibit_manager_v1_interface.name) == 0) { - client->idle_inhibit_manager = static_cast( + client->idle_inhibit_manager = static_cast( wl_registry_bind(registry, name, &zwp_idle_inhibit_manager_v1_interface, 1)); } } -void waybar::Client::handleGlobalRemove(void *data, struct wl_registry * /*registry*/, +void waybar::Client::handleGlobalRemove(void* data, struct wl_registry* /*registry*/, uint32_t name) { // Nothing here } -void waybar::Client::handleOutput(struct waybar_output &output) { +void waybar::Client::handleOutput(struct waybar_output& output) { static const struct zxdg_output_v1_listener xdgOutputListener = { - .logical_position = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {}, - .logical_size = [](void *, struct zxdg_output_v1 *, int32_t, int32_t) {}, + .logical_position = [](void*, struct zxdg_output_v1*, int32_t, int32_t) {}, + .logical_size = [](void*, struct zxdg_output_v1*, int32_t, int32_t) {}, .done = &handleOutputDone, .name = &handleOutputName, .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); } -struct waybar::waybar_output &waybar::Client::getOutput(void *addr) { +struct waybar::waybar_output& waybar::Client::getOutput(void* addr) { auto it = std::find_if(outputs_.begin(), outputs_.end(), - [&addr](const auto &output) { return &output == addr; }); + [&addr](const auto& output) { return &output == addr; }); if (it == outputs_.end()) { throw std::runtime_error("Unable to find valid output"); } return *it; } -std::vector waybar::Client::getOutputConfigs(struct waybar_output &output) { +std::vector waybar::Client::getOutputConfigs(struct waybar_output& output) { return config.getOutputConfigs(output.name, output.identifier); } -void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_output*/) { - auto *client = waybar::Client::inst(); +void waybar::Client::handleOutputDone(void* data, struct zxdg_output_v1* /*xdg_output*/) { + auto* client = waybar::Client::inst(); try { - auto &output = client->getOutput(data); + auto& output = client->getOutput(data); /** * Multiple .done events may arrive in batch. In this case libwayland would queue * xdg_output.destroy and dispatch all pending events, triggering this callback several times @@ -80,44 +80,44 @@ void waybar::Client::handleOutputDone(void *data, struct zxdg_output_v1 * /*xdg_ auto configs = client->getOutputConfigs(output); if (!configs.empty()) { - for (const auto &config : configs) { + for (const auto& config : configs) { client->bars.emplace_back(std::make_unique(&output, config)); } } } - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::warn("caught exception in zxdg_output_v1_listener::done: {}", e.what()); } } -void waybar::Client::handleOutputName(void *data, struct zxdg_output_v1 * /*xdg_output*/, - const char *name) { - auto *client = waybar::Client::inst(); +void waybar::Client::handleOutputName(void* data, struct zxdg_output_v1* /*xdg_output*/, + const char* name) { + auto* client = waybar::Client::inst(); try { - auto &output = client->getOutput(data); + auto& output = client->getOutput(data); output.name = name; - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::warn("caught exception in zxdg_output_v1_listener::name: {}", e.what()); } } -void waybar::Client::handleOutputDescription(void *data, struct zxdg_output_v1 * /*xdg_output*/, - const char *description) { - auto *client = waybar::Client::inst(); +void waybar::Client::handleOutputDescription(void* data, struct zxdg_output_v1* /*xdg_output*/, + const char* description) { + auto* client = waybar::Client::inst(); try { - auto &output = client->getOutput(data); + auto& output = client->getOutput(data); // Description format: "identifier (name)" auto s = std::string(description); auto pos = s.find(" ("); output.identifier = pos != std::string::npos ? s.substr(0, pos) : s; - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::warn("caught exception in zxdg_output_v1_listener::description: {}", e.what()); } } void waybar::Client::handleMonitorAdded(Glib::RefPtr monitor) { - auto &output = outputs_.emplace_back(); + auto& output = outputs_.emplace_back(); output.monitor = std::move(monitor); handleOutput(output); } @@ -146,10 +146,10 @@ void waybar::Client::handleDeferredMonitorRemoval(Glib::RefPtr mon ++it; } } - outputs_.remove_if([&monitor](const auto &output) { return output.monitor == monitor; }); + outputs_.remove_if([&monitor](const auto& output) { return output.monitor == monitor; }); } -const std::string waybar::Client::getStyle(const std::string &style, +const std::string waybar::Client::getStyle(const std::string& style, std::optional appearance = std::nullopt) { auto gtk_settings = Gtk::Settings::get_default(); std::optional css_file; @@ -182,7 +182,7 @@ const std::string waybar::Client::getStyle(const std::string &style, return css_file.value(); }; -auto waybar::Client::setupCss(const std::string &css_file) -> void { +auto waybar::Client::setupCss(const std::string& css_file) -> void { auto screen = Gdk::Screen::get_default(); if (!screen) { throw std::runtime_error("No default screen"); @@ -238,7 +238,7 @@ void waybar::Client::bindInterfaces() { sigc::mem_fun(*this, &Client::handleMonitorRemoved)); } -int waybar::Client::main(int argc, char *argv[]) { +int waybar::Client::main(int argc, char* argv[]) { bool show_help = false; bool show_version = false; std::string config_opt; @@ -299,7 +299,7 @@ int waybar::Client::main(int argc, char *argv[]) { if (m_config.isObject() && m_config["reload_style_on_change"].asBool()) { m_cssReloadHelper->monitorChanges(); } else if (m_config.isArray()) { - for (const auto &conf : m_config) { + for (const auto& conf : m_config) { if (conf["reload_style_on_change"].asBool()) { m_cssReloadHelper->monitorChanges(); break; diff --git a/src/config.cpp b/src/config.cpp index 145056dd9..266342ae5 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -23,10 +23,10 @@ const std::vector Config::CONFIG_DIRS = { "/etc/xdg/waybar/", SYSCONFDIR "/xdg/waybar/", "./resources/", }; -const char *Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR"; +const char* Config::CONFIG_PATH_ENV = "WAYBAR_CONFIG_DIR"; -std::vector Config::tryExpandPath(const std::string &base, - const std::string &filename) { +std::vector Config::tryExpandPath(const std::string& base, + const std::string& filename) { fs::path path; if (!filename.empty()) { @@ -65,18 +65,18 @@ std::vector Config::tryExpandPath(const std::string &base, return results; } -std::optional Config::findConfigPath(const std::vector &names, - const std::vector &dirs) { - if (const char *dir = std::getenv(Config::CONFIG_PATH_ENV)) { - for (const auto &name : names) { +std::optional Config::findConfigPath(const std::vector& names, + const std::vector& dirs) { + if (const char* dir = std::getenv(Config::CONFIG_PATH_ENV)) { + for (const auto& name : names) { if (auto res = tryExpandPath(dir, name); !res.empty()) { return res.front(); } } } - for (const auto &dir : dirs) { - for (const auto &name : names) { + for (const auto& dir : dirs) { + for (const auto& name : names) { if (auto res = tryExpandPath(dir, name); !res.empty()) { return res.front(); } @@ -85,7 +85,7 @@ std::optional Config::findConfigPath(const std::vector return std::nullopt; } -void Config::setupConfig(Json::Value &dst, const std::string &config_file, int depth) { +void Config::setupConfig(Json::Value& dst, const std::string& config_file, int depth) { if (depth > 100) { throw std::runtime_error("Aborting due to likely recursive include in config files"); } @@ -97,7 +97,7 @@ void Config::setupConfig(Json::Value &dst, const std::string &config_file, int d util::JsonParser parser; Json::Value tmp_config = parser.parse(str); if (tmp_config.isArray()) { - for (auto &config_part : tmp_config) { + for (auto& config_part : tmp_config) { resolveConfigIncludes(config_part, depth); } } else { @@ -106,18 +106,18 @@ void Config::setupConfig(Json::Value &dst, const std::string &config_file, int d mergeConfig(dst, tmp_config); } -std::vector Config::findIncludePath(const std::string &name, - const std::vector &dirs) { +std::vector Config::findIncludePath(const std::string& name, + const std::vector& dirs) { auto match1 = tryExpandPath(name, ""); if (!match1.empty()) { return match1; } - if (const char *dir = std::getenv(Config::CONFIG_PATH_ENV)) { + if (const char* dir = std::getenv(Config::CONFIG_PATH_ENV)) { if (auto res = tryExpandPath(dir, name); !res.empty()) { return res; } } - for (const auto &dir : dirs) { + for (const auto& dir : dirs) { if (auto res = tryExpandPath(dir, name); !res.empty()) { return res; } @@ -126,14 +126,14 @@ std::vector Config::findIncludePath(const std::string &name, return {}; } -void Config::resolveConfigIncludes(Json::Value &config, int depth) { +void Config::resolveConfigIncludes(Json::Value& config, int depth) { Json::Value includes = config["include"]; if (includes.isArray()) { - for (const auto &include : includes) { + for (const auto& include : includes) { spdlog::info("Including resource file: {}", include.asString()); auto matches = findIncludePath(include.asString()); if (!matches.empty()) { - for (const auto &match : matches) { + for (const auto& match : matches) { setupConfig(config, match, depth + 1); } } else { @@ -144,7 +144,7 @@ void Config::resolveConfigIncludes(Json::Value &config, int depth) { spdlog::info("Including resource file: {}", includes.asString()); auto matches = findIncludePath(includes.asString()); if (!matches.empty()) { - for (const auto &match : matches) { + for (const auto& match : matches) { setupConfig(config, match, depth + 1); } } else { @@ -153,12 +153,12 @@ void Config::resolveConfigIncludes(Json::Value &config, int depth) { } } -void Config::mergeConfig(Json::Value &a_config_, Json::Value &b_config_) { +void Config::mergeConfig(Json::Value& a_config_, Json::Value& b_config_) { if (!a_config_) { // For the first config a_config_ = b_config_; } else if (a_config_.isObject() && b_config_.isObject()) { - for (const auto &key : b_config_.getMemberNames()) { + for (const auto& key : b_config_.getMemberNames()) { // [] creates key with default value. Use `get` to avoid that. if (a_config_.get(key, Json::Value::nullSingleton()).isObject() && b_config_[key].isObject()) { @@ -174,10 +174,10 @@ void Config::mergeConfig(Json::Value &a_config_, Json::Value &b_config_) { spdlog::error("Cannot merge config, conflicting or invalid JSON types"); } } -bool isValidOutput(const Json::Value &config, const std::string &name, - const std::string &identifier) { +bool isValidOutput(const Json::Value& config, const std::string& name, + const std::string& identifier) { if (config["output"].isArray()) { - for (auto const &output_conf : config["output"]) { + for (auto const& output_conf : config["output"]) { if (output_conf.isString()) { auto config_output = output_conf.asString(); if (config_output.substr(0, 1) == "!") { @@ -211,7 +211,7 @@ bool isValidOutput(const Json::Value &config, const std::string &name, return true; } -void Config::load(const std::string &config) { +void Config::load(const std::string& config) { auto file = config.empty() ? findConfigPath({"config", "config.jsonc"}) : config; if (!file) { throw std::runtime_error("Missing required resource files"); @@ -222,11 +222,11 @@ void Config::load(const std::string &config) { setupConfig(config_, config_file_, 0); } -std::vector Config::getOutputConfigs(const std::string &name, - const std::string &identifier) { +std::vector Config::getOutputConfigs(const std::string& name, + const std::string& identifier) { std::vector configs; if (config_.isArray()) { - for (auto const &config : config_) { + for (auto const& config : config_) { if (config.isObject() && isValidOutput(config, name, identifier)) { configs.push_back(config); } diff --git a/src/factory.cpp b/src/factory.cpp index 2fd3e3b81..70b504f39 100644 --- a/src/factory.cpp +++ b/src/factory.cpp @@ -111,16 +111,32 @@ #ifdef HAVE_SYSTEMD_MONITOR #include "modules/systemd_failed_units.hpp" #endif -#ifdef HAVE_LIBGPS -#include "modules/gps.hpp" -#endif -#include "modules/cava/cava_frontend.hpp" #include "modules/cffi.hpp" #include "modules/custom.hpp" #include "modules/image.hpp" #include "modules/temperature.hpp" #include "modules/user.hpp" +extern std::mutex reap_mtx; +extern std::list reap; + +void* get_symbol(const char* path, const char* symbol) { + void* handle = dlopen(path, RTLD_NOW); + if (!handle) { + auto err = fmt::format("Cannot load shared-object: {}", dlerror()); + throw std::runtime_error(err); + } + dlerror(); + void* resolved = dlsym(handle, symbol); + char* error = dlerror(); + if (error != NULL) { + auto err = fmt::format("Cannot load shared-object functions: {}", error); + dlclose(handle); + throw std::runtime_error(err); + } + return resolved; +} + waybar::Factory::Factory(const Bar& bar, const Json::Value& config) : bar_(bar), config_(config) {} waybar::AModule* waybar::Factory::makeModule(const std::string& name, @@ -131,235 +147,245 @@ waybar::AModule* waybar::Factory::makeModule(const std::string& name, auto id = hash_pos != std::string::npos ? name.substr(hash_pos + 1) : ""; #if defined(__FreeBSD__) || defined(__linux__) if (ref == "battery") { - return new waybar::modules::Battery(id, bar_, config_[name]); + return new waybar::modules::Battery(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_GAMEMODE if (ref == "gamemode") { - return new waybar::modules::Gamemode(id, config_[name]); + return new waybar::modules::Gamemode(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_UPOWER if (ref == "upower") { - return new waybar::modules::UPower(id, config_[name]); + return new waybar::modules::UPower(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_PIPEWIRE if (ref == "privacy") { - return new waybar::modules::privacy::Privacy(id, config_[name], bar_.orientation, pos); + return new waybar::modules::privacy::Privacy(id, config_[name], bar_.orientation, pos, + reap_mtx, reap); } #endif #ifdef HAVE_MPRIS if (ref == "mpris") { - return new waybar::modules::mpris::Mpris(id, config_[name]); + return new waybar::modules::mpris::Mpris(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_SWAY if (ref == "sway/mode") { - return new waybar::modules::sway::Mode(id, config_[name]); + return new waybar::modules::sway::Mode(id, config_[name], reap_mtx, reap); } if (ref == "sway/workspaces") { - return new waybar::modules::sway::Workspaces(id, bar_, config_[name]); + return new waybar::modules::sway::Workspaces(id, bar_, config_[name], reap_mtx, reap); } if (ref == "sway/window") { - return new waybar::modules::sway::Window(id, bar_, config_[name]); + return new waybar::modules::sway::Window(id, bar_, config_[name], reap_mtx, reap); } if (ref == "sway/language") { - return new waybar::modules::sway::Language(id, config_[name]); + return new waybar::modules::sway::Language(id, config_[name], reap_mtx, reap); } if (ref == "sway/scratchpad") { - return new waybar::modules::sway::Scratchpad(id, config_[name]); + return new waybar::modules::sway::Scratchpad(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_WLR_TASKBAR if (ref == "wlr/taskbar") { - return new waybar::modules::wlr::Taskbar(id, bar_, config_[name]); + return new waybar::modules::wlr::Taskbar(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_EXT_WORKSPACES if (ref == "ext/workspaces") { - return new waybar::modules::ext::WorkspaceManager(id, bar_, config_[name]); + return new waybar::modules::ext::WorkspaceManager(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_RIVER if (ref == "river/mode") { - return new waybar::modules::river::Mode(id, bar_, config_[name]); + return new waybar::modules::river::Mode(id, bar_, config_[name], reap_mtx, reap); } if (ref == "river/tags") { - return new waybar::modules::river::Tags(id, bar_, config_[name]); + return new waybar::modules::river::Tags(id, bar_, config_[name], reap_mtx, reap); } if (ref == "river/window") { - return new waybar::modules::river::Window(id, bar_, config_[name]); + return new waybar::modules::river::Window(id, bar_, config_[name], reap_mtx, reap); } if (ref == "river/layout") { - return new waybar::modules::river::Layout(id, bar_, config_[name]); + return new waybar::modules::river::Layout(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_DWL if (ref == "dwl/tags") { - return new waybar::modules::dwl::Tags(id, bar_, config_[name]); + return new waybar::modules::dwl::Tags(id, bar_, config_[name], reap_mtx, reap); } if (ref == "dwl/window") { - return new waybar::modules::dwl::Window(id, bar_, config_[name]); + return new waybar::modules::dwl::Window(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_HYPRLAND if (ref == "hyprland/window") { - return new waybar::modules::hyprland::Window(id, bar_, config_[name]); + return new waybar::modules::hyprland::Window(id, bar_, config_[name], reap_mtx, reap); } if (ref == "hyprland/windowcount") { - return new waybar::modules::hyprland::WindowCount(id, bar_, config_[name]); + return new waybar::modules::hyprland::WindowCount(id, bar_, config_[name], reap_mtx, reap); } if (ref == "hyprland/language") { - return new waybar::modules::hyprland::Language(id, bar_, config_[name]); + return new waybar::modules::hyprland::Language(id, bar_, config_[name], reap_mtx, reap); } if (ref == "hyprland/submap") { - return new waybar::modules::hyprland::Submap(id, bar_, config_[name]); + return new waybar::modules::hyprland::Submap(id, bar_, config_[name], reap_mtx, reap); } if (ref == "hyprland/workspaces") { - return new waybar::modules::hyprland::Workspaces(id, bar_, config_[name]); + return new waybar::modules::hyprland::Workspaces(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_NIRI if (ref == "niri/language") { - return new waybar::modules::niri::Language(id, bar_, config_[name]); + return new waybar::modules::niri::Language(id, bar_, config_[name], reap_mtx, reap); } if (ref == "niri/window") { - return new waybar::modules::niri::Window(id, bar_, config_[name]); + return new waybar::modules::niri::Window(id, bar_, config_[name], reap_mtx, reap); } if (ref == "niri/workspaces") { - return new waybar::modules::niri::Workspaces(id, bar_, config_[name]); + return new waybar::modules::niri::Workspaces(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_WAYFIRE if (ref == "wayfire/window") { - return new waybar::modules::wayfire::Window(id, bar_, config_[name]); + return new waybar::modules::wayfire::Window(id, bar_, config_[name], reap_mtx, reap); } if (ref == "wayfire/workspaces") { - return new waybar::modules::wayfire::Workspaces(id, bar_, config_[name]); + return new waybar::modules::wayfire::Workspaces(id, bar_, config_[name], reap_mtx, reap); } #endif if (ref == "idle_inhibitor") { - return new waybar::modules::IdleInhibitor(id, bar_, config_[name]); + return new waybar::modules::IdleInhibitor(id, bar_, config_[name], reap_mtx, reap); } #if defined(HAVE_MEMORY_LINUX) || defined(HAVE_MEMORY_BSD) if (ref == "memory") { - return new waybar::modules::Memory(id, config_[name]); + return new waybar::modules::Memory(id, config_[name], reap_mtx, reap); } #endif #if defined(HAVE_CPU_LINUX) || defined(HAVE_CPU_BSD) if (ref == "cpu") { - return new waybar::modules::Cpu(id, config_[name]); + return new waybar::modules::Cpu(id, config_[name], reap_mtx, reap); } #if defined(HAVE_CPU_LINUX) if (ref == "cpu_frequency") { - return new waybar::modules::CpuFrequency(id, config_[name]); + return new waybar::modules::CpuFrequency(id, config_[name], reap_mtx, reap); } #endif if (ref == "cpu_usage") { - return new waybar::modules::CpuUsage(id, config_[name]); + return new waybar::modules::CpuUsage(id, config_[name], reap_mtx, reap); } if (ref == "load") { - return new waybar::modules::Load(id, config_[name]); + return new waybar::modules::Load(id, config_[name], reap_mtx, reap); } #endif if (ref == "clock") { - return new waybar::modules::Clock(id, config_[name]); + return new waybar::modules::Clock(id, config_[name], reap_mtx, reap); } if (ref == "user") { - return new waybar::modules::User(id, config_[name]); + return new waybar::modules::User(id, config_[name], reap_mtx, reap); } if (ref == "disk") { - return new waybar::modules::Disk(id, config_[name]); + return new waybar::modules::Disk(id, config_[name], reap_mtx, reap); } if (ref == "image") { - return new waybar::modules::Image(id, config_[name]); + return new waybar::modules::Image(id, config_[name], reap_mtx, reap); } #ifdef HAVE_DBUSMENU if (ref == "tray") { - return new waybar::modules::SNI::Tray(id, bar_, config_[name]); + return new waybar::modules::SNI::Tray(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBNL if (ref == "network") { - return new waybar::modules::Network(id, config_[name]); + return new waybar::modules::Network(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBUDEV if (ref == "backlight") { - return new waybar::modules::Backlight(id, config_[name]); + return new waybar::modules::Backlight(id, config_[name], reap_mtx, reap); } if (ref == "backlight/slider") { - return new waybar::modules::BacklightSlider(id, config_[name]); + return new waybar::modules::BacklightSlider(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBEVDEV if (ref == "keyboard-state") { - return new waybar::modules::KeyboardState(id, bar_, config_[name]); + return new waybar::modules::KeyboardState(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBPULSE if (ref == "pulseaudio") { - return new waybar::modules::Pulseaudio(id, config_[name]); + return new waybar::modules::Pulseaudio(id, config_[name], reap_mtx, reap); } if (ref == "pulseaudio/slider") { - return new waybar::modules::PulseaudioSlider(id, config_[name]); + return new waybar::modules::PulseaudioSlider(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBMPDCLIENT if (ref == "mpd") { - return new waybar::modules::MPD(id, config_[name]); + return new waybar::modules::MPD(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBSNDIO if (ref == "sndio") { - return new waybar::modules::Sndio(id, config_[name]); + return new waybar::modules::Sndio(id, config_[name], reap_mtx, reap); } #endif #if defined(__linux__) if (ref == "bluetooth") { - return new waybar::modules::Bluetooth(id, config_[name]); + return new waybar::modules::Bluetooth(id, config_[name], reap_mtx, reap); } if (ref == "power-profiles-daemon") { - return new waybar::modules::PowerProfilesDaemon(id, config_[name]); + return new waybar::modules::PowerProfilesDaemon(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LOGIND_INHIBITOR if (ref == "inhibitor") { - return new waybar::modules::Inhibitor(id, bar_, config_[name]); + return new waybar::modules::Inhibitor(id, bar_, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBJACK if (ref == "jack") { - return new waybar::modules::JACK(id, config_[name]); + return new waybar::modules::JACK(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBWIREPLUMBER if (ref == "wireplumber") { - return new waybar::modules::Wireplumber(id, config_[name]); + return new waybar::modules::Wireplumber(id, config_[name], reap_mtx, reap); } #endif if (ref == "cava") { - return waybar::modules::cava::getModule(id, config_[name]); + AModule* (*constructor)(const std::string&, const Json::Value&, std::mutex&, + std::list&); + void* symbol = get_symbol("waybar-module-cava.so", "new_cava"); + constructor = reinterpret_cast(symbol); + return constructor(id, config_[name], reap_mtx, reap); } #ifdef HAVE_SYSTEMD_MONITOR if (ref == "systemd-failed-units") { - return new waybar::modules::SystemdFailedUnits(id, config_[name]); + return new waybar::modules::SystemdFailedUnits(id, config_[name], reap_mtx, reap); } #endif #ifdef HAVE_LIBGPS if (ref == "gps") { - return new waybar::modules::Gps(id, config_[name]); + AModule* (*constructor)(const std::string&, const Json::Value&, std::mutex&, + std::list&); + void* symbol = get_symbol("waybar-module-gps.so", "new_gps"); + constructor = reinterpret_cast(symbol); + return constructor(id, config_[name], reap_mtx, reap); } #endif if (ref == "temperature") { - return new waybar::modules::Temperature(id, config_[name]); + return new waybar::modules::Temperature(id, config_[name], reap_mtx, reap); } if (ref.compare(0, 7, "custom/") == 0 && ref.size() > 7) { - return new waybar::modules::Custom(ref.substr(7), id, config_[name], bar_.output->name); + return new waybar::modules::Custom(ref.substr(7), id, config_[name], bar_.output->name, + reap_mtx, reap); } if (ref.compare(0, 5, "cffi/") == 0 && ref.size() > 5) { - return new waybar::modules::CFFI(ref.substr(5), id, config_[name]); + return new waybar::modules::CFFI(ref.substr(5), id, config_[name], reap_mtx, reap); } } catch (const std::exception& e) { auto err = fmt::format("Disabling module \"{}\", {}", name, e.what()); diff --git a/src/group.cpp b/src/group.cpp index 294743d73..06dfe6a5e 100644 --- a/src/group.cpp +++ b/src/group.cpp @@ -7,6 +7,9 @@ #include "gtkmm/enums.h" #include "gtkmm/widget.h" +extern std::mutex reap_mtx; +extern std::list reap; + namespace waybar { Gtk::RevealerTransitionType getPreferredTransitionType(bool is_vertical) { @@ -26,7 +29,7 @@ Gtk::RevealerTransitionType getPreferredTransitionType(bool is_vertical) { Group::Group(const std::string& name, const std::string& id, const Json::Value& config, bool vertical) - : AModule(config, name, id, true, false), + : AModule(config, name, id, reap_mtx, reap, true, false), box{vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0}, revealer_box{vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0} { box.set_name(name_); diff --git a/src/modules/backlight.cpp b/src/modules/backlight.cpp index 3c50f1d1f..9fe7e286b 100644 --- a/src/modules/backlight.cpp +++ b/src/modules/backlight.cpp @@ -13,8 +13,9 @@ #include "util/backend_common.hpp" #include "util/backlight_backend.hpp" -waybar::modules::Backlight::Backlight(const std::string &id, const Json::Value &config) - : ALabel(config, "backlight", id, "{percent}%", 2), +waybar::modules::Backlight::Backlight(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "backlight", id, "{percent}%", reap_mtx, reap, 2), preferred_device_(config["device"].isString() ? config["device"].asString() : ""), backend(interval_, [this] { dp.emit(); }) { dp.emit(); @@ -79,7 +80,7 @@ auto waybar::modules::Backlight::update() -> void { ALabel::update(); } -bool waybar::modules::Backlight::handleScroll(GdkEventScroll *e) { +bool waybar::modules::Backlight::handleScroll(GdkEventScroll* e) { // Check if the user has set a custom command for scrolling if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) { return AModule::handleScroll(e); diff --git a/src/modules/backlight_slider.cpp b/src/modules/backlight_slider.cpp index 6269dddbf..2daa43605 100644 --- a/src/modules/backlight_slider.cpp +++ b/src/modules/backlight_slider.cpp @@ -4,8 +4,9 @@ namespace waybar::modules { -BacklightSlider::BacklightSlider(const std::string& id, const Json::Value& config) - : ASlider(config, "backlight-slider", id), +BacklightSlider::BacklightSlider(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ASlider(config, "backlight-slider", id, reap_mtx, reap), interval_(config_["interval"].isUInt() ? config_["interval"].asUInt() : 1000), preferred_device_(config["device"].isString() ? config["device"].asString() : ""), backend(interval_, [this] { this->dp.emit(); }) {} @@ -20,4 +21,4 @@ void BacklightSlider::onValueChanged() { backend.set_scaled_brightness(preferred_device_, brightness); } -} // namespace waybar::modules \ No newline at end of file +} // namespace waybar::modules diff --git a/src/modules/battery.cpp b/src/modules/battery.cpp index c706eb3cd..7e0cc2c90 100644 --- a/src/modules/battery.cpp +++ b/src/modules/battery.cpp @@ -12,8 +12,9 @@ #include #include -waybar::modules::Battery::Battery(const std::string& id, const Bar& bar, const Json::Value& config) - : ALabel(config, "battery", id, "{capacity}%", 60), last_event_(""), bar_(bar) { +waybar::modules::Battery::Battery(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "battery", id, "{capacity}%", reap_mtx, reap, 60), last_event_(""), bar_(bar) { #if defined(__linux__) battery_watch_fd_ = inotify_init1(IN_CLOEXEC); if (battery_watch_fd_ == -1) { diff --git a/src/modules/bluetooth.cpp b/src/modules/bluetooth.cpp index 06475a2e5..aa3b749be 100644 --- a/src/modules/bluetooth.cpp +++ b/src/modules/bluetooth.cpp @@ -85,8 +85,9 @@ auto getUcharProperty(GDBusProxy* proxy, const char* property_name) -> unsigned } // namespace -waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config) - : ALabel(config, "bluetooth", id, " {status}", 10), +waybar::modules::Bluetooth::Bluetooth(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "bluetooth", id, " {status}", reap_mtx, reap, 10), #ifdef WANT_RFKILL rfkill_{RFKILL_TYPE_BLUETOOTH}, #endif diff --git a/src/modules/cava/cavaGLSL.cpp b/src/modules/cava/cavaGLSL.cpp index 4ab03bcd5..8d9d0a5b9 100644 --- a/src/modules/cava/cavaGLSL.cpp +++ b/src/modules/cava/cavaGLSL.cpp @@ -4,8 +4,9 @@ #include -waybar::modules::cava::CavaGLSL::CavaGLSL(const std::string& id, const Json::Value& config) - : AModule(config, "cavaGLSL", id, false, false), +waybar::modules::cava::CavaGLSL::CavaGLSL(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AModule(config, "cavaGLSL", id, reap_mtx, reap, false, false), backend_{waybar::modules::cava::CavaBackend::inst(config)} { set_name(name_); if (config_["hide_on_silence"].isBool()) hide_on_silence_ = config_["hide_on_silence"].asBool(); diff --git a/src/modules/cava/cavaRaw.cpp b/src/modules/cava/cavaRaw.cpp index edec902b8..ab82d115d 100644 --- a/src/modules/cava/cavaRaw.cpp +++ b/src/modules/cava/cavaRaw.cpp @@ -2,8 +2,9 @@ #include -waybar::modules::cava::Cava::Cava(const std::string& id, const Json::Value& config) - : ALabel(config, "cava", id, "{}", 60, false, false, false), +waybar::modules::cava::Cava::Cava(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "cava", id, "{}", reap_mtx, reap, 60, false, false, false), backend_{waybar::modules::cava::CavaBackend::inst(config)} { if (config_["hide_on_silence"].isBool()) hide_on_silence_ = config_["hide_on_silence"].asBool(); if (config_["format_silent"].isString()) format_silent_ = config_["format_silent"].asString(); diff --git a/src/modules/cava/cava_frontend.cpp b/src/modules/cava/cava_frontend.cpp new file mode 100644 index 000000000..25dcea802 --- /dev/null +++ b/src/modules/cava/cava_frontend.cpp @@ -0,0 +1,32 @@ +#include "modules/cava/cavaRaw.hpp" +#include "modules/cava/cava_backend.hpp" +#ifdef HAVE_LIBCAVAGLSL +#include "modules/cava/cavaGLSL.hpp" +#endif + +namespace waybar::modules::cava { +AModule* getModule(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) { + const std::shared_ptr backend_{waybar::modules::cava::CavaBackend::inst(config)}; + switch (backend_->getPrm()->output) { + case ::cava::output_method::OUTPUT_RAW: + return new waybar::modules::cava::Cava(id, config, reap_mtx, reap); + break; +#ifdef HAVE_LIBCAVAGLSL + case ::cava::output_method::OUTPUT_SDL_GLSL: + return new waybar::modules::cava::CavaGLSL(id, config, reap_mtx, reap); + break; +#endif + default: + break; + } + throw std::runtime_error("Unknown module"); +}; +} // namespace waybar::modules::cava + +extern "C" { +waybar::AModule* new_cava(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) { + return waybar::modules::cava::getModule(id, config, reap_mtx, reap); +} +} diff --git a/src/modules/cffi.cpp b/src/modules/cffi.cpp index 5c095f46a..40a27a861 100644 --- a/src/modules/cffi.cpp +++ b/src/modules/cffi.cpp @@ -9,8 +9,9 @@ namespace waybar::modules { -CFFI::CFFI(const std::string& name, const std::string& id, const Json::Value& config) - : AModule(config, name, id, true, true) { +CFFI::CFFI(const std::string& name, const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AModule(config, name, id, reap_mtx, reap, true, true) { const auto dynlib_path = config_["module_path"].asString(); if (dynlib_path.empty()) { throw std::runtime_error{"Missing or empty 'module_path' in module config"}; diff --git a/src/modules/clock.cpp b/src/modules/clock.cpp index 5fe5407bb..14c76b44e 100644 --- a/src/modules/clock.cpp +++ b/src/modules/clock.cpp @@ -20,8 +20,9 @@ using namespace date; namespace fmt_lib = waybar::util::date::format; -waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config) - : ALabel(config, "clock", id, "{:%H:%M}", 60, false, false, true), +waybar::modules::Clock::Clock(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "clock", id, "{:%H:%M}", reap_mtx, reap, 60, false, false, true), m_locale_{std::locale(config_["locale"].isString() ? config_["locale"].asString() : "")}, m_tlpFmt_{(config_["tooltip-format"].isString()) ? config_["tooltip-format"].asString() : ""}, m_tooltip_{new Gtk::Label()}, diff --git a/src/modules/cpu.cpp b/src/modules/cpu.cpp index 0703eaf7c..175adb893 100644 --- a/src/modules/cpu.cpp +++ b/src/modules/cpu.cpp @@ -13,8 +13,9 @@ #include #endif -waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config) - : ALabel(config, "cpu", id, "{usage}%", 10) { +waybar::modules::Cpu::Cpu(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "cpu", id, "{usage}%", reap_mtx, reap, 10) { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); diff --git a/src/modules/cpu_frequency/common.cpp b/src/modules/cpu_frequency/common.cpp index e47364ba7..cff5d78a1 100644 --- a/src/modules/cpu_frequency/common.cpp +++ b/src/modules/cpu_frequency/common.cpp @@ -9,8 +9,9 @@ #include #endif -waybar::modules::CpuFrequency::CpuFrequency(const std::string& id, const Json::Value& config) - : ALabel(config, "cpu_frequency", id, "{avg_frequency}", 10) { +waybar::modules::CpuFrequency::CpuFrequency(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "cpu_frequency", id, "{avg_frequency}", reap_mtx, reap, 10) { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); diff --git a/src/modules/cpu_usage/common.cpp b/src/modules/cpu_usage/common.cpp index e39479678..bf11749ee 100644 --- a/src/modules/cpu_usage/common.cpp +++ b/src/modules/cpu_usage/common.cpp @@ -9,8 +9,9 @@ #include #endif -waybar::modules::CpuUsage::CpuUsage(const std::string& id, const Json::Value& config) - : ALabel(config, "cpu_usage", id, "{usage}%", 10) { +waybar::modules::CpuUsage::CpuUsage(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "cpu_usage", id, "{usage}%", reap_mtx, reap, 10) { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index d75633e9c..1e5a1b97b 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -5,8 +5,9 @@ #include "util/scope_guard.hpp" waybar::modules::Custom::Custom(const std::string& name, const std::string& id, - const Json::Value& config, const std::string& output_name) - : ALabel(config, "custom-" + name, id, "{}"), + const Json::Value& config, const std::string& output_name, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "custom-" + name, id, "{}", reap_mtx, reap), name_(name), output_name_(output_name), id_(id), diff --git a/src/modules/disk.cpp b/src/modules/disk.cpp index ef257b721..085479534 100644 --- a/src/modules/disk.cpp +++ b/src/modules/disk.cpp @@ -2,8 +2,9 @@ using namespace waybar::util; -waybar::modules::Disk::Disk(const std::string& id, const Json::Value& config) - : ALabel(config, "disk", id, "{}%", 30), path_("/") { +waybar::modules::Disk::Disk(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "disk", id, "{}%", reap_mtx, reap, 30), path_("/") { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); @@ -112,4 +113,4 @@ float waybar::modules::Disk::calc_specific_divisor(std::string divisor) { } else { // default to Bytes if it is anything that we don't recongnise return 1.0; } -} \ No newline at end of file +} diff --git a/src/modules/dwl/tags.cpp b/src/modules/dwl/tags.cpp index c916eaf10..c34acc0a7 100644 --- a/src/modules/dwl/tags.cpp +++ b/src/modules/dwl/tags.cpp @@ -21,39 +21,39 @@ wl_array tags, layouts; static uint num_tags = 0; -static void toggle_visibility(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) { +static void toggle_visibility(void* data, zdwl_ipc_output_v2* zdwl_output_v2) { // Intentionally empty } -static void active(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t active) { +static void active(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t active) { // Intentionally empty } -static void set_tag(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t tag, uint32_t state, +static void set_tag(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused) { - static_cast(data)->handle_view_tags(tag, state, clients, focused); + static_cast(data)->handle_view_tags(tag, state, clients, focused); num_tags = (state & ZDWL_IPC_OUTPUT_V2_TAG_STATE_ACTIVE) ? num_tags | (1 << tag) : num_tags & ~(1 << tag); } -static void set_layout_symbol(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *layout) { +static void set_layout_symbol(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* layout) { // Intentionally empty } -static void title(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *title) { +static void title(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* title) { // Intentionally empty } -static void dwl_frame(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) { +static void dwl_frame(void* data, zdwl_ipc_output_v2* zdwl_output_v2) { // Intentionally empty } -static void set_layout(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t layout) { +static void set_layout(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t layout) { // Intentionally empty } -static void appid(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *appid) { +static void appid(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* appid) { // Intentionally empty }; @@ -68,35 +68,36 @@ static const zdwl_ipc_output_v2_listener output_status_listener_impl{ .frame = dwl_frame, }; -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version) { +static void handle_global(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) { - static_cast(data)->status_manager_ = static_cast( - (zdwl_ipc_manager_v2 *)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1)); + static_cast(data)->status_manager_ = static_cast( + (zdwl_ipc_manager_v2*)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1)); } if (std::strcmp(interface, wl_seat_interface.name) == 0) { version = std::min(version, 1); - static_cast(data)->seat_ = static_cast( - wl_registry_bind(registry, name, &wl_seat_interface, version)); + static_cast(data)->seat_ = + static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); } } -static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { /* Ignore event */ } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &config) - : waybar::AModule(config, "tags", id, false, false), +Tags::Tags(const std::string& id, const waybar::Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : waybar::AModule(config, "tags", id, reap_mtx, reap, false, false), status_manager_{nullptr}, seat_{nullptr}, bar_(bar), box_{bar.orientation, 0}, output_status_{nullptr} { - struct wl_display *display = Client::inst()->wl_display; - struct wl_registry *registry = wl_display_get_registry(display); + struct wl_display* display = Client::inst()->wl_display; + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); wl_display_roundtrip(display); @@ -133,8 +134,8 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con } uint32_t i = 1; - for (const auto &tag_label : tag_labels) { - Gtk::Button &button = buttons_.emplace_back(tag_label); + for (const auto& tag_label : tag_labels) { + Gtk::Button& button = buttons_.emplace_back(tag_label); button.set_relief(Gtk::RELIEF_NONE); box_.pack_start(button, false, false, 0); if (!config_["disable-click"].asBool()) { @@ -147,7 +148,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con i <<= 1; } - struct wl_output *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); + struct wl_output* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); output_status_ = zdwl_ipc_manager_v2_get_output(status_manager_, output); zdwl_ipc_output_v2_add_listener(output_status_, &output_status_listener_impl, this); @@ -170,7 +171,7 @@ void Tags::handle_primary_clicked(uint32_t tag) { zdwl_ipc_output_v2_set_tags(output_status_, tag, 1); } -bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) { +bool Tags::handle_button_press(GdkEventButton* event_button, uint32_t tag) { if (event_button->type == GDK_BUTTON_PRESS && event_button->button == 3) { if (!output_status_) return true; zdwl_ipc_output_v2_set_tags(output_status_, num_tags ^ tag, 0); @@ -180,7 +181,7 @@ bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) { void Tags::handle_view_tags(uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused) { // First clear all occupied state - auto &button = buttons_[tag]; + auto& button = buttons_[tag]; if (clients) { button.get_style_context()->add_class("occupied"); } else { diff --git a/src/modules/dwl/window.cpp b/src/modules/dwl/window.cpp index a960a1f04..cfe89ff21 100644 --- a/src/modules/dwl/window.cpp +++ b/src/modules/dwl/window.cpp @@ -14,37 +14,37 @@ namespace waybar::modules::dwl { -static void toggle_visibility(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) { +static void toggle_visibility(void* data, zdwl_ipc_output_v2* zdwl_output_v2) { // Intentionally empty } -static void active(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t active) { +static void active(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t active) { // Intentionally empty } -static void set_tag(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t tag, uint32_t state, +static void set_tag(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t tag, uint32_t state, uint32_t clients, uint32_t focused) { // Intentionally empty } -static void set_layout_symbol(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *layout) { - static_cast(data)->handle_layout_symbol(layout); +static void set_layout_symbol(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* layout) { + static_cast(data)->handle_layout_symbol(layout); } -static void title(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *title) { - static_cast(data)->handle_title(title); +static void title(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* title) { + static_cast(data)->handle_title(title); } -static void dwl_frame(void *data, zdwl_ipc_output_v2 *zdwl_output_v2) { - static_cast(data)->handle_frame(); +static void dwl_frame(void* data, zdwl_ipc_output_v2* zdwl_output_v2) { + static_cast(data)->handle_frame(); } -static void set_layout(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, uint32_t layout) { - static_cast(data)->handle_layout(layout); +static void set_layout(void* data, zdwl_ipc_output_v2* zdwl_output_v2, uint32_t layout) { + static_cast(data)->handle_layout(layout); } -static void appid(void *data, zdwl_ipc_output_v2 *zdwl_output_v2, const char *appid) { - static_cast(data)->handle_appid(appid); +static void appid(void* data, zdwl_ipc_output_v2* zdwl_output_v2, const char* appid) { + static_cast(data)->handle_appid(appid); }; static const zdwl_ipc_output_v2_listener output_status_listener_impl{ @@ -58,25 +58,26 @@ static const zdwl_ipc_output_v2_listener output_status_listener_impl{ .frame = dwl_frame, }; -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version) { +static void handle_global(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { if (std::strcmp(interface, zdwl_ipc_manager_v2_interface.name) == 0) { - static_cast(data)->status_manager_ = static_cast( - (zdwl_ipc_manager_v2 *)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1)); + static_cast(data)->status_manager_ = static_cast( + (zdwl_ipc_manager_v2*)wl_registry_bind(registry, name, &zdwl_ipc_manager_v2_interface, 1)); } } -static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { /* Ignore event */ } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -Window::Window(const std::string &id, const Bar &bar, const Json::Value &config) - : AAppIconLabel(config, "window", id, "{}", 0, true), bar_(bar) { - struct wl_display *display = Client::inst()->wl_display; - struct wl_registry *registry = wl_display_get_registry(display); +Window::Window(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AAppIconLabel(config, "window", id, "{}", reap_mtx, reap, 0, true), bar_(bar) { + struct wl_display* display = Client::inst()->wl_display; + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); wl_display_roundtrip(display); @@ -86,7 +87,7 @@ Window::Window(const std::string &id, const Bar &bar, const Json::Value &config) return; } - struct wl_output *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); + struct wl_output* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); output_status_ = zdwl_ipc_manager_v2_get_output(status_manager_, output); zdwl_ipc_output_v2_add_listener(output_status_, &output_status_listener_impl, this); zdwl_ipc_manager_v2_destroy(status_manager_); @@ -98,11 +99,11 @@ Window::~Window() { } } -void Window::handle_title(const char *title) { title_ = Glib::Markup::escape_text(title); } +void Window::handle_title(const char* title) { title_ = Glib::Markup::escape_text(title); } -void Window::handle_appid(const char *appid) { appid_ = Glib::Markup::escape_text(appid); } +void Window::handle_appid(const char* appid) { appid_ = Glib::Markup::escape_text(appid); } -void Window::handle_layout_symbol(const char *layout_symbol) { +void Window::handle_layout_symbol(const char* layout_symbol) { layout_symbol_ = Glib::Markup::escape_text(layout_symbol); } diff --git a/src/modules/ext/workspace_manager.cpp b/src/modules/ext/workspace_manager.cpp index 64c4be234..74c2f66c9 100644 --- a/src/modules/ext/workspace_manager.cpp +++ b/src/modules/ext/workspace_manager.cpp @@ -20,9 +20,12 @@ uint32_t WorkspaceManager::group_global_id = 0; uint32_t WorkspaceManager::workspace_global_id = 0; std::map Workspace::icon_map_; -WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar, - const Json::Value &config) - : waybar::AModule(config, "workspaces", id, false, false), bar_(bar), box_(bar.orientation, 0) { +WorkspaceManager::WorkspaceManager(const std::string& id, const waybar::Bar& bar, + const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : waybar::AModule(config, "workspaces", id, reap_mtx, reap, false, false), + bar_(bar), + box_(bar.orientation, 0) { add_registry_listener(this); // parse configuration @@ -70,7 +73,7 @@ WorkspaceManager::~WorkspaceManager() { groups_.clear(); if (ext_manager_ != nullptr) { - auto *display = Client::inst()->wl_display; + auto* display = Client::inst()->wl_display; // Send `stop` request and wait for one roundtrip. ext_workspace_manager_v1_stop(ext_manager_); wl_display_roundtrip(display); @@ -84,7 +87,7 @@ WorkspaceManager::~WorkspaceManager() { spdlog::debug("[ext/workspaces]: Workspace manager destroyed"); } -void WorkspaceManager::register_manager(wl_registry *registry, uint32_t name, uint32_t version) { +void WorkspaceManager::register_manager(wl_registry* registry, uint32_t name, uint32_t version) { if (ext_manager_ != nullptr) { spdlog::warn("[ext/workspaces]: Register workspace manager again although already registered!"); return; @@ -99,7 +102,7 @@ void WorkspaceManager::register_manager(wl_registry *registry, uint32_t name, ui void WorkspaceManager::remove_workspace_group(uint32_t id) { const auto it = - std::find_if(groups_.begin(), groups_.end(), [id](const auto &g) { return g->id() == id; }); + std::find_if(groups_.begin(), groups_.end(), [id](const auto& g) { return g->id() == id; }); if (it == groups_.end()) { spdlog::warn("[ext/workspaces]: Can't find workspace group with id {}", id); @@ -111,7 +114,7 @@ void WorkspaceManager::remove_workspace_group(uint32_t id) { void WorkspaceManager::remove_workspace(uint32_t id) { const auto it = std::find_if(workspaces_.begin(), workspaces_.end(), - [id](const auto &w) { return w->id() == id; }); + [id](const auto& w) { return w->id() == id; }); if (it == workspaces_.end()) { spdlog::warn("[ext/workspaces]: Can't find workspace with id {}", id); @@ -121,13 +124,13 @@ void WorkspaceManager::remove_workspace(uint32_t id) { workspaces_.erase(it); } -void WorkspaceManager::handle_workspace_group(ext_workspace_group_handle_v1 *handle) { +void WorkspaceManager::handle_workspace_group(ext_workspace_group_handle_v1* handle) { const auto new_id = ++group_global_id; groups_.push_back(std::make_unique(*this, handle, new_id)); spdlog::debug("[ext/workspaces]: Workspace group {} created", new_id); } -void WorkspaceManager::handle_workspace(ext_workspace_handle_v1 *handle) { +void WorkspaceManager::handle_workspace(ext_workspace_handle_v1* handle) { const auto new_id = ++workspace_global_id; const auto new_name = std::to_string(++workspace_name); workspaces_.push_back(std::make_unique(config_, *this, handle, new_id, new_name)); @@ -158,7 +161,7 @@ void WorkspaceManager::update() { AModule::update(); } -bool WorkspaceManager::has_button(const Gtk::Button *button) { +bool WorkspaceManager::has_button(const Gtk::Button* button) { const auto buttons = box_.get_children(); return std::find(buttons.begin(), buttons.end(), button) != buttons.end(); } @@ -166,20 +169,20 @@ bool WorkspaceManager::has_button(const Gtk::Button *button) { void WorkspaceManager::sort_workspaces() { // determine if workspace ID's and names can be sort numerically or literally - auto is_numeric = [](const std::string &s) { + auto is_numeric = [](const std::string& s) { return !s.empty() && std::all_of(s.begin(), s.end(), ::isdigit); }; auto sort_by_workspace_id_numerically = std::all_of(workspaces_.begin(), workspaces_.end(), - [&](const auto &w) { return is_numeric(w->workspace_id()); }); + [&](const auto& w) { return is_numeric(w->workspace_id()); }); auto sort_by_name_numerically = std::all_of(workspaces_.begin(), workspaces_.end(), - [&](const auto &w) { return is_numeric(w->name()); }); + [&](const auto& w) { return is_numeric(w->name()); }); // sort based on configuration setting with sort-by-id as fallback - std::sort(workspaces_.begin(), workspaces_.end(), [&](const auto &w1, const auto &w2) { + std::sort(workspaces_.begin(), workspaces_.end(), [&](const auto& w1, const auto& w2) { if (sort_by_id_ || (!sort_by_name_ && !sort_by_coordinates_)) { if (w1->workspace_id() == w2->workspace_id()) { return w1->id() < w2->id(); @@ -218,7 +221,7 @@ void WorkspaceManager::sort_workspaces() { } void WorkspaceManager::clear_buttons() { - for (const auto &workspace : workspaces_) { + for (const auto& workspace : workspaces_) { if (has_button(&workspace->button())) { box_.remove(workspace->button()); } @@ -226,13 +229,13 @@ void WorkspaceManager::clear_buttons() { } void WorkspaceManager::update_buttons() { - const auto *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); + const auto* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); // go through all workspace - for (const auto &workspace : workspaces_) { + for (const auto& workspace : workspaces_) { const bool workspace_on_any_group_for_output = - std::any_of(groups_.begin(), groups_.end(), [&](const auto &group) { + std::any_of(groups_.begin(), groups_.end(), [&](const auto& group) { const bool group_on_output = group->has_output(output) || all_outputs_; const bool workspace_on_group = group->has_workspace(workspace->handle()); return group_on_output && workspace_on_group; @@ -259,7 +262,7 @@ void WorkspaceManager::update_buttons() { // WorkspaceGroup -WorkspaceGroup::WorkspaceGroup(WorkspaceManager &manager, ext_workspace_group_handle_v1 *handle, +WorkspaceGroup::WorkspaceGroup(WorkspaceManager& manager, ext_workspace_group_handle_v1* handle, uint32_t id) : workspaces_manager_(manager), ext_handle_(handle), id_(id) { add_workspace_group_listener(ext_handle_, this); @@ -272,11 +275,11 @@ WorkspaceGroup::~WorkspaceGroup() { spdlog::debug("[ext/workspaces]: Workspace group {} destroyed", id_); } -bool WorkspaceGroup::has_output(const wl_output *output) { +bool WorkspaceGroup::has_output(const wl_output* output) { return std::find(outputs_.begin(), outputs_.end(), output) != outputs_.end(); } -bool WorkspaceGroup::has_workspace(const ext_workspace_handle_v1 *workspace) { +bool WorkspaceGroup::has_workspace(const ext_workspace_handle_v1* workspace) { return std::find(workspaces_.begin(), workspaces_.end(), workspace) != workspaces_.end(); } @@ -288,20 +291,20 @@ void WorkspaceGroup::handle_capabilities(uint32_t capabilities) { } } -void WorkspaceGroup::handle_output_enter(wl_output *output) { outputs_.push_back(output); } +void WorkspaceGroup::handle_output_enter(wl_output* output) { outputs_.push_back(output); } -void WorkspaceGroup::handle_output_leave(wl_output *output) { +void WorkspaceGroup::handle_output_leave(wl_output* output) { const auto it = std::find(outputs_.begin(), outputs_.end(), output); if (it != outputs_.end()) { outputs_.erase(it); } } -void WorkspaceGroup::handle_workspace_enter(ext_workspace_handle_v1 *handle) { +void WorkspaceGroup::handle_workspace_enter(ext_workspace_handle_v1* handle) { workspaces_.push_back(handle); } -void WorkspaceGroup::handle_workspace_leave(ext_workspace_handle_v1 *handle) { +void WorkspaceGroup::handle_workspace_leave(ext_workspace_handle_v1* handle) { const auto it = std::find(workspaces_.begin(), workspaces_.end(), handle); if (it != workspaces_.end()) { workspaces_.erase(it); @@ -315,30 +318,30 @@ void WorkspaceGroup::handle_removed() { // Workspace -Workspace::Workspace(const Json::Value &config, WorkspaceManager &manager, - ext_workspace_handle_v1 *handle, uint32_t id, const std::string &name) +Workspace::Workspace(const Json::Value& config, WorkspaceManager& manager, + ext_workspace_handle_v1* handle, uint32_t id, const std::string& name) : workspace_manager_(manager), ext_handle_(handle), id_(id), workspace_id_(name), name_(name) { add_workspace_listener(ext_handle_, this); // parse configuration - const auto &config_active_only = config["active-only"]; + const auto& config_active_only = config["active-only"]; if (config_active_only.isBool()) { active_only_ = config_active_only.asBool(); } - const auto &config_ignore_hidden = config["ignore-hidden"]; + const auto& config_ignore_hidden = config["ignore-hidden"]; if (config_ignore_hidden.isBool()) { ignore_hidden_ = config_ignore_hidden.asBool(); } - const auto &config_format = config["format"]; + const auto& config_format = config["format"]; format_ = config_format.isString() ? config_format.asString() : "{name}"; with_icon_ = format_.find("{icon}") != std::string::npos; if (with_icon_ && icon_map_.empty()) { - const auto &format_icons = config["format-icons"]; - for (auto &n : format_icons.getMemberNames()) { + const auto& format_icons = config["format-icons"]; + for (auto& n : format_icons.getMemberNames()) { icon_map_.emplace(n, format_icons[n].asString()); } } @@ -413,19 +416,19 @@ void Workspace::update() { fmt::arg("icon", with_icon_ ? icon() : ""))); } -void Workspace::handle_id(const std::string &id) { +void Workspace::handle_id(const std::string& id) { spdlog::debug("[ext/workspaces]: ID for workspace {}: {}", id_, id); workspace_id_ = id; workspace_manager_.set_needs_sorting(); } -void Workspace::handle_name(const std::string &name) { +void Workspace::handle_name(const std::string& name) { spdlog::debug("[ext/workspaces]: Name for workspace {}: {}", id_, name); name_ = name; workspace_manager_.set_needs_sorting(); } -void Workspace::handle_coordinates(const std::vector &coordinates) { +void Workspace::handle_coordinates(const std::vector& coordinates) { coordinates_ = coordinates; workspace_manager_.set_needs_sorting(); } @@ -453,7 +456,7 @@ void Workspace::handle_removed() { workspace_manager_.remove_workspace(id_); } -bool Workspace::handle_clicked(const GdkEventButton *button) const { +bool Workspace::handle_clicked(const GdkEventButton* button) const { std::string action; if (button->button == GDK_BUTTON_PRIMARY) { action = on_click_action_; diff --git a/src/modules/ext/workspace_manager_binding.cpp b/src/modules/ext/workspace_manager_binding.cpp index 2d9c6b48f..91110faf7 100644 --- a/src/modules/ext/workspace_manager_binding.cpp +++ b/src/modules/ext/workspace_manager_binding.cpp @@ -9,44 +9,44 @@ namespace waybar::modules::ext { -static void handle_global(void *data, wl_registry *registry, uint32_t name, const char *interface, +static void handle_global(void* data, wl_registry* registry, uint32_t name, const char* interface, uint32_t version) { if (std::strcmp(interface, ext_workspace_manager_v1_interface.name) == 0) { - static_cast(data)->register_manager(registry, name, version); + static_cast(data)->register_manager(registry, name, version); } } -static void handle_global_remove(void *data, wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, wl_registry* registry, uint32_t name) { /* Nothing to do here */ } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -void add_registry_listener(void *data) { - wl_display *display = Client::inst()->wl_display; - wl_registry *registry = wl_display_get_registry(display); +void add_registry_listener(void* data) { + wl_display* display = Client::inst()->wl_display; + wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, data); wl_display_roundtrip(display); } static void workspace_manager_handle_workspace_group( - void *data, ext_workspace_manager_v1 *_, ext_workspace_group_handle_v1 *workspace_group) { - static_cast(data)->handle_workspace_group(workspace_group); + void* data, ext_workspace_manager_v1* _, ext_workspace_group_handle_v1* workspace_group) { + static_cast(data)->handle_workspace_group(workspace_group); } -static void workspace_manager_handle_workspace(void *data, ext_workspace_manager_v1 *_, - ext_workspace_handle_v1 *workspace) { - static_cast(data)->handle_workspace(workspace); +static void workspace_manager_handle_workspace(void* data, ext_workspace_manager_v1* _, + ext_workspace_handle_v1* workspace) { + static_cast(data)->handle_workspace(workspace); } -static void workspace_manager_handle_done(void *data, ext_workspace_manager_v1 *_) { - static_cast(data)->handle_done(); +static void workspace_manager_handle_done(void* data, ext_workspace_manager_v1* _) { + static_cast(data)->handle_done(); } -static void workspace_manager_handle_finished(void *data, ext_workspace_manager_v1 *_) { - static_cast(data)->handle_finished(); +static void workspace_manager_handle_finished(void* data, ext_workspace_manager_v1* _) { + static_cast(data)->handle_finished(); } static const ext_workspace_manager_v1_listener workspace_manager_impl = { @@ -56,9 +56,9 @@ static const ext_workspace_manager_v1_listener workspace_manager_impl = { .finished = workspace_manager_handle_finished, }; -ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t name, - uint32_t version, void *data) { - auto *workspace_manager = static_cast( +ext_workspace_manager_v1* workspace_manager_bind(wl_registry* registry, uint32_t name, + uint32_t version, void* data) { + auto* workspace_manager = static_cast( wl_registry_bind(registry, name, &ext_workspace_manager_v1_interface, version)); if (workspace_manager) @@ -69,33 +69,33 @@ ext_workspace_manager_v1 *workspace_manager_bind(wl_registry *registry, uint32_t return workspace_manager; } -static void workspace_group_handle_capabilities(void *data, ext_workspace_group_handle_v1 *_, +static void workspace_group_handle_capabilities(void* data, ext_workspace_group_handle_v1* _, uint32_t capabilities) { - static_cast(data)->handle_capabilities(capabilities); + static_cast(data)->handle_capabilities(capabilities); } -static void workspace_group_handle_output_enter(void *data, ext_workspace_group_handle_v1 *_, - wl_output *output) { - static_cast(data)->handle_output_enter(output); +static void workspace_group_handle_output_enter(void* data, ext_workspace_group_handle_v1* _, + wl_output* output) { + static_cast(data)->handle_output_enter(output); } -static void workspace_group_handle_output_leave(void *data, ext_workspace_group_handle_v1 *_, - wl_output *output) { - static_cast(data)->handle_output_leave(output); +static void workspace_group_handle_output_leave(void* data, ext_workspace_group_handle_v1* _, + wl_output* output) { + static_cast(data)->handle_output_leave(output); } -static void workspace_group_handle_workspace_enter(void *data, ext_workspace_group_handle_v1 *_, - ext_workspace_handle_v1 *workspace) { - static_cast(data)->handle_workspace_enter(workspace); +static void workspace_group_handle_workspace_enter(void* data, ext_workspace_group_handle_v1* _, + ext_workspace_handle_v1* workspace) { + static_cast(data)->handle_workspace_enter(workspace); } -static void workspace_group_handle_workspace_leave(void *data, ext_workspace_group_handle_v1 *_, - ext_workspace_handle_v1 *workspace) { - static_cast(data)->handle_workspace_leave(workspace); +static void workspace_group_handle_workspace_leave(void* data, ext_workspace_group_handle_v1* _, + ext_workspace_handle_v1* workspace) { + static_cast(data)->handle_workspace_leave(workspace); } -static void workspace_group_handle_removed(void *data, ext_workspace_group_handle_v1 *_) { - static_cast(data)->handle_removed(); +static void workspace_group_handle_removed(void* data, ext_workspace_group_handle_v1* _) { + static_cast(data)->handle_removed(); } static const ext_workspace_group_handle_v1_listener workspace_group_impl = { @@ -106,43 +106,43 @@ static const ext_workspace_group_handle_v1_listener workspace_group_impl = { .workspace_leave = workspace_group_handle_workspace_leave, .removed = workspace_group_handle_removed}; -void add_workspace_group_listener(ext_workspace_group_handle_v1 *workspace_group_handle, - void *data) { +void add_workspace_group_listener(ext_workspace_group_handle_v1* workspace_group_handle, + void* data) { ext_workspace_group_handle_v1_add_listener(workspace_group_handle, &workspace_group_impl, data); } -void workspace_handle_name(void *data, struct ext_workspace_handle_v1 *_, const char *name) { - static_cast(data)->handle_name(name); +void workspace_handle_name(void* data, struct ext_workspace_handle_v1* _, const char* name) { + static_cast(data)->handle_name(name); } -void workspace_handle_id(void *data, struct ext_workspace_handle_v1 *_, const char *id) { - static_cast(data)->handle_id(id); +void workspace_handle_id(void* data, struct ext_workspace_handle_v1* _, const char* id) { + static_cast(data)->handle_id(id); } -void workspace_handle_coordinates(void *data, struct ext_workspace_handle_v1 *_, - struct wl_array *coordinates) { +void workspace_handle_coordinates(void* data, struct ext_workspace_handle_v1* _, + struct wl_array* coordinates) { std::vector coords_vec; - auto coords = static_cast(coordinates->data); + auto coords = static_cast(coordinates->data); for (size_t i = 0; i < coordinates->size / sizeof(uint32_t); ++i) { coords_vec.push_back(coords[i]); } - static_cast(data)->handle_coordinates(coords_vec); + static_cast(data)->handle_coordinates(coords_vec); } -void workspace_handle_state(void *data, struct ext_workspace_handle_v1 *workspace_handle, +void workspace_handle_state(void* data, struct ext_workspace_handle_v1* workspace_handle, uint32_t state) { - static_cast(data)->handle_state(state); + static_cast(data)->handle_state(state); } -static void workspace_handle_capabilities(void *data, - struct ext_workspace_handle_v1 *workspace_handle, +static void workspace_handle_capabilities(void* data, + struct ext_workspace_handle_v1* workspace_handle, uint32_t capabilities) { - static_cast(data)->handle_capabilities(capabilities); + static_cast(data)->handle_capabilities(capabilities); } -void workspace_handle_removed(void *data, struct ext_workspace_handle_v1 *workspace_handle) { - static_cast(data)->handle_removed(); +void workspace_handle_removed(void* data, struct ext_workspace_handle_v1* workspace_handle) { + static_cast(data)->handle_removed(); } static const ext_workspace_handle_v1_listener workspace_impl = { @@ -153,7 +153,7 @@ static const ext_workspace_handle_v1_listener workspace_impl = { .capabilities = workspace_handle_capabilities, .removed = workspace_handle_removed}; -void add_workspace_listener(ext_workspace_handle_v1 *workspace_handle, void *data) { +void add_workspace_listener(ext_workspace_handle_v1* workspace_handle, void* data) { ext_workspace_handle_v1_add_listener(workspace_handle, &workspace_impl, data); } } // namespace waybar::modules::ext diff --git a/src/modules/gamemode.cpp b/src/modules/gamemode.cpp index 72ef95033..e9ed97793 100644 --- a/src/modules/gamemode.cpp +++ b/src/modules/gamemode.cpp @@ -21,8 +21,12 @@ #include "util/gtk_icon.hpp" namespace waybar::modules { -Gamemode::Gamemode(const std::string& id, const Json::Value& config) - : AModule(config, "gamemode", id), box_(Gtk::ORIENTATION_HORIZONTAL, 0), icon_(), label_() { +Gamemode::Gamemode(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : AModule(config, "gamemode", id, reap_mtx, reap), + box_(Gtk::ORIENTATION_HORIZONTAL, 0), + icon_(), + label_() { box_.pack_start(icon_); box_.pack_start(label_); box_.set_name(name_); diff --git a/src/modules/gps.cpp b/src/modules/gps.cpp index a7bab659c..c3cb68ab6 100644 --- a/src/modules/gps.cpp +++ b/src/modules/gps.cpp @@ -15,13 +15,21 @@ #include #endif +extern "C" { +waybar::ALabel* new_gps(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) { + return new waybar::modules::Gps(id, config, reap_mtx, reap); +} +} + namespace { using namespace waybar::util; constexpr const char* DEFAULT_FORMAT = "{mode}"; } // namespace -waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config) - : ALabel(config, "gps", id, "{}", 5) +waybar::modules::Gps::Gps(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "gps", id, "{}", reap_mtx, reap, 5) #ifdef WANT_RFKILL , rfkill_{RFKILL_TYPE_GPS} diff --git a/src/modules/hyprland/language.cpp b/src/modules/hyprland/language.cpp index 25f6789d7..6b93c215c 100644 --- a/src/modules/hyprland/language.cpp +++ b/src/modules/hyprland/language.cpp @@ -9,8 +9,9 @@ namespace waybar::modules::hyprland { -Language::Language(const std::string& id, const Bar& bar, const Json::Value& config) - : ALabel(config, "language", id, "{}", 0, true), bar_(bar), m_ipc(IPC::inst()) { +Language::Language(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "language", id, "{}", reap_mtx, reap, 0, true), bar_(bar), m_ipc(IPC::inst()) { // get the active layout when open initLanguage(); diff --git a/src/modules/hyprland/submap.cpp b/src/modules/hyprland/submap.cpp index eb9b1de84..5b73b7ad1 100644 --- a/src/modules/hyprland/submap.cpp +++ b/src/modules/hyprland/submap.cpp @@ -4,8 +4,9 @@ namespace waybar::modules::hyprland { -Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config) - : ALabel(config, "submap", id, "{}", 0, true), bar_(bar), m_ipc(IPC::inst()) { +Submap::Submap(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "submap", id, "{}", reap_mtx, reap, 0, true), bar_(bar), m_ipc(IPC::inst()) { parseConfig(config); label_.hide(); diff --git a/src/modules/hyprland/window.cpp b/src/modules/hyprland/window.cpp index 23437c5f5..3418c9cea 100644 --- a/src/modules/hyprland/window.cpp +++ b/src/modules/hyprland/window.cpp @@ -17,8 +17,11 @@ namespace waybar::modules::hyprland { std::shared_mutex windowIpcSmtx; -Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) - : AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar), m_ipc(IPC::inst()) { +Window::Window(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AAppIconLabel(config, "window", id, "{title}", reap_mtx, reap, 0, true), + bar_(bar), + m_ipc(IPC::inst()) { std::unique_lock windowIpcUniqueLock(windowIpcSmtx); separateOutputs_ = config["separate-outputs"].asBool(); diff --git a/src/modules/hyprland/windowcount.cpp b/src/modules/hyprland/windowcount.cpp index b2721aea5..18d60e9dc 100644 --- a/src/modules/hyprland/windowcount.cpp +++ b/src/modules/hyprland/windowcount.cpp @@ -12,8 +12,11 @@ namespace waybar::modules::hyprland { -WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Value& config) - : AAppIconLabel(config, "windowcount", id, "{count}", 0, true), bar_(bar), m_ipc(IPC::inst()) { +WindowCount::WindowCount(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AAppIconLabel(config, "windowcount", id, "{count}", reap_mtx, reap, 0, true), + bar_(bar), + m_ipc(IPC::inst()) { separateOutputs_ = config.isMember("separate-outputs") ? config["separate-outputs"].asBool() : true; diff --git a/src/modules/hyprland/windowcreationpayload.cpp b/src/modules/hyprland/windowcreationpayload.cpp index 055b0f0ca..61ea606f1 100644 --- a/src/modules/hyprland/windowcreationpayload.cpp +++ b/src/modules/hyprland/windowcreationpayload.cpp @@ -11,7 +11,7 @@ namespace waybar::modules::hyprland { -WindowCreationPayload::WindowCreationPayload(Json::Value const &client_data) +WindowCreationPayload::WindowCreationPayload(Json::Value const& client_data) : m_window(std::make_pair(client_data["class"].asString(), client_data["title"].asString())), m_windowAddress(client_data["address"].asString()), m_workspaceName(client_data["workspace"]["name"].asString()) { @@ -73,7 +73,7 @@ void WindowCreationPayload::clearWorkspaceName() { } } -bool WindowCreationPayload::isEmpty(Workspaces &workspace_manager) { +bool WindowCreationPayload::isEmpty(Workspaces& workspace_manager) { if (std::holds_alternative(m_window)) { return std::get(m_window).empty(); } @@ -89,16 +89,16 @@ bool WindowCreationPayload::isEmpty(Workspaces &workspace_manager) { int WindowCreationPayload::incrementTimeSpentUncreated() { return m_timeSpentUncreated++; } -void WindowCreationPayload::moveToWorkspace(std::string &new_workspace_name) { +void WindowCreationPayload::moveToWorkspace(std::string& new_workspace_name) { m_workspaceName = new_workspace_name; } -WindowRepr WindowCreationPayload::repr(Workspaces &workspace_manager) { +WindowRepr WindowCreationPayload::repr(Workspaces& workspace_manager) { if (std::holds_alternative(m_window)) { return std::get(m_window); } if (std::holds_alternative(m_window)) { - auto const &[window_class, window_title] = std::get(m_window); + auto const& [window_class, window_title] = std::get(m_window); return {m_windowAddress, window_class, window_title, workspace_manager.getRewrite(window_class, window_title), m_isActive}; } diff --git a/src/modules/hyprland/workspace.cpp b/src/modules/hyprland/workspace.cpp index ae66bc845..4cdd89109 100644 --- a/src/modules/hyprland/workspace.cpp +++ b/src/modules/hyprland/workspace.cpp @@ -11,8 +11,8 @@ namespace waybar::modules::hyprland { -Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_manager, - const Json::Value &clients_data) +Workspace::Workspace(const Json::Value& workspace_data, Workspaces& workspace_manager, + const Json::Value& clients_data) : m_workspaceManager(workspace_manager), m_id(workspace_data["id"].asInt()), m_name(workspace_data["name"].asString()), @@ -45,8 +45,8 @@ Workspace::Workspace(const Json::Value &workspace_data, Workspaces &workspace_ma initializeWindowMap(clients_data); } -void addOrRemoveClass(const Glib::RefPtr &context, bool condition, - const std::string &class_name) { +void addOrRemoveClass(const Glib::RefPtr& context, bool condition, + const std::string& class_name) { if (condition) { context->add_class(class_name); } else { @@ -54,9 +54,9 @@ void addOrRemoveClass(const Glib::RefPtr &context, bool condi } } -std::optional Workspace::closeWindow(WindowAddress const &addr) { +std::optional Workspace::closeWindow(WindowAddress const& addr) { auto it = std::ranges::find_if(m_windowMap, - [&addr](const auto &window) { return window.address == addr; }); + [&addr](const auto& window) { return window.address == addr; }); // If the vector contains the address, remove it and return the window representation if (it != m_windowMap.end()) { WindowRepr windowRepr = *it; @@ -66,7 +66,7 @@ std::optional Workspace::closeWindow(WindowAddress const &addr) { return std::nullopt; } -bool Workspace::handleClicked(GdkEventButton *bt) const { +bool Workspace::handleClicked(GdkEventButton* bt) const { if (bt->type == GDK_BUTTON_PRESS) { try { if (id() > 0) { // normal @@ -87,14 +87,14 @@ bool Workspace::handleClicked(GdkEventButton *bt) const { m_ipc.getSocket1Reply("dispatch togglespecialworkspace"); } return true; - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Failed to dispatch workspace: {}", e.what()); } } return false; } -void Workspace::initializeWindowMap(const Json::Value &clients_data) { +void Workspace::initializeWindowMap(const Json::Value& clients_data) { m_windowMap.clear(); for (auto client : clients_data) { if (client["workspace"]["id"].asInt() == id()) { @@ -103,10 +103,10 @@ void Workspace::initializeWindowMap(const Json::Value &clients_data) { } } -void Workspace::setActiveWindow(WindowAddress const &addr) { +void Workspace::setActiveWindow(WindowAddress const& addr) { std::optional activeIdx; for (size_t i = 0; i < m_windowMap.size(); ++i) { - auto &window = m_windowMap[i]; + auto& window = m_windowMap[i]; bool isActive = (window.address == addr); window.setActive(isActive); if (isActive) { @@ -133,7 +133,7 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) { if (!repr.empty() || m_workspaceManager.enableTaskbar()) { auto addr = create_window_payload.getAddress(); auto it = std::ranges::find_if( - m_windowMap, [&addr](const auto &window) { return window.address == addr; }); + m_windowMap, [&addr](const auto& window) { return window.address == addr; }); // If the vector contains the address, update the window representation, otherwise insert it if (it != m_windowMap.end()) { *it = repr; @@ -144,7 +144,7 @@ void Workspace::insertWindow(WindowCreationPayload create_window_payload) { } }; -bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payload) { +bool Workspace::onWindowOpened(WindowCreationPayload const& create_window_payload) { if (create_window_payload.getWorkspaceName() == name()) { insertWindow(create_window_payload); return true; @@ -152,7 +152,7 @@ bool Workspace::onWindowOpened(WindowCreationPayload const &create_window_payloa return false; } -std::string &Workspace::selectIcon(std::map &icons_map) { +std::string& Workspace::selectIcon(std::map& icons_map) { spdlog::trace("Selecting icon for workspace {}", name()); if (isUrgent()) { auto urgentIconIt = icons_map.find("urgent"); @@ -209,7 +209,7 @@ std::string &Workspace::selectIcon(std::map &icons_map return m_name; } -void Workspace::update(const std::string &workspace_icon) { +void Workspace::update(const std::string& workspace_icon) { if (this->m_workspaceManager.persistentOnly() && !this->isPersistent()) { m_button.hide(); return; @@ -248,7 +248,7 @@ void Workspace::update(const std::string &workspace_icon) { bool isNotFirst = false; - for (const auto &window_repr : m_windowMap) { + for (const auto& window_repr : m_windowMap) { if (isNotFirst) { windows.append(windowSeparator); } @@ -276,10 +276,10 @@ bool Workspace::isEmpty() const { // If there are windows but they are all ignored, consider the workspace empty return std::all_of( m_windowMap.begin(), m_windowMap.end(), - [this, &ignore_list](const auto &window_repr) { return shouldSkipWindow(window_repr); }); + [this, &ignore_list](const auto& window_repr) { return shouldSkipWindow(window_repr); }); } -void Workspace::updateTaskbar(const std::string &workspace_icon) { +void Workspace::updateTaskbar(const std::string& workspace_icon) { for (auto child : m_content.get_children()) { if (child != &m_labelBefore) { m_content.remove(*child); @@ -287,7 +287,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) { } bool isFirst = true; - auto processWindow = [&](const WindowRepr &window_repr) { + auto processWindow = [&](const WindowRepr& window_repr) { if (shouldSkipWindow(window_repr)) { return; // skip } @@ -343,7 +343,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) { processWindow(*it); } } else { - for (const auto &window_repr : m_windowMap) { + for (const auto& window_repr : m_windowMap) { processWindow(window_repr); } } @@ -358,7 +358,7 @@ void Workspace::updateTaskbar(const std::string &workspace_icon) { } } -bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress const &addr) const { +bool Workspace::handleClick(const GdkEventButton* event_button, WindowAddress const& addr) const { if (event_button->type == GDK_BUTTON_PRESS) { std::string command = std::regex_replace(m_workspaceManager.onClickWindow(), std::regex("\\{address\\}"), "0x" + addr); @@ -372,9 +372,9 @@ bool Workspace::handleClick(const GdkEventButton *event_button, WindowAddress co return true; } -bool Workspace::shouldSkipWindow(const WindowRepr &window_repr) const { +bool Workspace::shouldSkipWindow(const WindowRepr& window_repr) const { auto ignore_list = m_workspaceManager.getIgnoredWindows(); - auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto &ignoreItem) { + auto it = std::ranges::find_if(ignore_list, [&window_repr](const auto& ignoreItem) { return std::regex_match(window_repr.window_class, ignoreItem) || std::regex_match(window_repr.window_title, ignoreItem); }); diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 8360137f4..806c4a168 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -14,8 +14,9 @@ namespace waybar::modules::hyprland { -Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) - : AModule(config, "workspaces", id, false, false), +Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AModule(config, "workspaces", id, reap_mtx, reap, false, false), m_bar(bar), m_box(bar.orientation, 0), m_ipc(IPC::inst()) { @@ -46,8 +47,8 @@ void Workspaces::init() { dp.emit(); } -Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name, - std::string const &monitor) { +Json::Value Workspaces::createMonitorWorkspaceData(std::string const& name, + std::string const& monitor) { spdlog::trace("Creating persistent workspace: {} on monitor {}", name, monitor); Json::Value workspaceData; @@ -62,14 +63,14 @@ Json::Value Workspaces::createMonitorWorkspaceData(std::string const &name, return workspaceData; } -void Workspaces::createWorkspace(Json::Value const &workspace_data, - Json::Value const &clients_data) { +void Workspaces::createWorkspace(Json::Value const& workspace_data, + Json::Value const& clients_data) { auto workspaceName = workspace_data["name"].asString(); auto workspaceId = workspace_data["id"].asInt(); spdlog::debug("Creating workspace {}", workspaceName); // avoid recreating existing workspaces - auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr const &w) { + auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr const& w) { if (workspaceId > 0) { return w->id() == workspaceId; } @@ -81,7 +82,7 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data, // don't recreate workspace, but update persistency if necessary const auto keys = workspace_data.getMemberNames(); - const auto *k = "persistent-rule"; + const auto* k = "persistent-rule"; if (std::ranges::find(keys, k) != keys.end()) { spdlog::debug("Set dynamic persistency of workspace {} to: {}", workspaceName, workspace_data[k].asBool() ? "true" : "false"); @@ -100,14 +101,14 @@ void Workspaces::createWorkspace(Json::Value const &workspace_data, // create new workspace m_workspaces.emplace_back(std::make_unique(workspace_data, *this, clients_data)); - Gtk::Button &newWorkspaceButton = m_workspaces.back()->button(); + Gtk::Button& newWorkspaceButton = m_workspaces.back()->button(); m_box.pack_start(newWorkspaceButton, false, false); sortWorkspaces(); newWorkspaceButton.show_all(); } void Workspaces::createWorkspacesToCreate() { - for (const auto &[workspaceData, clientsData] : m_workspacesToCreate) { + for (const auto& [workspaceData, clientsData] : m_workspacesToCreate) { createWorkspace(workspaceData, clientsData); } if (!m_workspacesToCreate.empty()) { @@ -139,9 +140,9 @@ void Workspaces::doUpdate() { } } -void Workspaces::extendOrphans(int workspaceId, Json::Value const &clientsJson) { +void Workspaces::extendOrphans(int workspaceId, Json::Value const& clientsJson) { spdlog::trace("Extending orphans with workspace {}", workspaceId); - for (const auto &client : clientsJson) { + for (const auto& client : clientsJson) { if (client["workspace"]["id"].asInt() == workspaceId) { registerOrphanWindow({client}); } @@ -163,7 +164,7 @@ std::string Workspaces::getRewrite(std::string window_class, std::string window_ std::vector Workspaces::getVisibleWorkspaces() { std::vector visibleWorkspaces; auto monitors = IPC::inst().getSocket1JsonReply("monitors"); - for (const auto &monitor : monitors) { + for (const auto& monitor : monitors) { auto ws = monitor["activeWorkspace"]; if (ws.isObject() && ws["id"].isInt()) { visibleWorkspaces.push_back(ws["id"].asInt()); @@ -181,7 +182,7 @@ void Workspaces::initializeWorkspaces() { spdlog::debug("Initializing workspaces"); // if the workspace rules changed since last initialization, make sure we reset everything: - for (auto &workspace : m_workspaces) { + for (auto& workspace : m_workspaces) { m_workspacesToRemove.push_back(std::to_string(workspace->id())); } @@ -209,7 +210,7 @@ void Workspaces::initializeWorkspaces() { loadPersistentWorkspacesFromWorkspaceRules(clientsJson); } -bool isDoubleSpecial(std::string const &workspace_name) { +bool isDoubleSpecial(std::string const& workspace_name) { // Hyprland's IPC sometimes reports the creation of workspaces strangely named // `special:special:`. This function checks for that and is used // to avoid creating (and then removing) such workspaces. @@ -217,8 +218,8 @@ bool isDoubleSpecial(std::string const &workspace_name) { return workspace_name.find("special:special:") != std::string::npos; } -bool Workspaces::isWorkspaceIgnored(std::string const &name) { - for (auto &rule : m_ignoreWorkspaces) { +bool Workspaces::isWorkspaceIgnored(std::string const& name) { + for (auto& rule : m_ignoreWorkspaces) { if (std::regex_match(name, rule)) { return true; break; @@ -228,19 +229,19 @@ bool Workspaces::isWorkspaceIgnored(std::string const &name) { return false; } -void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJson) { +void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const& clientsJson) { spdlog::info("Loading persistent workspaces from Waybar config"); const std::vector keys = m_persistentWorkspaceConfig.getMemberNames(); std::vector persistentWorkspacesToCreate; const std::string currentMonitor = m_bar.output->name; const bool monitorInConfig = std::ranges::find(keys, currentMonitor) != keys.end(); - for (const std::string &key : keys) { + for (const std::string& key : keys) { // only add if either: // 1. key is the current monitor name // 2. key is "*" and this monitor is not already defined in the config bool canCreate = key == currentMonitor || (key == "*" && !monitorInConfig); - const Json::Value &value = m_persistentWorkspaceConfig[key]; + const Json::Value& value = m_persistentWorkspaceConfig[key]; spdlog::trace("Parsing persistent workspace config: {} => {}", key, value.toStyledString()); if (value.isInt()) { @@ -255,13 +256,13 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs } else if (value.isArray() && !value.empty()) { // value is an array => create defined workspaces for this monitor if (canCreate) { - for (const Json::Value &workspace : value) { + for (const Json::Value& workspace : value) { spdlog::debug("Creating workspace {} on monitor {}", workspace, currentMonitor); persistentWorkspacesToCreate.emplace_back(workspace.asString()); } } else { // key is the workspace and value is array of monitors to create on - for (const Json::Value &monitor : value) { + for (const Json::Value& monitor : value) { if (monitor.isString() && monitor.asString() == currentMonitor) { persistentWorkspacesToCreate.emplace_back(currentMonitor); break; @@ -274,18 +275,18 @@ void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const &clientsJs } } - for (auto const &workspace : persistentWorkspacesToCreate) { + for (auto const& workspace : persistentWorkspacesToCreate) { auto workspaceData = createMonitorWorkspaceData(workspace, m_bar.output->name); workspaceData["persistent-config"] = true; m_workspacesToCreate.emplace_back(workspaceData, clientsJson); } } -void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &clientsJson) { +void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& clientsJson) { spdlog::info("Loading persistent workspaces from Hyprland workspace rules"); auto const workspaceRules = m_ipc.getSocket1JsonReply("workspacerules"); - for (Json::Value const &rule : workspaceRules) { + for (Json::Value const& rule : workspaceRules) { if (!rule["workspaceString"].isString()) { spdlog::warn("Workspace rules: invalid workspaceString, skipping: {}", rule); continue; @@ -300,7 +301,7 @@ void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &c if (workspace.starts_with("name:")) { workspace = workspace.substr(5); } - auto const &monitor = rule["monitor"].asString(); + auto const& monitor = rule["monitor"].asString(); // create this workspace persistently if: // 1. the allOutputs config option is enabled // 2. the rule's monitor is the current monitor @@ -317,7 +318,7 @@ void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value &c } } -void Workspaces::onEvent(const std::string &ev) { +void Workspaces::onEvent(const std::string& ev) { std::lock_guard lock(m_mutex); std::string eventName(begin(ev), begin(ev) + ev.find_first_of('>')); std::string payload = ev.substr(eventName.size() + 2); @@ -355,7 +356,7 @@ void Workspaces::onEvent(const std::string &ev) { dp.emit(); } -void Workspaces::onWorkspaceActivated(std::string const &payload) { +void Workspaces::onWorkspaceActivated(std::string const& payload) { const auto [workspaceIdStr, workspaceName] = splitDoublePayload(payload); const auto workspaceId = parseWorkspaceId(workspaceIdStr); if (workspaceId.has_value()) { @@ -363,19 +364,19 @@ void Workspaces::onWorkspaceActivated(std::string const &payload) { } } -void Workspaces::onSpecialWorkspaceActivated(std::string const &payload) { +void Workspaces::onSpecialWorkspaceActivated(std::string const& payload) { std::string name(begin(payload), begin(payload) + payload.find_first_of(',')); m_activeSpecialWorkspaceName = (!name.starts_with("special:") ? name : name.substr(8)); } -void Workspaces::onWorkspaceDestroyed(std::string const &payload) { +void Workspaces::onWorkspaceDestroyed(std::string const& payload) { const auto [workspaceId, workspaceName] = splitDoublePayload(payload); if (!isDoubleSpecial(workspaceName)) { m_workspacesToRemove.push_back(workspaceId); } } -void Workspaces::onWorkspaceCreated(std::string const &payload, Json::Value const &clientsData) { +void Workspaces::onWorkspaceCreated(std::string const& payload, Json::Value const& clientsData) { spdlog::debug("Workspace created: {}", payload); const auto [workspaceIdStr, _] = splitDoublePayload(payload); @@ -402,7 +403,7 @@ void Workspaces::onWorkspaceCreated(std::string const &payload, Json::Value cons if ((allOutputs() || m_bar.output->name == workspaceJson["monitor"].asString()) && (showSpecial() || !workspaceName.starts_with("special")) && !isDoubleSpecial(workspaceName)) { - for (Json::Value const &rule : workspaceRules) { + for (Json::Value const& rule : workspaceRules) { auto ruleWorkspaceName = rule.isMember("defaultName") ? rule["defaultName"].asString() : rule["workspaceString"].asString(); @@ -421,7 +422,7 @@ void Workspaces::onWorkspaceCreated(std::string const &payload, Json::Value cons } } -void Workspaces::onWorkspaceMoved(std::string const &payload) { +void Workspaces::onWorkspaceMoved(std::string const& payload) { spdlog::debug("Workspace moved: {}", payload); // Update active workspace @@ -442,7 +443,7 @@ void Workspaces::onWorkspaceMoved(std::string const &payload) { } } -void Workspaces::onWorkspaceRenamed(std::string const &payload) { +void Workspaces::onWorkspaceRenamed(std::string const& payload) { spdlog::debug("Workspace renamed: {}", payload); const auto [workspaceIdStr, newName] = splitDoublePayload(payload); @@ -451,7 +452,7 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) { return; } - for (auto &workspace : m_workspaces) { + for (auto& workspace : m_workspaces) { if (workspace->id() == *workspaceId) { workspace->setName(newName); break; @@ -460,7 +461,7 @@ void Workspaces::onWorkspaceRenamed(std::string const &payload) { sortWorkspaces(); } -void Workspaces::onMonitorFocused(std::string const &payload) { +void Workspaces::onMonitorFocused(std::string const& payload) { spdlog::trace("Monitor focused: {}", payload); const auto [monitorName, workspaceIdStr] = splitDoublePayload(payload); @@ -472,7 +473,7 @@ void Workspaces::onMonitorFocused(std::string const &payload) { m_activeWorkspaceId = *workspaceId; - for (Json::Value &monitor : m_ipc.getSocket1JsonReply("monitors")) { + for (Json::Value& monitor : m_ipc.getSocket1JsonReply("monitors")) { if (monitor["name"].asString() == monitorName) { const auto name = monitor["specialWorkspace"]["name"].asString(); m_activeSpecialWorkspaceName = !name.starts_with("special:") ? name : name.substr(8); @@ -480,7 +481,7 @@ void Workspaces::onMonitorFocused(std::string const &payload) { } } -void Workspaces::onWindowOpened(std::string const &payload) { +void Workspaces::onWindowOpened(std::string const& payload) { spdlog::trace("Window opened: {}", payload); updateWindowCount(); size_t lastCommaIdx = 0; @@ -501,18 +502,18 @@ void Workspaces::onWindowOpened(std::string const &payload) { m_windowsToCreate.emplace_back(workspaceName, windowAddress, windowClass, windowTitle, isActive); } -void Workspaces::onWindowClosed(std::string const &addr) { +void Workspaces::onWindowClosed(std::string const& addr) { spdlog::trace("Window closed: {}", addr); updateWindowCount(); m_orphanWindowMap.erase(addr); - for (auto &workspace : m_workspaces) { + for (auto& workspace : m_workspaces) { if (workspace->closeWindow(addr)) { break; } } } -void Workspaces::onWindowMoved(std::string const &payload) { +void Workspaces::onWindowMoved(std::string const& payload) { spdlog::trace("Window moved: {}", payload); updateWindowCount(); auto [windowAddress, _, workspaceName] = splitTriplePayload(payload); @@ -521,7 +522,7 @@ void Workspaces::onWindowMoved(std::string const &payload) { // If the window was still queued to be created, just change its destination // and exit - for (auto &window : m_windowsToCreate) { + for (auto& window : m_windowsToCreate) { if (window.getAddress() == windowAddress) { window.moveToWorkspace(workspaceName); return; @@ -529,7 +530,7 @@ void Workspaces::onWindowMoved(std::string const &payload) { } // Take the window's representation from the old workspace... - for (auto &workspace : m_workspaces) { + for (auto& workspace : m_workspaces) { if (auto windowAddr = workspace->closeWindow(windowAddress); windowAddr != std::nullopt) { windowRepr = windowAddr.value(); break; @@ -548,7 +549,7 @@ void Workspaces::onWindowMoved(std::string const &payload) { } } -void Workspaces::onWindowTitleEvent(std::string const &payload) { +void Workspaces::onWindowTitleEvent(std::string const& payload) { spdlog::trace("Window title changed: {}", payload); std::optional> inserter; @@ -558,7 +559,7 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) { if (m_orphanWindowMap.contains(windowAddress)) { inserter = [this](WindowCreationPayload wcp) { this->registerOrphanWindow(std::move(wcp)); }; } else { - auto windowWorkspace = std::ranges::find_if(m_workspaces, [windowAddress](auto &workspace) { + auto windowWorkspace = std::ranges::find_if(m_workspaces, [windowAddress](auto& workspace) { return workspace->containsWindow(windowAddress); }); @@ -570,7 +571,7 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) { }; } else { auto queuedWindow = - std::ranges::find_if(m_windowsToCreate, [&windowAddress](auto &windowPayload) { + std::ranges::find_if(m_windowsToCreate, [&windowAddress](auto& windowPayload) { return windowPayload.getAddress() == windowAddress; }); @@ -585,7 +586,7 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) { Json::Value clientsData = m_ipc.getSocket1JsonReply("clients"); std::string jsonWindowAddress = fmt::format("0x{}", windowAddress); - auto client = std::ranges::find_if(clientsData, [jsonWindowAddress](auto &client) { + auto client = std::ranges::find_if(clientsData, [jsonWindowAddress](auto& client) { return client["address"].asString() == jsonWindowAddress; }); @@ -595,17 +596,17 @@ void Workspaces::onWindowTitleEvent(std::string const &payload) { } } -void Workspaces::onActiveWindowChanged(WindowAddress const &activeWindowAddress) { +void Workspaces::onActiveWindowChanged(WindowAddress const& activeWindowAddress) { spdlog::trace("Active window changed: {}", activeWindowAddress); m_currentActiveWindowAddress = activeWindowAddress; - for (auto &[address, window] : m_orphanWindowMap) { + for (auto& [address, window] : m_orphanWindowMap) { window.setActive(address == activeWindowAddress); } - for (auto const &workspace : m_workspaces) { + for (auto const& workspace : m_workspaces) { workspace->setActiveWindow(activeWindowAddress); } - for (auto &window : m_windowsToCreate) { + for (auto& window : m_windowsToCreate) { window.setActive(window.getAddress() == activeWindowAddress); } } @@ -615,8 +616,8 @@ void Workspaces::onConfigReloaded() { init(); } -auto Workspaces::parseConfig(const Json::Value &config) -> void { - const auto &configFormat = config["format"]; +auto Workspaces::parseConfig(const Json::Value& config) -> void { + const auto& configFormat = config["format"]; m_formatBefore = configFormat.isString() ? configFormat.asString() : "{name}"; m_withIcon = m_formatBefore.find("{icon}") != std::string::npos; auto withWindows = m_formatBefore.find("{windows}") != std::string::npos; @@ -648,28 +649,28 @@ auto Workspaces::parseConfig(const Json::Value &config) -> void { } } -auto Workspaces::populateIconsMap(const Json::Value &formatIcons) -> void { - for (const auto &name : formatIcons.getMemberNames()) { +auto Workspaces::populateIconsMap(const Json::Value& formatIcons) -> void { + for (const auto& name : formatIcons.getMemberNames()) { m_iconsMap.emplace(name, formatIcons[name].asString()); } m_iconsMap.emplace("", ""); } -auto Workspaces::populateBoolConfig(const Json::Value &config, const std::string &key, bool &member) +auto Workspaces::populateBoolConfig(const Json::Value& config, const std::string& key, bool& member) -> void { - const auto &configValue = config[key]; + const auto& configValue = config[key]; if (configValue.isBool()) { member = configValue.asBool(); } } -auto Workspaces::populateSortByConfig(const Json::Value &config) -> void { - const auto &configSortBy = config["sort-by"]; +auto Workspaces::populateSortByConfig(const Json::Value& config) -> void { + const auto& configSortBy = config["sort-by"]; if (configSortBy.isString()) { auto sortByStr = configSortBy.asString(); try { m_sortBy = m_enumParser.parseStringToEnum(sortByStr, m_sortMap); - } catch (const std::invalid_argument &e) { + } catch (const std::invalid_argument& e) { m_sortBy = SortMethod::DEFAULT; spdlog::warn( "Invalid string representation for sort-by. Falling back to default sort method."); @@ -677,16 +678,16 @@ auto Workspaces::populateSortByConfig(const Json::Value &config) -> void { } } -auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value &config) -> void { +auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value& config) -> void { auto ignoreWorkspaces = config["ignore-workspaces"]; if (ignoreWorkspaces.isArray()) { - for (const auto &workspaceRegex : ignoreWorkspaces) { + for (const auto& workspaceRegex : ignoreWorkspaces) { if (workspaceRegex.isString()) { std::string ruleString = workspaceRegex.asString(); try { const std::regex rule{ruleString, std::regex_constants::icase}; m_ignoreWorkspaces.emplace_back(rule); - } catch (const std::regex_error &e) { + } catch (const std::regex_error& e) { spdlog::error("Invalid rule {}: {}", ruleString, e.what()); } } else { @@ -696,30 +697,30 @@ auto Workspaces::populateIgnoreWorkspacesConfig(const Json::Value &config) -> vo } } -auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value &config) -> void { - const auto &formatWindowSeparator = config["format-window-separator"]; +auto Workspaces::populateFormatWindowSeparatorConfig(const Json::Value& config) -> void { + const auto& formatWindowSeparator = config["format-window-separator"]; m_formatWindowSeparator = formatWindowSeparator.isString() ? formatWindowSeparator.asString() : " "; } -auto Workspaces::populateWindowRewriteConfig(const Json::Value &config) -> void { - const auto &windowRewrite = config["window-rewrite"]; +auto Workspaces::populateWindowRewriteConfig(const Json::Value& config) -> void { + const auto& windowRewrite = config["window-rewrite"]; if (!windowRewrite.isObject()) { spdlog::debug("window-rewrite is not defined or is not an object, using default rules."); return; } - const auto &windowRewriteDefaultConfig = config["window-rewrite-default"]; + const auto& windowRewriteDefaultConfig = config["window-rewrite-default"]; std::string windowRewriteDefault = windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?"; m_windowRewriteRules = util::RegexCollection( windowRewrite, windowRewriteDefault, - [this](std::string &window_rule) { return windowRewritePriorityFunction(window_rule); }); + [this](std::string& window_rule) { return windowRewritePriorityFunction(window_rule); }); } -auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> void { - const auto &workspaceTaskbar = config["workspace-taskbar"]; +auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value& config) -> void { + const auto& workspaceTaskbar = config["workspace-taskbar"]; if (!workspaceTaskbar.isObject()) { spdlog::debug("workspace-taskbar is not defined or is not an object, using default rules."); return; @@ -746,7 +747,7 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo auto iconTheme = workspaceTaskbar["icon-theme"]; if (iconTheme.isArray()) { - for (auto &c : iconTheme) { + for (auto& c : iconTheme) { m_iconLoader.add_custom_icon_theme(c.asString()); } } else if (iconTheme.isString()) { @@ -766,11 +767,11 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo } if (workspaceTaskbar["ignore-list"].isArray()) { - for (auto &windowRegex : workspaceTaskbar["ignore-list"]) { + for (auto& windowRegex : workspaceTaskbar["ignore-list"]) { std::string ruleString = windowRegex.asString(); try { m_ignoreWindows.emplace_back(ruleString, std::regex_constants::icase); - } catch (const std::regex_error &e) { + } catch (const std::regex_error& e) { spdlog::error("Invalid rule {}: {}", ruleString, e.what()); } } @@ -781,7 +782,7 @@ auto Workspaces::populateWorkspaceTaskbarConfig(const Json::Value &config) -> vo try { m_activeWindowPosition = m_activeWindowEnumParser.parseStringToEnum(posStr, m_activeWindowPositionMap); - } catch (const std::invalid_argument &e) { + } catch (const std::invalid_argument& e) { spdlog::warn( "Invalid string representation for active-window-position. Falling back to 'none'."); m_activeWindowPosition = ActiveWindowPosition::NONE; @@ -824,13 +825,13 @@ auto Workspaces::registerIpc() -> void { } void Workspaces::removeWorkspacesToRemove() { - for (const auto &workspaceString : m_workspacesToRemove) { + for (const auto& workspaceString : m_workspacesToRemove) { removeWorkspace(workspaceString); } m_workspacesToRemove.clear(); } -void Workspaces::removeWorkspace(std::string const &workspaceString) { +void Workspaces::removeWorkspace(std::string const& workspaceString) { spdlog::debug("Removing workspace {}", workspaceString); // If this succeeds, we have a workspace ID. @@ -848,7 +849,7 @@ void Workspaces::removeWorkspace(std::string const &workspaceString) { name = workspaceString; } - const auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr &x) { + const auto workspace = std::ranges::find_if(m_workspaces, [&](std::unique_ptr& x) { if (workspaceId.has_value()) { return *workspaceId == x->id(); } @@ -874,7 +875,7 @@ void Workspaces::setCurrentMonitorId() { // get monitor ID from name (used by persistent workspaces) m_monitorId = 0; auto monitors = m_ipc.getSocket1JsonReply("monitors"); - auto currentMonitor = std::ranges::find_if(monitors, [this](const Json::Value &m) { + auto currentMonitor = std::ranges::find_if(monitors, [this](const Json::Value& m) { return m["name"].asString() == m_bar.output->name; }); if (currentMonitor == monitors.end()) { @@ -890,7 +891,7 @@ void Workspaces::sortSpecialCentered() { std::vector> hiddenWorkspaces; std::vector> normalWorkspaces; - for (auto &workspace : m_workspaces) { + for (auto& workspace : m_workspaces) { if (workspace->isSpecial()) { specialWorkspaces.push_back(std::move(workspace)); } else { @@ -921,7 +922,7 @@ void Workspaces::sortSpecialCentered() { void Workspaces::sortWorkspaces() { std::ranges::sort( // - m_workspaces, [&](std::unique_ptr &a, std::unique_ptr &b) { + m_workspaces, [&](std::unique_ptr& a, std::unique_ptr& b) { // Helper comparisons auto isIdLess = a->id() < b->id(); auto isNameLess = a->name() < b->name(); @@ -934,7 +935,7 @@ void Workspaces::sortWorkspaces() { case SortMethod::NUMBER: try { return std::stoi(a->name()) < std::stoi(b->name()); - } catch (const std::invalid_argument &) { + } catch (const std::invalid_argument&) { // Handle the exception if necessary. break; } @@ -986,7 +987,7 @@ void Workspaces::sortWorkspaces() { } } -void Workspaces::setUrgentWorkspace(std::string const &windowaddress) { +void Workspaces::setUrgentWorkspace(std::string const& windowaddress) { const Json::Value clientsJson = m_ipc.getSocket1JsonReply("clients"); int workspaceId = -1; @@ -997,7 +998,7 @@ void Workspaces::setUrgentWorkspace(std::string const &windowaddress) { } } - auto workspace = std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr &x) { + auto workspace = std::ranges::find_if(m_workspaces, [workspaceId](std::unique_ptr& x) { return x->id() == workspaceId; }); if (workspace != m_workspaces.end()) { @@ -1012,8 +1013,8 @@ auto Workspaces::update() -> void { void Workspaces::updateWindowCount() { const Json::Value workspacesJson = m_ipc.getSocket1JsonReply("workspaces"); - for (auto const &workspace : m_workspaces) { - auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const &x) { + for (auto const& workspace : m_workspaces) { + auto workspaceJson = std::ranges::find_if(workspacesJson, [&](Json::Value const& x) { return x["name"].asString() == workspace->name() || (workspace->isSpecial() && x["name"].asString() == "special:" + workspace->name()); }); @@ -1021,7 +1022,7 @@ void Workspaces::updateWindowCount() { if (workspaceJson != workspacesJson.end()) { try { count = (*workspaceJson)["windows"].asUInt(); - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Failed to update window count: {}", e.what()); } } @@ -1032,9 +1033,9 @@ void Workspaces::updateWindowCount() { bool Workspaces::updateWindowsToCreate() { bool anyWindowCreated = false; std::vector notCreated; - for (auto &windowPayload : m_windowsToCreate) { + for (auto& windowPayload : m_windowsToCreate) { bool created = false; - for (auto &workspace : m_workspaces) { + for (auto& workspace : m_workspaces) { if (workspace->onWindowOpened(windowPayload)) { created = true; anyWindowCreated = true; @@ -1063,7 +1064,7 @@ void Workspaces::updateWorkspaceStates() { std::string currentWorkspaceName = currentWorkspace.isMember("name") ? currentWorkspace["name"].asString() : ""; - for (auto &workspace : m_workspaces) { + for (auto& workspace : m_workspaces) { bool isActiveByName = !currentWorkspaceName.empty() && workspace->name() == currentWorkspaceName; @@ -1075,11 +1076,11 @@ void Workspaces::updateWorkspaceStates() { } workspace->setVisible(std::ranges::find(visibleWorkspaces, workspace->id()) != visibleWorkspaces.end()); - std::string &workspaceIcon = m_iconsMap[""]; + std::string& workspaceIcon = m_iconsMap[""]; if (m_withIcon) { workspaceIcon = workspace->selectIcon(m_iconsMap); } - auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto &w) { + auto updatedWorkspace = std::ranges::find_if(updatedWorkspaces, [&workspace](const auto& w) { auto wNameRaw = w["name"].asString(); auto wName = wNameRaw.starts_with("special:") ? wNameRaw.substr(8) : wNameRaw; return wName == workspace->name(); @@ -1091,7 +1092,7 @@ void Workspaces::updateWorkspaceStates() { } } -int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) { +int Workspaces::windowRewritePriorityFunction(std::string const& window_rule) { // Rules that match against title are prioritized // Rules that don't specify if they're matching against either title or class are deprioritized bool const hasTitle = window_rule.find("title") != std::string::npos; @@ -1112,21 +1113,21 @@ int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) { } template -std::string Workspaces::makePayload(Args const &...args) { +std::string Workspaces::makePayload(Args const&... args) { std::ostringstream result; bool first = true; ((result << (first ? "" : ",") << args, first = false), ...); return result.str(); } -std::pair Workspaces::splitDoublePayload(std::string const &payload) { +std::pair Workspaces::splitDoublePayload(std::string const& payload) { const std::string part1 = payload.substr(0, payload.find(',')); const std::string part2 = payload.substr(part1.size() + 1); return {part1, part2}; } std::tuple Workspaces::splitTriplePayload( - std::string const &payload) { + std::string const& payload) { const size_t firstComma = payload.find(','); const size_t secondComma = payload.find(',', firstComma + 1); @@ -1137,10 +1138,10 @@ std::tuple Workspaces::splitTriplePayload return {part1, part2, part3}; } -std::optional Workspaces::parseWorkspaceId(std::string const &workspaceIdStr) { +std::optional Workspaces::parseWorkspaceId(std::string const& workspaceIdStr) { try { return workspaceIdStr == "special" ? -99 : std::stoi(workspaceIdStr); - } catch (std::exception const &e) { + } catch (std::exception const& e) { spdlog::debug("Workspace \"{}\" is not bound to an id: {}", workspaceIdStr, e.what()); return std::nullopt; } diff --git a/src/modules/idle_inhibitor.cpp b/src/modules/idle_inhibitor.cpp index a5fc9ac73..6988f397b 100644 --- a/src/modules/idle_inhibitor.cpp +++ b/src/modules/idle_inhibitor.cpp @@ -7,8 +7,9 @@ std::list waybar::modules::IdleInhibitor::modules; bool waybar::modules::IdleInhibitor::status = false; waybar::modules::IdleInhibitor::IdleInhibitor(const std::string& id, const Bar& bar, - const Json::Value& config) - : ALabel(config, "idle_inhibitor", id, "{status}", 0, false, true), + const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "idle_inhibitor", id, "{status}", reap_mtx, reap, 0, false, true), bar_(bar), idle_inhibitor_(nullptr), pid_(-1) { diff --git a/src/modules/image.cpp b/src/modules/image.cpp index 173aabd35..4864795c4 100644 --- a/src/modules/image.cpp +++ b/src/modules/image.cpp @@ -1,7 +1,8 @@ #include "modules/image.hpp" -waybar::modules::Image::Image(const std::string& id, const Json::Value& config) - : AModule(config, "image", id), box_(Gtk::ORIENTATION_HORIZONTAL, 0) { +waybar::modules::Image::Image(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AModule(config, "image", id, reap_mtx, reap), box_(Gtk::ORIENTATION_HORIZONTAL, 0) { box_.pack_start(image_); box_.set_name("image"); if (!id.empty()) { diff --git a/src/modules/inhibitor.cpp b/src/modules/inhibitor.cpp index fe2a4be41..ba7de3f40 100644 --- a/src/modules/inhibitor.cpp +++ b/src/modules/inhibitor.cpp @@ -97,8 +97,9 @@ auto getInhibitors(const Json::Value& config) -> std::string { namespace waybar::modules { -Inhibitor::Inhibitor(const std::string& id, const Bar& bar, const Json::Value& config) - : ALabel(config, "inhibitor", id, "{status}", true), +Inhibitor::Inhibitor(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "inhibitor", id, "{status}", reap_mtx, reap, true), dbus_(::dbus()), inhibitors_(::getInhibitors(config)) { event_box_.add_events(Gdk::BUTTON_PRESS_MASK); diff --git a/src/modules/jack.cpp b/src/modules/jack.cpp index 9bd6fcd6d..d8e98e2fc 100644 --- a/src/modules/jack.cpp +++ b/src/modules/jack.cpp @@ -2,8 +2,9 @@ namespace waybar::modules { -JACK::JACK(const std::string &id, const Json::Value &config) - : ALabel(config, "jack", id, "{load}%", 1) { +JACK::JACK(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "jack", id, "{load}%", reap_mtx, reap, 1) { running_ = false; client_ = NULL; @@ -113,14 +114,14 @@ void JACK::shutdown() { } // namespace waybar::modules -int bufSizeCallback(jack_nframes_t size, void *obj) { - return static_cast(obj)->bufSize(size); +int bufSizeCallback(jack_nframes_t size, void* obj) { + return static_cast(obj)->bufSize(size); } -int sampleRateCallback(jack_nframes_t rate, void *obj) { - return static_cast(obj)->sampleRate(rate); +int sampleRateCallback(jack_nframes_t rate, void* obj) { + return static_cast(obj)->sampleRate(rate); } -int xrunCallback(void *obj) { return static_cast(obj)->xrun(); } +int xrunCallback(void* obj) { return static_cast(obj)->xrun(); } -void shutdownCallback(void *obj) { return static_cast(obj)->shutdown(); } +void shutdownCallback(void* obj) { return static_cast(obj)->shutdown(); } diff --git a/src/modules/keyboard_state.cpp b/src/modules/keyboard_state.cpp index 18ce0a7c4..1a9118f16 100644 --- a/src/modules/keyboard_state.cpp +++ b/src/modules/keyboard_state.cpp @@ -79,8 +79,10 @@ auto supportsLockStates(const libevdev* dev) -> bool { } waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar, - const Json::Value& config) - : AModule(config, "keyboard-state", id, false, !config["disable-scroll"].asBool()), + const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : AModule(config, "keyboard-state", id, reap_mtx, reap, false, + !config["disable-scroll"].asBool()), box_(bar.orientation, 0), numlock_label_(""), capslock_label_(""), diff --git a/src/modules/load.cpp b/src/modules/load.cpp index 69a37b4eb..f6855b55a 100644 --- a/src/modules/load.cpp +++ b/src/modules/load.cpp @@ -9,8 +9,9 @@ #include #endif -waybar::modules::Load::Load(const std::string& id, const Json::Value& config) - : ALabel(config, "load", id, "{load1}", 10) { +waybar::modules::Load::Load(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "load", id, "{load1}", reap_mtx, reap, 10) { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); diff --git a/src/modules/memory/common.cpp b/src/modules/memory/common.cpp index a83f6526f..6300b0239 100644 --- a/src/modules/memory/common.cpp +++ b/src/modules/memory/common.cpp @@ -1,7 +1,8 @@ #include "modules/memory.hpp" -waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config) - : ALabel(config, "memory", id, "{}%", 30) { +waybar::modules::Memory::Memory(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "memory", id, "{}%", reap_mtx, reap, 30) { thread_ = [this] { dp.emit(); thread_.sleep_for(interval_); diff --git a/src/modules/mpd/mpd.cpp b/src/modules/mpd/mpd.cpp index 8e6bbb253..e60b5d38e 100644 --- a/src/modules/mpd/mpd.cpp +++ b/src/modules/mpd/mpd.cpp @@ -15,8 +15,9 @@ namespace waybar::modules { } // namespace waybar::modules #endif -waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config) - : ALabel(config, "mpd", id, "{album} - {artist} - {title}", 5, false, true), +waybar::modules::MPD::MPD(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "mpd", id, "{album} - {artist} - {title}", reap_mtx, reap, 5, false, true), module_name_(id.empty() ? "mpd" : "mpd#" + id), server_(nullptr), port_(config_["port"].isUInt() ? config["port"].asUInt() : 0), diff --git a/src/modules/mpris/mpris.cpp b/src/modules/mpris/mpris.cpp index 2b345fc5a..d782fa0df 100644 --- a/src/modules/mpris/mpris.cpp +++ b/src/modules/mpris/mpris.cpp @@ -18,8 +18,9 @@ namespace waybar::modules::mpris { const std::string DEFAULT_FORMAT = "{player} ({status}): {dynamic}"; -Mpris::Mpris(const std::string& id, const Json::Value& config) - : ALabel(config, "mpris", id, DEFAULT_FORMAT, 0, false, true), +Mpris::Mpris(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "mpris", id, DEFAULT_FORMAT, reap_mtx, reap, 0, false, true), tooltip_(DEFAULT_FORMAT), artist_len_(-1), album_len_(-1), diff --git a/src/modules/network.cpp b/src/modules/network.cpp index d0b7970c5..0b33b2a30 100644 --- a/src/modules/network.cpp +++ b/src/modules/network.cpp @@ -21,10 +21,10 @@ namespace { using namespace waybar::util; -constexpr const char *DEFAULT_FORMAT = "{ifname}"; +constexpr const char* DEFAULT_FORMAT = "{ifname}"; } // namespace -constexpr const char *NETDEV_FILE = +constexpr const char* NETDEV_FILE = "/proc/net/dev"; // std::ifstream does not take std::string_view as param std::optional> waybar::modules::Network::readBandwidthUsage() { @@ -82,8 +82,9 @@ waybar::modules::Network::readBandwidthUsage() { return {{receivedBytes, transmittedBytes}}; } -waybar::modules::Network::Network(const std::string &id, const Json::Value &config) - : ALabel(config, "network", id, DEFAULT_FORMAT, 60) { +waybar::modules::Network::Network(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "network", id, DEFAULT_FORMAT, reap_mtx, reap, 60) { // Start with some "text" in the module's label_. update() will then // update it. Since the text should be different, update() will be able // to show or hide the event_box_. This is to work around the case where @@ -216,7 +217,7 @@ void waybar::modules::Network::worker() { thread_timer_.sleep_for(interval_); }; #ifdef WANT_RFKILL - rfkill_.on_update.connect([this](auto &) { + rfkill_.on_update.connect([this](auto&) { /* If we are here, it's likely that the network thread already holds the mutex and will be * holding it for a next few seconds. * Let's delegate the update to the timer thread instead of blocking the main thread. @@ -397,7 +398,7 @@ auto waybar::modules::Network::update() -> void { } // https://gist.github.com/rressi/92af77630faf055934c723ce93ae2495 -static bool wildcardMatch(const std::string &pattern, const std::string &text) { +static bool wildcardMatch(const std::string& pattern, const std::string& text) { auto P = int(pattern.size()); auto T = int(text.size()); @@ -435,9 +436,9 @@ static bool wildcardMatch(const std::string &pattern, const std::string &text) { return p == P; } -bool waybar::modules::Network::matchInterface(const std::string &ifname, - const std::vector &altnames, - std::string &matched) const { +bool waybar::modules::Network::matchInterface(const std::string& ifname, + const std::vector& altnames, + std::string& matched) const { if (!config_["interface"].isString()) { return false; } @@ -448,7 +449,7 @@ bool waybar::modules::Network::matchInterface(const std::string &ifname, return true; } - for (const auto &altname : altnames) { + for (const auto& altname : altnames) { if (config_ifname == altname || wildcardMatch(config_ifname, altname)) { matched = altname; return true; @@ -478,8 +479,8 @@ void waybar::modules::Network::clearIface() { frequency_ = 0.0; } -int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { - auto net = static_cast(data); +int waybar::modules::Network::handleEvents(struct nl_msg* msg, void* data) { + auto net = static_cast(data); std::lock_guard lock(net->mutex_); auto nh = nlmsg_hdr(msg); bool is_del_event = false; @@ -488,8 +489,8 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { case RTM_DELLINK: is_del_event = true; case RTM_NEWLINK: { - struct ifinfomsg *ifi = static_cast(NLMSG_DATA(nh)); - struct nlattr *attrs[IFLA_MAX + 1]; + struct ifinfomsg* ifi = static_cast(NLMSG_DATA(nh)); + struct nlattr* attrs[IFLA_MAX + 1]; std::string ifname; std::vector altnames; std::optional carrier; @@ -517,7 +518,7 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { } if (attrs[IFLA_IFNAME] != nullptr) { - const char *ifname_ptr = nla_get_string(attrs[IFLA_IFNAME]); + const char* ifname_ptr = nla_get_string(attrs[IFLA_IFNAME]); size_t ifname_len = nla_len(attrs[IFLA_IFNAME]) - 1; // minus \0 ifname = std::string(ifname_ptr, ifname_len); } @@ -527,12 +528,12 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { } if (attrs[IFLA_PROP_LIST] != nullptr) { - struct nlattr *prop; + struct nlattr* prop; int rem; nla_for_each_nested(prop, attrs[IFLA_PROP_LIST], rem) { if (nla_type(prop) == IFLA_ALT_IFNAME) { - const char *altname_ptr = nla_get_string(prop); + const char* altname_ptr = nla_get_string(prop); size_t altname_len = nla_len(prop) - 1; // minus \0 altnames.emplace_back(altname_ptr, altname_len); } @@ -605,9 +606,9 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { case RTM_DELADDR: is_del_event = true; case RTM_NEWADDR: { - struct ifaddrmsg *ifa = static_cast(NLMSG_DATA(nh)); + struct ifaddrmsg* ifa = static_cast(NLMSG_DATA(nh)); ssize_t attrlen = IFA_PAYLOAD(nh); - struct rtattr *ifa_rta = IFA_RTA(ifa); + struct rtattr* ifa_rta = IFA_RTA(ifa); if ((int)ifa->ifa_index != net->ifid_) { return NL_OK; @@ -681,10 +682,10 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { // Based on https://gist.github.com/Yawning/c70d804d4b8ae78cc698 // to find the interface used to reach the outside world - struct rtmsg *rtm = static_cast(NLMSG_DATA(nh)); + struct rtmsg* rtm = static_cast(NLMSG_DATA(nh)); int family = rtm->rtm_family; ssize_t attrlen = RTM_PAYLOAD(nh); - struct rtattr *attr = RTM_RTA(rtm); + struct rtattr* attr = RTM_RTA(rtm); char gateway_addr[INET6_ADDRSTRLEN]; bool has_gateway = false; bool has_destination = false; @@ -725,17 +726,17 @@ int waybar::modules::Network::handleEvents(struct nl_msg *msg, void *data) { break; } for (uint32_t i = 0; i < dstlen; i += 1) { - c |= *((unsigned char *)RTA_DATA(attr) + i); + c |= *((unsigned char*)RTA_DATA(attr) + i); } has_destination = (c == 0); break; } case RTA_OIF: /* The output interface index. */ - temp_idx = *static_cast(RTA_DATA(attr)); + temp_idx = *static_cast(RTA_DATA(attr)); break; case RTA_PRIORITY: - priority = *(uint32_t *)RTA_DATA(attr); + priority = *(uint32_t*)RTA_DATA(attr); break; default: break; @@ -826,18 +827,18 @@ void waybar::modules::Network::askForStateDump(void) { } } -int waybar::modules::Network::handleEventsDone(struct nl_msg *msg, void *data) { - auto net = static_cast(data); +int waybar::modules::Network::handleEventsDone(struct nl_msg* msg, void* data) { + auto net = static_cast(data); net->dump_in_progress_ = false; net->askForStateDump(); return NL_OK; } -int waybar::modules::Network::handleScan(struct nl_msg *msg, void *data) { - auto net = static_cast(data); - auto gnlh = static_cast(nlmsg_data(nlmsg_hdr(msg))); - struct nlattr *tb[NL80211_ATTR_MAX + 1]; - struct nlattr *bss[NL80211_BSS_MAX + 1]; +int waybar::modules::Network::handleScan(struct nl_msg* msg, void* data) { + auto net = static_cast(data); + auto gnlh = static_cast(nlmsg_data(nlmsg_hdr(msg))); + struct nlattr* tb[NL80211_ATTR_MAX + 1]; + struct nlattr* bss[NL80211_BSS_MAX + 1]; struct nla_policy bss_policy[NL80211_BSS_MAX + 1]{}; bss_policy[NL80211_BSS_TSF].type = NLA_U64; bss_policy[NL80211_BSS_FREQUENCY].type = NLA_U32; @@ -869,9 +870,9 @@ int waybar::modules::Network::handleScan(struct nl_msg *msg, void *data) { return NL_OK; } -void waybar::modules::Network::parseEssid(struct nlattr **bss) { +void waybar::modules::Network::parseEssid(struct nlattr** bss) { if (bss[NL80211_BSS_INFORMATION_ELEMENTS] != nullptr) { - auto ies = static_cast(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS])); + auto ies = static_cast(nla_data(bss[NL80211_BSS_INFORMATION_ELEMENTS])); auto ies_len = nla_len(bss[NL80211_BSS_INFORMATION_ELEMENTS]); const auto hdr_len = 2; while (ies_len > hdr_len && ies[0] != 0) { @@ -888,7 +889,7 @@ void waybar::modules::Network::parseEssid(struct nlattr **bss) { } } -void waybar::modules::Network::parseSignal(struct nlattr **bss) { +void waybar::modules::Network::parseSignal(struct nlattr** bss) { if (bss[NL80211_BSS_SIGNAL_MBM] != nullptr) { // signalstrength in dBm from mBm signal_strength_dbm_ = nla_get_s32(bss[NL80211_BSS_SIGNAL_MBM]) / 100; @@ -924,16 +925,16 @@ void waybar::modules::Network::parseSignal(struct nlattr **bss) { } } -void waybar::modules::Network::parseFreq(struct nlattr **bss) { +void waybar::modules::Network::parseFreq(struct nlattr** bss) { if (bss[NL80211_BSS_FREQUENCY] != nullptr) { // in GHz frequency_ = (double)nla_get_u32(bss[NL80211_BSS_FREQUENCY]) / 1000; } } -void waybar::modules::Network::parseBssid(struct nlattr **bss) { +void waybar::modules::Network::parseBssid(struct nlattr** bss) { if (bss[NL80211_BSS_BSSID] != nullptr) { - auto bssid = static_cast(nla_data(bss[NL80211_BSS_BSSID])); + auto bssid = static_cast(nla_data(bss[NL80211_BSS_BSSID])); auto bssid_len = nla_len(bss[NL80211_BSS_BSSID]); if (bssid_len == 6) { bssid_ = fmt::format("{:x}:{:x}:{:x}:{:x}:{:x}:{:x}", bssid[0], bssid[1], bssid[2], bssid[3], @@ -942,7 +943,7 @@ void waybar::modules::Network::parseBssid(struct nlattr **bss) { } } -bool waybar::modules::Network::associatedOrJoined(struct nlattr **bss) { +bool waybar::modules::Network::associatedOrJoined(struct nlattr** bss) { if (bss[NL80211_BSS_STATUS] == nullptr) { return false; } @@ -958,7 +959,7 @@ bool waybar::modules::Network::associatedOrJoined(struct nlattr **bss) { } auto waybar::modules::Network::getInfo() -> void { - struct nl_msg *nl_msg = nlmsg_alloc(); + struct nl_msg* nl_msg = nlmsg_alloc(); if (nl_msg == nullptr) { return; } diff --git a/src/modules/niri/backend.cpp b/src/modules/niri/backend.cpp index fa4dc287e..1ee1bf3fd 100644 --- a/src/modules/niri/backend.cpp +++ b/src/modules/niri/backend.cpp @@ -21,7 +21,7 @@ namespace waybar::modules::niri { int IPC::connectToSocket() { - const char *socket_path = getenv("NIRI_SOCKET"); + const char* socket_path = getenv("NIRI_SOCKET"); if (socket_path == nullptr) { spdlog::warn("Niri is not running, niri IPC will not be available."); @@ -43,7 +43,7 @@ int IPC::connectToSocket() { int l = sizeof(struct sockaddr_un); - if (connect(socketfd, (struct sockaddr *)&addr, l) == -1) { + if (connect(socketfd, (struct sockaddr*)&addr, l) == -1) { close(socketfd); throw std::runtime_error("unable to connect"); } @@ -58,7 +58,7 @@ void IPC::startIPC() { int socketfd; try { socketfd = connectToSocket(); - } catch (std::exception &e) { + } catch (std::exception& e) { spdlog::error("Niri IPC: failed to start, reason: {}", e.what()); return; } @@ -87,7 +87,7 @@ void IPC::startIPC() { try { parseIPC(line); - } catch (std::exception &e) { + } catch (std::exception& e) { spdlog::warn("Failed to parse IPC message: {}, reason: {}", line, e.what()); } catch (...) { throw; @@ -98,7 +98,7 @@ void IPC::startIPC() { }).detach(); } -void IPC::parseIPC(const std::string &line) { +void IPC::parseIPC(const std::string& line) { const auto ev = parser_.parse(line); const auto members = ev.getMemberNames(); if (members.size() != 1) throw std::runtime_error("Event must have a single member"); @@ -106,28 +106,28 @@ void IPC::parseIPC(const std::string &line) { { auto lock = lockData(); - if (const auto &payload = ev["WorkspacesChanged"]) { + if (const auto& payload = ev["WorkspacesChanged"]) { workspaces_.clear(); - const auto &values = payload["workspaces"]; + const auto& values = payload["workspaces"]; std::copy(values.begin(), values.end(), std::back_inserter(workspaces_)); - std::sort(workspaces_.begin(), workspaces_.end(), [](const auto &a, const auto &b) { - const auto &aOutput = a["output"].asString(); - const auto &bOutput = b["output"].asString(); + std::sort(workspaces_.begin(), workspaces_.end(), [](const auto& a, const auto& b) { + const auto& aOutput = a["output"].asString(); + const auto& bOutput = b["output"].asString(); const auto aIdx = a["idx"].asUInt(); const auto bIdx = b["idx"].asUInt(); if (aOutput == bOutput) return aIdx < bIdx; return aOutput < bOutput; }); - } else if (const auto &payload = ev["WorkspaceActivated"]) { + } else if (const auto& payload = ev["WorkspaceActivated"]) { const auto id = payload["id"].asUInt64(); const auto focused = payload["focused"].asBool(); auto it = std::find_if(workspaces_.begin(), workspaces_.end(), - [id](const auto &ws) { return ws["id"].asUInt64() == id; }); + [id](const auto& ws) { return ws["id"].asUInt64() == id; }); if (it != workspaces_.end()) { - const auto &ws = *it; - const auto &output = ws["output"].asString(); - for (auto &ws : workspaces_) { + const auto& ws = *it; + const auto& output = ws["output"].asString(); + for (auto& ws : workspaces_) { const auto got_activated = (ws["id"].asUInt64() == id); if (ws["output"] == output) ws["is_active"] = got_activated; @@ -136,70 +136,70 @@ void IPC::parseIPC(const std::string &line) { } else { spdlog::error("Activated unknown workspace"); } - } else if (const auto &payload = ev["WorkspaceActiveWindowChanged"]) { + } else if (const auto& payload = ev["WorkspaceActiveWindowChanged"]) { const auto workspaceId = payload["workspace_id"].asUInt64(); - auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [workspaceId](const auto &ws) { + auto it = std::find_if(workspaces_.begin(), workspaces_.end(), [workspaceId](const auto& ws) { return ws["id"].asUInt64() == workspaceId; }); if (it != workspaces_.end()) { - auto &ws = *it; + auto& ws = *it; ws["active_window_id"] = payload["active_window_id"]; } else { spdlog::error("Active window changed on unknown workspace"); } - } else if (const auto &payload = ev["WorkspaceUrgencyChanged"]) { + } else if (const auto& payload = ev["WorkspaceUrgencyChanged"]) { const auto id = payload["id"].asUInt64(); const auto urgent = payload["urgent"].asBool(); auto it = std::find_if(workspaces_.begin(), workspaces_.end(), - [id](const auto &ws) { return ws["id"].asUInt64() == id; }); + [id](const auto& ws) { return ws["id"].asUInt64() == id; }); if (it != workspaces_.end()) { - auto &ws = *it; + auto& ws = *it; ws["is_urgent"] = urgent; } else { spdlog::error("Urgency changed for unknown workspace"); } - } else if (const auto &payload = ev["KeyboardLayoutsChanged"]) { - const auto &layouts = payload["keyboard_layouts"]; - const auto &names = layouts["names"]; + } else if (const auto& payload = ev["KeyboardLayoutsChanged"]) { + const auto& layouts = payload["keyboard_layouts"]; + const auto& names = layouts["names"]; keyboardLayoutCurrent_ = layouts["current_idx"].asUInt(); keyboardLayoutNames_.clear(); - for (const auto &fullName : names) keyboardLayoutNames_.push_back(fullName.asString()); - } else if (const auto &payload = ev["KeyboardLayoutSwitched"]) { + for (const auto& fullName : names) keyboardLayoutNames_.push_back(fullName.asString()); + } else if (const auto& payload = ev["KeyboardLayoutSwitched"]) { keyboardLayoutCurrent_ = payload["idx"].asUInt(); - } else if (const auto &payload = ev["WindowsChanged"]) { + } else if (const auto& payload = ev["WindowsChanged"]) { windows_.clear(); - const auto &values = payload["windows"]; + const auto& values = payload["windows"]; std::copy(values.begin(), values.end(), std::back_inserter(windows_)); - } else if (const auto &payload = ev["WindowOpenedOrChanged"]) { - const auto &window = payload["window"]; + } else if (const auto& payload = ev["WindowOpenedOrChanged"]) { + const auto& window = payload["window"]; const auto id = window["id"].asUInt64(); auto it = std::find_if(windows_.begin(), windows_.end(), - [id](const auto &win) { return win["id"].asUInt64() == id; }); + [id](const auto& win) { return win["id"].asUInt64() == id; }); if (it == windows_.end()) { windows_.push_back(window); if (window["is_focused"].asBool()) { - for (auto &win : windows_) { + for (auto& win : windows_) { win["is_focused"] = win["id"].asUInt64() == id; } } } else { *it = window; } - } else if (const auto &payload = ev["WindowClosed"]) { + } else if (const auto& payload = ev["WindowClosed"]) { const auto id = payload["id"].asUInt64(); auto it = std::find_if(windows_.begin(), windows_.end(), - [id](const auto &win) { return win["id"].asUInt64() == id; }); + [id](const auto& win) { return win["id"].asUInt64() == id; }); if (it != windows_.end()) { windows_.erase(it); } else { spdlog::error("Unknown window closed"); } - } else if (const auto &payload = ev["WindowFocusChanged"]) { + } else if (const auto& payload = ev["WindowFocusChanged"]) { const auto focused = !payload["id"].isNull(); const auto id = payload["id"].asUInt64(); - for (auto &win : windows_) { + for (auto& win : windows_) { win["is_focused"] = focused && win["id"].asUInt64() == id; } } @@ -207,14 +207,14 @@ void IPC::parseIPC(const std::string &line) { std::unique_lock lock(callbackMutex_); - for (auto &[eventname, handler] : callbacks_) { + for (auto& [eventname, handler] : callbacks_) { if (eventname == members[0]) { handler->onEvent(ev); } } } -void IPC::registerForIPC(const std::string &ev, EventHandler *ev_handler) { +void IPC::registerForIPC(const std::string& ev, EventHandler* ev_handler) { if (ev_handler == nullptr) { return; } @@ -223,7 +223,7 @@ void IPC::registerForIPC(const std::string &ev, EventHandler *ev_handler) { callbacks_.emplace_back(ev, ev_handler); } -void IPC::unregisterForIPC(EventHandler *ev_handler) { +void IPC::unregisterForIPC(EventHandler* ev_handler) { if (ev_handler == nullptr) { return; } @@ -231,7 +231,7 @@ void IPC::unregisterForIPC(EventHandler *ev_handler) { std::unique_lock lock(callbackMutex_); for (auto it = callbacks_.begin(); it != callbacks_.end();) { - auto &[eventname, handler] = *it; + auto& [eventname, handler] = *it; if (handler == ev_handler) { it = callbacks_.erase(it); } else { @@ -240,7 +240,7 @@ void IPC::unregisterForIPC(EventHandler *ev_handler) { } } -Json::Value IPC::send(const Json::Value &request) { +Json::Value IPC::send(const Json::Value& request) { int socketfd = connectToSocket(); if (socketfd == -1) throw std::runtime_error("Niri is not running"); diff --git a/src/modules/niri/language.cpp b/src/modules/niri/language.cpp index 496e54048..493a8f3f9 100644 --- a/src/modules/niri/language.cpp +++ b/src/modules/niri/language.cpp @@ -8,8 +8,9 @@ namespace waybar::modules::niri { -Language::Language(const std::string &id, const Bar &bar, const Json::Value &config) - : ALabel(config, "language", id, "{}", 0, false), bar_(bar) { +Language::Language(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "language", id, "{}", reap_mtx, reap, 0, false), bar_(bar) { label_.hide(); if (!gIPC) gIPC = std::make_unique(); @@ -32,7 +33,7 @@ void Language::updateFromIPC() { auto ipcLock = gIPC->lockData(); layouts_.clear(); - for (const auto &fullName : gIPC->keyboardLayoutNames()) layouts_.push_back(getLayout(fullName)); + for (const auto& fullName : gIPC->keyboardLayoutNames()) layouts_.push_back(getLayout(fullName)); current_idx_ = gIPC->keyboardLayoutCurrent(); } @@ -51,7 +52,7 @@ void Language::doUpdate() { label_.hide(); return; } - const auto &layout = layouts_[current_idx_]; + const auto& layout = layouts_[current_idx_]; spdlog::debug("niri language update with full name {}", layout.full_name); spdlog::debug("niri language update with short name {}", layout.short_name); @@ -97,7 +98,7 @@ void Language::update() { ALabel::update(); } -void Language::onEvent(const Json::Value &ev) { +void Language::onEvent(const Json::Value& ev) { if (ev["KeyboardLayoutsChanged"]) { updateFromIPC(); } else if (ev["KeyboardLayoutSwitched"]) { @@ -109,11 +110,11 @@ void Language::onEvent(const Json::Value &ev) { dp.emit(); } -Language::Layout Language::getLayout(const std::string &fullName) { - auto *const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES); +Language::Layout Language::getLayout(const std::string& fullName) { + auto* const context = rxkb_context_new(RXKB_CONTEXT_LOAD_EXOTIC_RULES); rxkb_context_parse_default_ruleset(context); - rxkb_layout *layout = rxkb_layout_first(context); + rxkb_layout* layout = rxkb_layout_first(context); while (layout != nullptr) { std::string nameOfLayout = rxkb_layout_get_description(layout); @@ -123,10 +124,10 @@ Language::Layout Language::getLayout(const std::string &fullName) { } auto name = std::string(rxkb_layout_get_name(layout)); - const auto *variantPtr = rxkb_layout_get_variant(layout); + const auto* variantPtr = rxkb_layout_get_variant(layout); std::string variant = variantPtr == nullptr ? "" : std::string(variantPtr); - const auto *descriptionPtr = rxkb_layout_get_brief(layout); + const auto* descriptionPtr = rxkb_layout_get_brief(layout); std::string description = descriptionPtr == nullptr ? "" : std::string(descriptionPtr); Layout info = Layout{nameOfLayout, name, variant, description}; diff --git a/src/modules/niri/window.cpp b/src/modules/niri/window.cpp index 6e6fd36ff..53aed8e43 100644 --- a/src/modules/niri/window.cpp +++ b/src/modules/niri/window.cpp @@ -9,8 +9,9 @@ namespace waybar::modules::niri { -Window::Window(const std::string &id, const Bar &bar, const Json::Value &config) - : AAppIconLabel(config, "window", id, "{title}", 0, true), bar_(bar) { +Window::Window(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AAppIconLabel(config, "window", id, "{title}", reap_mtx, reap, 0, true), bar_(bar) { if (!gIPC) gIPC = std::make_unique(); gIPC->registerForIPC("WindowsChanged", this); @@ -23,16 +24,16 @@ Window::Window(const std::string &id, const Bar &bar, const Json::Value &config) Window::~Window() { gIPC->unregisterForIPC(this); } -void Window::onEvent(const Json::Value &ev) { dp.emit(); } +void Window::onEvent(const Json::Value& ev) { dp.emit(); } void Window::doUpdate() { auto ipcLock = gIPC->lockData(); - const auto &windows = gIPC->windows(); - const auto &workspaces = gIPC->workspaces(); + const auto& windows = gIPC->windows(); + const auto& workspaces = gIPC->workspaces(); const auto separateOutputs = config_["separate-outputs"].asBool(); - const auto ws_it = std::find_if(workspaces.cbegin(), workspaces.cend(), [&](const auto &ws) { + const auto ws_it = std::find_if(workspaces.cbegin(), workspaces.cend(), [&](const auto& ws) { if (separateOutputs) { return ws["is_active"].asBool() && ws["output"].asString() == bar_.output->name; } @@ -46,13 +47,13 @@ void Window::doUpdate() { } else { const auto id = (*ws_it)["active_window_id"].asUInt64(); it = std::find_if(windows.cbegin(), windows.cend(), - [id](const auto &win) { return win["id"].asUInt64() == id; }); + [id](const auto& win) { return win["id"].asUInt64() == id; }); } setClass("empty", ws_it == workspaces.cend() || (*ws_it)["active_window_id"].isNull()); if (it != windows.cend()) { - const auto &window = *it; + const auto& window = *it; const auto title = window["title"].asString(); const auto appId = window["app_id"].asString(); @@ -71,7 +72,7 @@ void Window::doUpdate() { const auto id = window["id"].asUInt64(); const auto workspaceId = window["workspace_id"].asUInt64(); - const auto isSolo = std::none_of(windows.cbegin(), windows.cend(), [&](const auto &win) { + const auto isSolo = std::none_of(windows.cbegin(), windows.cend(), [&](const auto& win) { return win["id"].asUInt64() != id && win["workspace_id"].asUInt64() == workspaceId; }); setClass("solo", isSolo); @@ -95,7 +96,7 @@ void Window::update() { AAppIconLabel::update(); } -void Window::setClass(const std::string &className, bool enable) { +void Window::setClass(const std::string& className, bool enable) { auto styleContext = bar_.window.get_style_context(); if (enable) { if (!styleContext->has_class(className)) { diff --git a/src/modules/niri/workspaces.cpp b/src/modules/niri/workspaces.cpp index 7dfc0b351..86cb18501 100644 --- a/src/modules/niri/workspaces.cpp +++ b/src/modules/niri/workspaces.cpp @@ -6,8 +6,11 @@ namespace waybar::modules::niri { -Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) - : AModule(config, "workspaces", id, false, false), bar_(bar), box_(bar.orientation, 0) { +Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AModule(config, "workspaces", id, reap_mtx, reap, false, false), + bar_(bar), + box_(bar.orientation, 0) { box_.set_name("workspaces"); if (!id.empty()) { box_.get_style_context()->add_class(id); @@ -27,16 +30,16 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value Workspaces::~Workspaces() { gIPC->unregisterForIPC(this); } -void Workspaces::onEvent(const Json::Value &ev) { dp.emit(); } +void Workspaces::onEvent(const Json::Value& ev) { dp.emit(); } void Workspaces::doUpdate() { auto ipcLock = gIPC->lockData(); const auto alloutputs = config_["all-outputs"].asBool(); std::vector my_workspaces; - const auto &workspaces = gIPC->workspaces(); + const auto& workspaces = gIPC->workspaces(); std::copy_if(workspaces.cbegin(), workspaces.cend(), std::back_inserter(my_workspaces), - [&](const auto &ws) { + [&](const auto& ws) { if (alloutputs) return true; return ws["output"].asString() == bar_.output->name; }); @@ -44,7 +47,7 @@ void Workspaces::doUpdate() { // Remove buttons for removed workspaces. for (auto it = buttons_.begin(); it != buttons_.end();) { auto ws = std::find_if(my_workspaces.begin(), my_workspaces.end(), - [it](const auto &ws) { return ws["id"].asUInt64() == it->first; }); + [it](const auto& ws) { return ws["id"].asUInt64() == it->first; }); if (ws == my_workspaces.end()) { it = buttons_.erase(it); } else { @@ -53,9 +56,9 @@ void Workspaces::doUpdate() { } // Add buttons for new workspaces, update existing ones. - for (const auto &ws : my_workspaces) { + for (const auto& ws : my_workspaces) { auto bit = buttons_.find(ws["id"].asUInt64()); - auto &button = bit == buttons_.end() ? addButton(ws) : bit->second; + auto& button = bit == buttons_.end() ? addButton(ws) : bit->second; auto style_context = button.get_style_context(); if (ws["is_focused"].asBool()) @@ -103,13 +106,13 @@ void Workspaces::doUpdate() { fmt::arg("output", ws["output"].asString())); } if (!config_["disable-markup"].asBool()) { - static_cast(button.get_children()[0])->set_markup(name); + static_cast(button.get_children()[0])->set_markup(name); } else { button.set_label(name); } if (config_["current-only"].asBool()) { - const auto *property = alloutputs ? "is_focused" : "is_active"; + const auto* property = alloutputs ? "is_focused" : "is_active"; if (ws[property].asBool()) button.show(); else @@ -121,12 +124,12 @@ void Workspaces::doUpdate() { // Refresh the button order. for (auto it = my_workspaces.cbegin(); it != my_workspaces.cend(); ++it) { - const auto &ws = *it; + const auto& ws = *it; auto pos = ws["idx"].asUInt() - 1; if (alloutputs) pos = it - my_workspaces.cbegin(); - auto &button = buttons_[ws["id"].asUInt64()]; + auto& button = buttons_[ws["id"].asUInt64()]; box_.reorder_child(button, pos); } } @@ -136,7 +139,7 @@ void Workspaces::update() { AModule::update(); } -Gtk::Button &Workspaces::addButton(const Json::Value &ws) { +Gtk::Button& Workspaces::addButton(const Json::Value& ws) { std::string name; if (ws["name"]) { name = ws["name"].asString(); @@ -145,7 +148,7 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) { } auto pair = buttons_.emplace(ws["id"].asUInt64(), name); - auto &&button = pair.first->second; + auto&& button = pair.first->second; box_.pack_start(button, false, false, 0); button.set_relief(Gtk::RELIEF_NONE); if (!config_["disable-click"].asBool()) { @@ -154,13 +157,13 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) { try { // {"Action":{"FocusWorkspace":{"reference":{"Id":1}}}} Json::Value request(Json::objectValue); - auto &action = (request["Action"] = Json::Value(Json::objectValue)); - auto &focusWorkspace = (action["FocusWorkspace"] = Json::Value(Json::objectValue)); - auto &reference = (focusWorkspace["reference"] = Json::Value(Json::objectValue)); + auto& action = (request["Action"] = Json::Value(Json::objectValue)); + auto& focusWorkspace = (action["FocusWorkspace"] = Json::Value(Json::objectValue)); + auto& reference = (focusWorkspace["reference"] = Json::Value(Json::objectValue)); reference["Id"] = id; IPC::send(request); - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Error switching workspace: {}", e.what()); } }); @@ -168,8 +171,8 @@ Gtk::Button &Workspaces::addButton(const Json::Value &ws) { return button; } -std::string Workspaces::getIcon(const std::string &value, const Json::Value &ws) { - const auto &icons = config_["format-icons"]; +std::string Workspaces::getIcon(const std::string& value, const Json::Value& ws) { + const auto& icons = config_["format-icons"]; if (!icons) return value; if (ws["is_urgent"].asBool() && icons["urgent"]) return icons["urgent"].asString(); @@ -181,7 +184,7 @@ std::string Workspaces::getIcon(const std::string &value, const Json::Value &ws) if (ws["is_active"].asBool() && icons["active"]) return icons["active"].asString(); if (ws["name"]) { - const auto &name = ws["name"].asString(); + const auto& name = ws["name"].asString(); if (icons[name]) return icons[name].asString(); } diff --git a/src/modules/power_profiles_daemon.cpp b/src/modules/power_profiles_daemon.cpp index abad763dc..5a82b16d8 100644 --- a/src/modules/power_profiles_daemon.cpp +++ b/src/modules/power_profiles_daemon.cpp @@ -7,8 +7,10 @@ namespace waybar::modules { -PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Value& config) - : ALabel(config, "power-profiles-daemon", id, "{icon}", 0, false, true), connected_(false) { +PowerProfilesDaemon::PowerProfilesDaemon(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "power-profiles-daemon", id, "{icon}", reap_mtx, reap, 0, false, true), + connected_(false) { if (config_["tooltip-format"].isString()) { tooltipFormat_ = config_["tooltip-format"].asString(); } else { diff --git a/src/modules/privacy/privacy.cpp b/src/modules/privacy/privacy.cpp index 904c8fd95..1896a414a 100644 --- a/src/modules/privacy/privacy.cpp +++ b/src/modules/privacy/privacy.cpp @@ -16,8 +16,8 @@ using util::PipewireBackend::PRIVACY_NODE_TYPE_NONE; using util::PipewireBackend::PRIVACY_NODE_TYPE_VIDEO_INPUT; Privacy::Privacy(const std::string& id, const Json::Value& config, Gtk::Orientation orientation, - const std::string& pos) - : AModule(config, "privacy", id), + const std::string& pos, std::mutex& reap_mtx, std::list& reap) + : AModule(config, "privacy", id, reap_mtx, reap), nodes_screenshare(), nodes_audio_in(), nodes_audio_out(), diff --git a/src/modules/privacy/privacy_item.cpp b/src/modules/privacy/privacy_item.cpp index 6424da9e8..3a55eee7b 100644 --- a/src/modules/privacy/privacy_item.cpp +++ b/src/modules/privacy/privacy_item.cpp @@ -12,9 +12,9 @@ namespace waybar::modules::privacy { -PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privacy_type_, - std::list *nodes_, Gtk::Orientation orientation, - const std::string &pos, const uint icon_size, +PrivacyItem::PrivacyItem(const Json::Value& config_, enum PrivacyNodeType privacy_type_, + std::list* nodes_, Gtk::Orientation orientation, + const std::string& pos, const uint icon_size, const uint transition_duration) : Gtk::Revealer(), privacy_type(privacy_type_), @@ -83,7 +83,7 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac // Sets the window to use when showing the tooltip update_tooltip(); this->signal_query_tooltip().connect(sigc::track_obj( - [this](int x, int y, bool keyboard_tooltip, const Glib::RefPtr &tooltip) { + [this](int x, int y, bool keyboard_tooltip, const Glib::RefPtr& tooltip) { tooltip->set_custom(tooltip_window); return true; }, @@ -97,23 +97,23 @@ PrivacyItem::PrivacyItem(const Json::Value &config_, enum PrivacyNodeType privac void PrivacyItem::update_tooltip() { // Removes all old nodes - for (auto *child : tooltip_window.get_children()) { + for (auto* child : tooltip_window.get_children()) { tooltip_window.remove(*child); // despite the remove, still needs a delete to prevent memory leak. Speculating that this might // work differently in GTK4. delete child; } - for (auto *node : *nodes) { - auto *box = Gtk::make_managed(Gtk::ORIENTATION_HORIZONTAL, 4); + for (auto* node : *nodes) { + auto* box = Gtk::make_managed(Gtk::ORIENTATION_HORIZONTAL, 4); // Set device icon - auto *node_icon = Gtk::make_managed(); + auto* node_icon = Gtk::make_managed(); node_icon->set_pixel_size(tooltipIconSize); node_icon->set_from_icon_name(node->getIconName(), Gtk::ICON_SIZE_INVALID); box->add(*node_icon); // Set model - auto *nodeName = Gtk::make_managed(node->getName()); + auto* nodeName = Gtk::make_managed(node->getName()); box->add(*nodeName); tooltip_window.add(*box); diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index ceed20dd8..0c6fbafb0 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -1,7 +1,8 @@ #include "modules/pulseaudio.hpp" -waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value &config) - : ALabel(config, "pulseaudio", id, "{volume}%") { +waybar::modules::Pulseaudio::Pulseaudio(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "pulseaudio", id, "{volume}%", reap_mtx, reap) { event_box_.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); event_box_.signal_scroll_event().connect(sigc::mem_fun(*this, &Pulseaudio::handleScroll)); @@ -9,7 +10,7 @@ waybar::modules::Pulseaudio::Pulseaudio(const std::string &id, const Json::Value backend->setIgnoredSinks(config_["ignored-sinks"]); } -bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll *e) { +bool waybar::modules::Pulseaudio::handleScroll(GdkEventScroll* e) { // change the pulse volume only when no user provided // events are configured if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) { @@ -51,7 +52,7 @@ const std::vector waybar::modules::Pulseaudio::getPulseIcon() const res.push_back(backend->getDefaultSourceName()); std::string nameLC = backend->getSinkPortName() + backend->getFormFactor(); std::transform(nameLC.begin(), nameLC.end(), nameLC.begin(), ::tolower); - for (auto const &port : ports) { + for (auto const& port : ports) { if (nameLC.find(port) != std::string::npos) { if (sink_muted) { res.emplace_back(port + "-muted"); diff --git a/src/modules/pulseaudio_slider.cpp b/src/modules/pulseaudio_slider.cpp index bf85584ed..9050a6af7 100644 --- a/src/modules/pulseaudio_slider.cpp +++ b/src/modules/pulseaudio_slider.cpp @@ -2,8 +2,9 @@ namespace waybar::modules { -PulseaudioSlider::PulseaudioSlider(const std::string& id, const Json::Value& config) - : ASlider(config, "pulseaudio-slider", id) { +PulseaudioSlider::PulseaudioSlider(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ASlider(config, "pulseaudio-slider", id, reap_mtx, reap) { backend = util::AudioBackend::getInstance([this] { this->dp.emit(); }); backend->setIgnoredSinks(config_["ignored-sinks"]); @@ -79,4 +80,4 @@ void PulseaudioSlider::onValueChanged() { backend->changeVolume(volume, min_, max_); } -} // namespace waybar::modules \ No newline at end of file +} // namespace waybar::modules diff --git a/src/modules/river/layout.cpp b/src/modules/river/layout.cpp index 308a09017..c5a7151e8 100644 --- a/src/modules/river/layout.cpp +++ b/src/modules/river/layout.cpp @@ -7,48 +7,48 @@ namespace waybar::modules::river { -static void listen_focused_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, +static void listen_focused_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1, uint32_t tags) { // Intentionally empty } -static void listen_view_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, - struct wl_array *tags) { +static void listen_view_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1, + struct wl_array* tags) { // Intentionally empty } -static void listen_urgent_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, +static void listen_urgent_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1, uint32_t tags) { // Intentionally empty } -static void listen_layout_name(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, - const char *layout) { - static_cast(data)->handle_name(layout); +static void listen_layout_name(void* data, struct zriver_output_status_v1* zriver_output_status_v1, + const char* layout) { + static_cast(data)->handle_name(layout); } -static void listen_layout_name_clear(void *data, - struct zriver_output_status_v1 *zriver_output_status_v1) { - static_cast(data)->handle_clear(); +static void listen_layout_name_clear(void* data, + struct zriver_output_status_v1* zriver_output_status_v1) { + static_cast(data)->handle_clear(); } -static void listen_focused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - struct wl_output *output) { - static_cast(data)->handle_focused_output(output); +static void listen_focused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + struct wl_output* output) { + static_cast(data)->handle_focused_output(output); } -static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - struct wl_output *output) { - static_cast(data)->handle_unfocused_output(output); +static void listen_unfocused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + struct wl_output* output) { + static_cast(data)->handle_unfocused_output(output); } -static void listen_focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - const char *title) { +static void listen_focused_view(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + const char* title) { // Intentionally empty } -static void listen_mode(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - const char *mode) { +static void listen_mode(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + const char* mode) { // Intentionally empty } @@ -67,8 +67,8 @@ static const zriver_seat_status_v1_listener seat_status_listener_impl{ .mode = listen_mode, }; -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version) { +static void handle_global(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) { version = std::min(version, 4); @@ -80,32 +80,33 @@ static void handle_global(void *data, struct wl_registry *registry, uint32_t nam std::to_string(version)); return; } - static_cast(data)->status_manager_ = static_cast( + static_cast(data)->status_manager_ = static_cast( wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version)); } if (std::strcmp(interface, wl_seat_interface.name) == 0) { version = std::min(version, 1); - static_cast(data)->seat_ = static_cast( - wl_registry_bind(registry, name, &wl_seat_interface, version)); + static_cast(data)->seat_ = + static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); } } -static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { // Nobody cares } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -Layout::Layout(const std::string &id, const waybar::Bar &bar, const Json::Value &config) - : waybar::ALabel(config, "layout", id, "{}"), +Layout::Layout(const std::string& id, const waybar::Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : waybar::ALabel(config, "layout", id, "{}", reap_mtx, reap), status_manager_{nullptr}, seat_{nullptr}, bar_(bar), output_status_{nullptr} { - struct wl_display *display = Client::inst()->wl_display; - struct wl_registry *registry = wl_display_get_registry(display); + struct wl_display* display = Client::inst()->wl_display; + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); wl_display_roundtrip(display); @@ -141,7 +142,7 @@ Layout::~Layout() { } } -void Layout::handle_name(const char *name) { +void Layout::handle_name(const char* name) { if (std::strcmp(name, "") == 0 || format_.empty()) { label_.hide(); // hide empty labels or labels with empty format } else { @@ -162,7 +163,7 @@ void Layout::handle_clear() { ALabel::update(); } -void Layout::handle_focused_output(struct wl_output *output) { +void Layout::handle_focused_output(struct wl_output* output) { if (output_ == output) { // if we focused the output this bar belongs to label_.get_style_context()->add_class("focused"); ALabel::update(); @@ -170,7 +171,7 @@ void Layout::handle_focused_output(struct wl_output *output) { focused_output_ = output; } -void Layout::handle_unfocused_output(struct wl_output *output) { +void Layout::handle_unfocused_output(struct wl_output* output) { if (output_ == output) { // if we unfocused the output this bar belongs to label_.get_style_context()->remove_class("focused"); ALabel::update(); diff --git a/src/modules/river/mode.cpp b/src/modules/river/mode.cpp index 1f788e09d..6c65b1e8b 100644 --- a/src/modules/river/mode.cpp +++ b/src/modules/river/mode.cpp @@ -7,23 +7,23 @@ namespace waybar::modules::river { -static void listen_focused_output(void *data, struct zriver_seat_status_v1 *seat_status, - struct wl_output *output) { +static void listen_focused_output(void* data, struct zriver_seat_status_v1* seat_status, + struct wl_output* output) { // Intentionally empty } -static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *seat_status, - struct wl_output *output) { +static void listen_unfocused_output(void* data, struct zriver_seat_status_v1* seat_status, + struct wl_output* output) { // Intentionally empty } -static void listen_focused_view(void *data, struct zriver_seat_status_v1 *seat_status, - const char *title) { +static void listen_focused_view(void* data, struct zriver_seat_status_v1* seat_status, + const char* title) { // Intentionally empty } -static void listen_mode(void *data, struct zriver_seat_status_v1 *seat_status, const char *mode) { - static_cast(data)->handle_mode(mode); +static void listen_mode(void* data, struct zriver_seat_status_v1* seat_status, const char* mode) { + static_cast(data)->handle_mode(mode); } static const zriver_seat_status_v1_listener seat_status_listener_impl = { @@ -33,8 +33,8 @@ static const zriver_seat_status_v1_listener seat_status_listener_impl = { .mode = listen_mode, }; -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version) { +static void handle_global(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) { version = std::min(version, 3); if (version < ZRIVER_SEAT_STATUS_V1_MODE_SINCE_VERSION) { @@ -42,31 +42,32 @@ static void handle_global(void *data, struct wl_registry *registry, uint32_t nam "river server does not support the \"mode\" event; the module will be disabled"); return; } - static_cast(data)->status_manager_ = static_cast( + static_cast(data)->status_manager_ = static_cast( wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version)); } else if (std::strcmp(interface, wl_seat_interface.name) == 0) { version = std::min(version, 1); - static_cast(data)->seat_ = static_cast( - wl_registry_bind(registry, name, &wl_seat_interface, version)); + static_cast(data)->seat_ = + static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); } } -static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { // Nobody cares } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -Mode::Mode(const std::string &id, const waybar::Bar &bar, const Json::Value &config) - : waybar::ALabel(config, "mode", id, "{}"), +Mode::Mode(const std::string& id, const waybar::Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : waybar::ALabel(config, "mode", id, "{}", reap_mtx, reap), status_manager_{nullptr}, seat_{nullptr}, bar_(bar), mode_{""}, seat_status_{nullptr} { - struct wl_display *display = Client::inst()->wl_display; - struct wl_registry *registry = wl_display_get_registry(display); + struct wl_display* display = Client::inst()->wl_display; + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); wl_display_roundtrip(display); @@ -94,7 +95,7 @@ Mode::~Mode() { } } -void Mode::handle_mode(const char *mode) { +void Mode::handle_mode(const char* mode) { if (format_.empty()) { label_.hide(); } else { diff --git a/src/modules/river/tags.cpp b/src/modules/river/tags.cpp index 33be0e6f4..7c831e798 100644 --- a/src/modules/river/tags.cpp +++ b/src/modules/river/tags.cpp @@ -12,19 +12,19 @@ namespace waybar::modules::river { -static void listen_focused_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, +static void listen_focused_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1, uint32_t tags) { - static_cast(data)->handle_focused_tags(tags); + static_cast(data)->handle_focused_tags(tags); } -static void listen_view_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, - struct wl_array *tags) { - static_cast(data)->handle_view_tags(tags); +static void listen_view_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1, + struct wl_array* tags) { + static_cast(data)->handle_view_tags(tags); } -static void listen_urgent_tags(void *data, struct zriver_output_status_v1 *zriver_output_status_v1, +static void listen_urgent_tags(void* data, struct zriver_output_status_v1* zriver_output_status_v1, uint32_t tags) { - static_cast(data)->handle_urgent_tags(tags); + static_cast(data)->handle_urgent_tags(tags); } static const zriver_output_status_v1_listener output_status_listener_impl{ @@ -33,15 +33,15 @@ static const zriver_output_status_v1_listener output_status_listener_impl{ .urgent_tags = listen_urgent_tags, }; -static void listen_command_success(void *data, - struct zriver_command_callback_v1 *zriver_command_callback_v1, - const char *output) { +static void listen_command_success(void* data, + struct zriver_command_callback_v1* zriver_command_callback_v1, + const char* output) { // Do nothing but keep listener to avoid crashing when command was successful } -static void listen_command_failure(void *data, - struct zriver_command_callback_v1 *zriver_command_callback_v1, - const char *output) { +static void listen_command_failure(void* data, + struct zriver_command_callback_v1* zriver_command_callback_v1, + const char* output) { spdlog::error("failure when selecting/toggling tags {}", output); } @@ -50,47 +50,48 @@ static const zriver_command_callback_v1_listener command_callback_listener_impl{ .failure = listen_command_failure, }; -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version) { +static void handle_global(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) { version = std::min(version, 2u); if (version < ZRIVER_OUTPUT_STATUS_V1_URGENT_TAGS_SINCE_VERSION) { spdlog::warn("river server does not support urgent tags"); } - static_cast(data)->status_manager_ = static_cast( + static_cast(data)->status_manager_ = static_cast( wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version)); } if (std::strcmp(interface, zriver_control_v1_interface.name) == 0) { version = std::min(version, 1u); - static_cast(data)->control_ = static_cast( + static_cast(data)->control_ = static_cast( wl_registry_bind(registry, name, &zriver_control_v1_interface, version)); } if (std::strcmp(interface, wl_seat_interface.name) == 0) { version = std::min(version, 1u); - static_cast(data)->seat_ = static_cast( - wl_registry_bind(registry, name, &wl_seat_interface, version)); + static_cast(data)->seat_ = + static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); } } -static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { /* Ignore event */ } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &config) - : waybar::AModule(config, "tags", id, false, false), +Tags::Tags(const std::string& id, const waybar::Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : waybar::AModule(config, "tags", id, reap_mtx, reap, false, false), status_manager_{nullptr}, control_{nullptr}, seat_{nullptr}, bar_(bar), box_{bar.orientation, 0}, output_status_{nullptr} { - struct wl_display *display = Client::inst()->wl_display; - struct wl_registry *registry = wl_display_get_registry(display); + struct wl_display* display = Client::inst()->wl_display; + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); wl_display_roundtrip(display); @@ -129,7 +130,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con buttons_.emplace_back(std::to_string(tag + 1)); } - auto &button = buttons_[tag]; + auto& button = buttons_[tag]; button.set_relief(Gtk::RELIEF_NONE); box_.pack_start(button, false, false, 0); @@ -168,7 +169,7 @@ Tags::~Tags() { } void Tags::handle_show() { - struct wl_output *output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); + struct wl_output* output = gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); output_status_ = zriver_status_manager_v1_get_river_output_status(status_manager_, output); zriver_output_status_v1_add_listener(output_status_, &output_status_listener_impl, this); @@ -178,17 +179,17 @@ void Tags::handle_show() { void Tags::handle_primary_clicked(uint32_t tag) { // Send river command to select tag on left mouse click - zriver_command_callback_v1 *callback; + zriver_command_callback_v1* callback; zriver_control_v1_add_argument(control_, "set-focused-tags"); zriver_control_v1_add_argument(control_, std::to_string(tag).c_str()); callback = zriver_control_v1_run_command(control_, seat_); zriver_command_callback_v1_add_listener(callback, &command_callback_listener_impl, nullptr); } -bool Tags::handle_button_press(GdkEventButton *event_button, uint32_t tag) { +bool Tags::handle_button_press(GdkEventButton* event_button, uint32_t tag) { if (event_button->type == GDK_BUTTON_PRESS && event_button->button == 3) { // Send river command to toggle tag on right mouse click - zriver_command_callback_v1 *callback; + zriver_command_callback_v1* callback; zriver_control_v1_add_argument(control_, "toggle-focused-tags"); zriver_control_v1_add_argument(control_, std::to_string(tag).c_str()); callback = zriver_control_v1_run_command(control_, seat_); @@ -217,9 +218,9 @@ void Tags::handle_focused_tags(uint32_t tags) { } } -void Tags::handle_view_tags(struct wl_array *view_tags) { +void Tags::handle_view_tags(struct wl_array* view_tags) { uint32_t tags = 0; - auto view_tag = reinterpret_cast(view_tags->data); + auto view_tag = reinterpret_cast(view_tags->data); auto end = view_tag + (view_tags->size / sizeof(uint32_t)); for (; view_tag < end; ++view_tag) { tags |= *view_tag; diff --git a/src/modules/river/window.cpp b/src/modules/river/window.cpp index dc7a6459b..cb65a0c91 100644 --- a/src/modules/river/window.cpp +++ b/src/modules/river/window.cpp @@ -9,23 +9,23 @@ namespace waybar::modules::river { -static void listen_focused_view(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - const char *title) { - static_cast(data)->handle_focused_view(title); +static void listen_focused_view(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + const char* title) { + static_cast(data)->handle_focused_view(title); } -static void listen_focused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - struct wl_output *output) { - static_cast(data)->handle_focused_output(output); +static void listen_focused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + struct wl_output* output) { + static_cast(data)->handle_focused_output(output); } -static void listen_unfocused_output(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - struct wl_output *output) { - static_cast(data)->handle_unfocused_output(output); +static void listen_unfocused_output(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + struct wl_output* output) { + static_cast(data)->handle_unfocused_output(output); } -static void listen_mode(void *data, struct zriver_seat_status_v1 *zriver_seat_status_v1, - const char *mode) { +static void listen_mode(void* data, struct zriver_seat_status_v1* zriver_seat_status_v1, + const char* mode) { // This module doesn't care } @@ -36,36 +36,37 @@ static const zriver_seat_status_v1_listener seat_status_listener_impl{ .mode = listen_mode, }; -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version) { +static void handle_global(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { if (std::strcmp(interface, zriver_status_manager_v1_interface.name) == 0) { version = std::min(version, 2); - static_cast(data)->status_manager_ = static_cast( + static_cast(data)->status_manager_ = static_cast( wl_registry_bind(registry, name, &zriver_status_manager_v1_interface, version)); } if (std::strcmp(interface, wl_seat_interface.name) == 0) { version = std::min(version, 1); - static_cast(data)->seat_ = static_cast( - wl_registry_bind(registry, name, &wl_seat_interface, version)); + static_cast(data)->seat_ = + static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); } } -static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { /* Ignore event */ } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -Window::Window(const std::string &id, const waybar::Bar &bar, const Json::Value &config) - : waybar::ALabel(config, "window", id, "{}", 30), +Window::Window(const std::string& id, const waybar::Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : waybar::ALabel(config, "window", id, "{}", reap_mtx, reap, 30), status_manager_{nullptr}, seat_{nullptr}, bar_(bar), seat_status_{nullptr} { - struct wl_display *display = Client::inst()->wl_display; - struct wl_registry *registry = wl_display_get_registry(display); + struct wl_display* display = Client::inst()->wl_display; + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); wl_display_roundtrip(display); @@ -95,7 +96,7 @@ Window::~Window() { } } -void Window::handle_focused_view(const char *title) { +void Window::handle_focused_view(const char* title) { // don't change the label on unfocused outputs. // this makes the current output report its currently focused view, and unfocused outputs will // report their last focused views. when freshly starting the bar, unfocused outputs don't have a @@ -116,7 +117,7 @@ void Window::handle_focused_view(const char *title) { ALabel::update(); } -void Window::handle_focused_output(struct wl_output *output) { +void Window::handle_focused_output(struct wl_output* output) { if (output_ == output) { // if we focused the output this bar belongs to label_.get_style_context()->add_class("focused"); ALabel::update(); @@ -124,7 +125,7 @@ void Window::handle_focused_output(struct wl_output *output) { focused_output_ = output; } -void Window::handle_unfocused_output(struct wl_output *output) { +void Window::handle_unfocused_output(struct wl_output* output) { if (output_ == output) { // if we unfocused the output this bar belongs to label_.get_style_context()->remove_class("focused"); ALabel::update(); diff --git a/src/modules/sndio.cpp b/src/modules/sndio.cpp index 72e7207ce..0abfe3a4b 100644 --- a/src/modules/sndio.cpp +++ b/src/modules/sndio.cpp @@ -9,8 +9,8 @@ namespace waybar::modules { -void ondesc(void *arg, struct sioctl_desc *d, int curval) { - auto self = static_cast(arg); +void ondesc(void* arg, struct sioctl_desc* d, int curval) { + auto self = static_cast(arg); if (d == NULL) { // d is NULL when the list is done return; @@ -18,8 +18,8 @@ void ondesc(void *arg, struct sioctl_desc *d, int curval) { self->set_desc(d, curval); } -void onval(void *arg, unsigned int addr, unsigned int val) { - auto self = static_cast(arg); +void onval(void* arg, unsigned int addr, unsigned int val) { + auto self = static_cast(arg); self->put_val(addr, val); } @@ -40,8 +40,9 @@ auto Sndio::connect_to_sndio() -> void { pfds_.reserve(sioctl_nfds(hdl_)); } -Sndio::Sndio(const std::string &id, const Json::Value &config) - : ALabel(config, "sndio", id, "{volume}%", 1, false, true), +Sndio::Sndio(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "sndio", id, "{volume}%", reap_mtx, reap, 1, false, true), hdl_(nullptr), pfds_(0), addr_(0), @@ -80,7 +81,7 @@ Sndio::Sndio(const std::string &id, const Json::Value &config) while (thread_.isRunning()) { try { connect_to_sndio(); - } catch (std::runtime_error const &e) { + } catch (std::runtime_error const& e) { // avoid leaking hdl_ if (hdl_) { sioctl_close(hdl_); @@ -122,7 +123,7 @@ auto Sndio::update() -> void { ALabel::update(); } -auto Sndio::set_desc(struct sioctl_desc *d, unsigned int val) -> void { +auto Sndio::set_desc(struct sioctl_desc* d, unsigned int val) -> void { std::string name{d->func}; std::string node_name{d->node0.name}; @@ -140,7 +141,7 @@ auto Sndio::put_val(unsigned int addr, unsigned int val) -> void { } } -bool Sndio::handleScroll(GdkEventScroll *e) { +bool Sndio::handleScroll(GdkEventScroll* e) { // change the volume only when no user provided // events are configured if (config_["on-scroll-up"].isString() || config_["on-scroll-down"].isString()) { @@ -180,7 +181,7 @@ bool Sndio::handleScroll(GdkEventScroll *e) { return true; } -bool Sndio::handleToggle(GdkEventButton *const &e) { +bool Sndio::handleToggle(GdkEventButton* const& e) { // toggle mute only when no user provided events are configured if (config_["on-click"].isString()) { return AModule::handleToggle(e); diff --git a/src/modules/sni/tray.cpp b/src/modules/sni/tray.cpp index 34a3c05f6..c023aa1ec 100644 --- a/src/modules/sni/tray.cpp +++ b/src/modules/sni/tray.cpp @@ -8,8 +8,9 @@ namespace waybar::modules::SNI { -Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) - : AModule(config, "tray", id), +Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : AModule(config, "tray", id, reap_mtx, reap), box_(bar.orientation, 0), watcher_(SNI::Watcher::getInstance()), host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1), diff --git a/src/modules/sway/language.cpp b/src/modules/sway/language.cpp index f4cfa6c30..b9ae01fd1 100644 --- a/src/modules/sway/language.cpp +++ b/src/modules/sway/language.cpp @@ -17,8 +17,9 @@ namespace waybar::modules::sway { const std::string Language::XKB_LAYOUT_NAMES_KEY = "xkb_layout_names"; const std::string Language::XKB_ACTIVE_LAYOUT_NAME_KEY = "xkb_active_layout_name"; -Language::Language(const std::string& id, const Json::Value& config) - : ALabel(config, "language", id, "{}", 0, true) { +Language::Language(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "language", id, "{}", reap_mtx, reap, 0, true) { hide_single_ = config["hide-single-layout"].isBool() && config["hide-single-layout"].asBool(); is_variant_displayed = format_.find("{variant}") != std::string::npos; if (format_.find("{}") != std::string::npos || format_.find("{short}") != std::string::npos) { diff --git a/src/modules/sway/mode.cpp b/src/modules/sway/mode.cpp index b81735e54..131118eec 100644 --- a/src/modules/sway/mode.cpp +++ b/src/modules/sway/mode.cpp @@ -4,8 +4,9 @@ namespace waybar::modules::sway { -Mode::Mode(const std::string& id, const Json::Value& config) - : ALabel(config, "mode", id, "{}", 0, true) { +Mode::Mode(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : ALabel(config, "mode", id, "{}", reap_mtx, reap, 0, true) { ipc_.subscribe(R"(["mode"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Mode::onEvent)); // Launch worker diff --git a/src/modules/sway/scratchpad.cpp b/src/modules/sway/scratchpad.cpp index 17dc27071..2706fde7c 100644 --- a/src/modules/sway/scratchpad.cpp +++ b/src/modules/sway/scratchpad.cpp @@ -5,9 +5,11 @@ #include namespace waybar::modules::sway { -Scratchpad::Scratchpad(const std::string& id, const Json::Value& config) +Scratchpad::Scratchpad(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) : ALabel(config, "scratchpad", id, - config["format"].isString() ? config["format"].asString() : "{icon} {count}"), + config["format"].isString() ? config["format"].asString() : "{icon} {count}", reap_mtx, + reap), tooltip_format_(config_["tooltip-format"].isString() ? config_["tooltip-format"].asString() : "{app}: {title}"), show_empty_(config_["show-empty"].isBool() ? config_["show-empty"].asBool() : false), @@ -80,4 +82,4 @@ auto Scratchpad::onCmd(const struct Ipc::ipc_response& res) -> void { } auto Scratchpad::onEvent(const struct Ipc::ipc_response& res) -> void { getTree(); } -} // namespace waybar::modules::sway \ No newline at end of file +} // namespace waybar::modules::sway diff --git a/src/modules/sway/window.cpp b/src/modules/sway/window.cpp index 68655a764..c3884afcd 100644 --- a/src/modules/sway/window.cpp +++ b/src/modules/sway/window.cpp @@ -16,8 +16,9 @@ namespace waybar::modules::sway { -Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) - : AAppIconLabel(config, "window", id, "{}", 0, true), bar_(bar), windowId_(-1) { +Window::Window(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AAppIconLabel(config, "window", id, "{}", reap_mtx, reap, 0, true), bar_(bar), windowId_(-1) { ipc_.subscribe(R"(["window","workspace"])"); ipc_.signal_event.connect(sigc::mem_fun(*this, &Window::onEvent)); ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Window::onCmd)); diff --git a/src/modules/sway/workspaces.cpp b/src/modules/sway/workspaces.cpp index 86e7349eb..e5367d147 100644 --- a/src/modules/sway/workspaces.cpp +++ b/src/modules/sway/workspaces.cpp @@ -13,7 +13,7 @@ namespace waybar::modules::sway { int Workspaces::convertWorkspaceNameToNum(std::string name) { if (isdigit(name[0]) != 0) { errno = 0; - char *endptr = nullptr; + char* endptr = nullptr; long long parsed_num = strtoll(name.c_str(), &endptr, 10); if (errno != 0 || parsed_num > INT32_MAX || parsed_num < 0 || endptr == name.c_str()) { return -1; @@ -23,7 +23,7 @@ int Workspaces::convertWorkspaceNameToNum(std::string name) { return -1; } -int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) { +int Workspaces::windowRewritePriorityFunction(std::string const& window_rule) { // Rules that match against title are prioritized // Rules that don't specify if they're matching against either title or class are deprioritized bool const hasTitle = window_rule.find("title") != std::string::npos; @@ -41,12 +41,13 @@ int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) { return 0; } -Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) - : AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()), +Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AModule(config, "workspaces", id, reap_mtx, reap, false, !config["disable-scroll"].asBool()), bar_(bar), box_(bar.orientation, 0) { if (config["format-icons"]["high-priority-named"].isArray()) { - for (const auto &it : config["format-icons"]["high-priority-named"]) { + for (const auto& it : config["format-icons"]["high-priority-named"]) { high_priority_named_.push_back(it.asString()); } } @@ -61,9 +62,9 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value } else { m_formatWindowSeparator = " "; } - const Json::Value &windowRewrite = config["window-rewrite"]; + const Json::Value& windowRewrite = config["window-rewrite"]; if (windowRewrite.isObject()) { - const Json::Value &windowRewriteDefaultConfig = config["window-rewrite-default"]; + const Json::Value& windowRewriteDefaultConfig = config["window-rewrite-default"]; std::string windowRewriteDefault = windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?"; m_windowRewriteRules = waybar::util::RegexCollection( @@ -75,7 +76,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd)); ipc_.sendCmd(IPC_GET_TREE); if (config["enable-bar-scroll"].asBool()) { - auto &window = const_cast(bar_).window; + auto& window = const_cast(bar_).window; window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK); window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll)); } @@ -83,21 +84,21 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value ipc_.setWorker([this] { try { ipc_.handleEvent(); - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Workspaces: {}", e.what()); } }); } -void Workspaces::onEvent(const struct Ipc::ipc_response &res) { +void Workspaces::onEvent(const struct Ipc::ipc_response& res) { try { ipc_.sendCmd(IPC_GET_TREE); - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Workspaces: {}", e.what()); } } -void Workspaces::onCmd(const struct Ipc::ipc_response &res) { +void Workspaces::onCmd(const struct Ipc::ipc_response& res) { if (res.type == IPC_GET_TREE) { try { { @@ -107,7 +108,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { std::vector outputs; bool alloutputs = config_["all-outputs"].asBool(); std::copy_if(payload["nodes"].begin(), payload["nodes"].end(), std::back_inserter(outputs), - [&](const auto &output) { + [&](const auto& output) { if (alloutputs && output["name"].asString() != "__i3") { return true; } @@ -117,7 +118,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { return false; }); - for (auto &output : outputs) { + for (auto& output : outputs) { std::copy(output["nodes"].begin(), output["nodes"].end(), std::back_inserter(workspaces_)); std::copy(output["floating_nodes"].begin(), output["floating_nodes"].end(), @@ -126,13 +127,13 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { // adding persistent workspaces (as per the config file) if (config_["persistent-workspaces"].isObject()) { - const Json::Value &p_workspaces = config_["persistent-workspaces"]; + const Json::Value& p_workspaces = config_["persistent-workspaces"]; const std::vector p_workspaces_names = p_workspaces.getMemberNames(); - for (const std::string &p_w_name : p_workspaces_names) { - const Json::Value &p_w = p_workspaces[p_w_name]; + for (const std::string& p_w_name : p_workspaces_names) { + const Json::Value& p_w = p_workspaces[p_w_name]; auto it = std::find_if(workspaces_.begin(), workspaces_.end(), - [&p_w_name](const Json::Value &node) { + [&p_w_name](const Json::Value& node) { return node["name"].asString() == p_w_name; }); @@ -142,7 +143,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { if (p_w.isArray() && !p_w.empty()) { // Adding to target outputs - for (const Json::Value &output : p_w) { + for (const Json::Value& output : p_w) { if (output.asString() == bar_.output->name) { Json::Value v; v["name"] = p_w_name; @@ -185,10 +186,10 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { // agreement that the "workspace prev/next" commands may not follow // the order displayed in Waybar. int max_num = -1; - for (auto &workspace : workspaces_) { + for (auto& workspace : workspaces_) { max_num = std::max(workspace["num"].asInt(), max_num); } - for (auto &workspace : workspaces_) { + for (auto& workspace : workspaces_) { auto workspace_num = workspace["num"].asInt(); if (workspace_num > -1) { workspace["sort"] = workspace_num; @@ -197,7 +198,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { } } std::sort(workspaces_.begin(), workspaces_.end(), - [this](const Json::Value &lhs, const Json::Value &rhs) { + [this](const Json::Value& lhs, const Json::Value& rhs) { auto lname = lhs["name"].asString(); auto rname = rhs["name"].asString(); int l = lhs["sort"].asInt(); @@ -217,7 +218,7 @@ void Workspaces::onCmd(const struct Ipc::ipc_response &res) { }); } dp.emit(); - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Workspaces: {}", e.what()); } } @@ -227,7 +228,7 @@ bool Workspaces::filterButtons() { bool needReorder = false; for (auto it = buttons_.begin(); it != buttons_.end();) { auto ws = std::find_if(workspaces_.begin(), workspaces_.end(), - [it](const auto &node) { return node["name"].asString() == it->first; }); + [it](const auto& node) { return node["name"].asString() == it->first; }); if (ws == workspaces_.end() || (!config_["all-outputs"].asBool() && (*ws)["output"].asString() != bar_.output->name)) { it = buttons_.erase(it); @@ -239,23 +240,23 @@ bool Workspaces::filterButtons() { return needReorder; } -bool Workspaces::hasFlag(const Json::Value &node, const std::string &flag) { +bool Workspaces::hasFlag(const Json::Value& node, const std::string& flag) { if (node[flag].asBool()) { return true; } if (std::any_of(node["nodes"].begin(), node["nodes"].end(), - [&](auto const &e) { return hasFlag(e, flag); })) { + [&](auto const& e) { return hasFlag(e, flag); })) { return true; } if (std::any_of(node["floating_nodes"].begin(), node["floating_nodes"].end(), - [&](auto const &e) { return hasFlag(e, flag); })) { + [&](auto const& e) { return hasFlag(e, flag); })) { return true; } return false; } -void Workspaces::updateWindows(const Json::Value &node, std::string &windows) { +void Workspaces::updateWindows(const Json::Value& node, std::string& windows) { if ((node["type"].asString() == "con" || node["type"].asString() == "floating_con") && node["name"].isString()) { std::string title = g_markup_escape_text(node["name"].asString().c_str(), -1); @@ -274,10 +275,10 @@ void Workspaces::updateWindows(const Json::Value &node, std::string &windows) { windows.append(m_formatWindowSeparator); } } - for (const Json::Value &child : node["nodes"]) { + for (const Json::Value& child : node["nodes"]) { updateWindows(child, windows); } - for (const Json::Value &child : node["floating_nodes"]) { + for (const Json::Value& child : node["floating_nodes"]) { updateWindows(child, windows); } } @@ -290,7 +291,7 @@ auto Workspaces::update() -> void { if (bit == buttons_.end()) { needReorder = true; } - auto &button = bit == buttons_.end() ? addButton(*it) : bit->second; + auto& button = bit == buttons_.end() ? addButton(*it) : bit->second; if (needReorder) { box_.reorder_child(button, it - workspaces_.begin()); } @@ -344,7 +345,7 @@ auto Workspaces::update() -> void { fmt::arg("output", (*it)["output"].asString())); } if (!config_["disable-markup"].asBool()) { - static_cast(button.get_children()[0])->set_markup(output); + static_cast(button.get_children()[0])->set_markup(output); } else { button.set_label(output); } @@ -354,9 +355,9 @@ auto Workspaces::update() -> void { AModule::update(); } -Gtk::Button &Workspaces::addButton(const Json::Value &node) { +Gtk::Button& Workspaces::addButton(const Json::Value& node) { auto pair = buttons_.emplace(node["name"].asString(), node["name"].asString()); - auto &&button = pair.first->second; + auto&& button = pair.first->second; box_.pack_start(button, false, false, 0); button.set_name("sway-workspace-" + node["name"].asString()); button.set_relief(Gtk::RELIEF_NONE); @@ -375,7 +376,7 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) { : "", node["name"].asString())); } - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Workspaces: {}", e.what()); } }); @@ -383,18 +384,18 @@ Gtk::Button &Workspaces::addButton(const Json::Value &node) { return button; } -std::string Workspaces::getIcon(const std::string &name, const Json::Value &node) { +std::string Workspaces::getIcon(const std::string& name, const Json::Value& node) { std::vector keys = {"high-priority-named", "urgent", "focused", name, "default"}; - for (auto const &key : keys) { + for (auto const& key : keys) { if (key == "high-priority-named") { auto it = std::find_if(high_priority_named_.begin(), high_priority_named_.end(), - [&](const std::string &member) { return member == name; }); + [&](const std::string& member) { return member == name; }); if (it != high_priority_named_.end()) { return config_["format-icons"][name].asString(); } it = std::find_if(high_priority_named_.begin(), high_priority_named_.end(), - [&](const std::string &member) { + [&](const std::string& member) { return trimWorkspaceName(member) == trimWorkspaceName(name); }); if (it != high_priority_named_.end()) { @@ -417,8 +418,8 @@ std::string Workspaces::getIcon(const std::string &name, const Json::Value &node return name; } -bool Workspaces::handleScroll(GdkEventScroll *e) { - if (gdk_event_get_pointer_emulated((GdkEvent *)e) != 0) { +bool Workspaces::handleScroll(GdkEventScroll* e) { + if (gdk_event_get_pointer_emulated((GdkEvent*)e) != 0) { /** * Ignore emulated scroll events on window */ @@ -433,7 +434,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) { bool alloutputs = config_["all-outputs"].asBool(); std::lock_guard lock(mutex_); auto it = - std::find_if(workspaces_.begin(), workspaces_.end(), [alloutputs](const auto &workspace) { + std::find_if(workspaces_.begin(), workspaces_.end(), [alloutputs](const auto& workspace) { if (alloutputs) { return hasFlag(workspace, "focused"); } @@ -460,7 +461,7 @@ bool Workspaces::handleScroll(GdkEventScroll *e) { } try { ipc_.sendCmd(IPC_COMMAND, fmt::format(workspace_switch_cmd_, "--no-auto-back-and-forth", name)); - } catch (const std::exception &e) { + } catch (const std::exception& e) { spdlog::error("Workspaces: {}", e.what()); } if (!config_["warp-on-scroll"].isNull() && !config_["warp-on-scroll"].asBool()) { @@ -495,7 +496,7 @@ std::string Workspaces::trimWorkspaceName(std::string name) { return name; } -bool is_focused_recursive(const Json::Value &node) { +bool is_focused_recursive(const Json::Value& node) { // If a workspace has a focused container then get_tree will say // that the workspace itself isn't focused. Therefore we need to // check if any of its nodes are focused as well. @@ -505,13 +506,13 @@ bool is_focused_recursive(const Json::Value &node) { return true; } - for (const auto &child : node["nodes"]) { + for (const auto& child : node["nodes"]) { if (is_focused_recursive(child)) { return true; } } - for (const auto &child : node["floating_nodes"]) { + for (const auto& child : node["floating_nodes"]) { if (is_focused_recursive(child)) { return true; } @@ -520,7 +521,7 @@ bool is_focused_recursive(const Json::Value &node) { return false; } -void Workspaces::onButtonReady(const Json::Value &node, Gtk::Button &button) { +void Workspaces::onButtonReady(const Json::Value& node, Gtk::Button& button) { if (config_["current-only"].asBool()) { if (is_focused_recursive(node)) { button.show(); diff --git a/src/modules/systemd_failed_units.cpp b/src/modules/systemd_failed_units.cpp index 90f33be78..27cf7a416 100644 --- a/src/modules/systemd_failed_units.cpp +++ b/src/modules/systemd_failed_units.cpp @@ -10,8 +10,9 @@ static const unsigned UPDATE_DEBOUNCE_TIME_MS = 1000; namespace waybar::modules { -SystemdFailedUnits::SystemdFailedUnits(const std::string& id, const Json::Value& config) - : ALabel(config, "systemd-failed-units", id, "{nr_failed} failed", 1), +SystemdFailedUnits::SystemdFailedUnits(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "systemd-failed-units", id, "{nr_failed} failed", reap_mtx, reap, 1), hide_on_ok(true), update_pending(false), nr_failed_system(0), diff --git a/src/modules/temperature.cpp b/src/modules/temperature.cpp index fa23ef56f..a7769ebc5 100644 --- a/src/modules/temperature.cpp +++ b/src/modules/temperature.cpp @@ -7,8 +7,9 @@ #include #endif -waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config) - : ALabel(config, "temperature", id, "{temperatureC}°C", 10) { +waybar::modules::Temperature::Temperature(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "temperature", id, "{temperatureC}°C", reap_mtx, reap, 10) { #if defined(__FreeBSD__) // FreeBSD uses sysctlbyname instead of read from a file #else diff --git a/src/modules/upower.cpp b/src/modules/upower.cpp index 4844582f6..4ec4e4c5c 100644 --- a/src/modules/upower.cpp +++ b/src/modules/upower.cpp @@ -6,8 +6,10 @@ namespace waybar::modules { -UPower::UPower(const std::string &id, const Json::Value &config) - : AIconLabel(config, "upower", id, "{percentage}", 0, true, true, true), sleeping_{false} { +UPower::UPower(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : AIconLabel(config, "upower", id, "{percentage}", reap_mtx, reap, 0, true, true, true), + sleeping_{false} { box_.set_name(name_); box_.set_spacing(0); // Tooltip box @@ -59,7 +61,7 @@ UPower::UPower(const std::string &id, const Json::Value &config) sigc::mem_fun(*this, &UPower::getConn_cb)); // Make UPower client - GError **gErr = NULL; + GError** gErr = NULL; upClient_ = up_client_new_full(NULL, gErr); if (upClient_ == NULL) spdlog::error("Upower. UPower client connection error. {}", (*gErr)->message); @@ -92,7 +94,7 @@ UPower::~UPower() { removeDevices(); } -static const std::string getDeviceStatus(UpDeviceState &state) { +static const std::string getDeviceStatus(UpDeviceState& state) { switch (state) { case UP_DEVICE_STATE_CHARGING: case UP_DEVICE_STATE_PENDING_CHARGE: @@ -109,7 +111,7 @@ static const std::string getDeviceStatus(UpDeviceState &state) { } } -static const std::string getDeviceIcon(UpDeviceKind &kind) { +static const std::string getDeviceIcon(UpDeviceKind& kind) { switch (kind) { case UP_DEVICE_KIND_LINE_POWER: return "ac-adapter-symbolic"; @@ -222,7 +224,7 @@ auto UPower::update() -> void { label_.set_markup(getText(upDevice_, format_)); // Set icon if (upDevice_.icon_name == NULL || !gtkTheme_->has_icon(upDevice_.icon_name)) - upDevice_.icon_name = (char *)NO_BATTERY.c_str(); + upDevice_.icon_name = (char*)NO_BATTERY.c_str(); image_.set_from_icon_name(upDevice_.icon_name, Gtk::ICON_SIZE_INVALID); box_.show(); @@ -231,7 +233,7 @@ auto UPower::update() -> void { ALabel::update(); } -void UPower::getConn_cb(Glib::RefPtr &result) { +void UPower::getConn_cb(Glib::RefPtr& result) { try { conn_ = Gio::DBus::Connection::get_finish(result); // Subscribe DBUs events @@ -239,26 +241,26 @@ void UPower::getConn_cb(Glib::RefPtr &result) { "org.freedesktop.login1", "org.freedesktop.login1.Manager", "PrepareForSleep", "/org/freedesktop/login1"); - } catch (const Glib::Error &e) { + } catch (const Glib::Error& e) { spdlog::error("Upower. DBus connection error. {}", e.what().c_str()); } } -void UPower::onAppear(const Glib::RefPtr &conn, const Glib::ustring &name, - const Glib::ustring &name_owner) { +void UPower::onAppear(const Glib::RefPtr& conn, const Glib::ustring& name, + const Glib::ustring& name_owner) { upRunning_ = true; } -void UPower::onVanished(const Glib::RefPtr &conn, - const Glib::ustring &name) { +void UPower::onVanished(const Glib::RefPtr& conn, + const Glib::ustring& name) { upRunning_ = false; } -void UPower::prepareForSleep_cb(const Glib::RefPtr &connection, - const Glib::ustring &sender_name, const Glib::ustring &object_path, - const Glib::ustring &interface_name, - const Glib::ustring &signal_name, - const Glib::VariantContainerBase ¶meters) { +void UPower::prepareForSleep_cb(const Glib::RefPtr& connection, + const Glib::ustring& sender_name, const Glib::ustring& object_path, + const Glib::ustring& interface_name, + const Glib::ustring& signal_name, + const Glib::VariantContainerBase& parameters) { if (parameters.is_of_type(Glib::VariantType("(b)"))) { Glib::Variant sleeping; parameters.get_child(sleeping, 0); @@ -273,33 +275,33 @@ void UPower::prepareForSleep_cb(const Glib::RefPtr &conne } } -void UPower::deviceAdded_cb(UpClient *client, UpDevice *device, gpointer data) { - UPower *up{static_cast(data)}; +void UPower::deviceAdded_cb(UpClient* client, UpDevice* device, gpointer data) { + UPower* up{static_cast(data)}; up->addDevice(device); up->setDisplayDevice(); // Update the widget up->dp.emit(); } -void UPower::deviceRemoved_cb(UpClient *client, const gchar *objectPath, gpointer data) { - UPower *up{static_cast(data)}; +void UPower::deviceRemoved_cb(UpClient* client, const gchar* objectPath, gpointer data) { + UPower* up{static_cast(data)}; up->removeDevice(objectPath); up->setDisplayDevice(); // Update the widget up->dp.emit(); } -void UPower::deviceNotify_cb(UpDevice *device, GParamSpec *pspec, gpointer data) { - UPower *up{static_cast(data)}; +void UPower::deviceNotify_cb(UpDevice* device, GParamSpec* pspec, gpointer data) { + UPower* up{static_cast(data)}; // Update the widget up->dp.emit(); } -void UPower::addDevice(UpDevice *device) { +void UPower::addDevice(UpDevice* device) { std::lock_guard guard{mutex_}; if (G_IS_OBJECT(device)) { - const gchar *objectPath{up_device_get_object_path(device)}; + const gchar* objectPath{up_device_get_object_path(device)}; // Due to the device getting cleared after this event is fired, we // create a new object pointing to its objectPath @@ -322,7 +324,7 @@ void UPower::addDevice(UpDevice *device) { } } -void UPower::removeDevice(const gchar *objectPath) { +void UPower::removeDevice(const gchar* objectPath) { std::lock_guard guard{mutex_}; if (devices_.find(objectPath) != devices_.cend()) { auto upDevice{devices_[objectPath]}; @@ -348,10 +350,10 @@ void UPower::resetDevices() { removeDevices(); // Adds all devices - GPtrArray *newDevices = up_client_get_devices2(upClient_); + GPtrArray* newDevices = up_client_get_devices2(upClient_); if (newDevices != NULL) for (guint i{0}; i < newDevices->len; ++i) { - UpDevice *device{(UpDevice *)g_ptr_array_index(newDevices, i)}; + UpDevice* device{(UpDevice*)g_ptr_array_index(newDevices, i)}; if (device && G_IS_OBJECT(device)) addDevice(device); } } @@ -372,8 +374,8 @@ void UPower::setDisplayDevice() { up_client_get_devices2(upClient_), [](gpointer data, gpointer user_data) { upDevice_output upDevice; - auto thisPtr{static_cast(user_data)}; - upDevice.upDevice = static_cast(data); + auto thisPtr{static_cast(user_data)}; + upDevice.upDevice = static_cast(data); thisPtr->getUpDeviceInfo(upDevice); upDevice_output displayDevice{NULL}; if (!thisPtr->nativePath_.empty()) { @@ -399,7 +401,7 @@ void UPower::setDisplayDevice() { g_signal_connect(upDevice_.upDevice, "notify", G_CALLBACK(deviceNotify_cb), this); } -void UPower::getUpDeviceInfo(upDevice_output &upDevice_) { +void UPower::getUpDeviceInfo(upDevice_output& upDevice_) { if (upDevice_.upDevice != NULL && G_IS_OBJECT(upDevice_.upDevice)) { g_object_get(upDevice_.upDevice, "kind", &upDevice_.kind, "state", &upDevice_.state, "percentage", &upDevice_.percentage, "icon-name", &upDevice_.icon_name, @@ -416,7 +418,7 @@ native_path: \"{7}\". model: \"{8}\"", } } -const Glib::ustring UPower::getText(const upDevice_output &upDevice_, const std::string &format) { +const Glib::ustring UPower::getText(const upDevice_output& upDevice_, const std::string& format) { Glib::ustring ret{""}; if (upDevice_.upDevice != NULL) { std::string timeStr{""}; @@ -445,11 +447,11 @@ const Glib::ustring UPower::getText(const upDevice_output &upDevice_, const std: } bool UPower::queryTooltipCb(int x, int y, bool keyboard_tooltip, - const Glib::RefPtr &tooltip) { + const Glib::RefPtr& tooltip) { std::lock_guard guard{mutex_}; // Clear content box - contentBox_.forall([this](Gtk::Widget &wg) { contentBox_.remove(wg); }); + contentBox_.forall([this](Gtk::Widget& wg) { contentBox_.remove(wg); }); // Fill content box with the content for (auto pairDev : devices_) { @@ -459,33 +461,33 @@ bool UPower::queryTooltipCb(int x, int y, bool keyboard_tooltip, if (pairDev.second.kind != UpDeviceKind::UP_DEVICE_KIND_UNKNOWN && pairDev.second.kind != UpDeviceKind::UP_DEVICE_KIND_LINE_POWER) { // Make box record - Gtk::Box *boxRec{new Gtk::Box{box_.get_orientation(), tooltip_spacing_}}; + Gtk::Box* boxRec{new Gtk::Box{box_.get_orientation(), tooltip_spacing_}}; contentBox_.add(*boxRec); - Gtk::Box *boxDev{new Gtk::Box{box_.get_orientation()}}; - Gtk::Box *boxUsr{new Gtk::Box{box_.get_orientation()}}; + Gtk::Box* boxDev{new Gtk::Box{box_.get_orientation()}}; + Gtk::Box* boxUsr{new Gtk::Box{box_.get_orientation()}}; boxRec->add(*boxDev); boxRec->add(*boxUsr); // Construct device box // Set icon from kind std::string iconNameDev{getDeviceIcon(pairDev.second.kind)}; - if (!gtkTheme_->has_icon(iconNameDev)) iconNameDev = (char *)NO_BATTERY.c_str(); - Gtk::Image *iconDev{new Gtk::Image{}}; + if (!gtkTheme_->has_icon(iconNameDev)) iconNameDev = (char*)NO_BATTERY.c_str(); + Gtk::Image* iconDev{new Gtk::Image{}}; iconDev->set_from_icon_name(iconNameDev, Gtk::ICON_SIZE_INVALID); iconDev->set_pixel_size(iconSize_); boxDev->add(*iconDev); // Set label from model - Gtk::Label *labelDev{new Gtk::Label{pairDev.second.model}}; + Gtk::Label* labelDev{new Gtk::Label{pairDev.second.model}}; boxDev->add(*labelDev); // Construct user box // Set icon from icon state if (pairDev.second.icon_name == NULL || !gtkTheme_->has_icon(pairDev.second.icon_name)) - pairDev.second.icon_name = (char *)NO_BATTERY.c_str(); - Gtk::Image *iconTooltip{new Gtk::Image{}}; + pairDev.second.icon_name = (char*)NO_BATTERY.c_str(); + Gtk::Image* iconTooltip{new Gtk::Image{}}; iconTooltip->set_from_icon_name(pairDev.second.icon_name, Gtk::ICON_SIZE_INVALID); iconTooltip->set_pixel_size(iconSize_); boxUsr->add(*iconTooltip); // Set markup text - Gtk::Label *labelTooltip{new Gtk::Label{}}; + Gtk::Label* labelTooltip{new Gtk::Label{}}; labelTooltip->set_markup(getText(pairDev.second, tooltipFormat_)); boxUsr->add(*labelTooltip); } diff --git a/src/modules/user.cpp b/src/modules/user.cpp index 3ca5e431c..1586f7b2b 100644 --- a/src/modules/user.cpp +++ b/src/modules/user.cpp @@ -25,8 +25,10 @@ const static int LEFT_MOUSE_BUTTON_CODE = 1; namespace waybar::modules { -User::User(const std::string& id, const Json::Value& config) - : AIconLabel(config, "user", id, "{user} {work_H}:{work_M}", 60, false, true, true) { +User::User(const std::string& id, const Json::Value& config, std::mutex& reap_mtx, + std::list& reap) + : AIconLabel(config, "user", id, "{user} {work_H}:{work_M}", reap_mtx, reap, 60, false, true, + true) { AIconLabel::box_.set_spacing(0); if (AIconLabel::iconEnabled()) { this->init_avatar(AIconLabel::config_); diff --git a/src/modules/wayfire/window.cpp b/src/modules/wayfire/window.cpp index fbcde6ec7..e4612bac3 100644 --- a/src/modules/wayfire/window.cpp +++ b/src/modules/wayfire/window.cpp @@ -9,8 +9,9 @@ namespace waybar::modules::wayfire { -Window::Window(const std::string& id, const Bar& bar, const Json::Value& config) - : AAppIconLabel(config, "window", id, "{title}", 0, true), +Window::Window(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AAppIconLabel(config, "window", id, "{title}", reap_mtx, reap, 0, true), ipc{IPC::get_instance()}, handler{[this](const auto&) { dp.emit(); }}, bar_{bar} { diff --git a/src/modules/wayfire/workspaces.cpp b/src/modules/wayfire/workspaces.cpp index 4c4cd6c1e..d86293972 100644 --- a/src/modules/wayfire/workspaces.cpp +++ b/src/modules/wayfire/workspaces.cpp @@ -11,8 +11,9 @@ namespace waybar::modules::wayfire { -Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config) - : AModule{config, "workspaces", id, false, !config["disable-scroll"].asBool()}, +Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : AModule{config, "workspaces", id, reap_mtx, reap, false, !config["disable-scroll"].asBool()}, ipc{IPC::get_instance()}, handler{[this](const auto&) { dp.emit(); }}, bar_{bar} { diff --git a/src/modules/wireplumber.cpp b/src/modules/wireplumber.cpp index bb3005bdd..b7b219113 100644 --- a/src/modules/wireplumber.cpp +++ b/src/modules/wireplumber.cpp @@ -6,8 +6,9 @@ bool isValidNodeId(uint32_t id) { return id > 0 && id < G_MAXUINT32; } std::list waybar::modules::Wireplumber::modules; -waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Value& config) - : ALabel(config, "wireplumber", id, "{volume}%"), +waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : ALabel(config, "wireplumber", id, "{volume}%", reap_mtx, reap), wp_core_(nullptr), apis_(nullptr), om_(nullptr), diff --git a/src/modules/wlr/taskbar.cpp b/src/modules/wlr/taskbar.cpp index c5c522d85..f986a43f0 100644 --- a/src/modules/wlr/taskbar.cpp +++ b/src/modules/wlr/taskbar.cpp @@ -29,42 +29,42 @@ namespace waybar::modules::wlr { /* Task class implementation */ uint32_t Task::global_id = 0; -static void tl_handle_title(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle, - const char *title) { - return static_cast(data)->handle_title(title); +static void tl_handle_title(void* data, struct zwlr_foreign_toplevel_handle_v1* handle, + const char* title) { + return static_cast(data)->handle_title(title); } -static void tl_handle_app_id(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle, - const char *app_id) { - return static_cast(data)->handle_app_id(app_id); +static void tl_handle_app_id(void* data, struct zwlr_foreign_toplevel_handle_v1* handle, + const char* app_id) { + return static_cast(data)->handle_app_id(app_id); } -static void tl_handle_output_enter(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle, - struct wl_output *output) { - return static_cast(data)->handle_output_enter(output); +static void tl_handle_output_enter(void* data, struct zwlr_foreign_toplevel_handle_v1* handle, + struct wl_output* output) { + return static_cast(data)->handle_output_enter(output); } -static void tl_handle_output_leave(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle, - struct wl_output *output) { - return static_cast(data)->handle_output_leave(output); +static void tl_handle_output_leave(void* data, struct zwlr_foreign_toplevel_handle_v1* handle, + struct wl_output* output) { + return static_cast(data)->handle_output_leave(output); } -static void tl_handle_state(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle, - struct wl_array *state) { - return static_cast(data)->handle_state(state); +static void tl_handle_state(void* data, struct zwlr_foreign_toplevel_handle_v1* handle, + struct wl_array* state) { + return static_cast(data)->handle_state(state); } -static void tl_handle_done(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle) { - return static_cast(data)->handle_done(); +static void tl_handle_done(void* data, struct zwlr_foreign_toplevel_handle_v1* handle) { + return static_cast(data)->handle_done(); } -static void tl_handle_parent(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle, - struct zwlr_foreign_toplevel_handle_v1 *parent) { +static void tl_handle_parent(void* data, struct zwlr_foreign_toplevel_handle_v1* handle, + struct zwlr_foreign_toplevel_handle_v1* parent) { /* This is explicitly left blank */ } -static void tl_handle_closed(void *data, struct zwlr_foreign_toplevel_handle_v1 *handle) { - return static_cast(data)->handle_closed(); +static void tl_handle_closed(void* data, struct zwlr_foreign_toplevel_handle_v1* handle) { + return static_cast(data)->handle_closed(); } static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_impl = { @@ -81,8 +81,8 @@ static const struct zwlr_foreign_toplevel_handle_v1_listener toplevel_handle_imp static const std::vector target_entries = { Gtk::TargetEntry("WAYBAR_TOPLEVEL", Gtk::TARGET_SAME_APP, 0)}; -Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar, - struct zwlr_foreign_toplevel_handle_v1 *tl_handle, struct wl_seat *seat) +Task::Task(const waybar::Bar& bar, const Json::Value& config, Taskbar* tbar, + struct zwlr_foreign_toplevel_handle_v1* tl_handle, struct wl_seat* seat) : bar_{bar}, config_{config}, tbar_{tbar}, @@ -189,7 +189,7 @@ std::string Task::state_string(bool shortened) const { return res.substr(0, res.size() - 1); } -void Task::handle_title(const char *title) { +void Task::handle_title(const char* title) { if (title_.empty()) { spdlog::debug(fmt::format("Task ({}) setting title to {}", id_, title_)); } else { @@ -238,7 +238,7 @@ void Task::hide_if_ignored() { } } -void Task::handle_app_id(const char *app_id) { +void Task::handle_app_id(const char* app_id) { if (app_id_.empty()) { spdlog::debug(fmt::format("Task ({}) setting app_id to {}", id_, app_id)); } else { @@ -273,20 +273,20 @@ void Task::handle_app_id(const char *app_id) { spdlog::debug("Couldn't find icon for {}", app_id_); } -void Task::on_button_size_allocated(Gtk::Allocation &alloc) { +void Task::on_button_size_allocated(Gtk::Allocation& alloc) { gtk_widget_translate_coordinates(GTK_WIDGET(button.gobj()), GTK_WIDGET(bar_.window.gobj()), 0, 0, &minimize_hint.x, &minimize_hint.y); minimize_hint.w = button.get_width(); minimize_hint.h = button.get_height(); } -void Task::handle_output_enter(struct wl_output *output) { +void Task::handle_output_enter(struct wl_output* output) { if (ignored_) { spdlog::debug("{} is ignored", repr()); return; } - spdlog::debug("{} entered output {}", repr(), (void *)output); + spdlog::debug("{} entered output {}", repr(), (void*)output); if (!button_visible_ && (tbar_->all_outputs() || tbar_->show_output(output))) { /* The task entered the output of the current bar make the button visible */ @@ -299,8 +299,8 @@ void Task::handle_output_enter(struct wl_output *output) { } } -void Task::handle_output_leave(struct wl_output *output) { - spdlog::debug("{} left output {}", repr(), (void *)output); +void Task::handle_output_leave(struct wl_output* output) { + spdlog::debug("{} left output {}", repr(), (void*)output); if (button_visible_ && !tbar_->all_outputs() && tbar_->show_output(output)) { /* The task left the output of the current bar, make the button invisible */ @@ -311,11 +311,11 @@ void Task::handle_output_leave(struct wl_output *output) { } } -void Task::handle_state(struct wl_array *state) { +void Task::handle_state(struct wl_array* state) { state_ = 0; size_t size = state->size / sizeof(uint32_t); for (size_t i = 0; i < size; ++i) { - auto entry = static_cast(state->data)[i]; + auto entry = static_cast(state->data)[i]; if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED) state_ |= MAXIMIZED; if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MINIMIZED) state_ |= MINIMIZED; if (entry == ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_ACTIVATED) state_ |= ACTIVE; @@ -367,7 +367,7 @@ void Task::handle_closed() { tbar_->remove_task(id_); } -bool Task::handle_clicked(GdkEventButton *bt) { +bool Task::handle_clicked(GdkEventButton* bt) { /* filter out additional events for double/triple clicks */ if (bt->type == GDK_BUTTON_PRESS) { /* save where the button press occurred in case it becomes a drag */ @@ -412,7 +412,7 @@ bool Task::handle_clicked(GdkEventButton *bt) { return true; } -bool Task::handle_motion_notify(GdkEventMotion *mn) { +bool Task::handle_motion_notify(GdkEventMotion* mn) { if (drag_start_button == -1) return false; if (button.drag_check_threshold(drag_start_x, drag_start_y, mn->x, mn->y)) { @@ -420,25 +420,25 @@ bool Task::handle_motion_notify(GdkEventMotion *mn) { auto target_list = Gtk::TargetList::create(target_entries); auto refptr = Glib::RefPtr(target_list); auto drag_context = - button.drag_begin(refptr, Gdk::DragAction::ACTION_MOVE, drag_start_button, (GdkEvent *)mn); + button.drag_begin(refptr, Gdk::DragAction::ACTION_MOVE, drag_start_button, (GdkEvent*)mn); } return false; } -void Task::handle_drag_data_get(const Glib::RefPtr &context, - Gtk::SelectionData &selection_data, guint info, guint time) { +void Task::handle_drag_data_get(const Glib::RefPtr& context, + Gtk::SelectionData& selection_data, guint info, guint time) { spdlog::debug("drag_data_get"); - void *button_addr = (void *)&this->button; + void* button_addr = (void*)&this->button; - selection_data.set("WAYBAR_TOPLEVEL", 32, (const guchar *)&button_addr, sizeof(gpointer)); + selection_data.set("WAYBAR_TOPLEVEL", 32, (const guchar*)&button_addr, sizeof(gpointer)); } -void Task::handle_drag_data_received(const Glib::RefPtr &context, int x, int y, +void Task::handle_drag_data_received(const Glib::RefPtr& context, int x, int y, Gtk::SelectionData selection_data, guint info, guint time) { spdlog::debug("drag_data_received"); - gpointer handle = *(gpointer *)selection_data.get_data(); - auto dragged_button = (Gtk::Button *)handle; + gpointer handle = *(gpointer*)selection_data.get_data(); + auto dragged_button = (Gtk::Button*)handle; if (dragged_button == &this->button) return; @@ -447,7 +447,7 @@ void Task::handle_drag_data_received(const Glib::RefPtr &conte if (parent_of_dragged != parent_of_dest) return; - auto box = (Gtk::Box *)parent_of_dragged; + auto box = (Gtk::Box*)parent_of_dragged; auto position_prop = box->child_property_position(this->button); auto position = position_prop.get_value(); @@ -455,9 +455,9 @@ void Task::handle_drag_data_received(const Glib::RefPtr &conte box->reorder_child(*dragged_button, position); } -bool Task::operator==(const Task &o) const { return o.id_ == id_; } +bool Task::operator==(const Task& o) const { return o.id_ == id_; } -bool Task::operator!=(const Task &o) const { return o.id_ != id_; } +bool Task::operator!=(const Task& o) const { return o.id_ != id_; } void Task::update() { bool markup = config_["markup"].isBool() ? config_["markup"].asBool() : false; @@ -545,24 +545,25 @@ void Task::fullscreen(bool set) { void Task::close() { zwlr_foreign_toplevel_handle_v1_close(handle_); } /* Taskbar class implementation */ -static void handle_global(void *data, struct wl_registry *registry, uint32_t name, - const char *interface, uint32_t version) { +static void handle_global(void* data, struct wl_registry* registry, uint32_t name, + const char* interface, uint32_t version) { if (std::strcmp(interface, zwlr_foreign_toplevel_manager_v1_interface.name) == 0) { - static_cast(data)->register_manager(registry, name, version); + static_cast(data)->register_manager(registry, name, version); } else if (std::strcmp(interface, wl_seat_interface.name) == 0) { - static_cast(data)->register_seat(registry, name, version); + static_cast(data)->register_seat(registry, name, version); } } -static void handle_global_remove(void *data, struct wl_registry *registry, uint32_t name) { +static void handle_global_remove(void* data, struct wl_registry* registry, uint32_t name) { /* Nothing to do here */ } static const wl_registry_listener registry_listener_impl = {.global = handle_global, .global_remove = handle_global_remove}; -Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Value &config) - : waybar::AModule(config, "taskbar", id, false, false), +Taskbar::Taskbar(const std::string& id, const waybar::Bar& bar, const Json::Value& config, + std::mutex& reap_mtx, std::list& reap) + : waybar::AModule(config, "taskbar", id, reap_mtx, reap, false, false), bar_(bar), box_{bar.orientation, 0}, manager_{nullptr}, @@ -575,8 +576,8 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu box_.get_style_context()->add_class("empty"); event_box_.add(box_); - struct wl_display *display = Client::inst()->wl_display; - struct wl_registry *registry = wl_display_get_registry(display); + struct wl_display* display = Client::inst()->wl_display; + struct wl_registry* registry = wl_display_get_registry(display); wl_registry_add_listener(registry, ®istry_listener_impl, this); wl_display_roundtrip(display); @@ -592,7 +593,7 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu /* Get the configured icon theme if specified */ if (config_["icon-theme"].isArray()) { - for (auto &c : config_["icon-theme"]) { + for (auto& c : config_["icon-theme"]) { icon_loader_.add_custom_icon_theme(c.asString()); } } else if (config_["icon-theme"].isString()) { @@ -601,28 +602,28 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu // Load ignore-list if (config_["ignore-list"].isArray()) { - for (auto &app_name : config_["ignore-list"]) { + for (auto& app_name : config_["ignore-list"]) { ignore_list_.emplace(app_name.asString()); } } // Load app_id remappings if (config_["app_ids-mapping"].isObject()) { - const Json::Value &mapping = config_["app_ids-mapping"]; + const Json::Value& mapping = config_["app_ids-mapping"]; const std::vector app_ids = config_["app_ids-mapping"].getMemberNames(); - for (auto &app_id : app_ids) { + for (auto& app_id : app_ids) { app_ids_replace_map_.emplace(app_id, mapping[app_id].asString()); } } - for (auto &t : tasks_) { + for (auto& t : tasks_) { t->handle_app_id(t->app_id().c_str()); } } Taskbar::~Taskbar() { if (manager_) { - struct wl_display *display = Client::inst()->wl_display; + struct wl_display* display = Client::inst()->wl_display; /* * Send `stop` request and wait for one roundtrip. * This is not quite correct as the protocol encourages us to wait for the .finished event, @@ -640,13 +641,13 @@ Taskbar::~Taskbar() { } void Taskbar::update() { - for (auto &t : tasks_) { + for (auto& t : tasks_) { t->update(); } if (config_["sort-by-app-id"].asBool()) { std::stable_sort(tasks_.begin(), tasks_.end(), - [](const std::unique_ptr &a, const std::unique_ptr &b) { + [](const std::unique_ptr& a, const std::unique_ptr& b) { return a->app_id() < b->app_id(); }); @@ -658,13 +659,13 @@ void Taskbar::update() { AModule::update(); } -static void tm_handle_toplevel(void *data, struct zwlr_foreign_toplevel_manager_v1 *manager, - struct zwlr_foreign_toplevel_handle_v1 *tl_handle) { - return static_cast(data)->handle_toplevel_create(tl_handle); +static void tm_handle_toplevel(void* data, struct zwlr_foreign_toplevel_manager_v1* manager, + struct zwlr_foreign_toplevel_handle_v1* tl_handle) { + return static_cast(data)->handle_toplevel_create(tl_handle); } -static void tm_handle_finished(void *data, struct zwlr_foreign_toplevel_manager_v1 *manager) { - return static_cast(data)->handle_finished(); +static void tm_handle_finished(void* data, struct zwlr_foreign_toplevel_manager_v1* manager) { + return static_cast(data)->handle_finished(); } static const struct zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_impl = { @@ -672,7 +673,7 @@ static const struct zwlr_foreign_toplevel_manager_v1_listener toplevel_manager_i .finished = tm_handle_finished, }; -void Taskbar::register_manager(struct wl_registry *registry, uint32_t name, uint32_t version) { +void Taskbar::register_manager(struct wl_registry* registry, uint32_t name, uint32_t version) { if (manager_) { spdlog::warn("Register foreign toplevel manager again although already existing!"); return; @@ -687,7 +688,7 @@ void Taskbar::register_manager(struct wl_registry *registry, uint32_t name, uint // limit version to a highest supported by the client protocol file version = std::min(version, zwlr_foreign_toplevel_manager_v1_interface.version); - manager_ = static_cast( + manager_ = static_cast( wl_registry_bind(registry, name, &zwlr_foreign_toplevel_manager_v1_interface, version)); if (manager_) @@ -696,17 +697,17 @@ void Taskbar::register_manager(struct wl_registry *registry, uint32_t name, uint spdlog::debug("Failed to register manager"); } -void Taskbar::register_seat(struct wl_registry *registry, uint32_t name, uint32_t version) { +void Taskbar::register_seat(struct wl_registry* registry, uint32_t name, uint32_t version) { if (seat_) { spdlog::warn("Register seat again although already existing!"); return; } version = std::min(version, wl_seat_interface.version); - seat_ = static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); + seat_ = static_cast(wl_registry_bind(registry, name, &wl_seat_interface, version)); } -void Taskbar::handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1 *tl_handle) { +void Taskbar::handle_toplevel_create(struct zwlr_foreign_toplevel_handle_v1* tl_handle) { tasks_.push_back(std::make_unique(bar_, config_, this, tl_handle, seat_)); } @@ -715,14 +716,14 @@ void Taskbar::handle_finished() { manager_ = nullptr; } -void Taskbar::add_button(Gtk::Button &bt) { +void Taskbar::add_button(Gtk::Button& bt) { box_.pack_start(bt, false, false); box_.get_style_context()->remove_class("empty"); } -void Taskbar::move_button(Gtk::Button &bt, int pos) { box_.reorder_child(bt, pos); } +void Taskbar::move_button(Gtk::Button& bt, int pos) { box_.reorder_child(bt, pos); } -void Taskbar::remove_button(Gtk::Button &bt) { +void Taskbar::remove_button(Gtk::Button& bt) { box_.remove(bt); if (box_.get_children().empty()) { box_.get_style_context()->add_class("empty"); @@ -731,7 +732,7 @@ void Taskbar::remove_button(Gtk::Button &bt) { void Taskbar::remove_task(uint32_t id) { auto it = std::find_if(std::begin(tasks_), std::end(tasks_), - [id](const TaskPtr &p) { return p->id() == id; }); + [id](const TaskPtr& p) { return p->id() == id; }); if (it == std::end(tasks_)) { spdlog::warn("Can't find task with id {}", id); @@ -741,7 +742,7 @@ void Taskbar::remove_task(uint32_t id) { tasks_.erase(it); } -bool Taskbar::show_output(struct wl_output *output) const { +bool Taskbar::show_output(struct wl_output* output) const { return output == gdk_wayland_monitor_get_wl_output(bar_.output->monitor->gobj()); } @@ -749,11 +750,11 @@ bool Taskbar::all_outputs() const { return config_["all-outputs"].isBool() && config_["all-outputs"].asBool(); } -const IconLoader &Taskbar::icon_loader() const { return icon_loader_; } +const IconLoader& Taskbar::icon_loader() const { return icon_loader_; } -const std::unordered_set &Taskbar::ignore_list() const { return ignore_list_; } +const std::unordered_set& Taskbar::ignore_list() const { return ignore_list_; } -const std::map &Taskbar::app_ids_replace_map() const { +const std::map& Taskbar::app_ids_replace_map() const { return app_ids_replace_map_; } diff --git a/src/util/audio_backend.cpp b/src/util/audio_backend.cpp index 860168fdf..342d40b27 100644 --- a/src/util/audio_backend.cpp +++ b/src/util/audio_backend.cpp @@ -69,8 +69,8 @@ void AudioBackend::connectContext() { } } -void AudioBackend::contextStateCb(pa_context *c, void *data) { - auto *backend = static_cast(data); +void AudioBackend::contextStateCb(pa_context* c, void* data) { + auto* backend = static_cast(data); switch (pa_context_get_state(c)) { case PA_CONTEXT_TERMINATED: backend->mainloop_api_->quit(backend->mainloop_api_, 0); @@ -107,8 +107,8 @@ void AudioBackend::contextStateCb(pa_context *c, void *data) { /* * Called when an event we subscribed to occurs. */ -void AudioBackend::subscribeCb(pa_context *context, pa_subscription_event_type_t type, uint32_t idx, - void *data) { +void AudioBackend::subscribeCb(pa_context* context, pa_subscription_event_type_t type, uint32_t idx, + void* data) { unsigned facility = type & PA_SUBSCRIPTION_EVENT_FACILITY_MASK; unsigned operation = type & PA_SUBSCRIPTION_EVENT_TYPE_MASK; if (operation != PA_SUBSCRIPTION_EVENT_CHANGE) { @@ -130,8 +130,8 @@ void AudioBackend::subscribeCb(pa_context *context, pa_subscription_event_type_t /* * Called in response to a volume change request */ -void AudioBackend::volumeModifyCb(pa_context *c, int success, void *data) { - auto *backend = static_cast(data); +void AudioBackend::volumeModifyCb(pa_context* c, int success, void* data) { + auto* backend = static_cast(data); if (success != 0) { if ((backend->context_ != nullptr) && pa_context_get_state(backend->context_) == PA_CONTEXT_READY) { @@ -145,18 +145,18 @@ void AudioBackend::volumeModifyCb(pa_context *c, int success, void *data) { /* * Called when the requested sink information is ready. */ -void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, int /*eol*/, - void *data) { +void AudioBackend::sinkInfoCb(pa_context* /*context*/, const pa_sink_info* i, int /*eol*/, + void* data) { if (i == nullptr) return; auto running = i->state == PA_SINK_RUNNING; auto idle = i->state == PA_SINK_IDLE; spdlog::trace("Sink name {} Running:[{}] Idle:[{}]", i->name, running, idle); - auto *backend = static_cast(data); + auto* backend = static_cast(data); if (!backend->ignored_sinks_.empty()) { - for (const auto &ignored_sink : backend->ignored_sinks_) { + for (const auto& ignored_sink : backend->ignored_sinks_) { if (ignored_sink == i->description) { if (i->name == backend->current_sink_name_) { // If the current sink happens to be ignored it is never considered running @@ -205,7 +205,7 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i backend->desc_ = i->description; backend->monitor_ = i->monitor_source_name; backend->port_name_ = i->active_port != nullptr ? i->active_port->name : "Unknown"; - if (const 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; } else { backend->form_factor_ = ""; @@ -217,9 +217,9 @@ void AudioBackend::sinkInfoCb(pa_context * /*context*/, const pa_sink_info *i, i /* * Called when the requested source information is ready. */ -void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info *i, int /*eol*/, - void *data) { - auto *backend = static_cast(data); +void AudioBackend::sourceInfoCb(pa_context* /*context*/, const pa_source_info* i, int /*eol*/, + void* data) { + auto* backend = static_cast(data); if (i != nullptr && backend->default_source_name_ == i->name) { auto source_volume = static_cast(pa_cvolume_avg(&(i->volume))) / float{PA_VOLUME_NORM}; backend->source_volume_ = std::round(source_volume * 100.0F); @@ -235,8 +235,8 @@ void AudioBackend::sourceInfoCb(pa_context * /*context*/, const pa_source_info * * Called when the requested information on the server is ready. This is * used to find the default PulseAudio sink. */ -void AudioBackend::serverInfoCb(pa_context *context, const pa_server_info *i, void *data) { - auto *backend = static_cast(data); +void AudioBackend::serverInfoCb(pa_context* context, const pa_server_info* i, void* data) { + auto* backend = static_cast(data); backend->current_sink_name_ = i->default_sink_name; backend->default_sink_name = i->default_sink_name; backend->default_source_name_ = i->default_source_name; @@ -392,9 +392,9 @@ bool AudioBackend::isBluetooth() { monitor_.find("bluez") != std::string::npos; } -void AudioBackend::setIgnoredSinks(const Json::Value &config) { +void AudioBackend::setIgnoredSinks(const Json::Value& config) { if (config.isArray()) { - for (const auto &ignored_sink : config) { + for (const auto& ignored_sink : config) { if (ignored_sink.isString()) { ignored_sinks_.push_back(ignored_sink.asString()); } diff --git a/src/util/backlight_backend.cpp b/src/util/backlight_backend.cpp index 8ae52fb96..a136f6358 100644 --- a/src/util/backlight_backend.cpp +++ b/src/util/backlight_backend.cpp @@ -14,10 +14,10 @@ namespace { class FileDescriptor { public: explicit FileDescriptor(int fd) : fd_(fd) {} - FileDescriptor(const FileDescriptor &other) = delete; - FileDescriptor(FileDescriptor &&other) noexcept = delete; - FileDescriptor &operator=(const FileDescriptor &other) = delete; - FileDescriptor &operator=(FileDescriptor &&other) noexcept = delete; + FileDescriptor(const FileDescriptor& other) = delete; + FileDescriptor(FileDescriptor&& other) noexcept = delete; + FileDescriptor& operator=(const FileDescriptor& other) = delete; + FileDescriptor& operator=(FileDescriptor&& other) noexcept = delete; ~FileDescriptor() { if (fd_ != -1) { if (close(fd_) != 0) { @@ -31,27 +31,27 @@ class FileDescriptor { int fd_; }; -void check_eq(int rc, int expected, const char *message = "eq, rc was: ") { +void check_eq(int rc, int expected, const char* message = "eq, rc was: ") { if (rc != expected) { throw std::runtime_error(fmt::format(fmt::runtime(message), rc)); } } -void check_neq(int rc, int bad_rc, const char *message = "neq, rc was: ") { +void check_neq(int rc, int bad_rc, const char* message = "neq, rc was: ") { if (rc == bad_rc) { throw std::runtime_error(fmt::format(fmt::runtime(message), rc)); } } -void check0(int rc, const char *message = "rc wasn't 0") { check_eq(rc, 0, message); } +void check0(int rc, const char* message = "rc wasn't 0") { check_eq(rc, 0, message); } -void check_gte(int rc, int gte, const char *message = "rc was: ") { +void check_gte(int rc, int gte, const char* message = "rc was: ") { if (rc < gte) { throw std::runtime_error(fmt::format(fmt::runtime(message), rc)); } } -void check_nn(const void *ptr, const char *message = "ptr was null") { +void check_nn(const void* ptr, const char* message = "ptr was null") { if (ptr == nullptr) { throw std::runtime_error(message); } @@ -61,20 +61,20 @@ void check_nn(const void *ptr, const char *message = "ptr was null") { namespace waybar::util { -static void upsert_device(std::vector &devices, udev_device *dev) { - const char *name = udev_device_get_sysname(dev); +static void upsert_device(std::vector& devices, udev_device* dev) { + const char* name = udev_device_get_sysname(dev); check_nn(name); - const char *actual_brightness_attr = + const char* actual_brightness_attr = strncmp(name, "amdgpu_bl", 9) == 0 || strcmp(name, "apple-panel-bl") == 0 ? "brightness" : "actual_brightness"; - const char *actual = udev_device_get_sysattr_value(dev, actual_brightness_attr); - const char *max = udev_device_get_sysattr_value(dev, "max_brightness"); - const char *power = udev_device_get_sysattr_value(dev, "bl_power"); + const char* actual = udev_device_get_sysattr_value(dev, actual_brightness_attr); + const char* max = udev_device_get_sysattr_value(dev, "max_brightness"); + const char* power = udev_device_get_sysattr_value(dev, "bl_power"); - auto found = std::find_if(devices.begin(), devices.end(), [name](const BacklightDevice &device) { + auto found = std::find_if(devices.begin(), devices.end(), [name](const BacklightDevice& device) { return device.name() == name; }); if (found != devices.end()) { @@ -95,14 +95,14 @@ static void upsert_device(std::vector &devices, udev_device *de } } -static void enumerate_devices(std::vector &devices, udev *udev) { +static void enumerate_devices(std::vector& devices, udev* udev) { std::unique_ptr enumerate{udev_enumerate_new(udev)}; udev_enumerate_add_match_subsystem(enumerate.get(), "backlight"); udev_enumerate_scan_devices(enumerate.get()); - udev_list_entry *enum_devices = udev_enumerate_get_list_entry(enumerate.get()); - udev_list_entry *dev_list_entry; + udev_list_entry* enum_devices = udev_enumerate_get_list_entry(enumerate.get()); + udev_list_entry* dev_list_entry; udev_list_entry_foreach(dev_list_entry, enum_devices) { - const char *path = udev_list_entry_get_name(dev_list_entry); + const char* path = udev_list_entry_get_name(dev_list_entry); std::unique_ptr dev{udev_device_new_from_syspath(udev, path)}; check_nn(dev.get(), "dev new failed"); upsert_device(devices, dev.get()); @@ -184,7 +184,7 @@ BacklightBackend::BacklightBackend(std::chrono::milliseconds interval, devices = devices_; } for (int i = 0; i < event_count; ++i) { - const auto &event = events[i]; + const auto& event = events[i]; check_eq(event.data.fd, udev_fd, "unexpected udev fd"); std::unique_ptr dev{udev_monitor_receive_device(mon.get())}; if (!dev) { @@ -206,27 +206,27 @@ BacklightBackend::BacklightBackend(std::chrono::milliseconds interval, }; } -const BacklightDevice *BacklightBackend::best_device(const std::vector &devices, +const BacklightDevice* BacklightBackend::best_device(const std::vector& devices, std::string_view preferred_device) { const auto found = std::find_if( devices.begin(), devices.end(), - [preferred_device](const BacklightDevice &dev) { return dev.name() == preferred_device; }); + [preferred_device](const BacklightDevice& dev) { return dev.name() == preferred_device; }); if (found != devices.end()) { return &(*found); } const auto max = std::max_element( devices.begin(), devices.end(), - [](const BacklightDevice &l, const BacklightDevice &r) { return l.get_max() < r.get_max(); }); + [](const BacklightDevice& l, const BacklightDevice& r) { return l.get_max() < r.get_max(); }); return max == devices.end() ? nullptr : &(*max); } -const BacklightDevice *BacklightBackend::get_previous_best_device() { +const BacklightDevice* BacklightBackend::get_previous_best_device() { return previous_best_.has_value() ? &(*previous_best_) : nullptr; } -void BacklightBackend::set_previous_best_device(const BacklightDevice *device) { +void BacklightBackend::set_previous_best_device(const BacklightDevice* device) { if (device == nullptr) { previous_best_ = std::nullopt; } else { @@ -234,7 +234,7 @@ void BacklightBackend::set_previous_best_device(const BacklightDevice *device) { } } -void BacklightBackend::set_scaled_brightness(const 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); if (best != nullptr) { @@ -244,7 +244,7 @@ void BacklightBackend::set_scaled_brightness(const std::string &preferred_device } } -void BacklightBackend::set_brightness(const std::string &preferred_device, ChangeType change_type, +void BacklightBackend::set_brightness(const std::string& preferred_device, ChangeType change_type, double step) { GET_BEST_DEVICE(best, (*this), preferred_device); @@ -259,7 +259,7 @@ void BacklightBackend::set_brightness(const std::string &preferred_device, Chang } } -void BacklightBackend::set_brightness_internal(const std::string &device_name, int brightness, +void BacklightBackend::set_brightness_internal(const std::string& device_name, int brightness, int max_brightness) { brightness = std::clamp(brightness, 0, max_brightness); @@ -269,7 +269,7 @@ void BacklightBackend::set_brightness_internal(const std::string &device_name, i login_proxy_->call_sync("SetBrightness", call_args); } -int BacklightBackend::get_scaled_brightness(const std::string &preferred_device) { +int BacklightBackend::get_scaled_brightness(const std::string& preferred_device) { GET_BEST_DEVICE(best, (*this), preferred_device); if (best != nullptr) { diff --git a/src/util/icon_loader.cpp b/src/util/icon_loader.cpp index 69e25dbce..fe534f691 100644 --- a/src/util/icon_loader.cpp +++ b/src/util/icon_loader.cpp @@ -26,12 +26,12 @@ std::vector IconLoader::search_prefix() { } while (end != std::string::npos); } - for (auto &p : prefixes) spdlog::debug("Using 'desktop' search path prefix: {}", p); + for (auto& p : prefixes) spdlog::debug("Using 'desktop' search path prefix: {}", p); return prefixes; } -Glib::RefPtr IconLoader::get_app_info_by_name(const std::string &app_id) { +Glib::RefPtr IconLoader::get_app_info_by_name(const std::string& app_id) { static std::vector prefixes = search_prefix(); std::vector app_folders = {"", "applications/", "applications/kde/", @@ -39,9 +39,9 @@ Glib::RefPtr IconLoader::get_app_info_by_name(const std::st std::vector suffixes = {"", ".desktop"}; - for (auto const &prefix : prefixes) { - for (auto const &folder : app_folders) { - for (auto const &suffix : suffixes) { + for (auto const& prefix : prefixes) { + for (auto const& folder : app_folders) { + for (auto const& suffix : suffixes) { auto app_info_ = Gio::DesktopAppInfo::create_from_filename(prefix + folder + app_id + suffix); if (!app_info_) { @@ -56,7 +56,7 @@ Glib::RefPtr IconLoader::get_app_info_by_name(const std::st return {}; } -Glib::RefPtr IconLoader::get_desktop_app_info(const std::string &app_id) { +Glib::RefPtr IconLoader::get_desktop_app_info(const std::string& app_id) { auto app_info = get_app_info_by_name(app_id); if (app_info) { return app_info; @@ -64,7 +64,7 @@ Glib::RefPtr IconLoader::get_desktop_app_info(const std::st std::string desktop_file = ""; - gchar ***desktop_list = g_desktop_app_info_search(app_id.c_str()); + gchar*** desktop_list = g_desktop_app_info_search(app_id.c_str()); if (desktop_list != nullptr && desktop_list[0] != nullptr) { for (size_t i = 0; desktop_list[0][i]; i++) { if (desktop_file == "") { @@ -89,7 +89,7 @@ Glib::RefPtr IconLoader::get_desktop_app_info(const std::st return get_app_info_by_name(desktop_file); } -Glib::RefPtr IconLoader::load_icon_from_file(std::string const &icon_path, int size) { +Glib::RefPtr IconLoader::load_icon_from_file(std::string const& icon_path, int size) { try { auto pb = Gdk::Pixbuf::create_from_file(icon_path, size, size); return pb; @@ -99,13 +99,13 @@ Glib::RefPtr IconLoader::load_icon_from_file(std::string const &ico } std::string IconLoader::get_icon_name_from_icon_theme( - const Glib::RefPtr &icon_theme, const std::string &app_id) { + const Glib::RefPtr& icon_theme, const std::string& app_id) { if (icon_theme->lookup_icon(app_id, 24)) return app_id; return ""; } -bool IconLoader::image_load_icon(Gtk::Image &image, const Glib::RefPtr &icon_theme, +bool IconLoader::image_load_icon(Gtk::Image& image, const Glib::RefPtr& icon_theme, Glib::RefPtr app_info, int size) { std::string ret_icon_name = "unknown"; if (app_info) { @@ -152,16 +152,16 @@ bool IconLoader::image_load_icon(Gtk::Image &image, const Glib::RefPtrset_custom_theme(theme_name); custom_icon_themes_.push_back(icon_theme); spdlog::debug("Use custom icon theme: {}", theme_name); } -bool IconLoader::image_load_icon(Gtk::Image &image, Glib::RefPtr app_info, +bool IconLoader::image_load_icon(Gtk::Image& image, Glib::RefPtr app_info, int size) const { - for (auto &icon_theme : custom_icon_themes_) { + for (auto& icon_theme : custom_icon_themes_) { if (image_load_icon(image, icon_theme, app_info, size)) { return true; } @@ -170,7 +170,7 @@ bool IconLoader::image_load_icon(Gtk::Image &image, Glib::RefPtr IconLoader::get_app_info_from_app_id_list( - const std::string &app_id_list) { + const std::string& app_id_list) { std::string app_id; std::istringstream stream(app_id_list); Glib::RefPtr app_info_; diff --git a/src/util/pipewire/pipewire_backend.cpp b/src/util/pipewire/pipewire_backend.cpp index 6d859a91f..a88a3fbe7 100644 --- a/src/util/pipewire/pipewire_backend.cpp +++ b/src/util/pipewire/pipewire_backend.cpp @@ -4,11 +4,11 @@ namespace waybar::util::PipewireBackend { -static void getNodeInfo(void *data_, const struct pw_node_info *info) { - auto *pNodeInfo = static_cast(data_); +static void getNodeInfo(void* data_, const struct pw_node_info* info) { + auto* pNodeInfo = static_cast(data_); pNodeInfo->handleNodeEventInfo(info); - static_cast(pNodeInfo->data)->privacy_nodes_changed_signal_event.emit(); + static_cast(pNodeInfo->data)->privacy_nodes_changed_signal_event.emit(); } static const struct pw_node_events NODE_EVENTS = { @@ -16,8 +16,8 @@ static const struct pw_node_events NODE_EVENTS = { .info = getNodeInfo, }; -static void proxyDestroy(void *data) { - static_cast(data)->handleProxyEventDestroy(); +static void proxyDestroy(void* data) { + static_cast(data)->handleProxyEventDestroy(); } static const struct pw_proxy_events PROXY_EVENTS = { @@ -25,14 +25,14 @@ static const struct pw_proxy_events PROXY_EVENTS = { .destroy = proxyDestroy, }; -static void registryEventGlobal(void *_data, uint32_t id, uint32_t permissions, const char *type, - uint32_t version, const struct spa_dict *props) { - static_cast(_data)->handleRegistryEventGlobal(id, permissions, type, version, - props); +static void registryEventGlobal(void* _data, uint32_t id, uint32_t permissions, const char* type, + uint32_t version, const struct spa_dict* props) { + static_cast(_data)->handleRegistryEventGlobal(id, permissions, type, version, + props); } -static void registryEventGlobalRemove(void *_data, uint32_t id) { - static_cast(_data)->handleRegistryEventGlobalRemove(id); +static void registryEventGlobalRemove(void* _data, uint32_t id) { + static_cast(_data)->handleRegistryEventGlobalRemove(id); } static const struct pw_registry_events REGISTRY_EVENTS = { @@ -78,7 +78,7 @@ PipewireBackend::~PipewireBackend() { } if (registry_ != nullptr) { - pw_proxy_destroy((struct pw_proxy *)registry_); + pw_proxy_destroy((struct pw_proxy*)registry_); } spa_zero(registryListener_); @@ -103,11 +103,11 @@ std::shared_ptr PipewireBackend::getInstance() { return std::make_shared(tag); } -void PipewireBackend::handleRegistryEventGlobal(uint32_t id, uint32_t permissions, const char *type, - uint32_t version, const struct spa_dict *props) { +void PipewireBackend::handleRegistryEventGlobal(uint32_t id, uint32_t permissions, const char* type, + uint32_t version, const struct spa_dict* props) { if (props == nullptr || strcmp(type, PW_TYPE_INTERFACE_Node) != 0) return; - const char *lookupStr = spa_dict_lookup(props, PW_KEY_MEDIA_CLASS); + const char* lookupStr = spa_dict_lookup(props, PW_KEY_MEDIA_CLASS); if (lookupStr == nullptr) return; std::string mediaClass = lookupStr; enum PrivacyNodeType mediaType = PRIVACY_NODE_TYPE_NONE; @@ -121,11 +121,11 @@ void PipewireBackend::handleRegistryEventGlobal(uint32_t id, uint32_t permission return; } - auto *proxy = (pw_proxy *)pw_registry_bind(registry_, id, type, version, sizeof(PrivacyNodeInfo)); + auto* proxy = (pw_proxy*)pw_registry_bind(registry_, id, type, version, sizeof(PrivacyNodeInfo)); if (proxy == nullptr) return; - auto *pNodeInfo = (PrivacyNodeInfo *)pw_proxy_get_user_data(proxy); + auto* pNodeInfo = (PrivacyNodeInfo*)pw_proxy_get_user_data(proxy); new (pNodeInfo) PrivacyNodeInfo{}; pNodeInfo->id = id; pNodeInfo->data = this; diff --git a/src/util/pipewire/privacy_node_info.cpp b/src/util/pipewire/privacy_node_info.cpp index ec110b866..dbd6ed852 100644 --- a/src/util/pipewire/privacy_node_info.cpp +++ b/src/util/pipewire/privacy_node_info.cpp @@ -3,9 +3,9 @@ namespace waybar::util::PipewireBackend { std::string PrivacyNodeInfo::getName() { - const std::vector names{&application_name, &node_name}; + const std::vector names{&application_name, &node_name}; std::string name = "Unknown Application"; - for (const auto &item : names) { + for (const auto& item : names) { if (item != nullptr && !item->empty()) { name = *item; name[0] = toupper(name[0]); @@ -16,10 +16,10 @@ std::string PrivacyNodeInfo::getName() { } std::string PrivacyNodeInfo::getIconName() { - const std::vector names{&application_icon_name, &pipewire_access_portal_app_id, - &application_name, &node_name}; + const std::vector names{&application_icon_name, &pipewire_access_portal_app_id, + &application_name, &node_name}; std::string name = "application-x-executable-symbolic"; - for (const auto &item : names) { + for (const auto& item : names) { if (item != nullptr && !item->empty() && DefaultGtkIconThemeWrapper::has_icon(*item)) { return *item; } @@ -32,10 +32,10 @@ void PrivacyNodeInfo::handleProxyEventDestroy() { spa_hook_remove(&object_listener); } -void PrivacyNodeInfo::handleNodeEventInfo(const struct pw_node_info *info) { +void PrivacyNodeInfo::handleNodeEventInfo(const struct pw_node_info* info) { state = info->state; - const struct spa_dict_item *item; + const struct spa_dict_item* item; spa_dict_for_each(item, info->props) { if (strcmp(item->key, PW_KEY_CLIENT_ID) == 0) { client_id = strtoul(item->value, nullptr, 10); diff --git a/src/util/prepare_for_sleep.cpp b/src/util/prepare_for_sleep.cpp index 3adcdf672..ed4100beb 100644 --- a/src/util/prepare_for_sleep.cpp +++ b/src/util/prepare_for_sleep.cpp @@ -18,21 +18,21 @@ class PrepareForSleep { } } - static void prepareForSleep_cb(GDBusConnection *system_bus, const gchar *sender_name, - const gchar *object_path, const gchar *interface_name, - const gchar *signal_name, GVariant *parameters, + static void prepareForSleep_cb(GDBusConnection* system_bus, const gchar* sender_name, + const gchar* object_path, const gchar* interface_name, + const gchar* signal_name, GVariant* parameters, gpointer user_data) { if (g_variant_is_of_type(parameters, G_VARIANT_TYPE("(b)")) != 0) { gboolean sleeping; g_variant_get(parameters, "(b)", &sleeping); - auto *self = static_cast(user_data); + auto* self = static_cast(user_data); self->signal.emit(sleeping); } } public: - static PrepareForSleep &GetInstance() { + static PrepareForSleep& GetInstance() { static PrepareForSleep instance; return instance; } @@ -40,10 +40,10 @@ class PrepareForSleep { private: guint login1_id; - GDBusConnection *login1_connection; + GDBusConnection* login1_connection; }; } // namespace -waybar::SafeSignal &waybar::util::prepare_for_sleep() { +waybar::SafeSignal& waybar::util::prepare_for_sleep() { return PrepareForSleep::GetInstance().signal; } diff --git a/src/util/ustring_clen.cpp b/src/util/ustring_clen.cpp index a8b9c9af6..5a5b00287 100644 --- a/src/util/ustring_clen.cpp +++ b/src/util/ustring_clen.cpp @@ -1,6 +1,6 @@ #include "util/ustring_clen.hpp" -int ustring_clen(const Glib::ustring &str) { +int ustring_clen(const Glib::ustring& str) { int total = 0; for (unsigned int i : str) { total += g_unichar_iswide(i) + 1;