From 587bd0cd628a3cc5c7a333acdba31a5503d1e2d4 Mon Sep 17 00:00:00 2001 From: Austin Horstman Date: Fri, 8 Sep 2023 22:24:05 -0500 Subject: [PATCH] refactor: cleanup hyprland workspaces constructor --- include/modules/hyprland/workspaces.hpp | 2 ++ src/modules/hyprland/workspaces.cpp | 27 +++++++++++++++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/modules/hyprland/workspaces.hpp b/include/modules/hyprland/workspaces.hpp index 270c1e36..93faf494 100644 --- a/include/modules/hyprland/workspaces.hpp +++ b/include/modules/hyprland/workspaces.hpp @@ -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; diff --git a/src/modules/hyprland/workspaces.cpp b/src/modules/hyprland/workspaces.cpp index 82442d53..504a6caa 100644 --- a/src/modules/hyprland/workspaces.cpp +++ b/src/modules/hyprland/workspaces.cpp @@ -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(); } - init(); - gIPC->registerForIPC("workspace", this); gIPC->registerForIPC("createworkspace", this); gIPC->registerForIPC("destroyworkspace", this);