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.59 by sasha, Sun Aug 5 06:19:01 2007 UTC vs.
Revision 1.63 by sasha, Wed Aug 8 22:39:49 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 & bgPmap_Transparent)
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, short &clip_pos, unsigned short &clip_size) 146make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
147{ 147{
148 if (pos < 0) 148 int src_pos = 0;
149 { 149 dst_pos = 0;
150 clip_pos = 0; 150 dst_size = size;
151 clip_size = MIN (target_size, size + pos); 151 if (pos < 0 && size > target_size)
152 } 152 {
153 else
154 {
155 clip_pos = pos; 153 src_pos = -pos;
156 clip_size = size; 154 dst_size += pos;
157 if (pos < target_size && (int)clip_size > target_size - pos)
158 clip_pos = target_size - pos;
159 } 155 }
156 else if (pos > 0)
157 dst_pos = pos;
158
159 if (dst_pos + dst_size > target_size)
160 dst_size = target_size - dst_pos;
161 return src_pos;
160} 162}
161 163
162bool 164bool
163bgPixmap_t::handle_geometry (const char *geom) 165bgPixmap_t::handle_geometry (const char *geom)
164{ 166{
166 int x = 0, y = 0; 168 int x = 0, y = 0;
167 unsigned int w = 0, h = 0; 169 unsigned int w = 0, h = 0;
168 unsigned int n; 170 unsigned int n;
169 unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); 171 unsigned long new_flags = (flags&(~bgPmap_geometryFlags));
170 char *p; 172 char *p;
171#define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ 173# define MAXLEN_GEOM 256 /* could be longer then regular geometry string */
172 174
173 if (geom == NULL) 175 if (geom == NULL)
174 return false; 176 return false;
175 177
176 char str[MAXLEN_GEOM]; 178 char str[MAXLEN_GEOM];
177 179
178 if (!strcmp (geom, "?")) 180 if (!strcmp (geom, "?"))
179 { 181 {
180#if 0 /* TODO: */ 182 if (target)
183 {
181 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 184 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
182 min (h_scale, 32767), min (v_scale, 32767), 185 min (h_scale, 32767), min (v_scale, 32767),
183 min (h_align, 32767), min (v_align, 32767)); 186 min (h_align, 32767), min (v_align, 32767));
184 process_xterm_seq (XTerm_title, str, CHAR_ST); 187 target->process_xterm_seq (XTerm_title, str, CHAR_ST);
185#endif 188 }
186 return false; 189 return false;
187 } 190 }
188 while (isspace(*geom)) ++geom; 191 while (isspace(*geom)) ++geom;
189 if ((p = strchr (geom, ';')) == NULL) 192 if ((p = strchr (geom, ';')) == NULL)
190 p = strchr (geom, '\0'); 193 p = strchr (geom, '\0');
262 w = h = bgPmap_defaultScale; 265 w = h = bgPmap_defaultScale;
263 } 266 }
264 else if (geom_flags & WidthValue) 267 else if (geom_flags & WidthValue)
265 { 268 {
266 if (!(geom_flags & HeightValue)) 269 if (!(geom_flags & HeightValue))
267 h = w; 270 h = w;
268 } 271 }
269 else 272 else
270 w = h; 273 w = h;
271 } 274 }
272 } /* done parsing geometry string */ 275 } /* done parsing geometry string */
273 else if (!(flags & bgPmap_geometrySet)) 276 else if (!(flags & bgPmap_geometrySet))
274 { /* default geometry - scaled and centered */ 277 { /* default geometry - scaled and centered */
275 x = y = bgPmap_defaultAlign; 278 x = y = bgPmap_defaultAlign;
276 w = h = bgPmap_defaultScale; 279 w = h = bgPmap_defaultScale;
277 } 280 }
278 281
279 if (!(flags & bgPmap_geometrySet)) 282 if (!(flags & bgPmap_geometrySet))
280 geom_flags |= WidthValue|HeightValue|XValue|YValue; 283 geom_flags |= WidthValue|HeightValue|XValue|YValue;
281 284
282 if (ops) 285 if (ops)
283 { 286 {
284 while (*ops) 287 while (*ops)
285 { 288 {
286 while (*ops == ':' || isspace(*ops)) ++ops; 289 while (*ops == ':' || isspace(*ops)) ++ops;
287#define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 290# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
288 if (CHECK_GEOM_OPS("tile")) 291 if (CHECK_GEOM_OPS("tile"))
289 { 292 {
290 w = h = 0; 293 w = h = 0;
291 geom_flags |= WidthValue|HeightValue; 294 geom_flags |= WidthValue|HeightValue;
292 } 295 }
325 { 328 {
326 w = h = 100; 329 w = h = 100;
327 x = y = 50; 330 x = y = 50;
328 geom_flags |= WidthValue|HeightValue|XValue|YValue; 331 geom_flags |= WidthValue|HeightValue|XValue|YValue;
329 } 332 }
330#undef CHECK_GEOM_OPS 333# undef CHECK_GEOM_OPS
331 while (*ops != ':' && *ops != '\0') ++ops; 334 while (*ops != ':' && *ops != '\0') ++ops;
332 } /* done parsing ops */ 335 } /* done parsing ops */
333 } 336 }
334 337
335 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 338 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w))
350//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 353//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
351// flags, h_scale, v_scale, h_align, v_align); 354// flags, h_scale, v_scale, h_align, v_align);
352 return (changed > 0); 355 return (changed > 0);
353} 356}
354 357
355#ifdef HAVE_AFTERIMAGE 358# ifdef HAVE_AFTERIMAGE
356ASImage * 359bool
357bgPixmap_t::resize_asim (rxvt_term *target, ASImage *background, XRectangle &dst_rect) 360bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint)
358{ 361{
359 if (original_asim == NULL || target == NULL) 362 if (target == NULL)
360 return NULL; 363 return false;
361 364
362 int target_width = (int)target->szHint.width; 365 int target_width = (int)target->szHint.width;
363 int target_height = (int)target->szHint.height; 366 int target_height = (int)target->szHint.height;
367 int new_pmap_width = target_width, new_pmap_height = target_height;
368 ASImage *result = NULL;
369
370 int x = 0;
371 int y = 0;
364 int w = h_scale * target_width / 100; 372 int w = h_scale * target_width / 100;
365 int h = v_scale * target_height / 100; 373 int h = v_scale * target_height / 100;
366 int x = make_align_position (h_align, target_width, w);
367 int y = make_align_position (v_align, target_height, h);
368 374
369 make_clip_rectangle (x, w, target_width, dst_rect.x, dst_rect.width); 375 if (original_asim)
370 make_clip_rectangle (y, h, target_height, dst_rect.y, dst_rect.height); 376 {
377 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width);
378 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
379 }
371 380
372 /* TODO : actuall scaling code :) */ 381 if (original_asim == NULL
382 || x >= target_width
383 || y >= target_height
384 || (w > 0 && x + w <= 0)
385 || (h > 0 && y + h <= 0))
386 {
387 if (background)
388 {
389 new_pmap_width = background->width;
390 new_pmap_height = background->height;
391 result = background;
392 if (background_tint != TINT_LEAVE_SAME)
393 {
394 ASImage* tmp = tile_asimage (target->asv, background, 0, 0,
395 target_width, target_height, background_tint,
396 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
397 if (tmp)
398 result = tmp;
399 }
400 }
401 else
402 new_pmap_width = new_pmap_height = 0;
403 }
404 else
405 {
406 result = original_asim;
407 if ((w > 0 && w != original_asim->width)
408 || (h > 0 && h != original_asim->height))
409 {
410 result = scale_asimage (target->asv, original_asim,
411 w > 0 ? w : original_asim->width,
412 h > 0 ? h : original_asim->height,
413 background ? ASA_ASImage : ASA_XImage,
414 100, ASIMAGE_QUALITY_DEFAULT);
415 }
416 if (background == NULL)
417 {/* if tiling - pixmap has to be sized exactly as the image */
418 if (h_scale == 0)
419 new_pmap_width = result->width;
420 if (v_scale == 0)
421 new_pmap_height = result->height;
422 /* we also need to tile our image in one or both directions */
423 if (h_scale == 0 || v_scale == 0)
424 {
425 ASImage *tmp = tile_asimage (target->asv, result,
426 (h_scale > 0) ? 0 : (int)result->width - x,
427 (v_scale > 0) ? 0 : (int)result->height - y,
428 result->width, result->height,
429 TINT_LEAVE_SAME, ASA_XImage,
430 100, ASIMAGE_QUALITY_DEFAULT);
431 if (tmp)
432 {
433 if (result != original_asim)
434 destroy_asimage (&result);
435 result = tmp;
436 }
437 }
438 }
439 else
440 {/* if blending background and image - pixmap has to be sized same as target window */
441 ASImageLayer *layers = create_image_layers (2);
442 ASImage *merged_im = NULL;
373 443
444 layers[0].im = background;
445 layers[0].clip_width = target_width;
446 layers[0].clip_height = target_height;
447 layers[0].tint = background_tint;
448 layers[1].im = result;
449 if (w <= 0)
450 {/* tile horizontally */
451 while (x > 0) x -= (int)result->width;
452 layers[1].dst_x = x;
453 layers[1].clip_width = result->width+target_width;
454 }
455 else
456 {/* clip horizontally */
457 layers[1].dst_x = x;
458 layers[1].clip_width = result->width;
459 }
460 if (h <= 0)
461 {
462 while (y > 0) y -= (int)result->height;
463 layers[1].dst_y = y;
464 layers[1].clip_height = result->height + target_height;
465 }
466 else
467 {
468 layers[1].dst_y = y;
469 layers[1].clip_height = result->height;
470 }
471 if (target->rs[Rs_blendtype])
472 {
473 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
474 if (layers[1].merge_scanlines == NULL)
475 layers[1].merge_scanlines = alphablend_scanlines;
476 }
477 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height,
478 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
479 if (tmp)
480 {
481 if (result != original_asim)
482 destroy_asimage (&result);
483 result = tmp;
484 }
485 free (layers);
486 }
487 }
488
489 if (pixmap)
490 {
491 if (result == NULL
492 || pmap_width != new_pmap_width
493 || pmap_height != new_pmap_height
494 || pmap_depth != target->depth)
495 {
496 XFreePixmap (target->dpy, pixmap);
497 pixmap = None;
498 }
499 }
500
501 if (result)
502 {
503 XGCValues gcv;
504 GC gc;
505
506 /* create Pixmap */
507 if (pixmap == None)
508 {
509 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
510 pmap_width = new_pmap_width;
511 pmap_height = new_pmap_height;
512 pmap_depth = target->depth;
513 }
514 /* fill with background color ( if result's not completely overlapping it)*/
515 gcv.foreground = target->pix_colors[Color_bg];
516 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
517
518 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
519 int dst_width = result->width, dst_height = result->height;
520 if (background == NULL)
521 {
522 if (h_scale > 0)
523 src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width);
524 if (v_scale > 0)
525 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
526
527 if (dst_x > 0 || dst_y > 0
528 || dst_x + dst_width < new_pmap_width
529 || dst_y + dst_height < new_pmap_height)
530 {
531 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
532 }
533 }
534
535 /* put result on pixmap */
536 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
537 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
538
539 if (result != background && result != original_asim)
540 destroy_asimage (&result);
541
542 XFreeGC (target->dpy, gc);
543 if (background)
544 flags |= bgPmap_Transparent;
545 else
546 flags &= ~bgPmap_Transparent;
547 }
548
549 return true;
374} 550}
375#endif 551# endif /* HAVE_AFTERIMAGE */
376 552
377void 553void
378rxvt_term::resize_pixmap () 554rxvt_term::resize_pixmap ()
379{ 555{
380 XGCValues gcvalue; 556
381 GC gc;
382 unsigned int w = bgPixmap.h_scale*szHint.width/100;
383 unsigned int h = bgPixmap.v_scale*szHint.height/100;
384 int x = bgPixmap.h_align*szHint.width/100;
385 int y = bgPixmap.v_align*szHint.height/100;
386#ifdef HAVE_AFTERIMAGE
387 ASImage *im = bgPixmap.original_asim;
388#else
389 void *im = NULL;
390#endif
391/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
392 if (bgPixmap.pixmap != None)
393 {
394 XFreePixmap (dpy, bgPixmap.pixmap);
395 bgPixmap.pixmap = None ;
396 }
397#ifdef ENABLE_TRANSPARENCY 557# ifdef ENABLE_TRANSPARENCY
398 if (option(Opt_transparent) && am_transparent) 558 if (option(Opt_transparent) && am_transparent)
399 { 559 {
400 /* we need to re-generate transparency pixmap in that case ! */ 560 /* we need to re-generate transparency pixmap in that case ! */
401 check_our_parents (); 561 check_our_parents ();
402 return; 562 return;
403 } 563 }
404#endif 564# endif
405
406 if (im == NULL)
407 { /* So be it: I'm not using pixmaps */
408 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
409 return;
410 }
411
412 gcvalue.foreground = pix_colors[Color_bg];
413 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
414
415 /* don't zoom pixmap too much nor expand really small pixmaps */
416 if (w > 16000)
417 w = 1;
418 if (h > 16000)
419 h = 1;
420
421#ifdef HAVE_AFTERIMAGE 565# ifdef HAVE_AFTERIMAGE
422 if (w == 0) 566 bgPixmap.render_asim(NULL, TINT_LEAVE_SAME);
423 w = im->width; 567 bgPixmap.apply_background();
424 if (h == 0)
425 h = im->height;
426
427 if (w != im->width || h != im->height)
428 {
429 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
430 if (tmp != NULL)
431 im = tmp;
432 }
433 bgPixmap.pmap_width = MIN(w,szHint.width);
434 bgPixmap.pmap_height = MIN(h,szHint.height);
435#if 0 /* TODO: fix that! */
436 if (x != 0 || y != 0)
437 {
438 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
439 if (tmp != NULL)
440 {
441 if (im != bgPixmap.original_asim)
442 destroy_asimage (&im);
443 im = tmp;
444 }
445 }
446#endif
447 bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth);
448 bgPixmap.pmap_depth = depth;
449
450 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True);
451
452 if (im != bgPixmap.original_asim)
453 destroy_asimage (&im);
454#endif 568# endif
455 if( bgPixmap.pixmap )
456 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
457
458 XFreeGC (dpy, gc);
459} 569}
460 570
461void 571void
462rxvt_term::set_bgPixmap (const char *file) 572rxvt_term::set_bgPixmap (const char *file)
463{ 573{
472 } 582 }
473 583
474 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 584 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
475 if (*file != '\0') 585 if (*file != '\0')
476 { 586 {
477#ifdef HAVE_AFTERIMAGE 587# ifdef HAVE_AFTERIMAGE
478 if (asimman == NULL) 588 if (asimman == NULL)
479 asimman = create_generic_imageman(rs[Rs_path]); 589 asimman = create_generic_imageman(rs[Rs_path]);
480 if ((f = strchr (file, ';')) == NULL) 590 if ((f = strchr (file, ';')) == NULL)
481 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 591 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
482 else 592 else
486 strncpy (f, file, len); 596 strncpy (f, file, len);
487 f[len] = '\0'; 597 f[len] = '\0';
488 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); 598 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
489 free( f ); 599 free( f );
490 } 600 }
491#endif 601# endif
492 } 602 }
493 603 resize_pixmap (); /* TODO: temporary fix - should be done by the caller! */
494 resize_pixmap ();
495} 604}
496 605
497#endif /* XPM_BACKGROUND */ 606# endif /* XPM_BACKGROUND */
607
608# ifdef ENABLE_TRANSPARENCY
609/* make_transparency_pixmap()
610 * Builds a pixmap sized the same as terminal window, with depth same as the root window
611 * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by
612 * our window.
613 */
614#if 0
615bool
616bgPixmap_t::make_transparency_pixmap()
617{
618 if (target == NULL)
619 return false;
620
621 int sx, sy;
622 Window cr;
623 XTranslateCoordinates (target->dpy, target->parent[0], target->display->root,
624 0, 0, &sx, &sy, &cr);
625
626 /* check if we are outside of the visible part of the virtual screen : */
627 if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0
628 || sx >= wrootattr.width || sy >= wrootattr.height )
629 return false ;
630
631 XWindowAttributes wattr, wrootattr;
632
633 XGetWindowAttributes (dpy, display->root, &wrootattr);
634
635 /*
636 * Make the frame window set by the window manager have
637 * the root background. Some window managers put multiple nested frame
638 * windows for each client, so we have to take care about that.
639 */
640 i = (xa[XA_XROOTPMAP_ID]
641 && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID],
642 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
643 &nitems, &bytes_after, &prop) == Success);
644
645 if (!i || prop == NULL)
646 i = (xa[XA_ESETROOT_PMAP_ID]
647 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
648 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
649 &nitems, &bytes_after, &prop) == Success);
650
651 if (!i || prop == NULL)
652 rootpixmap = None;
653
654}
655#endif /* 0 */
656# endif /* ENABLE_TRANSPARENCY */
657
658void
659bgPixmap_t::apply_background()
660{
661 if (target)
662 {
663 if (pixmap != None)
664 { /* set target's background to pixmap */
665# ifdef ENABLE_TRANSPARENCY
666 if (flags & bgPmap_Transparent)
667 {
668 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
669 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
670 if (target->scrollBar.win)
671 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
672 }
673 else
674# endif
675 {
676 /* force old pixmap dereference in case it was transparent before :*/
677 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]);
678 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
679 /* do we also need to set scrollbar's background here ? */
680 }
681 }
682 else
683 { /* set target background to a pixel */
684 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]);
685 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
686 /* do we also need to set scrollbar's background here ? */
687 }
688 /* don't want Expose on the parent */
689 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
690 /* do want Expose on the vt */
691 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
692 }
693}
498#endif /* HAVE_BG_PIXMAP */ 694#endif /* HAVE_BG_PIXMAP */
695
696
499 697
500#ifdef ENABLE_TRANSPARENCY 698#ifdef ENABLE_TRANSPARENCY
501#ifndef HAVE_AFTERIMAGE 699#ifndef HAVE_AFTERIMAGE
502/* taken from aterm-0.4.2 */ 700/* taken from aterm-0.4.2 */
503 701
743} 941}
744 942
745void 943void
746rxvt_term::check_our_parents_cb (time_watcher &w) 944rxvt_term::check_our_parents_cb (time_watcher &w)
747{ 945{
748 int i, pchanged, aformat, rootdepth; 946 int i, aformat, rootdepth;
749 unsigned long nitems, bytes_after; 947 unsigned long nitems, bytes_after;
750 Atom atype; 948 Atom atype;
751 unsigned char *prop = NULL; 949 unsigned char *prop = NULL;
752 Window root, oldp, *list; 950 Window root, oldp, *list;
753 Pixmap rootpixmap = None; 951 Pixmap rootpixmap = None;
754 XWindowAttributes wattr, wrootattr; 952 XWindowAttributes wattr, wrootattr;
755 int sx, sy; 953 int sx, sy;
756 Window cr; 954 Window cr;
757 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 955 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
758 956
759 pchanged = 0;
760
761 if (!option (Opt_transparent)) 957 if (!option (Opt_transparent))
762 return /*pchanged*/; /* Don't try any more */ 958 return; /* Don't try any more */
763 959
764#if 0 960#if 0
765 struct timeval stv; 961 struct timeval stv;
766 gettimeofday (&stv,NULL); 962 gettimeofday (&stv,NULL);
767#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ 963#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\
779 975
780 if (rootdepth != wattr.depth) 976 if (rootdepth != wattr.depth)
781 { 977 {
782 if (am_transparent) 978 if (am_transparent)
783 { 979 {
784 pchanged = 1;
785 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); 980 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
786 am_transparent = am_pixmap_trans = 0; 981 am_transparent = am_pixmap_trans = 0;
787 } 982 }
788 983
789 return /*pchanged*/; /* Don't try any more */ 984 return; /* Don't try any more */
790 } 985 }
791 986
792 /* Get all X ops out of the queue so that our information is up-to-date. */ 987 /* Get all X ops out of the queue so that our information is up-to-date. */
793 XSync (dpy, False); 988 XSync (dpy, False);
794 989
812 i = (xa[XA_ESETROOT_PMAP_ID] 1007 i = (xa[XA_ESETROOT_PMAP_ID]
813 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], 1008 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
814 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 1009 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
815 &nitems, &bytes_after, &prop) == Success); 1010 &nitems, &bytes_after, &prop) == Success);
816 1011
817 /* TODO: the below logic needs to be cleaned up */
818 if (!i || prop == NULL 1012 if (!i || prop == NULL)
819 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL
820#ifdef HAVE_AFTERIMAGE
821 && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL
822#endif
823 )
824 )
825 rootpixmap = None; 1013 rootpixmap = None;
826 else 1014 else
827 { 1015 {
828 int junk; 1016 int junk;
829 unsigned int ujunk; 1017 unsigned int ujunk;
933 { 1121 {
934 destroy_asimage (&back_im); 1122 destroy_asimage (&back_im);
935 back_im = tmp; 1123 back_im = tmp;
936 } 1124 }
937 } 1125 }
938 1126 /* TODO: temporary fix - redo the logic, so that same function can do both
939 if (bgPixmap.original_asim != NULL) 1127 transparency and non-transparency */
940 { 1128 bgPixmap.render_asim (back_im, tint);
941 ASImageLayer *layers = create_image_layers (2);
942 ASImage *merged_im = NULL;
943 int fore_w, fore_h;
944
945 layers[0].im = back_im;
946 layers[0].clip_width = szHint.width;
947 layers[0].clip_height = szHint.height;
948 layers[0].tint = tint;
949 layers[1].im = bgPixmap.original_asim;
950
951 fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100;
952 fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100;
953
954 if (fore_w != bgPixmap.original_asim->width
955 || fore_h != bgPixmap.original_asim->height)
956 {
957 layers[1].im = scale_asimage (asv,
958 bgPixmap.original_asim,
959 fore_w, fore_h,
960 ASA_ASImage, 100,
961 ASIMAGE_QUALITY_DEFAULT);
962 }
963 layers[1].clip_width = szHint.width;
964 layers[1].clip_height = szHint.height;
965
966 if (rs[Rs_blendtype])
967 {
968 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
969 if (layers[1].merge_scanlines == NULL)
970 layers[1].merge_scanlines = alphablend_scanlines;
971 }
972 PRINT_BACKGROUND_OP_TIME;
973 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height,
974 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
975 if (layers[1].im != bgPixmap.original_asim)
976 destroy_asimage (&(layers[1].im));
977 free (layers);
978
979 if (merged_im != NULL)
980 {
981 destroy_asimage (&back_im);
982 back_im = merged_im;
983 }
984 PRINT_BACKGROUND_OP_TIME;
985 }
986 else if (tint != TINT_LEAVE_SAME)
987 {
988 ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
989 if (tmp)
990 {
991 destroy_asimage (&back_im);
992 back_im = tmp;
993 }
994 PRINT_BACKGROUND_OP_TIME;
995 }
996 asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True);
997 destroy_asimage (&back_im); 1129 destroy_asimage (&back_im);
1130
998 } /* back_im != NULL */ 1131 } /* back_im != NULL */
999 else 1132 else
1000 success = False; 1133 success = False;
1001 } 1134 }
1002#else /* HAVE_AFTERIMAGE */ 1135#else /* HAVE_AFTERIMAGE */
1019#endif /* HAVE_AFTERIMAGE */ 1152#endif /* HAVE_AFTERIMAGE */
1020 PRINT_BACKGROUND_OP_TIME; 1153 PRINT_BACKGROUND_OP_TIME;
1021 1154
1022 if (gc != NULL) 1155 if (gc != NULL)
1023 XFreeGC (dpy, gc); 1156 XFreeGC (dpy, gc);
1024 1157
1158 bgPixmap.apply_background();
1025 if (!success) 1159 if (!success)
1026 {
1027 if (am_transparent && am_pixmap_trans)
1028 {
1029 pchanged = 1;
1030 if (bgPixmap.pixmap != None)
1031 {
1032 XFreePixmap (dpy, bgPixmap.pixmap);
1033 bgPixmap.pixmap = None;
1034 }
1035 }
1036
1037 am_pixmap_trans = 0; 1160 am_pixmap_trans = 0;
1038 }
1039 else 1161 else
1040 { 1162 {
1041 XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap);
1042 XClearWindow (dpy, parent[0]);
1043
1044 if (!am_transparent || !am_pixmap_trans)
1045 pchanged = 1;
1046
1047 am_transparent = am_pixmap_trans = 1; 1163 am_transparent = am_pixmap_trans = 1;
1048 } 1164 }
1049 } /* rootpixmap != None */ 1165 } /* rootpixmap != None */
1050 1166
1051 if (am_pixmap_trans) 1167 if (am_pixmap_trans)
1052 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
1053 else
1054 {
1055 unsigned int n;
1056 /*
1057 * InheritPixmap transparency
1058 */
1059 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1060 {
1061 oldp = parent[i];
1062 XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n);
1063 XFree (list);
1064
1065 if (parent[i] == display->root)
1066 {
1067 if (oldp != None)
1068 pchanged = 1;
1069
1070 break;
1071 }
1072
1073 if (oldp != parent[i])
1074 pchanged = 1;
1075 }
1076
1077 n = 0;
1078
1079 if (pchanged)
1080 for (; n < (unsigned int)i; n++)
1081 {
1082 XGetWindowAttributes (dpy, parent[n], &wattr);
1083
1084 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
1085 {
1086 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
1087 break;
1088 }
1089 }
1090
1091 if (n > (sizeof (parent) / sizeof (parent[0])))
1092 {
1093 XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]);
1094 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
1095 am_transparent = 0;
1096 /* XXX: also turn off Opt_transparent? */
1097 }
1098 else
1099 {
1100 for (n = 0; n < (unsigned int)i; n++)
1101 {
1102 XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative);
1103 XClearWindow (dpy, parent[n]);
1104 }
1105
1106 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
1107 am_transparent = 1;
1108 }
1109
1110 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1111 parent[i] = None;
1112 } 1168 {
1113
1114 if (scrollBar.win) 1169 if (scrollBar.win)
1115 { 1170 {
1116 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
1117 scrollBar.setIdle (); 1171 scrollBar.setIdle ();
1118 scrollbar_show (0); 1172 scrollbar_show (0);
1119 } 1173 }
1120 1174
1121 if (am_transparent) 1175 if (am_transparent)
1122 { 1176 {
1123 want_refresh = want_full_refresh = 1; 1177 want_refresh = want_full_refresh = 1;
1124 if (am_pixmap_trans) 1178 if (am_pixmap_trans)
1125 flush (); 1179 flush ();
1180 }
1126 } 1181 }
1127
1128// return pchanged;
1129} 1182}
1130#endif 1183#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines