elkowar / eww

ElKowars wacky widgets
https://elkowar.github.io/eww
MIT License
9.21k stars 379 forks source link

systray: add `:visible-empty` property for `systray` widget #1097

Open vnva opened 5 months ago

vnva commented 5 months ago

Description

Issue

Added the :visible-empty property for the systray widget. By default, an empty tray is displayed.

I also noticed a problem that tray elements are not removed from systray.items.

Usage

(systray :visible-empty false)

Showcase

https://github.com/elkowar/eww/assets/57404657/d4faf8e2-9bac-4432-978f-c49365a4425a

Additional Notes

This is my first time writing in rust, so I might have made mistakes, please check carefully to see. I'm ready to correct mistakes.

As far as I understand, the documentation for widgets is generated automatically.

Checklist

Please make sure you can check all the boxes that apply to this PR.

vnva commented 5 months ago

Most likely this is not the best solution, I think it’s worth passing a condition on the number of elements in the tray in :visible, you don’t have to merge this PR. But it’s certainly worth fixing removing elements from the tray. This also conflicts with the :visible property.

vnva commented 5 months ago

@jlo62, i wrote a stupid script to count the number of elements in the tray, you can use it together with deflisten and :visible

#!/bin/bash

count=0

dbus-monitor --session "interface='org.kde.StatusNotifierWatcher'" |
while read -r signal; do
    if [[ $signal == *"StatusNotifierItemRegistered"* ]]; then
      count=$(($count + 1))
    elif [[ $signal == *"StatusNotifierItemUnregistered"* ]] then
      count=$(($count - 1))
    fi

    echo $count
done
(deflisten systray-items-count :initial 0 "path-to-script")
(systray :visible "${systray-items-count > 0}")
vnva commented 5 months ago

@elkowar, perhaps this method should be added to the docs or add a magic variable with the number of elements in the systray. Perhaps it’s generally worth disabling the widget’s display by default if there are no elements in it.