1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

lock: handle case where session lock is rejected

This commit is contained in:
bbedward
2026-01-09 09:46:39 -05:00
parent af0166a553
commit 0f09cc693a
4 changed files with 102 additions and 40 deletions

View File

@@ -12,37 +12,54 @@ Scope {
property string sharedPasswordBuffer: "" property string sharedPasswordBuffer: ""
property bool shouldLock: false property bool shouldLock: false
property bool processingExternalEvent: false property bool lockInitiatedLocally: false
property bool pendingLock: false
Component.onCompleted: { Component.onCompleted: {
IdleService.lockComponent = this; IdleService.lockComponent = this;
} }
function notifyLoginctl(lockAction: bool) {
if (!SettingsData.loginctlLockIntegration || !DMSService.isConnected)
return;
if (lockAction)
DMSService.lockSession(() => {});
else
DMSService.unlockSession(() => {});
}
function lock() { function lock() {
if (SettingsData.customPowerActionLock && SettingsData.customPowerActionLock.length > 0) { if (SettingsData.customPowerActionLock?.length > 0) {
Quickshell.execDetached(["sh", "-c", SettingsData.customPowerActionLock]); Quickshell.execDetached(["sh", "-c", SettingsData.customPowerActionLock]);
return; return;
} }
shouldLock = true; if (shouldLock || pendingLock)
if (!processingExternalEvent && SettingsData.loginctlLockIntegration && DMSService.isConnected) { return;
DMSService.lockSession(response => {
if (response.error) lockInitiatedLocally = true;
console.warn("Lock: loginctl.lock failed:", response.error);
}); if (!SessionService.active && SessionService.loginctlAvailable) {
pendingLock = true;
notifyLoginctl(true);
return;
} }
shouldLock = true;
notifyLoginctl(true);
} }
function unlock() { function unlock() {
if (!processingExternalEvent && SettingsData.loginctlLockIntegration && DMSService.isConnected) { if (!shouldLock)
DMSService.unlockSession(response => { return;
if (response.error) { lockInitiatedLocally = false;
console.warn("Lock: Failed to call loginctl.unlock:", response.error); notifyLoginctl(false);
shouldLock = false; shouldLock = false;
} }
});
} else { function forceReset() {
shouldLock = false; lockInitiatedLocally = false;
} pendingLock = false;
shouldLock = false;
} }
function activate() { function activate() {
@@ -53,15 +70,39 @@ Scope {
target: SessionService target: SessionService
function onSessionLocked() { function onSessionLocked() {
processingExternalEvent = true; if (shouldLock || pendingLock)
return;
if (!SessionService.active && SessionService.loginctlAvailable) {
pendingLock = true;
lockInitiatedLocally = false;
return;
}
lockInitiatedLocally = false;
shouldLock = true; shouldLock = true;
processingExternalEvent = false;
} }
function onSessionUnlocked() { function onSessionUnlocked() {
processingExternalEvent = true; if (pendingLock) {
pendingLock = false;
lockInitiatedLocally = false;
return;
}
if (!shouldLock || lockInitiatedLocally)
return;
shouldLock = false; shouldLock = false;
processingExternalEvent = false; }
function onLoginctlStateChanged() {
if (SessionService.active && pendingLock) {
pendingLock = false;
lockInitiatedLocally = true;
shouldLock = true;
return;
}
if (SessionService.locked && !shouldLock && !pendingLock) {
lockInitiatedLocally = false;
shouldLock = true;
}
} }
} }
@@ -79,8 +120,10 @@ Scope {
locked: shouldLock locked: shouldLock
onLockedChanged: { onLockedChanged: {
if (locked) if (locked) {
pendingLock = false;
dpmsReapplyTimer.start(); dpmsReapplyTimer.start();
}
} }
WlSessionLockSurface { WlSessionLockSurface {
@@ -104,9 +147,7 @@ Scope {
sharedPasswordBuffer: root.sharedPasswordBuffer sharedPasswordBuffer: root.sharedPasswordBuffer
screenName: lockSurface.currentScreenName screenName: lockSurface.currentScreenName
isLocked: shouldLock isLocked: shouldLock
onUnlockRequested: { onUnlockRequested: root.unlock()
root.unlock();
}
onPasswordChanged: newPassword => { onPasswordChanged: newPassword => {
root.sharedPasswordBuffer = newPassword; root.sharedPasswordBuffer = newPassword;
} }
@@ -122,13 +163,15 @@ Scope {
target: "lock" target: "lock"
function lock() { function lock() {
root.shouldLock = true; root.lock();
if (SettingsData.loginctlLockIntegration && DMSService.isConnected) { }
DMSService.lockSession(response => {
if (response.error) function unlock() {
console.warn("Lock: loginctl.lock failed:", response.error); root.unlock();
}); }
}
function forceReset() {
root.forceReset();
} }
function demo() { function demo() {
@@ -138,6 +181,17 @@ Scope {
function isLocked(): bool { function isLocked(): bool {
return sessionLock.locked; return sessionLock.locked;
} }
function status(): string {
return JSON.stringify({
shouldLock: root.shouldLock,
sessionLockLocked: sessionLock.locked,
lockInitiatedLocally: root.lockInitiatedLocally,
pendingLock: root.pendingLock,
loginctlLocked: SessionService.locked,
loginctlActive: SessionService.active
});
}
} }
Timer { Timer {

View File

@@ -34,6 +34,13 @@ Item {
signal unlockRequested signal unlockRequested
function resetLockState() {
lockerReadySent = false;
lockerReadyArmed = true;
unlocking = false;
pamState = "";
}
function pickRandomFact() { function pickRandomFact() {
randomFact = Facts.getRandomFact(); randomFact = Facts.getRandomFact();
} }

View File

@@ -3,7 +3,6 @@ pragma ComponentBehavior: Bound
import QtQuick import QtQuick
import Quickshell import Quickshell
import Quickshell.Wayland import Quickshell.Wayland
import qs.Common
PanelWindow { PanelWindow {
id: root id: root
@@ -26,13 +25,13 @@ PanelWindow {
color: "transparent" color: "transparent"
function showDemo(): void { function showDemo(): void {
console.log("Showing lock screen demo") console.log("Showing lock screen demo");
demoActive = true demoActive = true;
} }
function hideDemo(): void { function hideDemo(): void {
console.log("Hiding lock screen demo") console.log("Hiding lock screen demo");
demoActive = false demoActive = false;
} }
Loader { Loader {

View File

@@ -32,8 +32,10 @@ Rectangle {
} }
onIsLockedChanged: { onIsLockedChanged: {
if (!isLocked) { if (isLocked) {
lockContent.unlocking = false; lockContent.resetLockState();
return;
} }
lockContent.unlocking = false;
} }
} }