kdeui: do not ask top-level widgets for close twice

it could happen because after session management is done klauncher sends
SIGTERM to the programs (the session manager does not close the
applications)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-05-10 03:26:40 +03:00
parent 957f5be670
commit d79faf5d2e

View file

@ -84,6 +84,8 @@ static const int s_quit_signals[] = {
0
};
static QWidgetList s_asked;
static void quit_handler(int sig)
{
if (!qApp) {
@ -99,6 +101,10 @@ static void quit_handler(int sig)
if (!topwidget || !topwidget->isWindow() || !topwidget->inherits("QMainWindow")) {
continue;
}
if (s_asked.contains(topwidget)) {
kDebug() << "already asked" << topwidget;
continue;
}
kDebug() << "closing" << topwidget;
if (!topwidget->close()) {
kDebug() << "not quiting because a top-level window did not close";
@ -462,24 +468,18 @@ KConfig* KApplication::sessionConfig()
bool KApplication::saveSession()
{
foreach (KMainWindow *window, KMainWindow::memberList()) {
if (!window->testAttribute(Qt::WA_WState_Hidden)) {
QCloseEvent e;
QApplication::sendEvent(window, &e);
if (!e.isAccepted()) {
return false;
}
}
}
foreach (QWidget* widget, QApplication::topLevelWidgets()) {
if (!widget || widget->isHidden() || widget->inherits("QMainWindow")) {
s_asked.clear();
foreach (QWidget* topwidget, QApplication::topLevelWidgets()) {
if (!topwidget || !topwidget->isWindow() || !topwidget->inherits("QMainWindow")) {
continue;
}
QCloseEvent e;
QApplication::sendEvent(widget, &e);
QApplication::sendEvent(topwidget, &e);
if (!e.isAccepted()) {
s_asked.clear();
return false;
}
s_asked.append(topwidget);
}
d->session_save = true;