Topic: How-To xfce4-panel and tint2 panel launch scripts

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 smile

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..

http://www.zimagez.com/miniature/screenshot-08052011-035243pm.png

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

http://www.zimagez.com/miniature/screenshot-08052011-040101pm.png

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..

http://www.zimagez.com/miniature/screenshot-08052011-064935pm.png

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 luncher panel, but will open if not open, and iconify either way depending on what state the app is in.

Last edited by VastOne (2011-11-26 21:42:26)

Re: How-To xfce4-panel and tint2 panel launch scripts

I chose tint2 as my final replacement.. It is the only one of the three that mimics cairo-dock in allowing the mouse scrollwheel to open apps

xfce4-panel also has a white background when you hover over an icon..  This does not happen to everyone and I have open threads trying to resolve it...

ADeskBar is good but seems to have lost it's developer and is being maintained on Conky PitStop.  It also seems "slow" to me in responses..

This is all IMHO, YMMV....

Last edited by VastOne (2011-08-06 00:53:33)

Re: How-To xfce4-panel and tint2 panel launch scripts

ADeskBar - isn't being maintained at CPS just keeping links to existing versions out there but it looks like there is someone on the French Ubuntu site that is continuing the work.  CKDevelop is going to keep Adeskbar alive! Being French or knowing French will really help.

EDIT:

Just took a quick look ... I'm very impressed!
Great work!

Last edited by Sector11 (2011-08-06 01:14:07)

Re: How-To xfce4-panel and tint2 panel launch scripts

Sector11 wrote:

ADeskBar - isn't being maintained at CPS just keeping links to existing versions out there but it looks like there is someone on the French Ubuntu site that is continuing the work.  CKDevelop is going to keep Adeskbar alive! Being French or knowing French will really help.

Keeping the links alive is maintaining it's life...

smile

Re: How-To xfce4-panel and tint2 panel launch scripts

Sector11 wrote:

EDIT:

Just took a quick look ... I'm very impressed!
Great work!


Thank you!  For the compliment and the suggestion to build this...

Re: How-To xfce4-panel and tint2 panel launch scripts

VastOne wrote:
Sector11 wrote:

ADeskBar - isn't being maintained at CPS just keeping links to existing versions out there but it looks like there is someone on the French Ubuntu site that is continuing the work.  CKDevelop is going to keep Adeskbar alive! Being French or knowing French will really help.

Keeping the links alive is maintaining it's life...

smile

OK, I understand where you are coming from, I stand corrected.

Re: How-To xfce4-panel and tint2 panel launch scripts

VastOne wrote:
Sector11 wrote:

EDIT:

Just took a quick look ... I'm very impressed!
Great work!


Thank you!  For the compliment and the suggestion to build this...

I suggested, you did the work.
Tomorrow I start/try to build it.  big_smile

Last edited by Sector11 (2012-02-08 21:35:36)

Re: How-To xfce4-panel and tint2 panel launch scripts

VastOne wrote:

I chose tint2 as my final replacement.. It is the only one of the three that mimics cairo-dock in allowing the mouse scrollwheel to open apps

xfce4-panel also has a white background when you hover over an icon..  This does not happen to everyone and I have open threads trying to resolve it...

I have since resolved my issues with the white background when hovering over xfce4-panels and now use these..  The fix was a hack to the gtkrc2 theme I use within it's gtkrc file

Using xfce4-panels, I can add more types of launchers, including menu launchers and use all of the dbus functions..

As far as resources, tint2 and xfce4-panel use the same amount of memory in the setup I use

Re: How-To xfce4-panel and tint2 panel launch scripts

UPDATE - 08 February 2012

Using the launchers the same as tasks is now doable now thanks to my friend ToZ.  The  launch file above and instructions has been updated and now:

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

Re: How-To xfce4-panel and tint2 panel launch scripts

Wonderful hack, while waiting for tint2 to add the support natively.

However, I'm having a problem with the application in focus not minimizing.
Instead, the script seems to defer any action until the application loses focus/gets minimized, only then to bring it back to focus smile

Anyone else have this problem?

Re: How-To xfce4-panel and tint2 panel launch scripts

^ Do you have xdotool installed?

What you are describing is what the original scripts did with just the wmctrl support

With the addition of xdotool, it should iconify either way when clicked on.

That is how it works for me.

I agree also. it would be nice if tint2 did this natively.

Re: How-To xfce4-panel and tint2 panel launch scripts

I do.
As this was just a quick virtualbox attempt, I'll try again at home, and report back with results.

Also, unminimizing is noticably slower than when using the taskbar... Sure hope they add it

Re: How-To xfce4-panel and tint2 panel launch scripts

I would also make sure that everything is in the path..  that you can run each of the tools and script from anywhere. shot in the dark,  I know.  smile

I recall an issue when I first set this up until I rebooted..

Re: How-To xfce4-panel and tint2 panel launch scripts

Well, seems there's a problem with xdotool...

First off, my version doesn't accept the syntax used in your example:
"xdotool getactivewindow getwindowpid" outputs "Usage: getactivewindow".

But, replacing the offenfing line with ACTIV_WIN=$(xdotool getwindowpid $(xdotool getactivewindow))
gets me to the proper if.

However, "xdotool windowminimize" keeps throwing Segmentation faults whichever way I try to invoke it.

Could you, perhaps, tell me which version you are using?
(I'm doing this on a vanilla Statler installation, standard repos, no fiddling)

Re: How-To xfce4-panel and tint2 panel launch scripts

Sorry for the double post, but yes, it was the xdotool version...

Updating to xdotool2 ( I found some debs @ http://distro.ibiblio.org/debian/pool/main/x/xdotool/) resolved my issue.

Perhaps adding this info to you tutorial might help some future poor soul encountering my issue?

Last edited by Mandark (2012-02-17 15:30:37)

16

Re: How-To xfce4-panel and tint2 panel launch scripts

Mandark wrote:

Updating to xdotool2 ( I found some debs @ http://distro.ibiblio.org/debian/pool/main/x/xdotool/) resolved my issue.

Mine too! Thanks to both of you!

xdotool2 is in Sid, othor mirrors for same deb at http://packages.debian.org/sid/xdotool

Last edited by rml (2012-03-04 16:48:40)