Requesters/dialogs stealing focus

When requesters such as confirmation dialogs etc. pop up (possibly after lengthy pre-operations such as counting files etc.) they immediately steal the focus.

Now the problem is that if you're typing something elsewhere, you could easily inadvertently activate some shortcut or at the very least accidentally press enter in that moment.

AFAIK Windows has some mechanism where newly popped-up window won't steal focus if another window was receiving input events some milliseconds ago. Quick googling found this: https://technet.microsoft.com/en-us/library/cc957208.aspx, so this or something similar is not being honored by Opus' dialogs/requesters.

This happened to me at work today; I had Opus in foreground on a second monitor crunching some file task while I was typing code in Sublime Text on the first monitor, and Opus' confirmation requester popped up and quickly closed with me having no idea what I've just accidentally confirmed or canceled or whatever.

It's not something that should happen or that we do on purpose, but Windows' system for preventing focus-stealing does have some strange behaviors sometimes.

The way it is supposed to work is that a process which does not already have the focus should only be able to get it in three ways:

  1. The user clicks on one of the process's windows (of course!)

  2. The process that has the focus calls an API which specifies that the other process is allowed to take it. (That usually happens when one program launches another, or similar.)

  3. Certain APIs are used to force the focus to be taken. (Shouldn't be relevant with the progress dialogs and Replace / Error dialogs in Opus.)

It's possible that 2 is happening somehow, maybe by the text editor launching a folder (which would indirectly cause it to tell Windows to let Opus take the focus), and then either the focus not being taken in the end, or the permission to take it remaining for some reason.

I think the way Windows does the bookkeeping for this has never been perfect, but I don't know exactly why it fails sometimes.

If there are particular steps that can reproduce the problem, we might be able to see if we can do things differently to prevent it or make it less likely. It's not something I usually see, so it might depend on doing things in a particular way, or maybe something particular that Sublime does, if it only happens with that (I use a different editor, but it may not be relevant).

1 Like

Thanks for a detailed reply Leo! :+1:
I'll try to figure out the more precise repro steps and will report once/if I have some useful info.