conky and yad - some possibilities

PackRat

I was working on a yad command (battery notification) and came across this internal yad command (from the yad man page):

--notification
              Display notification icon.


so the command:

yad --notification

sends a notification icon to the system tray. That got me thinking that yad can be used with conky so that conky can send notifications to the system tray - low battery, high cpu, that sort of thing. The goal is to make conky proactive instead of reactive (in the sense that the user needs to be reading it). That way, if a window is covering the conky, a user can still get critical information.

Proof of concept:

My usual conky with fluxbox - I have it docked in the slit so it's always visible, and use "if" to colorize the output for CPU and MEM:



Add a bit of code (snippet)-

chage:

${offset 8}${if_match ${memperc}<=50}${color7}

to

${offset 8}${if_match ${memperc}<=50}${color7}${exec yad --notification}


and sure enough, I get a notification icon (which can be changed in yad) - but the conky itself no longer displays. Same result using execpi, texeci and not docking the conky.



There has to be a way to make this work without a lot of scripting which could get cpu and mem intensive.

Thoughts?

I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

misko_2083

I know very little about conky.
If you can make conky write to stdout and format the output to correct format it would work.
yad notification icon can read from standard input but only possible
    commands are icon, tooltip, visible, action, menu and quit.

NOTIFICATION
       Allows commands to be sent to yad in the form  command:args.   Possible
       commands are icon, tooltip, visible, action, menu and quit.

       icon:ICONNAME
              Set notification icon to ICONNAME.

       tooltip:STRING
              Set notification tooltip.

       visible:[true|false|blink]
              Set notification icon to visible, invisible or blinking states.

       action:COMMAND
              Specify  the  command  running  when click on the icon.  Special
              string "quit" exit the program.

       menu:STRING
              Set popup menu for notification icon.  STRING must  be  in  form
              name1[!action1[!icon1]]|name2[!action2[!icon2]]....   Empty name
              add separator to menu.  Separator  character  for  values  (e.g.
              `|')  sets  with  --separator argument.  Separator character for
              menu items (e.g. `!') sets with --item-separator argument.

       quit   Exit the program. Middle click on icon also send quit command.

Open a terminal window and enter
yad --notification --image="gtk-help" --listen
then enter and type in
tooltip:Hello\nPackrat
mouse over the icon and you will see a tooltip.
To quit type in
quit
This example shows how to use it in a script.
I don't think it can be done without some scripting.

PackRat

Quote from: misko_2083 on May 05, 2017, 11:03:12 PM
I don't think it can be done without some scripting.

That's what I have concluded. I did a bit of searching to see if a lua function could send notifications to the system tray. Nothing.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo

filip

I think the issue here is that Conky waits for the command to return, which YAD doesn't since it's sitting active in the tray.
You should be able to confirm this by clicking the tray icon ( default is to quit on click ) after which Conky should redraw/show.
If so, then I don't think you can easily work around it.

On the other hand, going the regular bash route, something like this should do the job:

#!/bin/bash

PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE

exec 3<> $PIPE

function exit() {
    echo "quit" >&3
    rm -f $PIPE
}
trap exit EXIT

# "--command" is left empty with the purpose of
# disabling "Quit on left click".
# You can still middle click to quit.
yad --notification                  \
    --kill-parent                   \
    --listen                        \
    --image="gtk-help"              \
    --visible=false                 \
    --text="Tooltip text goes here" \
    --command="" <&3 &

function battery_check() {

# BATTERY=$(command to get battery percentage)

}
battery_check

while true; do
    if [[ "$BATTERY" -le 10 ]]; then
        echo "icon:battery_empty" >&3
        echo "visible:blink" >&3
    else
        echo "visible:false" >&3
    fi
    sleep 10s
    battery_check
done


I'm not using a laptop and don't know the command to get battery percentage, so you'll need to fill that in @"battery_check" function.
Also, it won't get anywhere close to hogging the RAM or the CPU, as long as you don't go wild with the "sleep" inside the "while" loop ( low intervals like "sleep 0.1s" ).
:)

PackRat

QuoteYou should be able to confirm this by clicking the tray icon ( default is to quit on click ) after which Conky should redraw/show.

Confirmed. By accident though, I was checking the tool tip and quit the yad icon.  :D

Thanks for that script. I'll check it out when I get some time.
I am tired of talk that comes to nothing.
-- Chief Joseph

...the sun, the darkness, the winds are all listening to what we have to say.
-- Geronimo