Why is the desktop treated so special in window ordering?


Clipboarder Gadget wants to know why the desktop is treated so special in window ordering. Specifically, when you double-click a folder icon on the desktop, and the immediately close it, why does focus not go back to the desktop? Instead it goes to some random window.

Actually, it's the other way around. Focus is going to a random window specifically because the desktop is not being treated special.

The rules for focus transfer when a window is closed is that focus goes to the owner, if any. If there is no owner, then the window manager starts looking around, in a rather complicated way, but the next enabled window in the Z-order is on the candidate list. And since the desktop sits at the bottom of the Z-order, it almost never wins the "next enabled window in the Z-order" contest. Having the desktop somehow "jump the queue" and gain focus under certain conditions would mean giving the desktop special treatment.

Even if you wanted to grant the desktop that special treatment, what would the rules be for deciding when to grant the desktop exception? The Explorer window for the folder you opened has no special connection to the desktop window in the window hierarchy. It belongs to a different thread. Depending on how your system is configured, it might even be in another process. What would you use to determine that closing that window should move focus to the desktop?

Consider: You double-click the icon to open the folder. Then you click on Notepad. Then you click back on the folder window and close it. Shouldn't focus go to Notepad? Why should the desktop be special?

[Raymond is currently away; this message was pre-recorded.]

