author | Alan Coopersmith <Alan.Coopersmith@Oracle.COM> |
Sun, 23 Nov 2014 21:46:46 -0800 | |
changeset 1422 | e9cadc0026d8 |
parent 1233 | 1134c9fd2fe6 |
permissions | -rw-r--r-- |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
1 |
/* |
1233
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
2 |
* Copyright (c) 1990, 2011, Oracle and/or its affiliates. All rights reserved. |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
3 |
* |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
919
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
5 |
* copy of this software and associated documentation files (the "Software"), |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
6 |
* to deal in the Software without restriction, including without limitation |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
8 |
* and/or sell copies of the Software, and to permit persons to whom the |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
9 |
* Software is furnished to do so, subject to the following conditions: |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
10 |
* |
919
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
11 |
* The above copyright notice and this permission notice (including the next |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
12 |
* paragraph) shall be included in all copies or substantial portions of the |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
13 |
* Software. |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
14 |
* |
919
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
15 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
16 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
17 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
18 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
19 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
20 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
425233ae7236
6931307 Standardize Sun copyright & license notices in X gate on current format
Alan Coopersmith <Alan.Coopersmith@Sun.COM>
parents:
907
diff
changeset
|
21 |
* DEALINGS IN THE SOFTWARE. |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
22 |
* |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
23 |
*/ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
24 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
25 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
26 |
#include <stdio.h> |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
27 |
#ifndef SYSV |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
28 |
#include <alloca.h> |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
29 |
#endif |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
30 |
#include <X11/Xlib.h> |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
31 |
#include <X11/Xatom.h> |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
32 |
#include "cmc.h" |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
33 |
#include "cmcutil.h" |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
34 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
35 |
#define MIN(a,b) ((a)<(b)?(a):(b)) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
36 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
37 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
38 |
static void |
1233
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
39 |
cmc_alloc ( |
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
40 |
Screen *screen, |
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
41 |
int ncolors, |
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
42 |
XColor *colors) |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
43 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
44 |
{ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
45 |
register Colormap cmap = DefaultColormapOfScreen(screen); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
46 |
register Pixel *p; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
47 |
register XColor *c; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
48 |
register int nalloc; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
49 |
register int total_alloc = 0; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
50 |
register int ntotal; |
1233
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
51 |
unsigned long mask; |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
52 |
Pixel *pixels; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
53 |
int nc; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
54 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
55 |
ntotal = 1<<PlanesOfScreen(screen); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
56 |
#ifdef SYSV |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
57 |
pixels = (Pixel *) malloc(ntotal * sizeof(Pixel)); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
58 |
#else |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
59 |
pixels = (Pixel *) alloca(ntotal * sizeof(Pixel)); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
60 |
#endif |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
61 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
62 |
/* Grab as many private cells as we can */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
63 |
for (nalloc=ntotal, p=pixels; nalloc > 0; nalloc>>=1) { |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
64 |
if (!XAllocColorCells(DisplayOfScreen(screen), cmap, 0, &mask, 0, |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
65 |
p, nalloc)) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
66 |
continue; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
67 |
p += nalloc; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
68 |
total_alloc += nalloc; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
69 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
70 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
71 |
/* |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
72 |
** May not be able to get as many colors as requested. |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
73 |
*/ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
74 |
nc = MIN(ncolors, total_alloc); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
75 |
if (nc != ncolors) { |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
76 |
(void) fprintf(stderr, "Warning: can only allocate %d of the requested %d colors.\n", nc, ncolors); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
77 |
(void) fprintf(stderr, "Continuing anyway.\n"); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
78 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
79 |
ncolors = nc; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
80 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
81 |
/* Free enough space for workspace colors */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
82 |
nalloc = total_alloc - ncolors; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
83 |
XFreeColors(DisplayOfScreen(screen), cmap, pixels+nalloc, ncolors, 0); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
84 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
85 |
/* Allocate the workspace colors */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
86 |
for (c=colors+ncolors-1; c>=colors; c--) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
87 |
if (!XAllocColor(DisplayOfScreen(screen), cmap, c)) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
88 |
fatal_error("attempt to allocate color failed"); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
89 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
90 |
/* Free placeholder pixels */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
91 |
XFreeColors(DisplayOfScreen(screen), cmap, pixels, nalloc, 0); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
92 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
93 |
/* |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
94 |
** Tell everybody how many workspace colors there are. |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
95 |
** Be sure to include white/black if they're at the |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
96 |
** high end. |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
97 |
*/ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
98 |
{ Visual *vis = DefaultVisualOfScreen(screen); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
99 |
int cmap_size = vis->map_entries; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
100 |
if (WhitePixelOfScreen(screen) == cmap_size-1 || |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
101 |
WhitePixelOfScreen(screen) == cmap_size-2) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
102 |
ncolors++; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
103 |
if (BlackPixelOfScreen(screen) == cmap_size-1 || |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
104 |
BlackPixelOfScreen(screen) == cmap_size-2) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
105 |
ncolors++; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
106 |
prop_update(DisplayOfScreen(screen), RootWindowOfScreen(screen), |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
107 |
COUNT_PROP_NAME, XA_INTEGER, 32, ncolors, 1); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
108 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
109 |
#ifdef SYSV |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
110 |
free(pixels); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
111 |
#endif |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
112 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
113 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
114 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
115 |
static void |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
116 |
cmc_alloc_protected (screen, ncolors, colors) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
117 |
Screen *screen; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
118 |
int ncolors; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
119 |
XColor *colors; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
120 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
121 |
{ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
122 |
XGrabServer(DisplayOfScreen(screen)); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
123 |
cmc_alloc(screen, ncolors, colors); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
124 |
XUngrabServer(DisplayOfScreen(screen)); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
125 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
126 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
127 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
128 |
/* |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
129 |
** For each screen for which there is saved workspace colors, |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
130 |
** allocates these colors as high as possible in the default |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
131 |
** colormap of the screen. |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
132 |
*/ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
133 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
134 |
void |
1233
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
135 |
cmc_init (void) |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
136 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
137 |
{ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
138 |
Display *dpy; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
139 |
FILE *f; |
1233
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
140 |
const char *filename; |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
141 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
142 |
/* Open display */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
143 |
if (!(dpy = open_display(display_name))) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
144 |
fatal_error("cannot open display '%s'\n", display_name); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
145 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
146 |
/* For some strange reason, cmc_alloc_protected fails if not |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
147 |
run synchronously */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
148 |
XSynchronize(dpy, 1); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
149 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
150 |
/* Open file where workspace colors are stored */ |
1233
1134c9fd2fe6
7125797 Fix crufty code complaints uncovered by xorg-macros new tougher defaults
Alan Coopersmith <Alan.Coopersmith@Oracle.COM>
parents:
943
diff
changeset
|
151 |
filename = comp_colors_filename(basename_arg); |
550
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
152 |
if ((f = fopen(filename, "r")) == NULL) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
153 |
/* Do nothing if not found */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
154 |
return; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
155 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
156 |
/* Check magic number and version */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
157 |
cmc_header_test(f); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
158 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
159 |
/* Abandon any previously allocated workspace colors (all screens) */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
160 |
resource_discard(dpy); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
161 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
162 |
/* For each screen of display ... */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
163 |
for (;;) { |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
164 |
Screen *screen; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
165 |
int scr_num; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
166 |
int ncolors; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
167 |
XColor *colors; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
168 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
169 |
if (!cmc_read(f, &scr_num, &ncolors, &colors)) |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
170 |
break; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
171 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
172 |
/* See if screen is still present */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
173 |
if (scr_num >= ScreenCount(dpy)) { |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
174 |
warning("Warning: cannot allocated saved colors for screen %d because\nthe display no longer has this many screens\n", scr_num); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
175 |
continue; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
176 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
177 |
screen = ScreenOfDisplay(dpy, scr_num); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
178 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
179 |
/* |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
180 |
** Existence of workspace colors for the screen implies |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
181 |
** that its default visual was dynamic indexed. Make sure |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
182 |
** it still is. |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
183 |
*/ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
184 |
if (!dynamic_indexed_default_visual(screen)) { |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
185 |
warning("default visual for screen %d is no longer dynamic indexed\nsaved colors not allocated for screen %d", scr_num, scr_num); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
186 |
continue; |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
187 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
188 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
189 |
/* Allocate workspace colors at high end of colormap */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
190 |
cmc_alloc_protected(screen, ncolors, colors); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
191 |
free((char *)colors); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
192 |
} |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
193 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
194 |
/* Preserve newly allocated client resources */ |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
195 |
resource_preserve(dpy); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
196 |
|
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
197 |
XCloseDisplay(dpy); |
3b62053c3b77
6730028 Moving /usr/openwin/lib/mkcookie to /usr/X11/lib
Sam Lau <Sam.Lau@Sun.COM>
parents:
diff
changeset
|
198 |
} |