When a focused window is closed, Windows will typically set focus to a different window when possible. I’m trying to figure out what exactly causes this to happen, and in what scenarios does this not occur. I’m noticing that when some windows are closed, they do not cause the OS to set focus to a new window (eg. Discord, Slack). Discord and Slack are both hidden instead of destroyed on close, but then there are also other windows that when hidden will still cause the OS to set focus to a different window. One such example is with a fresh WPF app and changing the window’s Visibility to Collapsed – this causes the window to be hidden, not destroyed, and yet the OS reassigns focus to another window. What causes some windows when hidden to reassign focus (eg. WPF collapse)? As opposed to applications like Discord/Slack, which are hidden, yet do not reassign OS focus.
Share
The decision to reassign focus when a window is closed is typically based on the window’s behavior when being closed. This behavior is typically controlled by the application that created the window and the specific action that was taken to close the window (e.g. clicking the close button, using a keyboard shortcut, etc.).
For example, some applications may choose to hide the window when it is closed instead of destroying it, which would not trigger the OS to reassign focus. On the other hand, when a WPF window is collapsed, it is treated as if it were closed and the OS will reassign focus as it would with a closed window.
It’s also worth noting that the behavior of window management in Windows can vary depending on the specific version of the operating system and the desktop environment being used.