From 671c81c2d990f0e8e06139261e3d47d87eb15d71 Mon Sep 17 00:00:00 2001 From: yeshanshan Date: Mon, 23 Nov 2026 19:28:39 +0800 Subject: [PATCH] fix: use focused shutdown-menu actions for right-click menu items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Root cause: ShutdownApplet::requestShutdown Wayland branch mapped Shutdown/Restart/Suspend/Hibernate/Logout types all to shutdown() (action_shutdown_menu=24), always showing the generic menu instead of focusing the matching button via the focused variants (26-30) 2. Fix: add powerOff/reboot/suspend/hibernate/logout methods to TreeLandLockScreen calling trigger with enum 26-30, map each type to its corresponding method in requestShutdown 3. Impact: right-click menu items now directly focus the matching action button; left-click and X11 branch unaffected Influence: 1. Test right-click shutdown icon and select each menu item 2. Verify focused button matches the selected action 3. Test left-click still shows generic shutdown menu 4. Verify X11 session shutdown behavior unchanged fix: 右键关机菜单项直接触发对应操作而非总弹通用界面 1. 根因:ShutdownApplet::requestShutdown 的 Wayland 分支将 Shutdown/Restart/Suspend/Hibernate/Logout 全部映射到 shutdown() (action_shutdown_menu=24),总是弹出通用菜单而非通过 focused 变体(26-30)聚焦到对应按钮 2. 方案:在 TreeLandLockScreen 中新增 powerOff/reboot/suspend/ hibernate/logout 五个方法分别调用 trigger 枚举 26-30,在 requestShutdown 中将每种 type 映射到对应方法 3. 影响:右键菜单项现在直接聚焦到对应操作按钮;左键单击和 X11 分支不受影响 Influence: 1. 测试右键关机图标后选择各菜单项 2. 验证聚焦按钮与选择的操作一致 3. 测试左键单击仍弹出通用关机菜单 4. 验证 X11 会话关机行为无变化 Log: Right-click shutdown menu items now directly trigger focused actions PMS: BUG-381309 --- applets/dde-shutdown/shutdownapplet.cpp | 19 +++++++----- applets/dde-shutdown/treelandlockscreen.cpp | 34 +++++++++++++++++++++ applets/dde-shutdown/treelandlockscreen.h | 5 +++ 3 files changed, 51 insertions(+), 7 deletions(-) diff --git a/applets/dde-shutdown/shutdownapplet.cpp b/applets/dde-shutdown/shutdownapplet.cpp index 375d461d8..0f3c81703 100644 --- a/applets/dde-shutdown/shutdownapplet.cpp +++ b/applets/dde-shutdown/shutdownapplet.cpp @@ -1,4 +1,4 @@ -// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. +// SPDX-FileCopyrightText: 2024 - 2026 UnionTech Software Technology Co., Ltd. // // SPDX-License-Identifier: GPL-3.0-or-later @@ -48,16 +48,21 @@ bool ShutdownApplet::requestShutdown(const QString &type) // TODO: left mouse clicked, show shutdown page m_lockscreen->shutdown(); } else if (type == QStringLiteral("Shutdown")) { - m_lockscreen->shutdown(); + m_lockscreen->powerOff(); } else if (type == QStringLiteral("Lock")) { m_lockscreen->lock(); } else if (type == QStringLiteral("SwitchUser")) { m_lockscreen->switchUser(); - } else if (type == QStringLiteral("UpdateAndShutdown") || type == QStringLiteral("UpdateAndReboot") || - type == QStringLiteral("Suspend") || type == QStringLiteral("Hibernate") || - type == QStringLiteral("Restart") || type == QStringLiteral("Logout")) { - // TODO: implement these types - m_lockscreen->shutdown(); + } else if (type == QStringLiteral("Restart") || type == QStringLiteral("UpdateAndReboot")) { + m_lockscreen->reboot(); + } else if (type == QStringLiteral("Suspend")) { + m_lockscreen->suspend(); + } else if (type == QStringLiteral("Hibernate")) { + m_lockscreen->hibernate(); + } else if (type == QStringLiteral("Logout")) { + m_lockscreen->logout(); + } else if (type == QStringLiteral("UpdateAndShutdown")) { + m_lockscreen->powerOff(); } } else { if (type == QStringLiteral("Lock")) { diff --git a/applets/dde-shutdown/treelandlockscreen.cpp b/applets/dde-shutdown/treelandlockscreen.cpp index 2ea5a8e75..c9392bc9d 100644 --- a/applets/dde-shutdown/treelandlockscreen.cpp +++ b/applets/dde-shutdown/treelandlockscreen.cpp @@ -40,5 +40,39 @@ void TreeLandLockScreen::switchUser() trigger(action_show_user_switch); } } +void TreeLandLockScreen::powerOff() +{ + if (isActive()) { + trigger(action_shutdown_menu_power_off); + } +} + +void TreeLandLockScreen::reboot() +{ + if (isActive()) { + trigger(action_shutdown_menu_reboot); + } +} + +void TreeLandLockScreen::suspend() +{ + if (isActive()) { + trigger(action_shutdown_menu_suspend); + } +} + +void TreeLandLockScreen::hibernate() +{ + if (isActive()) { + trigger(action_shutdown_menu_hibernate); + } +} + +void TreeLandLockScreen::logout() +{ + if (isActive()) { + trigger(action_shutdown_menu_log_out); + } +} } DS_END_NAMESPACE diff --git a/applets/dde-shutdown/treelandlockscreen.h b/applets/dde-shutdown/treelandlockscreen.h index 1cd74cf35..12b190dec 100644 --- a/applets/dde-shutdown/treelandlockscreen.h +++ b/applets/dde-shutdown/treelandlockscreen.h @@ -22,6 +22,11 @@ class TreeLandLockScreen : public QWaylandClientExtensionTemplate