Xfce Forum

Sub domains
 

You are not logged in.

#26 2012-02-08 04:38:35

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

Hi ToZ

Yes to the logic.  This would handle anything in a panel or launcher. 

I understand wmctrl -k does close everything and from a launcher standpoint, that is fine.  Not the best but not the worst either ... smile 

I have spent the last couple of hours trying to find he xdotool and/or wmctrl function to minimize an app and have not found if it is even possible.

Offline

#27 2012-02-08 15:13:51

ToZ
Member
From: Toronto, Canada
Registered: 2011-06-02
Posts: 935

Re: [Solved] 4.8 Panel question/suggestion

Try this (only tested with 2 apps):

#!/bin/bash

# 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

# test to see if program is already running
if [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1`" ]; then 
	# means it must already be running
	ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
	LAUNCH_WIN=$(pidof $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 $1 | cut -d' ' -f1`
		do
		    wmctrl -i -a $win
		done
	fi
	exit

else
	# start it up
	$*&
	exit
fi

exit 0

Last edited by ToZ (2012-02-08 15:15:01)

Offline

#28 2012-02-08 16:49:57

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

Morning ToZ

Thanks for looking into and helping with this! smile

It works on most apps.  It partially works on Iceweasel that I have running from a .desktop file.  If there are no focused Windows, clicking on the Iceweasel Icon does nothing at all.  If there is a different focused Window then clicking the icon does work, but it never minimizes when clicking the Iceweasel icon

Nearly the same thing happens with my music app gmuscibrowser also running as a .desktop file.  The only difference is clicking the icon will always maximize gmb but will never minimize it

I thought it might be an issue from within the .desktop files but it is not.  These two apps are the only two I am using that the Window Title changes to show what is on the app when running

On xfce4-terminal, file manager and Xchat it works perfectly.  These three load the same way with a .desktop file

Last edited by Vastone (2012-02-08 17:03:02)

Offline

#29 2012-02-08 17:08:23

ToZ
Member
From: Toronto, Canada
Registered: 2011-06-02
Posts: 935

Re: [Solved] 4.8 Panel question/suggestion

Turns out that the gmusicbrowser app is a script that is run via perl. I had to change the pidof command to also return the pid of scripts being run (-x parameter). I don't have iceweasel installed to test, but this version now works with gmusicbrowser (also tested with firefox, gcalctool & abiword)

#!/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

# test to see if program is already running
if [ "`wmctrl -lx | tr -s ' ' | cut -d' ' -f1-3 | grep -i $1`" ]; then 
	# means it must already be running
	ACTIV_WIN=$(xdotool getactivewindow getwindowpid)
	LAUNCH_WIN=$(pidof -x $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 $1 | cut -d' ' -f1`
		do
		    wmctrl -i -a $win
		done
	fi
	exit

else
	# start it up
	$*&
fi

exit 0

EDIT: Also works with gimp.

Last edited by ToZ (2012-02-08 17:18:40)

Offline

#30 2012-02-08 17:24:47

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

^ It is interesting that it works with firefox for you and not iceweasel for me.  As you know, iceweasel is just a rebranded ff

I made the changes and but I am not seeing it do anything different with GMB. The difference I see is that I am running gmb from a specific path and gmusicbrowser.pl (the git version) from the .desktop file.

Offline

#31 2012-02-08 18:28:32

ToZ
Member
From: Toronto, Canada
Registered: 2011-06-02
Posts: 935

Re: [Solved] 4.8 Panel question/suggestion

What does:

ps -ef | grep -i gmusicbrowser

return?

and

ps -ef | grep -i iceweasel

return?

Last edited by ToZ (2012-02-08 18:29:49)

Offline

#32 2012-02-08 18:31:48

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

vastone   3427     1  4 11:44 ?        00:01:58 /usr/bin/perl /home/vastone/gmusicbrowser/gmusicbrowser.pl
vastone   2800     1 12 11:43 ?        00:06:08 /usr/lib/iceweasel/firefox-bin

Offline

#33 2012-02-08 19:15:11

ToZ
Member
From: Toronto, Canada
Registered: 2011-06-02
Posts: 935

Re: [Solved] 4.8 Panel question/suggestion

Okay. The original script only worked with one-word executables that existed in the system path. I've updated the script to take care of non-path executables. Tested to work on gmusicbrowser from git. The command I used to test it was:

launch /home/toz/Downloads/squentin-gmusicbrowser-92f0302/gmusicbrowser.pl

Here is the updated script:

#!/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 "$1" | 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

Now about iceweasel. As you can see, its just running firefox-bin (even though its called iceweasel). This is going to make it difficult.

What command is used to start iceweasel?

Last edited by ToZ (2012-02-08 19:15:57)

Offline

#34 2012-02-08 19:20:14

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

Awesome - that patched worked for both!!

Every one of the launchers is now acting as it should..

Very nice work! 

If you have a paypal setup I can send you some coin for this!

I really appreciate this ... smile

Offline

#35 2012-02-08 19:24:45

ToZ
Member
From: Toronto, Canada
Registered: 2011-06-02
Posts: 935

Re: [Solved] 4.8 Panel question/suggestion

No worries, I enjoy the challenge. Keeps me sharp (and out of trouble).

I did however find one error in the script that may or may not be a bug (line 22, $1 instead of $BNAME). Here is the script updated to fix that. Give it a try and see if it still works (looks good here, but can't test iceweasel).

#!/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

Offline

#36 2012-02-08 19:29:19

Vastone
Member
Registered: 2011-08-03
Posts: 50

Re: [Solved] 4.8 Panel question/suggestion

I did apply it and test it and it works just the same.

Iceweasel and every other launcher is working

Glad I can help in keeping you out of trouble! smile

Nice job mate!

Offline

Board footer

Powered by FluxBB