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.61 by ayin, Tue Aug 7 15:23:11 2007 UTC vs.
Revision 1.67 by sasha, Tue Aug 14 14:06:51 2007 UTC

72 72
73#ifdef HAVE_BG_PIXMAP 73#ifdef HAVE_BG_PIXMAP
74bool 74bool
75bgPixmap_t::window_size_sensitive () 75bgPixmap_t::window_size_sensitive ()
76{ 76{
77#ifdef XPM_BACKGROUND 77# ifdef XPM_BACKGROUND
78#ifdef HAVE_AFTERIMAGE 78# ifdef HAVE_AFTERIMAGE
79 if (original_asim != NULL) 79 if (original_asim != NULL)
80#endif 80# endif
81 { 81 {
82 if (h_scale != 0 || v_scale != 0) 82 if (h_scale != 0 || v_scale != 0)
83 return true; 83 return true;
84 } 84 }
85#endif 85# endif
86#ifdef ENABLE_TRANSPARENCY 86# ifdef ENABLE_TRANSPARENCY
87 if (flags & bgPmap_Transparent) 87 if (flags & isTransparent)
88 return true; 88 return true;
89#endif 89# endif
90 return false; 90 return false;
91} 91}
92 92
93#ifdef XPM_BACKGROUND 93# ifdef XPM_BACKGROUND
94static inline bool 94static inline bool
95check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) 95check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
96{ 96{
97 if (geom_flags & flag) 97 if (geom_flags & flag)
98 { 98 {
132 int smaller = MIN (image_size,window_size); 132 int smaller = MIN (image_size,window_size);
133 133
134 if (align >= 0 && align <= 50) 134 if (align >= 0 && align <= 50)
135 return diff * align / 100; 135 return diff * align / 100;
136 else if (align > 50 && align <= 100) 136 else if (align > 50 && align <= 100)
137 return window_size - image_size + diff * align / 100; 137 return window_size - image_size - diff * (100 - align) / 100;
138 else if (align > 100 && align <= 200 ) 138 else if (align > 100 && align <= 200 )
139 return ((align - 100) * smaller / 100) + window_size - smaller; 139 return ((align - 100) * smaller / 100) + window_size - smaller;
140 else if (align > -100 && align < 0) 140 else if (align > -100 && align < 0)
141 return ((align + 100) * smaller / 100) - image_size; 141 return ((align + 100) * smaller / 100) - image_size;
142 return 0; 142 return 0;
143} 143}
144 144
145static inline void 145static inline int
146make_clip_rectangle (int pos, int size, int target_size, int &clip_pos, int &clip_size) 146make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
147{ 147{
148 if (size <= 0) 148 int src_pos = 0;
149 { /* special case - tiling */ 149 dst_pos = 0;
150 dst_size = size;
151 if (pos < 0 && size > target_size)
152 {
150 clip_pos = pos; 153 src_pos = -pos;
151 clip_size = target_size; 154 dst_size += pos;
152 } 155 }
153 else if (pos < 0) 156 else if (pos > 0)
154 {
155 clip_pos = 0;
156 clip_size = MIN (target_size, size + pos);
157 }
158 else
159 {
160 clip_pos = pos; 157 dst_pos = pos;
161 clip_size = size; 158
162 if (pos < target_size && (int)clip_size > target_size - pos) 159 if (dst_pos + dst_size > target_size)
163 clip_pos = target_size - pos; 160 dst_size = target_size - dst_pos;
164 } 161 return src_pos;
165} 162}
166 163
167bool 164bool
168bgPixmap_t::handle_geometry (const char *geom) 165bgPixmap_t::set_geometry (const char *geom)
169{ 166{
170 int geom_flags = 0, changed = 0; 167 int geom_flags = 0, changed = 0;
171 int x = 0, y = 0; 168 int x = 0, y = 0;
172 unsigned int w = 0, h = 0; 169 unsigned int w = 0, h = 0;
173 unsigned int n; 170 unsigned int n;
174 unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); 171 unsigned long new_flags = (flags & (~geometryFlags));
175 char *p; 172 char *p;
176#define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 173# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */
177 174
178 if (geom == NULL) 175 if (geom == NULL)
179 return false; 176 return false;
180 177
181 char str[MAXLEN_GEOM]; 178 char str[MAXLEN_GEOM];
182 179
183 if (!strcmp (geom, "?"))
184 {
185#if 0 /* TODO: */
186 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
187 min (h_scale, 32767), min (v_scale, 32767),
188 min (h_align, 32767), min (v_align, 32767));
189 process_xterm_seq (XTerm_title, str, CHAR_ST);
190#endif
191 return false;
192 }
193 while (isspace(*geom)) ++geom; 180 while (isspace(*geom)) ++geom;
194 if ((p = strchr (geom, ';')) == NULL) 181 if ((p = strchr (geom, ';')) == NULL)
195 p = strchr (geom, '\0'); 182 p = strchr (geom, '\0');
196 183
197 n = (p - geom); 184 n = (p - geom);
198 if (n < MAXLEN_GEOM) 185 if (n < MAXLEN_GEOM)
199 { 186 {
200 char *ops; 187 char *ops;
201 new_flags |= bgPmap_geometrySet; 188 new_flags |= geometrySet;
202 189
203 strncpy (str, geom, n); 190 strncpy (str, geom, n);
204 str[n] = '\0'; 191 str[n] = '\0';
205 if (str[0] == ':') 192 if (str[0] == ':')
206 ops = &str[0]; 193 ops = &str[0];
227 { 214 {
228 y = x; 215 y = x;
229 geom_flags |= YValue; 216 geom_flags |= YValue;
230 } 217 }
231 218
232 if (flags & bgPmap_geometrySet) 219 if (flags & geometrySet)
233 {/* new geometry is an adjustment to the old one ! */ 220 {/* new geometry is an adjustment to the old one ! */
234 if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) 221 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
235 { 222 {
236 if (w == 0 && h != 0) 223 if (w == 0 && h != 0)
237 { 224 {
255 } 242 }
256 else /* setting up geometry from scratch */ 243 else /* setting up geometry from scratch */
257 { 244 {
258 if (!(geom_flags & XValue)) 245 if (!(geom_flags & XValue))
259 {/* use default geometry - centered */ 246 {/* use default geometry - centered */
260 x = y = bgPmap_defaultAlign; 247 x = y = defaultAlign;
261 } 248 }
262 else if (!(geom_flags & YValue)) 249 else if (!(geom_flags & YValue))
263 y = x; 250 y = x;
264 251
265 if ((geom_flags & (WidthValue|HeightValue)) == 0) 252 if ((geom_flags & (WidthValue|HeightValue)) == 0)
266 {/* use default geometry - scaled */ 253 {/* use default geometry - scaled */
267 w = h = bgPmap_defaultScale; 254 w = h = defaultScale;
268 } 255 }
269 else if (geom_flags & WidthValue) 256 else if (geom_flags & WidthValue)
270 { 257 {
271 if (!(geom_flags & HeightValue)) 258 if (!(geom_flags & HeightValue))
272 h = w; 259 h = w;
273 } 260 }
274 else 261 else
275 w = h; 262 w = h;
276 } 263 }
277 } /* done parsing geometry string */ 264 } /* done parsing geometry string */
278 else if (!(flags & bgPmap_geometrySet)) 265 else if (!(flags & geometrySet))
279 { /* default geometry - scaled and centered */ 266 { /* default geometry - scaled and centered */
280 x = y = bgPmap_defaultAlign; 267 x = y = defaultAlign;
281 w = h = bgPmap_defaultScale; 268 w = h = defaultScale;
282 } 269 }
283 270
284 if (!(flags & bgPmap_geometrySet)) 271 if (!(flags & geometrySet))
285 geom_flags |= WidthValue|HeightValue|XValue|YValue; 272 geom_flags |= WidthValue|HeightValue|XValue|YValue;
286 273
287 if (ops) 274 if (ops)
288 { 275 {
289 while (*ops) 276 while (*ops)
290 { 277 {
291 while (*ops == ':' || isspace(*ops)) ++ops; 278 while (*ops == ':' || isspace(*ops)) ++ops;
292#define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 279# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
293 if (CHECK_GEOM_OPS("tile")) 280 if (CHECK_GEOM_OPS("tile"))
294 { 281 {
295 w = h = 0; 282 w = h = 0;
296 geom_flags |= WidthValue|HeightValue; 283 geom_flags |= WidthValue|HeightValue;
297 } 284 }
300 if (w == 0 && h == 0) 287 if (w == 0 && h == 0)
301 { 288 {
302 w = 100; 289 w = 100;
303 geom_flags |= WidthValue; 290 geom_flags |= WidthValue;
304 } 291 }
305 new_flags |= bgPmap_propScale; 292 new_flags |= propScale;
306 } 293 }
307 else if (CHECK_GEOM_OPS("hscale")) 294 else if (CHECK_GEOM_OPS("hscale"))
308 { 295 {
309 if (w == 0) 296 if (w == 0)
310 w = 100; 297 w = 100;
330 { 317 {
331 w = h = 100; 318 w = h = 100;
332 x = y = 50; 319 x = y = 50;
333 geom_flags |= WidthValue|HeightValue|XValue|YValue; 320 geom_flags |= WidthValue|HeightValue|XValue|YValue;
334 } 321 }
335#undef CHECK_GEOM_OPS 322# undef CHECK_GEOM_OPS
336 while (*ops != ':' && *ops != '\0') ++ops; 323 while (*ops != ':' && *ops != '\0') ++ops;
337 } /* done parsing ops */ 324 } /* done parsing ops */
338 } 325 }
339 326
340 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 327 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w))
355//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 342//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
356// flags, h_scale, v_scale, h_align, v_align); 343// flags, h_scale, v_scale, h_align, v_align);
357 return (changed > 0); 344 return (changed > 0);
358} 345}
359 346
360#ifdef HAVE_AFTERIMAGE 347# ifdef HAVE_AFTERIMAGE
361bool 348bool
362bgPixmap_t::render_asim (rxvt_term *target, ASImage *background, ARGB32 background_tint) 349bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint)
363{ 350{
364 if (target == NULL) 351 if (target == NULL)
365 return false; 352 return false;
366 353
367 int target_width = (int)target->szHint.width; 354 int target_width = (int)target->szHint.width;
378 { 365 {
379 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 366 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
380 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); 367 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
381 } 368 }
382 369
383 int dst_x, dst_y; 370 if (original_asim == NULL
384 int clip_width, clip_height; 371 || x >= target_width
385 372 || y >= target_height
386 make_clip_rectangle (x, w, target_width, dst_x, clip_width); 373 || (w > 0 && x + w <= 0)
387 make_clip_rectangle (y, h, target_height, dst_y, clip_height); 374 || (h > 0 && y + h <= 0))
388
389 /* TODO : actuall scaling code :) */
390 if (dst_x >= target_width || dst_y >= target_height
391 || clip_width <= 0 || clip_height <= 0 || original_asim == NULL)
392 { 375 {
393 result = background;
394 dst_x = dst_y = 0;
395 if (background) 376 if (background)
396 { 377 {
397 new_pmap_width = clip_width = background->width; 378 new_pmap_width = background->width;
398 new_pmap_height = clip_height = background->height; 379 new_pmap_height = background->height;
380 result = background;
381 if (background_tint != TINT_LEAVE_SAME)
382 {
383 ASImage* tmp = tile_asimage (target->asv, background, 0, 0,
384 target_width, target_height, background_tint,
385 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
386 if (tmp)
387 result = tmp;
388 }
399 } 389 }
400 else 390 else
401 new_pmap_width = new_pmap_height = 0; 391 new_pmap_width = new_pmap_height = 0;
402 } 392 }
403 else 393 else
404 { 394 {
405 result = original_asim; 395 result = original_asim;
406 if ((w > 0 && w != original_asim->width) 396 if ((w > 0 && w != original_asim->width)
416 {/* if tiling - pixmap has to be sized exactly as the image */ 406 {/* if tiling - pixmap has to be sized exactly as the image */
417 if (h_scale == 0) 407 if (h_scale == 0)
418 new_pmap_width = result->width; 408 new_pmap_width = result->width;
419 if (v_scale == 0) 409 if (v_scale == 0)
420 new_pmap_height = result->height; 410 new_pmap_height = result->height;
411 /* we also need to tile our image in one or both directions */
412 if (h_scale == 0 || v_scale == 0)
413 {
414 ASImage *tmp = tile_asimage (target->asv, result,
415 (h_scale > 0) ? 0 : (int)result->width - x,
416 (v_scale > 0) ? 0 : (int)result->height - y,
417 result->width, result->height,
418 TINT_LEAVE_SAME, ASA_XImage,
419 100, ASIMAGE_QUALITY_DEFAULT);
420 if (tmp)
421 {
422 if (result != original_asim)
423 destroy_asimage (&result);
424 result = tmp;
425 }
426 }
421 } 427 }
422 else 428 else
423 {/* if blending background and image - pixmap has to be sized same as target window */ 429 {/* if blending background and image - pixmap has to be sized same as target window */
424 ASImageLayer *layers = create_image_layers (2); 430 ASImageLayer *layers = create_image_layers (2);
425 ASImage *merged_im = NULL; 431 ASImage *merged_im = NULL;
429 layers[0].clip_height = target_height; 435 layers[0].clip_height = target_height;
430 layers[0].tint = background_tint; 436 layers[0].tint = background_tint;
431 layers[1].im = result; 437 layers[1].im = result;
432 if (w <= 0) 438 if (w <= 0)
433 {/* tile horizontally */ 439 {/* tile horizontally */
434 layers[1].dst_x = dst_x - (int)result->width; 440 while (x > 0) x -= (int)result->width;
441 layers[1].dst_x = x;
435 layers[1].clip_width = result->width; 442 layers[1].clip_width = result->width+target_width;
436 } 443 }
437 else 444 else
438 {/* clip horizontally */ 445 {/* clip horizontally */
439 layers[1].dst_x = dst_x; 446 layers[1].dst_x = x;
440 layers[1].clip_width = clip_width; 447 layers[1].clip_width = result->width;
441 } 448 }
442 if (h <= 0) 449 if (h <= 0)
443 { 450 {
444 layers[1].dst_y = dst_y - (int)result->height; 451 while (y > 0) y -= (int)result->height;
452 layers[1].dst_y = y;
453 layers[1].clip_height = result->height + target_height;
454 }
455 else
456 {
457 layers[1].dst_y = y;
445 layers[1].clip_height = result->height; 458 layers[1].clip_height = result->height;
446 }
447 else
448 {
449 layers[1].dst_y = dst_y;
450 layers[1].clip_height = clip_height;
451 } 459 }
452 if (target->rs[Rs_blendtype]) 460 if (target->rs[Rs_blendtype])
453 { 461 {
454 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 462 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
455 if (layers[1].merge_scanlines == NULL) 463 if (layers[1].merge_scanlines == NULL)
460 if (tmp) 468 if (tmp)
461 { 469 {
462 if (result != original_asim) 470 if (result != original_asim)
463 destroy_asimage (&result); 471 destroy_asimage (&result);
464 result = tmp; 472 result = tmp;
465 dst_x = dst_y = 0;
466 clip_width = target_width;
467 clip_height = target_height;
468 } 473 }
469 free (layers); 474 free (layers);
470 } 475 }
471 } 476 }
472 477
497 } 502 }
498 /* fill with background color ( if result's not completely overlapping it)*/ 503 /* fill with background color ( if result's not completely overlapping it)*/
499 gcv.foreground = target->pix_colors[Color_bg]; 504 gcv.foreground = target->pix_colors[Color_bg];
500 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 505 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
501 506
507 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
508 int dst_width = result->width, dst_height = result->height;
509 if (background == NULL)
510 {
511 if (h_scale > 0)
512 src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width);
513 if (v_scale > 0)
514 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
515
502 if (dst_x > 0 || dst_y > 0 516 if (dst_x > 0 || dst_y > 0
503 || dst_x + clip_width < new_pmap_width 517 || dst_x + dst_width < new_pmap_width
504 || dst_y + clip_height < new_pmap_height) 518 || dst_y + dst_height < new_pmap_height)
505 { 519 {
506 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 520 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
507 } 521 }
522 }
523
508 /* put result on pixmap */ 524 /* put result on pixmap */
525 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
509 asimage2drawable (target->asv, pixmap, result, gc, 0, 0, dst_x, dst_y, clip_width, clip_height, True); 526 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
510 527
511 /* set target's background to pixmap */ 528 if (result != background && result != original_asim)
512 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 529 destroy_asimage (&result);
513 530
514 XFreeGC (target->dpy, gc); 531 XFreeGC (target->dpy, gc);
515 } 532 }
516 else
517 {
518 /* set target background to a pixel */
519 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
520 }
521 533
522 return true; 534 return true;
523} 535}
524#endif 536# endif /* HAVE_AFTERIMAGE */
525 537
526void 538bool
527rxvt_term::resize_pixmap () 539bgPixmap_t::set_file (const char *file)
528{
529 XGCValues gcvalue;
530 GC gc;
531 unsigned int w = bgPixmap.h_scale*szHint.width/100;
532 unsigned int h = bgPixmap.v_scale*szHint.height/100;
533 int x = bgPixmap.h_align*szHint.width/100;
534 int y = bgPixmap.v_align*szHint.height/100;
535#ifdef HAVE_AFTERIMAGE
536 ASImage *im = bgPixmap.original_asim;
537#else
538 void *im = NULL;
539#endif
540/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
541 if (bgPixmap.pixmap != None)
542 {
543 XFreePixmap (dpy, bgPixmap.pixmap);
544 bgPixmap.pixmap = None ;
545 }
546#ifdef ENABLE_TRANSPARENCY
547 if (option(Opt_transparent) && am_transparent)
548 {
549 /* we need to re-generate transparency pixmap in that case ! */
550 check_our_parents ();
551 return;
552 }
553#endif
554
555 if (im == NULL)
556 { /* So be it: I'm not using pixmaps */
557 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
558 return;
559 }
560
561 gcvalue.foreground = pix_colors[Color_bg];
562 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
563
564 /* don't zoom pixmap too much nor expand really small pixmaps */
565 if (w > 16000)
566 w = 1;
567 if (h > 16000)
568 h = 1;
569
570#ifdef HAVE_AFTERIMAGE
571 if (w == 0)
572 w = im->width;
573 if (h == 0)
574 h = im->height;
575
576 if (w != im->width || h != im->height)
577 {
578 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
579 if (tmp != NULL)
580 im = tmp;
581 }
582 bgPixmap.pmap_width = MIN(w,szHint.width);
583 bgPixmap.pmap_height = MIN(h,szHint.height);
584#if 0 /* TODO: fix that! */
585 if (x != 0 || y != 0)
586 {
587 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
588 if (tmp != NULL)
589 {
590 if (im != bgPixmap.original_asim)
591 destroy_asimage (&im);
592 im = tmp;
593 }
594 }
595#endif
596 bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth);
597 bgPixmap.pmap_depth = depth;
598
599 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True);
600
601 if (im != bgPixmap.original_asim)
602 destroy_asimage (&im);
603#endif
604 if( bgPixmap.pixmap )
605 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
606
607 XFreeGC (dpy, gc);
608}
609
610void
611rxvt_term::set_bgPixmap (const char *file)
612{ 540{
613 char *f; 541 char *f;
614 542
615 assert (file != NULL); 543 assert (file != NULL);
616 544
617 if (bgPixmap.pixmap != None)
618 {
619 XFreePixmap (dpy, bgPixmap.pixmap);
620 bgPixmap.pixmap = None;
621 }
622
623 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
624 if (*file != '\0') 545 if (*file != '\0')
625 { 546 {
626#ifdef HAVE_AFTERIMAGE 547# ifdef HAVE_AFTERIMAGE
627 if (asimman == NULL) 548 if (target->asimman == NULL)
628 asimman = create_generic_imageman(rs[Rs_path]); 549 target->asimman = create_generic_imageman(target->rs[Rs_path]);
629 if ((f = strchr (file, ';')) == NULL) 550 if ((f = strchr (file, ';')) == NULL)
630 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 551 original_asim = get_asimage( target->asimman, file, 0xFFFFFFFF, 100 );
631 else 552 else
632 { 553 {
633 size_t len = f - file; 554 size_t len = f - file;
634 f = (char *)malloc (len + 1); 555 f = (char *)malloc (len + 1);
635 strncpy (f, file, len); 556 strncpy (f, file, len);
636 f[len] = '\0'; 557 f[len] = '\0';
637 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); 558 original_asim = get_asimage( target->asimman, f, 0xFFFFFFFF, 100 );
638 free( f ); 559 free( f );
639 } 560 }
561 return (original_asim != NULL);
640#endif 562# endif
641 } 563 }
642 564 return false;
643 resize_pixmap ();
644} 565}
645 566
646#endif /* XPM_BACKGROUND */ 567# endif /* XPM_BACKGROUND */
568
569# ifdef ENABLE_TRANSPARENCY
570bool
571bgPixmap_t::set_transparent ()
572{
573 if (!(flags & isTransparent))
574 {
575 flags |= isTransparent;
576 return true;
577 }
578}
579
580bool
581bgPixmap_t::set_blur_radius (const char *geom)
582{
583 int changed = 0;
584 unsigned int hr, vr;
585 int junk;
586 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
587 if (!(geom_flags&WidthValue))
588 hr = 1;
589 if (!(geom_flags&HeightValue))
590 vr = hr;
591
592 if (h_blurRadius != hr)
593 {
594 ++changed;
595 h_blurRadius = hr;
596 }
597 if (v_blurRadius != vr)
598 {
599 ++changed;
600 v_blurRadius = vr;
601 }
602 return (changed>0);
603}
604
605static inline unsigned long
606compute_tint_shade_flags (rxvt_color *tint, int shade)
607{
608 unsigned long flags = 0;
609
610 if (shade > 0 && shade <100)
611 flags |= bgPixmap_t::tintNeeded;
612 else if (tint)
613 {
614 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
615 tint->get (c);
616
617 flags |= bgPixmap_t::tintNeeded;
618 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
619 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
620 {
621 flags |= bgPixmap_t::tintNeeded;
622#define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700)
623 if (IS_COMPONENT_WHOLESOME (c.r)
624 && IS_COMPONENT_WHOLESOME (c.g)
625 && IS_COMPONENT_WHOLESOME (c.b))
626 flags |= bgPixmap_t::tintServerSide;
627#undef IS_COMPONENT_WHOLESOME
628 }
629 }
630 return flags;
631}
632
633bool
634bgPixmap_t::set_tint (rxvt_color &new_tint)
635{
636 if (tint != new_tint)
637 {
638 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
639 tint = new_tint;
640 flags = (flags & ~tintFlags) | new_flags | tintSet;
641 return true;
642 }
643 return false;
644}
645
646bool
647bgPixmap_t::unset_tint ()
648{
649 unsigned long new_flags = compute_tint_shade_flags (NULL, shade);
650
651 if (new_flags != (flags & tintFlags))
652 {
653 flags = (flags&~tintFlags)|new_flags;
654 return true;
655 }
656 return false;
657}
658
659bool
660bgPixmap_t::set_shade (const char *shade_str)
661{
662 int new_shade = (shade_str) ? atoi (shade_str) : 0;
663
664 if (new_shade == 100)
665 new_shade = 0;
666
667 if (new_shade != shade)
668 {
669 unsigned long new_flags = compute_tint_shade_flags (&tint, new_shade);
670 shade = new_shade;
671 flags = (flags & ~tintFlags) | new_flags;
672 return true;
673 }
674 return false;
675}
676
677
678/* make_transparency_pixmap()
679 * Builds a pixmap sized the same as terminal window, with depth same as the root window
680 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
681 * our window.
682 */
683unsigned long
684bgPixmap_t::make_transparency_pixmap ()
685{
686 unsigned long result = 0;
687
688 if (target == NULL)
689 return 0;
690
691 /* root dimentions may change from call to call - but Display structure should
692 * be always up-to-date, so let's use it :
693 */
694 Window root = target->display->root;
695 int screen = target->display->screen;
696 Display *dpy = target->dpy;
697 int root_width = DisplayWidth (dpy, screen);
698 int root_height = DisplayHeight (dpy, screen);
699 unsigned int root_pmap_width, root_pmap_height;
700 int window_width = target->szHint.width;
701 int window_height = target->szHint.height;
702 int sx, sy;
703 XGCValues gcv;
704
705 target->get_window_origin (sx, sy);
706
707 /* check if we are outside of the visible part of the virtual screen : */
708 if (sx + window_width <= 0 || sy + window_height <= 0
709 || sx >= root_width || sy >= root_height)
710 return 0;
711
712 if (root_pixmap != None)
713 {/* we want to validate the pixmap and get it's size at the same time : */
714 int junk;
715 unsigned int ujunk;
716 /* root pixmap may be bad - allow a error */
717 target->allowedxerror = -1;
718 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk))
719 root_pixmap = None;
720 target->allowedxerror = 0;
721 }
722
723 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
724 GC gc = NULL;
725
726 if (tiled_root_pmap == None) /* something really bad happened - abort */
727 return 0;
728
729 if (root_pixmap == None)
730 { /* use tricks to obtain the root background image :*/
731 /* we want to create Overrideredirect window overlapping out window
732 with background type of Parent Relative and then grab it */
733 XSetWindowAttributes attr;
734 Window src;
735 bool success = false;
736
737 attr.background_pixmap = ParentRelative;
738 attr.backing_store = Always;
739 attr.event_mask = ExposureMask;
740 attr.override_redirect = True;
741 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
742 CopyFromParent, CopyFromParent, CopyFromParent,
743 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
744 &attr);
745
746 if (src != None)
747 {
748 XEvent event;
749 int ev_count = 0;
750 XGrabServer (dpy);
751 XMapRaised (dpy, src);
752 XSync (dpy, False);
753 /* XSync should get window where it's properly exposed,
754 * but to be on the safe side - let's check for the actuall event to arrive : */
755 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
756 ++ev_count;
757 if (ev_count > 0);
758 { /* hooray! - we can grab the image! */
759 gc = XCreateGC (dpy, root, 0, NULL);
760 if (gc)
761 {
762 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
763 success = true;
764 }
765 }
766 XDestroyWindow (dpy, src);
767 XUngrabServer (dpy);
768 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
769 }
770 if (!success)
771 {
772 XFreePixmap (dpy, tiled_root_pmap);
773 tiled_root_pmap = None;
774 }
775 else
776 result |= transpPmapTiled;
777 }
778 else
779 {/* strightforward pixmap copy */
780 gcv.tile = root_pixmap;
781 gcv.fill_style = FillTiled;
782 while (sx < 0) sx += (int)window_width;
783 while (sy < 0) sy += (int)window_height;
784 gcv.ts_x_origin = -sx;
785 gcv.ts_y_origin = -sy;
786 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
787 if (gc)
788 {
789 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
790 result |= transpPmapTiled;
791 }
792 }
793
794 if (tiled_root_pmap != None)
795 {
796 if (flags & tintNeeded)
797 {
798 if ((flags & tintServerSide)
799 && h_blurRadius <= 1 && v_blurRadius <= 1
800# ifdef HAVE_AFTERIMAGE
801 && original_asim == NULL
802# endif
803 )
804 { /* In this case we can tint image server-side getting significant
805 * performance improvements, as we eliminate XImage transfer
806 */
807 gcv.foreground = Pixel (tint);
808 gcv.function = GXand;
809 gcv.fill_style = FillSolid;
810 if (gc)
811 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
812 else
813 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
814 if (gc)
815 {
816 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
817 result |= transpPmapTinted;
818 }
819 }
820 }
821 if (pixmap)
822 XFreePixmap (dpy, pixmap);
823 pixmap = tiled_root_pmap;
824 pmap_width = window_width;
825 pmap_height = window_height;
826 pmap_depth = root_depth;
827 }
828
829 if (gc)
830 XFreeGC (dpy, gc);
831
832 return result;
833}
834
835bool
836bgPixmap_t::set_root_pixmap ()
837{
838 Pixmap new_root_pixmap = None;
839
840 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
841 if (new_root_pixmap == None)
842 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
843
844 if (new_root_pixmap != root_pixmap)
845 {
846 root_pixmap = new_root_pixmap;
847 return true;
848 }
849 return false;
850}
851# endif /* ENABLE_TRANSPARENCY */
852
853# ifndef HAVE_AFTERIMAGE
854static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm);
855#endif
856
857
858bool
859bgPixmap_t::render ()
860{
861 unsigned long background_flags = 0;
862
863 if (target == NULL)
864 return false;
865
866 invalidate();
867# ifdef ENABLE_TRANSPARENCY
868 if (flags & isTransparent)
869 {
870 /* we need to re-generate transparency pixmap in that case ! */
871 background_flags = make_transparency_pixmap ();
872 if (background_flags == 0)
873 return false;
874 else if ((background_flags & transpTransformations) == (flags & transpTransformations)
875 && pmap_depth == target->depth)
876 flags = flags & ~isInvalid;
877 }
878# endif
879
880 XImage *result = NULL;
881# ifdef HAVE_AFTERIMAGE
882 if (original_asim
883 || (background_flags & transpTransformations) != (flags & transpTransformations))
884 {
885 ASImage *background = NULL;
886 ARGB32 as_tint = TINT_LEAVE_SAME;
887 if (background_flags)
888 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
889
890 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
891 {
892 ShadingInfo as_shade;
893 as_shade.shading = (shade == 0) ? 100 : shade;
894
895 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
896 tint.get (c);
897 as_shade.tintColor.red = c.r;
898 as_shade.tintColor.green = c.g;
899 as_shade.tintColor.blue = c.b;
900
901 as_tint = shading2tint32 (&as_shade);
902 }
903 if (render_asim (background, as_tint))
904 flags = flags & ~isInvalid;
905 if (background)
906 destroy_asimage (&background);
907 }
908 else if (background_flags && pmap_depth != target->depth)
909 {
910 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
911 }
912# else /* our own client-side tinting */
913 if (background_flags && (flags & isInvalid))
914 {
915 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
916 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
917 {
918 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
919 tint.get (c);
920 ShadeXImage (target, result, shade, c.r, c.g, c.b);
921 }
922 }
923# endif
924 if (result != NULL)
925 {
926 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
927 if (gc)
928 {
929 if (pmap_depth != target->depth && pixmap != None)
930 {
931 XFreePixmap (target->dpy, pixmap);
932 pixmap = None;
933 }
934 if (pixmap == None)
935 {
936 pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth);
937 pmap_width = result->width;
938 pmap_height = result->height;
939 pmap_depth = target->depth;
940 }
941 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
942 XFreeGC (target->dpy, gc);
943 flags = flags & ~isInvalid;
944 }
945 XDestroyImage (result);
946 }
947
948 if (flags & isInvalid)
949 {
950 if (pixmap != None)
951 {
952 XFreePixmap (target->dpy, pixmap);
953 pixmap = None;
954 }
955// TODO : we need to get rid of that garbadge :
956 target->am_transparent = target->am_pixmap_trans = 0;
957 }
958 else
959 target->am_transparent = target->am_pixmap_trans = 1;
960
961 apply ();
962
963 return true;
964}
965
966bool
967bgPixmap_t::set_target (rxvt_term *new_target)
968{
969 if (new_target)
970 if (target != new_target)
971 {
972 target = new_target;
973# ifdef ENABLE_TRANSPARENCY
974 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
975# endif
976 return true;
977 }
978 return false;
979}
980
981void
982bgPixmap_t::apply()
983{
984 if (target)
985 {
986 if (pixmap != None)
987 { /* set target's background to pixmap */
988# ifdef ENABLE_TRANSPARENCY
989 if (flags & isTransparent)
990 {
991 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
992 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
993# if HAVE_SCROLLBARS
994 if (target->scrollBar.win)
995 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
996# endif
997 }
998 else
999# endif
1000 {
1001 /* force old pixmap dereference in case it was transparent before :*/
1002 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1003 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1004 /* do we also need to set scrollbar's background here ? */
1005# if HAVE_SCROLLBARS
1006 if (target->scrollBar.win)
1007 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1008# endif
1009 }
1010 }
1011 else
1012 { /* set target background to a pixel */
1013 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1014 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1015 /* do we also need to set scrollbar's background here ? */
1016# if HAVE_SCROLLBARS
1017 if (target->scrollBar.win)
1018 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1019# endif
1020 }
1021 /* don't want Expose on the parent */
1022 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
1023 /* do want Expose on the vt */
1024 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
1025#if HAVE_SCROLLBARS
1026 if (target->scrollBar.win)
1027 {
1028 target->scrollBar.setIdle ();
1029 target->scrollbar_show (0);
1030 }
1031#endif
1032 target->want_refresh = target->want_full_refresh = 1;
1033 target->flush ();
1034 }
1035}
647#endif /* HAVE_BG_PIXMAP */ 1036#endif /* HAVE_BG_PIXMAP */
1037
1038
1039void
1040rxvt_term::get_window_origin (int &x, int &y)
1041{
1042 Window cr;
1043 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
1044}
1045
1046Pixmap
1047rxvt_term::get_pixmap_property (int prop_id)
1048{
1049 if (prop_id > 0 && prop_id < NUM_XA)
1050 if (xa[prop_id])
1051 {
1052 int aformat, rootdepth;
1053 unsigned long nitems, bytes_after;
1054 Atom atype;
1055 unsigned char *prop = NULL;
1056 int result = XGetWindowProperty (dpy, display->root, xa[prop_id],
1057 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
1058 &nitems, &bytes_after, &prop);
1059 if (result == Success && prop && atype == XA_PIXMAP)
1060 {
1061 return *(Pixmap *)prop;
1062 }
1063 }
1064 return None;
1065}
1066
648 1067
649#ifdef ENABLE_TRANSPARENCY 1068#ifdef ENABLE_TRANSPARENCY
650#ifndef HAVE_AFTERIMAGE 1069#ifndef HAVE_AFTERIMAGE
651/* taken from aterm-0.4.2 */ 1070/* taken from aterm-0.4.2 */
652 1071
662 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1081 unsigned int upper_lim_r, upper_lim_g, upper_lim_b;
663 int i; 1082 int i;
664 1083
665 Visual *visual = term->visual; 1084 Visual *visual = term->visual;
666 1085
667 if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; 1086 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ;
668 1087
1088 if (shade == 0)
1089 shade = 100;
1090
669 /* for convenience */ 1091 /* for convenience */
670 mask_r = visual->red_mask; 1092 mask_r = visual->red_mask;
671 mask_g = visual->green_mask; 1093 mask_g = visual->green_mask;
672 mask_b = visual->blue_mask; 1094 mask_b = visual->blue_mask;
673 1095
892} 1314}
893 1315
894void 1316void
895rxvt_term::check_our_parents_cb (time_watcher &w) 1317rxvt_term::check_our_parents_cb (time_watcher &w)
896{ 1318{
1319#if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */
1320
897 int i, pchanged, aformat, rootdepth; 1321 int i, aformat, rootdepth;
898 unsigned long nitems, bytes_after; 1322 unsigned long nitems, bytes_after;
899 Atom atype; 1323 Atom atype;
900 unsigned char *prop = NULL; 1324 unsigned char *prop = NULL;
901 Window root, oldp, *list; 1325 Window root, oldp, *list;
902 Pixmap rootpixmap = None; 1326 Pixmap rootpixmap = None;
903 XWindowAttributes wattr, wrootattr; 1327 XWindowAttributes wattr, wrootattr;
904 int sx, sy; 1328 int sx, sy;
905 Window cr; 1329 Window cr;
906 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 1330 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
907 1331
908 pchanged = 0;
909
910 if (!option (Opt_transparent)) 1332 if (!option (Opt_transparent))
911 return /*pchanged*/; /* Don't try any more */ 1333 return; /* Don't try any more */
912
913#if 0 1334#if 0
914 struct timeval stv; 1335 struct timeval stv;
915 gettimeofday (&stv,NULL); 1336 gettimeofday (&stv,NULL);
916#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ 1337#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
917 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\ 1338 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
928 1349
929 if (rootdepth != wattr.depth) 1350 if (rootdepth != wattr.depth)
930 { 1351 {
931 if (am_transparent) 1352 if (am_transparent)
932 { 1353 {
933 pchanged = 1;
934 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); 1354 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
935 am_transparent = am_pixmap_trans = 0; 1355 am_transparent = am_pixmap_trans = 0;
936 } 1356 }
937 1357
938 return /*pchanged*/; /* Don't try any more */ 1358 return; /* Don't try any more */
939 } 1359 }
940 1360
941 /* Get all X ops out of the queue so that our information is up-to-date. */ 1361 /* Get all X ops out of the queue so that our information is up-to-date. */
942 XSync (dpy, False); 1362 XSync (dpy, False);
943 1363
1001 whole_tint = (IS_COMPONENT_WHOLESOME(c.r) 1421 whole_tint = (IS_COMPONENT_WHOLESOME(c.r)
1002 && IS_COMPONENT_WHOLESOME(c.g) 1422 && IS_COMPONENT_WHOLESOME(c.g)
1003 && IS_COMPONENT_WHOLESOME(c.b)); 1423 && IS_COMPONENT_WHOLESOME(c.b));
1004 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); 1424 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
1005#undef IS_COMPONENT_WHOLESOME 1425#undef IS_COMPONENT_WHOLESOME
1006 /* theer are no performance advantages to reusing same pixmap */
1007 if (bgPixmap.pixmap != None)
1008 XFreePixmap (dpy, bgPixmap.pixmap);
1009 bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth);
1010 bgPixmap.pmap_width = szHint.width;
1011 bgPixmap.pmap_height = szHint.height;
1012 bgPixmap.pmap_depth = rootdepth;
1013 1426
1014#if 0 /* TODO : identify cases where this will be detrimental to performance : */ 1427 bgPixmap.make_transparency_pixmap();
1015 /* we want to tile root pixmap into our own pixmap in this cases :
1016 * 1) rootpixmap does not cover our window entirely
1017 * 2) whole_tint - we can use server-side tinting or tinting disabled
1018 */
1019 if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height)
1020 {
1021 }
1022#endif
1023 gcvalue.tile = rootpixmap;
1024 gcvalue.fill_style = FillTiled;
1025 gcvalue.ts_x_origin = -sx;
1026 gcvalue.ts_y_origin = -sy;
1027 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue);
1028 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1029 1428
1030 if (whole_tint && !no_tint) 1429 if (whole_tint && !no_tint)
1031 { 1430 {
1032 /* In this case we can tint image server-side getting significant
1033 * performance improvements, as we eliminate XImage transfer
1034 */
1035 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
1036 gcvalue.function = GXand;
1037 gcvalue.fill_style = FillSolid;
1038 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
1039 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1040 } 1431 }
1041 success = True; 1432 success = True;
1042#ifdef HAVE_AFTERIMAGE 1433#ifdef HAVE_AFTERIMAGE
1043 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) 1434 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
1044 { 1435 {
1075 { 1466 {
1076 destroy_asimage (&back_im); 1467 destroy_asimage (&back_im);
1077 back_im = tmp; 1468 back_im = tmp;
1078 } 1469 }
1079 } 1470 }
1080 1471 /* TODO: temporary fix - redo the logic, so that same function can do both
1081 if (bgPixmap.original_asim != NULL) 1472 transparency and non-transparency */
1082 { 1473 bgPixmap.render_asim (back_im, tint);
1083 ASImageLayer *layers = create_image_layers (2);
1084 ASImage *merged_im = NULL;
1085 int fore_w, fore_h;
1086
1087 layers[0].im = back_im;
1088 layers[0].clip_width = szHint.width;
1089 layers[0].clip_height = szHint.height;
1090 layers[0].tint = tint;
1091 layers[1].im = bgPixmap.original_asim;
1092
1093 fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100;
1094 fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100;
1095
1096 if (fore_w != bgPixmap.original_asim->width
1097 || fore_h != bgPixmap.original_asim->height)
1098 {
1099 layers[1].im = scale_asimage (asv,
1100 bgPixmap.original_asim,
1101 fore_w, fore_h,
1102 ASA_ASImage, 100,
1103 ASIMAGE_QUALITY_DEFAULT);
1104 }
1105 layers[1].clip_width = szHint.width;
1106 layers[1].clip_height = szHint.height;
1107
1108 if (rs[Rs_blendtype])
1109 {
1110 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
1111 if (layers[1].merge_scanlines == NULL)
1112 layers[1].merge_scanlines = alphablend_scanlines;
1113 }
1114 PRINT_BACKGROUND_OP_TIME;
1115 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height,
1116 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
1117 if (layers[1].im != bgPixmap.original_asim)
1118 destroy_asimage (&(layers[1].im));
1119 free (layers);
1120
1121 if (merged_im != NULL)
1122 {
1123 destroy_asimage (&back_im);
1124 back_im = merged_im;
1125 }
1126 PRINT_BACKGROUND_OP_TIME;
1127 }
1128 else if (tint != TINT_LEAVE_SAME)
1129 {
1130 ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
1131 if (tmp)
1132 {
1133 destroy_asimage (&back_im);
1134 back_im = tmp;
1135 }
1136 PRINT_BACKGROUND_OP_TIME;
1137 }
1138 asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True);
1139 destroy_asimage (&back_im); 1474 destroy_asimage (&back_im);
1475
1140 } /* back_im != NULL */ 1476 } /* back_im != NULL */
1141 else 1477 else
1142 success = False; 1478 success = False;
1143 } 1479 }
1144#else /* HAVE_AFTERIMAGE */ 1480#else /* HAVE_AFTERIMAGE */
1161#endif /* HAVE_AFTERIMAGE */ 1497#endif /* HAVE_AFTERIMAGE */
1162 PRINT_BACKGROUND_OP_TIME; 1498 PRINT_BACKGROUND_OP_TIME;
1163 1499
1164 if (gc != NULL) 1500 if (gc != NULL)
1165 XFreeGC (dpy, gc); 1501 XFreeGC (dpy, gc);
1166 1502
1503 bgPixmap.apply();
1167 if (!success) 1504 if (!success)
1168 {
1169 if (am_transparent && am_pixmap_trans)
1170 {
1171 pchanged = 1;
1172 if (bgPixmap.pixmap != None)
1173 {
1174 XFreePixmap (dpy, bgPixmap.pixmap);
1175 bgPixmap.pixmap = None;
1176 }
1177 }
1178
1179 am_pixmap_trans = 0; 1505 am_pixmap_trans = 0;
1180 }
1181 else 1506 else
1182 { 1507 {
1183 XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap);
1184 XClearWindow (dpy, parent[0]);
1185
1186 if (!am_transparent || !am_pixmap_trans)
1187 pchanged = 1;
1188
1189 am_transparent = am_pixmap_trans = 1; 1508 am_transparent = am_pixmap_trans = 1;
1190 } 1509 }
1191 } /* rootpixmap != None */ 1510 } /* rootpixmap != None */
1192 1511
1193 if (am_pixmap_trans) 1512 if (am_pixmap_trans)
1194 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); 1513 {
1195 else
1196 return;
1197
1198 if (scrollBar.win) 1514 if (scrollBar.win)
1199 { 1515 {
1200 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
1201 scrollBar.setIdle (); 1516 scrollBar.setIdle ();
1202 scrollbar_show (0); 1517 scrollbar_show (0);
1203 } 1518 }
1204 1519
1205 if (am_transparent) 1520 if (am_transparent)
1206 { 1521 {
1207 want_refresh = want_full_refresh = 1; 1522 want_refresh = want_full_refresh = 1;
1208 if (am_pixmap_trans) 1523 if (am_pixmap_trans)
1209 flush (); 1524 flush ();
1525 }
1210 } 1526 }
1211 1527#endif
1212// return pchanged;
1213} 1528}
1214#endif 1529#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines