1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-08-06 05:28:29 -04:00

lock: add lockAndOutputsOff IPC function

This commit is contained in:
bbedward
2026-07-17 15:24:35 -04:00
parent f8fe16738e
commit bf12665adb
3 changed files with 134 additions and 19 deletions
+1
View File
@@ -63,6 +63,7 @@ const DMS_ACTIONS = [
{ id: "spawn dms ipc call keybinds open niri", label: "Keybinds Cheatsheet: Open", compositor: "niri" }, { id: "spawn dms ipc call keybinds open niri", label: "Keybinds Cheatsheet: Open", compositor: "niri" },
{ id: "spawn dms ipc call keybinds close", label: "Keybinds Cheatsheet: Close" }, { id: "spawn dms ipc call keybinds close", label: "Keybinds Cheatsheet: Close" },
{ id: "spawn dms ipc call lock lock", label: "Lock Screen" }, { id: "spawn dms ipc call lock lock", label: "Lock Screen" },
{ id: "spawn dms ipc call lock lockAndOutputsOff", label: "Lock Screen & Outputs Off" },
{ id: "spawn dms ipc call lock demo", label: "Lock Screen: Demo" }, { id: "spawn dms ipc call lock demo", label: "Lock Screen: Demo" },
{ id: "spawn dms ipc call inhibit toggle", label: "Idle Inhibit: Toggle" }, { id: "spawn dms ipc call inhibit toggle", label: "Idle Inhibit: Toggle" },
{ id: "spawn dms ipc call inhibit enable", label: "Idle Inhibit: Enable" }, { id: "spawn dms ipc call inhibit enable", label: "Idle Inhibit: Enable" },
+131 -18
View File
@@ -13,6 +13,12 @@ Scope {
property string sharedPasswordBuffer: "" property string sharedPasswordBuffer: ""
property bool shouldLock: false property bool shouldLock: false
onSharedPasswordBufferChanged: {
if (!powerOffFadeTimer.running)
return;
cancelPowerOffFade();
}
onShouldLockChanged: { onShouldLockChanged: {
IdleService.isShellLocked = shouldLock; IdleService.isShellLocked = shouldLock;
if (shouldLock && lockPowerOffArmed) { if (shouldLock && lockPowerOffArmed) {
@@ -27,12 +33,8 @@ Scope {
onTriggered: { onTriggered: {
if (sessionLock.locked && lockPowerOffArmed) { if (sessionLock.locked && lockPowerOffArmed) {
pendingLock = false; pendingLock = false;
IdleService.monitorsOff = true;
CompositorService.powerOffMonitors();
lockWakeAllowed = false;
lockWakeDebounce.restart();
lockPowerOffArmed = false; lockPowerOffArmed = false;
dpmsReapplyTimer.start(); beginPowerOff();
} }
} }
} }
@@ -42,6 +44,38 @@ Scope {
property bool lockPowerOffArmed: false property bool lockPowerOffArmed: false
property bool lockWakeAllowed: false property bool lockWakeAllowed: false
property bool customLockerSpawned: false property bool customLockerSpawned: false
readonly property bool powerOffOnLock: SettingsData.lockScreenPowerOffMonitorsOnLock || IdleService.lockPowerOffRequested
property real powerOffFadeTarget: 0
property bool powerOffFadeInstant: false
function beginPowerOff() {
if (!SettingsData.fadeToDpmsEnabled || SettingsData.fadeToDpmsGracePeriod <= 0) {
applyMonitorsOff();
return;
}
powerOffFadeInstant = false;
powerOffFadeTarget = 1;
powerOffFadeTimer.restart();
}
function applyMonitorsOff() {
IdleService.monitorsOff = true;
CompositorService.powerOffMonitors();
lockWakeAllowed = false;
lockWakeDebounce.restart();
dpmsReapplyTimer.start();
}
function resetPowerOffFade() {
powerOffFadeTimer.stop();
powerOffFadeInstant = true;
powerOffFadeTarget = 0;
}
function cancelPowerOffFade() {
resetPowerOffFade();
IdleService.lockPowerOffRequested = false;
}
Component.onCompleted: { Component.onCompleted: {
IdleService.lockComponent = this; IdleService.lockComponent = this;
@@ -65,6 +99,7 @@ Scope {
} }
function spawnCustomLocker() { function spawnCustomLocker() {
IdleService.lockPowerOffRequested = false;
Quickshell.execDetached(["sh", "-c", SettingsData.customPowerActionLock]); Quickshell.execDetached(["sh", "-c", SettingsData.customPowerActionLock]);
// The custom locker manages its own surface; DMS never engages // The custom locker manages its own surface; DMS never engages
// WlSessionLock here, so isShellLocked stays false and the fade // WlSessionLock here, so isShellLocked stays false and the fade
@@ -90,7 +125,7 @@ Scope {
return; return;
lockInitiatedLocally = true; lockInitiatedLocally = true;
lockPowerOffArmed = SettingsData.lockScreenPowerOffMonitorsOnLock; lockPowerOffArmed = powerOffOnLock;
if (!SessionService.active && SessionService.loginctlAvailable && SettingsData.loginctlLockIntegration) { if (!SessionService.active && SessionService.loginctlAvailable && SettingsData.loginctlLockIntegration) {
pendingLock = true; pendingLock = true;
@@ -102,6 +137,16 @@ Scope {
notifyLoginctl(true); notifyLoginctl(true);
} }
function lockAndOutputsOff() {
IdleService.lockPowerOffRequested = true;
if (sessionLock.locked) {
beginPowerOff();
return;
}
lockPowerOffArmed = true;
lock();
}
function unlock() { function unlock() {
if (!shouldLock) if (!shouldLock)
return; return;
@@ -115,6 +160,8 @@ Scope {
pendingLock = false; pendingLock = false;
shouldLock = false; shouldLock = false;
customLockerSpawned = false; customLockerSpawned = false;
resetPowerOffFade();
IdleService.lockPowerOffRequested = false;
} }
function activate() { function activate() {
@@ -135,7 +182,7 @@ Scope {
return; return;
} }
lockInitiatedLocally = false; lockInitiatedLocally = false;
lockPowerOffArmed = SettingsData.lockScreenPowerOffMonitorsOnLock; lockPowerOffArmed = powerOffOnLock;
shouldLock = true; shouldLock = true;
} }
@@ -155,7 +202,7 @@ Scope {
if (SessionService.active && pendingLock) { if (SessionService.active && pendingLock) {
pendingLock = false; pendingLock = false;
lockInitiatedLocally = true; lockInitiatedLocally = true;
lockPowerOffArmed = SettingsData.lockScreenPowerOffMonitorsOnLock; lockPowerOffArmed = powerOffOnLock;
shouldLock = true; shouldLock = true;
return; return;
} }
@@ -163,7 +210,7 @@ Scope {
if (handleLoginctlCustomLock()) if (handleLoginctlCustomLock())
return; return;
lockInitiatedLocally = false; lockInitiatedLocally = false;
lockPowerOffArmed = SettingsData.lockScreenPowerOffMonitorsOnLock; lockPowerOffArmed = powerOffOnLock;
shouldLock = true; shouldLock = true;
} }
} }
@@ -175,6 +222,11 @@ Scope {
function onLockRequested() { function onLockRequested() {
lock(); lock();
} }
function onMonitorsOffChanged() {
if (!IdleService.monitorsOff)
root.resetPowerOffFade();
}
} }
Pam { Pam {
@@ -214,6 +266,46 @@ Scope {
root.sharedPasswordBuffer = newPassword; root.sharedPasswordBuffer = newPassword;
} }
} }
Rectangle {
anchors.fill: parent
color: "black"
opacity: root.powerOffFadeTarget
visible: opacity > 0 || powerOffFadeTimer.running
Behavior on opacity {
enabled: !root.powerOffFadeInstant
NumberAnimation {
duration: SettingsData.fadeToDpmsGracePeriod * 1000
easing.type: Easing.OutCubic
}
}
MouseArea {
property real baselineX: -1
property real baselineY: -1
anchors.fill: parent
enabled: powerOffFadeTimer.running
hoverEnabled: enabled
onEnabledChanged: {
baselineX = -1;
baselineY = -1;
}
onPressed: root.cancelPowerOffFade()
onWheel: root.cancelPowerOffFade()
onPositionChanged: mouse => {
if (baselineX < 0) {
baselineX = mouse.x;
baselineY = mouse.y;
return;
}
if (Math.abs(mouse.x - baselineX) < 5 && Math.abs(mouse.y - baselineY) < 5)
return;
root.cancelPowerOffFade();
}
}
}
} }
} }
@@ -224,22 +316,19 @@ Scope {
notifyLockedHint(sessionLock.locked); notifyLockedHint(sessionLock.locked);
if (sessionLock.locked) { if (sessionLock.locked) {
pendingLock = false; pendingLock = false;
if (lockPowerOffArmed && SettingsData.lockScreenPowerOffMonitorsOnLock) { if (lockPowerOffArmed && powerOffOnLock)
IdleService.monitorsOff = true; beginPowerOff();
CompositorService.powerOffMonitors();
lockWakeAllowed = false;
lockWakeDebounce.restart();
}
lockPowerOffArmed = false; lockPowerOffArmed = false;
dpmsReapplyTimer.start();
return; return;
} }
lockWakeAllowed = false; lockWakeAllowed = false;
if (IdleService.monitorsOff && SettingsData.lockScreenPowerOffMonitorsOnLock) { resetPowerOffFade();
if (IdleService.monitorsOff && powerOffOnLock) {
IdleService.monitorsOff = false; IdleService.monitorsOff = false;
CompositorService.powerOnMonitors(); CompositorService.powerOnMonitors();
} }
IdleService.lockPowerOffRequested = false;
} }
} }
@@ -254,6 +343,10 @@ Scope {
root.lock(); root.lock();
} }
function lockAndOutputsOff() {
root.lockAndOutputsOff();
}
function unlock() { function unlock() {
root.unlock(); root.unlock();
} }
@@ -282,6 +375,26 @@ Scope {
} }
} }
Timer {
id: powerOffFadeTimer
interval: SettingsData.fadeToDpmsGracePeriod * 1000
repeat: false
onTriggered: root.applyMonitorsOff()
}
IdleMonitor {
timeout: 1
respectInhibitors: false
enabled: powerOffFadeTimer.running
onIsIdleChanged: {
if (isIdle)
return;
if (!powerOffFadeTimer.running)
return;
root.cancelPowerOffFade();
}
}
Timer { Timer {
id: dpmsReapplyTimer id: dpmsReapplyTimer
interval: 100 interval: 100
@@ -296,7 +409,7 @@ Scope {
onTriggered: { onTriggered: {
if (!sessionLock.locked) if (!sessionLock.locked)
return; return;
if (!SettingsData.lockScreenPowerOffMonitorsOnLock) if (!powerOffOnLock)
return; return;
if (!IdleService.monitorsOff) { if (!IdleService.monitorsOff) {
lockWakeAllowed = true; lockWakeAllowed = true;
+2 -1
View File
@@ -67,6 +67,7 @@ Singleton {
property var lockComponent: null property var lockComponent: null
property bool monitorsOff: false property bool monitorsOff: false
property bool isShellLocked: false property bool isShellLocked: false
property bool lockPowerOffRequested: false
function reapplyDpmsIfNeeded() { function reapplyDpmsIfNeeded() {
if (monitorsOff) if (monitorsOff)
@@ -146,7 +147,7 @@ Singleton {
id: lockWakeMonitor id: lockWakeMonitor
timeout: 1 timeout: 1
respectInhibitors: false respectInhibitors: false
enabled: root.enabled && root.isShellLocked && root.monitorsOff && SettingsData.lockScreenPowerOffMonitorsOnLock enabled: root.enabled && root.isShellLocked && root.monitorsOff && (SettingsData.lockScreenPowerOffMonitorsOnLock || root.lockPowerOffRequested)
onIsIdleChanged: { onIsIdleChanged: {
if (!isIdle && root.monitorsOff) if (!isIdle && root.monitorsOff)
root.requestMonitorOn(); root.requestMonitorOn();