10.7.1 Normal Focus Events and Focus Events While Grabbed
Normal focus events are identified by
XFocusInEvent
or
XFocusOutEvent
structures whose mode member is set to 
NotifyNormal.
Focus events while grabbed are identified by
XFocusInEvent
or
XFocusOutEvent
structures whose mode member is set to 
NotifyWhileGrabbed.
The X server processes normal focus and focus events while grabbed according to 
the following:
- 
When the focus moves from window A to window B, A is an inferior of B, 
and the pointer is in window P, 
the X server does the following:
- 
It generates a
FocusOut
event on window A, with the detail member of the
XFocusOutEvent
structure set to 
NotifyAncestor. 
 - 
It generates a
FocusOut
event on each window between window A and window B, exclusive,
with the detail member of each
XFocusOutEvent
structure set to 
NotifyVirtual.
 - 
It generates a
FocusIn
event on window B, with the detail member of the 
XFocusOutEvent
structure set to 
NotifyInferior.
 - 
If window P is an inferior of window B
but window P is not window A or an inferior or ancestor of window A,
it generates a
FocusIn
event on each window below window B, down to and including window P, 
with the detail member of each 
XFocusInEvent
structure set to 
NotifyPointer.
 
 - 
When the focus moves from window A to window B, B is an inferior of A, 
and the pointer is in window P, 
the X server does the following:
- 
If window P is an inferior of window A
but P is not an inferior of window B or an ancestor of B,
it generates a
FocusOut
event on each window from window P up to but not including window A,
with the detail member of each 
XFocusOutEvent
structure set to  
NotifyPointer.
 - 
It generates a
FocusOut
event on window A,
with the detail member of the
XFocusOutEvent
structure set to  
NotifyInferior. 
 - 
It generates a
FocusIn
event on each window between window A and window B, exclusive, with the 
detail member of each 
XFocusInEvent
structure set to  
NotifyVirtual. 
 - 
It generates a
FocusIn
event on window B, with the detail member of the 
XFocusInEvent
structure set to  
NotifyAncestor.
 
 - 
When the focus moves from window A to window B, 
window C is their least common ancestor, 
and the pointer is in window P, 
the X server does the following:
- 
If window P is an inferior of window A,
it generates a
FocusOut
event on each window from window P up to but not including window A, 
with the detail member of the 
XFocusOutEvent
structure set to  
NotifyPointer.
 - 
It generates a
FocusOut
event on window A,
with the detail member of the
XFocusOutEvent
structure set to  
NotifyNonlinear.
 - 
It generates a
FocusOut
event on each window between window A and window C, exclusive,
with the detail member of each
XFocusOutEvent
structure set to  
NotifyNonlinearVirtual.
 - 
It generates a
FocusIn
event on each window between C and B, exclusive,
with the detail member of each
XFocusInEvent
structure set to  
NotifyNonlinearVirtual.
 - 
It generates a
FocusIn
event on window B, with the detail member of the 
XFocusInEvent
structure set to  
NotifyNonlinear.
 - 
If window P is an inferior of window B, it generates a
FocusIn
event on each window below window B down to and including window P, 
with the detail member of the 
XFocusInEvent
structure set to  
NotifyPointer.
 
 - 
When the focus moves from window A to window B on different screens 
and the pointer is in window P, 
the X server does the following:
- 
If window P is an inferior of window A, it generates a
FocusOut
event on each window from window P up to but not including window A, 
with the detail member of each 
XFocusOutEvent
structure set to  
NotifyPointer .
 - 
It generates a
FocusOut
event on window A,
with the detail member of the
XFocusOutEvent
structure set to  
NotifyNonlinear.
 - 
If window A is not a root window,
it generates a
FocusOut
event on each window above window A up to and including its root, 
with the detail member of each
XFocusOutEvent
structure set to  
NotifyNonlinearVirtual.
 - 
If window B is not a root window,
it generates a
FocusIn
event on each window from window B's root down to but not including
window B, with the detail member of each
XFocusInEvent
structure set to  
NotifyNonlinearVirtual.
 - 
It generates a
FocusIn
event on window B, with the detail member of each 
XFocusInEvent
structure set to  
NotifyNonlinear.
 - 
If window P is an inferior of window B, it generates a
FocusIn
event on each window below window B down to and including window P, 
with the detail member of each 
XFocusInEvent
structure set to  
NotifyPointer.
 
 - 
When the focus moves from window A to 
PointerRoot
(events sent to the window under the pointer)
or
None 
(discard), and the pointer is in window P,
the X server does the following:
- 
If window P is an inferior of window A, it generates a
FocusOut
event on each window from window P up to but not including window A, 
with the detail member of each 
XFocusOutEvent
structure set to  
NotifyPointer.
 - 
It generates a
FocusOut
event on window A, with the detail member of the
XFocusOutEvent
structure set to
NotifyNonlinear.
 - 
If window A is not a root window,
it generates a
FocusOut
event on each window above window A up to and including its root, 
with the detail member of each
XFocusOutEvent
structure set to
NotifyNonlinearVirtual.
 - 
It generates a
FocusIn
event on the root window of all screens, with the detail member of each
XFocusInEvent
structure set to
NotifyPointerRoot
(or
NotifyDetailNone).
 - 
If the new focus is
PointerRoot,
it generates a
FocusIn
event on each window from window P's root down to and including window P, 
with the detail member of each
XFocusInEvent
structure set to
NotifyPointer.
 
 - 
When the focus moves from 
PointerRoot
(events sent to the window under the pointer)
or
None 
to window A, and the pointer is in window P, 
the X server does the following: 
- 
If the old focus is
PointerRoot,
it generates a
FocusOut
event on each window from window P up to and including window P's root, 
with the detail member of each
XFocusOutEvent
structure set to
NotifyPointer .
 - 
It generates a
FocusOut
event on all root windows,
with the detail member of each
XFocusOutEvent
structure set to
NotifyPointerRoot
(or
NotifyDetailNone).
 - 
If window A is not a root window,
it generates a
FocusIn
event on each window from window A's root down to but not including window A,
with the detailmember of each
XFocusInEvent
structure set to
NotifyNonlinearVirtual.
 - 
It generates a
FocusIn
event on window A,
with the detail member of the 
XFocusInEvent
structure set to  
NotifyNonlinear.
 - 
If window P is an inferior of window A, it generates a
FocusIn
event on each window below window A down to and including window P, 
with the detail member of each 
XFocusInEvent
structure set to  
NotifyPointer.
 
 - 
When the focus moves from 
PointerRoot
(events sent to the window under the pointer)
to
None
(or vice versa), and the pointer is in window P, 
the X server does the following:
- 
If the old focus is
PointerRoot ,
it generates a
FocusOut
event on each window from window P up to and including window P's root, 
with the detail member of each
XFocusOutEvent
structure set to
NotifyPointer.
 - 
It generates a
FocusOut
event on all root windows,
with the detail member of each 
XFocusOutEvent
structure set to either
NotifyPointerRoot
or
NotifyDetailNone. 
 - 
It generates a
FocusIn
event on all root windows,
with the detail member of each
XFocusInEvent
structure set to
NotifyDetailNone 
or
NotifyPointerRoot.
 - 
If the new focus is
PointerRoot,
it generates a
FocusIn
event on each window from window P's root down to and including window P, 
with the detail member of each
XFocusInEvent
structure set to
NotifyPointer.
 
 
Christophe Tronche, ch.tronche@computer.org