Skip to content

Commit

Permalink
feat: add module class to the root elements of the modules
Browse files Browse the repository at this point in the history
Previously, the only way to select all the module labels was with the
following kind of selector:
```css
.modules-left > widget > label,
.modules-center > widget > label,
.modules-right > widget > label {
    /* ... */
}
```
(and a matching block for the `box` containers).

Now, this can be expressed as
```css
label.module, box.module {
    /* ... */
}
```
  • Loading branch information
alebastr committed Feb 15, 2024
1 parent 2f555a6 commit d590d50
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 5 deletions.
2 changes: 2 additions & 0 deletions include/AModule.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ namespace waybar {

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

virtual ~AModule();
auto update() -> void override;
virtual auto refresh(int) -> void{};
Expand Down
1 change: 1 addition & 0 deletions src/ALabel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
if (!id.empty()) {
label_.get_style_context()->add_class(id);
}
label_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(label_);
if (config_["max-length"].isUInt()) {
label_.set_max_width_chars(config_["max-length"].asInt());
Expand Down
1 change: 1 addition & 0 deletions src/ASlider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ ASlider::ASlider(const Json::Value& config, const std::string& name, const std::
if (!id.empty()) {
scale_.get_style_context()->add_class(id);
}
scale_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(scale_);
scale_.signal_value_changed().connect(sigc::mem_fun(*this, &ASlider::onValueChanged));

Expand Down
12 changes: 7 additions & 5 deletions src/modules/custom.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,18 @@ auto waybar::modules::Custom::update() -> void {
}
}
}
auto classes = label_.get_style_context()->list_classes();
auto style = label_.get_style_context();
auto classes = style->list_classes();
for (auto const& c : classes) {
if (c == id_) continue;
label_.get_style_context()->remove_class(c);
style->remove_class(c);
}
for (auto const& c : class_) {
label_.get_style_context()->add_class(c);
style->add_class(c);
}
label_.get_style_context()->add_class("flat");
label_.get_style_context()->add_class("text-button");
style->add_class("flat");
style->add_class("text-button");
style->add_class(MODULE_CLASS);
event_box_.show();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/dwl/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);

// Default to 9 tags, cap at 32
Expand Down
1 change: 1 addition & 0 deletions src/modules/hyprland/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
if (!id.empty()) {
m_box.get_style_context()->add_class(id);
}
m_box.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(m_box);

if (!gIPC) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);

dp.emit();
Expand Down
1 change: 1 addition & 0 deletions src/modules/keyboard_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar&
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);
if (config_["device-path"].isString()) {
Expand Down
1 change: 1 addition & 0 deletions src/modules/river/tags.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);

// Default to 9 tags, cap at 32
Expand Down
1 change: 1 addition & 0 deletions src/modules/sni/tray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
if (config_["spacing"].isUInt()) {
box_.set_spacing(config_["spacing"].asUInt());
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/sway/workspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);
ipc_.subscribe(R"(["workspace"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
Expand Down
1 change: 1 addition & 0 deletions src/modules/wlr/taskbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Valu
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
box_.get_style_context()->add_class("empty");
event_box_.add(box_);

Expand Down
1 change: 1 addition & 0 deletions src/modules/wlr/workspace_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_);

add_registry_listener(this);
Expand Down

0 comments on commit d590d50

Please sign in to comment.