From 6e3577087b5c548444e424fb8f4d6bec9791079f Mon Sep 17 00:00:00 2001 From: alejandrogs73 Date: Sat, 26 Sep 2026 19:39:02 +0200 Subject: [PATCH] slstatus: red sin procesos, zonas clicables, BT OFF y refresco cada 2 s Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MymT1wzMgXhfC3ZwHqNAVF --- slstatus/config.h | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/slstatus/config.h b/slstatus/config.h index a2ab6f3..66018ae 100644 --- a/slstatus/config.h +++ b/slstatus/config.h @@ -1,7 +1,7 @@ /* See LICENSE file for copyright and license details. */ /* interval between updates (in ms) */ -const unsigned int interval = 1000; +const unsigned int interval = 2000; /* text to show if no value can be retrieved */ static const char unknown_str[] = "N/A"; @@ -21,18 +21,39 @@ static const char unknown_str[] = "N/A"; * run_command output of a shell command command * wifi_essid WiFi network name interface name (wlan0) */ +/* + * Red sin lanzar procesos: ETH si hay cable en enp3s0; si no, la red WiFi de + * wlp4s0 (se lee por netlink con el componente wifi_essid de slstatus). + */ +static const char * +red(const char *unused) +{ + const char *s; + + if ((s = cat("/sys/class/net/enp3s0/operstate")) && !strcmp(s, "up")) + return "ETH"; + if (!(s = wifi_essid("wlp4s0"))) + return "WiFi: N/A"; + return bprintf("WiFi: %s", s); +} + +/* + * Los bytes \001, \002 y \003 delimitan las zonas clicables de la barra + * (parche statuscmd de dwm): la red, el volumen y el bluetooth. Lo que hace + * cada clic está en statuscmds, en el config.h de dwm. + */ static const struct arg args[] = { - /* function format argument */ - { cpu_perc, "[ CPU: %s%% ] ", NULL }, - { ram_perc, "[ RAM: %s%% ] ", NULL }, - /* ETH si hay cable en enp3s0; si no, la red WiFi de wlp4s0 */ - { run_command, "[ %s ] ", "if [ \"$(cat /sys/class/net/enp3s0/operstate)\" = up ]; then echo ETH; " - "else s=$(iw dev wlp4s0 link | sed -n 's/^[[:space:]]*SSID: //p'); echo \"WiFi: ${s:-N/A}\"; fi" }, - { battery_perc, "[ BAT: %s%%", "BAT1" }, - { battery_state, " %s ] ", "BAT1" }, + /* function format argument */ + { cpu_perc, "[ CPU: %s%% ] ", NULL }, + { ram_perc, "[ RAM: %s%% ] ", NULL }, + { red, "\001[ %s ]\001 ", NULL }, + { battery_perc, "[ BAT: %s%%", "BAT1" }, + { battery_state, " %s ] ", "BAT1" }, /* mismo volumen que maneja wpctl (PipeWire); MIC OFF si el micro está silenciado */ - { run_command, "[ VOL: %s ] ", "wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{ printf \"%d%%\", $2 * 100 + 0.5 } /MUTED/ { printf \" MUT\" }'; " - "wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep -q MUTED && printf ' MIC OFF'" }, - { run_command, "[ BT: %s ] ", "bluetoothctl devices Connected | head -1 | cut -d' ' -f3-" }, - { datetime, "[ %s ]", "%d/%m/%y %H:%M:%S" }, + { run_command, "\002[ VOL: %s ]\002 ", "wpctl get-volume @DEFAULT_AUDIO_SINK@ | awk '{ printf \"%d%%\", $2 * 100 + 0.5 } /MUTED/ { printf \" MUT\" }'; " + "wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep -q MUTED && printf ' MIC OFF'" }, + /* OFF si el adaptador está apagado; si no, el primer dispositivo conectado */ + { run_command, "\003[ BT: %s ]\003 ", "bluetoothctl show | grep -q 'Powered: yes' || { echo OFF; exit; }; " + "bluetoothctl devices Connected | head -1 | cut -d' ' -f3-" }, + { datetime, "[ %s ]", "%d/%m/%y %H:%M" }, };