MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / getWindowStates

Method getWindowStates

app/src/API/Handlers/WindowHandler.cpp:322–362  ·  view source on GitHub ↗

* @brief Return window states for all items in the taskbar buttons model. */

Source from the content-addressed store, hash-verified

320 * @brief Return window states for all items in the taskbar buttons model.
321 */
322API::CommandResponse API::Handlers::WindowHandler::getWindowStates(const QString& id,
323 const QJsonObject& params)
324{
325 Q_UNUSED(params)
326
327 auto* taskbar = UI::UISessionRegistry::instance().primaryTaskbar();
328 if (!taskbar)
329 return noSession(id);
330
331 auto* model = taskbar->fullModel();
332 QJsonArray states;
333
334 auto entryFor = [](const QStandardItem* item) {
335 QJsonObject entry;
336 entry[QStringLiteral("id")] = item->data(UI::TaskbarModel::WindowIdRole).toInt();
337 entry[QStringLiteral("state")] = item->data(UI::TaskbarModel::WindowStateRole).toInt();
338 entry[QStringLiteral("name")] = item->data(UI::TaskbarModel::WidgetNameRole).toString();
339 return entry;
340 };
341
342 for (int i = 0; i < model->rowCount(); ++i) {
343 const auto* top = model->item(i);
344 if (!top)
345 continue;
346
347 if (!top->data(UI::TaskbarModel::IsGroupRole).toBool()) {
348 states.append(entryFor(top));
349 continue;
350 }
351
352 for (int j = 0; j < top->rowCount(); ++j) {
353 const auto* child = top->child(j);
354 if (child)
355 states.append(entryFor(child));
356 }
357 }
358
359 QJsonObject result;
360 result[QStringLiteral("windows")] = states;
361 return CommandResponse::makeSuccess(id, result);
362}
363
364/**
365 * @brief Set the window state for a window by ID.

Callers

nothing calls this directly

Calls 6

noSessionFunction · 0.85
primaryTaskbarMethod · 0.80
fullModelMethod · 0.80
rowCountMethod · 0.80
dataMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected