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.

  • 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 'SO- stop being evil' 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 'SO- stop being evil' 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

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.

  • 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).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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