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

Method setWindowState

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

* @brief Set the window state for a window by ID. */

Source from the content-addressed store, hash-verified

365 * @brief Set the window state for a window by ID.
366 */
367API::CommandResponse API::Handlers::WindowHandler::setWindowState(const QString& id,
368 const QJsonObject& params)
369{
370 if (!params.contains(QStringLiteral("id")) || !params.contains(QStringLiteral("state"))) {
371 return CommandResponse::makeError(
372 id, ErrorCode::MissingParam, QStringLiteral("Missing required parameters: id, state"));
373 }
374
375 auto* taskbar = UI::UISessionRegistry::instance().primaryTaskbar();
376 if (!taskbar)
377 return noSession(id);
378
379 const int win_id = params.value(QStringLiteral("id")).toInt();
380 const int state_int = params.value(QStringLiteral("state")).toInt();
381
382 if (state_int < 0 || state_int > 2) {
383 return CommandResponse::makeError(
384 id,
385 ErrorCode::InvalidParam,
386 QStringLiteral("Invalid state: %1. Valid range: 0-2").arg(state_int));
387 }
388
389 const auto state = static_cast<UI::TaskbarModel::WindowState>(state_int);
390 QMetaObject::invokeMethod(taskbar,
391 [taskbar, win_id, state]() { taskbar->setWindowState(win_id, state); });
392
393 QJsonObject result;
394 result[QStringLiteral("id")] = win_id;
395 result[QStringLiteral("state")] = state_int;
396 return CommandResponse::makeSuccess(id, result);
397}
398
399//--------------------------------------------------------------------------------------------------
400// Layout operations

Callers

nothing calls this directly

Calls 4

noSessionFunction · 0.85
primaryTaskbarMethod · 0.80
containsMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected