Please stop grabbing focus on startup

Please stop grabbing focus when starting up the program. A very annoying thing where I might be typing something into another already executing program and then when DOPUS starts up, it grabs screen focus away. Most well-behaved programs stopped doing this a long time ago! Please stop doing this!

It's not something we do on purpose (nor that Windows should even let us do), and not something I see happening.

How/when are you launching Opus when this happens?

Is this at system boot or are you opening it manually? Via hotkey, taskbar, icon, etc. or something else?

Leo, thanks for the quick response. It is always during system startup and always, without fail, when it happens, it is DOPUS that is open on my screen. For example, I have an app that also comes up at system startup and it asks me for a password as part of its execution. Maybe about 2 or 3 times out of 10, I am typing the password and part way through me typing the long password, up pops DOPUS showing my 2 folder view and I can assure you, I did not click on DOPUS while in the middle of typing my password. It has NEVER been any other program than DOPUS that shows itself when this problem occurs, so I have to believe it is DOPUS grabbing screen focus. I did notice on this forum that there have been several issues raised about screen focus being grabbed so I also have to believe that your program knows how to do that. This exact problem occurred once again today and I had reached my breaking point with it and sure enough, DOPUS was there open on my screen.

Best regards, Don Bouchard

And by the way, I agree with you that Windows shouldn't let any program do that, but sadly it does.

1 Like

Is that not the default (annoying) behavior from windows? A program that is launched always grabs the focus?!
I know that on my work notebook (nearly) every program (which starts not minimized) is grabbing the focus from any other program (Win 10).

Ok, the outlook notification stays in background and notifications from skype or Teams also, but everything else...

So both Opus and the program you're typing into are started on Windows startup?

You can set Opus to not open any windows at Windows startup by selecting Preferences / Launching Opus / Startup / Don't open any Listers. (Or set it not to run at Windows startup at all, of course.)

I don't think we're doing anything to take focus, other than opening windows as they are normally opened, where the OS would only let them gain focus if the thing that launched us had focus and told Windows to pass that right on to us. My guess is the thing launching all the programs has focus and allowing all of them to take it if they activate a window; otherwise it shouldn't be possible (and isn't something we'd go out of our way to do, either; there's no reason to try to take focus from our point of view).

No, it is not the default behavior. There is a specific call to the OS to grab focus, a program has to make that call, else a program will start up in its own window and you have to select that window and then your app would be ready to receive input or clicks or whatever.

There is a function to request focus for an existing window, and when windows are made visible they can gain focus automatically, but Windows enforces rules on both that preclude the "stealing" of focus from other applications. If Opus is gaining focus it's because those rules are satisfied.

We can't not ask for focus at all, because most users expect that when a program launches it does become the foreground window.

Normally if you run an app from e.g. taskbar, it will take focus, except you focus another app while its loading, then it opens in background.

There's a good discussion of the issue, and the shortcomings in how Windows handles focus changes, here:

https://social.technet.microsoft.com/Forums/en-US/c22363e5-802c-4f43-b4e3-8a7259865648/windows-10-stop-any-application-from-stealing-focus-ever-is-it-possible?forum=win10itprogeneral

I was a developer on the Windows shell team at Microsoft during the Win7/Win8 time frame. I know they've thought a lot about this problem, but have ultimately punted on trying to do much more about it, because there's no way for the window manager to know whether an app is something the user wants to take activation or not. There's nothing in the architecture that can tie a specific window appearing back to a specific user-initiated launch of the app that window belongs to. Therefore it boils down to guesswork. For example, if I launch an app, and it finishes loading within 1 second, odds are very high that I expect that app to become the active window because I just launched it... it would be weird if I launched it and it didn't get activated. On the other hand, if the app takes 30 seconds to load, then odds are high that I went of to do something else and thus don't want it stealing activation. I believe their "solution" to this was basically to implement a time-based threshold between clicking on taskbar or start menu icons to launch an app and some new window appearing and requesting activation. But obviously any value you choose for the threshold isn't going to be perfect and is still going to annoy someone somewhere.

What they really need to do is build in more sensible logic like the following: "If user clicked an app launch icon, and window activation hasn't changed away from the explorer.exe process, and the user hasn't clicked on anything or pressed any keys anywhere inside the explorer.exe process, and a new window appears and asks for activation, then let it take activation. If a new window appears and asks for activation and it belongs to the process that already has the active window, let it take activation. Deny all other requests by any other windows to take activation, period."

Going into more detail about the specific problem in the root post:

  • You have two programs launching automatically at startup.
  • You want one to gain focus but not the other one.

There isn't really a way to get that in Windows*, at least that I can see and as things stand currently. If Windows was improved in the way the text I quoted suggests then it would work a lot better, but that's outside our control.

Both launched programs can potentially take focus. And indeed you want the program showing the password prompt to take focus! But there's nothing special about that program as far as the OS is concerned. It's not different to Opus. (And indeed, if the launch order or startup times of the programs were slightly different, the other program would be stealing focus from Opus.)

Assuming the launcher starts out owning the focus, it is up to the launcher, not the programs being launched, whether some or all of the things it launches are allowed to take that focus. The launcher leaves the door open for both programs, since it has no way to know you only want one of them to be activated. The door only shuts when you explicitly change which window has focus (e.g. clicking with the mouse or alt-tab).

I can't find any way for Opus to say "pretend AllowSetForegroundWindow was never called on our process". I did some experiments by calling AllowSetForegroundWindow and SetForegroundWindow on another program's window to give away focus if we had it, but our windows were still able to take focus after that, so it didn't seem to work as a way to disavow the ability to gain focus. It seems to be something the launcher needs to do (or not do).

The only thing we could do is ensure all calls to ShowWindow(..., SW_SHOW) were changed to use SW_SHOWNA instead, but I've looked into that and it's not very easy, give the number of different ways listers can open at startup (and in general), and when we'd only want it to happen at a specific time (during startup, if an option was on, and not at any other time).

An easier solution, if it's causing problems, is to configure Opus not to open at Windows startup, or not to open any windows at Windows startup.

(* Actually, one way to do it would be to have a proxy process which was launched by Windows at startup, and which then launches the real process without passing focus on to it. I think that would prevent the focus reaching the real process. I guess we could change the startup shortcut to run something like that if an option was turned on.)

1 Like

I tried that today and it doesn't work; if a process has focus and launches another process, that process can also get focus (even without calling AllowSetForegroundWindow), and there doesn't seem to be any way to prevent it even if you want to.

Also spent a long time looking for any other method to avoid gaining focus, or to launch a child process and block it from gaining focus, and there do not seem to be any ways to do it in Windows. Lots of people asking the same question, but no answers (or none that actually work with current versions of Windows, at least). It seems to be a flaw in the OS which we can't do much about.

3 Likes