Change Panel icon on the fly

Style your desktop
Forum rules
Before you post read how to get help. Topics in this forum are automatically closed 6 months after creation.
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

42 days later... I finally managed to come up with something that looks good!
YAD-ON preview
YAD-ON preview
YAD-ON-preview.png (54.14 KiB) Viewed 1225 times
YAD-OFF preview
YAD-OFF preview
YAD-OFF-preview.png (54.43 KiB) Viewed 1225 times

This thing is based on the YAD package. You must install this one first. I worked hard to make things as simple as possible. I tested and re-tested it all on both LM MATE (18.3) and Cinnamon (20.1). There are 2 scripts:
  • yad-notification0: This is the launcher. You can replace --command="./yad-toggle" with any command you want, like your --command="./cytoggle" for instance.
  • yad-toggle: This just for a quick demonstration. You can replace this script with your cytoggle. In your script, where you want the tray icon to be changed, put this: echo "icon:/PATH/TO/ICON.SVG" > $HOME/.var/yad-pipe
...And you can replace my generic icons with your icons in both scripts. But please take note that on MATE i found you must use some /path/to/icon, not just the icon name.

For a quick test, you can copy all these into some simple text editor, save them with their filenames displayed here, put them all in the same directory, and make sure both scripts are executable (File Properties > Permissions > Allow executing...). But i will probably make it easier to download this whole package some time later this week-end...

yad-notification0 (launcher with status icon)

Code: Select all

#!/bin/bash

mkdir -p $HOME/.var; rm -f $HOME/.var/yad-toggle
PIPE=$HOME/.var/yad-pipe; rm -f $PIPE
# Create a FIFO file, used to manage the I/O redirection from shell
mkfifo $PIPE
# Attach a file descriptor to the file
exec 3<> $PIPE

# Create the notification icon (default icon-size=16)
yad --notification --listen --no-middle   \
    --image="./yad-icon-off.svg"          \
    --icon-size=24 --text="Toggle ON/OFF" \
    --command="./yad-toggle" <&3

# If you need to QUIT, open your Terminal and type: echo "quit" > $HOME/.var/yad-pipe
yad-toggle (just a simple example)

Code: Select all

#!/bin/bash

TOGGLE=$HOME/.var/yad-toggle

if [ ! -e $TOGGLE ]; then
    touch $TOGGLE
    echo "icon:./yad-icon-on.svg" > $HOME/.var/yad-pipe
else
    rm $TOGGLE
    echo "icon:./yad-icon-off.svg" > $HOME/.var/yad-pipe
fi
yad-icon-off.svg (optional)

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   id="svg8"
   version="1.1"
   viewBox="0 0 12.7 12.7"
   height="48"
   width="48">
  <defs
     id="defs2" />
  <metadata
     id="metadata5">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     id="layer1">
    <circle
       style="opacity:1;fill:#ff1a2c;fill-opacity:1;stroke:none;stroke-width:0;stroke-miterlimit:4;stroke-dasharray:none"
       id="path833"
       cx="6.3499999"
       cy="6.3499999"
       r="6.3499999" />
    <circle
       style="opacity:1;fill:none;fill-opacity:1;stroke:#ffffff;stroke-width:1.5875;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
       id="circle873"
       cx="6.3500004"
       cy="6.3500004"
       r="4.2333336" />
  </g>
</svg>
yad-icon-on.svg (optional)

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
   xmlns:dc="http://purl.org/dc/elements/1.1/"
   xmlns:cc="http://creativecommons.org/ns#"
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
   xmlns:svg="http://www.w3.org/2000/svg"
   xmlns="http://www.w3.org/2000/svg"
   id="svg8"
   version="1.1"
   viewBox="0 0 12.7 12.7"
   height="48"
   width="48">
  <defs
     id="defs2" />
  <metadata
     id="metadata5">
    <rdf:RDF>
      <cc:Work
         rdf:about="">
        <dc:format>image/svg+xml</dc:format>
        <dc:type
           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
        <dc:title></dc:title>
      </cc:Work>
    </rdf:RDF>
  </metadata>
  <g
     id="layer1">
    <circle
       style="opacity:1;fill:#0088ff;fill-opacity:1;stroke:none;stroke-width:0;stroke-miterlimit:4;stroke-dasharray:none"
       id="path833"
       cx="6.3499999"
       cy="6.3499999"
       r="6.3499999" />
    <path
       style="fill:none;stroke:#ffffff;stroke-width:2.11666667;stroke-linecap:round;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
       d="M 6.3499997,2.1166667 V 10.583333"
       id="path853" />
  </g>
</svg>
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

I forgot to mention you need to "start" this launcher: double-click to run... But this was just for testing purposes. I checked if i could make it fully simple and operational, and succeeded.
  • I placed those 2 scripts into /usr/local/bin
  • I placed those 2 images into /usr/share/icons
  • I edited the 2 scripts for those modified path/to/files
  • I added yad-notification0 into the Startup Applications
Now, my session always starts with this special launcher and everything works fine. It is 100% automated. Of course, this thing is just a test. It is a starting base. It does nothing else but toggle between 2 icons, but it could easily do all sorts of things.

More on this later. I should upload these edited scripts soon...
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
User avatar
sebastjava
Level 5
Level 5
Posts: 706
Joined: Wed Jun 28, 2017 8:01 pm
Location: Montréal, Québec, Canada
Contact:

Re: Change Panel icon on the fly

Post by sebastjava »

I created a mini repository showing this example of a YAD notification:

https://github.com/SebastJava/YAD-notification

YAD-notification-on.png
YAD-notification-off.png

There you will find:
  • A complete description
  • These small files grouped together and downloadable with just one click
  • Automated INSTALL and automated REMOVE, or a simple manual installation procedure
(And updates when needed...)
The future Linux Mint Forums is here.
Self-Appointed Benevolent Designer on Linux Mint Cinnamon.
Image
Locked

Return to “Themes, Icons & Wallpaper”