vars1ty / HybridBar

A status bar focused on wlroots Wayland compositors
MIT License
196 stars 10 forks source link

[feature-request] individual "update_rate" for every label/button #21

Closed revuwa closed 1 year ago

revuwa commented 1 year ago

I realized that the more commands I execute, the more the cpu usage HybridBar needs, (of course πŸ˜…). Since I (currently) use >23 commands, I saw that the bar now uses 0.1% more cpu as with less commands, so I wondered if this couldn't be optimized with individual update rates?

My config as example, I thought that cpu/mem/disk/... usage could have bigger update rates, than volume/clock/workspaces/... should have.

So I thought it would be cool, if the

    "hybrid": {
        "update_rate": 100,
        ...

could be some kind of fallback if no individual "update_rate" is given, but otherwise commands which doesn't change (in results) that much, could be declared like this:

    "right-label_user": {
        "update_rate": 60000,
        "command": "whoami"
    },
    "right-label_host": {
        "update_rate": 36000000,
        "command": "hostname"
    },
    "right-label_time": {
        "command": "date +%H:%M"
    },

So whoami triggers ever minute, hostname every hour, and date every 100ms.

What do you think?

vars1ty commented 1 year ago

Could look into it later today or tomorrow, since I was considering doing something like this a few days ago but never really got to actually doing it

vars1ty commented 1 year ago

Done in afb84a9bbd73883d93e3865c1af8b32ea9fd8869 (0.3.8), 1:1 syntax as you suggested. If update_rate is left unspecified, then it uses 100 as the default value. Using values like 0 completely shuts off command listening, making it a static label

vars1ty commented 1 year ago

Reopening because I forgot to make it call the command immediately upon startup. Currently if you have a command set to 30m, then it won't be executed until 30m later on and will be left blank until then. Will fix in a few hours

revuwa commented 1 year ago

Reopening because I forgot to make it call the command immediately upon startup. Currently if you have a command set to 30m, then it won't be executed until 30m later on and will be left blank until then.

First of all thank you so much for implementing this πŸ™ And sorry for late response, because I realized that behavior, and wanted to report this, too.

In this context I experienced another side effect, but I don't know if this is related to the latest change/s 🀷 Since 0.3.8 the tooltips needs (partly way) more time to display. With 0.3.7 I hovered over the single buttons/labels and instantly got the tooltips / results of tooltip_commands. With 0.3.8 I get the result/s after few moments to several seconds later.

Is it possible, that the display time until tooltips appear could be related to update_rate? I stopped for tooltips with update_rate of 5000 from <1 sec up to ~7 seconds, until they got displayed. But for a tooltips with update_rate of 1000 ~3-4 seconds. I'm confused, and hope you got what I mean, because I can't narrow it down further, for now 😞

EDIT: Even buttons which opens applications triggers the execution of them delayed (~1-3 sec delay).

vars1ty commented 1 year ago

The tooltips part seems like an issue on your end, I just tested it and can't notice anything OOTO. Neither can I notice slowdowns with buttons, here's a video of it all: https://streamable.com/y3y1rc

revuwa commented 1 year ago

The tooltips part seems like an issue on your end

πŸ€” Thanks for your clip; so I made one, too: https://streamable.com/6ts31f There is not every single time a noticeable delay, but some times, with different seconds of delay. Some times >10 sec.

I don't want to exclude that it's an issue on my end; I just wanted to precise the behavior I have.

vars1ty commented 1 year ago

What's the update frequency of that tooltip?

revuwa commented 1 year ago

What's the update frequency of that tooltip?

-> 10000 (10s), but I personally don't think it have to be related, because I played around with much bigger values, too, but every tooltip interacts the same way.

My complete config is this:

``` { "variables": { "$foot_term": "foot -c /etc/foot/foot.ini" }, "hybrid": { "stylesheet": "style.css", "r": 10, "g": 10, "b": 10, "a": 0.2 }, "left-spacing_workspaces_margin": { "update_rate": 0, "spacing_start": 1, "spacing_end": 7 }, "left-label_workspaces": { "update_rate": 500, "command": "for i in $(hyprctl workspaces -j | jq -r 'sort_by(.id) | .[].id'); do if [[ $i == $(hyprctl monitors -j | jq -r '.[].activeWorkspace.id') ]]; then echo [$i] | tr '\n' ' '; else echo $i | tr '\n' ' '; fi; done" }, "centered-label_titles": { "update_rate": 500, "command": "hyprctl activewindow -j | jq -r '.title' | sed -E 's/ - Chromium| β€” LibreWolf| β€” Mozilla Firefox//'" }, "right-button_cpu": { "update_rate": 0, "text": "#", "command": "hyprctl dispatch exec \"$foot_term -a 'foot-float' btop\"", "tooltip": "run btop" }, "right-label_cpu": { "update_rate": 3000, "command": "top -b -n 1 | grep 'Cpu(s):' | awk '{printf \"%02d\", (100-$8)}' | cut -f 1 -d '.'", "tooltip_command": "ps -A -o pcpu,comm --sort=-pcpu | head -n 10" }, "right-label_cpu_close": { "update_rate": 0, "text": "% " }, "right-label_temp": { "update_rate": 10000, "text": "(", "command": "cat /sys/class/thermal/thermal_zone0/temp | awk '{print ($1)/1000}'", "tooltip": "temperature" }, "right-label_temp_close": { "update_rate": 0, "text": "Β°C) | ", "tooltip": "temperature" }, "right-label_mem": { "update_rate": 3000, "text": "☰ ", "command": "free -m | grep 'Mem:' | awk '{print ($3/$2)*100}' | cut -f 1 -d '.'", "tooltip_command": "free -h | grep 'Mem:' | awk '{print $3 \" used (\" $7 \"/\" $2 \" free)\"}' | sed 's/Gi/GB/g'" }, "right-label_mem_close": { "update_rate": 0, "text": "% | " }, "right-label_disk": { "update_rate": 10000, "text": "⛁ ", "command": "df -h / | awk '{print $5}' | tail -n 1", "tooltip_command": "df -h | grep -v -E '(tmp|boot)' | tail -n 1 | awk '{print $3 \" used (\" $4 \"/\" $2 \" free)\"}' | sed 's/G/GB/g'" }, "right-label_disk_separator": { "update_rate": 0, "text": " | " }, "right-label_volmuted": { "update_rate": 500, "command": "if wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep 'Volume:' | grep -q 'MUTED'; then echo 'βˆ… '; else echo '⚟ '; fi" }, "right-label_vol": { "update_rate": 500, "command": "wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep 'Volume:' | awk -F 'Volume: ' '{print ($2)*100 \"%\"}'", "tooltip_command": "if wpctl get-volume @DEFAULT_AUDIO_SINK@ | grep 'Volume:' | grep -q 'MUTED'; then echo 'audio muted'; else echo 'audio unmuted'; fi" }, "right-label_micmuted": { "update_rate": 500, "command": "if wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep 'Volume:' | grep -q 'MUTED'; then echo ' ('; else echo ' (●'; fi" }, "right-label_micvol": { "update_rate": 500, "command": "wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep 'Volume:' | awk -F 'Volume: ' '{print ($2)*100 \"%)\"}'", "tooltip_command": "if wpctl get-volume @DEFAULT_AUDIO_SOURCE@ | grep 'Volume:' | grep -q 'MUTED'; then echo 'mic muted'; else echo 'mic unmuted'; fi" }, "right-button_audiomgmt": { "update_rate": 0, "text": "βš™", "command": "hyprctl dispatch exec \"pavucontrol\"", "tooltip": "run pavucontrol" }, "right-label_audio_separator": { "update_rate": 0, "text": "|" }, "right-button_wifistats": { "update_rate": 0, "text": "οͺ¨", "command": "hyprctl dispatch exec \"$foot_term -a 'foot-float' wavemon\"", "tooltip": "run wavemon" }, "right-label_wifi": { "update_rate": 1000, "command": "if iwctl station wlan0 show | grep 'State' | awk -F 'State' '{print $2}' | grep -q 'disconnected'; then echo 'βœ•'; else echo 'οΊ΄'; fi", "tooltip_command": "iwctl station wlan0 show | grep 'Connected network' | awk -F 'Connected network' '{print $2}' | awk '{gsub(/^[ \t]+|[ \t]+$/, \"\"); print}'" }, "right-label_wifi_separator": { "update_rate": 0, "text": " |" }, "right-label_workspacescount": { "update_rate": 1000, "text": "ο«— ", "command": "hyprctl workspaces -j | jq -r '.[].id' | wc -l", "tooltip": "active windows: ", "tooltip_command": "hyprctl clients -j | jq -r '.[].pid' | wc -l" }, "right-label_workspacescount_separator": { "update_rate": 0, "text": " |" }, "right-button_idleinhibition": { "update_rate": 0, "text": "☯", "command": "slc=$(echo -e \"10 minutes\n1 hour\n1 day\ncancel all\" | bemenu -p 'inhibit idle for:' -i -l 4 -c -W 0.1); if [[ $slc == '10 minutes' ]]; then hyprctl dispatch exec \"systemd-inhibit --what=idle --why=HybridBarIdleInhibition sleep 10m\"; elif [[ $slc == '1 hour' ]]; then hyprctl dispatch exec \"systemd-inhibit --what=idle --why=HybridBarIdleInhibition sleep 1h\"; elif [[ $slc == '1 day' ]]; then hyprctl dispatch exec \"systemd-inhibit --what=idle --why=HybridBarIdleInhibition sleep 1d\"; elif [[ $slc == 'cancel all' ]]; then pkill systemd-inhibit; fi", "tooltip": "inhibit idle" }, "right-label_idleinhibition": { "update_rate": 1000, "command": "if systemd-inhibit --list | grep -q 'HybridBarIdleInhibition'; then echo '⏸ '; else echo '∞ '; fi", "tooltip_command": "if systemd-inhibit --list | grep -q 'HybridBarIdleInhibition'; then echo 'idle inhibition active'; else echo 'idle inhibition inactive '; fi" }, "right-label_idleinhibition_separator": { "update_rate": 0, "text": "|" }, "right-button_calendar": { "update_rate": 0, "text": "祥", "command": "hyprctl dispatch exec \"$foot_term -a 'foot-float-cal' -H cal -Y\"", "tooltip": "run calendar" }, "right-label_timedate": { "update_rate": 1000, "command": "date +%H:%M", "tooltip_command": "date +%d.%m.%Y" }, "right-label_timedate_separator": { "update_rate": 0, "text": " |" }, "right-button_powermenu": { "update_rate": 0, "text": "⏻", "command": "slc=$(echo -e \"logout\nreboot\nshutdown\" | bemenu -p 'power menu' -i -l 3 -c -W 0.1); if [[ $slc == logout ]]; then hyprctl dispatch exec \"loginctl terminate-user $USER\"; elif [[ $slc == reboot ]]; then hyprctl dispatch exec \"systemctl reboot\"; elif [[ $slc == shutdown ]]; then hyprctl dispatch exec \"systemctl poweroff\"; fi", "tooltip": "power menu" } } ```

vars1ty commented 1 year ago

Can re-create but at a much smaller scale, although no idea what the root cause of it is as of right now. Could you try and backup your config, make a new one with just a Label/Button with a dynamic tooltip command, see if it's also slow?

revuwa commented 1 year ago

Tried just the following:

{
    "hybrid": {
        "r": 10,
        "g": 10,
        "b": 10,
        "a": 0.2
    },
    "right-label_cpu": {
        "update_rate": 5000,
        "command": "top -b -n 1 | grep 'Cpu(s):' | awk '{printf \"%02d\", (100-$8)}' | cut -f 1 -d '.'",
        "tooltip_command": "ps -A -o pcpu,comm --sort=-pcpu | head -n 10"
    }
}

and it was mostly blazing fast. None of my tries was >1s. So it seems that it could be linked to the amount of used labels/buttons (in my personal case)?

vars1ty commented 1 year ago

It's most likely blocking the UI Thread temporarily for a few milliseconds when updating widgets, leading to the slight delay. I can look into it in a bit, although don't expect a fix for it since async with GTK and Labels is a hit or miss, so we'll see if it works out

vars1ty commented 1 year ago

Update: Won't fix since it doesn't bother me, and because making it run in an asynchronous-like way would require a ton of rework to be done, just doing it for the Cava output was a huge nightmare and is hacky as-is.

So until I can be bothered dealing with this in the future (or someone else, if so open a PR), it'll remain as-is.

revuwa commented 1 year ago

Won't fix since it doesn't bother me, and because making it run in an asynchronous-like way would require a ton of rework to be done, just doing it for the Cava output was a huge nightmare and is hacky as-is.

Thanks a ton for looking into this and spending so much time, before making this decision πŸ’•