Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions include/AAppIconLabel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ namespace waybar {

class AAppIconLabel : public AIconLabel {
public:
AAppIconLabel(const Json::Value &config, const std::string &name, const std::string &id,
const std::string &format, uint16_t interval = 0, bool ellipsize = false,
bool enable_click = false, bool enable_scroll = false);
AAppIconLabel(const Json::Value& config, const std::string& name, const std::string& id,
const std::string& format, std::mutex& reap_mtx, std::list<pid_t>& reap,
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
bool enable_scroll = false);
virtual ~AAppIconLabel() = default;
auto update() -> void override;

protected:
void updateAppIconName(const std::string &app_identifier,
const std::string &alternative_app_identifier);
void updateAppIconName(const std::string& app_identifier,
const std::string& alternative_app_identifier);
void updateAppIcon();
unsigned app_icon_size_{24};
bool update_app_icon_{true};
Expand Down
7 changes: 4 additions & 3 deletions include/AIconLabel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ namespace waybar {

class AIconLabel : public ALabel {
public:
AIconLabel(const Json::Value &config, const std::string &name, const std::string &id,
const std::string &format, uint16_t interval = 0, bool ellipsize = false,
bool enable_click = false, bool enable_scroll = false);
AIconLabel(const Json::Value& config, const std::string& name, const std::string& id,
const std::string& format, std::mutex& reap_mtx, std::list<pid_t>& reap,
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
bool enable_scroll = false);
virtual ~AIconLabel() = default;
auto update() -> void override;

Expand Down
16 changes: 8 additions & 8 deletions include/ALabel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ namespace waybar {

class ALabel : public AModule {
public:
ALabel(const Json::Value &, const std::string &, const std::string &, const std::string &format,
uint16_t interval = 0, bool ellipsize = false, bool enable_click = false,
bool enable_scroll = false);
ALabel(const Json::Value&, const std::string&, const std::string&, const std::string& format,
std::mutex& reap_mtx, std::list<pid_t>& reap, uint16_t interval = 0,
bool ellipsize = false, bool enable_click = false, bool enable_scroll = false);
virtual ~ALabel() = default;
auto update() -> void override;
virtual std::string getIcon(uint16_t, const std::string &alt = "", uint16_t max = 0);
virtual std::string getIcon(uint16_t, const std::vector<std::string> &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<std::string>& alts, uint16_t max = 0);

protected:
Gtk::Label label_;
Expand All @@ -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<std::string, GtkMenuItem *> submenus_;
std::map<std::string, GtkMenuItem*> submenus_;
std::map<std::string, std::string> menuActionsMap_;
static void handleGtkMenuEvent(GtkMenuItem *menuitem, gpointer data);
static void handleGtkMenuEvent(GtkMenuItem* menuitem, gpointer data);
};

} // namespace waybar
33 changes: 18 additions & 15 deletions include/AModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,46 +12,49 @@ namespace waybar {

class AModule : public IModule {
public:
static constexpr const char *MODULE_CLASS = "module";
static constexpr const char* MODULE_CLASS = "module";

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

/// Emitting on this dispatcher triggers a update() call
Glib::Dispatcher dp;

bool expandEnabled() const;

std::mutex& reap_mtx;
std::list<pid_t>& reap;

protected:
// Don't need to make an object directly
// Derived classes are able to use it
AModule(const Json::Value &, const std::string &, const std::string &, bool enable_click = false,
bool enable_scroll = false);
AModule(const Json::Value&, const std::string&, const std::string&, std::mutex& reap_mtx,
std::list<pid_t>& reap, bool enable_click = false, bool enable_scroll = false);

enum SCROLL_DIR { NONE, UP, DOWN, LEFT, RIGHT };

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

std::vector<int> 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_;
Expand Down
5 changes: 3 additions & 2 deletions include/ASlider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ namespace waybar {

class ASlider : public AModule {
public:
ASlider(const Json::Value& config, const std::string& name, const std::string& id);
ASlider(const Json::Value& config, const std::string& name, const std::string& id,
std::mutex& reap_mtx, std::list<pid_t>& reap);
virtual void onValueChanged();

protected:
Expand All @@ -16,4 +17,4 @@ class ASlider : public AModule {
Gtk::Scale scale_;
};

} // namespace waybar
} // namespace waybar
4 changes: 4 additions & 0 deletions include/IModule.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#pragma once

#include <gtkmm/widget.h>
#include <sys/types.h>

#include <list>
#include <mutex>

namespace waybar {

Expand Down
22 changes: 11 additions & 11 deletions include/bar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand All @@ -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();

Expand Down
36 changes: 18 additions & 18 deletions include/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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::Application> gtk_app;
Glib::RefPtr<Gdk::Display> 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<std::unique_ptr<Bar>> bars;
Config config;
std::string bar_id;

private:
Client() = default;
const std::string getStyle(const std::string &style, std::optional<Appearance> appearance);
const std::string getStyle(const std::string& style, std::optional<Appearance> appearance);
void bindInterfaces();
void handleOutput(struct waybar_output &output);
auto setupCss(const std::string &css_file) -> void;
struct waybar_output &getOutput(void *);
std::vector<Json::Value> getOutputConfigs(struct waybar_output &output);

static void handleGlobal(void *data, struct wl_registry *registry, uint32_t name,
const char *interface, uint32_t version);
static void handleGlobalRemove(void *data, struct wl_registry *registry, uint32_t name);
static void handleOutputDone(void *, struct zxdg_output_v1 *);
static void handleOutputName(void *, struct zxdg_output_v1 *, const char *);
static void handleOutputDescription(void *, struct zxdg_output_v1 *, const char *);
void handleOutput(struct waybar_output& output);
auto setupCss(const std::string& css_file) -> void;
struct waybar_output& getOutput(void*);
std::vector<Json::Value> getOutputConfigs(struct waybar_output& output);

static void handleGlobal(void* data, struct wl_registry* registry, uint32_t name,
const char* interface, uint32_t version);
static void handleGlobalRemove(void* data, struct wl_registry* registry, uint32_t name);
static void handleOutputDone(void*, struct zxdg_output_v1*);
static void handleOutputName(void*, struct zxdg_output_v1*, const char*);
static void handleOutputDescription(void*, struct zxdg_output_v1*, const char*);
void handleMonitorAdded(Glib::RefPtr<Gdk::Monitor> monitor);
void handleMonitorRemoved(Glib::RefPtr<Gdk::Monitor> monitor);
void handleDeferredMonitorRemoval(Glib::RefPtr<Gdk::Monitor> monitor);
Expand Down
22 changes: 11 additions & 11 deletions include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,29 @@ namespace waybar {
class Config {
public:
static const std::vector<std::string> 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<std::string> findConfigPath(
const std::vector<std::string> &names, const std::vector<std::string> &dirs = CONFIG_DIRS);
const std::vector<std::string>& names, const std::vector<std::string>& dirs = CONFIG_DIRS);

static std::vector<std::string> tryExpandPath(const std::string &base,
const std::string &filename);
static std::vector<std::string> 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<Json::Value> getOutputConfigs(const std::string &name, const std::string &identifier);
std::vector<Json::Value> 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<std::string> findIncludePath(
const std::string &name, const std::vector<std::string> &dirs = CONFIG_DIRS);
const std::string& name, const std::vector<std::string>& dirs = CONFIG_DIRS);

std::string config_file_;

Expand Down
1 change: 1 addition & 0 deletions include/factory.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <dlfcn.h>
#include <json/json.h>

#include <AModule.hpp>
Expand Down
14 changes: 7 additions & 7 deletions include/group.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
};
Expand Down
4 changes: 2 additions & 2 deletions include/modules/backlight.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ namespace waybar::modules {

class Backlight : public ALabel {
public:
Backlight(const std::string &, const Json::Value &);
Backlight(const std::string&, const Json::Value&, std::mutex&, std::list<pid_t>&);
virtual ~Backlight() = default;
auto update() -> void override;

bool handleScroll(GdkEventScroll *e) override;
bool handleScroll(GdkEventScroll* e) override;

const std::string preferred_device_;

Expand Down
4 changes: 2 additions & 2 deletions include/modules/backlight_slider.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace waybar::modules {

class BacklightSlider : public ASlider {
public:
BacklightSlider(const std::string&, const Json::Value&);
BacklightSlider(const std::string&, const Json::Value&, std::mutex&, std::list<pid_t>&);
virtual ~BacklightSlider() = default;

void update() override;
Expand All @@ -21,4 +21,4 @@ class BacklightSlider : public ASlider {
util::BacklightBackend backend;
};

} // namespace waybar::modules
} // namespace waybar::modules
3 changes: 2 additions & 1 deletion include/modules/battery.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ namespace fs = std::filesystem;

class Battery : public ALabel {
public:
Battery(const std::string&, const waybar::Bar&, const Json::Value&);
Battery(const std::string&, const waybar::Bar&, const Json::Value&, std::mutex&,
std::list<pid_t>&);
virtual ~Battery();
auto update() -> void override;

Expand Down
2 changes: 1 addition & 1 deletion include/modules/bluetooth.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Bluetooth : public ALabel {
};

public:
Bluetooth(const std::string&, const Json::Value&);
Bluetooth(const std::string&, const Json::Value&, std::mutex&, std::list<pid_t>&);
virtual ~Bluetooth() = default;
auto update() -> void override;

Expand Down
Loading