How can I stop new windows from popping up over what I'm doing?

Usually, in Ubuntu 10.04 Netbook, if I want to open a program, it usually goes from this: An arbitrary open program
(An open program)

to this:
Using a program launcher to launch another program http://a.yfrog.com/img251/3201/workspace2002thumb.png

(Opening another program using Kupfer)

to this:
The other program launches and ends up on top of the current program

How can I change the behavior so that after launching the program, the focus is set back to (and stays on) the original program, or in other words, make all new windows open in the background?

I'm using Ubuntu 10.04 Netbook using Mutter, though this happened when using Metacity also.


Solution 1:

Edit: Actually, there's a bug in GNOME that will allow you to achieve what you want quite simply. All you have to do is set a window, any window, to Always On Top. All windows subsequently opened will do so in the background and won't get focus. I recommend you make eg a terminal as small as possible, stick it out of the way eg in a corner, and set Always On Top.

Note that this fix is simple to implement, but in actuality is a messy workaround not a real solution, and will stop working as soon as the linked bug is fixed (though that could be 2+ release cycles away).


There is a gconf key for Mutter to prevent applications from stealing focus:

Launch gconf-editor, navigate to apps --> metacity --> general and set "focus new windows" to strict.

You may find that this is not enough, and that some or all apps are still launching with focus. At the very least the above will stop apps launched from the terminal from stealing focus, so you can workaround this by doing the below:

Pretend that menu items and panel buttons are launched from terminals, by modifying their "command" field.

So firefox becomes

gnome-terminal -e firefox

Some applications will not return the prompt immediately, therefore a further step is needed in the form of a script.

The command is gnome-terminal -e "/bin/bglaunch.sh firefox"

Where /bin/bglaunch.sh is the following script, which launches the application in background:

#!/bin/bash
nohup $1 >/dev/null & 

Solution 2:

From the Ubuntu Software Center, install "Advanced Desktop Effects Settings (ccsm)".

After the installation, a new menu item called "CompizConfig Settings Manager" will appear in the System->Preferences menu. Click on that and navigate to General->General Options->Focus and Raise Behaviour. Set the "Focus Prevention Level" to "High" or "Very High" to prevent new windows from opening in the foreground.

Solution 3:

One way is, in the main menu, to right-click on the top bar of the window, and set it to be always on top.

Solution 4:

20 years ago "focus grabbing" settings were a basic feature of the system display preferences. So much for 'advanced' technology. :(

A simple way to open the program in the background and release the terminal would be "firefox&". The ampersand runs the command as a background process. "/bin/bglaunch.sh firefox" I believe would launch a terminal which then launch firefox.