* @brief Return window states for all items in the taskbar buttons model. */
| 320 | * @brief Return window states for all items in the taskbar buttons model. |
| 321 | */ |
| 322 | API::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. |