From 3efbc99a7845b4876844dc4e066524aff9b8bfec Mon Sep 17 00:00:00 2001 From: rong wang Date: Fri, 29 Nov 2024 16:43:05 +0800 Subject: [PATCH] fix: fix fail to kill linglong app Previously, when killing an application, system-monitor needed to obtain the pid of the app. However, on a desktop environment using X11, system-monitor obtained an inaccurate pid of the linglong app, which resulted in failure to kill the app or accidental killing. Now consider using the window manager to kill the application, because the window manager contains detailed information about the application window. Log: fix fail to kill linglong app Bug: https://pms.uniontech.com/bug-view-283189.html --- .../gui/main_window.cpp | 29 ++++++++++++++----- deepin-system-monitor-main/gui/main_window.h | 5 ++++ .../gui/process_page_widget.cpp | 4 +-- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/deepin-system-monitor-main/gui/main_window.cpp b/deepin-system-monitor-main/gui/main_window.cpp index 022f8d5e..5235576c 100644 --- a/deepin-system-monitor-main/gui/main_window.cpp +++ b/deepin-system-monitor-main/gui/main_window.cpp @@ -110,12 +110,15 @@ void MainWindow::initUI() // adjust toolbar tab order setTabOrder(titlebar(), m_toolbar); - // kill process menu item - QAction *killAction = new QAction(DApplication::translate("Title.Bar.Context.Menu", "Force end application"), menu); - // control + alt + k - killAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_K)); - // emit process kill requested signal if kill process menu item triggered - connect(killAction, &QAction::triggered, this, [=]() { Q_EMIT killProcessPerformed(); }); + if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.KWin"))) { + // kill process menu item + QAction *killAction = new QAction(DApplication::translate("Title.Bar.Context.Menu", "Force end application"), menu); + // control + alt + k + killAction->setShortcut(QKeySequence(Qt::CTRL + Qt::ALT + Qt::Key_K)); + // emit process kill requested signal if kill process menu item triggered + connect(killAction, &QAction::triggered, this, [=]() { Q_EMIT killProcessPerformed(); }); + menu->addAction(killAction); + } // display mode menu item DMenu *modeMenu = new DMenu(DApplication::translate("Title.Bar.Context.Menu", "View"), menu); @@ -155,7 +158,6 @@ void MainWindow::initUI() QAction *settingAction(new QAction(tr("Settings"), this)); connect(settingAction, &QAction::triggered, this, &MainWindow::popupSettingsDialog); - menu->addAction(killAction); menu->addSeparator(); menu->addMenu(modeMenu); @@ -249,6 +251,8 @@ void MainWindow::initConnections() connect(&DetailWidgetManager::getInstance(), &DetailWidgetManager::sigJumpToProcessWidget, this, &MainWindow::onDetailInfoByDbus, Qt::QueuedConnection); connect(&DetailWidgetManager::getInstance(), &DetailWidgetManager::sigJumpToDetailWidget, this, &MainWindow::onDetailInfoByDbus, Qt::QueuedConnection); + + connect(this, &MainWindow::killProcessPerformed, this, &MainWindow::onKillProcess); } // resize event handler @@ -361,3 +365,14 @@ void MainWindow::popupSettingsDialog() // 销毁窗口 dialog->deleteLater(); } + +void MainWindow::onKillProcess() +{ + if (QDBusConnection::sessionBus().interface()->isServiceRegistered(QStringLiteral("org.kde.KWin"))) { + auto message = QDBusMessage::createMethodCall(QStringLiteral("org.kde.KWin"), + QStringLiteral("/KWin"), + QStringLiteral("org.kde.KWin"), + QStringLiteral("killWindow")); + QDBusConnection::sessionBus().asyncCall(message); + } +} diff --git a/deepin-system-monitor-main/gui/main_window.h b/deepin-system-monitor-main/gui/main_window.h index 0f499076..5bc49eca 100644 --- a/deepin-system-monitor-main/gui/main_window.h +++ b/deepin-system-monitor-main/gui/main_window.h @@ -85,6 +85,11 @@ public Q_SLOTS: */ void popupSettingsDialog(); + /** + * @brief onKillProcess + */ + void onKillProcess(); + protected: /** * @brief Initialize ui components diff --git a/deepin-system-monitor-main/gui/process_page_widget.cpp b/deepin-system-monitor-main/gui/process_page_widget.cpp index 2772156c..5ed578b5 100644 --- a/deepin-system-monitor-main/gui/process_page_widget.cpp +++ b/deepin-system-monitor-main/gui/process_page_widget.cpp @@ -270,8 +270,8 @@ void ProcessPageWidget::initConnections() { auto *mainWindow = gApp->mainWindow(); // kill application signal triggered, show application kill preview widget - connect(mainWindow, &MainWindow::killProcessPerformed, this, - &ProcessPageWidget::showWindowKiller); + // connect(mainWindow, &MainWindow::killProcessPerformed, this, + // &ProcessPageWidget::showWindowKiller); // switch display mode signal triggered, switch performance display mode connect(mainWindow, &MainWindow::displayModeChanged, this, &ProcessPageWidget::switchDisplayMode);