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.2 by pcg, Mon Nov 24 17:31:28 2003 UTC vs.
Revision 1.44 by ayin, Sat Jun 30 23:34:57 2007 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*----------------------------------------------------------------------*
2 * File: xpm.c 2 * File: xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: xpm.C,v 1.2 2003/11/24 17:31:28 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>
9 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com>
10 * 10 *
11 * This program is free software; you can redistribute it and/or modify 11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or 13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version. 14 * (at your option) any later version.
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *---------------------------------------------------------------------*/ 24 *---------------------------------------------------------------------*/
25 25
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28#include "xpm.intpro" /* PROTOS for internal routines */
29 28
30#ifdef XPM_BACKGROUND 29#ifdef XPM_BACKGROUND
30
31/*
32 * Calculate tiling sizes and increments
33 * At start, p == 0, incr == xpmwidthheight
34 */
35static void
36rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
37{
38 unsigned int cwh, cxy;
39 float cincr, cp;
40
41 cp = 0;
42 cincr = (float)xpmwidthheight;
43 cxy = *xy;
44 cwh = *wh;
45 if (cwh == 1)
46 { /* display one image, no horizontal/vertical scaling */
47 cincr = (float)widthheight;
48 if (xpmwidthheight <= widthheight)
49 {
50 cwh = xpmwidthheight;
51 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
52 cwh += cxy;
53 }
54 else
55 {
56 cxy = 0;
57 cwh = widthheight;
58 }
59 }
60 else if (cwh < 10)
61 { /* fit WH images across/down screen */
62 cincr *= cwh;
63 cxy = 0;
64 cwh = widthheight;
65 }
66 else
67 {
68 cincr *= 100.0 / cwh;
69 if (cwh < 100)
70 { /* contract */
71 float pos;
72
73 cwh = (cwh * widthheight) / 100;
74 pos = (float)cxy / 100 * widthheight - (cwh / 2);
75
76 cxy = (widthheight - cwh);
77 if (pos <= 0)
78 cxy = 0;
79 else if (pos < cxy)
80 cxy = (int) pos;
81 cwh += cxy;
82 }
83 else
84 { /* expand */
85 if (cxy > 0)
86 { /* position */
87 float pos;
88
89 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2);
90 cp = xpmwidthheight - cincr;
91 if (pos <= 0)
92 cp = 0;
93 else if (pos < cp)
94 cp = pos;
95 }
96 cxy = 0;
97 cwh = widthheight;
98 }
99 }
100 cincr /= widthheight;
101 *wh = cwh;
102 *xy = cxy;
103 *incr = cincr;
104 *p = cp;
105}
31 106
32/* 107/*
33 * These GEOM strings indicate absolute size/position: 108 * These GEOM strings indicate absolute size/position:
34 * @ `WxH+X+Y' 109 * @ `WxH+X+Y'
35 * @ `WxH+X' -> Y = X 110 * @ `WxH+X' -> Y = X
47 * @ `+X' -> Y = X 122 * @ `+X' -> Y = X
48 * 123 *
49 * And this GEOM string is for querying current scale/position: 124 * And this GEOM string is for querying current scale/position:
50 * @ `?' 125 * @ `?'
51 */ 126 */
52/* EXTPROTO */
53int 127int
54rxvt_scale_pixmap(pR_ const char *geom) 128rxvt_term::scale_pixmap (const char *geom)
55{ 129{
56 int flags, changed = 0; 130 int flags, changed = 0;
57 int x = 0, y = 0; 131 int x = 0, y = 0;
58 unsigned int w = 0, h = 0; 132 unsigned int w = 0, h = 0;
59 unsigned int n; 133 unsigned int n;
60 char *p, *str; 134 char *p;
61 bgPixmap_t *bgpixmap = &(R->h->bgPixmap); 135 bgPixmap_t *bgpixmap = &bgPixmap;
62 136
63#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 137#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
64 138
65 if (geom == NULL) 139 if (geom == NULL)
66 return 0; 140 return 0;
67 str = rxvt_malloc(MAXLEN_GEOM + 1); 141
68 if (!STRCMP(geom, "?")) { 142 char str[MAXLEN_GEOM];
143
144 if (!strcmp (geom, "?"))
145 {
69 sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */ 146 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
70 min(bgpixmap->w, 9999), min(bgpixmap->h, 9999), 147 min (bgpixmap->w, 32767), min (bgpixmap->h, 32767),
71 min(bgpixmap->x, 9999), min(bgpixmap->y, 9999)); 148 min (bgpixmap->x, 32767), min (bgpixmap->y, 32767));
72 rxvt_xterm_seq(aR_ XTerm_title, str, CHAR_ST); 149 process_xterm_seq (XTerm_title, str, CHAR_ST);
73 free(str); 150 return 0;
74 return 0;
75 } 151 }
76 152
77 if ((p = STRCHR(geom, ';')) == NULL) 153 if ((p = strchr (geom, ';')) == NULL)
78 p = STRCHR(geom, '\0'); 154 p = strchr (geom, '\0');
155
79 n = (p - geom); 156 n = (p - geom);
80 if (n <= MAXLEN_GEOM) { 157 if (n < MAXLEN_GEOM)
81 STRNCPY(str, geom, n); 158 {
159 strncpy (str, geom, n);
82 str[n] = '\0'; 160 str[n] = '\0';
83 161
162 if (strcmp(str, "auto") == 0)
163 {
164 if (!bgpixmap->auto_resize)
165 changed++;
166 bgpixmap->auto_resize = True ;
167 w = szHint.width ;
168 h = szHint.height ;
169 flags = WidthValue|HeightValue ;
170 }
171 else
172 {
173 bgpixmap->auto_resize = False ;
84 flags = XParseGeometry(str, &x, &y, &w, &h); 174 flags = XParseGeometry (str, &x, &y, &w, &h);
85 if (!flags) { 175 }
176
177 if (!flags)
178 {
86 flags |= WidthValue; 179 flags |= WidthValue;
87 w = 0; 180 w = 0;
88 } /* default is tile */ 181 } /* default is tile */
182
89 if (flags & WidthValue) { 183 if (flags & WidthValue)
184 {
185 if (!(flags & XValue))
186 x = 50;
187
188 if (!(flags & HeightValue))
189 h = w;
190
191 if (w && !h)
192 {
193 w = (bgpixmap->w * w) / 100;
194 h = bgpixmap->h;
195 }
196 else if (h && !w)
197 {
198 w = bgpixmap->w;
199 h = (bgpixmap->h * h) / 100;
200 }
201
202 min_it (w, 32767);
203 min_it (h, 32767);
204
205 if (bgpixmap->w != (short)w)
206 {
207 bgpixmap->w = (short)w;
208 changed++;
209 }
210
211 if (bgpixmap->h != (short)h)
212 {
213 bgpixmap->h = (short)h;
214 changed++;
215 }
216 }
217
90 if (!(flags & XValue)) 218 if (!(flags & YValue))
91 x = 50; 219 {
92 if (!(flags & HeightValue)) 220 if (flags & XNegative)
93 h = w; 221 flags |= YNegative;
94 if (w && !h) { 222
95 w = (bgpixmap->w * w) / 100; 223 y = x;
96 h = bgpixmap->h; 224 }
97 } else if (h && !w) { 225
98 w = bgpixmap->w; 226 if (!(flags & WidthValue) && geom[0] != '=')
99 h = (bgpixmap->h * h) / 100; 227 {
228 x += bgpixmap->x;
229 y += bgpixmap->y;
230 }
231
232 if (xpmAttr.width && xpmAttr.height)
233 {
234 x = MOD(x, xpmAttr.width);
235 y = MOD(y, xpmAttr.height);
236 }
237
238 if (bgpixmap->x != x)
239 {
240 bgpixmap->x = x;
241 changed++;
242 }
243
244 if (bgpixmap->y != y)
245 {
246 bgpixmap->y = y;
247 changed++;
248 }
100 } 249 }
101 if (w > 1000)
102 w = 1000;
103 if (h > 1000)
104 h = 1000;
105 if (bgpixmap->w != (short)w) {
106 bgpixmap->w = (short)w;
107 changed++;
108 }
109 if (bgpixmap->h != (short)h) {
110 bgpixmap->h = (short)h;
111 changed++;
112 }
113 }
114 if (!(flags & YValue)) {
115 if (flags & XNegative)
116 flags |= YNegative;
117 y = x;
118 }
119 250
120 if (!(flags & WidthValue) && geom[0] != '=') {
121 x += bgpixmap->x;
122 y += bgpixmap->y;
123 } else {
124 if (flags & XNegative)
125 x += 100;
126 if (flags & YNegative)
127 y += 100;
128 }
129 MIN_IT(x, 100);
130 MIN_IT(y, 100);
131 MAX_IT(x, 0);
132 MAX_IT(y, 0);
133 if (bgpixmap->x != x) {
134 bgpixmap->x = x;
135 changed++;
136 }
137 if (bgpixmap->y != y) {
138 bgpixmap->y = y;
139 changed++;
140 }
141 }
142 free(str);
143 return changed; 251 return changed;
144} 252}
145 253
146/* EXTPROTO */
147void 254void
148rxvt_resize_pixmap(pR) 255rxvt_term::resize_pixmap ()
149{ 256{
150 XGCValues gcvalue; 257 XGCValues gcvalue;
151 GC gc; 258 GC gc;
152 unsigned int width = TermWin_TotalWidth();
153 unsigned int height = TermWin_TotalHeight();
154 259
155 if (R->TermWin.pixmap != None) 260 if (pixmap != None)
156 XFreePixmap(R->Xdisplay, R->TermWin.pixmap);
157
158 if (R->h->bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */
159 R->TermWin.pixmap = None;
160 if (!(R->Options & Opt_transparent) || R->h->am_transparent == 0)
161 XSetWindowBackground(R->Xdisplay, R->TermWin.vt,
162 R->PixColors[Color_bg]);
163 return;
164 } 261 {
262 XFreePixmap (dpy, pixmap);
263 pixmap = None ;
264 }
165 265
266 if (bgPixmap.pixmap == None)
267 { /* So be it: I'm not using pixmaps */
268 pixmap = None;
269
270#ifdef ENABLE_TRANSPARENCY
271 if (!option (Opt_transparent) || !am_transparent)
272#endif
273 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
274
275 return;
276 }
277
166 gcvalue.foreground = R->PixColors[Color_bg]; 278 gcvalue.foreground = pix_colors[Color_bg];
167 gc = XCreateGC(R->Xdisplay, R->TermWin.vt, GCForeground, &gcvalue); 279 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
168 280
169 if (R->h->bgPixmap.pixmap != None) { /* we have a specified pixmap */ 281 if (bgPixmap.pixmap != None)
282 { /* we have a specified pixmap */
170 unsigned int w = R->h->bgPixmap.w, h = R->h->bgPixmap.h, 283 unsigned int w = bgPixmap.w, h = bgPixmap.h,
171 x = R->h->bgPixmap.x, y = R->h->bgPixmap.y; 284 x = bgPixmap.x, y = bgPixmap.y;
172 unsigned int xpmh = R->h->xpmAttr.height, 285 unsigned int xpmh = xpmAttr.height,
173 xpmw = R->h->xpmAttr.width; 286 xpmw = xpmAttr.width;
174 287
175 /* 288 if (bgPixmap.auto_resize)
289 {
290 w = szHint.width ;
291 h = szHint.height ;
292 }
293 /*
176 * don't zoom pixmap too much nor expand really small pixmaps 294 * don't zoom pixmap too much nor expand really small pixmaps
177 */ 295 */
178 if (w > 1000 || h > 1000) 296 if (w > 32767 || h > 32767)
179 w = 1; 297 w = 1;
180 else if (width > (10 * xpmw) 298 else if (width > (10 * xpmw)
181 || height > (10 * xpmh)) 299 || height > (10 * xpmh))
182 w = 0; /* tile */ 300 w = 0; /* tile */
183 301
184 if (w == 0) { 302 if (!w)
303 {
185 /* basic X tiling - let the X server do it */ 304 /* basic X tiling - let the X server do it */
186 R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 305 pixmap = XCreatePixmap (dpy, vt, xpmw, xpmh, depth);
187 xpmw, xpmh,
188 (unsigned int)XDEPTH);
189 XCopyArea(R->Xdisplay, R->h->bgPixmap.pixmap, R->TermWin.pixmap, gc,
190 0, 0, xpmw, xpmh, 0, 0);
191 } else {
192 float incr, p;
193 Pixmap tmp;
194 306
195 R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 307 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0);
196 width, height, 308 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y);
197 (unsigned int)XDEPTH); 309 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0);
198 /* 310 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y);
311 }
312 else
313#ifdef HAVE_AFTERIMAGE
314#ifdef ENABLE_TRANSPARENCY
315 if (!option(Opt_transparent) || !am_transparent)
316 /* will do that in check_our_parents otherwise */
317#endif
318 {
319 ASImage *scaled_im = scale_asimage( display->asv, original_asim, w, h, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT );
320 if (scaled_im)
321 {
322 pixmap = asimage2pixmap( display->asv, display->root, scaled_im, gc, True );
323 destroy_asimage( &scaled_im );
324 }
325 }
326#else /* HAVE_AFTERIMAGE */
327 {
328 float incr, p;
329 Pixmap tmp;
330
331 pixmap = XCreatePixmap (dpy, vt, width, height, depth);
332 /*
199 * horizontal scaling 333 * horizontal scaling
200 */ 334 */
201 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); 335 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
202 336
203 tmp = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 337 tmp = XCreatePixmap (dpy, vt, width, xpmh, depth);
204 width, xpmh, (unsigned int)XDEPTH);
205 XFillRectangle(R->Xdisplay, tmp, gc, 0, 0, width, 338 XFillRectangle (dpy, tmp, gc, 0, 0, width, xpmh);
206 xpmh);
207 339
208 for ( /*nil */ ; x < w; x++, p += incr) { 340 for ( /*nil */ ; x < w; x++, p += incr)
209 if (p >= xpmw) 341 {
210 p = 0; 342 if (p >= xpmw)
343 p = 0;
344
211 /* copy one column from the original pixmap to the tmp pixmap */ 345 /* copy one column from the original pixmap to the tmp pixmap */
212 XCopyArea(R->Xdisplay, R->h->bgPixmap.pixmap, tmp, gc, 346 XCopyArea (dpy, bgPixmap.pixmap, tmp, gc, (int)p, 0, 1, xpmh, (int)x, 0);
213 (int)p, 0, 1, xpmh, (int)x, 0); 347 }
214 }
215 348
216 /* 349 /*
217 * vertical scaling 350 * vertical scaling
218 */ 351 */
219 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); 352 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
220 353
221 if (y > 0) 354 if (y > 0)
222 XFillRectangle(R->Xdisplay, R->TermWin.pixmap, gc, 0, 0, width, 355 XFillRectangle (dpy, pixmap, gc, 0, 0, width, y);
223 y); 356
224 if (h < height) 357 if (h < height)
225 XFillRectangle(R->Xdisplay, R->TermWin.pixmap, gc, 0, (int)h, 358 XFillRectangle (dpy, pixmap, gc, 0, (int)h, width, height - h + 1);
226 width, height - h + 1); 359
227 for ( /*nil */ ; y < h; y++, p += incr) { 360 for ( /*nil */ ; y < h; y++, p += incr)
228 if (p >= xpmh) 361 {
229 p = 0; 362 if (p >= xpmh)
363 p = 0;
364
230 /* copy one row from the tmp pixmap to the main pixmap */ 365 /* copy one row from the tmp pixmap to the main pixmap */
231 XCopyArea(R->Xdisplay, tmp, R->TermWin.pixmap, gc, 366 XCopyArea (dpy, tmp, pixmap, gc, 0, (int)p, width, 1, 0, (int)y);
232 0, (int)p, width, 1, 0, (int)y); 367 }
368
369 XFreePixmap (dpy, tmp);
370 }
371#endif /* HAVE_AFTERIMAGE */
233 } 372 }
234 XFreePixmap(R->Xdisplay, tmp); 373
235 } 374 XSetWindowBackgroundPixmap (dpy, vt, pixmap);
236 } 375
237 XSetWindowBackgroundPixmap(R->Xdisplay, R->TermWin.vt, R->TermWin.pixmap);
238 XFreeGC(R->Xdisplay, gc); 376 XFreeGC (dpy, gc);
377#ifdef ENABLE_TRANSPARENCY
239 R->h->am_transparent = 0; 378 am_transparent = 0;
240 379#endif
241 XClearWindow(R->Xdisplay, R->TermWin.vt);
242
243 XSync(R->Xdisplay, False);
244} 380}
245 381
382Pixmap
383rxvt_term::set_bgPixmap (const char *file)
384{
385 char *f;
386
387 assert (file != NULL);
388
389 if (bgPixmap.pixmap != None)
390 {
391 XFreePixmap (dpy, bgPixmap.pixmap);
392 bgPixmap.pixmap = None;
393 }
394
395 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
396
397 if (*file != '\0')
398 {
399 /* XWindowAttributes attr; */
400
401 /*
402 * we already have the required attributes
403 */
404 /* XGetWindowAttributes (dpy, vt, &attr); */
405
406#ifdef HAVE_AFTERIMAGE
407 if (asimman == NULL)
408 asimman = create_generic_imageman(rs[Rs_path]);
409 if ((f = strchr (file, ';')) == NULL)
410 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
411 else
412 {
413 size_t len = f - file;
414 f = (char *)malloc (len + 1);
415 strncpy (f, file, len);
416 f[len] = '\0';
417 original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
418 free( f );
419 }
420 if (original_asim)
421 {
422 bgPixmap.pixmap = asimage2pixmap( display->asv, display->root, original_asim, NULL, True );
423 xpmAttr.width = original_asim->width ;
424 xpmAttr.height = original_asim->height ;
425 }
426#else /* HAVE_AFTERIMAGE */
427 xpmAttr.closeness = 30000;
428 xpmAttr.colormap = cmap;
429 xpmAttr.visual = visual;
430 xpmAttr.depth = depth;
431 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual
432 | XpmDepth | XpmSize | XpmReturnPixels);
433
434 /* search environment variables here too */
435 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
436 if (f == NULL
437 || XpmReadFileToPixmap (dpy, display->root, f,
438 &bgPixmap.pixmap, NULL,
439 &xpmAttr))
440 {
441 char *p;
442
443 /* semi-colon delimited */
444 if ((p = strchr (file, ';')) == NULL)
445 p = strchr (file, '\0');
446
447 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
448 }
449 free (f);
450#endif /* HAVE_AFTERIMAGE */
451 }
452
453 resize_pixmap ();
454 return bgPixmap.pixmap;
455}
456
457#endif /* XPM_BACKGROUND */
458
459#ifdef ENABLE_TRANSPARENCY
460#if TINTING && !defined(HAVE_AFTERIMAGE)
461/* taken from aterm-0.4.2 */
462
463typedef uint32_t RUINT32T;
464
465static void
466ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm)
467{
468 int sh_r, sh_g, sh_b;
469 RUINT32T mask_r, mask_g, mask_b;
470 RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b;
471 unsigned int lower_lim_r, lower_lim_g, lower_lim_b;
472 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
473 int i;
474
475 Visual *visual = term->visual;
476
477 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ;
478
479 /* for convenience */
480 mask_r = visual->red_mask;
481 mask_g = visual->green_mask;
482 mask_b = visual->blue_mask;
483
484 /* boring lookup table pre-initialization */
485 switch (srcImage->bits_per_pixel) {
486 case 15:
487 if ((mask_r != 0x7c00) ||
488 (mask_g != 0x03e0) ||
489 (mask_b != 0x001f))
490 return;
491 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32));
492 lookup_r = lookup;
493 lookup_g = lookup+32;
494 lookup_b = lookup+32+32;
495 sh_r = 10;
496 sh_g = 5;
497 sh_b = 0;
498 break;
499 case 16:
500 if ((mask_r != 0xf800) ||
501 (mask_g != 0x07e0) ||
502 (mask_b != 0x001f))
503 return;
504 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32));
505 lookup_r = lookup;
506 lookup_g = lookup+32;
507 lookup_b = lookup+32+64;
508 sh_r = 11;
509 sh_g = 5;
510 sh_b = 0;
511 break;
512 case 24:
513 if ((mask_r != 0xff0000) ||
514 (mask_g != 0x00ff00) ||
515 (mask_b != 0x0000ff))
516 return;
517 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
518 lookup_r = lookup;
519 lookup_g = lookup+256;
520 lookup_b = lookup+256+256;
521 sh_r = 16;
522 sh_g = 8;
523 sh_b = 0;
524 break;
525 case 32:
526 if ((mask_r != 0xff0000) ||
527 (mask_g != 0x00ff00) ||
528 (mask_b != 0x0000ff))
529 return;
530 lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256));
531 lookup_r = lookup;
532 lookup_g = lookup+256;
533 lookup_b = lookup+256+256;
534 sh_r = 16;
535 sh_g = 8;
536 sh_b = 0;
537 break;
538 default:
539 return; /* we do not support this color depth */
540 }
541
542 /* prepare limits for color transformation (each channel is handled separately) */
543 if (shade < 0) {
544 shade = -shade;
545 if (shade < 0) shade = 0;
546 if (shade > 100) shade = 100;
547
548 lower_lim_r = 65535-rm;
549 lower_lim_g = 65535-gm;
550 lower_lim_b = 65535-bm;
551
552 lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100);
553 lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100);
554 lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100);
555
556 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
557 } else {
558 if (shade < 0) shade = 0;
559 if (shade > 100) shade = 100;
560
561 lower_lim_r = lower_lim_g = lower_lim_b = 0;
562
563 upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100);
564 upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100);
565 upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100);
566 }
567
568 /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */
569 if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 ))
570 {
571 unsigned int tmp;
572
573 tmp = lower_lim_r;
574 lower_lim_r = lower_lim_b;
575 lower_lim_b = tmp;
576
577 tmp = upper_lim_r;
578 upper_lim_r = upper_lim_b;
579 upper_lim_b = tmp;
580 }
581
582 /* fill our lookup tables */
583 for (i = 0; i <= mask_r>>sh_r; i++)
584 {
585 RUINT32T tmp;
586 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r));
587 tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r);
588 lookup_r[i] = (tmp/65535)<<sh_r;
589 }
590 for (i = 0; i <= mask_g>>sh_g; i++)
591 {
592 RUINT32T tmp;
593 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g));
594 tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g);
595 lookup_g[i] = (tmp/65535)<<sh_g;
596 }
597 for (i = 0; i <= mask_b>>sh_b; i++)
598 {
599 RUINT32T tmp;
600 tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b));
601 tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b);
602 lookup_b[i] = (tmp/65535)<<sh_b;
603 }
604
605 /* apply table to input image (replacing colors by newly calculated ones) */
606 switch (srcImage->bits_per_pixel)
607 {
608 case 15:
609 {
610 unsigned short *p1, *pf, *p, *pl;
611 p1 = (unsigned short *) srcImage->data;
612 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
613 while (p1 < pf)
614 {
615 p = p1;
616 pl = p1 + srcImage->width;
617 for (; p < pl; p++)
618 {
619 *p = lookup_r[(*p & 0x7c00)>>10] |
620 lookup_g[(*p & 0x03e0)>> 5] |
621 lookup_b[(*p & 0x001f)];
622 }
623 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
624 }
625 break;
626 }
627 case 16:
628 {
629 unsigned short *p1, *pf, *p, *pl;
630 p1 = (unsigned short *) srcImage->data;
631 pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
632 while (p1 < pf)
633 {
634 p = p1;
635 pl = p1 + srcImage->width;
636 for (; p < pl; p++)
637 {
638 *p = lookup_r[(*p & 0xf800)>>11] |
639 lookup_g[(*p & 0x07e0)>> 5] |
640 lookup_b[(*p & 0x001f)];
641 }
642 p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line);
643 }
644 break;
645 }
646 case 24:
647 {
648 unsigned char *p1, *pf, *p, *pl;
649 p1 = (unsigned char *) srcImage->data;
650 pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
651 while (p1 < pf)
652 {
653 p = p1;
654 pl = p1 + srcImage->width * 3;
655 for (; p < pl; p += 3)
656 {
657 p[0] = lookup_r[(p[0] & 0xff0000)>>16];
658 p[1] = lookup_r[(p[1] & 0x00ff00)>> 8];
659 p[2] = lookup_r[(p[2] & 0x0000ff)];
660 }
661 p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line);
662 }
663 break;
664 }
665 case 32:
666 {
667 RUINT32T *p1, *pf, *p, *pl;
668 p1 = (RUINT32T *) srcImage->data;
669 pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line);
670
671 while (p1 < pf)
672 {
673 p = p1;
674 pl = p1 + srcImage->width;
675 for (; p < pl; p++)
676 {
677 *p = lookup_r[(*p & 0xff0000)>>16] |
678 lookup_g[(*p & 0x00ff00)>> 8] |
679 lookup_b[(*p & 0x0000ff)] |
680 (*p & ~0xffffff);
681 }
682 p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line);
683 }
684 break;
685 }
686 }
687
688 free (lookup);
689}
690#endif
691
246/* 692/*
247 * Calculate tiling sizes and increments 693 * Check our parents are still who we think they are.
248 * At start, p == 0, incr == xpmwidthheight 694 * Do transparency updates if required
249 */ 695 */
250/* INTPROTO */ 696int
697rxvt_term::check_our_parents ()
698{
699 check_our_parents_ev.stop ();
700 check_our_parents_ev.start (NOW + .1);
701 return 0;
702}
703
251void 704void
252rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) 705rxvt_term::check_our_parents_cb (time_watcher &w)
253{ 706{
254 unsigned int cwh, cxy; 707 int i, pchanged, aformat, have_pixmap, rootdepth;
255 float cincr, cp; 708 unsigned long nitems, bytes_after;
709 Atom atype;
710 unsigned char *prop = NULL;
711 Window root, oldp, *list;
712 Pixmap rootpixmap = None;
713 XWindowAttributes wattr, wrootattr;
714 int sx, sy;
715 Window cr;
256 716
257 cp = 0; 717 pchanged = 0;
258 cincr = (float)xpmwidthheight;
259 cxy = *xy;
260 cwh = *wh;
261 if (cwh == 1) { /* display one image, no horizontal/vertical scaling */
262 cincr = (float)widthheight;
263 if (xpmwidthheight <= widthheight) {
264 cwh = xpmwidthheight;
265 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
266 cwh += cxy;
267 } else {
268 cxy = 0;
269 cwh = widthheight;
270 }
271 } else if (cwh < 10) { /* fit WH images across/down screen */
272 cincr *= cwh;
273 cxy = 0;
274 cwh = widthheight;
275 } else {
276 cincr *= 100.0 / cwh;
277 if (cwh < 100) { /* contract */
278 float pos;
279 718
280 cwh = (cwh * widthheight) / 100; 719 if (!option (Opt_transparent))
281 pos = (float)cxy / 100 * widthheight - (cwh / 2); 720 return /*pchanged*/; /* Don't try any more */
282 721
283 cxy = (widthheight - cwh); 722 XGetWindowAttributes (dpy, display->root, &wrootattr);
284 if (pos <= 0) 723 rootdepth = wrootattr.depth;
285 cxy = 0;
286 else if (pos < cxy)
287 cxy = pos;
288 cwh += cxy;
289 } else { /* expand */
290 if (cxy > 0) { /* position */
291 float pos;
292 724
293 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2); 725 XGetWindowAttributes (dpy, parent[0], &wattr);
294 cp = xpmwidthheight - cincr; 726
295 if (pos <= 0) 727 if (rootdepth != wattr.depth)
296 cp = 0; 728 {
297 else if (pos < cp) 729 if (am_transparent)
298 cp = pos; 730 {
731 pchanged = 1;
732 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
733 am_transparent = am_pixmap_trans = 0;
734 }
735
736 return /*pchanged*/; /* Don't try any more */
299 } 737 }
300 cxy = 0; 738
301 cwh = widthheight; 739 /* Get all X ops out of the queue so that our information is up-to-date. */
302 } 740 XSync (dpy, False);
741
742 XTranslateCoordinates (dpy, parent[0], display->root,
743 0, 0, &sx, &sy, &cr);
744
745 /* check if we are outside of the visible part of the virtual screen : */
746 if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0
747 || sx >= wrootattr.width || sy >= wrootattr.height )
748 return /* 0 */ ;
749 /*
750 * Make the frame window set by the window manager have
751 * the root background. Some window managers put multiple nested frame
752 * windows for each client, so we have to take care about that.
753 */
754 i = (xa[XA_XROOTPMAP_ID]
755 && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID],
756 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
757 &nitems, &bytes_after, &prop) == Success);
758
759 if (!i || prop == NULL)
760 i = (xa[XA_ESETROOT_PMAP_ID]
761 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
762 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
763 &nitems, &bytes_after, &prop) == Success);
764
765 if (!i || prop == NULL
766#if TINTING
767 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL
768#ifdef HAVE_AFTERIMAGE
769 && original_asim == NULL && rs[Rs_blurradius] == NULL
770#endif
771 )
772#endif
773 )
774 have_pixmap = 0;
775 else
776 {
777 have_pixmap = 1;
778 rootpixmap = *(Pixmap *)prop;
779 XFree (prop);
780 }
781
782 if (have_pixmap)
783 {
784 Bool success = False ;
785 GC gc = NULL;
786 XGCValues gcvalue;
787#ifdef HAVE_AFTERIMAGE
788 {
789 Pixmap tmp_pmap = None ;
790 ShadingInfo shade;
791 ARGB32 tint ;
792 unsigned int pmap_w = 0, pmap_h = 0;
793
794 if (get_drawable_size( rootpixmap, &pmap_w, &pmap_h ))
795 {
796 int root_x = 0, root_y = 0;
797
798 shade.shading = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
799 if (ISSET_PIXCOLOR (Color_tint))
800 {
801 rgba c;
802 pix_colors_focused [Color_tint].get (c);
803 shade.tintColor.red = c.r;
804 shade.tintColor.green = c.g;
805 shade.tintColor.blue = c.b;
806 }
807 else
808 shade.tintColor.red = shade.tintColor.green = shade.tintColor.blue = 0xFFFF;
809 tint = shading2tint32( &shade );
810 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
811 if (GetWinPosition (parent[0], &root_x, &root_y) )
812 {
813 ASImageLayer *layers = create_image_layers( 2 );
814 ASImage *merged_im = NULL;
815 int back_x, back_y, back_w, back_h;
816 /* merge_layers does good job at tiling background appropriately,
817 so all we need is to cut out smallest possible piece : */
818#define MAKE_ROOTPMAP_GEOM(xy,wh,widthheight) \
819 do{ while( root_##xy < 0 ) root_##xy += (int)wrootattr.widthheight; \
820 back_##xy = root_##xy % pmap_##wh; /* that gives us left side of the closest tile : */ \
821 if( pmap_##wh >= back_##xy + szHint.widthheight ) \
822 back_##wh = szHint.widthheight;/* background is large - limit it by our size */ \
823 else \
824 { /* small background - need the whole of it for successfull tiling :*/ \
825 back_##xy = 0; \
826 back_##wh = pmap_##wh; \
827 }}while(0)
303 } 828
304 cincr /= widthheight; 829 MAKE_ROOTPMAP_GEOM(x,w,width);
305 *wh = cwh; 830 MAKE_ROOTPMAP_GEOM(y,h,height);
306 *xy = cxy; 831
307 *incr = cincr; 832 layers[0].im = pixmap2asimage (display->asv, rootpixmap, back_x, back_y, back_w, back_h, AllPlanes, ASA_ASImage, 100);
308 *p = cp; 833 layers[0].clip_x = (back_w == pmap_w)?root_x:0;
834 layers[0].clip_y = (back_h == pmap_h)?root_y:0;
835 layers[0].clip_width = szHint.width;
836 layers[0].clip_height = szHint.height;
837 layers[0].tint = tint;
838 if (rs[Rs_blurradius] && layers[0].im)
839 {
840 double r = atof(rs[Rs_blurradius]);
841 ASImage* tmp = blur_asimage_gauss(display->asv, layers[0].im, r, r, 0xFFFFFFFF, ASA_ASImage, 100, ASIMAGE_QUALITY_DEFAULT );
842 if( tmp )
843 {
844 destroy_asimage( &layers[0].im );
845 layers[0].im = tmp;
846 }
847 }
848 if (original_asim != NULL)
849 {
850 int fore_w, fore_h;
851 layers[1].im = original_asim;
852 if( bgPixmap.auto_resize )
853 {
854 fore_w = szHint.width;
855 fore_h = szHint.height;
856 }
857 else
858 {
859 fore_w = bgPixmap.w;
860 fore_h = bgPixmap.h;
861 }
862 if (fore_w != original_asim->width
863 || fore_h != original_asim->height)
864 {
865 layers[1].im = scale_asimage( display->asv,
866 original_asim,
867 fore_w, fore_h,
868 ASA_ASImage, 100,
869 ASIMAGE_QUALITY_DEFAULT );
870 }
871
872 layers[1].clip_width = szHint.width;
873 layers[1].clip_height = szHint.height;
874
875 if (rs[Rs_blendtype])
876 {
877 layers[1].merge_scanlines = blend_scanlines_name2func(rs[Rs_blendtype]);
878 if( layers[1].merge_scanlines == NULL )
879 layers[1].merge_scanlines = alphablend_scanlines;
880 }
881 }
882 merged_im = merge_layers( display->asv, layers, layers[1].im?2:1,
883 szHint.width, szHint.height,
884 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT );
885 if (layers[1].im != original_asim)
886 destroy_asimage( &(layers[1].im) );
887 destroy_asimage( &(layers[0].im) );
888 if (merged_im != NULL)
889 {
890 tmp_pmap = asimage2pixmap( display->asv, DefaultRootWindow(dpy), merged_im, gc, True );
891 destroy_asimage( &merged_im );
892 }
893 free( layers );
894 }
895 }
896 if (tmp_pmap != None)
897 {
898 success = True;
899 if (pixmap != None)
900 XFreePixmap (dpy, pixmap);
901 pixmap = tmp_pmap;
902 }
903 }
904#else /* HAVE_AFTERIMAGE */
905 {
906 /*
907 * Copy display->root pixmap transparency
908 */
909 int nx, ny;
910 unsigned int nw, nh;
911 XImage *image;
912
913 nw = (unsigned int)szHint.width;
914 nh = (unsigned int)szHint.height;
915 nx = ny = 0;
916
917 if (sx < 0)
918 {
919 nw += sx;
920 nx = -sx;
921 sx = 0;
922 }
923
924 if (sy < 0)
925 {
926 nh += sy;
927 ny = -sy;
928 sy = 0;
929 }
930
931 min_it (nw, (unsigned int) (wrootattr.width - sx));
932 min_it (nh, (unsigned int) (wrootattr.height - sy));
933
934 XSync (dpy, False);
935 allowedxerror = -1;
936 image = XGetImage (dpy, rootpixmap, sx, sy, nw, nh, AllPlanes, ZPixmap);
937
938 /* XXX: handle BadMatch - usually because we're outside the pixmap */
939 /* XXX: may need a delay here? */
940 allowedxerror = 0;
941 if (image != NULL)
942 {
943 if (pixmap != None)
944 XFreePixmap (dpy, pixmap);
945
946#if TINTING
947 if (ISSET_PIXCOLOR (Color_tint))
948 {
949 int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
950
951 rgba c;
952 pix_colors_focused [Color_tint].get (c);
953 ShadeXImage (this, image, shade, c.r, c.g, c.b);
954 }
955#endif
956
957 pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, image->depth);
958 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
959 XPutImage (dpy, pixmap, gc, image, 0, 0,
960 nx, ny, image->width, image->height);
961 XDestroyImage (image);
962 success = True ;
963 }
964 }
965#endif /* HAVE_AFTERIMAGE */
966 if (gc != NULL)
967 XFreeGC (dpy, gc);
968
969 if (!success)
970 {
971 if (am_transparent && am_pixmap_trans)
972 {
973 pchanged = 1;
974 if (pixmap != None)
975 {
976 XFreePixmap (dpy, pixmap);
977 pixmap = None;
978 }
979 }
980
981 am_pixmap_trans = 0;
982 }
983 else
984 {
985 XSetWindowBackgroundPixmap (dpy, parent[0], pixmap);
986 XClearWindow (dpy, parent[0]);
987
988 if (!am_transparent || !am_pixmap_trans)
989 pchanged = 1;
990
991 am_transparent = am_pixmap_trans = 1;
992 }
993 }
994
995 if (am_pixmap_trans)
996 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
997 else
998 {
999 unsigned int n;
1000 /*
1001 * InheritPixmap transparency
1002 */
1003 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1004 {
1005 oldp = parent[i];
1006 XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n);
1007 XFree (list);
1008
1009 if (parent[i] == display->root)
1010 {
1011 if (oldp != None)
1012 pchanged = 1;
1013
1014 break;
1015 }
1016
1017 if (oldp != parent[i])
1018 pchanged = 1;
1019 }
1020
1021 n = 0;
1022
1023 if (pchanged)
1024 for (; n < (unsigned int)i; n++)
1025 {
1026 XGetWindowAttributes (dpy, parent[n], &wattr);
1027
1028 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
1029 {
1030 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
1031 break;
1032 }
1033 }
1034
1035 if (n > (sizeof (parent) / sizeof (parent[0])))
1036 {
1037 XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]);
1038 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
1039 am_transparent = 0;
1040 /* XXX: also turn off Opt_transparent? */
1041 }
1042 else
1043 {
1044 for (n = 0; n < (unsigned int)i; n++)
1045 {
1046 XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative);
1047 XClearWindow (dpy, parent[n]);
1048 }
1049
1050 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
1051 am_transparent = 1;
1052 }
1053
1054 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1055 parent[i] = None;
1056 }
1057
1058 if (scrollBar.win)
1059 {
1060 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
1061 scrollBar.setIdle ();
1062 scrollbar_show (0);
1063 }
1064
1065 if (am_transparent)
1066 {
1067 want_refresh = want_full_refresh = 1;
1068 if (am_pixmap_trans)
1069 flush ();
1070 }
1071
1072// return pchanged;
309} 1073}
310 1074#endif
311/* EXTPROTO */
312Pixmap
313rxvt_set_bgPixmap(pR_ const char *file)
314{
315 char *f;
316
317 assert(file != NULL);
318
319 if (R->h->bgPixmap.pixmap != None) {
320 XFreePixmap(R->Xdisplay, R->h->bgPixmap.pixmap);
321 R->h->bgPixmap.pixmap = None;
322 }
323 XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]);
324
325 if (*file != '\0') {
326/* XWindowAttributes attr; */
327
328 /*
329 * we already have the required attributes
330 */
331/* XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &attr); */
332
333 R->h->xpmAttr.closeness = 30000;
334 R->h->xpmAttr.colormap = XCMAP;
335 R->h->xpmAttr.visual = XVISUAL;
336 R->h->xpmAttr.depth = XDEPTH;
337 R->h->xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
338 XpmDepth | XpmSize | XpmReturnPixels);
339
340 /* search environment variables here too */
341 f = (char *)rxvt_File_find(file, ".xpm", R->h->rs[Rs_path]);
342 if (f == NULL
343 || XpmReadFileToPixmap(R->Xdisplay, Xroot, f,
344 &R->h->bgPixmap.pixmap, NULL,
345 &R->h->xpmAttr)) {
346 char *p;
347
348 /* semi-colon delimited */
349 if ((p = STRCHR(file, ';')) == NULL)
350 p = STRCHR(file, '\0');
351
352 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file),
353 file);
354 }
355 free(f);
356 }
357 rxvt_resize_pixmap(aR);
358 return R->h->bgPixmap.pixmap;
359}
360
361#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines