Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

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

share|improve this question

5 Answers 5

up vote 2 down vote accepted
+100

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 & 
share|improve this answer
1  
Did you get a chance to try this yet? –  imoatama Sep 14 '10 at 0:38
    
@imoatama It pops up an ugly terminal when run, but nonetheless does make the thing open in the background. –  digitxp Sep 14 '10 at 3:25
    
I don't have the time to do that to every menu entry though. –  digitxp Sep 14 '10 at 3:25
    
Just setting it to strict wasn't enough? Ie if you don't start things via terminal they steal focus? –  imoatama Sep 14 '10 at 14:03
    
See edited answer for a simpler workaround. –  imoatama Sep 14 '10 at 14:22

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.

share|improve this answer
    
Does that work even using a different Window Manager? I'd be screwed if it replaced Mutter with Compiz because of the horrible graphics of the eeePC 1005HA. –  digitxp Sep 12 '10 at 19:23
1  
This doesn't work with anything but Compiz. How bad graphics are we talking? From what I've heard Mutter is quite demanding as well, though admittedly at least a bit less than Compiz. –  imoatama Sep 14 '10 at 14:04
    
Thanks mate, I did it for me :-) –  Albus Dumbledore May 18 '11 at 7:11

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.

share|improve this answer
    
nice and simple! +1 –  studiohack Sep 13 '10 at 1:59
1  
But I want that behavior to be for every window, so it won't work to have all those windows on top. –  digitxp Sep 13 '10 at 10:43

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.

share|improve this answer

hi! Try this:

#!/bin/bash
delay=0.5
while true; do 
        windowId=`xdotool getwindowfocus`
        xdotool getwindowname $windowId
        xdotool windowactivate $windowId; 
        sleep $delay; 
done

This script depends on you setting the "Focus prevention level" high enough so that new opened windows wont get the focus. It works on Ubuntu 10.04 and 12.04 at least, but should work anywhere... if it fails for you, say so and we can think together!

This is an endless loop (break it with ctrl+c) that will "activate" the window that has focus (focus for keyboard input). So it will make the focused window "jump" to foreground each 0.5 seconds (you can lower or up the delay value to your needs/taste).

So all new opened applications and windows will still open in the foreground but will be promptly hidden by the window that has focus!

Just to make it clear, they will not open in the background but this script will provide almost the same effect. Almost because if you are very unlucky you can still click on the new opened window before the focused one be put to foreground, what will make the new window be the focused one... Lowering the delay will help prevent that but consume more cpu, I think less than 0.1 is not good, but you must test to see what works better for you...

PS.: your xdotool version must support these commands: getwindowfocus, getwindowname, windowactivate

share|improve this answer
    
Hello Aquaris, could you provide two or three background infos to what this line actually does? (Even a "It does what the OP asked for" is ok) –  nixda Jan 2 '13 at 20:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.