Merge pull request #2921 from alebastr/module-classes

Add `module` class to the root elements of the modules
This commit is contained in:
Alexis Rouillard 2024-02-16 13:34:50 +01:00 committed by GitHub
commit 3cd311819b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 134 additions and 77 deletions

View File

@ -11,6 +11,8 @@ namespace waybar {
class AModule : public IModule { class AModule : public IModule {
public: public:
static constexpr const char *MODULE_CLASS = "module";
virtual ~AModule(); virtual ~AModule();
auto update() -> void override; auto update() -> void override;
virtual auto refresh(int) -> void{}; virtual auto refresh(int) -> void{};

View File

@ -62,7 +62,7 @@ class BarSurface {
virtual void setLayer(bar_layer layer) = 0; virtual void setLayer(bar_layer layer) = 0;
virtual void setMargins(const struct bar_margins &margins) = 0; virtual void setMargins(const struct bar_margins &margins) = 0;
virtual void setPassThrough(bool enable) = 0; virtual void setPassThrough(bool enable) = 0;
virtual void setPosition(const std::string_view &position) = 0; virtual void setPosition(Gtk::PositionType position) = 0;
virtual void setSize(uint32_t width, uint32_t height) = 0; virtual void setSize(uint32_t width, uint32_t height) = 0;
virtual void commit(){}; virtual void commit(){};
@ -89,8 +89,9 @@ class Bar {
Json::Value config; Json::Value config;
struct wl_surface *surface; struct wl_surface *surface;
bool visible = true; bool visible = true;
bool vertical = false;
Gtk::Window window; Gtk::Window window;
Gtk::Orientation orientation = Gtk::ORIENTATION_HORIZONTAL;
Gtk::PositionType position = Gtk::POS_TOP;
int x_global; int x_global;
int y_global; int y_global;

View File

@ -20,6 +20,7 @@ ALabel::ALabel(const Json::Value& config, const std::string& name, const std::st
if (!id.empty()) { if (!id.empty()) {
label_.get_style_context()->add_class(id); label_.get_style_context()->add_class(id);
} }
label_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(label_); event_box_.add(label_);
if (config_["max-length"].isUInt()) { if (config_["max-length"].isUInt()) {
label_.set_max_width_chars(config_["max-length"].asInt()); label_.set_max_width_chars(config_["max-length"].asInt());

View File

@ -13,6 +13,7 @@ ASlider::ASlider(const Json::Value& config, const std::string& name, const std::
if (!id.empty()) { if (!id.empty()) {
scale_.get_style_context()->add_class(id); scale_.get_style_context()->add_class(id);
} }
scale_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(scale_); event_box_.add(scale_);
scale_.signal_value_changed().connect(sigc::mem_fun(*this, &ASlider::onValueChanged)); scale_.signal_value_changed().connect(sigc::mem_fun(*this, &ASlider::onValueChanged));

View File

@ -93,6 +93,32 @@ void from_json(const Json::Value& j, bar_mode& m) {
} }
} }
/* Deserializer for enum Gtk::PositionType */
void from_json(const Json::Value& j, Gtk::PositionType& pos) {
if (j == "left") {
pos = Gtk::POS_LEFT;
} else if (j == "right") {
pos = Gtk::POS_RIGHT;
} else if (j == "top") {
pos = Gtk::POS_TOP;
} else if (j == "bottom") {
pos = Gtk::POS_BOTTOM;
}
}
Glib::ustring to_string(Gtk::PositionType pos) {
switch (pos) {
case Gtk::POS_LEFT:
return "left";
case Gtk::POS_RIGHT:
return "right";
case Gtk::POS_TOP:
return "top";
case Gtk::POS_BOTTOM:
return "bottom";
}
}
/* Deserializer for JSON Object -> map<string compatible type, Value> /* Deserializer for JSON Object -> map<string compatible type, Value>
* Assumes that all the values in the object are deserializable to the same type. * Assumes that all the values in the object are deserializable to the same type.
*/ */
@ -158,18 +184,26 @@ struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
} }
} }
void setPosition(const std::string_view& position) override { void setPosition(Gtk::PositionType position) override {
auto unanchored = GTK_LAYER_SHELL_EDGE_BOTTOM; auto unanchored = GTK_LAYER_SHELL_EDGE_BOTTOM;
vertical_ = false; orientation_ = Gtk::ORIENTATION_HORIZONTAL;
if (position == "bottom") { switch (position) {
unanchored = GTK_LAYER_SHELL_EDGE_TOP; case Gtk::POS_LEFT:
} else if (position == "left") { unanchored = GTK_LAYER_SHELL_EDGE_RIGHT;
unanchored = GTK_LAYER_SHELL_EDGE_RIGHT; orientation_ = Gtk::ORIENTATION_VERTICAL;
vertical_ = true; break;
} else if (position == "right") { case Gtk::POS_RIGHT:
vertical_ = true; unanchored = GTK_LAYER_SHELL_EDGE_LEFT;
unanchored = GTK_LAYER_SHELL_EDGE_LEFT; orientation_ = Gtk::ORIENTATION_VERTICAL;
} break;
case Gtk::POS_TOP:
unanchored = GTK_LAYER_SHELL_EDGE_BOTTOM;
break;
case Gtk::POS_BOTTOM:
unanchored = GTK_LAYER_SHELL_EDGE_TOP;
break;
};
for (auto edge : {GTK_LAYER_SHELL_EDGE_LEFT, GTK_LAYER_SHELL_EDGE_RIGHT, for (auto edge : {GTK_LAYER_SHELL_EDGE_LEFT, GTK_LAYER_SHELL_EDGE_RIGHT,
GTK_LAYER_SHELL_EDGE_TOP, GTK_LAYER_SHELL_EDGE_BOTTOM}) { GTK_LAYER_SHELL_EDGE_TOP, GTK_LAYER_SHELL_EDGE_BOTTOM}) {
gtk_layer_set_anchor(window_.gobj(), edge, unanchored != edge); gtk_layer_set_anchor(window_.gobj(), edge, unanchored != edge);
@ -178,10 +212,10 @@ struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
// Disable anchoring for other edges too if the width // Disable anchoring for other edges too if the width
// or the height has been set to a value other than 'auto' // or the height has been set to a value other than 'auto'
// otherwise the bar will use all space // otherwise the bar will use all space
if (vertical_ && height_ > 1) { if (orientation_ == Gtk::ORIENTATION_VERTICAL && height_ > 1) {
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_BOTTOM, false); gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_BOTTOM, false);
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_TOP, false); gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_TOP, false);
} else if (!vertical_ && width_ > 1) { } else if (orientation_ == Gtk::ORIENTATION_HORIZONTAL && width_ > 1) {
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_LEFT, false); gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_LEFT, false);
gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, false); gtk_layer_set_anchor(window_.gobj(), GTK_LAYER_SHELL_EDGE_RIGHT, false);
} }
@ -195,11 +229,11 @@ struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
private: private:
Gtk::Window& window_; Gtk::Window& window_;
Gtk::Orientation orientation_ = Gtk::ORIENTATION_HORIZONTAL;
std::string output_name_; std::string output_name_;
uint32_t width_; uint32_t width_;
uint32_t height_; uint32_t height_;
bool passthrough_ = false; bool passthrough_ = false;
bool vertical_ = false;
void onMap(GdkEventAny* ev) { setPassThrough(passthrough_); } void onMap(GdkEventAny* ev) { setPassThrough(passthrough_); }
@ -212,7 +246,7 @@ struct GLSSurfaceImpl : public BarSurface, public sigc::trackable {
* Note: forced resizing to a window smaller than required by GTK would not work with * Note: forced resizing to a window smaller than required by GTK would not work with
* gtk-layer-shell. * gtk-layer-shell.
*/ */
if (vertical_) { if (orientation_ == Gtk::ORIENTATION_VERTICAL) {
if (width_ > 1 && ev->width > static_cast<int>(width_)) { if (width_ > 1 && ev->width > static_cast<int>(width_)) {
spdlog::warn(MIN_WIDTH_MSG, width_, ev->width); spdlog::warn(MIN_WIDTH_MSG, width_, ev->width);
} }
@ -304,15 +338,21 @@ struct RawSurfaceImpl : public BarSurface, public sigc::trackable {
} }
} }
void setPosition(const std::string_view& position) override { void setPosition(Gtk::PositionType position) override {
anchor_ = HORIZONTAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP; switch (position) {
if (position == "bottom") { case Gtk::POS_LEFT:
anchor_ = HORIZONTAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM; anchor_ = VERTICAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT;
} else if (position == "left") { break;
anchor_ = VERTICAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT; case Gtk::POS_RIGHT:
} else if (position == "right") { anchor_ = VERTICAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
anchor_ = VERTICAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT; break;
} case Gtk::POS_TOP:
anchor_ = HORIZONTAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP;
break;
case Gtk::POS_BOTTOM:
anchor_ = HORIZONTAL_ANCHOR | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
break;
};
// updating already mapped window // updating already mapped window
if (layer_surface_) { if (layer_surface_) {
@ -493,17 +533,18 @@ waybar::Bar::Bar(struct waybar_output* w_output, const Json::Value& w_config)
window.set_decorated(false); window.set_decorated(false);
window.get_style_context()->add_class(output->name); window.get_style_context()->add_class(output->name);
window.get_style_context()->add_class(config["name"].asString()); window.get_style_context()->add_class(config["name"].asString());
window.get_style_context()->add_class(config["position"].asString());
auto position = config["position"].asString(); from_json(config["position"], position);
orientation = (position == Gtk::POS_LEFT || position == Gtk::POS_RIGHT)
? Gtk::ORIENTATION_VERTICAL
: Gtk::ORIENTATION_HORIZONTAL;
if (position == "right" || position == "left") { window.get_style_context()->add_class(to_string(position));
left_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0);
center_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0); left_ = Gtk::Box(orientation, 0);
right_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0); center_ = Gtk::Box(orientation, 0);
box_ = Gtk::Box(Gtk::ORIENTATION_VERTICAL, 0); right_ = Gtk::Box(orientation, 0);
vertical = true; box_ = Gtk::Box(orientation, 0);
}
left_.get_style_context()->add_class("modules-left"); left_.get_style_context()->add_class("modules-left");
center_.get_style_context()->add_class("modules-center"); center_.get_style_context()->add_class("modules-center");
@ -829,34 +870,38 @@ void waybar::Bar::onConfigure(GdkEventConfigure* ev) {
void waybar::Bar::configureGlobalOffset(int width, int height) { void waybar::Bar::configureGlobalOffset(int width, int height) {
auto monitor_geometry = *output->monitor->property_geometry().get_value().gobj(); auto monitor_geometry = *output->monitor->property_geometry().get_value().gobj();
auto position = config["position"].asString();
int x; int x;
int y; int y;
if (position == "bottom") { switch (position) {
if (width + margins_.left + margins_.right >= monitor_geometry.width) case Gtk::POS_BOTTOM:
if (width + margins_.left + margins_.right >= monitor_geometry.width)
x = margins_.left;
else
x = (monitor_geometry.width - width) / 2;
y = monitor_geometry.height - height - margins_.bottom;
break;
case Gtk::POS_LEFT:
x = margins_.left; x = margins_.left;
else if (height + margins_.top + margins_.bottom >= monitor_geometry.height)
x = (monitor_geometry.width - width) / 2; y = margins_.top;
y = monitor_geometry.height - height - margins_.bottom; else
} else if (position == "left") { y = (monitor_geometry.height - height) / 2;
x = margins_.left; break;
if (height + margins_.top + margins_.bottom >= monitor_geometry.height) case Gtk::POS_RIGHT:
x = monitor_geometry.width - width - margins_.right;
if (height + margins_.top + margins_.bottom >= monitor_geometry.height)
y = margins_.top;
else
y = (monitor_geometry.height - height) / 2;
break;
case Gtk::POS_TOP:
// position is top
if (width + margins_.left + margins_.right >= monitor_geometry.width)
x = margins_.left;
else
x = (monitor_geometry.width - width) / 2;
y = margins_.top; y = margins_.top;
else break;
y = (monitor_geometry.height - height) / 2;
} else if (position == "right") {
x = monitor_geometry.width - width - margins_.right;
if (height + margins_.top + margins_.bottom >= monitor_geometry.height)
y = margins_.top;
else
y = (monitor_geometry.height - height) / 2;
} else {
// position is top
if (width + margins_.left + margins_.right >= monitor_geometry.width)
x = margins_.left;
else
x = (monitor_geometry.width - width) / 2;
y = margins_.top;
} }
x_global = x + monitor_geometry.x; x_global = x + monitor_geometry.x;

View File

@ -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) { for (auto const& c : classes) {
if (c == id_) continue; if (c == id_) continue;
label_.get_style_context()->remove_class(c); style->remove_class(c);
} }
for (auto const& c : class_) { for (auto const& c : class_) {
label_.get_style_context()->add_class(c); style->add_class(c);
} }
label_.get_style_context()->add_class("flat"); style->add_class("flat");
label_.get_style_context()->add_class("text-button"); style->add_class("text-button");
style->add_class(MODULE_CLASS);
event_box_.show(); event_box_.show();
} }
} }

