File: x11dummy.c

package info (click to toggle)
mgp 1.13a+upstream20090219-11
  • links: PTS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 4,128 kB
  • sloc: ansic: 32,387; sh: 4,295; lisp: 1,405; yacc: 945; lex: 264; makefile: 158; perl: 117; awk: 9
file content (172 lines) | stat: -rw-r--r-- 4,319 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
 * Copyright (C) 1997 and 1998 WIDE Project.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. Neither the name of the project nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
/*
 * $Id: x11dummy.c,v 1.13 2000/03/04 02:37:48 nishida Exp $
 */

#include "mgp.h"

int window_x;
int window_y;

void
init_win1(geometry)
	char *geometry;
{
	if ((display = XOpenDisplay(NULL)) == NULL) {
		fprintf(stderr, "Can't open display\n");
		exit(-1);
	}
}

void
init_win2()
{
	XWindowAttributes xa;
	XSetWindowAttributes xsa;
	u_long mask = 0;

	screen = DefaultScreen(display);
	depth = DefaultDepth(display, screen);
	visual = DefaultVisual(display, screen);
	XGetWindowAttributes(display, DefaultRootWindow(display), &xa);
	if (window_width == 0 || window_height == 0) {
		window_width = xa.width;
		window_height = xa.height;
	}

	window = XCreateSimpleWindow(display, RootWindow(display, 0),
		0, 0, 800, 600, 0, fore_color[0], back_color[0]);

	pixmap  = XCreatePixmap(display, window,
		window_width, window_height, depth);
	xsa.override_redirect = True;
	mask |= CWOverrideRedirect;
	xsa.backing_store = Always;
	mask |= CWBackingStore;

	XChangeWindowAttributes(display, window, mask, &xsa);

	XFlush(display);
}

void
finish_win()
{
	XCloseDisplay(display);
}

#if 0
int
get_color(colorname, value)
	char *colorname;
	u_long *value;
{
	if (*value)
		*value = 0;
	return 0;	/*ok*/
}
#endif

int
get_color(colorname, value)
	char *colorname;
	u_long *value;
{
	XColor c0, c1;

	screen = DefaultScreen(display);
	colormap = DefaultColormap(display, screen);
/*XXX*/
	if (strcasecmp(colorname, "darkblue") == 0)
		colorname = "#00008b";
	if (XAllocNamedColor(display, colormap, colorname, &c1, &c0) == 0)
		return -1;
	if (value)
		*value = c1.pixel;
	return 0;
}


struct g_color *
name2gcolor(colorname)
	char *colorname;
{
	Colormap cmap;
	XColor c0, c1;
	struct g_color *color;

	color = (struct g_color *)malloc(sizeof(struct g_color));
	cmap = DefaultColormap(display, 0);

	if (XLookupColor(display, cmap, colorname, &c1, &c0)) {
		color->r = (c1.red >> 8) & 0xff;
		color->g = (c1.green >> 8) & 0xff;
		color->b = (c1.blue >> 8) & 0xff;
	} else
		fprintf(stderr, "color '%s' unknown. ignored.\n", colorname);

	return color;
}

void
free_alloc_colors(clr)
struct  alloc_color *clr;
{  
#ifdef COLOR_BUGFIX
	if (!(mgp_flag & FL_PRIVATE)) return;
#endif
	if (clr->num){
		XFreeColors(display, colormap, clr->colors, clr->num, 0);
		free(clr->colors);
		clr->colors = NULL;
		clr->num = 0;
	}
}

void
regist_alloc_colors(clr, colors, num)
struct  alloc_color *clr;
u_long  *colors;
int     num;
{
	u_int   i;

#ifdef COLOR_BUGFIX
	if (!(mgp_flag & FL_PRIVATE)) return;
#endif
	if (!clr->num)
		clr->colors = (long *)malloc(sizeof(u_long) * num);
	else
		clr->colors = (long *)realloc(clr->colors,
						sizeof(u_long) * (clr->num + num));
	for (i = 0; i < num; i++)
		clr->colors[clr->num +i] = (u_long)*(colors +i);
	clr->num += num;
}