Skip to content

Commit

Permalink
fix: fix fail to kill linglong app
Browse files Browse the repository at this point in the history
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
  • Loading branch information
wangrong1069 committed Nov 29, 2024
1 parent 4adfbef commit 3efbc99
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
29 changes: 22 additions & 7 deletions deepin-system-monitor-main/gui/main_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
5 changes: 5 additions & 0 deletions deepin-system-monitor-main/gui/main_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ public Q_SLOTS:
*/
void popupSettingsDialog();

/**
* @brief onKillProcess
*/
void onKillProcess();

protected:
/**
* @brief Initialize ui components
Expand Down
4 changes: 2 additions & 2 deletions deepin-system-monitor-main/gui/process_page_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3efbc99

Please sign in to comment.