ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xpm.C
(Generate patch)

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.7 by pcg, Sun Feb 1 01:34:41 2004 UTC vs.
Revision 1.28 by root, Wed Jan 18 17:49:47 2006 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: xpm.c 2 * File: xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: xpm.C,v 1.7 2004/02/01 01:34:41 pcg Exp $
5 * 4 *
6 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au> 6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
8 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
9 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
25 24
26#include "../config.h" /* NECESSARY */ 25#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 26#include "rxvt.h" /* NECESSARY */
28#include "xpm.intpro" /* PROTOS for internal routines */
29 27
30#ifdef XPM_BACKGROUND 28#ifdef XPM_BACKGROUND
29
30static void rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight);
31 31
32/* 32/*
33 * These GEOM strings indicate absolute size/position: 33 * These GEOM strings indicate absolute size/position:
34 * @ `WxH+X+Y' 34 * @ `WxH+X+Y'
35 * @ `WxH+X' -> Y = X 35 * @ `WxH+X' -> Y = X
50 * @ `?' 50 * @ `?'
51 */ 51 */
52int 52int
53rxvt_term::scale_pixmap (const char *geom) 53rxvt_term::scale_pixmap (const char *geom)
54{ 54{
55 int flags, changed = 0; 55 int flags, changed = 0;
56 int x = 0, y = 0; 56 int x = 0, y = 0;
57 unsigned int w = 0, h = 0; 57 unsigned int w = 0, h = 0;
58 unsigned int n; 58 unsigned int n;
59 char *p, *str; 59 char *p;
60 bgPixmap_t *bgpixmap = &(bgPixmap); 60 bgPixmap_t *bgpixmap = & (bgPixmap);
61 61
62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 62#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
63 63
64 if (geom == NULL) 64 if (geom == NULL)
65 return 0; 65 return 0;
66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 66
67 if (!STRCMP(geom, "?")) 67 char str[MAXLEN_GEOM];
68
69 if (!strcmp (geom, "?"))
68 { 70 {
69 sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */ 71 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
70 min(bgpixmap->w, 9999), min(bgpixmap->h, 9999), 72 min (bgpixmap->w, 32767), min (bgpixmap->h, 32767),
71 min(bgpixmap->x, 9999), min(bgpixmap->y, 9999)); 73 min (bgpixmap->x, 32767), min (bgpixmap->y, 32767));
72 xterm_seq (XTerm_title, str, CHAR_ST); 74 process_xterm_seq (XTerm_title, str, CHAR_ST);
73 free(str);
74 return 0; 75 return 0;
75 } 76 }
76 77
77 if ((p = STRCHR(geom, ';')) == NULL) 78 if ((p = strchr (geom, ';')) == NULL)
78 p = STRCHR(geom, '\0'); 79 p = strchr (geom, '\0');
80
79 n = (p - geom); 81 n = (p - geom);
80 if (n <= MAXLEN_GEOM) 82 if (n <= MAXLEN_GEOM)
81 { 83 {
82 STRNCPY(str, geom, n); 84 strncpy (str, geom, n);
83 str[n] = '\0'; 85 str[n] = '\0';
84 86
85 flags = XParseGeometry(str, &x, &y, &w, &h); 87 flags = XParseGeometry (str, &x, &y, &w, &h);
88
86 if (!flags) 89 if (!flags)
87 { 90 {
88 flags |= WidthValue; 91 flags |= WidthValue;
89 w = 0; 92 w = 0;
90 } /* default is tile */ 93 } /* default is tile */
94
91 if (flags & WidthValue) 95 if (flags & WidthValue)
92 { 96 {
93 if (!(flags & XValue)) 97 if (!(flags & XValue))
94 x = 50; 98 x = 50;
99
95 if (!(flags & HeightValue)) 100 if (!(flags & HeightValue))
96 h = w; 101 h = w;
102
97 if (w && !h) 103 if (w && !h)
98 { 104 {
99 w = (bgpixmap->w * w) / 100; 105 w = (bgpixmap->w * w) / 100;
100 h = bgpixmap->h; 106 h = bgpixmap->h;
101 } 107 }
102 else if (h && !w) 108 else if (h && !w)
103 { 109 {
104 w = bgpixmap->w; 110 w = bgpixmap->w;
105 h = (bgpixmap->h * h) / 100; 111 h = (bgpixmap->h * h) / 100;
106 } 112 }
107 if (w > 1000) 113
108 w = 1000; 114 min_it (w, 32767);
109 if (h > 1000) 115 min_it (h, 32767);
110 h = 1000; 116
111 if (bgpixmap->w != (short)w) 117 if (bgpixmap->w != (short)w)
112 { 118 {
113 bgpixmap->w = (short)w; 119 bgpixmap->w = (short)w;
114 changed++; 120 changed++;
115 } 121 }
122
116 if (bgpixmap->h != (short)h) 123 if (bgpixmap->h != (short)h)
117 { 124 {
118 bgpixmap->h = (short)h; 125 bgpixmap->h = (short)h;
119 changed++; 126 changed++;
120 } 127 }
121 } 128 }
129
122 if (!(flags & YValue)) 130 if (!(flags & YValue))
123 { 131 {
124 if (flags & XNegative) 132 if (flags & XNegative)
125 flags |= YNegative; 133 flags |= YNegative;
134
126 y = x; 135 y = x;
127 } 136 }
128 137
129 if (!(flags & WidthValue) && geom[0] != '=') 138 if (!(flags & WidthValue) && geom[0] != '=')
130 { 139 {
131 x += bgpixmap->x; 140 x += bgpixmap->x;
132 y += bgpixmap->y; 141 y += bgpixmap->y;
133 } 142 }
134 else 143
135 { 144 if (xpmAttr.width && xpmAttr.height)
136 if (flags & XNegative)
137 x += 100;
138 if (flags & YNegative)
139 y += 100;
140 } 145 {
141 MIN_IT(x, 100); 146 x = MOD(x, xpmAttr.width);
142 MIN_IT(y, 100); 147 y = MOD(y, xpmAttr.height);
143 MAX_IT(x, 0); 148 }
144 MAX_IT(y, 0); 149
145 if (bgpixmap->x != x) 150 if (bgpixmap->x != x)
146 { 151 {
147 bgpixmap->x = x; 152 bgpixmap->x = x;
148 changed++; 153 changed++;
149 } 154 }
155
150 if (bgpixmap->y != y) 156 if (bgpixmap->y != y)
151 { 157 {
152 bgpixmap->y = y; 158 bgpixmap->y = y;
153 changed++; 159 changed++;
154 } 160 }
155 } 161 }
156 free(str); 162
157 return changed; 163 return changed;
158} 164}
159 165
160void 166void
161rxvt_term::resize_pixmap () 167rxvt_term::resize_pixmap ()
162{ 168{
163 XGCValues gcvalue; 169 XGCValues gcvalue;
164 GC gc; 170 GC gc;
165 unsigned int width = TermWin_TotalWidth(); 171 dDisp;
166 unsigned int height = TermWin_TotalHeight();
167 172
168 if (TermWin.pixmap != None) 173 if (pixmap != None)
169 XFreePixmap(Xdisplay, TermWin.pixmap); 174 XFreePixmap (disp, pixmap);
170 175
171 if (bgPixmap.pixmap == None) 176 if (bgPixmap.pixmap == None)
172 { /* So be it: I'm not using pixmaps */ 177 { /* So be it: I'm not using pixmaps */
173 TermWin.pixmap = None; 178 pixmap = None;
179
174 if (!(Options & Opt_transparent) || am_transparent == 0) 180 if (!OPTION (Opt_transparent) || !am_transparent)
175 XSetWindowBackground(Xdisplay, TermWin.vt, 181 XSetWindowBackground (disp, vt, pix_colors[Color_bg]);
176 PixColors[Color_bg]); 182
177 return; 183 return;
178 } 184 }
179 185
180 gcvalue.foreground = PixColors[Color_bg]; 186 gcvalue.foreground = pix_colors[Color_bg];
181 gc = XCreateGC(Xdisplay, TermWin.vt, GCForeground, &gcvalue); 187 gc = XCreateGC (disp, vt, GCForeground, &gcvalue);
182 188
183 if (bgPixmap.pixmap != None) 189 if (bgPixmap.pixmap != None)
184 { /* we have a specified pixmap */ 190 { /* we have a specified pixmap */
185 unsigned int w = bgPixmap.w, h = bgPixmap.h, 191 unsigned int w = bgPixmap.w, h = bgPixmap.h,
186 x = bgPixmap.x, y = bgPixmap.y; 192 x = bgPixmap.x, y = bgPixmap.y;
187 unsigned int xpmh = xpmAttr.height, 193 unsigned int xpmh = xpmAttr.height,
188 xpmw = xpmAttr.width; 194 xpmw = xpmAttr.width;
189 195
190 /* 196 /*
191 * don't zoom pixmap too much nor expand really small pixmaps 197 * don't zoom pixmap too much nor expand really small pixmaps
192 */ 198 */
193 if (w > 1000 || h > 1000) 199 if (w > 32767 || h > 32767)
194 w = 1; 200 w = 1;
195 else if (width > (10 * xpmw) 201 else if (width > (10 * xpmw)
196 || height > (10 * xpmh)) 202 || height > (10 * xpmh))
197 w = 0; /* tile */ 203 w = 0; /* tile */
198 204
199 if (w == 0) 205 if (!w)
200 { 206 {
201 /* basic X tiling - let the X server do it */ 207 /* basic X tiling - let the X server do it */
202 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, 208 pixmap = XCreatePixmap (disp, vt, xpmw, xpmh, display->depth);
203 xpmw, xpmh, 209
204 (unsigned int)XDEPTH); 210 XCopyArea (disp, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0);
205 XCopyArea(Xdisplay, bgPixmap.pixmap, TermWin.pixmap, gc, 211 XCopyArea (disp, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y);
206 0, 0, xpmw, xpmh, 0, 0); 212 XCopyArea (disp, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0);
213 XCopyArea (disp, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y);
207 } 214 }
208 else 215 else
209 { 216 {
210 float incr, p; 217 float incr, p;
211 Pixmap tmp; 218 Pixmap tmp;
212 219
213 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, 220 pixmap = XCreatePixmap (disp, vt, width, height,
214 width, height,
215 (unsigned int)XDEPTH); 221 (unsigned int)display->depth);
216 /* 222 /*
217 * horizontal scaling 223 * horizontal scaling
218 */ 224 */
219 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); 225 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
220 226
221 tmp = XCreatePixmap(Xdisplay, TermWin.vt, 227 tmp = XCreatePixmap (disp, vt, width, xpmh, (unsigned int)display->depth);
222 width, xpmh, (unsigned int)XDEPTH);
223 XFillRectangle(Xdisplay, tmp, gc, 0, 0, width, 228 XFillRectangle (disp, tmp, gc, 0, 0, width, xpmh);
224 xpmh);
225 229
226 for ( /*nil */ ; x < w; x++, p += incr) 230 for ( /*nil */ ; x < w; x++, p += incr)
227 { 231 {
228 if (p >= xpmw) 232 if (p >= xpmw)
229 p = 0; 233 p = 0;
234
230 /* copy one column from the original pixmap to the tmp pixmap */ 235 /* copy one column from the original pixmap to the tmp pixmap */
231 XCopyArea(Xdisplay, bgPixmap.pixmap, tmp, gc, 236 XCopyArea (disp, bgPixmap.pixmap, tmp, gc,
232 (int)p, 0, 1, xpmh, (int)x, 0); 237 (int)p, 0, 1, xpmh, (int)x, 0);
233 } 238 }
234 239
235 /* 240 /*
236 * vertical scaling 241 * vertical scaling
237 */ 242 */
238 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); 243 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
239 244
240 if (y > 0) 245 if (y > 0)
241 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, 0, width, 246 XFillRectangle (disp, pixmap, gc, 0, 0, width, y);
242 y); 247
243 if (h < height) 248 if (h < height)
244 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, (int)h, 249 XFillRectangle (disp, pixmap, gc, 0, (int)h, width, height - h + 1);
245 width, height - h + 1); 250
246 for ( /*nil */ ; y < h; y++, p += incr) 251 for ( /*nil */ ; y < h; y++, p += incr)
247 { 252 {
248 if (p >= xpmh) 253 if (p >= xpmh)
249 p = 0; 254 p = 0;
255
250 /* copy one row from the tmp pixmap to the main pixmap */ 256 /* copy one row from the tmp pixmap to the main pixmap */
251 XCopyArea(Xdisplay, tmp, TermWin.pixmap, gc, 257 XCopyArea (disp, tmp, pixmap, gc,
252 0, (int)p, width, 1, 0, (int)y); 258 0, (int)p, width, 1, 0, (int)y);
253 } 259 }
260
254 XFreePixmap(Xdisplay, tmp); 261 XFreePixmap (disp, tmp);
255 } 262 }
256 } 263 }
264
257 XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt, TermWin.pixmap); 265 XSetWindowBackgroundPixmap (disp, vt, pixmap);
266
267 if (pixmap != None)
268 {
269 XFreePixmap (disp, pixmap);
270 pixmap = None;
271 }
272
258 XFreeGC(Xdisplay, gc); 273 XFreeGC (disp, gc);
259 am_transparent = 0; 274 am_transparent = 0;
260
261 XClearWindow(Xdisplay, TermWin.vt);
262
263 XSync(Xdisplay, False);
264} 275}
265 276
266/* 277/*
267 * Calculate tiling sizes and increments 278 * Calculate tiling sizes and increments
268 * At start, p == 0, incr == xpmwidthheight 279 * At start, p == 0, incr == xpmwidthheight
269 */ 280 */
270/* INTPROTO */
271static void 281static void
272rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) 282rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
273{ 283{
274 unsigned int cwh, cxy; 284 unsigned int cwh, cxy;
275 float cincr, cp; 285 float cincr, cp;
276 286
277 cp = 0; 287 cp = 0;
341} 351}
342 352
343Pixmap 353Pixmap
344rxvt_term::set_bgPixmap (const char *file) 354rxvt_term::set_bgPixmap (const char *file)
345{ 355{
346 char *f; 356 char *f;
347 357
348 assert(file != NULL); 358 assert (file != NULL);
349 359
350 if (bgPixmap.pixmap != None) 360 if (bgPixmap.pixmap != None)
351 { 361 {
352 XFreePixmap(Xdisplay, bgPixmap.pixmap); 362 XFreePixmap (display->display, bgPixmap.pixmap);
353 bgPixmap.pixmap = None; 363 bgPixmap.pixmap = None;
354 } 364 }
365
355 XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]); 366 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]);
356 367
357 if (*file != '\0') 368 if (*file != '\0')
358 { 369 {
359 /* XWindowAttributes attr; */ 370 /* XWindowAttributes attr; */
360 371
361 /* 372 /*
362 * we already have the required attributes 373 * we already have the required attributes
363 */ 374 */
364 /* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */ 375 /* XGetWindowAttributes (display->display, vt, &attr); */
365 376
366 xpmAttr.closeness = 30000; 377 xpmAttr.closeness = 30000;
367 xpmAttr.colormap = XCMAP; 378 xpmAttr.colormap = display->cmap;
368 xpmAttr.visual = XVISUAL; 379 xpmAttr.visual = display->visual;
369 xpmAttr.depth = XDEPTH; 380 xpmAttr.depth = display->depth;
370 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | 381 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
371 XpmDepth | XpmSize | XpmReturnPixels); 382 XpmDepth | XpmSize | XpmReturnPixels);
372 383
373 /* search environment variables here too */ 384 /* search environment variables here too */
374 f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]); 385 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
375 if (f == NULL 386 if (f == NULL
376 || XpmReadFileToPixmap(Xdisplay, Xroot, f, 387 || XpmReadFileToPixmap (display->display, display->root, f,
377 &bgPixmap.pixmap, NULL, 388 &bgPixmap.pixmap, NULL,
378 &xpmAttr)) 389 &xpmAttr))
379 { 390 {
380 char *p; 391 char *p;
381 392
382 /* semi-colon delimited */ 393 /* semi-colon delimited */
383 if ((p = STRCHR(file, ';')) == NULL) 394 if ((p = strchr (file, ';')) == NULL)
384 p = STRCHR(file, '\0'); 395 p = strchr (file, '\0');
385 396
386 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), 397 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
387 file);
388 } 398 }
399
389 free(f); 400 free (f);
390 } 401 }
402
391 resize_pixmap (); 403 resize_pixmap ();
392 return bgPixmap.pixmap; 404 return bgPixmap.pixmap;
393} 405}
394 406
395#endif /* XPM_BACKGROUND */ 407#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines