How-To xfce4-panel and tint2 panel launch scripts

VastOne

Noticed this golden oldie was not brought over when I started here...

It is here for reference and a ToZ thank you!


Background - I have used cairo-dock forever..  I wanted to switch to tint2 launchers or xfce4-panel launchers but each had limitations as to how they behaved..

ToZ is an individual I met on the XFCE forums and did ALL of this coding..  He gets every bit of the credit, all I did was request for help and ToZ did it all..  I am very grateful to ToZ :)

Tint2 -

The new launcher capability in tint2 is great, but I could not use it like I had cairo-dock setup.  If you had an app open and clicked on the launcher again, it would open a new instance of the app.  In cairo-dock, this is defined by a class of the program that you linked to it and stopped multiple instances opening..

tint2 - Solution

You will first need to install wmctrl and xdotool, the tools that are used to manage windows (opened apps)

sudo apt-get install wmctrl
sudo apt-get install xdotool

Now create the launch file

gksudo gedit /usr/local/bin/launch

and put the following code in:

#!/bin/bash
# This script acts as a launcher for apps that observes the following rules:
#   1. If the app is not running, then start it up
#   2. If the app is running, don't start a second instance, instead:
#     2a. If the app does not have focus, give it focus
#     2b. If the app has focus, minimize it
# Reference link: http://forum.xfce.org/viewtopic.php?id=6168&p=1

# there has to be at least one parameter, the name of the file to execute
if [ $# -lt 1 ]
then
  echo "Usage: `basename $0` {executable_name parameters}"
  exit 1
fi

BNAME=`basename $1`

# test to see if program is already running
if [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $BNAME`" ]; then
    # means it must already be running
    ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
    LAUNCH_WIN=$(ps -ef | grep "$BNAME" | grep -v grep | tr -s ' ' | cut -d' ' -f2 | head -n 1)

    if [ "$ACTIV_WIN" == "$LAUNCH_WIN" ]; then
        # launched app is currently in focus, so minimize
        xdotool getactivewindow windowminimize
    else
        # launched app is not in focus, so raise and bring to focus
        for win in `wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $BNAME | cut -d' ' -f1`
        do
            wmctrl -i -a $win
        done
    fi
    exit

else
    # start it up
    $*&
fi

exit 0


Save the file

next make the file executable

sudo chmod +x /usr/local/bin/launch

Now you are set to create launchers in tint2

Here is how I use mine, with a couple of key points to consider...
#---------------------------------------------
# TINT2 CONFIG FILE
#---------------------------------------------

#---------------------------------------------
# BACKGROUND AND BORDER
#---------------------------------------------

# Background definitions
# ID 1 for Panel
rounded = 0
border_width = 0
background_color = #ffffff 0
#border_color = #000000 70

# ID 2
rounded = 1
border_width = 1
background_color = #ffffff 0
#border_color = #D8D8D8 29

# ID 3
rounded = 1
border_width = 1
background_color = #ffffff 0
#border_color = #121212 89

# ID 4
rounded = 1
border_width = 1
background_color = #ffffff 0
#border_color = #ED2323 60

# ID 5
rounded = 0
border_width = 1
background_color = #ffffff 0
#border_color = #000000 0

# ID 6
rounded = 6
border_width = 0
background_color = #ffffff 0
#border_color = #D8D8D8 0

# ID 7
rounded = 3
border_width = 0
background_color = #ffffff 0
#border_color = #222222 89

# ID 8
rounded = 1
border_width = 1
background_color = #ffffff 0
#border_color = #888888 200

# ID 9
rounded = 6
border_width = 0
background_color = #ffffff 0
#border_color = #888888 20

# ID 10
rounded = 0
border_width = 0
background_color = #ffffff 0
#border_color = #888888 20


#---------------------------------------------
# PANEL
#---------------------------------------------
panel_items = L
panel_monitor = all
panel_position = bottom middle
panel_size = 30% 85
panel_margin = 0 0
panel_padding = 7 0
font_shadow = 0
panel_background_id = 0
panel_layer = top

#---------------------------------------------
# TASKBAR
#---------------------------------------------
taskbar_mode = single_desktop
taskbar_padding = 0 0 0
taskbar_background_id = 1

#---------------------------------------------
# TASKS
#---------------------------------------------
#task_icon = 1
#task_text = 0
#task_width = 40
#task_centered = 1
#task_padding = 2 2
#task_font = sans 7
#task_font_color = #ffffff 70
#task_active_font_color = #ffffff 85
#task_background_id = 3
#task_active_background_id = 2

#---------------------------------------------
# SYSTRAYBAR
#---------------------------------------------
#systray_padding = 4 2 3
#systray_background_id = 1

#---------------------------------------------
# CLOCK
#---------------------------------------------
#time1_format = %H:%M
#time1_font = sans 8
#time2_format = %A %d %B
#time2_font = sans 6
#clock_font_color = #ffffff 76
#clock_padding = 4 4
#clock_background_id = 1

#---------------------------------------------
# BATTERY
#---------------------------------------------
#battery = 0
#battery_low_status = 7
#battery_low_cmd = notify-send "battery low"
#bat1_font = sans 8
#bat2_font = sans 6
#battery_font_color = #ffffff 76
#battery_padding = 1 0
#battery_background_id = 0

# Launchers
launcher_icon_theme = LinuxLex-8
launcher_padding = 5 0 10
launcher_background_id = 9
launcher_icon_size = 85
# launcher_item_app = /usr/share/applications/gedit.desktop
launcher_item_app = /home/vastone/bin/iceweasel.desktop
launcher_item_app = /home/vastone/bin/terminator.desktop
launcher_item_app = /home/vastone/bin/pcmanfm-mod.desktop
launcher_item_app = /home/vastone/bin/gmusicbrowser.desktop
# launcher_item_app = /usr/share/applications/clementine.desktop
launcher_item_app = /home/vastone/bin/virtualbox.desktop
launcher_item_app = /home/vastone/bin/xchat.desktop
# launcher_item_app = /usr/share/applications/vlc.desktop


#---------------------------------------------
# MOUSE ACTION ON TASK
#---------------------------------------------
mouse_middle = none
mouse_right = none
mouse_scroll_up = toggle
mouse_scroll_down = iconify


# Panel Autohide
autohide = 1
autohide_show_timeout = 0.0
autohide_hide_timeout = 0.0
autohide_height = 3
strut_policy = minimum


Note that I have only L in

panel_items = L

That is because I use this as a second tint2 config (tint2rctwo) and call it on startup.  This keeps the launchers only at the bottom, just like I had it setup in cairo-dock.

In tint2,  .desktop files needed for launchers (and are the only way you can launch and app)... as you can see, I have moved some of my launchers to my /home/vastone/bin directory..  I did this so that I can easily edit them and use the icons and launcher that is needed..  You can keep and use and edit the ones already in /user/share/applications

Here is a snippet of my iceweasel launcher and how I use launch to make it work

[Desktop Entry]

(deleted non important info for this How To)

Exec=launch iceweasel %u
Terminal=false
X-MultipleArgs=false
Type=Application
Icon=/home/vastone/images/firefox01-04.png
Categories=Network;WebBrowser;
MimeType=text/html;text/xml;application/xhtml+xml;application/xml;application/vnd.mozilla.xul+xml;application/rss+xml;application/rdf+xml;image/gif;image/jpeg;image/png;x-scheme-handler/http;x-scheme-handler/https;
StartupWMClass=Firefox-bin
StartupNotify=true


You see in

Exec=launch iceweasel %u      This is where the launch script is engaged ..  and in

Icon=/home/vastone/images/firefox01-04.png      is where I setup my icon for this...

Thats it for tint2

xcfe4-panel

Same situation, you can create Launchers within xfce4-panel, but if you click on an icon it opens a new instance and not what is already open

xfce4-panel solution

Using the same launch script add it to the launchers you create within the panel

Create a new launcher (pcmanfm-mod for demo purposes):
Right-click Panel->Panel->Add New Items,
select "Launcher" and click "Add" (new launcher appears on panel), click "Close"
Right-click the new launcher icon->Properties
click on "Add new empty item" button (4th button down on right side)
set: Name = pcmanfm
       Comment = <whatever_you_want>
       Command = launch pcmanfm-mod --no-desktop
       Select an icon
       Check "Use startup notification"
Click "Create

Image showing the setup..



And that is all there is to it for tint2 and xfce4-panels to be more intuitive as launchers and for me, to replace cairo-dock

This image shows tint2 at the bottom and xfce4-panel on the left



Thats it...  Again a million thanks to ToZ for hearing my requests and sharing his great solutions..!

Edit - I also tested this with adeskbar and it works great..  Just add "launch" before any command..



UPDATE - 08 February 2012

Using the launchers the same as tasks is now doable now thanks to my friend ToZ.  The  launch file above has been updated and now uses wmctrl and xdotool and will treat each tint2 launcher the same as a task.  It will not add a task to the launcher panel, but will open if not open, and iconify either way depending on what state the app is in.
VSIDO      VSIDO Change Blog    

    I dev VSIDO