mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2025-12-08 06:25:37 -05:00
GPU warning
This commit is contained in:
@@ -71,6 +71,7 @@ Item {
|
|||||||
"text": "GPU Temperature",
|
"text": "GPU Temperature",
|
||||||
"description": "GPU temperature display",
|
"description": "GPU temperature display",
|
||||||
"icon": "auto_awesome_mosaic",
|
"icon": "auto_awesome_mosaic",
|
||||||
|
"warning": "This widget prevents GPU power off states, which can significantly impact battery life on laptops. It is not recommended to use this on laptops with hybrid graphics.",
|
||||||
"enabled": true
|
"enabled": true
|
||||||
}, {
|
}, {
|
||||||
"id": "systemTray",
|
"id": "systemTray",
|
||||||
|
|||||||
@@ -185,6 +185,59 @@ Column {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Item {
|
||||||
|
width: 32
|
||||||
|
height: 32
|
||||||
|
visible: modelData.id === "gpuTemp" && modelData.warning
|
||||||
|
|
||||||
|
DankIcon {
|
||||||
|
name: "warning"
|
||||||
|
size: 20
|
||||||
|
color: Theme.error
|
||||||
|
anchors.centerIn: parent
|
||||||
|
opacity: warningArea.containsMouse ? 1.0 : 0.8
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseArea {
|
||||||
|
id: warningArea
|
||||||
|
anchors.fill: parent
|
||||||
|
hoverEnabled: true
|
||||||
|
cursorShape: Qt.PointingHandCursor
|
||||||
|
}
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: warningTooltip
|
||||||
|
width: warningTooltipText.contentWidth + Theme.spacingM * 2
|
||||||
|
height: warningTooltipText.contentHeight + Theme.spacingS * 2
|
||||||
|
radius: Theme.cornerRadius
|
||||||
|
color: Theme.surfaceContainer
|
||||||
|
border.color: Theme.outline
|
||||||
|
border.width: 1
|
||||||
|
visible: warningArea.containsMouse
|
||||||
|
opacity: visible ? 1 : 0
|
||||||
|
x: -width - Theme.spacingS
|
||||||
|
y: (parent.height - height) / 2
|
||||||
|
z: 100
|
||||||
|
|
||||||
|
StyledText {
|
||||||
|
id: warningTooltipText
|
||||||
|
anchors.centerIn: parent
|
||||||
|
text: modelData.warning || "Warning"
|
||||||
|
font.pixelSize: Theme.fontSizeSmall
|
||||||
|
color: Theme.surfaceText
|
||||||
|
width: 300
|
||||||
|
wrapMode: Text.WordWrap
|
||||||
|
}
|
||||||
|
|
||||||
|
Behavior on opacity {
|
||||||
|
NumberAnimation {
|
||||||
|
duration: Theme.shortDuration
|
||||||
|
easing.type: Theme.standardEasing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
width: 32
|
width: 32
|
||||||
height: 32
|
height: 32
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import QtQuick
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
import qs.Services
|
import qs.Services
|
||||||
|
import qs.Common
|
||||||
|
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
@@ -76,6 +77,61 @@ Singleton {
|
|||||||
property string biosVersion: ""
|
property string biosVersion: ""
|
||||||
property var availableGpus: []
|
property var availableGpus: []
|
||||||
|
|
||||||
|
// Check if any GPU temperature widgets are configured
|
||||||
|
function hasGpuTempWidgets() {
|
||||||
|
const allWidgets = [...(SettingsData.topBarLeftWidgets || []),
|
||||||
|
...(SettingsData.topBarCenterWidgets || []),
|
||||||
|
...(SettingsData.topBarRightWidgets || [])]
|
||||||
|
|
||||||
|
return allWidgets.some(widget => {
|
||||||
|
const widgetId = typeof widget === "string" ? widget : widget.id
|
||||||
|
const widgetEnabled = typeof widget === "string" ? true : (widget.enabled !== false)
|
||||||
|
return widgetId === "gpuTemp" && widgetEnabled
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any NVIDIA GPU temperature widgets are configured
|
||||||
|
function hasNvidiaGpuTempWidgets() {
|
||||||
|
if (!hasGpuTempWidgets()) return false
|
||||||
|
|
||||||
|
const allWidgets = [...(SettingsData.topBarLeftWidgets || []),
|
||||||
|
...(SettingsData.topBarCenterWidgets || []),
|
||||||
|
...(SettingsData.topBarRightWidgets || [])]
|
||||||
|
|
||||||
|
return allWidgets.some(widget => {
|
||||||
|
const widgetId = typeof widget === "string" ? widget : widget.id
|
||||||
|
const widgetEnabled = typeof widget === "string" ? true : (widget.enabled !== false)
|
||||||
|
if (widgetId !== "gpuTemp" || !widgetEnabled) return false
|
||||||
|
|
||||||
|
const selectedGpuIndex = typeof widget === "string" ? 0 : (widget.selectedGpuIndex || 0)
|
||||||
|
if (availableGpus && availableGpus[selectedGpuIndex]) {
|
||||||
|
return availableGpus[selectedGpuIndex].driver === "nvidia"
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if any non-NVIDIA GPU temperature widgets are configured
|
||||||
|
function hasNonNvidiaGpuTempWidgets() {
|
||||||
|
if (!hasGpuTempWidgets()) return false
|
||||||
|
|
||||||
|
const allWidgets = [...(SettingsData.topBarLeftWidgets || []),
|
||||||
|
...(SettingsData.topBarCenterWidgets || []),
|
||||||
|
...(SettingsData.topBarRightWidgets || [])]
|
||||||
|
|
||||||
|
return allWidgets.some(widget => {
|
||||||
|
const widgetId = typeof widget === "string" ? widget : widget.id
|
||||||
|
const widgetEnabled = typeof widget === "string" ? true : (widget.enabled !== false)
|
||||||
|
if (widgetId !== "gpuTemp" || !widgetEnabled) return false
|
||||||
|
|
||||||
|
const selectedGpuIndex = typeof widget === "string" ? 0 : (widget.selectedGpuIndex || 0)
|
||||||
|
if (availableGpus && availableGpus[selectedGpuIndex]) {
|
||||||
|
return availableGpus[selectedGpuIndex].driver !== "nvidia"
|
||||||
|
}
|
||||||
|
return true // Default to true if GPU not found yet (static data might not be loaded)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function addRef() {
|
function addRef() {
|
||||||
refCount++
|
refCount++
|
||||||
if (refCount === 1) {
|
if (refCount === 1) {
|
||||||
@@ -642,7 +698,10 @@ readonly property string staticDataScript: `exec 2>/dev/null
|
|||||||
readonly property string dynamicDataScript: `
|
readonly property string dynamicDataScript: `
|
||||||
sort_key=\${1:-cpu}
|
sort_key=\${1:-cpu}
|
||||||
max_procs=\${2:-20}
|
max_procs=\${2:-20}
|
||||||
|
collect_gpu_temps=\${3:-0}
|
||||||
|
collect_nvidia_only=\${4:-0}
|
||||||
|
|
||||||
|
collect_non_nvidia=\${5:-1}
|
||||||
json_escape() { sed -e 's/\\\\/\\\\\\\\/g' -e 's/"/\\\\"/g' -e ':a;N;$!ba;s/\\n/\\\\n/g'; }
|
json_escape() { sed -e 's/\\\\/\\\\\\\\/g' -e 's/"/\\\\"/g' -e ':a;N;$!ba;s/\\n/\\\\n/g'; }
|
||||||
|
|
||||||
printf "{"
|
printf "{"
|
||||||
@@ -833,27 +892,30 @@ readonly property string staticDataScript: `exec 2>/dev/null
|
|||||||
printf ']',
|
printf ']',
|
||||||
|
|
||||||
printf '"gputemps":['
|
printf '"gputemps":['
|
||||||
gfirst=1
|
if [ "$collect_gpu_temps" = "1" ]; then
|
||||||
tmp_gpu=$(mktemp)
|
gfirst=1
|
||||||
|
tmp_gpu=$(mktemp)
|
||||||
|
|
||||||
# Gather GPU temperatures only
|
# Gather GPU temperatures only
|
||||||
for card in /sys/class/drm/card*; do
|
for card in /sys/class/drm/card*; do
|
||||||
[ -e "$card/device/driver" ] || continue
|
[ -e "$card/device/driver" ] || continue
|
||||||
|
|
||||||
drv=$(basename "$(readlink -f "$card/device/driver")")
|
drv=$(basename "$(readlink -f "$card/device/driver")")
|
||||||
drv=\${drv##*/}
|
drv=\${drv##*/}
|
||||||
|
|
||||||
# Temperature
|
# Temperature (only scan hwmon for non-NVIDIA GPUs)
|
||||||
hw=""; temp="0"
|
hw=""; temp="0"
|
||||||
for h in "$card/device"/hwmon/hwmon*; do
|
if [ "$collect_non_nvidia" = "1" ]; then
|
||||||
[ -e "$h/temp1_input" ] || continue
|
for h in "$card/device"/hwmon/hwmon*; do
|
||||||
hw=$(basename "$h")
|
[ -e "$h/temp1_input" ] || continue
|
||||||
temp=$(awk '{printf "%.1f",$1/1000}' "$h/temp1_input" 2>/dev/null || echo "0")
|
hw=$(basename "$h")
|
||||||
break
|
temp=$(awk '{printf "%.1f",$1/1000}' "$h/temp1_input" 2>/dev/null || echo "0")
|
||||||
done
|
break
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
# NVIDIA temperature fallback
|
# NVIDIA temperature fallback
|
||||||
if [ "$drv" = "nvidia" ] && [ "$temp" = "0" ] && command -v nvidia-smi >/dev/null 2>&1; then
|
if [ "$drv" = "nvidia" ] && [ "$temp" = "0" ] && [ "$collect_nvidia_only" = "1" ] && command -v nvidia-smi >/dev/null 2>&1; then
|
||||||
t=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits 2>/dev/null | head -1)
|
t=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits 2>/dev/null | head -1)
|
||||||
[ -n "$t" ] && { temp="$t"; hw="\${hw:-nvidia}"; }
|
[ -n "$t" ] && { temp="$t"; hw="\${hw:-nvidia}"; }
|
||||||
fi
|
fi
|
||||||
@@ -866,7 +928,7 @@ readonly property string staticDataScript: `exec 2>/dev/null
|
|||||||
done
|
done
|
||||||
|
|
||||||
# Fallback if no DRM cards found but nvidia-smi is available
|
# Fallback if no DRM cards found but nvidia-smi is available
|
||||||
if [ $gfirst -eq 1 ]; then
|
if [ $gfirst -eq 1 ] && [ \"$collect_nvidia_only\" = \"1\" ]; then
|
||||||
if command -v nvidia-smi >/dev/null 2>&1; then
|
if command -v nvidia-smi >/dev/null 2>&1; then
|
||||||
temp=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits 2>/dev/null | head -1)
|
temp=$(nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits 2>/dev/null | head -1)
|
||||||
[ -n "$temp" ] && {
|
[ -n "$temp" ] && {
|
||||||
@@ -876,7 +938,8 @@ readonly property string staticDataScript: `exec 2>/dev/null
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rm -f "$tmp_gpu"
|
rm -f "$tmp_gpu"
|
||||||
|
fi
|
||||||
printf ']'
|
printf ']'
|
||||||
|
|
||||||
printf "}\\n"`
|
printf "}\\n"`
|
||||||
@@ -916,8 +979,8 @@ readonly property string staticDataScript: `exec 2>/dev/null
|
|||||||
|
|
||||||
Process {
|
Process {
|
||||||
id: dynamicStatsProcess
|
id: dynamicStatsProcess
|
||||||
command: ["bash", "-c", "bash -s \"$1\" \"$2\" <<'QS_EOF'\n"
|
command: ["bash", "-c", "bash -s \"$1\" \"$2\" \"$3\" \"$4\" \"$5\" <<'QS_EOF'\n"
|
||||||
+ root.dynamicDataScript + "\nQS_EOF\n", root.sortBy, String(root.maxProcesses)]
|
+ root.dynamicDataScript + "\nQS_EOF\n", "-", root.sortBy, String(root.maxProcesses), root.hasGpuTempWidgets() ? "1" : "0", root.hasNvidiaGpuTempWidgets() ? "1" : "0", root.hasNonNvidiaGpuTempWidgets() ? "1" : "0"]
|
||||||
running: false
|
running: false
|
||||||
onExited: exitCode => {
|
onExited: exitCode => {
|
||||||
if (exitCode !== 0) {
|
if (exitCode !== 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user