Skip to content

Commit

Permalink
refactor(group): made it better? (todo: fixup this commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
haug1 committed Apr 30, 2024
1 parent f679d30 commit 189a61a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
4 changes: 2 additions & 2 deletions include/factory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class Bar;
class Factory {
public:
Factory(const Bar& bar, const Json::Value& config);
AModule* addModule(const std::string& name, const std::string& pos);
std::shared_ptr<AModule> addModule(const std::string& name, const std::string& pos);
std::vector<std::shared_ptr<waybar::AModule>> modules_all_;

private:
const Bar& bar_;
const Json::Value& config_;
AModule* makeModule(const std::string& name, const std::string& pos, waybar::Factory& factory) const;
waybar::AModule* makeModule(const std::string& name, const std::string& pos, waybar::Factory& factory) const;
};

} // namespace waybar
11 changes: 5 additions & 6 deletions src/bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ void waybar::Bar::setupAltFormatKeyForModuleList(const char* module_list_name) {
}

void waybar::Bar::handleSignal(int signal) {
for (auto& module : factory_.modules_all_) {
for (const auto& module : factory_.modules_all_) {
module->refresh(signal);
}
}
Expand All @@ -477,16 +477,15 @@ void waybar::Bar::getModules(const std::string& pos) {
for (const auto& name : module_list) {
try {
auto ref = name.asString();
AModule* module = factory_.addModule(ref, pos);
std::shared_ptr<AModule> module_sp(module);
auto module = factory_.addModule(ref, pos);
if (pos == "modules-left") {
modules_left_.emplace_back(module_sp);
modules_left_.emplace_back(module);
}
if (pos == "modules-center") {
modules_center_.emplace_back(module_sp);
modules_center_.emplace_back(module);
}
if (pos == "modules-right") {
modules_right_.emplace_back(module_sp);
modules_right_.emplace_back(module);
}
module->dp.connect([module, ref] {
try {
Expand Down
7 changes: 4 additions & 3 deletions src/factory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "factory.hpp"
#include <memory>

#include "bar.hpp"
#include "gtkmm/enums.h"
Expand Down Expand Up @@ -114,9 +115,9 @@
waybar::Factory::Factory(const Bar& bar, const Json::Value& config) : bar_(bar), config_(config) {
}

waybar::AModule* waybar::Factory::addModule(const std::string& name,
const std::string& pos) {
auto *module = makeModule(name, pos, *this);
std::shared_ptr<waybar::AModule> waybar::Factory::addModule(const std::string& name,
const std::string& pos) {
auto module = std::make_shared<waybar::AModule>(makeModule(name, pos, *this));
modules_all_.emplace_back(module);
return module;
}
Expand Down
5 changes: 2 additions & 3 deletions src/group.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ Group::Group(const std::string& name, const std::string& id, const Json::Value&
for (const auto& name : module_list) {
try {
auto ref = name.asString();
AModule* module = factory.addModule(ref, pos);
std::shared_ptr<AModule> module_sp(module);
addWidget(*module_sp);
auto module = factory.addModule(ref, pos);
addWidget(*module);
module->dp.connect([module, ref] {
try {
module->update();
Expand Down

0 comments on commit 189a61a

Please sign in to comment.