mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 07:52:50 -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"
|
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 {
|
Variants {
|
||||||
model: SettingsData.getFilteredScreens("toast")
|
model: SettingsData.getFilteredScreens("toast")
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,8 @@ Item {
|
|||||||
implicitWidth: isVertical ? px(effectiveBarThickness + SettingsData.dankBarSpacing + (SettingsData.dankBarGothCornersEnabled ? _wingR : 0)) : 0
|
implicitWidth: isVertical ? px(effectiveBarThickness + SettingsData.dankBarSpacing + (SettingsData.dankBarGothCornersEnabled ? _wingR : 0)) : 0
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
|
||||||
|
property var nativeInhibitor: null
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
const fonts = Qt.fontFamilies()
|
const fonts = Qt.fontFamilies()
|
||||||
if (fonts.indexOf("Material Symbols Rounded") === -1) {
|
if (fonts.indexOf("Material Symbols Rounded") === -1) {
|
||||||
@@ -93,6 +95,10 @@ Item {
|
|||||||
|
|
||||||
updateGpuTempConfig()
|
updateGpuTempConfig()
|
||||||
Qt.callLater(() => Qt.callLater(forceWidgetRefresh))
|
Qt.callLater(() => Qt.callLater(forceWidgetRefresh))
|
||||||
|
|
||||||
|
if (SessionService.nativeInhibitorAvailable) {
|
||||||
|
createNativeInhibitor()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
@@ -124,6 +130,38 @@ Item {
|
|||||||
DgopService.nonNvidiaGpuTempEnabled = hasGpuTempWidget || SessionData.nonNvidiaGpuTempEnabled
|
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 {
|
Connections {
|
||||||
function onDankBarLeftWidgetsChanged() {
|
function onDankBarLeftWidgetsChanged() {
|
||||||
barWindow.updateGpuTempConfig()
|
barWindow.updateGpuTempConfig()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import QtQuick
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import Quickshell.Hyprland
|
import Quickshell.Hyprland
|
||||||
|
import Quickshell.Wayland
|
||||||
import qs.Common
|
import qs.Common
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
@@ -18,9 +19,18 @@ Singleton {
|
|||||||
property bool idleInhibited: false
|
property bool idleInhibited: false
|
||||||
property string inhibitReason: "Keep system awake"
|
property string inhibitReason: "Keep system awake"
|
||||||
|
|
||||||
|
readonly property bool nativeInhibitorAvailable: {
|
||||||
|
try {
|
||||||
|
return typeof IdleInhibitor !== "undefined"
|
||||||
|
} catch (e) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
detectElogindProcess.running = true
|
detectElogindProcess.running = true
|
||||||
detectHibernateProcess.running = true
|
detectHibernateProcess.running = true
|
||||||
|
console.log("SessionService: Native inhibitor available:", nativeInhibitorAvailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -132,6 +142,7 @@ Singleton {
|
|||||||
if (idleInhibited) {
|
if (idleInhibited) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.log("SessionService: Enabling idle inhibit (native:", nativeInhibitorAvailable, ")")
|
||||||
idleInhibited = true
|
idleInhibited = true
|
||||||
inhibitorChanged()
|
inhibitorChanged()
|
||||||
}
|
}
|
||||||
@@ -140,6 +151,7 @@ Singleton {
|
|||||||
if (!idleInhibited) {
|
if (!idleInhibited) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
console.log("SessionService: Disabling idle inhibit (native:", nativeInhibitorAvailable, ")")
|
||||||
idleInhibited = false
|
idleInhibited = false
|
||||||
inhibitorChanged()
|
inhibitorChanged()
|
||||||
}
|
}
|
||||||
@@ -155,7 +167,7 @@ Singleton {
|
|||||||
function setInhibitReason(reason) {
|
function setInhibitReason(reason) {
|
||||||
inhibitReason = reason
|
inhibitReason = reason
|
||||||
|
|
||||||
if (idleInhibited) {
|
if (idleInhibited && !nativeInhibitorAvailable) {
|
||||||
const wasActive = idleInhibited
|
const wasActive = idleInhibited
|
||||||
idleInhibited = false
|
idleInhibited = false
|
||||||
|
|
||||||
@@ -171,17 +183,22 @@ Singleton {
|
|||||||
id: idleInhibitProcess
|
id: idleInhibitProcess
|
||||||
|
|
||||||
command: {
|
command: {
|
||||||
if (!idleInhibited) {
|
if (!idleInhibited || nativeInhibitorAvailable) {
|
||||||
return ["true"]
|
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"]
|
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) {
|
onExited: function (exitCode) {
|
||||||
if (idleInhibited && exitCode !== 0) {
|
if (idleInhibited && exitCode !== 0 && !nativeInhibitorAvailable) {
|
||||||
console.warn("SessionService: Inhibitor process crashed with exit code:", exitCode)
|
console.warn("SessionService: Inhibitor process crashed with exit code:", exitCode)
|
||||||
idleInhibited = false
|
idleInhibited = false
|
||||||
ToastService.showWarning("Idle inhibitor failed")
|
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