MCPcopy Create free account
hub / github.com/Alexays/Waybar / Workspaces

Method Workspaces

src/modules/sway/workspaces.cpp:44–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44Workspaces::Workspaces(const std::string& id, const Bar& bar, const Json::Value& config)
45 : AModule(config, "workspaces", id, false, !config["disable-scroll"].asBool()),
46 bar_(bar),
47 box_(bar.orientation, 0) {
48 if (config["format-icons"]["high-priority-named"].isArray()) {
49 for (const auto& it : config["format-icons"]["high-priority-named"]) {
50 high_priority_named_.push_back(it.asString());
51 }
52 }
53 box_.set_name("workspaces");
54 if (!id.empty()) {
55 box_.get_style_context()->add_class(id);
56 }
57 box_.get_style_context()->add_class(MODULE_CLASS);
58 event_box_.add(box_);
59 if (config_["format-window-separator"].isString()) {
60 m_formatWindowSeparator = config_["format-window-separator"].asString();
61 } else {
62 m_formatWindowSeparator = " ";
63 }
64 const Json::Value& windowRewrite = config["window-rewrite"];
65 if (windowRewrite.isObject()) {
66 const Json::Value& windowRewriteDefaultConfig = config["window-rewrite-default"];
67 std::string windowRewriteDefault =
68 windowRewriteDefaultConfig.isString() ? windowRewriteDefaultConfig.asString() : "?";
69 m_windowRewriteRules = waybar::util::RegexCollection(
70 windowRewrite, std::move(windowRewriteDefault), windowRewritePriorityFunction);
71 }
72 ipc_.subscribe(R"(["workspace"])");
73 ipc_.subscribe(R"(["window"])");
74 ipc_.signal_event.connect(sigc::mem_fun(*this, &Workspaces::onEvent));
75 ipc_.signal_cmd.connect(sigc::mem_fun(*this, &Workspaces::onCmd));
76 ipc_.sendCmd(IPC_GET_TREE);
77 if (config["enable-bar-scroll"].asBool()) {
78 auto& window = const_cast<Bar&>(bar_).window;
79 window.add_events(Gdk::SCROLL_MASK | Gdk::SMOOTH_SCROLL_MASK);
80 window.signal_scroll_event().connect(sigc::mem_fun(*this, &Workspaces::handleScroll));
81 }
82 // Launch worker
83 ipc_.setWorker([this] {
84 try {
85 ipc_.handleEvent();
86 } catch (const std::exception& e) {
87 spdlog::error("Workspaces: {}", e.what());
88 }
89 });
90}
91
92void Workspaces::onEvent(const struct Ipc::ipc_response& res) {
93 try {

Callers

nothing calls this directly

Calls 7

RegexCollectionClass · 0.85
emptyMethod · 0.80
subscribeMethod · 0.80
connectMethod · 0.80
sendCmdMethod · 0.80
setWorkerMethod · 0.80
handleEventMethod · 0.45

Tested by

no test coverage detected