+ "setting DirectFB focus to unexpected window" );
+
+ // Don't set DirectFB focus if we're called from HandleFocusEvent() on
+ // this window, because we already have the focus in that case. Not only
+ // would it be unnecessary, it would be harmful: RequestFocus() adds
+ // an event to DirectFB event queue and calling it when in
+ // HandleFocusEvent() could result in a window being focused when it
+ // should not be. Consider this example:
+ //
+ // tlw1->SetFocus(); // (1)
+ // tlw2->SetFocus(); // (2)
+ //
+ // This results in adding these events to DFB queue:
+ //
+ // DWET_GOTFOCUS(tlw1)
+ // DWET_LOSTFOCUS(tlw1)
+ // DWET_GOTFOCUS(tlw2)
+ //
+ // Note that the events are processed by event loop, i.e. not between
+ // execution of lines (1) and (2) above. So by the time the first
+ // DWET_GOTFOCUS event is handled, tlw2->SetFocus() was already executed.
+ // If we onconditionally called RequestFocus() from here, handling the
+ // first event would result in this change to the event queue:
+ //
+ // DWET_LOSTFOCUS(tlw1)
+ // DWET_GOTFOCUS(tlw2) // (3)
+ // DWET_LOSTFOCUS(tlw2)
+ // DWET_GOTFOCUS(tlw1)
+ //
+ // And the focus would get back to tlw1 even though that's not what we
+ // wanted.
+
+ if ( gs_insideDFBFocusHandlerOf == this )
+ return;