From 3916cdc78a827acf43a04215e835ec7bc77b5c76 Mon Sep 17 00:00:00 2001 From: Charliechen114514 <725610365@qq.com> Date: Wed, 1 Jul 2026 14:19:38 +0800 Subject: [PATCH] refactor(desktop): drop calculator builtin adapter, make desktop core app-free The desktop core held an in-process builtin adapter for calculator (CalculatorBuiltinPanel), making calculator the only user app with source inside the desktop layer -- a reverse desktop->apps coupling via CMake target_sources + include path + link. Externalize calculator to match the other four apps (noter/system_state/alarm_clock/calendar), which are already pure detached executables with zero code in desktop/. Changes: - Delete desktop/ui/components/builtin_apps/calculator_builtin_panel.{h,cpp} - CFDesktopEntity.cpp: drop the calculator builtin include and its construction/registration block (About registration kept intact) - builtin_apps/CMakeLists.txt: drop the calculator adapter source, the target_sources of apps/calculator/calculator_panel.cpp, the apps/calculator include dir, and the cfdesktop_calculator_parser link - apps/calculator/app.json: launch_kind auto -> detached (clean direct launch, no Auto-fallback log on low tier) - top-level CMakeLists.txt: refresh the stale apps-before-desktop comment (the parser-lib coupling it justified is gone) The builtin MECHANISM is fully preserved (IBuiltinPanel, BuiltinPanelRegistry, LaunchKind::BuiltinPanel, HardwareTier::prefer_inprocess_apps adjudication, About panel) for any future panel that needs in-process rendering. Only calculator's builtin adapter is retired. Verified: desktop exe, libCFDesktop_shared.so, and libcfdesktop_builtin_apps.a contain zero CalculatorPanel symbols; AboutPanel still present in the .so; parser_test 15/15 and builtin_panel_registry_test 5/5 pass; full build green. --- CMakeLists.txt | 7 +- apps/calculator/app.json | 2 +- desktop/ui/CFDesktopEntity.cpp | 4 - .../ui/components/builtin_apps/CMakeLists.txt | 20 ++-- .../builtin_apps/calculator_builtin_panel.cpp | 69 ----------- .../builtin_apps/calculator_builtin_panel.h | 113 ------------------ 6 files changed, 13 insertions(+), 202 deletions(-) delete mode 100644 desktop/ui/components/builtin_apps/calculator_builtin_panel.cpp delete mode 100644 desktop/ui/components/builtin_apps/calculator_builtin_panel.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 959724230..a375974e7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,9 +66,10 @@ setup_third_party( GIT_TAG v0.1.0) # Standalone desktop apps. Each ships a standalone executable launched via -# QProcess; the calculator parser lib (cfdesktop_calculator_parser) is also -# reused in-process by the desktop builtin_apps target, so apps must configure -# before desktop. +# QProcess. (Historically apps/ had to precede desktop because desktop reused +# the calculator parser lib defined here; that coupling has been removed -- the +# desktop core no longer reaches into apps/. apps/ now only needs to precede +# test/, which it does; the apps-before-desktop ordering below is convention.) log_module_start("apps") add_subdirectory(apps) log_module_end("apps") diff --git a/apps/calculator/app.json b/apps/calculator/app.json index c3ca60fbc..45a82c67b 100644 --- a/apps/calculator/app.json +++ b/apps/calculator/app.json @@ -2,5 +2,5 @@ "app_id": "calculator", "display_name": "Calculator", "exec": "calculator", - "launch_kind": "auto" + "launch_kind": "detached" } diff --git a/desktop/ui/CFDesktopEntity.cpp b/desktop/ui/CFDesktopEntity.cpp index ffc76537b..6f493bb19 100644 --- a/desktop/ui/CFDesktopEntity.cpp +++ b/desktop/ui/CFDesktopEntity.cpp @@ -12,7 +12,6 @@ #include "components/WindowManager.h" #include "components/builtin_apps/about_panel.h" #include "components/builtin_apps/builtin_panel_registry.h" -#include "components/builtin_apps/calculator_builtin_panel.h" #include "components/launcher/app_discoverer.h" #include "components/launcher/app_launch_service.h" #include "components/launcher/app_launcher.h" @@ -330,9 +329,6 @@ CFDesktopEntity::RunsSetupResult CFDesktopEntity::run_init(RunsSetupMethod m) { auto& builtin_registry = cf::desktop::desktop_component::BuiltinPanelRegistry::instance(); auto* about_panel = new cf::desktop::desktop_component::AboutPanel(desktop_entity_); builtin_registry.registerPanel(about_panel); - auto* calc_builtin = - new cf::desktop::desktop_component::CalculatorBuiltinPanel(desktop_entity_); - builtin_registry.registerPanel(calc_builtin); // Hardware tier decides whether Auto apps run in-process (Low tier) or // detached (Mid/High). setDeviceConfigOverride (env/tests) takes precedence. diff --git a/desktop/ui/components/builtin_apps/CMakeLists.txt b/desktop/ui/components/builtin_apps/CMakeLists.txt index af9035446..508f5506d 100644 --- a/desktop/ui/components/builtin_apps/CMakeLists.txt +++ b/desktop/ui/components/builtin_apps/CMakeLists.txt @@ -1,15 +1,17 @@ -# Builtin in-process apps (child widgets over the desktop, e.g. About). +# Builtin in-process panels (child widgets over the desktop, e.g. About). # These are NOT launched via QProcess; CFDesktop shows them directly, which # suits single-framebuffer targets (linuxfb) where an external GUI app would # fight the desktop for /dev/fb0. +# +# Note: user apps (calculator/noter/system_state/alarm_clock/calendar) are all +# standalone executables launched as detached processes — the +# desktop core holds no app source. This lib keeps only desktop-core builtin +# panels (About) + the generic registry. The builtin MECHANISM (IBuiltinPanel + +# BuiltinPanelRegistry + LaunchKind::BuiltinPanel + HardwareTier adjudication) +# stays available for any future panel that needs in-process rendering. add_library(cfdesktop_builtin_apps STATIC about_panel.cpp builtin_panel_registry.cpp - calculator_builtin_panel.cpp - # Architecture exception: compile the standalone Calculator's panel source - # into the builtin lib so the same panel runs in-process. The standalone - # executable (apps/calculator/) compiles its own copy independently. - ${CMAKE_SOURCE_DIR}/apps/calculator/calculator_panel.cpp ) target_include_directories(cfdesktop_builtin_apps PUBLIC @@ -17,15 +19,9 @@ target_include_directories(cfdesktop_builtin_apps PUBLIC $ ) -# calculator_panel.h lives under apps/calculator/. -target_include_directories(cfdesktop_builtin_apps PRIVATE - ${CMAKE_SOURCE_DIR}/apps/calculator -) - target_link_libraries(cfdesktop_builtin_apps PRIVATE Qt6::Core Qt6::Gui Qt6::Widgets - cfdesktop_calculator_parser QuarkWidgets::quarkwidgets cflogger # Diagnostic logging for the registry ) diff --git a/desktop/ui/components/builtin_apps/calculator_builtin_panel.cpp b/desktop/ui/components/builtin_apps/calculator_builtin_panel.cpp deleted file mode 100644 index 193161bad..000000000 --- a/desktop/ui/components/builtin_apps/calculator_builtin_panel.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/** - * @file calculator_builtin_panel.cpp - * @brief Implementation of CalculatorBuiltinPanel. - * - * @author Charliechen114514 (chengh1922@mails.jlu.edu.cn) - * @date 2026-07-01 - * @version 0.1 - * @since 0.20 - * @ingroup components - */ - -#include "calculator_builtin_panel.h" - -#include "calculator_panel.h" - -#include -#include -#include - -namespace cf::desktop::desktop_component { - -namespace { -/// Builtin calculator size (matches the standalone window default). -constexpr int kPanelWidth = 360; -constexpr int kPanelHeight = 520; -} // namespace - -CalculatorBuiltinPanel::CalculatorBuiltinPanel(QWidget* parent) : QWidget(parent), panel_(nullptr) { - setWindowFlags(Qt::FramelessWindowHint); - setAttribute(Qt::WA_TranslucentBackground); - setAttribute(Qt::WA_OpaquePaintEvent, false); - setAutoFillBackground(false); - - panel_ = new CalculatorPanel(this); - auto* layout = new QVBoxLayout(this); - layout->setContentsMargins(0, 0, 0, 0); - layout->addWidget(panel_); - hide(); // Hidden until popup(); Qt would otherwise auto-show this child. -} - -CalculatorBuiltinPanel::~CalculatorBuiltinPanel() = default; - -QString CalculatorBuiltinPanel::appId() const { - return QStringLiteral("calculator"); -} - -QString CalculatorBuiltinPanel::displayName() const { - return QStringLiteral("Calculator"); -} - -void CalculatorBuiltinPanel::popup(const QRect& available) { - QRect avail = available; - if (!avail.isValid() || avail.width() <= 0 || avail.height() <= 0) { - if (const auto* screen = QGuiApplication::primaryScreen()) { - avail = screen->availableGeometry(); - } - } - const int x = avail.center().x() - kPanelWidth / 2; - const int y = avail.center().y() - kPanelHeight / 2; - setGeometry(x, y, kPanelWidth, kPanelHeight); - show(); - raise(); -} - -void CalculatorBuiltinPanel::hidePanel() { - hide(); -} - -} // namespace cf::desktop::desktop_component diff --git a/desktop/ui/components/builtin_apps/calculator_builtin_panel.h b/desktop/ui/components/builtin_apps/calculator_builtin_panel.h deleted file mode 100644 index 96360d122..000000000 --- a/desktop/ui/components/builtin_apps/calculator_builtin_panel.h +++ /dev/null @@ -1,113 +0,0 @@ -/** - * @file calculator_builtin_panel.h - * @brief In-process builtin adapter for the Calculator app. - * - * Wraps the standalone CalculatorPanel (apps/calculator/) as an in-process - * IBuiltinPanel so the Calculator can run either detached (its own process - * via the apps/calculator executable) or in-process (this adapter, when the - * hardware tier prefers in-process apps to save RAM). The CalculatorPanel - * source is shared between both builds; only this adapter adds the builtin - * lifecycle (popup/hidePanel over the desktop). - * - * @note Architecture exception: desktop links the apps/calculator panel - * source. Tracked for migration to a neutral shared lib in - * milestone_05. - * - * @author Charliechen114514 (chengh1922@mails.jlu.edu.cn) - * @date 2026-07-01 - * @version 0.1 - * @since 0.20 - * @ingroup components - */ - -#pragma once - -#include "ibuiltin_panel.h" - -#include - -class QRect; - -namespace cf::desktop::desktop_component { - -class CalculatorPanel; // forward — full definition needed only in the .cpp - -/** - * @brief In-process builtin adapter wrapping the standalone CalculatorPanel. - * - * Holds a CalculatorPanel child and exposes it through IBuiltinPanel so the - * launcher grid can surface a "calculator" entry that renders in-process. - * - * @ingroup components - */ -class CalculatorBuiltinPanel final : public QWidget, public IBuiltinPanel { - public: - /** - * @brief Constructs the builtin Calculator adapter. - * - * @param[in] parent Owning widget (the desktop surface). - * - * @throws None - * @note Starts hidden; call popup() to show. - * @since 0.20 - * @ingroup components - */ - explicit CalculatorBuiltinPanel(QWidget* parent = nullptr); - - /** - * @brief Destructs the adapter. - * - * @throws None - * @since 0.20 - * @ingroup components - */ - ~CalculatorBuiltinPanel() override; - - /** - * @brief Returns the stable launcher app_id. - * - * @return The id "calculator". - * - * @throws None - * @since 0.20 - * @ingroup components - */ - QString appId() const override; - - /** - * @brief Returns the icon label. - * - * @return The display name "Calculator". - * - * @throws None - * @since 0.20 - * @ingroup components - */ - QString displayName() const override; - - /** - * @brief Sizes/centers the panel over the area and shows it. - * - * @param[in] available Free screen geometry (excludes docked panels). - * - * @throws None - * @note A null/empty rect centers on the primary screen. - * @since 0.20 - * @ingroup components - */ - void popup(const QRect& available) override; - - /** - * @brief Hides the panel. - * - * @throws None - * @since 0.20 - * @ingroup components - */ - void hidePanel() override; - - private: - CalculatorPanel* panel_; ///< The wrapped panel (Qt-child owned). -}; - -} // namespace cf::desktop::desktop_component