Subversion Repositories shark

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 pj 1
/*
2
 * util32.c --
3
 *
4
 *      Miscellaneous functions that deal with 32 bit color displays.
5
 *
6
 */
7
 
8
/*
9
 * Copyright (c) 1995 The Regents of the University of California.
10
 * All rights reserved.
11
 *
12
 * Permission to use, copy, modify, and distribute this software and its
13
 * documentation for any purpose, without fee, and without written agreement is
14
 * hereby granted, provided that the above copyright notice and the following
15
 * two paragraphs appear in all copies of this software.
16
 *
17
 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
18
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
19
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
20
 * CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
21
 *
22
 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
23
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
 * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
25
 * ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
26
 * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
27
 */
28
 
29
/*
30
 * Portions of this software Copyright (c) 1995 Brown University.
31
 * All rights reserved.
32
 *
33
 * Permission to use, copy, modify, and distribute this software and its
34
 * documentation for any purpose, without fee, and without written agreement
35
 * is hereby granted, provided that the above copyright notice and the
36
 * following two paragraphs appear in all copies of this software.
37
 *
38
 * IN NO EVENT SHALL BROWN UNIVERSITY BE LIABLE TO ANY PARTY FOR
39
 * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
40
 * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF BROWN
41
 * UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42
 *
43
 * BROWN UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
44
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
45
 * PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
46
 * BASIS, AND BROWN UNIVERSITY HAS NO OBLIGATION TO PROVIDE MAINTENANCE,
47
 * SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
48
 */
49
 
50
#include <stdio.h>
51
#include <X11/Xlib.h>
52
#include <X11/Xutil.h>
53
#include "video.h"
54
#include "proto.h"
55
 
56
/*
57
   Changes to make the code reentrant:
58
      deglobalized: matched_depth
59
      use X variables in xinfo instead of globals
60
   Additional changes:
61
      #ifdef DISABLE_DITHER  - don't compile dither code
62
      fix parameter types for XCreateWindow call
63
   -lsh@cs.brown.edu (Loring Holden)
64
 */
65
 
66
 
67
/*
68
 *--------------------------------------------------------------
69
 *
70
 * FindFullColorVisual
71
 *
72
 *  Returns a pointer to a full color bit visual on the display
73
 *
74
 * Results:
75
 *      See above.
76
 *  
77
 * Side effects:
78
 *      Unknown.
79
 *
80
 *--------------------------------------------------------------
81
 */
82
Visual *
83
FindFullColorVisual (dpy, depth)
84
     Display *dpy;
85
     int *depth;
86
{
87
  XVisualInfo vinfo;
88
  XVisualInfo *vinfo_ret;
89
  int numitems, maxdepth;
90
 
91
  vinfo.class = TrueColor;
92
 
93
  vinfo_ret = XGetVisualInfo(dpy, VisualClassMask, &vinfo, &numitems);
94
 
95
  if (numitems == 0) return NULL;
96
 
97
  maxdepth = 0;
98
  while(numitems > 0) {
99
    if (vinfo_ret[numitems-1].depth > maxdepth) {
100
      maxdepth = vinfo_ret[numitems-1 ].depth;
101
    }
102
    numitems--;
103
  }
104
  XFree((void *) vinfo_ret);
105
 
106
  if (maxdepth < 16) return NULL;
107
 
108
  if (XMatchVisualInfo(dpy, DefaultScreen(dpy), maxdepth,
109
                       TrueColor, &vinfo)) {
110
    *depth = maxdepth;
111
    return vinfo.visual;
112
  }
113
 
114
  return NULL;
115
}
116
 
117
 
118
/*
119
 *--------------------------------------------------------------
120
 *
121
 * CreateFullColorWindow
122
 *
123
 *  Creates a window capable of handling 32 bit color.
124
 *
125
 * Results:
126
 *      See above.
127
 *  
128
 * Side effects:
129
 *      Unknown.
130
 *
131
 *--------------------------------------------------------------
132
 */
133
void
134
CreateFullColorWindow (xinfo)
135
     XInfo *xinfo;
136
{
137
  int depth;
138
  Visual *visual;
139
  XSetWindowAttributes xswa;
140
  unsigned long mask;
141
  unsigned int class;
142
  int screen;
143
  Display *dpy=xinfo->display;
144
  int x = xinfo->hints.x,
145
      y = xinfo->hints.y;
146
  unsigned int w = xinfo->hints.width,
147
               h = xinfo->hints.height;
148
 
149
  screen = XDefaultScreen(dpy);
150
  class = InputOutput;  /* Could be InputOnly */
151
  if (xinfo->visual == NULL) {
152
    xinfo->visual = visual = FindFullColorVisual (dpy, &depth);
153
    xinfo->depth = depth;
154
  } else {
155
     visual=xinfo->visual;
156
     depth=xinfo->depth;
157
  }
158
 
159
  if (visual == NULL) {
160
    return;
161
  }
162
  mask = CWBackPixel | CWColormap | CWBorderPixel;
163
  if (xinfo->cmap==0) {
164
  xswa.colormap = XCreateColormap(dpy,
165
                                  XRootWindow(dpy, screen),
166
                                  visual, AllocNone);
167
  } else xswa.colormap = xinfo->cmap;
168
  xswa.background_pixel = BlackPixel(dpy, DefaultScreen(dpy));
169
  xswa.border_pixel = WhitePixel(dpy, DefaultScreen(dpy));
170
 
171
  xinfo->window = XCreateWindow(dpy, RootWindow(dpy, screen), x, y, w, h,
172
    (unsigned int) 1, depth, class, visual, mask, &xswa);
173
}