Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a script that recompiles and relaunches a software project I am building in linux. However, I don't usually want to see my program's window immediately after it has launched, as I want to keep my keyboard focus on my vim window.

Normally, my program launches, is automatically given focus, and appears on top of the other windows on my workspace.

Is it possible in linux to launch a program but not have it steal focus, and not have it appear on top of all other windows?

Note: If it matters, I am running Fedora 13, GNOME, compiz, and use Emerald themes.

share|improve this question
    
That depends largely on your window manager. The application can do something, but the WM will often override that. So what is your window manager? –  Gilles Apr 8 '11 at 22:57
    
I'm running gnome, is that the window manager? –  Cory Klein Apr 8 '11 at 23:03
    
That's the desktop environment, but it's enough information. –  Gilles Apr 8 '11 at 23:05
    
@Gilles not necessarily, depending on whether he has desktop effect enabled will mean whether or not it's compiz or metacity. Gnome is not tied as strongly to one window manager as KDE and they have switched several time. I used to use fvwm with Gnome. –  penguin359 Apr 8 '11 at 23:35
    
I am using compiz –  Cory Klein Apr 8 '11 at 23:35

2 Answers 2

up vote 5 down vote accepted

Some Window Managers have a lot of customizability to do stuff like this, but a lot more recent ones including metacity and compiz have lost this kind of customization. I used to use fvwm to do stuff like that. A simpler WM independent approach would be to try and reassign focus back to the right window. Look at the xdotool http://www.semicomplete.com/projects/xdotool/xdotool. It should be available in your distro repository. It can, among other things, assign focus to specific Windows. I assume your running a script from a Terminal that you don't want to loose focus. If so, you should be able to use $WINDOWID to retrieve the Window ID for your terminal and use xdotool at the end of the script to refocus your Terminal.

share|improve this answer
    
WOW that is an awesome tool! –  Cory Klein Apr 8 '11 at 23:55
    
I've actually never heard of it before. It just seemed that there must be a command-line tool out there to control focus in X11. A quick search on Google brought that up. –  penguin359 Apr 9 '11 at 0:05

An alternative is to have the program connect to a different X server. You can either

  1. run a separate instance of X on a different virtual console. Switch with e.g. Ctrl-alt-F8.
  2. run Xnest to have an X server acting as a client to the main Xserver

Either way, your testing script should set DISPLAY to redirect the program to the other X server (it will probably be named :1).

share|improve this answer

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.