4 * This file manages a cache of X Atoms in order to avoid interactions
5 * with the X server. It's much like the Xmu routines, except it has a
6 * cleaner interface (caller doesn't have to provide permanent storage
7 * for atom names, for example).
9 * Copyright (c) 1990-1994 The Regents of the University of California.
10 * Copyright (c) 1994 Sun Microsystems, Inc.
12 * See the file "license.terms" for information on usage and redistribution of
13 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
19 * The following are a list of the predefined atom strings. They should match
20 * those found in xatom.h
23 static const char *const atomNameArray[] = {
24 "PRIMARY", "SECONDARY", "ARC",
25 "ATOM", "BITMAP", "CARDINAL",
26 "COLORMAP", "CURSOR", "CUT_BUFFER0",
27 "CUT_BUFFER1", "CUT_BUFFER2", "CUT_BUFFER3",
28 "CUT_BUFFER4", "CUT_BUFFER5", "CUT_BUFFER6",
29 "CUT_BUFFER7", "DRAWABLE", "FONT",
30 "INTEGER", "PIXMAP", "POINT",
31 "RECTANGLE", "RESOURCE_MANAGER", "RGB_COLOR_MAP",
32 "RGB_BEST_MAP", "RGB_BLUE_MAP", "RGB_DEFAULT_MAP",
33 "RGB_GRAY_MAP", "RGB_GREEN_MAP", "RGB_RED_MAP",
34 "STRING", "VISUALID", "WINDOW",
35 "WM_COMMAND", "WM_HINTS", "WM_CLIENT_MACHINE",
36 "WM_ICON_NAME", "WM_ICON_SIZE", "WM_NAME",
37 "WM_NORMAL_HINTS", "WM_SIZE_HINTS", "WM_ZOOM_HINTS",
38 "MIN_SPACE", "NORM_SPACE", "MAX_SPACE",
39 "END_SPACE", "SUPERSCRIPT_X", "SUPERSCRIPT_Y",
40 "SUBSCRIPT_X", "SUBSCRIPT_Y", "UNDERLINE_POSITION",
41 "UNDERLINE_THICKNESS", "STRIKEOUT_ASCENT", "STRIKEOUT_DESCENT",
42 "ITALIC_ANGLE", "X_HEIGHT", "QUAD_WIDTH",
43 "WEIGHT", "POINT_SIZE", "RESOLUTION",
44 "COPYRIGHT", "NOTICE", "FONT_NAME",
45 "FAMILY_NAME", "FULL_NAME", "CAP_HEIGHT",
46 "WM_CLASS", "WM_TRANSIENT_FOR",
51 * Forward references to functions defined in this file:
54 static void AtomInit(TkDisplay *dispPtr);
57 *--------------------------------------------------------------
61 * Given a string, produce the equivalent X atom. This function is
62 * equivalent to XInternAtom, except that it keeps a local cache of
63 * atoms. Once a name is known, the server need not be contacted again
67 * The return value is the Atom corresponding to name.
70 * A new entry may be added to the local atom cache.
72 *--------------------------------------------------------------
77 Tk_Window tkwin, /* Window token; map name to atom for this
78 * window's display. */
79 const char *name) /* Name to turn into atom. */
85 dispPtr = ((TkWindow *) tkwin)->dispPtr;
86 if (!dispPtr->atomInit) {
90 hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew);
95 atom = XInternAtom(dispPtr->display, name, False);
96 Tcl_SetHashValue(hPtr, INT2PTR(atom));
97 hPtr2 = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew);
98 Tcl_SetHashValue(hPtr2, Tcl_GetHashKey(&dispPtr->nameTable, hPtr));
100 return (Atom)PTR2INT(Tcl_GetHashValue(hPtr));
104 *--------------------------------------------------------------
108 * This function is equivalent to XGetAtomName except that it uses the
109 * local atom cache to avoid contacting the server.
112 * The return value is a character string corresponding to the atom given
113 * by "atom". This string's storage space is static: it need not be freed
114 * by the caller, and should not be modified by the caller. If "atom"
115 * doesn't exist on tkwin's display, then the string "?bad atom?" is
121 *--------------------------------------------------------------
126 Tk_Window tkwin, /* Window token; map atom to name relative to
127 * this window's display. */
128 Atom atom) /* Atom whose name is wanted. */
133 dispPtr = ((TkWindow *) tkwin)->dispPtr;
134 if (!dispPtr->atomInit) {
138 hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, INT2PTR(atom));
141 Tk_ErrorHandler handler;
143 char *mustFree = NULL;
145 handler = Tk_CreateErrorHandler(dispPtr->display, BadAtom, -1, -1,
147 name = mustFree = XGetAtomName(dispPtr->display, atom);
151 Tk_DeleteErrorHandler(handler);
152 hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew);
153 Tcl_SetHashValue(hPtr, INT2PTR(atom));
157 name = (const char *)Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
158 hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew);
159 Tcl_SetHashValue(hPtr, name);
161 return (const char *)Tcl_GetHashValue(hPtr);
165 *--------------------------------------------------------------
169 * Initialize atom-related information for a display.
175 * Tables get initialized, etc. etc..
177 *--------------------------------------------------------------
182 TkDisplay *dispPtr)/* Display to initialize. */
187 dispPtr->atomInit = 1;
188 Tcl_InitHashTable(&dispPtr->nameTable, TCL_STRING_KEYS);
189 Tcl_InitHashTable(&dispPtr->atomTable, TCL_ONE_WORD_KEYS);
191 for (atom = 1; atom <= XA_LAST_PREDEFINED; atom++) {
195 hPtr = Tcl_FindHashEntry(&dispPtr->atomTable, INT2PTR(atom));
200 name = atomNameArray[atom - 1];
201 hPtr = Tcl_CreateHashEntry(&dispPtr->nameTable, name, &isNew);
202 Tcl_SetHashValue(hPtr, INT2PTR(atom));
203 name = (const char *)Tcl_GetHashKey(&dispPtr->nameTable, hPtr);
204 hPtr = Tcl_CreateHashEntry(&dispPtr->atomTable, INT2PTR(atom), &isNew);
205 Tcl_SetHashValue(hPtr, name);