Make the weather location and graphics device choosable
The last two values that could only be changed by editing a file. Weather was pinned to hardcoded coordinates, so the card could not be pointed anywhere else. It is a location search now, not latitude and longitude fields: nobody knows their own coordinates, and a control that demands them is one nobody uses. Open-Meteo's geocoding endpoint needs no key, the same reason the forecast already uses them. Only the search term leaves the machine -- the stored place name is a label -- and coordinates are rounded to four decimals, far finer than a weather reading resolves and coarse enough to keep a precise home location out of the settings file. The graphics readout was hardcoded to card1. This machine has two amdgpu cards, discrete and integrated, so that was right only by luck, and the path is meaningless on any other machine. GPUs are enumerated with a readable name from lspci, since sysfs exposes only numeric ids, and the picker appears only when there is more than one to choose between. A stored path the machine does not have is refused and reported rather than silently measuring nothing. Also merges the per-application notification rules UI. Its three commits were believed integrated but the page half was not actually in the tree: main had the service side in Notifs.qml and zero references to setAppRule in NotificationsPage. Ancestry is not content. Claude-Session: https://claude.ai/code/session_01BRvzt4H8XXLPVH5MyYdk9L
This commit is contained in:
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Enumerates GPUs that can report utilisation, with a readable name for each.
|
||||
#
|
||||
# Panama's vitals readout needs one specific sysfs file, and the card numbering
|
||||
# is neither stable across machines nor meaningful to a person: this box has
|
||||
# card1 and card2, both amdgpu, one discrete and one integrated. Picking a
|
||||
# number blindly shows whichever the kernel happened to enumerate first.
|
||||
#
|
||||
# Names come from lspci where available, because the sysfs device directory
|
||||
# exposes only numeric vendor/device ids.
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
first=true
|
||||
printf '['
|
||||
|
||||
for busy in /sys/class/drm/card*/device/gpu_busy_percent; do
|
||||
[[ -r "$busy" ]] || continue
|
||||
|
||||
device_dir="$(dirname "$busy")"
|
||||
card="$(basename "$(dirname "$device_dir")")"
|
||||
|
||||
# The device directory is a symlink into the PCI tree; its target's basename
|
||||
# is the PCI address lspci wants.
|
||||
pci="$(basename "$(readlink -f "$device_dir")" 2>/dev/null || true)"
|
||||
name=""
|
||||
if [[ -n "$pci" ]] && command -v lspci >/dev/null 2>&1; then
|
||||
# Strip the leading domain: lspci -s wants 00:02.0, sysfs gives 0000:00:02.0
|
||||
short="${pci#*:}"
|
||||
name="$(lspci -s "$short" 2>/dev/null | sed -E 's/^[^ ]+ [^:]+: //' | head -1)"
|
||||
fi
|
||||
if [[ -z "$name" ]]; then
|
||||
driver="$(sed -n 's/^DRIVER=//p' "$device_dir/uevent" 2>/dev/null | head -1)"
|
||||
name="${driver:-Graphics} ($card)"
|
||||
fi
|
||||
|
||||
reading="$(cat "$busy" 2>/dev/null || printf '')"
|
||||
[[ "$reading" =~ ^[0-9]+$ ]] || reading=-1
|
||||
|
||||
[[ "$first" == true ]] || printf ','
|
||||
first=false
|
||||
printf '{"card":"%s","path":"%s","name":%s,"busy":%s}' \
|
||||
"$card" "$busy" "$(printf '%s' "$name" | jq -Rs .)" "$reading"
|
||||
done
|
||||
|
||||
printf ']\n'
|
||||
Reference in New Issue
Block a user