mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-06 05:25:41 -05:00
use wayland idle-inhibit when available
This commit is contained in:
32
DMSShell.qml
32
DMSShell.qml
@@ -673,6 +673,38 @@ ShellRoot {
|
||||
target: "notepad"
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
function toggle(): string {
|
||||
SessionService.toggleIdleInhibit()
|
||||
return SessionService.idleInhibited ? "Idle inhibit enabled" : "Idle inhibit disabled"
|
||||
}
|
||||
|
||||
function enable(): string {
|
||||
SessionService.enableIdleInhibit()
|
||||
return "Idle inhibit enabled"
|
||||
}
|
||||
|
||||
function disable(): string {
|
||||
SessionService.disableIdleInhibit()
|
||||
return "Idle inhibit disabled"
|
||||
}
|
||||
|
||||
function status(): string {
|
||||
return SessionService.idleInhibited ? "Idle inhibit is enabled" : "Idle inhibit is disabled"
|
||||
}
|
||||
|
||||
function reason(newReason: string): string {
|
||||
if (!newReason) {
|
||||
return `Current reason: ${SessionService.inhibitReason}`
|
||||
}
|
||||
|
||||
SessionService.setInhibitReason(newReason)
|
||||
return `Inhibit reason set to: ${newReason}`
|
||||
}
|
||||
|
||||
target: "inhibit"
|
||||
}
|
||||
|
||||
Variants {
|
||||
model: SettingsData.getFilteredScreens("toast")
|
||||
|
||||
|
||||
@@ -74,6 +74,8 @@ Item {
|
||||
implicitWidth: isVertical ? px(effectiveBarThickness + SettingsData.dankBarSpacing + (SettingsData.dankBarGothCornersEnabled ? _wingR : 0)) : 0
|
||||
color: "transparent"
|
||||
|
||||
property var nativeInhibitor: null
|
||||
|
||||
Component.onCompleted: {
|
||||
const fonts = Qt.fontFamilies()
|
||||
if (fonts.indexOf("Material Symbols Rounded") === -1) {
|
||||
@@ -93,6 +95,10 @@ Item {
|
||||
|
||||
updateGpuTempConfig()
|
||||
Qt.callLater(() => Qt.callLater(forceWidgetRefresh))
|
||||
|
||||
if (SessionService.nativeInhibitorAvailable) {
|
||||
createNativeInhibitor()
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
@@ -124,6 +130,38 @@ Item {
|
||||
DgopService.nonNvidiaGpuTempEnabled = hasGpuTempWidget || SessionData.nonNvidiaGpuTempEnabled
|
||||
}
|
||||
|
||||
function createNativeInhibitor() {
|
||||
if (!SessionService.nativeInhibitorAvailable) {
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const qmlString = `
|
||||
import QtQuick
|
||||
import Quickshell.Wayland
|
||||
|
||||
IdleInhibitor {
|
||||
enabled: false
|
||||
}
|
||||
`
|
||||
|
||||
nativeInhibitor = Qt.createQmlObject(qmlString, barWindow, "DankBar.NativeInhibitor")
|
||||
nativeInhibitor.window = barWindow
|
||||
nativeInhibitor.enabled = Qt.binding(() => SessionService.idleInhibited)
|
||||
nativeInhibitor.enabledChanged.connect(function() {
|
||||
console.log("DankBar: Native inhibitor enabled changed to:", nativeInhibitor.enabled)
|
||||
if (SessionService.idleInhibited !== nativeInhibitor.enabled) {
|
||||
SessionService.idleInhibited = nativeInhibitor.enabled
|
||||
SessionService.inhibitorChanged()
|
||||
}
|
||||
})
|
||||
console.log("DankBar: Created native Wayland IdleInhibitor for", barWindow.screenName)
|
||||
} catch (e) {
|
||||
console.warn("DankBar: Failed to create native IdleInhibitor:", e)
|
||||
nativeInhibitor = null
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
function onDankBarLeftWidgetsChanged() {
|
||||
barWindow.updateGpuTempConfig()
|
||||
|
||||
@@ -6,6 +6,7 @@ import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Hyprland
|
||||
import Quickshell.Wayland
|
||||
import qs.Common
|
||||
|
||||
Singleton {
|
||||
@@ -18,9 +19,18 @@ Singleton {
|
||||
property bool idleInhibited: false
|
||||
property string inhibitReason: "Keep system awake"
|
||||
|
||||
readonly property bool nativeInhibitorAvailable: {
|
||||
try {
|
||||
return typeof IdleInhibitor !== "undefined"
|
||||
} catch (e) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
detectElogindProcess.running = true
|
||||
detectHibernateProcess.running = true
|
||||
console.log("SessionService: Native inhibitor available:", nativeInhibitorAvailable)
|
||||
}
|
||||
|
||||
|
||||
@@ -132,6 +142,7 @@ Singleton {
|
||||
if (idleInhibited) {
|
||||
return
|
||||
}
|
||||
console.log("SessionService: Enabling idle inhibit (native:", nativeInhibitorAvailable, ")")
|
||||
idleInhibited = true
|
||||
inhibitorChanged()
|
||||
}
|
||||
@@ -140,6 +151,7 @@ Singleton {
|
||||
if (!idleInhibited) {
|
||||
return
|
||||
}
|
||||
console.log("SessionService: Disabling idle inhibit (native:", nativeInhibitorAvailable, ")")
|
||||
idleInhibited = false
|
||||
inhibitorChanged()
|
||||
}
|
||||
@@ -155,7 +167,7 @@ Singleton {
|
||||
function setInhibitReason(reason) {
|
||||
inhibitReason = reason
|
||||
|
||||
if (idleInhibited) {
|
||||
if (idleInhibited && !nativeInhibitorAvailable) {
|
||||
const wasActive = idleInhibited
|
||||
idleInhibited = false
|
||||
|
||||
@@ -171,17 +183,22 @@ Singleton {
|
||||
id: idleInhibitProcess
|
||||
|
||||
command: {
|
||||
if (!idleInhibited) {
|
||||
if (!idleInhibited || nativeInhibitorAvailable) {
|
||||
return ["true"]
|
||||
}
|
||||
|
||||
console.log("SessionService: Starting systemd/elogind inhibit process")
|
||||
return [isElogind ? "elogind-inhibit" : "systemd-inhibit", "--what=idle", "--who=quickshell", `--why=${inhibitReason}`, "--mode=block", "sleep", "infinity"]
|
||||
}
|
||||
|
||||
running: idleInhibited
|
||||
running: idleInhibited && !nativeInhibitorAvailable
|
||||
|
||||
onRunningChanged: {
|
||||
console.log("SessionService: Inhibit process running:", running, "(native:", nativeInhibitorAvailable, ")")
|
||||
}
|
||||
|
||||
onExited: function (exitCode) {
|
||||
if (idleInhibited && exitCode !== 0) {
|
||||
if (idleInhibited && exitCode !== 0 && !nativeInhibitorAvailable) {
|
||||
console.warn("SessionService: Inhibitor process crashed with exit code:", exitCode)
|
||||
idleInhibited = false
|
||||
ToastService.showWarning("Idle inhibitor failed")
|
||||
@@ -189,35 +206,4 @@ Singleton {
|
||||
}
|
||||
}
|
||||
|
||||
IpcHandler {
|
||||
function toggle(): string {
|
||||
root.toggleIdleInhibit()
|
||||
return root.idleInhibited ? "Idle inhibit enabled" : "Idle inhibit disabled"
|
||||
}
|
||||
|
||||
function enable(): string {
|
||||
root.enableIdleInhibit()
|
||||
return "Idle inhibit enabled"
|
||||
}
|
||||
|
||||
function disable(): string {
|
||||
root.disableIdleInhibit()
|
||||
return "Idle inhibit disabled"
|
||||
}
|
||||
|
||||
function status(): string {
|
||||
return root.idleInhibited ? "Idle inhibit is enabled" : "Idle inhibit is disabled"
|
||||
}
|
||||
|
||||
function reason(newReason: string): string {
|
||||
if (!newReason) {
|
||||
return `Current reason: ${root.inhibitReason}`
|
||||
}
|
||||
|
||||
root.setInhibitReason(newReason)
|
||||
return `Inhibit reason set to: ${newReason}`
|
||||
}
|
||||
|
||||
target: "inhibit"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user