jdk/src/solaris/classes/sun/awt/X11/XlibUtil.java
author yan
Mon, 06 Oct 2008 16:45:00 +0400
changeset 1966 12a51fb0db0d
parent 439 3488710b02f8
child 2802 d05a9dcc8296
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
/*
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
     2
 * Copyright 2006-2008 Sun Microsystems, Inc.  All Rights Reserved.
2
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
package sun.awt.X11;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.Dimension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.awt.GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.awt.Point;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.awt.Rectangle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import sun.awt.X11GraphicsConfig;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.awt.X11GraphicsDevice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.awt.X11GraphicsEnvironment;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This class is a collection of utility methods that operate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * with native windows.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
public class XlibUtil
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * The constructor is made private to eliminate any
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * instances of this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private XlibUtil()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * Xinerama-aware version of XlibWrapper.RootWindow method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static long getRootWindow(int screenNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            X11GraphicsEnvironment x11ge = (X11GraphicsEnvironment)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                GraphicsEnvironment.getLocalGraphicsEnvironment();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            if (x11ge.runningXinerama())
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
                // all the Xinerama windows share the same root window
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
                return XlibWrapper.RootWindow(XToolkit.getDisplay(), 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            else
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                return XlibWrapper.RootWindow(XToolkit.getDisplay(), screenNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * Checks if the given window is a root window for the given screen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    static boolean isRoot(long rootCandidate, long screenNumber)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        long root;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            root = XlibWrapper.RootWindow(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                                          screenNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return root == rootCandidate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Returns the bounds of the given window, in absolute coordinates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    static Rectangle getWindowGeometry(long window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            int res = XlibWrapper.XGetGeometry(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                                               window,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                                               XlibWrapper.larg1, // root_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                                               XlibWrapper.larg2, // x_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                                               XlibWrapper.larg3, // y_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                                               XlibWrapper.larg4, // width_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
                                               XlibWrapper.larg5, // height_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                                               XlibWrapper.larg6, // border_width_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                                               XlibWrapper.larg7); // depth_return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            if (res == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            int x = Native.getInt(XlibWrapper.larg2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            int y = Native.getInt(XlibWrapper.larg3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            long width = Native.getUInt(XlibWrapper.larg4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            long height = Native.getUInt(XlibWrapper.larg5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            return new Rectangle(x, y, (int)width, (int)height);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Translates the given point from one window to another. Returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * null if the translation is failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    static Point translateCoordinates(long src, long dst, Point p)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        Point translated = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            XTranslateCoordinates xtc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                new XTranslateCoordinates(src, dst, p.x, p.y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                int status = xtc.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                if ((status != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    ((XToolkit.saved_error == null) ||
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   155
                     (XToolkit.saved_error.get_error_code() == XConstants.Success)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    translated = new Point(xtc.get_dest_x(), xtc.get_dest_y());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                xtc.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        return translated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * Translates the given rectangle from one window to another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns null if the translation is failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    static Rectangle translateCoordinates(long src, long dst, Rectangle r)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        Point translatedLoc = translateCoordinates(src, dst, r.getLocation());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (translatedLoc == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            return new Rectangle(translatedLoc, r.getSize());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * Returns the parent for the given window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
    static long getParentWindow(long window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            XBaseWindow bw = XToolkit.windowToXWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            if (bw != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                XBaseWindow pbw = bw.getParentWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (pbw != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                    return pbw.getWindow();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            XQueryTree qt = new XQueryTree(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                if (qt.execute() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                    return qt.get_parent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                qt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * Returns all the children for the given window
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    static Set<Long> getChildWindows(long window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            XBaseWindow bw = XToolkit.windowToXWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (bw != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                return bw.getChildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            XQueryTree xqt = new XQueryTree(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                int status = xqt.execute();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                if (status == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    return Collections.emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                long children = xqt.get_children();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                if (children == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                    return Collections.emptySet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                int childrenCount = xqt.get_nchildren();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                Set<Long> childrenSet = new HashSet<Long>(childrenCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                for (int i = 0; i < childrenCount; i++)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                    childrenSet.add(Native.getWindow(children, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                return childrenSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                xqt.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Checks if the given window is a Java window and is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * instance of XWindowPeer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    static boolean isXAWTToplevelWindow(long window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return XToolkit.windowToXWindow(window) instanceof XWindowPeer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * NOTICE: Right now returns only decorated top-levels (not Window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    static boolean isToplevelWindow(long window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (XToolkit.windowToXWindow(window) instanceof XDecoratedPeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            WindowPropertyGetter wpg =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                new WindowPropertyGetter(window, XWM.XA_WM_STATE, 0, 1, false,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                                         XWM.XA_WM_STATE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                wpg.execute(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                if (wpg.getActualType() == XWM.XA_WM_STATE.getAtom())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                wpg.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * The same as isToplevelWindow(window), but doesn't treat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * XEmbeddedFramePeer as toplevel.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    static boolean isTrueToplevelWindow(long window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        if (XToolkit.windowToXWindow(window) instanceof XEmbeddedFramePeer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return isToplevelWindow(window);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    static int getWindowMapState(long window)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        XWindowAttributes wattr = new XWindowAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            XToolkit.WITH_XERROR_HANDLER(XToolkit.IgnoreBadWindowHandler);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            int status = XlibWrapper.XGetWindowAttributes(XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                                                          window, wattr.pData);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            XToolkit.RESTORE_XERROR_HANDLER();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            if ((status != 0) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                ((XToolkit.saved_error == null) ||
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   354
                 (XToolkit.saved_error.get_error_code() == XConstants.Success)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                return wattr.get_map_state();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        finally
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            wattr.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
   365
        return XConstants.IsUnmapped;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * XSHAPE extension support.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    // The variable is declared static as the XSHAPE extension cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    // be disabled at run-time, and thus is available all the time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    // once the check is passed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    static Boolean isShapingSupported = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *  Returns whether the XSHAPE extension available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     *  @since 1.7
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    static synchronized boolean isShapingSupported() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        if (isShapingSupported == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                isShapingSupported =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
                    XlibWrapper.XShapeQueryExtension(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                            XToolkit.getDisplay(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                            XlibWrapper.larg1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                            XlibWrapper.larg2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        return isShapingSupported.booleanValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
}