001: /*
002: * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.X11;
027:
028: import java.util.logging.*;
029:
030: import java.util.*;
031:
032: class XProtocol {
033: private final static Logger log = Logger
034: .getLogger("sun.awt.X11.XProtocol");
035:
036: private Map<XAtom, XAtomList> atomToList = new HashMap<XAtom, XAtomList>();
037: private Map<XAtom, Long> atomToAnchor = new HashMap<XAtom, Long>();
038:
039: /*
040: * Temporary error handler that ensures that we know if
041: * XChangeProperty succeeded or not.
042: */
043: static XToolkit.XErrorHandler VerifyChangePropertyHandler = new XToolkit.XErrorHandler() {
044: public int handleError(long display, XErrorEvent err) {
045: XToolkit.XERROR_SAVE(err);
046: if (err.get_request_code() == XlibWrapper.X_ChangeProperty) {
047: return 0;
048: } else {
049: return XToolkit.SAVED_ERROR_HANDLER(display, err);
050: }
051: }
052: };
053: volatile boolean firstCheck = true;
054:
055: /*
056: * Check that that the list of protocols specified by WM in property
057: * named LIST_NAME on the root window contains protocol PROTO.
058: */
059: boolean checkProtocol(XAtom listName, XAtom protocol) {
060: XAtomList protocols = atomToList.get(listName);
061:
062: if (protocols != null) {
063: return protocols.contains(protocol);
064: }
065:
066: protocols = listName.getAtomListPropertyList(XToolkit
067: .getDefaultRootWindow());
068: atomToList.put(listName, protocols);
069: try {
070: return protocols.contains(protocol);
071: } finally {
072: if (firstCheck) {
073: firstCheck = false;
074: log.log(Level.FINE, "{0}:{1} supports {2}",
075: new Object[] { this , listName, protocols });
076: }
077: }
078: }
079:
080: /*
081: * Check for anchor_prop(anchor_type) on root, take the value as the
082: * window id and check if that window exists and has anchor_prop(anchor_type)
083: * with the same value (i.e. pointing back to self).
084: *
085: * Returns the anchor window, as some WM may put interesting stuff in
086: * its properties (e.g. sawfish).
087: */
088: long checkAnchorImpl(XAtom anchorProp, long anchorType) {
089: long root_xref, self_xref;
090:
091: XToolkit.awtLock();
092: try {
093: root_xref = anchorProp.get32Property(XToolkit
094: .getDefaultRootWindow(), anchorType);
095: } finally {
096: XToolkit.awtUnlock();
097: }
098: if (root_xref == 0) {
099: return 0;
100: }
101: self_xref = anchorProp.get32Property(root_xref, anchorType);
102: if (self_xref != root_xref) {
103: return 0;
104: }
105: return self_xref;
106: }
107:
108: public long checkAnchor(XAtom anchorProp, long anchorType) {
109: Long val = atomToAnchor.get(anchorProp);
110: if (val != null) {
111: return val.longValue();
112: }
113: long res = checkAnchorImpl(anchorProp, anchorType);
114: atomToAnchor.put(anchorProp, res);
115: return res;
116: }
117:
118: public long checkAnchor(XAtom anchorProp, XAtom anchorType) {
119: return checkAnchor(anchorProp, anchorType.getAtom());
120: }
121:
122: }
|