refactor: cleanup hyprland workspaces constructor

This commit is contained in:
Austin Horstman 2023-09-08 22:24:05 -05:00
parent 309edd0585
commit 587bd0cd62
No known key found for this signature in database
2 changed files with 23 additions and 6 deletions

View File

@ -80,6 +80,8 @@ class Workspaces : public AModule, public EventHandler {
void create_workspace(Json::Value& value);
void remove_workspace(std::string name);
void set_urgent_workspace(std::string windowaddress);
void parse_config(const Json::Value& config);
void register_ipc();
bool all_outputs_ = false;
bool show_special_ = false;

View File

@ -14,6 +14,20 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
: AModule(config, "workspaces", id, false, false),
bar_(bar),
box_(bar.vertical ? Gtk::ORIENTATION_VERTICAL : Gtk::ORIENTATION_HORIZONTAL, 0) {
parse_config(config);
box_.set_name("workspaces");
if (!id.empty()) {
box_.get_style_context()->add_class(id);
}
event_box_.add(box_);
register_ipc();
init();
}
auto Workspaces::parse_config(const Json::Value &config) -> void {
Json::Value config_format = config["format"];
format_ = config_format.isString() ? config_format.asString() : "{name}";
@ -43,18 +57,19 @@ Workspaces::Workspaces(const std::string &id, const Bar &bar, const Json::Value
active_only_ = config_active_only.asBool();
}
box_.set_name("workspaces");
if (!id.empty()) {
box_.get_style_context()->add_class(id);
auto config_sort_by = config_["sort-by"];
if (config_sort_by.isString()) {
sort_by = config_sort_by.asString();
}
event_box_.add(box_);
}
auto Workspaces::register_ipc() -> void {
modulesReady = true;
if (!gIPC) {
gIPC = std::make_unique<IPC>();
}
init();
gIPC->registerForIPC("workspace", this);
gIPC->registerForIPC("createworkspace", this);
gIPC->registerForIPC("destroyworkspace", this);