1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-29 16:02:51 -05:00

power: replace hibernate with "suspend behavior" opt

This commit is contained in:
bbedward
2025-11-04 13:05:48 -05:00
parent 20116b3933
commit 9e4b53e20b
5 changed files with 59 additions and 50 deletions

View File

@@ -34,6 +34,12 @@ Singleton {
Custom Custom
} }
enum SuspendBehavior {
Suspend,
Hibernate,
SuspendThenHibernate
}
readonly property string defaultFontFamily: "Inter Variable" readonly property string defaultFontFamily: "Inter Variable"
readonly property string defaultMonoFontFamily: "Fira Code" readonly property string defaultMonoFontFamily: "Fira Code"
readonly property string _homeUrl: StandardPaths.writableLocation(StandardPaths.HomeLocation) readonly property string _homeUrl: StandardPaths.writableLocation(StandardPaths.HomeLocation)
@@ -213,11 +219,11 @@ Singleton {
property int acMonitorTimeout: 0 property int acMonitorTimeout: 0
property int acLockTimeout: 0 property int acLockTimeout: 0
property int acSuspendTimeout: 0 property int acSuspendTimeout: 0
property int acHibernateTimeout: 0 property int acSuspendBehavior: SettingsData.SuspendBehavior.Suspend
property int batteryMonitorTimeout: 0 property int batteryMonitorTimeout: 0
property int batteryLockTimeout: 0 property int batteryLockTimeout: 0
property int batterySuspendTimeout: 0 property int batterySuspendTimeout: 0
property int batteryHibernateTimeout: 0 property int batterySuspendBehavior: SettingsData.SuspendBehavior.Suspend
property bool lockBeforeSuspend: false property bool lockBeforeSuspend: false
property bool loginctlLockIntegration: true property bool loginctlLockIntegration: true
property string launchPrefix: "" property string launchPrefix: ""

View File

@@ -136,11 +136,11 @@ var SPEC = {
acMonitorTimeout: { def: 0 }, acMonitorTimeout: { def: 0 },
acLockTimeout: { def: 0 }, acLockTimeout: { def: 0 },
acSuspendTimeout: { def: 0 }, acSuspendTimeout: { def: 0 },
acHibernateTimeout: { def: 0 }, acSuspendBehavior: { def: 0 },
batteryMonitorTimeout: { def: 0 }, batteryMonitorTimeout: { def: 0 },
batteryLockTimeout: { def: 0 }, batteryLockTimeout: { def: 0 },
batterySuspendTimeout: { def: 0 }, batterySuspendTimeout: { def: 0 },
batteryHibernateTimeout: { def: 0 }, batterySuspendBehavior: { def: 0 },
lockBeforeSuspend: { def: false }, lockBeforeSuspend: { def: false },
loginctlLockIntegration: { def: true }, loginctlLockIntegration: { def: true },
launchPrefix: { def: "" }, launchPrefix: { def: "" },

View File

@@ -266,38 +266,44 @@ Item {
} }
} }
DankDropdown { Column {
id: hibernateDropdown width: parent.width
property var timeoutOptions: ["Never", "1 minute", "2 minutes", "3 minutes", "5 minutes", "10 minutes", "15 minutes", "20 minutes", "30 minutes", "1 hour", "1 hour 30 minutes", "2 hours", "3 hours"] spacing: Theme.spacingS
property var timeoutValues: [0, 60, 120, 180, 300, 600, 900, 1200, 1800, 3600, 5400, 7200, 10800]
text: I18n.tr("Hibernate system after")
options: timeoutOptions
visible: SessionService.hibernateSupported visible: SessionService.hibernateSupported
Connections { StyledText {
target: powerCategory text: I18n.tr("Suspend behavior")
function onCurrentIndexChanged() { font.pixelSize: Theme.fontSizeMedium
const currentTimeout = powerCategory.currentIndex === 0 ? SettingsData.acHibernateTimeout : SettingsData.batteryHibernateTimeout color: Theme.surfaceText
const index = hibernateDropdown.timeoutValues.indexOf(currentTimeout) }
hibernateDropdown.currentValue = index >= 0 ? hibernateDropdown.timeoutOptions[index] : "Never"
DankButtonGroup {
id: suspendBehaviorSelector
anchors.horizontalCenter: parent.horizontalCenter
model: ["Suspend", "Hibernate", "Suspend then Hibernate"]
selectionMode: "single"
checkEnabled: false
Connections {
target: powerCategory
function onCurrentIndexChanged() {
const behavior = powerCategory.currentIndex === 0 ? SettingsData.acSuspendBehavior : SettingsData.batterySuspendBehavior
suspendBehaviorSelector.currentIndex = behavior
}
} }
}
Component.onCompleted: { Component.onCompleted: {
const currentTimeout = powerCategory.currentIndex === 0 ? SettingsData.acHibernateTimeout : SettingsData.batteryHibernateTimeout const behavior = powerCategory.currentIndex === 0 ? SettingsData.acSuspendBehavior : SettingsData.batterySuspendBehavior
const index = timeoutValues.indexOf(currentTimeout) currentIndex = behavior
currentValue = index >= 0 ? timeoutOptions[index] : "Never" }
}
onValueChanged: value => { onSelectionChanged: (index, selected) => {
const index = timeoutOptions.indexOf(value) if (selected) {
if (index >= 0) { if (powerCategory.currentIndex === 0) {
const timeout = timeoutValues[index] SettingsData.set("acSuspendBehavior", index)
if (powerCategory.currentIndex === 0) { } else {
SettingsData.set("acHibernateTimeout", timeout) SettingsData.set("batterySuspendBehavior", index)
} else { }
SettingsData.set("batteryHibernateTimeout", timeout)
} }
} }
} }

View File

@@ -26,12 +26,11 @@ Singleton {
readonly property int monitorTimeout: isOnBattery ? SettingsData.batteryMonitorTimeout : SettingsData.acMonitorTimeout readonly property int monitorTimeout: isOnBattery ? SettingsData.batteryMonitorTimeout : SettingsData.acMonitorTimeout
readonly property int lockTimeout: isOnBattery ? SettingsData.batteryLockTimeout : SettingsData.acLockTimeout readonly property int lockTimeout: isOnBattery ? SettingsData.batteryLockTimeout : SettingsData.acLockTimeout
readonly property int suspendTimeout: isOnBattery ? SettingsData.batterySuspendTimeout : SettingsData.acSuspendTimeout readonly property int suspendTimeout: isOnBattery ? SettingsData.batterySuspendTimeout : SettingsData.acSuspendTimeout
readonly property int hibernateTimeout: isOnBattery ? SettingsData.batteryHibernateTimeout : SettingsData.acHibernateTimeout readonly property int suspendBehavior: isOnBattery ? SettingsData.batterySuspendBehavior : SettingsData.acSuspendBehavior
onMonitorTimeoutChanged: _rearmIdleMonitors() onMonitorTimeoutChanged: _rearmIdleMonitors()
onLockTimeoutChanged: _rearmIdleMonitors() onLockTimeoutChanged: _rearmIdleMonitors()
onSuspendTimeoutChanged: _rearmIdleMonitors() onSuspendTimeoutChanged: _rearmIdleMonitors()
onHibernateTimeoutChanged: _rearmIdleMonitors()
function _rearmIdleMonitors() { function _rearmIdleMonitors() {
_enableGate = false _enableGate = false
@@ -42,12 +41,10 @@ Singleton {
signal requestMonitorOff() signal requestMonitorOff()
signal requestMonitorOn() signal requestMonitorOn()
signal requestSuspend() signal requestSuspend()
signal requestHibernate()
property var monitorOffMonitor: null property var monitorOffMonitor: null
property var lockMonitor: null property var lockMonitor: null
property var suspendMonitor: null property var suspendMonitor: null
property var hibernateMonitor: null
function wake() { function wake() {
requestMonitorOn() requestMonitorOn()
@@ -102,16 +99,6 @@ Singleton {
root.requestSuspend() root.requestSuspend()
} }
}) })
hibernateMonitor = Qt.createQmlObject(qmlString, root, "IdleService.HibernateMonitor")
hibernateMonitor.enabled = Qt.binding(() => root._enableGate && root.enabled && root.idleMonitorAvailable && root.hibernateTimeout > 0)
hibernateMonitor.respectInhibitors = Qt.binding(() => root.respectInhibitors)
hibernateMonitor.timeout = Qt.binding(() => root.hibernateTimeout)
hibernateMonitor.isIdleChanged.connect(function() {
if (hibernateMonitor.isIdle) {
root.requestHibernate()
}
})
} catch (e) { } catch (e) {
console.warn("IdleService: Error creating IdleMonitors:", e) console.warn("IdleService: Error creating IdleMonitors:", e)
} }
@@ -128,11 +115,7 @@ Singleton {
} }
function onRequestSuspend() { function onRequestSuspend() {
SessionService.suspend() SessionService.suspendWithBehavior(root.suspendBehavior)
}
function onRequestHibernate() {
SessionService.hibernate()
} }
} }

View File

@@ -217,6 +217,20 @@ Singleton {
} }
} }
function suspendThenHibernate() {
Quickshell.execDetached([isElogind ? "loginctl" : "systemctl", "suspend-then-hibernate"])
}
function suspendWithBehavior(behavior) {
if (behavior === SettingsData.SuspendBehavior.Hibernate) {
hibernate()
} else if (behavior === SettingsData.SuspendBehavior.SuspendThenHibernate) {
suspendThenHibernate()
} else {
suspend()
}
}
function reboot() { function reboot() {
if (SettingsData.customPowerActionReboot.length === 0) { if (SettingsData.customPowerActionReboot.length === 0) {
Quickshell.execDetached([isElogind ? "loginctl" : "systemctl", "reboot"]) Quickshell.execDetached([isElogind ? "loginctl" : "systemctl", "reboot"])