jdk/src/solaris/classes/sun/awt/X11/doc-files/Modality.txt
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
5100701: Toolkit.getLockingKeyState() does not work on XToolkit, but works on Motif Summary: Does not work on Motif but works on XToolkit now; implemented using XQueryPointer. Reviewed-by: anthony
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/* 
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
1. Useful API:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
  XWindowPeer.isModalBlocked()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
    Checks if this window is blocked by any modal dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
    For common component peers use getToplevelXWindow().isModalBlocked()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  XWindowPeer.setModalBlocked(Dialog blocker, boolean blocked)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
    Implementation of WindoePeer.setModalBlocked() method
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    Marks this window blocked/unblocked and adds/removes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
      from transient_for chain (see below)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    Don't call this method directly, it should be used from shared
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
      code only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  XWindowPeer.addToTransientFors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  XWindowPeer.removeFromTransientFors()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    See below
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
2. Filtering mouse events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  Mouse events are filtered in the shared code. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    java.awt.ModalFilter class for details
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
3. Filtering key events
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  Key events are filtering by preventing the blocked windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    to get native focus. All the AWT windows use global active focus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    input model (see ICCCM for details) and listens to WM_TAKE_FOCUS
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    protocol. If the window manager asks AWT to set focus on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    blocked window, in XDecoratedPeer.handleWmTakeFocus() method we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    set the focus to the window's blocker.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
4. Z-order
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  According to the Modality spec any modal dialog should be always on
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    top of its blocked windows. It is implemented with using
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    WM_TRANSIENT_FOR hint.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
  WM_TRANSIENT_FOR is used to mark one window to be a child of another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    one, in particular for any kind of dialogs. When a modal dialog
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    is shown it temporary becomes a child of all its blocked windows
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    and thus remains on top of them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
  WM_TRANSIENT_FOR value is a single window, so we can't directly make
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    a dialog be a child of several other windows. It is implemented
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    as a "transient_for chain": all the blocked windows are arranged
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    into a chain, each next window is transient for the prev.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  The chain is stored in XWindowPeer's fields 'prevTransientFor' and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    'nextTransientFor'. If window is not blocked both of these fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    are set to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  However, the value of WM_TRANSIENT_FOR hint and prevTransientFor
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    may differ sometimes. This happens when two windows are in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    different window states, usually NormalState and IconifiedState.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    Some window managers don't allow a dialog to be visible is its
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    parent window is iconified. The situation is even worse: we
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    don't receive any notifications when the dialog is iconified
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    together with its parent frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  Thus we need to track all the window's state changes. Also, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    any window state (NormalState, IconifiedState, WithdrawnState)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    a distinct chain is tracked. Below is a brief example.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
  Let's consider two frames F1 and F2 and two modeless dialogs D1
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    (with F1 as a parent) and D2 (F2). Their Z-order is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    F1 - D1 - F2 - D2 (D1 is above F1, F2 is above D1, etc). Then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    a modal dialog D3 is shown and all these four windows become
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    blocked by it. Transient_for chain is constructed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    following way: F1 - D2 - F2 - D2 - D3. Respectively, F2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    temporarily becomes a child of D1 (WM_TRANSIENT_FOR hint is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    set to F2 with a value of D1), etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
  Then F1 is iconified (some window managers allow this action).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    F1.nextTransientFor and D1.prevTransientFor aren't changed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    however the values of WM_TRANSIENT_FOR hint for them are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    changed: hint value for F1 is set to None, and hint value for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    D1 is set to None.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
  Let's iconify another window, F2. prev/nextTransientFor field
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    values aren't changed again, but WM_TRANSIENT_FOR hint is:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    the value for D2 is D1, the value for F2 is F1 (both are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    iconified).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  When either F1 or F2 is restored, the value for its hint is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    restored according to the value stored in prevTransientFor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    and nextTransientFor fields.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
  Note that some window managers don't allow iconifying for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    those windows that are children of some other toplevel. That
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    is any dialog can't be iconified and any blocked window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    that is not the first in the transient_for chain too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
  All the updates of the hint's value is performed in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    XWindowPeer.setToplevelTransientFor() method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
5. Multiscreen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
  All the problems with WM_TRANSIENT_FOR hint and different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    window states can be applied to different X screens (if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    Xinerama is off). For example, some window managers ignore
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    the hint if window and transient_for window are on different
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    screens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
  That leads to us to track a separate transient_for chain for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    every screen in the system, as well as for every window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    state. See XWindowPeer.updateTransientFor() for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
6. See also
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
  Some examples how transient_for chain is constructed and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    destructed can be found in JavaDoc comments for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    following methods: XWindowPeer.addToTransientFors(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    XWindowPeer.removeFromTransientFors(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    XWindowPeer.setToplevelTransientFor(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    XWindowPeer.stateChanged().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142