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

Method loadPersistentWorkspacesFromConfig

src/modules/hyprland/workspaces.cpp:231–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

229}
230
231void Workspaces::loadPersistentWorkspacesFromConfig(Json::Value const& clientsJson) {
232 spdlog::info("Loading persistent workspaces from Waybar config");
233 const std::vector<std::string> keys = m_persistentWorkspaceConfig.getMemberNames();
234 std::vector<std::string> persistentWorkspacesToCreate;
235
236 const std::string currentMonitor = m_bar.output->name;
237 const bool monitorInConfig = std::ranges::find(keys, currentMonitor) != keys.end();
238 for (const std::string& key : keys) {
239 // only add if either:
240 // 1. key is the current monitor name
241 // 2. key is "*" and this monitor is not already defined in the config
242 bool canCreate = key == currentMonitor || (key == "*" && !monitorInConfig);
243 const Json::Value& value = m_persistentWorkspaceConfig[key];
244 spdlog::trace("Parsing persistent workspace config: {} => {}", key, value.toStyledString());
245
246 if (value.isInt()) {
247 // value is a number => create that many workspaces for this monitor
248 if (canCreate) {
249 int amount = value.asInt();
250 spdlog::debug("Creating {} persistent workspaces for monitor {}", amount, currentMonitor);
251 for (int i = 0; i < amount; i++) {
252 persistentWorkspacesToCreate.emplace_back(std::to_string((m_monitorId * amount) + i + 1));
253 }
254 }
255 } else if (value.isArray() && !value.empty()) {
256 // value is an array => create defined workspaces for this monitor
257 if (canCreate) {
258 for (const Json::Value& workspace : value) {
259 spdlog::debug("Creating workspace {} on monitor {}", workspace, currentMonitor);
260 persistentWorkspacesToCreate.emplace_back(workspace.asString());
261 }
262 } else {
263 // key is the workspace and value is array of monitors to create on
264 for (const Json::Value& monitor : value) {
265 if (monitor.isString() && monitor.asString() == currentMonitor) {
266 persistentWorkspacesToCreate.emplace_back(currentMonitor);
267 break;
268 }
269 }
270 }
271 } else {
272 // this workspace should be displayed on all monitors
273 persistentWorkspacesToCreate.emplace_back(key);
274 }
275 }
276
277 for (auto const& workspace : persistentWorkspacesToCreate) {
278 auto workspaceData = createMonitorWorkspaceData(workspace, m_bar.output->name);
279 workspaceData["persistent-config"] = true;
280 m_workspacesToCreate.emplace_back(workspaceData, clientsJson);
281 }
282}
283
284void Workspaces::loadPersistentWorkspacesFromWorkspaceRules(const Json::Value& clientsJson) {
285 spdlog::info("Loading persistent workspaces from Hyprland workspace rules");

Callers

nothing calls this directly

Calls 3

to_stringFunction · 0.85
emptyMethod · 0.80
endMethod · 0.45

Tested by

no test coverage detected