View File

@ -93,7 +93,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
status_manager_{nullptr}, status_manager_{nullptr},
seat_{nullptr}, seat_{nullptr},
bar_(bar), bar_(bar),
box_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0}, box_{bar.orientation, 0},
output_status_{nullptr} { output_status_{nullptr} {
struct wl_display *display = Client::inst()->wl_display; struct wl_display *display = Client::inst()->wl_display;
struct wl_registry *registry = wl_display_get_registry(display); struct wl_registry *registry = wl_display_get_registry(display);
@ -113,6 +113,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
// Default to 9 tags, cap at 32 // Default to 9 tags, cap at 32

View File

@ -34,9 +34,7 @@ int Workspaces::windowRewritePriorityFunction(std::string const &window_rule) {
} }
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
: AModule(config, "workspaces", id, false, false), : AModule(config, "workspaces", id, false, false), m_bar(bar), m_box(bar.orientation, 0) {
m_bar(bar),
m_box(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
modulesReady = true; modulesReady = true;
parseConfig(config); parseConfig(config);
@ -44,6 +42,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
if (!id.empty()) { if (!id.empty()) {
m_box.get_style_context()->add_class(id); m_box.get_style_context()->add_class(id);
} }
m_box.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(m_box); event_box_.add(m_box);
if (!gIPC) { if (!gIPC) {

View File

@ -7,6 +7,7 @@ waybar::modules::Image::Image(const std::string& id, const Json::Value& config)
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
dp.emit(); dp.emit();

View File

@ -81,7 +81,7 @@ auto supportsLockStates(const libevdev* dev) -> bool {
waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar, waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar& bar,
const Json::Value& config) const Json::Value& config)
: AModule(config, "keyboard-state", id, false, !config["disable-scroll"].asBool()), : AModule(config, "keyboard-state", id, false, !config["disable-scroll"].asBool()),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0), box_(bar.orientation, 0),
numlock_label_(""), numlock_label_(""),
capslock_label_(""), capslock_label_(""),
numlock_format_(config_["format"].isString() ? config_["format"].asString() numlock_format_(config_["format"].isString() ? config_["format"].asString()
@ -132,6 +132,7 @@ waybar::modules::KeyboardState::KeyboardState(const std::string& id, const Bar&
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
if (config_["device-path"].isString()) { if (config_["device-path"].isString()) {

View File

@ -87,7 +87,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
control_{nullptr}, control_{nullptr},
seat_{nullptr}, seat_{nullptr},
bar_(bar), bar_(bar),
box_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0}, box_{bar.orientation, 0},
output_status_{nullptr} { output_status_{nullptr} {
struct wl_display *display = Client::inst()->wl_display; struct wl_display *display = Client::inst()->wl_display;
struct wl_registry *registry = wl_display_get_registry(display); struct wl_registry *registry = wl_display_get_registry(display);
@ -111,6 +111,7 @@ Tags::Tags(const std::string &id, const waybar::Bar &bar, const Json::Value &con
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
// Default to 9 tags, cap at 32 // Default to 9 tags, cap at 32

View File

@ -6,7 +6,7 @@ namespace waybar::modules::SNI {
Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config) Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
: AModule(config, "tray", id), : AModule(config, "tray", id),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0), box_(bar.orientation, 0),
watcher_(SNI::Watcher::getInstance()), watcher_(SNI::Watcher::getInstance()),
host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1), host_(nb_hosts_, config, bar, std::bind(&Tray::onAdd, this, std::placeholders::_1),
std::bind(&Tray::onRemove, this, std::placeholders::_1)) { std::bind(&Tray::onRemove, this, std::placeholders::_1)) {
@ -15,6 +15,7 @@ Tray::Tray(const std::string& id, const Bar& bar, const Json::Value& config)
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
if (config_["spacing"].isUInt()) { if (config_["spacing"].isUInt()) {
box_.set_spacing(config_["spacing"].asUInt()); box_.set_spacing(config_["spacing"].asUInt());
} }

View File

@ -27,7 +27,7 @@ int Workspaces::convertWorkspaceNameToNum(std::string name) {
Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config) Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value &config)
: AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()), : AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()),
bar_(bar), bar_(bar),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) { box_(bar.orientation, 0) {
if (config["format-icons"]["high-priority-named"].isArray()) { if (config["format-icons"]["high-priority-named"].isArray()) {
for (auto &it : config["format-icons"]["high-priority-named"]) { for (auto &it : config["format-icons"]["high-priority-named"]) {
high_priority_named_.push_back(it.asString()); high_priority_named_.push_back(it.asString());
@ -37,6 +37,7 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
ipc_.subscribe(R"(["workspace"])"); ipc_.subscribe(R"(["workspace"])");
ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent)); ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));

View File

@ -277,7 +277,7 @@ Task::Task(const waybar::Bar &bar, const Json::Value &config, Taskbar *tbar,
handle_{tl_handle}, handle_{tl_handle},
seat_{seat}, seat_{seat},
id_{global_id++}, id_{global_id++},
content_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0} { content_{bar.orientation, 0} {
zwlr_foreign_toplevel_handle_v1_add_listener(handle_, &toplevel_handle_impl, this); zwlr_foreign_toplevel_handle_v1_add_listener(handle_, &toplevel_handle_impl, this);
button.set_relief(Gtk::RELIEF_NONE); button.set_relief(Gtk::RELIEF_NONE);
@ -730,13 +730,14 @@ static const wl_registry_listener registry_listener_impl = {.global = handle_glo
Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Value &config) Taskbar::Taskbar(const std::string &id, const waybar::Bar &bar, const Json::Value &config)
: waybar::AModule(config, "taskbar", id, false, false), : waybar::AModule(config, "taskbar", id, false, false),
bar_(bar), bar_(bar),
box_{bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0}, box_{bar.orientation, 0},
manager_{nullptr}, manager_{nullptr},
seat_{nullptr} { seat_{nullptr} {
box_.set_name("taskbar"); box_.set_name("taskbar");
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
box_.get_style_context()->add_class("empty"); box_.get_style_context()->add_class("empty");
event_box_.add(box_); event_box_.add(box_);

View File

@ -21,9 +21,7 @@ std::map<std::string, std::string> Workspace::icons_map_;
WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar, WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar,
const Json::Value &config) const Json::Value &config)
: waybar::AModule(config, "workspaces", id, false, false), : waybar::AModule(config, "workspaces", id, false, false), bar_(bar), box_(bar.orientation, 0) {
bar_(bar),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
auto config_sort_by_name = config_["sort-by-name"]; auto config_sort_by_name = config_["sort-by-name"];
if (config_sort_by_name.isBool()) { if (config_sort_by_name.isBool()) {
sort_by_name_ = config_sort_by_name.asBool(); sort_by_name_ = config_sort_by_name.asBool();
@ -54,6 +52,7 @@ WorkspaceManager::WorkspaceManager(const std::string &id, const waybar::Bar &bar
if (!id.empty()) { if (!id.empty()) {
box_.get_style_context()->add_class(id); box_.get_style_context()->add_class(id);
} }
box_.get_style_context()->add_class(MODULE_CLASS);
event_box_.add(box_); event_box_.add(box_);
add_registry_listener(this); add_registry_listener(this);