refactor: don't use a group's box directly in bar
This commit is contained in:
parent
a3774dc586
commit
bbb7fb0c82
|
@ -12,6 +12,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "AModule.hpp"
|
||||
#include "group.hpp"
|
||||
#include "xdg-output-unstable-v1-client-protocol.h"
|
||||
|
||||
namespace waybar {
|
||||
|
@ -101,7 +102,7 @@ class Bar {
|
|||
private:
|
||||
void onMap(GdkEventAny *);
|
||||
auto setupWidgets() -> void;
|
||||
void getModules(const Factory &, const std::string &, Gtk::Box *);
|
||||
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 &);
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include <json/json.h>
|
||||
|
||||
#include "AModule.hpp"
|
||||
#include "bar.hpp"
|
||||
#include "factory.hpp"
|
||||
|
||||
namespace waybar {
|
||||
|
||||
|
@ -16,6 +14,10 @@ class Group : public AModule {
|
|||
~Group() = default;
|
||||
auto update() -> void override;
|
||||
operator Gtk::Widget&() override;
|
||||
|
||||
virtual Gtk::Box& getBox();
|
||||
|
||||
protected:
|
||||
Gtk::Box box;
|
||||
};
|
||||
|
||||
|
|
17
src/bar.cpp
17
src/bar.cpp
|
@ -740,7 +740,7 @@ void waybar::Bar::handleSignal(int signal) {
|
|||
}
|
||||
|
||||
void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
||||
Gtk::Box* group = nullptr) {
|
||||
waybar::Group* group = nullptr) {
|
||||
auto module_list = group ? config[pos]["modules"] : config[pos];
|
||||
if (module_list.isArray()) {
|
||||
for (const auto& name : module_list) {
|
||||
|
@ -753,10 +753,17 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
|||
auto id_name = ref.substr(6, hash_pos - 6);
|
||||
auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : "";
|
||||
|
||||
auto parent = group ? group : &this->box_;
|
||||
auto vertical = parent->get_orientation() == Gtk::ORIENTATION_VERTICAL;
|
||||
// auto parent = group ? group : &this->box_;
|
||||
// auto vertical = parent->get_orientation() == Gtk::ORIENTATION_VERTICAL;
|
||||
|
||||
auto vertical = (
|
||||
group ?
|
||||
group->getBox().get_orientation() :
|
||||
box_.get_orientation()
|
||||
) == Gtk::ORIENTATION_VERTICAL;
|
||||
|
||||
auto group_module = new waybar::Group(id_name, class_name, config[ref], vertical);
|
||||
getModules(factory, ref, &group_module->box);
|
||||
getModules(factory, ref, group_module);
|
||||
module = group_module;
|
||||
} else {
|
||||
module = factory.makeModule(ref);
|
||||
|
@ -765,7 +772,7 @@ void waybar::Bar::getModules(const Factory& factory, const std::string& pos,
|
|||
std::shared_ptr<AModule> module_sp(module);
|
||||
modules_all_.emplace_back(module_sp);
|
||||
if (group) {
|
||||
group->pack_start(*module, false, false);
|
||||
group->getBox().pack_start(*module, false, false);
|
||||
} else {
|
||||
if (pos == "modules-left") {
|
||||
modules_left_.emplace_back(module_sp);
|
||||
|
|
|
@ -35,6 +35,8 @@ auto Group::update() -> void {
|
|||
// noop
|
||||
}
|
||||
|
||||
Group::operator Gtk::Widget&() { return box; }
|
||||
Gtk::Box& Group::getBox() { return box; }
|
||||
|
||||
Group::operator Gtk::Widget&() { return getBox(); }
|
||||
|
||||
} // namespace waybar
|
||||
|
|
Loading…
Reference in New Issue