jdk/src/solaris/classes/sun/awt/X11/XProtocol.java
author mchung
Tue, 29 Sep 2009 16:03:03 -0700
changeset 3938 ef327bd847c0
parent 2802 d05a9dcc8296
child 4214 0fa32d38146b
permissions -rw-r--r--
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes Summary: Replace calls to Logger with sun.util.logging.PlatformLogger Reviewed-by: prr, art, alexp, dcherepanov, igor, dav, 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
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    28
import sun.util.logging.PlatformLogger;
2
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 {
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    33
    private final static PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XProtocol");
2
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
    volatile boolean firstCheck = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
     * Check that that the list of protocols specified by WM in property
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * named LIST_NAME on the root window contains protocol PROTO.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    boolean checkProtocol(XAtom listName, XAtom protocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        XAtomList protocols = atomToList.get(listName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        if (protocols != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            return protocols.contains(protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        protocols = listName.getAtomListPropertyList(XToolkit.getDefaultRootWindow());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        atomToList.put(listName, protocols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            return protocols.contains(protocol);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            if (firstCheck) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
                firstCheck = false;
3938
ef327bd847c0 6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents: 2802
diff changeset
    57
                log.fine("{0}:{1} supports {2}", this, listName, protocols);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * Check for anchor_prop(anchor_type) on root, take the value as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * window id and check if that window exists and has anchor_prop(anchor_type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * with the same value (i.e. pointing back to self).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * Returns the anchor window, as some WM may put interesting stuff in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * its properties (e.g. sawfish).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    long checkAnchorImpl(XAtom anchorProp, long anchorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        long root_xref, self_xref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        XToolkit.awtLock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            root_xref = anchorProp.get32Property(XToolkit.getDefaultRootWindow(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                                                 anchorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            XToolkit.awtUnlock();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        if (root_xref == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        self_xref = anchorProp.get32Property(root_xref, anchorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        if (self_xref != root_xref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return self_xref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public long checkAnchor(XAtom anchorProp, long anchorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        Long val = atomToAnchor.get(anchorProp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (val != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            return val.longValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        long res = checkAnchorImpl(anchorProp, anchorType);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        atomToAnchor.put(anchorProp, res);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        return res;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public long checkAnchor(XAtom anchorProp, XAtom anchorType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        return checkAnchor(anchorProp, anchorType.getAtom());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
}