blob: 34c900ed4d05b89e673ab0fccbf8c1e53f801f41 [file] [log] [blame]
J. Duke319a3b92007-12-01 00:00:00 +00001/*
2 * Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Sun designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Sun in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22 * CA 95054 USA or visit www.sun.com if you need additional information or
23 * have any questions.
24 */
25
26package sun.awt.X11;
27
28import java.util.logging.*;
29
30import java.util.*;
31
32class XProtocol {
33 private final static Logger log = Logger.getLogger("sun.awt.X11.XProtocol");
34
35 private Map<XAtom, XAtomList> atomToList = new HashMap<XAtom, XAtomList>();
36 private Map<XAtom, Long> atomToAnchor = new HashMap<XAtom, Long>();
37
38 /*
39 * Temporary error handler that ensures that we know if
40 * XChangeProperty succeeded or not.
41 */
42 static XToolkit.XErrorHandler VerifyChangePropertyHandler = new XToolkit.XErrorHandler() {
43 public int handleError(long display, XErrorEvent err) {
44 XToolkit.XERROR_SAVE(err);
45 if (err.get_request_code() == XlibWrapper.X_ChangeProperty) {
46 return 0;
47 } else {
48 return XToolkit.SAVED_ERROR_HANDLER(display, err);
49 }
50 }
51 };
52 volatile boolean firstCheck = true;
53 /*
54 * Check that that the list of protocols specified by WM in property
55 * named LIST_NAME on the root window contains protocol PROTO.
56 */
57 boolean checkProtocol(XAtom listName, XAtom protocol) {
58 XAtomList protocols = atomToList.get(listName);
59
60 if (protocols != null) {
61 return protocols.contains(protocol);
62 }
63
64 protocols = listName.getAtomListPropertyList(XToolkit.getDefaultRootWindow());
65 atomToList.put(listName, protocols);
66 try {
67 return protocols.contains(protocol);
68 } finally {
69 if (firstCheck) {
70 firstCheck = false;
71 log.log(Level.FINE, "{0}:{1} supports {2}", new Object[] {this, listName, protocols});
72 }
73 }
74 }
75
76 /*
77 * Check for anchor_prop(anchor_type) on root, take the value as the
78 * window id and check if that window exists and has anchor_prop(anchor_type)
79 * with the same value (i.e. pointing back to self).
80 *
81 * Returns the anchor window, as some WM may put interesting stuff in
82 * its properties (e.g. sawfish).
83 */
84 long checkAnchorImpl(XAtom anchorProp, long anchorType) {
85 long root_xref, self_xref;
86
87 XToolkit.awtLock();
88 try {
89 root_xref = anchorProp.get32Property(XToolkit.getDefaultRootWindow(),
90 anchorType);
91 } finally {
92 XToolkit.awtUnlock();
93 }
94 if (root_xref == 0) {
95 return 0;
96 }
97 self_xref = anchorProp.get32Property(root_xref, anchorType);
98 if (self_xref != root_xref) {
99 return 0;
100 }
101 return self_xref;
102 }
103 public long checkAnchor(XAtom anchorProp, long anchorType) {
104 Long val = atomToAnchor.get(anchorProp);
105 if (val != null) {
106 return val.longValue();
107 }
108 long res = checkAnchorImpl(anchorProp, anchorType);
109 atomToAnchor.put(anchorProp, res);
110 return res;
111 }
112 public long checkAnchor(XAtom anchorProp, XAtom anchorType) {
113 return checkAnchor(anchorProp, anchorType.getAtom());
114 }
115
116}