mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-24 21:42:51 -05:00
102
quickshell/Modules/Lock/FadeToDpmsWindow.qml
Normal file
102
quickshell/Modules/Lock/FadeToDpmsWindow.qml
Normal file
@@ -0,0 +1,102 @@
|
||||
pragma ComponentBehavior: Bound
|
||||
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import qs.Common
|
||||
|
||||
PanelWindow {
|
||||
id: root
|
||||
|
||||
property bool active: false
|
||||
|
||||
signal fadeCompleted
|
||||
signal fadeCancelled
|
||||
|
||||
visible: active
|
||||
color: "transparent"
|
||||
|
||||
WlrLayershell.namespace: "dms:fade-to-dpms"
|
||||
WlrLayershell.layer: WlrLayershell.Overlay
|
||||
WlrLayershell.exclusiveZone: -1
|
||||
WlrLayershell.keyboardFocus: active ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
|
||||
|
||||
anchors {
|
||||
left: true
|
||||
right: true
|
||||
top: true
|
||||
bottom: true
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
id: fadeOverlay
|
||||
anchors.fill: parent
|
||||
color: "black"
|
||||
opacity: 0
|
||||
|
||||
onOpacityChanged: {
|
||||
if (opacity >= 0.99 && root.active) {
|
||||
root.fadeCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SequentialAnimation {
|
||||
id: fadeSeq
|
||||
running: false
|
||||
|
||||
NumberAnimation {
|
||||
target: fadeOverlay
|
||||
property: "opacity"
|
||||
from: 0.0
|
||||
to: 1.0
|
||||
duration: SettingsData.fadeToDpmsGracePeriod * 1000
|
||||
easing.type: Easing.OutCubic
|
||||
}
|
||||
}
|
||||
|
||||
function startFade() {
|
||||
if (!SettingsData.fadeToDpmsEnabled)
|
||||
return;
|
||||
active = true;
|
||||
fadeOverlay.opacity = 0.0;
|
||||
fadeSeq.stop();
|
||||
fadeSeq.start();
|
||||
}
|
||||
|
||||
function cancelFade() {
|
||||
fadeSeq.stop();
|
||||
fadeOverlay.opacity = 0.0;
|
||||
active = false;
|
||||
fadeCancelled();
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
enabled: root.active
|
||||
onClicked: root.cancelFade()
|
||||
onPressed: root.cancelFade()
|
||||
}
|
||||
|
||||
FocusScope {
|
||||
anchors.fill: parent
|
||||
focus: root.active
|
||||
|
||||
Keys.onPressed: event => {
|
||||
root.cancelFade();
|
||||
event.accepted = true;
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
if (active) {
|
||||
forceActiveFocus();
|
||||
}
|
||||
}
|
||||
|
||||
onActiveChanged: {
|
||||
if (active) {
|
||||
forceActiveFocus();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,15 +23,12 @@ Scope {
|
||||
Quickshell.execDetached(["sh", "-c", SettingsData.customPowerActionLock]);
|
||||
return;
|
||||
}
|
||||
shouldLock = true;
|
||||
if (!processingExternalEvent && SettingsData.loginctlLockIntegration && DMSService.isConnected) {
|
||||
DMSService.lockSession(response => {
|
||||
if (response.error) {
|
||||
console.warn("Lock: Failed to call loginctl.lock:", response.error);
|
||||
shouldLock = true;
|
||||
}
|
||||
if (response.error)
|
||||
console.warn("Lock: loginctl.lock failed:", response.error);
|
||||
});
|
||||
} else {
|
||||
shouldLock = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,6 +78,11 @@ Scope {
|
||||
|
||||
locked: shouldLock
|
||||
|
||||
onLockedChanged: {
|
||||
if (locked)
|
||||
dpmsReapplyTimer.start();
|
||||
}
|
||||
|
||||
WlSessionLockSurface {
|
||||
id: lockSurface
|
||||
|
||||
@@ -120,15 +122,12 @@ Scope {
|
||||
target: "lock"
|
||||
|
||||
function lock() {
|
||||
if (!root.processingExternalEvent && SettingsData.loginctlLockIntegration && DMSService.isConnected) {
|
||||
root.shouldLock = true;
|
||||
if (SettingsData.loginctlLockIntegration && DMSService.isConnected) {
|
||||
DMSService.lockSession(response => {
|
||||
if (response.error) {
|
||||
console.warn("Lock: Failed to call loginctl.lock:", response.error);
|
||||
root.shouldLock = true;
|
||||
}
|
||||
if (response.error)
|
||||
console.warn("Lock: loginctl.lock failed:", response.error);
|
||||
});
|
||||
} else {
|
||||
root.shouldLock = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,4 +139,11 @@ Scope {
|
||||
return sessionLock.locked;
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: dpmsReapplyTimer
|
||||
interval: 100
|
||||
repeat: false
|
||||
onTriggered: IdleService.reapplyDpmsIfNeeded()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user