refactor: don't use a group's box directly in bar

pull/2574/head
Brenno Lemos 2023-10-14 13:08:44 -03:00
parent a3774dc586
commit bbb7fb0c82
4 changed files with 21 additions and 9 deletions

View File

@ -12,6 +12,7 @@
#include <vector> #include <vector>
#include "AModule.hpp" #include "AModule.hpp"
#include "group.hpp"
#include "xdg-output-unstable-v1-client-protocol.h" #include "xdg-output-unstable-v1-client-protocol.h"
namespace waybar { namespace waybar {
@ -101,7 +102,7 @@ class Bar {
private: private:
void onMap(GdkEventAny *); void onMap(GdkEventAny *);
auto setupWidgets() -> void; 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 setupAltFormatKeyForModule(const std::string &module_name);
void setupAltFormatKeyForModuleList(const char *module_list_name); void setupAltFormatKeyForModuleList(const char *module_list_name);
void setMode(const bar_mode &); void setMode(const bar_mode &);

View File

@ -5,8 +5,6 @@
#include <json/json.h> #include <json/json.h>
#include "AModule.hpp" #include "AModule.hpp"
#include "bar.hpp"
#include "factory.hpp"
namespace waybar { namespace waybar {
@ -16,6 +14,10 @@ class Group : public AModule {
~Group() = default; ~Group() = default;
auto update() -> void override; auto update() -> void override;
operator Gtk::Widget&() override; operator Gtk::Widget&() override;
virtual Gtk::Box& getBox();
protected:
Gtk::Box box; Gtk::Box box;
}; };

View File

@ -740,7 +740,7 @@ void waybar::Bar::handleSignal(int signal) {
} }
void waybar::Bar::getModules(const Factory& factory, const std::string& pos, 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]; auto module_list = group ? config[pos]["modules"] : config[pos];
if (module_list.isArray()) { if (module_list.isArray()) {
for (const auto& name : module_list) { 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 id_name = ref.substr(6, hash_pos - 6);
auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : ""; auto class_name = hash_pos != std::string::npos ? ref.substr(hash_pos + 1) : "";
auto parent = group ? group : &this->box_; // auto parent = group ? group : &this->box_;
auto vertical = parent->get_orientation() == Gtk::ORIENTATION_VERTICAL; // 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); 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; module = group_module;
} else { } else {
module = factory.makeModule(ref); 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); std::shared_ptr<AModule> module_sp(module);
modules_all_.emplace_back(module_sp); modules_all_.emplace_back(module_sp);
if (group) { if (group) {
group->pack_start(*module, false, false); group->getBox().pack_start(*module, false, false);
} else { } else {
if (pos == "modules-left") { if (pos == "modules-left") {
modules_left_.emplace_back(module_sp); modules_left_.emplace_back(module_sp);

View File

@ -35,6 +35,8 @@ auto Group::update() -> void {
// noop // noop
} }
Group::operator Gtk::Widget&() { return box; } Gtk::Box& Group::getBox() { return box; }
Group::operator Gtk::Widget&() { return getBox(); }
} // namespace waybar } // namespace waybar