From c87d90645dab4a4899dbb50950ff9cc422f96f57 Mon Sep 17 00:00:00 2001 From: Nate Graham Date: Tue, 17 Sep 2019 11:34:20 -0600 Subject: [PATCH] When asked to switch sessions, jump to session creation if there's nothing to switch to Summary: TL;DR version: whenever you currently would be taken to a session switcher page where the only possible action is to go to SDDM and start a new session, instead just show SDDM immediately instead. Currently, the session switcher screen suffers from a few UX problems: - There's a fake "start new session" item that looks like a button but isn't clickable - Asking to switch users always goes to the screen where you can switch to existing sessions even if there are no existing sessions to switch to, which is an unnecessary extra step This patch aims to solve those problems in the following ways: - Don't show a fake "start new session" item in the Breeze theme; instead add a real button in the UI to do this - When asked to show the session management screen and there is only one session so the on;y thing you could do on that screen is create another session, instead just go to session creation directly - For themes where the fake "start new session" button is shown, use a better icon that doesn't make it look like a clickable button BUG: 386361 FIXED-IN: 5.17.0 Depends on D23279 Test Plan: 1. Have only one session > Kickoff/Kicker/dash/Krunner > Switch User -> you go directly to SDDM where you can start a new session 2. Start a new session, then Switch user again -> you go to the session management screen where you can switch to the other session, or start a new one Videos: Clicking "Switch User" when there are no other sessions: {F7264475} Clicking "Switch User" when there is another session to switch to, and then switching to it: {F7264476} Clicking "Switch User" when there is another session to switch to, and then starting a new session: {F7264480} Switching between multiple sessions in the session switcher: {F7264483} If the fake "New Session" item is shown (e.g in other themes), here's what it now looks like: {F7264485} Reviewers: #plasma, #vdg, GB_2, mart Reviewed By: #plasma, #vdg, GB_2, mart Subscribers: GB_2, gregormi, broulik, plasma-devel Tags: #plasma Differential Revision: https://phabricator.kde.org/D23283 --- components/sessionsprivate/sessionsmodel.cpp | 2 +- .../contents/lockscreen/LockScreenUi.qml | 56 +++++++++++++++---- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/components/sessionsprivate/sessionsmodel.cpp b/components/sessionsprivate/sessionsmodel.cpp index 64653ac0e..25d3f3d19 100644 --- a/components/sessionsprivate/sessionsmodel.cpp +++ b/components/sessionsprivate/sessionsmodel.cpp @@ -251,7 +251,7 @@ QVariant SessionsModel::data(const QModelIndex &index, int role) const if (index.row() == m_data.count()) { switch (static_cast(role)) { case Role::RealName: return i18n("New Session"); - case Role::IconName: return QStringLiteral("list-add"); + case Role::IconName: return QStringLiteral("system-switch-user"); case Role::Name: return i18n("New Session"); case Role::DisplayNumber: return 0; //NA case Role::VtNumber: return -1; //an invalid VtNumber - which we'll use to indicate it's to start a new session diff --git a/lookandfeel/contents/lockscreen/LockScreenUi.qml b/lookandfeel/contents/lockscreen/LockScreenUi.qml index e1ccb7348..32e234a31 100644 --- a/lookandfeel/contents/lockscreen/LockScreenUi.qml +++ b/lookandfeel/contents/lockscreen/LockScreenUi.qml @@ -57,7 +57,7 @@ PlasmaCore.ColorScope { SessionsModel { id: sessionsModel - showNewSessionEntry: true + showNewSessionEntry: false } PlasmaCore.DataSource { @@ -249,7 +249,18 @@ PlasmaCore.ColorScope { ActionButton { text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Switch User") iconSource: "system-switch-user" - onClicked: mainStack.push(switchSessionPage) + onClicked: { + // If there are no existing sessions to switch to, create a new one instead + if (((sessionsModel.showNewSessionEntry && sessionsModel.count === 1) || + (!sessionsModel.showNewSessionEntry && sessionsModel.count === 0)) && + sessionsModel.canSwitchUser) { + mainStack.pop({immediate:true}) + sessionsModel.startNewSession(true /* lock the screen too */) + lockScreenRoot.state = '' + } else { + mainStack.push(switchSessionPage) + } + } visible: sessionsModel.canStartNewSession && sessionsModel.canSwitchUser } ] @@ -264,9 +275,17 @@ PlasmaCore.ColorScope { Component.onCompleted: { if (defaultToSwitchUser) { //context property - mainStack.push({ - item: switchSessionPage, - immediate: true}); + // If we are in the only session, then going to the session switcher is + // a pointless extra step; instead create a new session immediately + if (((sessionsModel.showNewSessionEntry && sessionsModel.count === 1) || + (!sessionsModel.showNewSessionEntry && sessionsModel.count === 0)) && + sessionsModel.canStartNewSession) { + sessionsModel.startNewSession(true /* lock the screen too */) + } else { + mainStack.push({ + item: switchSessionPage, + immediate: true}); + } } } } @@ -414,14 +433,31 @@ PlasmaCore.ColorScope { Keys.onReturnPressed: initSwitchSession() Keys.onEscapePressed: mainStack.pop() - PlasmaComponents.Button { + ColumnLayout { Layout.fillWidth: true - font.pointSize: theme.defaultFont.pointSize + 1 - // the magic "-1" vtNumber indicates the "New Session" entry - text: userListCurrentModelData.vtNumber === -1 ? i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Start New Session") : i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Switch Session") - onClicked: initSwitchSession() + spacing: units.largeSpacing + + PlasmaComponents.Button { + Layout.fillWidth: true + font.pointSize: theme.defaultFont.pointSize + 1 + text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Switch to This Session") + onClicked: initSwitchSession() + visible: sessionsModel.count > 0 + } + + PlasmaComponents.Button { + Layout.fillWidth: true + font.pointSize: theme.defaultFont.pointSize + 1 + text: i18nd("plasma_lookandfeel_org.kde.lookandfeel", "Start New Session") + onClicked: { + mainStack.pop({immediate:true}) + sessionsModel.startNewSession(true /* lock the screen too */) + lockScreenRoot.state = '' + } + } } + actionItems: [ ActionButton { iconSource: "go-previous"