* @brief Pre-stashes saved geometries so registerWindow can apply them per-window before first * paint, avoiding the minimumSize flash. */
| 794 | * paint, avoiding the minimumSize flash. |
| 795 | */ |
| 796 | void UI::WindowManager::preloadPendingGeometries(const QJsonObject& layout) |
| 797 | { |
| 798 | m_pendingGeometries.clear(); |
| 799 | m_manualGeometries.clear(); |
| 800 | m_manualMargins.clear(); |
| 801 | if (layout.isEmpty() || !layout.contains("geometries")) |
| 802 | return; |
| 803 | |
| 804 | if (layout["autoLayout"].toBool(true)) |
| 805 | return; |
| 806 | |
| 807 | const int savedCanvasW = layout["canvasWidth"].toInt(0); |
| 808 | const int savedCanvasH = layout["canvasHeight"].toInt(0); |
| 809 | const int canvasW = static_cast<int>(width()); |
| 810 | const int canvasH = static_cast<int>(height()); |
| 811 | const int marginCanvasW = savedCanvasW > 0 ? savedCanvasW : canvasW; |
| 812 | const int marginCanvasH = savedCanvasH > 0 ? savedCanvasH : canvasH; |
| 813 | m_manualCanvasWidth = marginCanvasW; |
| 814 | m_manualCanvasHeight = marginCanvasH; |
| 815 | |
| 816 | const QHash<StableKey, int> stableLookup = buildStableKeyToWindowId(); |
| 817 | |
| 818 | const QJsonArray geometries = layout["geometries"].toArray(); |
| 819 | for (const auto& val : std::as_const(geometries)) { |
| 820 | const QJsonObject winGeom = val.toObject(); |
| 821 | const int id = resolveSavedWindowId(winGeom, stableLookup, m_windows); |
| 822 | if (id < 0) |
| 823 | continue; |
| 824 | |
| 825 | const int x = static_cast<int>(SerialStudio::toDouble(winGeom["x"], 0.0)); |
| 826 | const int y = static_cast<int>(SerialStudio::toDouble(winGeom["y"], 0.0)); |
| 827 | const int w = static_cast<int>(SerialStudio::toDouble(winGeom["width"], 200.0)); |
| 828 | const int h = static_cast<int>(SerialStudio::toDouble(winGeom["height"], 150.0)); |
| 829 | const QRect geom(x, y, w, h); |
| 830 | const QMargins margins = manualMarginsForGeometry(geom, marginCanvasW, marginCanvasH); |
| 831 | const QRect anchored = anchoredGeometry(geom, margins, canvasW, canvasH); |
| 832 | |
| 833 | m_manualGeometries.insert(id, geom); |
| 834 | m_manualMargins.insert(id, margins); |
| 835 | m_pendingGeometries.insert(id, anchored); |
| 836 | } |
| 837 | } |
| 838 | |
| 839 | /** |
| 840 | * @brief Reconciles m_windowOrder against the authoritative taskbar order. |
no test coverage detected