1 /*
2  * xutil.c --
3  *
4  *	This function contains generic X emulation routines.
5  *
6  * Copyright (c) 1995-1996 Sun Microsystems, Inc.
7  *
8  * See the file "license.terms" for information on usage and redistribution
9  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
10  *
11  * RCS: @(#) $Id: xutil.c,v 1.2 1998/09/14 18:24:03 stanton Exp $
12  */
13 
14 #include <stdlib.h>
15 #include <tk.h>
16 
17 #ifdef MAC_TCL
18 #       include <Xutil.h>
19 #       include <Xatom.h>
20 #else
21 #       include <X11/Xutil.h>
22 #       include <X11/Xatom.h>
23 #endif
24 
25 /*
26  *----------------------------------------------------------------------
27  *
28  * XInternAtom --
29  *
30  *	This procedure simulates the XInternAtom function by calling
31  *	Tk_Uid to get a unique id for every atom.  This is only a
32  *	partial implementation, since it doesn't work across
33  *	applications.
34  *
35  * Results:
36  *	A new Atom.
37  *
38  * Side effects:
39  *	None.
40  *
41  *----------------------------------------------------------------------
42  */
43 
44 Atom
XInternAtom(display,atom_name,only_if_exists)45 XInternAtom(display, atom_name, only_if_exists)
46     Display* display;
47     _Xconst char* atom_name;
48     Bool only_if_exists;
49 {
50     static Atom atom = XA_LAST_PREDEFINED;
51 
52     display->request++;
53     return ++atom;
54 }
55 
56 /*
57  *----------------------------------------------------------------------
58  *
59  * XGetVisualInfo --
60  *
61  *	Returns information about the specified visual.
62  *
63  * Results:
64  *	Returns a newly allocated XVisualInfo structure.
65  *
66  * Side effects:
67  *	Allocates storage.
68  *
69  *----------------------------------------------------------------------
70  */
71 
72 XVisualInfo *
XGetVisualInfo(display,vinfo_mask,vinfo_template,nitems_return)73 XGetVisualInfo(display, vinfo_mask, vinfo_template, nitems_return)
74     Display* display;
75     long vinfo_mask;
76     XVisualInfo* vinfo_template;
77     int* nitems_return;
78 {
79     XVisualInfo *info = (XVisualInfo *)ckalloc(sizeof(XVisualInfo));
80     info->visual = DefaultVisual(display, 0);
81     info->visualid = info->visual->visualid;
82     info->screen = 0;
83     info->depth = info->visual->bits_per_rgb;
84     info->class = info->visual->class;
85     info->colormap_size = info->visual->map_entries;
86     info->bits_per_rgb = info->visual->bits_per_rgb;
87     info->red_mask = info->visual->red_mask;
88     info->green_mask = info->visual->green_mask;
89     info->blue_mask = info->visual->blue_mask;
90 
91     if (((vinfo_mask & VisualIDMask)
92 	    && (vinfo_template->visualid != info->visualid))
93 	    || ((vinfo_mask & VisualScreenMask)
94 		    && (vinfo_template->screen != info->screen))
95 	    || ((vinfo_mask & VisualDepthMask)
96 		    && (vinfo_template->depth != info->depth))
97 	    || ((vinfo_mask & VisualClassMask)
98 		    && (vinfo_template->class != info->class))
99 	    || ((vinfo_mask & VisualColormapSizeMask)
100 		    && (vinfo_template->colormap_size != info->colormap_size))
101 	    || ((vinfo_mask & VisualBitsPerRGBMask)
102 		    && (vinfo_template->bits_per_rgb != info->bits_per_rgb))
103 	    || ((vinfo_mask & VisualRedMaskMask)
104 		    && (vinfo_template->red_mask != info->red_mask))
105 	    || ((vinfo_mask & VisualGreenMaskMask)
106 		    && (vinfo_template->green_mask != info->green_mask))
107 	    || ((vinfo_mask & VisualBlueMaskMask)
108 		    && (vinfo_template->blue_mask != info->blue_mask))
109 	) {
110 	ckfree((char *) info);
111 	return NULL;
112     }
113 
114     *nitems_return = 1;
115     return info;
116 }
117