Comments (26)
  1. harmony7 says:

    I guess the thing here is that the desktop feels like it's part of the Explorer process, so when you open a folder window by double clicking an icon on the desktop it feels like the desktop should own the folder window.

  2. configurator says:

    Maybe the "special" treatment is that the z-order doesn't change. If the desktop was a regular window, a click would bring it to the front of the z-order, and opening notepad and closing it would mean that the next window to be shown is indeed the desktop. But that would also mean that clicking the desktop hides all your programs. Could be interesting.

  3. Random832 says:

    Of course, the desktop really does get special treatment: It's the only window that doesn't move to the top of the Z-order when you focus it. So people have a mental model of a list that windows are moved to the top of when they are focused (which is the case if you consider the Z order to be such a list), and of the focus going to the next one down when you close a window (which is, as you said, true) – they just don't realize this is the same as Z-order and thus affected by the fact that the desktop doesn't get put in front of other windows when you click on it.

    Also consider the fact that the alt-tab list, which constantly rearranges itself [in accordance with the Z order, I assume, since topmost windows appear at the front of the list always], displays this apparent behavior – and omits the desktop [another bit of special treatment].

    So, the way to make the desktop behave the same, in terms of focus, as other windows, would be to implement an "F-order" that acts the same as the Z order except it doesn't give the desktop special treatment. [or, for that matter, topmost windows – it doesn't matter for the focus thing since it's "next" rather than "first", but you could also use F-order for the alt-tab list]

  4. Bradley says:

    I doubt most people actually realize it's going by Z-Order.  Most people are probably under the assumption that it's going to the window (program) that had focus previously.  That just happens to match up with the Z-Order most of the time.

  5. SMW says:

    @Random832: The Desktop appears on the Alt-Tab list on my machine (Windows 7).  However, selecting it from Alt-Tab does not move it to the front of that list.  It's not the last entry, either, so something affects it's position in the list.

  6. Avi says:

    @SMW:

    The Desktop does not appear in my list.  Windows 7 Enterprise 64bit.  I use the Classic theme, though.  Perhaps that makes a difference?

  7. Klimax says:

    @Avi:

    Looks so as I use Windows 7 (altered) theme thus have Aero active and I do get Desktop in alt+tab order.

  8. Tim Dawson says:

    The original comment is valid. It is stupid that if you double-click something on the desktop to open it, then immediately close it, the desktop doesn't get the focus so you can move on to the next item. This should work on last focused, not topmost in the z order.

    [Think about it. Returning to last-focused would be extremely annoying for modal dialogs. -Raymond]
  9. Random832 says:

    @Klimax, SMW Are you sure? As I recall, Desktop appears in win-tab [which doesn't exist in classic] but not alt-tab.

  10. Klimax says:

    I'm pretty sure. (Tested before posting.)

  11. James says:

    Windows 7 (both 64 32-bit): I can confirm that he Desktop does indeed appear in the Alt+Tab list while using Aero themes, but the Classic theme seems to remove it from the list, much to my annoyance.

  12. Skyborne says:

    I have a Desktop item in the list in Alt+Tab on Vista using Aero Basic (where Win+Tab does nothing).  It makes sense it would be missing from the classic theme, because classically, it wasn't there….

  13. Clipboarder Gadget says:

    Thanks for answering my question!

    I really was under the impression that focus goes to the window that previously had it.

    The F-Order that Random832 suggested is a nice solution, but it would probably break compatibility. If I were at the explorer folks, I'd simply add an OpenedFromDesktop Flag to each folder window. It gets zeroed when the explorer window loses focus to a non-owned window and when the window is about to be closed or minimized and the flag is still set, the focus is set to the desktop. It's not perfect, but unlikely to break things and it would make navigating on the desktop with the keyboard much easier.

  14. Nektar says:

    What is strange and annoying though is the manner that on Windows Vista and above the Alt+Tab application-switching feature orders application windows when the desktop is involve. Normally, when pressing Alt+(the tab key repeatedly) to switch among all open applications, they are presented in a last-used-first ordering, i.e. the application which had the focus last appears first, the application you had used second to last appears second and so on. However, it seems to me that this logic is only followed when your focus is originally not on the desktop. On Windows Vista and 7 and if your focus is on the desktop when starting to press the Alt+Tab combination, application windows appear in some strange ordering, I think the reverse order that the buttons of the applications appear on the taskbar. I find this inconsistency very confusing and really annoying especially for users who like using the keyboard. When you start Alt+Tabbing from the desktop there is one type of behavior but when you start Alt+Tabbing from any other application another type of behavior. Is this a bug and if so why hasn't anyone noticed for so many years?

  15. @Raymond says:

    > Think about it. Returning to last-focused would be extremely annoying for modal dialogs.

    Mmh why ? If I have a modal dialog, I probably want the focus to return to the Window which fired the dialog which is likely to be the last which had focus.

    I know you must be right – but I can't figure out why.

  16. Tim says:

    @@Raymond: Open Notepad, choose File -> Save as, switch to another application, return to Notepad (still with the modal Save As dialog displayed), close the dialog. Apply the "return to last-focused" rule.

  17. 640k says:

    @Tim: focus should only goto last focused when there's no owner.

  18. Random832 says:

    "The F-Order that Random832 suggested is a nice solution, but it would probably break compatibility."

    Oh, certainly. The last opportunity to add this was Windows 3.1, whose "cool alt-tab" function exposed the Z-order rule as a feature. People have by now gotten used to, among other things, using alt-shift-tab to quickly get to topmost windows.

  19. Skyborne says:

    The more complexity that gets layered on, the harder it is to predict, and knowing humans it STILL won't do what you want.

    What about windows like gimp's floating tool boxes?

  20. Tim says:

    @640k: We were talking about modal dialogs. Obviously, there are no unowned modal dialogs.

  21. @Tim says:

    If a window to be closed is owned, focus should go to the owner. If the window is unowned, focus should go to the window that is now the foremost window (top of z-order), but with handling the desktop like any other window => can have a pseudo z-position other than the last.

  22. Mark says:

    I think the main reason against this proposed F-order is that all windows *obscure* the desktop.  So having focus revert to a window whose highlight is likely not to be visible is bound to lead to accidents.  Users expect the window that's in front of them to be in focus (which is why focus stealing apps are so evil).

    If you're regularly opening things from the desktop using the keyboard, stick all those shortcuts into a folder and open that first.

  23. @Mark says:

    "I think the main reason against this proposed F-order is that all windows *obscure* the desktop.  So having focus revert to a window whose highlight is likely not to be visible is bound to lead to accidents."

    You have clicked something at the desktop, which means that there is no window obscuring that point at that time. If a windows is obscuring that point in the meantime, you have moved it there, or started it, and so it will have a higher position in the F-oder than the desktop. It will get the focus and everthing works as expected.

    Also: Because Vista & Win 7 makes it very hard to distingush the active window from other windows (only small difference of the color of the title bar), nowadays you always have to look carefully where the focus is. Especially for a multi-monitor configuration. This is one of this bad design decisions after XP that I cannot understand.

  24. Ivan K says:

    [re Win-Tab] Aha! So that's what's happening – Accidentally hitting the Windows key instead of Alt on some computers. Then that weird scrolling windows thing (3D?) happens. And when it happens I see what's going on, but always select the wrong window. My guess is I look at the center of the screen and work out what window's there, rather than the one that's fully presented to the peripheral right. (Total guess, since I can't reproduce it on my non-aero pc).

  25. Robert says:

    "Also: Because Vista & Win 7 makes it very hard to distingush the active window from other windows (only small difference of the color of the title bar), nowadays you always have to look carefully where the focus is. Especially for a multi-monitor configuration. This is one of this bad design decisions after XP that I cannot understand."

    Yes, this irritates me so much and is just such an unbelievably bad change that I'm pretty sure the person(s) who did it *must* be color-blind. Is Windows 8 any better in this regard?

  26. Someone says:

    I'm currently in front of a Win7 system with the "Basic" theme. On the second monitor, Outlook 2010 is running. It is obviously using its own custom-drawn window frame: The title bar still has a vertical gradient which makes it looking different from the other non-active windows. So it always looks like the active windows.

    It would not be bad at all when there would be a greater difference between active and non-active windows.

    Is there no company policy to not abuse the non-client area in Microsoft's own applications? The Office team only needed to look at the code of mspaint.exe as an example of a Windows stock application that places icons in the title bar, but still shows a design-consistent title bar…

Comments are closed.

Skip to main content