diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml
index 0fad47c4..25f62c8e 100644
--- a/.github/workflows/clang-format.yml
+++ b/.github/workflows/clang-format.yml
@@ -10,13 +10,9 @@ jobs:
lint:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
- # TODO: bump to clang 19 release
- # - uses: DoozyX/clang-format-lint-action@v0.18.2
- - uses: DoozyX/clang-format-lint-action@558090054b3f39e3d6af24f0cd73b319535da809
+ - uses: actions/checkout@v6
+ - uses: RafikFarhad/clang-format-github-action@v6
name: clang-format
with:
- source: "."
- extensions: "hpp,h,cpp,c"
- style: "file:.clang-format"
- clangFormatVersion: 19
+ sources: "src/**/*.hpp,src/**/*.cpp"
+ style: "file"
diff --git a/.github/workflows/clang-tidy.yml.bak b/.github/workflows/clang-tidy.yml.bak
index ec67fb7e..9e9da80c 100644
--- a/.github/workflows/clang-tidy.yml.bak
+++ b/.github/workflows/clang-tidy.yml.bak
@@ -12,7 +12,7 @@ jobs:
container:
image: alexays/waybar:debian
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v6
- name: configure
run: |
meson -Dcpp_std=c++20 build # necessary to generate compile_commands.json
diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml
index 0e7e2944..ea8eb08b 100644
--- a/.github/workflows/docker.yml
+++ b/.github/workflows/docker.yml
@@ -17,7 +17,7 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@v4
+ - uses: actions/checkout@v6
- name: Login to Docker Hub
uses: docker/login-action@v3
diff --git a/.github/workflows/freebsd.yml b/.github/workflows/freebsd.yml
index b9114c31..f6c96f95 100644
--- a/.github/workflows/freebsd.yml
+++ b/.github/workflows/freebsd.yml
@@ -12,13 +12,13 @@ jobs:
# https://github.com/actions/runner/issues/385 - for FreeBSD runner support
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v6
- name: Test in FreeBSD VM
uses: cross-platform-actions/action@v0.28.0
timeout-minutes: 180
env:
CPPFLAGS: '-isystem/usr/local/include'
- LDFLAGS: '-L/usr/local/lib'
+ LDFLAGS: '-L/usr/local/lib'
with:
operating_system: freebsd
version: "14.2"
diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
index c36f68e2..12a995d7 100644
--- a/.github/workflows/linux.yml
+++ b/.github/workflows/linux.yml
@@ -25,7 +25,7 @@ jobs:
image: alexays/waybar:${{ matrix.distro }}
steps:
- - uses: actions/checkout@v3
+ - uses: actions/checkout@v6
- name: configure
run: meson setup -Dman-pages=enabled -Dcpp_std=${{matrix.cpp_std}} build
- name: build
diff --git a/.github/workflows/nix-tests.yml b/.github/workflows/nix-tests.yml
index 8859ecb5..c2193b99 100644
--- a/.github/workflows/nix-tests.yml
+++ b/.github/workflows/nix-tests.yml
@@ -2,16 +2,19 @@ name: "Nix-Tests"
on:
pull_request:
push:
+concurrency:
+ group: ${{ github.workflow }}-nix-${{ github.event.pull_request.number || github.ref }}
+ cancel-in-progress: true
jobs:
nix-flake-check:
runs-on: ubuntu-latest
steps:
- - uses: actions/checkout@v4
- - uses: cachix/install-nix-action@v27
- with:
- extra_nix_config: |
- experimental-features = nix-command flakes
- access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- - run: nix flake show
- - run: nix flake check --print-build-logs
- - run: nix build --print-build-logs
+ - uses: actions/checkout@v6
+ - uses: cachix/install-nix-action@v31
+ with:
+ extra_nix_config: |
+ experimental-features = nix-command flakes
+ access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
+ - run: nix flake show
+ - run: nix flake check --print-build-logs
+ - run: nix build --print-build-logs
diff --git a/.github/workflows/nix-update-flake-lock.yml b/.github/workflows/nix-update-flake-lock.yml
index a1679ead..de8a0ea1 100644
--- a/.github/workflows/nix-update-flake-lock.yml
+++ b/.github/workflows/nix-update-flake-lock.yml
@@ -4,19 +4,19 @@ on:
schedule:
- cron: '0 0 1 * *' # Run monthly
push:
- paths:
- - 'flake.nix'
+ paths:
+ - 'flake.nix'
jobs:
lockfile:
runs-on: ubuntu-latest
if: github.event_name != 'schedule' || github.repository == 'Alexays/Waybar'
steps:
- name: Checkout repository
- uses: actions/checkout@v4
+ - uses: actions/checkout@v6
- name: Install Nix
- uses: cachix/install-nix-action@v27
+ uses: cachix/install-nix-action@v31
with:
extra_nix_config: |
access-tokens = github.com=${{ secrets.GITHUB_TOKEN }}
- name: Update flake.lock
- uses: DeterminateSystems/update-flake-lock@v21
+ uses: DeterminateSystems/update-flake-lock@v28
diff --git a/.gitignore b/.gitignore
index b486237e..f42bf85e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -7,6 +7,7 @@ vgcore.*
*.swp
packagecache
/subprojects/**/
+/subprojects/.wraplock
/build*
/dist
/meson.egg-info
@@ -50,3 +51,4 @@ result
result-*
.ccls-cache
+_codeql_detected_source_root
diff --git a/README.md b/README.md
index 4edf2253..9ca041d1 100644
--- a/README.md
+++ b/README.md
@@ -119,7 +119,7 @@ sudo apt install \
On Arch, you can use this command:
```
-pacman -S \
+pacman -S --asdeps \
gtkmm3 \
jsoncpp \
libsigc++ \
@@ -151,6 +151,10 @@ Contributions welcome!
Have fun :)
The style guidelines are [Google's](https://google.github.io/styleguide/cppguide.html)
+> [!CAUTION]
+> Distributions of Waybar are only released on the [official GitHub page](https://github.com/Alexays/Waybar).
+> Waybar does **not** have an official website. Do not trust any sites that claim to be official.
+
## License
Waybar is licensed under the MIT license. [See LICENSE for more information](https://github.com/Alexays/Waybar/blob/master/LICENSE).
diff --git a/_codeql_detected_source_root b/_codeql_detected_source_root
new file mode 120000
index 00000000..945c9b46
--- /dev/null
+++ b/_codeql_detected_source_root
@@ -0,0 +1 @@
+.
\ No newline at end of file
diff --git a/flake.lock b/flake.lock
index d689d35b..e3e70a02 100644
--- a/flake.lock
+++ b/flake.lock
@@ -3,11 +3,11 @@
"flake-compat": {
"flake": false,
"locked": {
- "lastModified": 1747046372,
- "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
+ "lastModified": 1767039857,
+ "narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=",
"owner": "edolstra",
"repo": "flake-compat",
- "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
+ "rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
"type": "github"
},
"original": {
@@ -18,11 +18,11 @@
},
"nixpkgs": {
"locked": {
- "lastModified": 1760878510,
- "narHash": "sha256-K5Osef2qexezUfs0alLvZ7nQFTGS9DL2oTVsIXsqLgs=",
+ "lastModified": 1769461804,
+ "narHash": "sha256-msG8SU5WsBUfVVa/9RPLaymvi5bI8edTavbIq3vRlhI=",
"owner": "NixOS",
"repo": "nixpkgs",
- "rev": "5e2a59a5b1a82f89f2c7e598302a9cacebb72a67",
+ "rev": "bfc1b8a4574108ceef22f02bafcf6611380c100d",
"type": "github"
},
"original": {
diff --git a/include/AAppIconLabel.hpp b/include/AAppIconLabel.hpp
index d09ab14a..e8532e18 100644
--- a/include/AAppIconLabel.hpp
+++ b/include/AAppIconLabel.hpp
@@ -9,15 +9,15 @@ 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,
+ 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);
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 054d031a..f0fb8614 100644
--- a/include/AIconLabel.hpp
+++ b/include/AIconLabel.hpp
@@ -9,8 +9,8 @@ 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,
+ 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);
virtual ~AIconLabel() = default;
auto update() -> void override;
diff --git a/include/ALabel.hpp b/include/ALabel.hpp
index 92fc2e0f..b3852877 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,
+ 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);
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 2fcbfc23..6b29045c 100644
--- a/include/AModule.hpp
+++ b/include/AModule.hpp
@@ -12,13 +12,13 @@ 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;
@@ -28,30 +28,30 @@ class AModule : public IModule {
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,
+ AModule(const Json::Value&, const std::string&, const std::string&, 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/bar.hpp b/include/bar.hpp
index 9953b1f5..54b332bf 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 0e68f002..c3df3f21 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);
+ 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 *);
+ 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);
@@ -56,6 +56,8 @@ class Client {
std::list outputs_;
std::unique_ptr m_cssReloadHelper;
std::string m_cssFile;
+ sigc::connection monitor_added_connection_;
+ sigc::connection monitor_removed_connection_;
};
} // namespace waybar
diff --git a/include/config.hpp b/include/config.hpp
index bf653c2a..1ef9ef5f 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/group.hpp b/include/group.hpp
index 5ce331a8..41cb5ee0 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 110cd434..46b38972 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&);
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/battery.hpp b/include/modules/battery.hpp
index c593e59b..09c172b0 100644
--- a/include/modules/battery.hpp
+++ b/include/modules/battery.hpp
@@ -6,6 +6,7 @@
#if defined(__linux__)
#include
#endif
+#include
#include
#include
@@ -15,6 +16,7 @@
#include "ALabel.hpp"
#include "bar.hpp"
#include "util/sleeper_thread.hpp"
+#include "util/udev_deleter.hpp"
namespace waybar::modules {
@@ -37,15 +39,17 @@ class Battery : public ALabel {
void setBarClass(std::string&);
void processEvents(std::string& state, std::string& status, uint8_t capacity);
- int global_watch;
std::map batteries_;
+ std::unique_ptr udev_;
+ std::array poll_fds_;
+ std::unique_ptr mon_;
fs::path adapter_;
int battery_watch_fd_;
- int global_watch_fd_;
std::mutex battery_list_mutex_;
std::string old_status_;
std::string last_event_;
bool warnFirstTime_{true};
+ bool weightedAverage_{true};
const Bar& bar_;
util::SleeperThread thread_;
diff --git a/include/modules/cava/cavaGLSL.hpp b/include/modules/cava/cavaGLSL.hpp
new file mode 100644
index 00000000..d2632aff
--- /dev/null
+++ b/include/modules/cava/cavaGLSL.hpp
@@ -0,0 +1,43 @@
+#pragma once
+
+#include
+
+#include "AModule.hpp"
+#include "cava_backend.hpp"
+
+namespace waybar::modules::cava {
+
+class CavaGLSL final : public AModule, public Gtk::GLArea {
+ public:
+ CavaGLSL(const std::string&, const Json::Value&);
+ ~CavaGLSL() = default;
+
+ private:
+ std::shared_ptr backend_;
+ struct ::cava::config_params prm_;
+ int frame_counter{0};
+ bool silence_{false};
+ bool hide_on_silence_{false};
+ // Cava method
+ auto onUpdate(const ::cava::audio_raw& input) -> void;
+ auto onSilence() -> void;
+ // Member variable to store the shared pointer
+ std::shared_ptr<::cava::audio_raw> m_data_;
+ GLuint shaderProgram_;
+ // OpenGL variables
+ GLuint fbo_;
+ GLuint texture_;
+ GLint uniform_bars_;
+ GLint uniform_previous_bars_;
+ GLint uniform_bars_count_;
+ GLint uniform_time_;
+ // Methods
+ void onRealize();
+ bool onRender(const Glib::RefPtr& context);
+
+ void initShaders();
+ void initSurface();
+ void initGLSL();
+ GLuint loadShader(const std::string& fileName, GLenum type);
+};
+} // namespace waybar::modules::cava
diff --git a/include/modules/cava/cava.hpp b/include/modules/cava/cavaRaw.hpp
similarity index 96%
rename from include/modules/cava/cava.hpp
rename to include/modules/cava/cavaRaw.hpp
index 6b13c4bd..f4ceb603 100644
--- a/include/modules/cava/cava.hpp
+++ b/include/modules/cava/cavaRaw.hpp
@@ -9,20 +9,20 @@ class Cava final : public ALabel, public sigc::trackable {
public:
Cava(const std::string&, const Json::Value&);
~Cava() = default;
- auto onUpdate(const std::string& input) -> void;
- auto onSilence() -> void;
auto doAction(const std::string& name) -> void override;
private:
std::shared_ptr backend_;
// Text to display
- std::string label_text_{""};
+ Glib::ustring label_text_{""};
+ bool silence_{false};
bool hide_on_silence_{false};
std::string format_silent_{""};
int ascii_range_{0};
- bool silence_{false};
// Cava method
void pause_resume();
+ auto onUpdate(const std::string& input) -> void;
+ auto onSilence() -> void;
// ModuleActionMap
static inline std::map
actionMap_{{"mode", &waybar::modules::cava::Cava::pause_resume}};
diff --git a/include/modules/cava/cava_backend.hpp b/include/modules/cava/cava_backend.hpp
index c88182b3..4022a2ff 100644
--- a/include/modules/cava/cava_backend.hpp
+++ b/include/modules/cava/cava_backend.hpp
@@ -32,16 +32,22 @@ class CavaBackend final {
int getAsciiRange();
void doPauseResume();
void Update();
+ const struct ::cava::config_params* getPrm();
+ std::chrono::milliseconds getFrameTimeMilsec();
+
// Signal accessor
using type_signal_update = sigc::signal;
type_signal_update signal_update();
+ using type_signal_audio_raw_update = sigc::signal;
+ type_signal_audio_raw_update signal_audio_raw_update();
using type_signal_silence = sigc::signal;
type_signal_silence signal_silence();
private:
CavaBackend(const Json::Value& config);
- util::SleeperThread thread_;
util::SleeperThread read_thread_;
+ util::SleeperThread out_thread_;
+
// Cava API to read audio source
::cava::ptr input_source_{NULL};
@@ -55,6 +61,7 @@ class CavaBackend final {
// Delay to handle audio source
std::chrono::milliseconds frame_time_milsec_{1s};
+ const Json::Value& config_;
int re_paint_{0};
bool silence_{false};
bool silence_prev_{false};
@@ -66,9 +73,12 @@ class CavaBackend final {
void execute();
bool isSilence();
void doUpdate(bool force = false);
+ void loadConfig();
+ void freeBackend();
// Signal
type_signal_update m_signal_update_;
+ type_signal_audio_raw_update m_signal_audio_raw_;
type_signal_silence m_signal_silence_;
};
} // namespace waybar::modules::cava
diff --git a/include/modules/cava/cava_frontend.hpp b/include/modules/cava/cava_frontend.hpp
new file mode 100644
index 00000000..402a9bad
--- /dev/null
+++ b/include/modules/cava/cava_frontend.hpp
@@ -0,0 +1,27 @@
+#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) {
+#ifdef HAVE_LIBCAVAGLSL
+ case ::cava::output_method::OUTPUT_SDL_GLSL:
+ return new waybar::modules::cava::CavaGLSL(id, config);
+#endif
+ default:
+ return new waybar::modules::cava::Cava(id, config);
+ }
+#else
+ throw std::runtime_error("Unknown module");
+#endif
+};
+} // namespace waybar::modules::cava
diff --git a/include/modules/dwl/tags.hpp b/include/modules/dwl/tags.hpp
index 53dff989..856a35dd 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&);
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 43586399..5efd0abb 100644
--- a/include/modules/dwl/window.hpp
+++ b/include/modules/dwl/window.hpp
@@ -13,26 +13,26 @@ 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&);
~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 686c7fc7..f21ff26e 100644
--- a/include/modules/ext/workspace_manager.hpp
+++ b/include/modules/ext/workspace_manager.hpp
@@ -20,16 +20,16 @@ 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);
~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 +38,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 +52,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 +64,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 b41f207c..20232970 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 69c0c3ae..f63861a3 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&);
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/hyprland/submap.hpp b/include/modules/hyprland/submap.hpp
index 7e3425ef..0dcb5d5a 100644
--- a/include/modules/hyprland/submap.hpp
+++ b/include/modules/hyprland/submap.hpp
@@ -26,6 +26,7 @@ class Submap : public waybar::ALabel, public EventHandler {
const Bar& bar_;
util::JsonParser parser_;
std::string submap_;
+ std::string prev_submap_;
bool always_on_ = false;
std::string default_submap_ = "Default";
diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp
index a5d94bbf..8bf88888 100644
--- a/include/modules/hyprland/workspaces.hpp
+++ b/include/modules/hyprland/workspaces.hpp
@@ -43,6 +43,7 @@ class Workspaces : public AModule, public EventHandler {
auto moveToMonitor() const -> bool { return m_moveToMonitor; }
auto enableTaskbar() const -> bool { return m_enableTaskbar; }
auto taskbarWithIcon() const -> bool { return m_taskbarWithIcon; }
+ auto barScroll() const -> bool { return m_barScroll; }
auto getBarOutput() const -> std::string { return m_bar.output->name; }
auto formatBefore() const -> std::string { return m_formatBefore; }
@@ -122,6 +123,8 @@ class Workspaces : public AModule, public EventHandler {
static std::pair splitDoublePayload(std::string const& payload);
static std::tuple splitTriplePayload(
std::string const& payload);
+ // scroll events
+ bool handleScroll(GdkEventScroll* e) override;
// Update methods
void doUpdate();
@@ -145,6 +148,7 @@ class Workspaces : public AModule, public EventHandler {
bool m_specialVisibleOnly = false;
bool m_persistentOnly = false;
bool m_moveToMonitor = false;
+ bool m_barScroll = false;
Json::Value m_persistentWorkspaceConfig;
// Map for windows stored in workspaces not present in the current bar.
diff --git a/include/modules/jack.hpp b/include/modules/jack.hpp
index 452c43a3..5c30739e 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&);
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 be90eee4..db7f2550 100644
--- a/include/modules/keyboard_state.hpp
+++ b/include/modules/keyboard_state.hpp
@@ -3,6 +3,7 @@
#include
#include
+#include
#include
#include
@@ -41,6 +42,7 @@ class KeyboardState : public AModule {
struct libinput* libinput_;
std::unordered_map libinput_devices_;
+ std::mutex devices_mutex_; // protects libinput_devices_
std::set binding_keys;
util::SleeperThread libinput_thread_, hotplug_thread_;
diff --git a/include/modules/niri/language.hpp b/include/modules/niri/language.hpp
index 77f0a624..cff2b352 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&);
~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 909ae6f0..6be4686e 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&);
~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 a6850ed1..08986412 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&);
~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 a2bd3858..b2436171 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&);
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 cb6a34da..68d2bf19 100644
--- a/include/modules/privacy/privacy.hpp
+++ b/include/modules/privacy/privacy.hpp
@@ -13,15 +13,15 @@ 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);
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 f5f572c0..31e200e3 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/river/layout.hpp b/include/modules/river/layout.hpp
index 89f0c7d9..3486472e 100644
--- a/include/modules/river/layout.hpp
+++ b/include/modules/river/layout.hpp
@@ -10,25 +10,25 @@ 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&);
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 246cecae..91585309 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&);
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 fd867346..386ddecf 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&);
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 bf29ebbf..0d759bb2 100644
--- a/include/modules/river/window.hpp
+++ b/include/modules/river/window.hpp
@@ -12,22 +12,22 @@ 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&);
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 3fe36fad..43c84f9e 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&);
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/watcher.hpp b/include/modules/sni/watcher.hpp
index 5cb0f19e..49d2dae5 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 a9a3e4e9..c5178c2b 100644
--- a/include/modules/sway/ipc/client.hpp
+++ b/include/modules/sway/ipc/client.hpp
@@ -13,6 +13,7 @@
#include "ipc.hpp"
#include "util/sleeper_thread.hpp"
+#include "util/SafeSignal.hpp"
namespace waybar::modules::sway {
@@ -27,21 +28,21 @@ class Ipc {
std::string payload;
};
- sigc::signal signal_event;
- sigc::signal signal_cmd;
+ ::waybar::SafeSignal signal_event;
+ ::waybar::SafeSignal 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/systemd_failed_units.hpp b/include/modules/systemd_failed_units.hpp
index 48b0074e..ffb25082 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&);
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/upower.hpp b/include/modules/upower.hpp
index 60a276db..0d445047 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&);
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/wlr/taskbar.hpp b/include/modules/wlr/taskbar.hpp
index 8dc4dadd..413eae85 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,12 @@ 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&);
~Taskbar();
void update();
private:
- const waybar::Bar &bar_;
+ const waybar::Bar& bar_;
Gtk::Box box_;
std::vector tasks_;
@@ -155,30 +155,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 eb42d3cc..ba3ccca7 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 73fa5415..48123549 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 4b9decaa..89d4372a 100644
--- a/include/util/command.hpp
+++ b/include/util/command.hpp
@@ -109,7 +109,7 @@ inline FILE* open(const std::string& cmd, int& pid, const std::string& output_na
::close(fd[0]);
dup2(fd[1], 1);
setpgid(child_pid, child_pid);
- if (output_name != "") {
+ if (!output_name.empty()) {
setenv("WAYBAR_OUTPUT_NAME", output_name.c_str(), 1);
}
execlp("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0);
@@ -138,7 +138,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, const std::string& output_name) {
if (cmd == "") return -1;
pid_t pid = fork();
@@ -157,6 +157,9 @@ inline int32_t forkExec(const std::string& cmd) {
err = pthread_sigmask(SIG_UNBLOCK, &mask, nullptr);
if (err != 0) spdlog::error("pthread_sigmask in forkExec failed: {}", strerror(err));
setpgid(pid, pid);
+ if (!output_name.empty()) {
+ setenv("WAYBAR_OUTPUT_NAME", output_name.c_str(), 1);
+ }
execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0);
exit(0);
} else {
@@ -169,4 +172,6 @@ inline int32_t forkExec(const std::string& cmd) {
return pid;
}
+inline int32_t forkExec(const std::string& cmd) { return forkExec(cmd, ""); }
+
} // namespace waybar::util::command
diff --git a/include/util/icon_loader.hpp b/include/util/icon_loader.hpp
index 664e510c..f9256eb5 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/json.hpp b/include/util/json.hpp
index f0736f9b..5f756f35 100644
--- a/include/util/json.hpp
+++ b/include/util/json.hpp
@@ -30,15 +30,16 @@ class JsonParser {
std::istringstream jsonStream(modifiedJsonStr);
std::string errs;
- if (!Json::parseFromStream(m_readerBuilder, jsonStream, &root, &errs)) {
+ // Use local CharReaderBuilder for thread safety - the IPC singleton's
+ // parser can be called concurrently from multiple module threads
+ Json::CharReaderBuilder readerBuilder;
+ if (!Json::parseFromStream(readerBuilder, jsonStream, &root, &errs)) {
throw std::runtime_error("Error parsing JSON: " + errs);
}
return root;
}
private:
- Json::CharReaderBuilder m_readerBuilder;
-
static std::string replaceHexadecimalEscape(const std::string& str) {
static std::regex re("\\\\x");
return std::regex_replace(str, re, "\\u00");
diff --git a/include/util/pipewire/privacy_node_info.hpp b/include/util/pipewire/privacy_node_info.hpp
index 54da7d16..54acad42 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/udev_deleter.hpp b/include/util/udev_deleter.hpp
new file mode 100644
index 00000000..77493c4a
--- /dev/null
+++ b/include/util/udev_deleter.hpp
@@ -0,0 +1,21 @@
+#pragma once
+
+#include
+
+namespace waybar::util {
+struct UdevDeleter {
+ void operator()(udev* ptr) const { udev_unref(ptr); }
+};
+
+struct UdevDeviceDeleter {
+ void operator()(udev_device* ptr) const { udev_device_unref(ptr); }
+};
+
+struct UdevEnumerateDeleter {
+ void operator()(udev_enumerate* ptr) const { udev_enumerate_unref(ptr); }
+};
+
+struct UdevMonitorDeleter {
+ void operator()(udev_monitor* ptr) const { udev_monitor_unref(ptr); }
+};
+} // namespace waybar::util
\ No newline at end of file
diff --git a/include/util/ustring_clen.hpp b/include/util/ustring_clen.hpp
index cddd2e1a..63311d53 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/man/waybar-battery.5.scd b/man/waybar-battery.5.scd
index 2819aa68..42b9e046 100644
--- a/man/waybar-battery.5.scd
+++ b/man/waybar-battery.5.scd
@@ -91,6 +91,11 @@ The *battery* module displays the current capacity and state (eg. charging) of y
typeof: string ++
Command to execute when scrolling up on the module.
+*weighted-average*: ++
+ typeof: bool ++
+ default: true ++
+ Option to combine multiple batteries with different capacities.
+
*on-scroll-down*: ++
typeof: string ++
Command to execute when scrolling down on the module.
@@ -175,8 +180,9 @@ The *battery* module allows one to define custom formats based on up to two fact
Every entry in the *events* object consists of a *