1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2025-12-06 05:25:41 -05:00
Files
DankMaterialShell/quickshell/Modules/Lock/Lock.qml
2025-12-03 12:15:22 -05:00

144 lines
3.9 KiB
QML

pragma ComponentBehavior: Bound
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Wayland
import qs.Common
import qs.Services
Scope {
id: root
property string sharedPasswordBuffer: ""
property bool shouldLock: false
property bool processingExternalEvent: false
Component.onCompleted: {
IdleService.lockComponent = this;
}
function lock() {
if (SettingsData.customPowerActionLock && SettingsData.customPowerActionLock.length > 0) {
Quickshell.execDetached(["sh", "-c", SettingsData.customPowerActionLock]);
return;
}
if (!processingExternalEvent && SettingsData.loginctlLockIntegration && DMSService.isConnected) {
DMSService.lockSession(response => {
if (response.error) {
console.warn("Lock: Failed to call loginctl.lock:", response.error);
shouldLock = true;
}
});
} else {
shouldLock = true;
}
}
function unlock() {
if (!processingExternalEvent && SettingsData.loginctlLockIntegration && DMSService.isConnected) {
DMSService.unlockSession(response => {
if (response.error) {
console.warn("Lock: Failed to call loginctl.unlock:", response.error);
shouldLock = false;
}
});
} else {
shouldLock = false;
}
}
function activate() {
lock();
}
Connections {
target: SessionService
function onSessionLocked() {
processingExternalEvent = true;
shouldLock = true;
processingExternalEvent = false;
}
function onSessionUnlocked() {
processingExternalEvent = true;
shouldLock = false;
processingExternalEvent = false;
}
}
Connections {
target: IdleService
function onLockRequested() {
lock();
}
}
WlSessionLock {
id: sessionLock
locked: shouldLock
WlSessionLockSurface {
id: lockSurface
property string currentScreenName: screen?.name ?? ""
property bool isActiveScreen: {
if (Quickshell.screens.length <= 1)
return true;
if (SettingsData.lockScreenActiveMonitor === "all")
return true;
return currentScreenName === SettingsData.lockScreenActiveMonitor;
}
color: isActiveScreen ? "transparent" : SettingsData.lockScreenInactiveColor
LockSurface {
anchors.fill: parent
visible: lockSurface.isActiveScreen
lock: sessionLock
sharedPasswordBuffer: root.sharedPasswordBuffer
screenName: lockSurface.currentScreenName
isLocked: shouldLock
onUnlockRequested: {
root.unlock();
}
onPasswordChanged: newPassword => {
root.sharedPasswordBuffer = newPassword;
}
}
}
}
LockScreenDemo {
id: demoWindow
}
IpcHandler {
target: "lock"
function lock() {
if (!root.processingExternalEvent && SettingsData.loginctlLockIntegration && DMSService.isConnected) {
DMSService.lockSession(response => {
if (response.error) {
console.warn("Lock: Failed to call loginctl.lock:", response.error);
root.shouldLock = true;
}
});
} else {
root.shouldLock = true;
}
}
function demo() {
demoWindow.showDemo();
}
function isLocked(): bool {
return sessionLock.locked;
}
}
}