[openbox] Launching applications

Anthony Thyssen A.Thyssen at griffith.edu.au
Mon Oct 3 19:43:46 EDT 2011


On Mon, 3 Oct 2011 12:57:05 +0100
Jorge Almeida <jjalmeida at gmail.com> wrote:
| On Mon, Oct 3, 2011 at 11:54 AM, Manolo Martínez
| <manolo at austrohungaro.com> wrote:
| >
| > I have a number of keybindings for launching common applications. Currently,
| > say, A-F5 launches mutt in a urxvt terminal and, if I press that key
| > combination twice, I get two mutt instances.
| >
| > Is there any way to find out whether there is already a window running mutt
| > somewhere and, if so, instruct A-F5 to raise and focus that window, instead of
| > launching a new one?
| >
| 
| Make sure your mutt window has a descriptive title, call wmctrl to
| raise it an on failure call urxvt.
| 
| Try this as command launched by your shortcut keys (untested):
| 
| sh -c 'wmctrl -F -a "Mutt" || urxvt -T "Mutt" -e /usr/bin/mutt '
| 
This will also raise/focus on the application if it is already running,
whcih is a good thing.

As I said before.  It can take some time (many seconds) for an
application to configure and setup its application window.
Now  xrxvt is quite fast, but keystrokes are faster, and the launch
command will typically be run in parallel (in background)

During that time multiple key presses and thus multiple urxvt commands
could have been launched which is what the user is actually requesting.
As such some form of locking will be needed...

The pseudo-code to prevent multiple launches while testing for a
clients window will thus need some locking...

     get/wait for lock
     test for window again (now we have lock), exit if found running
     launch client window
     wait for client window to appear OR timeout
     clear lock

This works and in general is clean for things like power failures,
as the lock is only present for the launch period only. Something to
clear the lock during X window start when you can guarantee no
application is running is also a good idea, though not essential.

The alternative is to also save the applications PID (perhaps in
a permanent lockfile) which can be used to check validity of the
lock.  This is how system daemons typically ensure uniqueness
but permanent locks are a pain.


  Anthony Thyssen ( System Programmer )    <A.Thyssen at griffith.edu.au>
 --------------------------------------------------------------------------
    You know, the very powerful and the very stupid have one thing in
    common.  They don't alter their views to fit the facts. They alter
    the facts to fit their views.     -- Doctor Who, "The Face of Evil"
 --------------------------------------------------------------------------
   Anthony's Castle     http://www.ict.griffith.edu.au/anthony/


More information about the openbox mailing list