diff --git a/krunner/view.cpp b/krunner/view.cpp index 6d491bbef..0b2215618 100644 --- a/krunner/view.cpp +++ b/krunner/view.cpp @@ -1,446 +1,445 @@ /* * Copyright 2014 Marco Martin * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #include "view.h" #include #include #include -#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "appadaptor.h" View::View(QWindow *) : PlasmaQuick::Dialog(), m_offset(.5), m_floating(false), m_plasmaShell(nullptr) { initWayland(); setClearBeforeRendering(true); setColor(QColor(Qt::transparent)); setFlags(Qt::FramelessWindowHint | Qt::WindowStaysOnTopHint); KCrash::setFlags(KCrash::AutoRestart); //used only by screen readers setTitle(i18n("KRunner")); m_config = KConfigGroup(KSharedConfig::openConfig(QStringLiteral("krunnerrc")), "General"); setFreeFloating(m_config.readEntry("FreeFloating", false)); reloadConfig(); new AppAdaptor(this); QDBusConnection::sessionBus().registerObject(QStringLiteral("/App"), this); QAction *a = new QAction(0); QObject::connect(a, &QAction::triggered, this, &View::displayOrHide); a->setText(i18n("Run Command")); a->setObjectName(QStringLiteral("run command")); a->setProperty("componentDisplayName", i18nc("Name for krunner shortcuts category", "Run Command")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << QKeySequence(Qt::ALT + Qt::Key_Space), KGlobalAccel::NoAutoloading); KGlobalAccel::self()->setShortcut(a, QList() << QKeySequence(Qt::ALT + Qt::Key_Space) << QKeySequence(Qt::ALT + Qt::Key_F2) << Qt::Key_Search); a = new QAction(0); QObject::connect(a, &QAction::triggered, this, &View::displayWithClipboardContents); a->setText(i18n("Run Command on clipboard contents")); a->setObjectName(QStringLiteral("run command on clipboard contents")); a->setProperty("componentDisplayName", i18nc("Name for krunner shortcuts category", "Run Command")); KGlobalAccel::self()->setDefaultShortcut(a, QList() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2)); KGlobalAccel::self()->setShortcut(a, QList() << QKeySequence(Qt::ALT+Qt::SHIFT+Qt::Key_F2)); m_qmlObj = new KDeclarative::QmlObject(this); m_qmlObj->setInitializationDelayed(true); connect(m_qmlObj, &KDeclarative::QmlObject::finished, this, &View::objectIncubated); KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); if (!packageName.isEmpty()) { package.setPath(packageName); } m_qmlObj->setSource(QUrl::fromLocalFile(package.filePath("runcommandmainscript"))); m_qmlObj->engine()->rootContext()->setContextProperty(QStringLiteral("runnerWindow"), this); m_qmlObj->completeInitialization(); auto screenRemoved = [this](QScreen* screen) { if (screen == this->screen()) { setScreen(qGuiApp->primaryScreen()); hide(); } }; auto screenAdded = [this](QScreen* screen) { connect(screen, &QScreen::geometryChanged, this, &View::screenGeometryChanged); screenGeometryChanged(); }; foreach(QScreen* s, QGuiApplication::screens()) screenAdded(s); connect(qGuiApp, &QGuiApplication::screenAdded, this, screenAdded); connect(qGuiApp, &QGuiApplication::screenRemoved, this, screenRemoved); connect(KWindowSystem::self(), &KWindowSystem::workAreaChanged, this, &View::resetScreenPos); connect(this, &View::visibleChanged, this, &View::resetScreenPos); KDirWatch::self()->addFile(m_config.name()); // Catch both, direct changes to the config file ... connect(KDirWatch::self(), &KDirWatch::dirty, this, &View::reloadConfig); connect(KDirWatch::self(), &KDirWatch::created, this, &View::reloadConfig); if (m_floating) { setLocation(Plasma::Types::Floating); } else { setLocation(Plasma::Types::TopEdge); } connect(qGuiApp, &QGuiApplication::focusWindowChanged, this, &View::slotFocusWindowChanged); } View::~View() { } void View::initWayland() { if (!KWindowSystem::isPlatformWayland()) { return; } using namespace KWayland::Client; auto connection = ConnectionThread::fromApplication(this); if (!connection) { return; } Registry *registry = new Registry(this); registry->create(connection); QObject::connect(registry, &Registry::interfacesAnnounced, this, [registry, this] { const auto interface = registry->interface(Registry::Interface::PlasmaShell); if (interface.name != 0) { m_plasmaShell = registry->createPlasmaShell(interface.name, interface.version, this); } } ); registry->setup(); connection->roundtrip(); } void View::objectIncubated() { connect(m_qmlObj->rootObject(), SIGNAL(widthChanged()), this, SLOT(resetScreenPos())); setMainItem(qobject_cast(m_qmlObj->rootObject())); } void View::slotFocusWindowChanged() { if (!QGuiApplication::focusWindow()) { setVisible(false); } } bool View::freeFloating() const { return m_floating; } void View::setFreeFloating(bool floating) { if (m_floating == floating) { return; } m_floating = floating; if (m_floating) { setLocation(Plasma::Types::Floating); } else { setLocation(Plasma::Types::TopEdge); } positionOnScreen(); } void View::reloadConfig() { m_config.config()->reparseConfiguration(); setFreeFloating(m_config.readEntry("FreeFloating", false)); const QStringList history = m_config.readEntry("history", QStringList()); if (m_history != history) { m_history = history; emit historyChanged(); } } bool View::event(QEvent *event) { // QXcbWindow overwrites the state in its show event. There are plans // to fix this in 5.4, but till then we must explicitly overwrite it // each time. const bool retval = Dialog::event(event); bool setState = event->type() == QEvent::Show; if (event->type() == QEvent::PlatformSurface) { setState = (static_cast(event)->surfaceEventType() == QPlatformSurfaceEvent::SurfaceCreated); } if (setState) { KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager); } if (m_plasmaShell && event->type() == QEvent::Expose) { using namespace KWayland::Client; auto ee = static_cast(event); if (ee->region().isNull()) { return retval; } if (!m_plasmaShellSurface && isVisible()) { Surface *s = Surface::fromWindow(this); if (!s) { return retval; } m_plasmaShellSurface = m_plasmaShell->createSurface(s, this); m_plasmaShellSurface->setPanelBehavior(PlasmaShellSurface::PanelBehavior::WindowsGoBelow); m_plasmaShellSurface->setPanelTakesFocus(true); m_plasmaShellSurface->setRole(PlasmaShellSurface::Role::Panel); //this should be on showEvent, but it was too soon so none of those had any effect KWindowSystem::setOnAllDesktops(winId(), true); positionOnScreen(); requestActivate(); //positionOnScreen tried to position it in the position it already had, so no moveevent happens and we need to manually posiyion the surface m_plasmaShellSurface->setPosition(position()); } } else if (event->type() == QEvent::Hide) { delete m_plasmaShellSurface; } else if (m_plasmaShellSurface && event->type() == QEvent::Move) { QMoveEvent *me = static_cast(event); m_plasmaShellSurface->setPosition(me->pos()); } return retval; } void View::resizeEvent(QResizeEvent *event) { if (event->oldSize().width() != event->size().width()) { positionOnScreen(); } } void View::showEvent(QShowEvent *event) { KWindowSystem::setOnAllDesktops(winId(), true); Dialog::showEvent(event); positionOnScreen(); requestActivate(); } void View::screenGeometryChanged() { if (isVisible()) { positionOnScreen(); } } void View::resetScreenPos() { if (isVisible() && !m_floating) { positionOnScreen(); } } void View::positionOnScreen() { QScreen *shownOnScreen = QGuiApplication::primaryScreen(); Q_FOREACH (QScreen* screen, QGuiApplication::screens()) { if (screen->geometry().contains(QCursor::pos(screen))) { shownOnScreen = screen; break; } } setScreen(shownOnScreen); const QRect r = shownOnScreen->availableGeometry(); if (m_floating && !m_customPos.isNull()) { int x = qBound(r.left(), m_customPos.x(), r.right() - width()); int y = qBound(r.top(), m_customPos.y(), r.bottom() - height()); setPosition(x, y); show(); return; } const int w = width(); int x = r.left() + (r.width() * m_offset) - (w / 2); int y = r.top(); if (m_floating) { y += r.height() / 3; } x = qBound(r.left(), x, r.right() - width()); y = qBound(r.top(), y, r.bottom() - height()); setPosition(x, y); if (m_floating) { KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); KWindowSystem::setType(winId(), NET::Normal); //Turn the sliding effect off KWindowEffects::slideWindow(winId(), KWindowEffects::NoEdge, 0); } else { KWindowSystem::setOnAllDesktops(winId(), true); KWindowEffects::slideWindow(winId(), KWindowEffects::TopEdge, 0); } KWindowSystem::forceActiveWindow(winId()); //qDebug() << "moving to" << m_screenPos[screen]; } void View::displayOrHide() { if (isVisible() && !QGuiApplication::focusWindow()) { KWindowSystem::forceActiveWindow(winId()); return; } setVisible(!isVisible()); } void View::display() { setVisible(true); } void View::displaySingleRunner(const QString &runnerName) { setVisible(true); m_qmlObj->rootObject()->setProperty("runner", runnerName); m_qmlObj->rootObject()->setProperty("query", QString()); } void View::displayWithClipboardContents() { setVisible(true); m_qmlObj->rootObject()->setProperty("runner", QString()); m_qmlObj->rootObject()->setProperty("query", QGuiApplication::clipboard()->text(QClipboard::Selection)); } void View::query(const QString &term) { setVisible(true); m_qmlObj->rootObject()->setProperty("runner", QString()); m_qmlObj->rootObject()->setProperty("query", term); } void View::querySingleRunner(const QString &runnerName, const QString &term) { setVisible(true); m_qmlObj->rootObject()->setProperty("runner", runnerName); m_qmlObj->rootObject()->setProperty("query", term); } void View::switchUser() { QDBusConnection::sessionBus().asyncCall( QDBusMessage::createMethodCall(QStringLiteral("org.kde.ksmserver"), QStringLiteral("/KSMServer"), QStringLiteral("org.kde.KSMServerInterface"), QStringLiteral("openSwitchUserDialog")) ); } void View::displayConfiguration() { QProcess::startDetached(QStringLiteral("kcmshell5"), QStringList() << QStringLiteral("plasmasearch")); } QStringList View::history() const { return m_history; } void View::addToHistory(const QString &item) { if (item == QLatin1String("SESSIONS")) { return; } if (!KAuthorized::authorize(QStringLiteral("lineedit_text_completion"))) { return; } m_history.removeOne(item); m_history.prepend(item); while (m_history.count() > 50) { // make configurable? m_history.removeLast(); } emit historyChanged(); writeHistory(); m_config.sync(); } void View::removeFromHistory(int index) { if (index < 0 || index >= m_history.count()) { return; } m_history.removeAt(index); emit historyChanged(); writeHistory(); } void View::writeHistory() { m_config.writeEntry("history", m_history); } diff --git a/ksmserver/shutdowndlg.cpp b/ksmserver/shutdowndlg.cpp index dc6178254..07f0c9d20 100644 --- a/ksmserver/shutdowndlg.cpp +++ b/ksmserver/shutdowndlg.cpp @@ -1,325 +1,324 @@ /***************************************************************** ksmserver - the KDE session management server Copyright 2000 Matthias Ettrich Copyright 2007 Urs Wolfer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************/ #include "shutdowndlg.h" #include "ksmserver_debug.h" #include -#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include Q_DECLARE_METATYPE(Solid::PowerManagement::SleepState) KSMShutdownDlg::KSMShutdownDlg( QWindow* parent, bool maysd, bool choose, KWorkSpace::ShutdownType sdtype, const QString& theme, KWayland::Client::PlasmaShell *plasmaShell) : QQuickView(parent), m_result(false), m_theme(theme), m_waylandPlasmaShell(plasmaShell) // this is a WType_Popup on purpose. Do not change that! Not // having a popup here has severe side effects. { // window stuff setClearBeforeRendering(true); setColor(QColor(Qt::transparent)); setResizeMode(QQuickView::SizeRootObjectToView); // Qt doesn't set this on unmanaged windows //FIXME: or does it? if (KWindowSystem::isPlatformX11()) { XChangeProperty( QX11Info::display(), winId(), XInternAtom( QX11Info::display(), "WM_WINDOW_ROLE", False ), XA_STRING, 8, PropModeReplace, (unsigned char *)"logoutdialog", strlen( "logoutdialog" )); XClassHint classHint; classHint.res_name = const_cast("ksmserver"); classHint.res_class = const_cast("ksmserver"); XSetClassHint(QX11Info::display(), winId(), &classHint); } //QQuickView *windowContainer = QQuickView::createWindowContainer(m_view, this); //windowContainer->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred); QQmlContext *context = rootContext(); context->setContextProperty(QStringLiteral("maysd"), maysd); context->setContextProperty(QStringLiteral("choose"), choose); context->setContextProperty(QStringLiteral("sdtype"), sdtype); QQmlPropertyMap *mapShutdownType = new QQmlPropertyMap(this); mapShutdownType->insert(QStringLiteral("ShutdownTypeDefault"), QVariant::fromValue(KWorkSpace::ShutdownTypeDefault)); mapShutdownType->insert(QStringLiteral("ShutdownTypeNone"), QVariant::fromValue(KWorkSpace::ShutdownTypeNone)); mapShutdownType->insert(QStringLiteral("ShutdownTypeReboot"), QVariant::fromValue(KWorkSpace::ShutdownTypeReboot)); mapShutdownType->insert(QStringLiteral("ShutdownTypeHalt"), QVariant::fromValue(KWorkSpace::ShutdownTypeHalt)); mapShutdownType->insert(QStringLiteral("ShutdownTypeLogout"), QVariant::fromValue(KWorkSpace::ShutdownTypeLogout)); context->setContextProperty(QStringLiteral("ShutdownType"), mapShutdownType); QQmlPropertyMap *mapSpdMethods = new QQmlPropertyMap(this); QSet spdMethods = Solid::PowerManagement::supportedSleepStates(); mapSpdMethods->insert(QStringLiteral("StandbyState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::StandbyState))); mapSpdMethods->insert(QStringLiteral("SuspendState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::SuspendState))); mapSpdMethods->insert(QStringLiteral("HibernateState"), QVariant::fromValue(spdMethods.contains(Solid::PowerManagement::HibernateState))); context->setContextProperty(QStringLiteral("spdMethods"), mapSpdMethods); context->setContextProperty(QStringLiteral("canLogout"), KAuthorized::authorize(QStringLiteral("logout"))); QString bootManager = KConfig(QStringLiteral(KDE_CONFDIR "/kdm/kdmrc"), KConfig::SimpleConfig) .group("Shutdown") .readEntry("BootManager", "None"); context->setContextProperty(QStringLiteral("bootManager"), bootManager); QStringList options; int def, cur; if ( KDisplayManager().bootOptions( rebootOptions, def, cur ) ) { if ( cur > -1 ) { def = cur; } } QQmlPropertyMap *rebootOptionsMap = new QQmlPropertyMap(this); rebootOptionsMap->insert(QStringLiteral("options"), QVariant::fromValue(rebootOptions)); rebootOptionsMap->insert(QStringLiteral("default"), QVariant::fromValue(def)); context->setContextProperty(QStringLiteral("rebootOptions"), rebootOptionsMap); // engine stuff KDeclarative::KDeclarative kdeclarative; kdeclarative.setDeclarativeEngine(engine()); kdeclarative.initialize(); kdeclarative.setupBindings(); // windowContainer->installEventFilter(this); } void KSMShutdownDlg::init() { rootContext()->setContextProperty(QStringLiteral("screenGeometry"), screen()->geometry()); QString fileName; if(m_theme.isEmpty()) { KPackage::Package package = KPackage::PackageLoader::self()->loadPackage(QStringLiteral("Plasma/LookAndFeel")); KConfigGroup cg(KSharedConfig::openConfig(QStringLiteral("kdeglobals")), "KDE"); const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); if (!packageName.isEmpty()) { package.setPath(packageName); } fileName = package.filePath("logoutmainscript"); } else fileName = m_theme; if (QFile::exists(fileName)) { //qCDebug(KSMSERVER) << "Using QML theme" << fileName; setSource(QUrl::fromLocalFile(fileName)); } else { qCWarning(KSMSERVER) << "Couldn't find a theme for the Shutdown dialog" << fileName; return; } if(!errors().isEmpty()) { qCWarning(KSMSERVER) << errors(); } connect(rootObject(), SIGNAL(logoutRequested()), SLOT(slotLogout())); connect(rootObject(), SIGNAL(haltRequested()), SLOT(slotHalt())); connect(rootObject(), SIGNAL(suspendRequested(int)), SLOT(slotSuspend(int)) ); connect(rootObject(), SIGNAL(rebootRequested()), SLOT(slotReboot())); connect(rootObject(), SIGNAL(rebootRequested2(int)), SLOT(slotReboot(int)) ); connect(rootObject(), SIGNAL(cancelRequested()), SLOT(reject())); connect(rootObject(), SIGNAL(lockScreenRequested()), SLOT(slotLockScreen())); connect(screen(), &QScreen::geometryChanged, this, [this] { setGeometry(screen()->geometry()); }); //decide in backgroundcontrast wether doing things darker or lighter //set backgroundcontrast here, because in QEvent::PlatformSurface //is too early and we don't have the root object yet const QColor backgroundColor = rootObject() ? rootObject()->property("backgroundColor").value() : QColor(); KWindowEffects::enableBackgroundContrast(winId(), true, 0.4, (backgroundColor.value() > 128 ? 1.6 : 0.3), 1.7); QQuickView::showFullScreen(); requestActivate(); KWindowSystem::setState(winId(), NET::SkipTaskbar|NET::SkipPager); setKeyboardGrabEnabled(true); } void KSMShutdownDlg::resizeEvent(QResizeEvent *e) { QQuickView::resizeEvent( e ); if( KWindowSystem::compositingActive()) { //TODO: reenable window mask when we are without composite? // clearMask(); } else { // setMask(m_view->mask()); } } bool KSMShutdownDlg::event(QEvent *e) { if (e->type() == QEvent::PlatformSurface) { switch (static_cast(e)->surfaceEventType()) { case QPlatformSurfaceEvent::SurfaceCreated: setupWaylandIntegration(); KWindowEffects::enableBlurBehind(winId(), true); break; case QPlatformSurfaceEvent::SurfaceAboutToBeDestroyed: delete m_shellSurface; m_shellSurface = nullptr; break; } } return QQuickView::event(e); } void KSMShutdownDlg::setupWaylandIntegration() { if (m_shellSurface) { // already setup return; } using namespace KWayland::Client; if (!m_waylandPlasmaShell) { return; } Surface *s = Surface::fromWindow(this); if (!s) { return; } m_shellSurface = m_waylandPlasmaShell->createSurface(s, this); // TODO: set a proper window type to indicate to KWin that this is the logout dialog // maybe we need a dedicated type for it? m_shellSurface->setPosition(geometry().topLeft()); } void KSMShutdownDlg::slotLogout() { m_shutdownType = KWorkSpace::ShutdownTypeNone; accept(); } void KSMShutdownDlg::slotReboot() { // no boot option selected -> current m_bootOption.clear(); m_shutdownType = KWorkSpace::ShutdownTypeReboot; accept(); } void KSMShutdownDlg::slotReboot(int opt) { if (int(rebootOptions.size()) > opt) m_bootOption = rebootOptions[opt]; m_shutdownType = KWorkSpace::ShutdownTypeReboot; accept(); } void KSMShutdownDlg::slotLockScreen() { m_bootOption.clear(); QDBusMessage call = QDBusMessage::createMethodCall(QStringLiteral("org.kde.screensaver"), QStringLiteral("/ScreenSaver"), QStringLiteral("org.freedesktop.ScreenSaver"), QStringLiteral("Lock")); QDBusConnection::sessionBus().asyncCall(call); reject(); } void KSMShutdownDlg::slotHalt() { m_bootOption.clear(); m_shutdownType = KWorkSpace::ShutdownTypeHalt; accept(); } void KSMShutdownDlg::slotSuspend(int spdMethod) { m_bootOption.clear(); switch (spdMethod) { case Solid::PowerManagement::StandbyState: case Solid::PowerManagement::SuspendState: Solid::PowerManagement::requestSleep(Solid::PowerManagement::SuspendState, 0, 0); break; case Solid::PowerManagement::HibernateState: Solid::PowerManagement::requestSleep(Solid::PowerManagement::HibernateState, 0, 0); break; } reject(); } void KSMShutdownDlg::accept() { emit accepted(); } void KSMShutdownDlg::reject() { emit rejected(); } diff --git a/systemmonitor/ksystemactivitydialog.cpp b/systemmonitor/ksystemactivitydialog.cpp index ab2c753cc..c945a25ea 100644 --- a/systemmonitor/ksystemactivitydialog.cpp +++ b/systemmonitor/ksystemactivitydialog.cpp @@ -1,142 +1,141 @@ /* * Copyright (C) 2007-2010 John Tapsell * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU Library General Public License version 2 as * published by the Free Software Foundation * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details * * You should have received a copy of the GNU Library General Public * License along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef Q_WS_WIN #include "ksystemactivitydialog.h" #include #include #include #include #include #include #include #include #include #include #include #include #include -#include #include #include #include #include #include #include #include KSystemActivityDialog::KSystemActivityDialog(QWidget *parent) : QDialog(parent), m_processList(0) { setWindowTitle(i18n("System Activity")); setWindowIcon(QIcon::fromTheme(QStringLiteral( "utilities-system-monitor" ))); QVBoxLayout *mainLayout = new QVBoxLayout; setLayout(mainLayout); mainLayout->addWidget(&m_processList); m_processList.setScriptingEnabled(true); setSizeGripEnabled(true); (void)minimumSizeHint(); //Force the dialog to be laid out now layout()->setContentsMargins(0,0,0,0); // Since we kinda act like an application more than just a Window, map the usual ctrl+Q shortcut to close as well QAction *closeWindow = new QAction(this); closeWindow->setShortcut(QKeySequence::Quit); connect(closeWindow, &QAction::triggered, this, &KSystemActivityDialog::accept); addAction(closeWindow); // We need the resizing to be done once the dialog has been initialized // otherwise we don't actually have a window. QTimer::singleShot(0, this, &KSystemActivityDialog::slotInit); } void KSystemActivityDialog::slotInit() { resize(QSize(650, 420)); KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog"); KWindowConfig::restoreWindowSize(windowHandle(), cg); m_processList.loadSettings(cg); // Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this const bool keepAbove = true; // KRunnerSettings::keepTaskDialogAbove(); if (keepAbove) { KWindowSystem::setState(winId(), NET::KeepAbove); } QDBusConnection con = QDBusConnection::sessionBus(); con.registerObject(QStringLiteral("/"), this, QDBusConnection::ExportAllSlots); QRect geom = windowHandle()->screen()->geometry(); QSize ourSize = windowHandle()->size(); int w = ourSize.width(); int h = ourSize.height(); setGeometry((geom.width() - w)/2, (geom.height() - h)/2, w, h); } void KSystemActivityDialog::run() { show(); raise(); KWindowSystem::setOnDesktop(winId(), KWindowSystem::currentDesktop()); KWindowSystem::forceActiveWindow(winId()); } void KSystemActivityDialog::setFilterText(const QString &filterText) { m_processList.filterLineEdit()->setText(filterText); m_processList.filterLineEdit()->setFocus(); } QString KSystemActivityDialog::filterText() const { return m_processList.filterLineEdit()->text(); } void KSystemActivityDialog::closeEvent(QCloseEvent *event) { saveDialogSettings(); event->accept(); } void KSystemActivityDialog::reject () { saveDialogSettings(); QDialog::reject(); } void KSystemActivityDialog::saveDialogSettings() { //When the user closes the dialog, save the position and the KeepAbove state KConfigGroup cg = KSharedConfig::openConfig()->group("TaskDialog"); KWindowConfig::saveWindowSize(windowHandle(), cg); m_processList.saveSettings(cg); // Since we default to forcing the window to be KeepAbove, if the user turns this off, remember this // vHanda: Temporarily commented out // bool keepAbove = KWindowSystem::windowInfo(winId(), NET::WMState).hasState(NET::KeepAbove); // KRunnerSettings::setKeepTaskDialogAbove(keepAbove); KSharedConfig::openConfig()->sync(); } #endif // not Q_WS_WIN