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

7

3

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.

digitxp

Posted 2010-09-04T18:08:40.023

Reputation: 13 502

Answers

2

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 & 

imoatama

Posted 2010-09-04T18:08:40.023

Reputation: 1 906

1Did you get a chance to try this yet? – imoatama – 2010-09-14T00:38:52.233

@imoatama It pops up an ugly terminal when run, but nonetheless does make the thing open in the background. – digitxp – 2010-09-14T03:25:18.353

I don't have the time to do that to every menu entry though. – digitxp – 2010-09-14T03:25:36.997

Just setting it to strict wasn't enough? Ie if you don't start things via terminal they steal focus? – imoatama – 2010-09-14T14:03:43.977

See edited answer for a simpler workaround. – imoatama – 2010-09-14T14:22:56.647

Your workaround worked. In 2 release cycles I'll probably be installing Jolicloud anyway. Thanks. – digitxp – 2010-09-16T11:31:59.153

9

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.

Hippo

Posted 2010-09-04T18:08:40.023

Reputation: 474

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 – 2010-09-12T19:23:31.000

1This 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 – 2010-09-14T14:04:52.697

2

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.

Ryan Gooler

Posted 2010-09-04T18:08:40.023

Reputation: 1 844

nice and simple! +1 – studiohack – 2010-09-13T01:59:04.360

1But I want that behavior to be for every window, so it won't work to have all those windows on top. – digitxp – 2010-09-13T10:43:54.727

1

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.

Dave

Posted 2010-09-04T18:08:40.023

Reputation: 11

0

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

Aquarius

Posted 2010-09-04T18:08:40.023

Reputation: 1

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 – 2013-01-02T20:49:21.970