Prevent windows from stealing focus

12,895

Solution 1

The setting is in CompizConfig > General > Focus & Raise Behavior as so documented. The Window Matching rules are quite important.

Solution 2

This is not something you should configure globally. I.e. you don't really want no new windows to take focus: you want no test windows to take focus. To accomplish this, use the Compiz Window Rules plugin to prevent all "test" Firefox windows from taking focus.

You would need to write a rule to identify only "test" Firefox instances. If they all have a specific string in the title, that would work. Otherwise you could use wmctrl to set the WM_ICON_NAME X property. (I don't know how to easily set X properties for Firefox .. if anyone else does, please chime in!)

Share:
12,895

Related videos on Youtube

Joel
Author by

Joel

I'm primarily a C# and Java developer. I also know Objective-C and have done some work with the iPhone SDK. I know some PHP, ASP.net, C++, and dabbled in some other languages.

Updated on September 17, 2022

Comments

  • Joel
    Joel over 1 year

    I'm using Maverick with Compiz enabled.

    I've searched AskUbuntu and Google. AskUbuntu doesn't have anything on this topic and everything Google turns up is a couple years old.

    I'm doing browser tests and my tests are constantly spawning new Firefox windows. The problem is, when the window is spawned it takes focus. This is incredibly annoying as I'm usually in the middle of typing somewhere else. This doesn't only happen with my tests, but is the most common example I run into. Sometimes my IDE decides it wants focus when something special happens (like when something is done compiling) and then later I'll find fragments of IM messages I've typed in my code. This is driving me crazy. I've looked in both Gnome settings and Compiz settings and can't find a way to prevent that from happening.

    Does anyone know of a way to prevent an app from stealing focus when it is opened? I'd rather have the taskbar flash at me or something to get my attention.

  • Joel
    Joel over 13 years
    Thanks, that helps. That keeps what I type going to the correct window, but the firefox windows that are being opened are still being opened ON TOP of what I'm working on... even though they don't have focus. Also, IntelliJ still ignores the rule.
  • lovinglinux
    lovinglinux over 13 years
    What kind of test you are doing and what kind of new windows are opened?
  • Joel
    Joel over 13 years
    @lovinglinux: sorry just noticed you asked. I'm running selenium tests so Firefox windows open. Also, I'm running JUnit tests with a debugger so when a breakpoint is hit IntelliJ decides to take focus to tell me about it. The Firefox focus issue was resolved by tweaking Compiz as stated in msw's post. IntelliJ, however, tends to ignore the Compiz setting.
  • blueyed
    blueyed almost 12 years
    @Joel how did you setup it? What Focus Prevention Level are you using and how did you configure the "Focus Prevention Windows" matching rules?
  • Joel
    Joel almost 12 years
    @blueyed, sorry, but it's been so long and I've since switched computers and don't remember what the settings were.
  • Dmitry Koroliov
    Dmitry Koroliov over 7 years
    in 16.04 the path to the option is CompizConfig -> General Options -> Focus&Raise Behavior tab. The word "General" in the answer is a bit misleading, since there is a tab General at the main CompizConfig view
  • 谈 超
    谈 超 over 7 years
    This helped me fix the Itellij idea focus steal on Ubuntu 16.04 with Unity by setting Focus Prevention Level to Very High or High and Focus Prevention Windows to !(class=Polkit-gnome-authentication-agent-1) & class=jetbrains-idea