From fe97f4272432de0ad563fe32aeaaaaff6a8dee84 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Tue, 17 Nov 2015 19:56:21 +0100 Subject: [PATCH] Add pretty user switcher This adds a user switcher borrowing elements from the lock screen and log out dialog. It will be used instead of KRunner as main UI for switching sessions. The sessions runner will stay there for the time being. CHANGLOG: The main user switcher UI has been completely re-designed REVIEW: 124585 --- ksmserver/CMakeLists.txt | 1 + ksmserver/org.kde.KSMServerInterface.xml | 1 + ksmserver/server.cpp | 13 +++ ksmserver/server.h | 2 + ksmserver/switchuserdialog.cpp | 118 +++++++++++++++++++++++ ksmserver/switchuserdialog.h | 46 +++++++++ 6 files changed, 181 insertions(+) create mode 100644 ksmserver/switchuserdialog.cpp create mode 100644 ksmserver/switchuserdialog.h diff --git a/ksmserver/CMakeLists.txt b/ksmserver/CMakeLists.txt index b4eb9b8a5..538e98570 100644 --- a/ksmserver/CMakeLists.txt +++ b/ksmserver/CMakeLists.txt @@ -14,6 +14,7 @@ set(ksmserver_KDEINIT_SRCS main.cpp server.cpp shutdowndlg.cpp + switchuserdialog.cpp legacy.cpp startup.cpp shutdown.cpp diff --git a/ksmserver/org.kde.KSMServerInterface.xml b/ksmserver/org.kde.KSMServerInterface.xml index 3680ed722..a27c4b16d 100644 --- a/ksmserver/org.kde.KSMServerInterface.xml +++ b/ksmserver/org.kde.KSMServerInterface.xml @@ -38,6 +38,7 @@ + diff --git a/ksmserver/server.cpp b/ksmserver/server.cpp index 92855e3dd..9477e5423 100644 --- a/ksmserver/server.cpp +++ b/ksmserver/server.cpp @@ -91,6 +91,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include +#include "switchuserdialog.h" + KSMServer* the_server = 0; KSMServer* KSMServer::self() @@ -1080,3 +1082,14 @@ void KSMServer::rebootWithoutConfirmation() { shutdown(KWorkSpace::ShutdownConfirmNo, KWorkSpace::ShutdownTypeReboot, KWorkSpace::ShutdownModeDefault); } + +void KSMServer::openSwitchUserDialog() +{ + KDisplayManager dm; + if (!dm.isSwitchable()) { + return; + } + + QScopedPointer dlg(new KSMSwitchUserDialog(&dm)); + dlg->exec(); +} diff --git a/ksmserver/server.h b/ksmserver/server.h index d356dd9c8..1a2f0810c 100644 --- a/ksmserver/server.h +++ b/ksmserver/server.h @@ -217,6 +217,8 @@ private: QStringList saveOnly = QStringList() ); void restoreSubSession( const QString &name ); + void openSwitchUserDialog(); + Q_SIGNALS: void subSessionClosed(); void subSessionCloseCanceled(); diff --git a/ksmserver/switchuserdialog.cpp b/ksmserver/switchuserdialog.cpp new file mode 100644 index 000000000..26d67102c --- /dev/null +++ b/ksmserver/switchuserdialog.cpp @@ -0,0 +1,118 @@ +/* + * Copyright 2015 Kai Uwe Broulik + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#include "switchuserdialog.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +KSMSwitchUserDialog::KSMSwitchUserDialog(KDisplayManager *dm, QWindow *parent) + : QQuickView(parent) + , m_displayManager(dm) +{ + setClearBeforeRendering(true); + setColor(QColor(Qt::transparent)); + setFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint); + + QPoint globalPosition(QCursor::pos()); + foreach (QScreen *s, QGuiApplication::screens()) { + if (s->geometry().contains(globalPosition)) { + setScreen(s); + break; + } + } + + // Qt doesn't set this on unmanaged windows + //FIXME: or does it? + XChangeProperty( QX11Info::display(), winId(), + XInternAtom( QX11Info::display(), "WM_WINDOW_ROLE", False ), XA_STRING, 8, PropModeReplace, + (unsigned char *)"logoutdialog", strlen( "logoutdialog" )); + + + rootContext()->setContextProperty(QStringLiteral("screenGeometry"), screen()->geometry()); + + setModality(Qt::ApplicationModal); + + KDeclarative::KDeclarative kdeclarative; + kdeclarative.setDeclarativeEngine(engine()); + //kdeclarative.initialize(); + kdeclarative.setupBindings(); + + KPackage::Package package = KPackage::PackageLoader::self()->loadPackage("Plasma/LookAndFeel"); + KConfigGroup cg(KSharedConfig::openConfig("kdeglobals"), "KDE"); + const QString packageName = cg.readEntry("LookAndFeelPackage", QString()); + if (!packageName.isEmpty()) { + package.setPath(packageName); + } + + const QString fileName = package.filePath("userswitchermainscript"); + + if (QFile::exists(fileName)) { + setSource(QUrl::fromLocalFile(fileName)); + } else { + qWarning() << "Couldn't find a theme for the Switch User dialog" << fileName; + return; + } + + setPosition(screen()->virtualGeometry().center().x() - width() / 2, + screen()->virtualGeometry().center().y() - height() / 2); + + if (!errors().isEmpty()) { + qWarning() << errors(); + } + + connect(rootObject(), SIGNAL(dismissed()), this, SIGNAL(dismissed())); + + show(); + requestActivate(); + + KWindowSystem::setState(winId(), NET::SkipTaskbar | NET::SkipPager); +} + +void KSMSwitchUserDialog::exec() +{ + QEventLoop loop; + connect(this, &KSMSwitchUserDialog::dismissed, &loop, &QEventLoop::quit); + loop.exec(); +} diff --git a/ksmserver/switchuserdialog.h b/ksmserver/switchuserdialog.h new file mode 100644 index 000000000..091a1a45a --- /dev/null +++ b/ksmserver/switchuserdialog.h @@ -0,0 +1,46 @@ +/* + * Copyright 2015 Kai Uwe Broulik + * + * 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) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * 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, see . + */ + +#ifndef SWITCHUSERDIALOG_H +#define SWITCHUSERDIALOG_H + +#include + +class KDisplayManager; + +class KSMSwitchUserDialog : public QQuickView +{ + Q_OBJECT + +public: + explicit KSMSwitchUserDialog(KDisplayManager *dm, QWindow *parent = nullptr); + virtual ~KSMSwitchUserDialog() = default; + + void exec(); + +signals: + void dismissed(); + +private: + KDisplayManager *m_displayManager = nullptr; + +}; + +#endif // SWITCHUSERDIALOG_H