jdk/src/solaris/classes/sun/awt/X11/XProtocol.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 2003-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.util.logging.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
class XProtocol {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    private final static Logger log = Logger.getLogger("sun.awt.X11.XProtocol");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    private Map<XAtom, XAtomList> atomToList = new HashMap<XAtom, XAtomList>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    private Map<XAtom, Long> atomToAnchor = new HashMap<XAtom, Long>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
     * Temporary error handler that ensures that we know if
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * XChangeProperty succeeded or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    static XToolkit.XErrorHandler VerifyChangePropertyHandler = new XToolkit.XErrorHandler() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
            public int handleError(long display, XErrorEvent err) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
                XToolkit.XERROR_SAVE(err);
439
3488710b02f8 6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents: 2
diff changeset
    45
                if (err.get_request_code() == XProtocolConstants.X_ChangeProperty) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
                    return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                    return XToolkit.SAVED_ERROR_HANDLER(display, err);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    volatile boolean firstCheck = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     * Check that that the list of protocols specified by WM in property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * named LIST_NAME on the root window contains protocol PROTO.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    boolean checkProtocol(XAtom listName, XAtom protocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        XAtomList protocols = atomToList.get(listName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        if (protocols != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            return protocols.contains(protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        protocols = listName.getAtomListPropertyList(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        atomToList.put(listName, protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            return protocols.contains(protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (firstCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                firstCheck = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                log.log(Level.FINE, "{0}:{1} supports {2}", new Object[] {this, listName, protocols});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Check for anchor_prop(anchor_type) on root, take the value as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * window id and check if that window exists and has anchor_prop(anchor_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * with the same value (i.e. pointing back to self).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * Returns the anchor window, as some WM may put interesting stuff in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * its properties (e.g. sawfish).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    long checkAnchorImpl(XAtom anchorProp, long anchorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        long root_xref, self_xref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            root_xref = anchorProp.get32Property(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                                                 anchorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (root_xref == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        self_xref = anchorProp.get32Property(root_xref, anchorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (self_xref != root_xref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        return self_xref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public long checkAnchor(XAtom anchorProp, long anchorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        Long val = atomToAnchor.get(anchorProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (val != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            return val.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        long res = checkAnchorImpl(anchorProp, anchorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        atomToAnchor.put(anchorProp, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public long checkAnchor(XAtom anchorProp, XAtom anchorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return checkAnchor(anchorProp, anchorType.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
}