kdeui: raise and activate KMessageBox and queued KDialog windows

this is mostly for status notifier dialogs, if the dialogs are not raised
and activated they will block (because QDialog::exec() is called) and
manual activation has to be done (via alt+tab)

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-12 02:02:58 +03:00
parent 37f9ea4dba
commit b3b190e6ae
4 changed files with 20 additions and 10 deletions

View file

@ -44,6 +44,7 @@
#include <kstandardguiitem.h>
#include <ktoolinvocation.h>
#include <kurllabel.h>
#include <kwindowsystem.h>
#ifdef Q_WS_X11
#include <qx11info_x11.h>
@ -1108,6 +1109,9 @@ void KDialogQueue::Private::slotShowQueuedDialog()
} while(!dialog);
busy = true;
dialog->show();
KWindowSystem::raiseWindow(dialog->winId());
KWindowSystem::forceActiveWindow(dialog->winId());
dialog->exec();
busy = false;
delete dialog;

View file

@ -40,21 +40,20 @@
*/
class KDialogQueue : public QObject
{
Q_OBJECT
public:
Q_OBJECT
public:
static void queueDialog(QDialog *);
~KDialogQueue();
protected:
protected:
KDialogQueue();
static KDialogQueue *self();
private:
private:
Q_PRIVATE_SLOT(d, void slotShowQueuedDialog())
private:
private:
class Private;
friend class Private;
Private* const d;

View file

@ -31,6 +31,7 @@
#include "kwindowsystem.h"
#include <QtCore/QPointer>
#include <QtCore/QDebug>
#include <QtGui/QCheckBox>
#include <QtGui/QGroupBox>
#include <QtGui/QLabel>
@ -333,11 +334,17 @@ int KMessageBox::createKMessageBox(KDialog *dialog, const QIcon &icon,
return KMessageBox::Cancel; // We have to return something.
}
// We use a QPointer because the dialog may get deleted
// use a QPointer because the dialog may get deleted
// during exec() if the parent of the dialog gets deleted.
// In that case the QPointer will reset to 0.
QPointer<KDialog> guardedDialog = dialog;
// raise the dialog in case the parent is minimized (hidden), e.g. status
// status notifier item (kget)
guardedDialog->show();
KWindowSystem::raiseWindow(guardedDialog->winId());
KWindowSystem::forceActiveWindow(guardedDialog->winId());
const int result = guardedDialog->exec();
if (checkbox && checkboxReturn) {
*checkboxReturn = checkbox->isChecked();

View file

@ -22,13 +22,13 @@
#ifndef KMESSAGEBOX_H
#define KMESSAGEBOX_H
#include <QtGui/QMessageBox>
#include <QMessageBox>
#include <QWidget>
#include <QStringList>
#include <kguiitem.h>
#include <kstandardguiitem.h>
#include <QWidget>
#include <QStringList>
class KConfig;
class KDialog;