mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-08-01 19:18:28 -04:00
lock: add resilience for when the lock surface is rejected
related #2778 related #2841 port 1.5
This commit is contained in:
@@ -10,6 +10,8 @@ import qs.Services
|
|||||||
Scope {
|
Scope {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
|
readonly property var log: Log.scoped("Lock")
|
||||||
|
|
||||||
property string sharedPasswordBuffer: ""
|
property string sharedPasswordBuffer: ""
|
||||||
property bool shouldLock: false
|
property bool shouldLock: false
|
||||||
|
|
||||||
@@ -21,26 +23,13 @@ Scope {
|
|||||||
|
|
||||||
onShouldLockChanged: {
|
onShouldLockChanged: {
|
||||||
IdleService.isShellLocked = shouldLock;
|
IdleService.isShellLocked = shouldLock;
|
||||||
if (shouldLock && lockPowerOffArmed) {
|
|
||||||
lockStateCheck.restart();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: lockStateCheck
|
|
||||||
interval: 100
|
|
||||||
repeat: false
|
|
||||||
onTriggered: {
|
|
||||||
if (sessionLock.locked && lockPowerOffArmed) {
|
|
||||||
pendingLock = false;
|
|
||||||
lockPowerOffArmed = false;
|
|
||||||
beginPowerOff();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
property bool lockInitiatedLocally: false
|
property bool lockInitiatedLocally: false
|
||||||
property bool pendingLock: false
|
property bool pendingLock: false
|
||||||
|
readonly property int maxLockRetries: 3
|
||||||
|
property int lockRetryAttempts: 0
|
||||||
|
property bool lockRetryPending: false
|
||||||
property bool lockPowerOffArmed: false
|
property bool lockPowerOffArmed: false
|
||||||
property bool lockWakeAllowed: false
|
property bool lockWakeAllowed: false
|
||||||
property bool customLockerSpawned: false
|
property bool customLockerSpawned: false
|
||||||
@@ -116,6 +105,24 @@ Scope {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function resetLockRetry() {
|
||||||
|
lockRetryAttempts = 0;
|
||||||
|
lockRetryPending = false;
|
||||||
|
lockRetryTimer.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleLockLost() {
|
||||||
|
if (lockRetryAttempts >= maxLockRetries) {
|
||||||
|
log.error("Compositor refused session lock", maxLockRetries, "times - resetting lock state");
|
||||||
|
forceReset();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
lockRetryAttempts++;
|
||||||
|
lockRetryPending = true;
|
||||||
|
lockRetryTimer.restart();
|
||||||
|
log.warn("Session lock lost while lock requested - retry", lockRetryAttempts, "/", maxLockRetries);
|
||||||
|
}
|
||||||
|
|
||||||
function lock() {
|
function lock() {
|
||||||
if (SettingsData.customPowerActionLock?.length > 0) {
|
if (SettingsData.customPowerActionLock?.length > 0) {
|
||||||
spawnCustomLocker();
|
spawnCustomLocker();
|
||||||
@@ -124,6 +131,7 @@ Scope {
|
|||||||
if (shouldLock || pendingLock)
|
if (shouldLock || pendingLock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
resetLockRetry();
|
||||||
lockInitiatedLocally = true;
|
lockInitiatedLocally = true;
|
||||||
lockPowerOffArmed = powerOffOnLock;
|
lockPowerOffArmed = powerOffOnLock;
|
||||||
|
|
||||||
@@ -139,7 +147,7 @@ Scope {
|
|||||||
|
|
||||||
function lockAndOutputsOff() {
|
function lockAndOutputsOff() {
|
||||||
IdleService.lockPowerOffRequested = true;
|
IdleService.lockPowerOffRequested = true;
|
||||||
if (sessionLock.locked) {
|
if (sessionLock.secure) {
|
||||||
beginPowerOff();
|
beginPowerOff();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -150,6 +158,7 @@ Scope {
|
|||||||
function unlock() {
|
function unlock() {
|
||||||
if (!shouldLock)
|
if (!shouldLock)
|
||||||
return;
|
return;
|
||||||
|
resetLockRetry();
|
||||||
lockInitiatedLocally = false;
|
lockInitiatedLocally = false;
|
||||||
notifyLoginctl(false);
|
notifyLoginctl(false);
|
||||||
shouldLock = false;
|
shouldLock = false;
|
||||||
@@ -160,6 +169,7 @@ Scope {
|
|||||||
pendingLock = false;
|
pendingLock = false;
|
||||||
shouldLock = false;
|
shouldLock = false;
|
||||||
customLockerSpawned = false;
|
customLockerSpawned = false;
|
||||||
|
resetLockRetry();
|
||||||
resetPowerOffFade();
|
resetPowerOffFade();
|
||||||
IdleService.lockPowerOffRequested = false;
|
IdleService.lockPowerOffRequested = false;
|
||||||
}
|
}
|
||||||
@@ -198,6 +208,15 @@ Scope {
|
|||||||
shouldLock = false;
|
shouldLock = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onSessionResumed() {
|
||||||
|
if (!shouldLock || sessionLock.locked)
|
||||||
|
return;
|
||||||
|
log.warn("Session lock dead after resume - re-locking");
|
||||||
|
resetLockRetry();
|
||||||
|
lockRetryPending = true;
|
||||||
|
lockRetryPending = false;
|
||||||
|
}
|
||||||
|
|
||||||
function onLoginctlStateChanged() {
|
function onLoginctlStateChanged() {
|
||||||
if (SessionService.active && pendingLock) {
|
if (SessionService.active && pendingLock) {
|
||||||
pendingLock = false;
|
pendingLock = false;
|
||||||
@@ -239,7 +258,7 @@ Scope {
|
|||||||
WlSessionLock {
|
WlSessionLock {
|
||||||
id: sessionLock
|
id: sessionLock
|
||||||
|
|
||||||
locked: shouldLock
|
locked: shouldLock && !lockRetryPending
|
||||||
|
|
||||||
WlSessionLockSurface {
|
WlSessionLockSurface {
|
||||||
id: lockSurface
|
id: lockSurface
|
||||||
@@ -312,16 +331,20 @@ Scope {
|
|||||||
Connections {
|
Connections {
|
||||||
target: sessionLock
|
target: sessionLock
|
||||||
|
|
||||||
function onLockedChanged() {
|
function onSecureChanged() {
|
||||||
notifyLockedHint(sessionLock.locked);
|
notifyLockedHint(sessionLock.secure);
|
||||||
if (sessionLock.locked) {
|
if (!sessionLock.secure)
|
||||||
pendingLock = false;
|
|
||||||
if (lockPowerOffArmed && powerOffOnLock)
|
|
||||||
beginPowerOff();
|
|
||||||
lockPowerOffArmed = false;
|
|
||||||
return;
|
return;
|
||||||
}
|
lockRetryAttempts = 0;
|
||||||
|
pendingLock = false;
|
||||||
|
if (lockPowerOffArmed && powerOffOnLock)
|
||||||
|
beginPowerOff();
|
||||||
|
lockPowerOffArmed = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function onLockedChanged() {
|
||||||
|
if (sessionLock.locked)
|
||||||
|
return;
|
||||||
lockWakeAllowed = false;
|
lockWakeAllowed = false;
|
||||||
resetPowerOffFade();
|
resetPowerOffFade();
|
||||||
if (IdleService.monitorsOff && powerOffOnLock) {
|
if (IdleService.monitorsOff && powerOffOnLock) {
|
||||||
@@ -329,6 +352,8 @@ Scope {
|
|||||||
CompositorService.powerOnMonitors();
|
CompositorService.powerOnMonitors();
|
||||||
}
|
}
|
||||||
IdleService.lockPowerOffRequested = false;
|
IdleService.lockPowerOffRequested = false;
|
||||||
|
if (shouldLock && !lockRetryPending)
|
||||||
|
handleLockLost();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,13 +385,15 @@ Scope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function isLocked(): bool {
|
function isLocked(): bool {
|
||||||
return sessionLock.locked;
|
return sessionLock.secure;
|
||||||
}
|
}
|
||||||
|
|
||||||
function status(): string {
|
function status(): string {
|
||||||
return JSON.stringify({
|
return JSON.stringify({
|
||||||
shouldLock: root.shouldLock,
|
shouldLock: root.shouldLock,
|
||||||
sessionLockLocked: sessionLock.locked,
|
sessionLockLocked: sessionLock.locked,
|
||||||
|
sessionLockSecure: sessionLock.secure,
|
||||||
|
lockRetryAttempts: root.lockRetryAttempts,
|
||||||
lockInitiatedLocally: root.lockInitiatedLocally,
|
lockInitiatedLocally: root.lockInitiatedLocally,
|
||||||
pendingLock: root.pendingLock,
|
pendingLock: root.pendingLock,
|
||||||
loginctlLocked: SessionService.locked,
|
loginctlLocked: SessionService.locked,
|
||||||
@@ -395,6 +422,13 @@ Scope {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: lockRetryTimer
|
||||||
|
interval: 1000
|
||||||
|
repeat: false
|
||||||
|
onTriggered: root.lockRetryPending = false
|
||||||
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
id: dpmsReapplyTimer
|
id: dpmsReapplyTimer
|
||||||
interval: 100
|
interval: 100
|
||||||
@@ -407,7 +441,7 @@ Scope {
|
|||||||
interval: 200
|
interval: 200
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
if (!sessionLock.locked)
|
if (!sessionLock.secure)
|
||||||
return;
|
return;
|
||||||
if (!powerOffOnLock)
|
if (!powerOffOnLock)
|
||||||
return;
|
return;
|
||||||
@@ -426,7 +460,7 @@ Scope {
|
|||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
enabled: sessionLock.locked
|
enabled: sessionLock.secure
|
||||||
hoverEnabled: enabled
|
hoverEnabled: enabled
|
||||||
onPressed: lockWakeDebounce.restart()
|
onPressed: lockWakeDebounce.restart()
|
||||||
onPositionChanged: lockWakeDebounce.restart()
|
onPositionChanged: lockWakeDebounce.restart()
|
||||||
@@ -435,10 +469,10 @@ Scope {
|
|||||||
|
|
||||||
FocusScope {
|
FocusScope {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
focus: sessionLock.locked
|
focus: sessionLock.secure
|
||||||
|
|
||||||
Keys.onPressed: event => {
|
Keys.onPressed: event => {
|
||||||
if (!sessionLock.locked)
|
if (!sessionLock.secure)
|
||||||
return;
|
return;
|
||||||
lockWakeDebounce.restart();
|
lockWakeDebounce.restart();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ Singleton {
|
|||||||
respectInhibitors: root.respectInhibitors
|
respectInhibitors: root.respectInhibitors
|
||||||
enabled: false
|
enabled: false
|
||||||
onIsIdleChanged: {
|
onIsIdleChanged: {
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
if (isIdle) {
|
if (isIdle) {
|
||||||
if (SettingsData.fadeToDpmsEnabled) {
|
if (SettingsData.fadeToDpmsEnabled) {
|
||||||
root.fadeToDpmsRequested();
|
root.fadeToDpmsRequested();
|
||||||
@@ -101,6 +103,8 @@ Singleton {
|
|||||||
respectInhibitors: root.respectInhibitors
|
respectInhibitors: root.respectInhibitors
|
||||||
enabled: false
|
enabled: false
|
||||||
onIsIdleChanged: {
|
onIsIdleChanged: {
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
if (isIdle) {
|
if (isIdle) {
|
||||||
root.requestMonitorOff();
|
root.requestMonitorOff();
|
||||||
} else {
|
} else {
|
||||||
@@ -115,6 +119,8 @@ Singleton {
|
|||||||
respectInhibitors: root.respectInhibitors
|
respectInhibitors: root.respectInhibitors
|
||||||
enabled: false
|
enabled: false
|
||||||
onIsIdleChanged: {
|
onIsIdleChanged: {
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
if (isIdle) {
|
if (isIdle) {
|
||||||
if (SettingsData.fadeToLockEnabled) {
|
if (SettingsData.fadeToLockEnabled) {
|
||||||
root.fadeToLockRequested();
|
root.fadeToLockRequested();
|
||||||
@@ -135,6 +141,8 @@ Singleton {
|
|||||||
respectInhibitors: root.respectInhibitors
|
respectInhibitors: root.respectInhibitors
|
||||||
enabled: false
|
enabled: false
|
||||||
onIsIdleChanged: {
|
onIsIdleChanged: {
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
if (isIdle)
|
if (isIdle)
|
||||||
root.requestSuspend();
|
root.requestSuspend();
|
||||||
}
|
}
|
||||||
@@ -149,6 +157,8 @@ Singleton {
|
|||||||
respectInhibitors: false
|
respectInhibitors: false
|
||||||
enabled: root.enabled && root.isShellLocked && root.monitorsOff && (SettingsData.lockScreenPowerOffMonitorsOnLock || root.lockPowerOffRequested)
|
enabled: root.enabled && root.isShellLocked && root.monitorsOff && (SettingsData.lockScreenPowerOffMonitorsOnLock || root.lockPowerOffRequested)
|
||||||
onIsIdleChanged: {
|
onIsIdleChanged: {
|
||||||
|
if (!enabled)
|
||||||
|
return;
|
||||||
if (!isIdle && root.monitorsOff)
|
if (!isIdle && root.monitorsOff)
|
||||||
root.requestMonitorOn();
|
root.requestMonitorOn();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user