From 0ba6bbd1818831a2d7a472c295aff06552d7eedd Mon Sep 17 00:00:00 2001 From: Tetardtek Date: Mon, 23 Feb 2026 22:16:05 +0100 Subject: [PATCH] feat(waybar): modules cpu-temp et disks portables par scripts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remplace les modules natifs temperature (thermal-zone codé en dur) et disk (chemin fixe /) par des custom scripts auto-détectés. - cpu-temp.sh : détecte x86_pkg_temp / k10temp / coretemp via thermal_zone et hwmon, émet warning à 65° et critical à 80° - disks.sh : liste tous les FS montés réels, exclut snap/tmpfs/efi, affiche icône selon le point de montage, tooltip détaillé CSS : styles warning + hover ajoutés pour les deux modules --- INSTALL/configs/waybar/config | 29 ++++++----- INSTALL/configs/waybar/scripts/cpu-temp.sh | 43 ++++++++++++++++ INSTALL/configs/waybar/scripts/disks.sh | 58 ++++++++++++++++++++++ INSTALL/themes/violet-chaton-waybar.css | 17 +++++-- 4 files changed, 129 insertions(+), 18 deletions(-) create mode 100755 INSTALL/configs/waybar/scripts/cpu-temp.sh create mode 100755 INSTALL/configs/waybar/scripts/disks.sh diff --git a/INSTALL/configs/waybar/config b/INSTALL/configs/waybar/config index 611082e..80c1eff 100644 --- a/INSTALL/configs/waybar/config +++ b/INSTALL/configs/waybar/config @@ -20,10 +20,10 @@ "custom/launcher", "custom/sep", "cpu", - "temperature", + "custom/cpu-temp", "custom/gpu", "memory", - "disk", + "custom/disks", "custom/sep", "custom/network" ], @@ -77,15 +77,13 @@ "interval": 2 }, - // ── Température ───────────────────────────────────────────────────────── + // ── Température CPU (auto-détection) ──────────────────────────────────── - "temperature": { - "thermal-zone": 9, - "format": " {temperatureC}°", - "format-critical": " {temperatureC}°", - "critical-threshold": 80, - "tooltip": false, - "interval": 2 + "custom/cpu-temp": { + "exec": "~/.config/waybar/scripts/cpu-temp.sh", + "return-type": "json", + "interval": 2, + "format": "{}" }, // ── GPU ───────────────────────────────────────────────────────────────── @@ -109,12 +107,13 @@ "interval": 2 }, - // ── Disque ────────────────────────────────────────────────────────────── + // ── Disques (auto-détection) ───────────────────────────────────────────── - "disk": { - "format": "󰋊 {used}", - "tooltip-format": "󰋊 Disque /\n{used} / {total}\n{percentage_used}% utilisé", - "interval": 30 + "custom/disks": { + "exec": "~/.config/waybar/scripts/disks.sh", + "return-type": "json", + "interval": 30, + "format": "{}" }, // ── Réseau ────────────────────────────────────────────────────────────── diff --git a/INSTALL/configs/waybar/scripts/cpu-temp.sh b/INSTALL/configs/waybar/scripts/cpu-temp.sh new file mode 100755 index 0000000..c6c99f0 --- /dev/null +++ b/INSTALL/configs/waybar/scripts/cpu-temp.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env bash +# cpu-temp.sh — température CPU auto-détection → JSON waybar +# Priorité 1 : thermal zone x86_pkg_temp (Intel) ou k10temp (AMD) +# Priorité 2 : hwmon coretemp / k10temp / zenpower +# Retourne vide si aucune source trouvée + +emit() { + local temp=$1 + local cls="normal" + (( temp >= 80 )) && cls="critical" + (( temp >= 65 && temp < 80 )) && cls="warning" + printf '{"text":" %d°","tooltip":"CPU %d°C","class":"%s","percentage":%d}\n' \ + "$temp" "$temp" "$cls" "$temp" + exit 0 +} + +# Priorité 1 — thermal_zone x86_pkg_temp (Intel) / TCPU / k10temp (AMD) +for zone in /sys/class/thermal/thermal_zone*/; do + zone_type=$(cat "${zone}type" 2>/dev/null) || continue + case "$zone_type" in + x86_pkg_temp|k10temp|TCPU|cpu_thermal) + temp_raw=$(cat "${zone}temp" 2>/dev/null) || continue + emit $(( temp_raw / 1000 )) + ;; + esac +done + +# Priorité 2 — hwmon coretemp (Intel desktop) ou k10temp (AMD) +for hw in /sys/class/hwmon/hwmon*/; do + hw_name=$(cat "${hw}name" 2>/dev/null) || continue + case "$hw_name" in + coretemp|k10temp|zenpower|amd_energy) + for f in "${hw}temp1_input" "${hw}temp2_input"; do + [[ -r "$f" ]] || continue + temp_raw=$(cat "$f" 2>/dev/null) || continue + emit $(( temp_raw / 1000 )) + done + ;; + esac +done + +# Aucune source — module masqué +printf '{"text":"","class":"unavailable"}\n' diff --git a/INSTALL/configs/waybar/scripts/disks.sh b/INSTALL/configs/waybar/scripts/disks.sh new file mode 100755 index 0000000..6764dfd --- /dev/null +++ b/INSTALL/configs/waybar/scripts/disks.sh @@ -0,0 +1,58 @@ +#!/usr/bin/env bash +# disks.sh — liste les vrais systèmes de fichiers montés → JSON waybar +# Exclut tmpfs, devtmpfs, squashfs (snap), overlay, efi, etc. + +TEXT="" +TOOLTIP="󰋊 Disques\n" + +while IFS= read -r line; do + fs=$(awk '{print $1}' <<< "$line") + size=$(awk '{print $2}' <<< "$line") + used=$(awk '{print $3}' <<< "$line") + avail=$(awk '{print $4}' <<< "$line") + pct=$(awk '{print $5}' <<< "$line") + mnt=$(awk '{print $6}' <<< "$line") + + # Exclure mounts sans intérêt + [[ "$mnt" == /snap/* ]] && continue + [[ "$mnt" == /boot/efi ]] && continue + [[ "$mnt" == /boot ]] && continue + [[ "$mnt" == /recovery ]] && continue + [[ "$mnt" == /run* ]] && continue + [[ "$mnt" == /sys* ]] && continue + [[ "$mnt" == /proc* ]] && continue + [[ "$mnt" == /dev* ]] && continue + + # Icône selon le point de montage + case "$mnt" in + /) icon="󰋊" ;; + /home) icon="󱂵" ;; + /data*) icon="󱦡" ;; + /media*) icon="󰆼" ;; + /mnt*) icon="󱛟" ;; + *) icon="󰋊" ;; + esac + + # Texte compact : icône + montage court + espace utilisé + label=$(basename "$mnt") + [[ "$mnt" == "/" ]] && label="/" + [[ -n "$TEXT" ]] && TEXT+=" " + TEXT+="${icon} ${label}: ${used}" + + TOOLTIP+="${icon} ${mnt}\n Utilisé : ${used} / ${size} (${pct})\n Libre : ${avail}\n" + +done < <(df -hP --exclude-type=tmpfs \ + --exclude-type=devtmpfs \ + --exclude-type=squashfs \ + --exclude-type=overlay \ + --exclude-type=fuse.portal \ + --exclude-type=efivarfs \ + 2>/dev/null | tail -n +2 | sort -k6) + +if [[ -z "$TEXT" ]]; then + printf '{"text":"󰋊 N/A","tooltip":"Aucun disque détecté","class":"unavailable"}\n' +else + # Échapper uniquement les guillemets pour JSON (\n reste tel quel = saut de ligne) + TOOLTIP_JSON=$(printf '%s' "$TOOLTIP" | sed 's/"/\\"/g') + printf '{"text":"%s","tooltip":"%s"}\n' "$TEXT" "$TOOLTIP_JSON" +fi diff --git a/INSTALL/themes/violet-chaton-waybar.css b/INSTALL/themes/violet-chaton-waybar.css index 1d121f5..a5bc567 100644 --- a/INSTALL/themes/violet-chaton-waybar.css +++ b/INSTALL/themes/violet-chaton-waybar.css @@ -102,9 +102,11 @@ window#waybar { #cpu, #temperature, +#custom-cpu-temp, #custom-gpu, #memory, #disk, +#custom-disks, #custom-network, #clock, #custom-date, @@ -140,7 +142,8 @@ window#waybar { /* ── Température ──────────────────────────────────────────────────────────── */ -#temperature { +#temperature, +#custom-cpu-temp { color: rgba(139, 233, 253, 0.60); font-size: 11px; font-weight: normal; @@ -148,12 +151,17 @@ window#waybar { padding-right: 10px; } -#temperature.critical { +#temperature.critical, +#custom-cpu-temp.critical { color: #f38ba8; font-weight: bold; animation: pulse-critical 0.8s linear infinite; } +#custom-cpu-temp.warning { + color: #f9e2af; +} + /* ── GPU ──────────────────────────────────────────────────────────────────── */ #custom-gpu { @@ -186,7 +194,8 @@ window#waybar { /* ── Disque ───────────────────────────────────────────────────────────────── */ -#disk { +#disk, +#custom-disks { color: rgba(255, 121, 198, 0.70); font-size: 11px; font-weight: normal; @@ -405,6 +414,8 @@ tooltip label { #cpu:hover, #memory:hover, #disk:hover, +#custom-disks:hover, +#custom-cpu-temp:hover, #custom-network:hover, #wireplumber:hover, #backlight:hover,