Author Topic: Application Launch Feedback for LXDE. (cant be done you say...)  (Read 726 times)

Offline Village Idiot

  • Hero Member
  • *****
  • Posts: 2345
  • Have A Nice Day.
Launch Feedback for LXDE.

To celebrate Neal's promotion to the top rung of the forum, I offer a solution to an issue with LXDE that, up until now, was apparently unsolvable.

LXDE, unlike KDE currently does not have any program launch feedback feature built in. This means if you are running a giant program such as Firefox or Open Office on older hardware, you'll wait several seconds before the main window comes up. When a program shortcut is placed on the taskbar on a slow computer, an impatient user is tempted to multi click the icon and then, moments later, has numerous instances of the same program on the screen.

The solution to this is launch feedback. The following script is executed simultaneously with your slow program and places a zenity info box immediately on the screen. The script collects the program ID (PID) and waits for the top window to be that particular PID. For some programs the main window is a different PID to the executable that is called. In this instance the script will drop out after 5 seconds(adjustable). This also applies to a program that did not start for whatever reason.

How to use:

1) Copy the script to a text editor and save the file in your home directory as lfeedback.sh

2) Start a terminal and make the script executable:
$  chmod +x lfeedback.sh

3) change to root (and give root pw)
$ su

4) Copy and give the script root access and move it to an executable directory
# cp lfeedback.sh lfeedback
# chown root lfeedback
# chgrp root lfeedback
# mv lfeedback /usr/bin/

5) Switch to the desktop entry directory (as root)
# cd /usr/share/applications

6) Copy and change the Firefox desktop entry to have launch feedback
# cp firefox.desktop firefox-lfb.desktop
# leafpad firefox-lfb.desktop

Look for the line:
Exec=firefox %u

And change it to:
Exec=lfeedback firefox %u

Save the file. And exit from the terminal

7) You can add this new entry to your taskbar if you'd like.

That's it! Enjoy. And feel free to comment.  :)

The script:
Code: [Select]
#!/bin/bash -l

#lfeedback
#Launch FeedBack

#Version: 0.0.1


# extract the program from the command line
#===================================================
PROGRAM=$@


# script params
#===================================================
TIMEOUT=5
UPDATEINV=1


# run the program
#===================================================
$PROGRAM &


# get the pid of the program
#===================================================
PID="`echo $!`"


# start the zentiy dialog
#===================================================
zenity --info --title="$PROGRAM" --text="*** Launch Feedback ***\n\nProgram Starting: \n\n$PROGRAM\n\nPID: $PID" &


# get pid of zenity dialog so we can kill it later on..
#===================================================
PIDZENITY="`echo $!`"


# Start the timer..
#===================================================
while [ "$PID" != "$PID2" ]
do

  #kill some time..
  sleep $UPDATEINV

  # break if the top window is not detected after the timeout
  ((TIMEOUT=TIMEOUT-UPDATEINV))
  if [ $TIMEOUT -le "0" ]; then
     break
  fi

  #get the pid of the top window
  PID2=`xprop -id $(xprop -root | awk '/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}') | awk '/_NET_WM_PID\(CARDINAL\)/{print $NF}'`

  #debug: display in console info of the current top window:
  #ps -P $PID2

done


# finish
#===================================================
kill $PIDZENITY
« Last Edit: January 02, 2011, 04:09:17 PM by Neal »
$ fortune
No Microsoft products were used in any way for the creation of this message.
If you are using a Microsoft product to view it, BEWARE! - I'm not
responsible for any harm you might encounter as a result.