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.60 by sasha, Mon Aug 6 22:42:05 2007 UTC vs.
Revision 1.64 by sasha, Thu Aug 9 22:08:21 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, 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::handle_geometry (const char *geom)
169{ 166{
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&(~bgPmap_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, "?")) 180 if (!strcmp (geom, "?"))
184 { 181 {
185#if 0 /* TODO: */ 182 if (target)
183 {
186 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 184 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
187 min (h_scale, 32767), min (v_scale, 32767), 185 min (h_scale, 32767), min (v_scale, 32767),
188 min (h_align, 32767), min (v_align, 32767)); 186 min (h_align, 32767), min (v_align, 32767));
189 process_xterm_seq (XTerm_title, str, CHAR_ST); 187 target->process_xterm_seq (XTerm_title, str, CHAR_ST);
190#endif 188 }
191 return false; 189 return false;
192 } 190 }
193 while (isspace(*geom)) ++geom; 191 while (isspace(*geom)) ++geom;
194 if ((p = strchr (geom, ';')) == NULL) 192 if ((p = strchr (geom, ';')) == NULL)
195 p = strchr (geom, '\0'); 193 p = strchr (geom, '\0');
267 w = h = bgPmap_defaultScale; 265 w = h = bgPmap_defaultScale;
268 } 266 }
269 else if (geom_flags & WidthValue) 267 else if (geom_flags & WidthValue)
270 { 268 {
271 if (!(geom_flags & HeightValue)) 269 if (!(geom_flags & HeightValue))
272 h = w; 270 h = w;
273 } 271 }
274 else 272 else
275 w = h; 273 w = h;
276 } 274 }
277 } /* done parsing geometry string */ 275 } /* done parsing geometry string */
278 else if (!(flags & bgPmap_geometrySet)) 276 else if (!(flags & bgPmap_geometrySet))
279 { /* default geometry - scaled and centered */ 277 { /* default geometry - scaled and centered */
280 x = y = bgPmap_defaultAlign; 278 x = y = bgPmap_defaultAlign;
281 w = h = bgPmap_defaultScale; 279 w = h = bgPmap_defaultScale;
282 } 280 }
283 281
284 if (!(flags & bgPmap_geometrySet)) 282 if (!(flags & bgPmap_geometrySet))
285 geom_flags |= WidthValue|HeightValue|XValue|YValue; 283 geom_flags |= WidthValue|HeightValue|XValue|YValue;
286 284
287 if (ops) 285 if (ops)
288 { 286 {
289 while (*ops) 287 while (*ops)
290 { 288 {
291 while (*ops == ':' || isspace(*ops)) ++ops; 289 while (*ops == ':' || isspace(*ops)) ++ops;
292#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)
293 if (CHECK_GEOM_OPS("tile")) 291 if (CHECK_GEOM_OPS("tile"))
294 { 292 {
295 w = h = 0; 293 w = h = 0;
296 geom_flags |= WidthValue|HeightValue; 294 geom_flags |= WidthValue|HeightValue;
297 } 295 }
330 { 328 {
331 w = h = 100; 329 w = h = 100;
332 x = y = 50; 330 x = y = 50;
333 geom_flags |= WidthValue|HeightValue|XValue|YValue; 331 geom_flags |= WidthValue|HeightValue|XValue|YValue;
334 } 332 }
335#undef CHECK_GEOM_OPS 333# undef CHECK_GEOM_OPS
336 while (*ops != ':' && *ops != '\0') ++ops; 334 while (*ops != ':' && *ops != '\0') ++ops;
337 } /* done parsing ops */ 335 } /* done parsing ops */
338 } 336 }
339 337
340 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 338 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w))
355//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 353//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
356// flags, h_scale, v_scale, h_align, v_align); 354// flags, h_scale, v_scale, h_align, v_align);
357 return (changed > 0); 355 return (changed > 0);
358} 356}
359 357
360#ifdef HAVE_AFTERIMAGE 358# ifdef HAVE_AFTERIMAGE
361bool 359bool
362bgPixmap_t::render_asim (rxvt_term *target, ASImage *background, ARGB32 background_tint) 360bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint)
363{ 361{
364 if (target == NULL) 362 if (target == NULL)
365 return false; 363 return false;
366 364
367 int target_width = (int)target->szHint.width; 365 int target_width = (int)target->szHint.width;
378 { 376 {
379 x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); 377 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); 378 y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height);
381 } 379 }
382 380
383 int dst_x, dst_y; 381 if (original_asim == NULL
384 int clip_width, clip_height; 382 || x >= target_width
385 383 || y >= target_height
386 make_clip_rectangle (x, w, target_width, dst_x, clip_width); 384 || (w > 0 && x + w <= 0)
387 make_clip_rectangle (y, h, target_height, dst_y, clip_height); 385 || (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 { 386 {
393 result = background;
394 dst_x = dst_y = 0;
395 if (background) 387 if (background)
396 { 388 {
397 new_pmap_width = clip_width = background->width; 389 new_pmap_width = background->width;
398 new_pmap_height = clip_height = background->height; 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 }
399 } 400 }
400 else 401 else
401 new_pmap_width = new_pmap_height = 0; 402 new_pmap_width = new_pmap_height = 0;
402 } 403 }
403 else 404 else
404 { 405 {
405 result = original_asim; 406 result = original_asim;
406 if ((w > 0 && w != original_asim->width) 407 if ((w > 0 && w != original_asim->width)
416 {/* if tiling - pixmap has to be sized exactly as the image */ 417 {/* if tiling - pixmap has to be sized exactly as the image */
417 if (h_scale == 0) 418 if (h_scale == 0)
418 new_pmap_width = result->width; 419 new_pmap_width = result->width;
419 if (v_scale == 0) 420 if (v_scale == 0)
420 new_pmap_height = result->height; 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 }
421 } 438 }
422 else 439 else
423 {/* if blending background and image - pixmap has to be sized same as target window */ 440 {/* if blending background and image - pixmap has to be sized same as target window */
424 ASImageLayer *layers = create_image_layers (2); 441 ASImageLayer *layers = create_image_layers (2);
425 ASImage *merged_im = NULL; 442 ASImage *merged_im = NULL;
429 layers[0].clip_height = target_height; 446 layers[0].clip_height = target_height;
430 layers[0].tint = background_tint; 447 layers[0].tint = background_tint;
431 layers[1].im = result; 448 layers[1].im = result;
432 if (w <= 0) 449 if (w <= 0)
433 {/* tile horizontally */ 450 {/* tile horizontally */
434 layers[1].dst_x = dst_x - (int)result->width; 451 while (x > 0) x -= (int)result->width;
452 layers[1].dst_x = x;
435 layers[1].clip_width = result->width; 453 layers[1].clip_width = result->width+target_width;
436 } 454 }
437 else 455 else
438 {/* clip horizontally */ 456 {/* clip horizontally */
439 layers[1].dst_x = dst_x; 457 layers[1].dst_x = x;
440 layers[1].clip_width = clip_width; 458 layers[1].clip_width = result->width;
441 } 459 }
442 if (h <= 0) 460 if (h <= 0)
443 { 461 {
444 layers[1].dst_y = dst_y - (int)result->height; 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;
445 layers[1].clip_height = result->height; 469 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 } 470 }
452 if (target->rs[Rs_blendtype]) 471 if (target->rs[Rs_blendtype])
453 { 472 {
454 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 473 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]);
455 if (layers[1].merge_scanlines == NULL) 474 if (layers[1].merge_scanlines == NULL)
460 if (tmp) 479 if (tmp)
461 { 480 {
462 if (result != original_asim) 481 if (result != original_asim)
463 destroy_asimage (&result); 482 destroy_asimage (&result);
464 result = tmp; 483 result = tmp;
465 dst_x = dst_y = 0;
466 clip_width = target_width;
467 clip_height = target_height;
468 } 484 }
469 free (layers); 485 free (layers);
470 } 486 }
471 } 487 }
472 488
497 } 513 }
498 /* fill with background color ( if result's not completely overlapping it)*/ 514 /* fill with background color ( if result's not completely overlapping it)*/
499 gcv.foreground = target->pix_colors[Color_bg]; 515 gcv.foreground = target->pix_colors[Color_bg];
500 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 516 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv);
501 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
502 if (dst_x > 0 || dst_y > 0 527 if (dst_x > 0 || dst_y > 0
503 || dst_x + clip_width < new_pmap_width 528 || dst_x + dst_width < new_pmap_width
504 || dst_y + clip_height < new_pmap_height) 529 || dst_y + dst_height < new_pmap_height)
505 { 530 {
506 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 531 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
507 } 532 }
533 }
534
508 /* put result on pixmap */ 535 /* put result on pixmap */
536 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); 537 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
510 538
511 /* set target's background to pixmap */ 539 if (result != background && result != original_asim)
512 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 540 destroy_asimage (&result);
513 541
514 XFreeGC (target->dpy, gc); 542 XFreeGC (target->dpy, gc);
515 } 543 if (background)
544 flags |= bgPmap_Transparent;
516 else 545 else
517 { 546 flags &= ~bgPmap_Transparent;
518 /* set target background to a pixel */
519 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
520 } 547 }
521 548
522 return true; 549 return true;
523} 550}
524#endif 551# endif /* HAVE_AFTERIMAGE */
525 552
526void 553void
527rxvt_term::resize_pixmap () 554rxvt_term::resize_pixmap ()
528{ 555{
529 XGCValues gcvalue; 556
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 557# ifdef ENABLE_TRANSPARENCY
547 if (option(Opt_transparent) && am_transparent) 558 if (option(Opt_transparent) && am_transparent)
548 { 559 {
549 /* we need to re-generate transparency pixmap in that case ! */ 560 /* we need to re-generate transparency pixmap in that case ! */
550 check_our_parents (); 561 check_our_parents ();
551 return; 562 return;
552 } 563 }
553#endif 564# 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 565# ifdef HAVE_AFTERIMAGE
571 if (w == 0) 566 bgPixmap.render_asim(NULL, TINT_LEAVE_SAME);
572 w = im->width; 567 bgPixmap.apply_background();
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 568# endif
604 if( bgPixmap.pixmap )
605 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
606
607 XFreeGC (dpy, gc);
608} 569}
609 570
610void 571void
611rxvt_term::set_bgPixmap (const char *file) 572rxvt_term::set_bgPixmap (const char *file)
612{ 573{
621 } 582 }
622 583
623 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 584 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
624 if (*file != '\0') 585 if (*file != '\0')
625 { 586 {
626#ifdef HAVE_AFTERIMAGE 587# ifdef HAVE_AFTERIMAGE
627 if (asimman == NULL) 588 if (asimman == NULL)
628 asimman = create_generic_imageman(rs[Rs_path]); 589 asimman = create_generic_imageman(rs[Rs_path]);
629 if ((f = strchr (file, ';')) == NULL) 590 if ((f = strchr (file, ';')) == NULL)
630 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 591 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
631 else 592 else
635 strncpy (f, file, len); 596 strncpy (f, file, len);
636 f[len] = '\0'; 597 f[len] = '\0';
637 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); 598 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
638 free( f ); 599 free( f );
639 } 600 }
640#endif 601# endif
641 } 602 }
642 603 resize_pixmap (); /* TODO: temporary fix - should be done by the caller! */
643 resize_pixmap ();
644} 604}
645 605
646#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 */
614bool
615bgPixmap_t::make_transparency_pixmap()
616{
617 if (target == NULL)
618 return false;
619
620 /* root dimentions may change from call to call - but Display structure should
621 * be always up-to-date, so let's use it :
622 */
623 Window root = target->display->root;
624 int screen = target->display->screen;
625 Display *dpy = target->dpy;
626 int root_width = DisplayWidth (dpy, screen);
627 int root_height = DisplayHeight (dpy, screen);
628 unsigned int root_pmap_width, root_pmap_height;
629 int window_width = target->szHint.width;
630 int window_height = target->szHint.height;
631 int sx, sy;
632
633 target->get_window_origin (sx, sy);
634
635 /* check if we are outside of the visible part of the virtual screen : */
636 if (sx + window_width <= 0 || sy + window_height <= 0
637 || sx >= root_width || sy >= root_height)
638 return false;
639
640 if (root_pixmap != None)
641 {/* we want to validate the pixmap and get it's size at the same time : */
642 int junk;
643 unsigned int ujunk;
644 /* root pixmap may be bad - allow a error */
645 target->allowedxerror = -1;
646 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk))
647 root_pixmap = None;
648 target->allowedxerror = 0;
649 }
650
651 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
652 GC gc = NULL;
653
654 if (tiled_root_pmap == None) /* something really bad happened - abort */
655 return false;
656
657 if (root_pixmap == None)
658 { /* use tricks to obtain the root background image :*/
659 /* we want to create Overrideredirect window overlapping out window
660 with background type of Parent Relative and then grab it */
661 XSetWindowAttributes attr;
662 Window src;
663 bool success = false;
664
665 attr.background_pixmap = ParentRelative;
666 attr.backing_store = Always;
667 attr.event_mask = ExposureMask;
668 attr.override_redirect = True;
669 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
670 CopyFromParent, CopyFromParent, CopyFromParent,
671 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
672 &attr);
673
674 if (src != None)
675 {
676 XEvent event;
677 int ev_count = 0;
678 XGrabServer (dpy);
679 XMapRaised (dpy, src);
680 XSync (dpy, False);
681 /* XSync should get window where it's properly exposed,
682 * but to be on the safe side - let's check for the actuall event to arrive : */
683 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
684 ++ev_count;
685 if (ev_count > 0);
686 { /* hooray! - we can grab the image! */
687 gc = XCreateGC (dpy, root, 0, NULL);
688 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
689 success = true;
690 }
691 XDestroyWindow (dpy, src);
692 XUngrabServer (dpy);
693 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
694 }
695 if (!success)
696 {
697 XFreePixmap (dpy, tiled_root_pmap);
698 tiled_root_pmap = None;
699 }
700 }
701 else
702 {/* strightforward pixmap copy */
703 XGCValues gcv;
704 gcv.tile = root_pixmap;
705 gcv.fill_style = FillTiled;
706 while (sx < 0) sx += (int)window_width;
707 while (sy < 0) sy += (int)window_height;
708 gcv.ts_x_origin = -sx;
709 gcv.ts_y_origin = -sy;
710 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
711 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
712 }
713
714 if (gc)
715 XFreeGC (dpy, gc);
716
717 if (tiled_root_pmap != None)
718 {
719 if (pixmap)
720 XFreePixmap (dpy, pixmap);
721 pixmap = tiled_root_pmap;
722 pmap_width = window_width;
723 pmap_height = window_height;
724 pmap_depth = root_depth;
725 }
726}
727
728# endif /* ENABLE_TRANSPARENCY */
729
730bool
731bgPixmap_t::set_target (rxvt_term *new_target)
732{
733 if (new_target)
734 if (target != new_target)
735 {
736 target = new_target;
737# ifdef ENABLE_TRANSPARENCY
738 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
739 root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
740 if (root_pixmap == None)
741 root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
742# endif
743 return true;
744 }
745 return false;
746}
747
748void
749bgPixmap_t::apply_background()
750{
751 if (target)
752 {
753 if (pixmap != None)
754 { /* set target's background to pixmap */
755# ifdef ENABLE_TRANSPARENCY
756 if (flags & bgPmap_Transparent)
757 {
758 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
759 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
760 if (target->scrollBar.win)
761 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
762 }
763 else
764# endif
765 {
766 /* force old pixmap dereference in case it was transparent before :*/
767 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]);
768 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
769 /* do we also need to set scrollbar's background here ? */
770 }
771 }
772 else
773 { /* set target background to a pixel */
774 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]);
775 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
776 /* do we also need to set scrollbar's background here ? */
777 }
778 /* don't want Expose on the parent */
779 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
780 /* do want Expose on the vt */
781 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
782 }
783}
647#endif /* HAVE_BG_PIXMAP */ 784#endif /* HAVE_BG_PIXMAP */
785
786
787void
788rxvt_term::get_window_origin (int &x, int &y)
789{
790 Window cr;
791 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
792}
793
794Pixmap
795rxvt_term::get_pixmap_property (int prop_id)
796{
797 if (prop_id > 0 && prop_id < NUM_XA)
798 if (xa[prop_id])
799 {
800 int aformat, rootdepth;
801 unsigned long nitems, bytes_after;
802 Atom atype;
803 unsigned char *prop = NULL;
804 int result = XGetWindowProperty (dpy, display->root, xa[prop_id],
805 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
806 &nitems, &bytes_after, &prop);
807 if (result == Success && prop && atype == XA_PIXMAP)
808 {
809 return *(Pixmap *)prop;
810 }
811 }
812 return None;
813}
814
648 815
649#ifdef ENABLE_TRANSPARENCY 816#ifdef ENABLE_TRANSPARENCY
650#ifndef HAVE_AFTERIMAGE 817#ifndef HAVE_AFTERIMAGE
651/* taken from aterm-0.4.2 */ 818/* taken from aterm-0.4.2 */
652 819
892} 1059}
893 1060
894void 1061void
895rxvt_term::check_our_parents_cb (time_watcher &w) 1062rxvt_term::check_our_parents_cb (time_watcher &w)
896{ 1063{
897 int i, pchanged, aformat, rootdepth; 1064 int i, aformat, rootdepth;
898 unsigned long nitems, bytes_after; 1065 unsigned long nitems, bytes_after;
899 Atom atype; 1066 Atom atype;
900 unsigned char *prop = NULL; 1067 unsigned char *prop = NULL;
901 Window root, oldp, *list; 1068 Window root, oldp, *list;
902 Pixmap rootpixmap = None; 1069 Pixmap rootpixmap = None;
903 XWindowAttributes wattr, wrootattr; 1070 XWindowAttributes wattr, wrootattr;
904 int sx, sy; 1071 int sx, sy;
905 Window cr; 1072 Window cr;
906 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 1073 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
907 1074
908 pchanged = 0;
909
910 if (!option (Opt_transparent)) 1075 if (!option (Opt_transparent))
911 return /*pchanged*/; /* Don't try any more */ 1076 return; /* Don't try any more */
912
913#if 0 1077#if 0
914 struct timeval stv; 1078 struct timeval stv;
915 gettimeofday (&stv,NULL); 1079 gettimeofday (&stv,NULL);
916#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ 1080#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__,\ 1081 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
928 1092
929 if (rootdepth != wattr.depth) 1093 if (rootdepth != wattr.depth)
930 { 1094 {
931 if (am_transparent) 1095 if (am_transparent)
932 { 1096 {
933 pchanged = 1;
934 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); 1097 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
935 am_transparent = am_pixmap_trans = 0; 1098 am_transparent = am_pixmap_trans = 0;
936 } 1099 }
937 1100
938 return /*pchanged*/; /* Don't try any more */ 1101 return; /* Don't try any more */
939 } 1102 }
940 1103
941 /* Get all X ops out of the queue so that our information is up-to-date. */ 1104 /* Get all X ops out of the queue so that our information is up-to-date. */
942 XSync (dpy, False); 1105 XSync (dpy, False);
943 1106
961 i = (xa[XA_ESETROOT_PMAP_ID] 1124 i = (xa[XA_ESETROOT_PMAP_ID]
962 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], 1125 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
963 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 1126 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
964 &nitems, &bytes_after, &prop) == Success); 1127 &nitems, &bytes_after, &prop) == Success);
965 1128
966 /* TODO: the below logic needs to be cleaned up */
967 if (!i || prop == NULL 1129 if (!i || prop == NULL)
968 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL
969#ifdef HAVE_AFTERIMAGE
970 && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL
971#endif
972 )
973 )
974 rootpixmap = None; 1130 rootpixmap = None;
975 else 1131 else
976 { 1132 {
977 int junk; 1133 int junk;
978 unsigned int ujunk; 1134 unsigned int ujunk;
1008 whole_tint = (IS_COMPONENT_WHOLESOME(c.r) 1164 whole_tint = (IS_COMPONENT_WHOLESOME(c.r)
1009 && IS_COMPONENT_WHOLESOME(c.g) 1165 && IS_COMPONENT_WHOLESOME(c.g)
1010 && IS_COMPONENT_WHOLESOME(c.b)); 1166 && IS_COMPONENT_WHOLESOME(c.b));
1011 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); 1167 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
1012#undef IS_COMPONENT_WHOLESOME 1168#undef IS_COMPONENT_WHOLESOME
1013 /* theer are no performance advantages to reusing same pixmap */
1014 if (bgPixmap.pixmap != None)
1015 XFreePixmap (dpy, bgPixmap.pixmap);
1016 bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth);
1017 bgPixmap.pmap_width = szHint.width;
1018 bgPixmap.pmap_height = szHint.height;
1019 bgPixmap.pmap_depth = rootdepth;
1020 1169
1021#if 0 /* TODO : identify cases where this will be detrimental to performance : */ 1170 bgPixmap.make_transparency_pixmap();
1022 /* we want to tile root pixmap into our own pixmap in this cases :
1023 * 1) rootpixmap does not cover our window entirely
1024 * 2) whole_tint - we can use server-side tinting or tinting disabled
1025 */
1026 if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height)
1027 {
1028 }
1029#endif
1030 gcvalue.tile = rootpixmap;
1031 gcvalue.fill_style = FillTiled;
1032 gcvalue.ts_x_origin = -sx;
1033 gcvalue.ts_y_origin = -sy;
1034 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue);
1035 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1036 1171
1037 if (whole_tint && !no_tint) 1172 if (whole_tint && !no_tint)
1038 { 1173 {
1039 /* In this case we can tint image server-side getting significant 1174 /* In this case we can tint image server-side getting significant
1040 * performance improvements, as we eliminate XImage transfer 1175 * performance improvements, as we eliminate XImage transfer
1041 */ 1176 */
1042 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]); 1177 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
1043 gcvalue.function = GXand; 1178 gcvalue.function = GXand;
1044 gcvalue.fill_style = FillSolid; 1179 gcvalue.fill_style = FillSolid;
1180 if (gc)
1045 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue); 1181 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
1182 else
1183 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcvalue);
1046 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height); 1184 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1047 } 1185 }
1048 success = True; 1186 success = True;
1049#ifdef HAVE_AFTERIMAGE 1187#ifdef HAVE_AFTERIMAGE
1050 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) 1188 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
1082 { 1220 {
1083 destroy_asimage (&back_im); 1221 destroy_asimage (&back_im);
1084 back_im = tmp; 1222 back_im = tmp;
1085 } 1223 }
1086 } 1224 }
1087 1225 /* TODO: temporary fix - redo the logic, so that same function can do both
1088 if (bgPixmap.original_asim != NULL) 1226 transparency and non-transparency */
1089 { 1227 bgPixmap.render_asim (back_im, tint);
1090 ASImageLayer *layers = create_image_layers (2);
1091 ASImage *merged_im = NULL;
1092 int fore_w, fore_h;
1093
1094 layers[0].im = back_im;
1095 layers[0].clip_width = szHint.width;
1096 layers[0].clip_height = szHint.height;
1097 layers[0].tint = tint;
1098 layers[1].im = bgPixmap.original_asim;
1099
1100 fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100;
1101 fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100;
1102
1103 if (fore_w != bgPixmap.original_asim->width
1104 || fore_h != bgPixmap.original_asim->height)
1105 {
1106 layers[1].im = scale_asimage (asv,
1107 bgPixmap.original_asim,
1108 fore_w, fore_h,
1109 ASA_ASImage, 100,
1110 ASIMAGE_QUALITY_DEFAULT);
1111 }
1112 layers[1].clip_width = szHint.width;
1113 layers[1].clip_height = szHint.height;
1114
1115 if (rs[Rs_blendtype])
1116 {
1117 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
1118 if (layers[1].merge_scanlines == NULL)
1119 layers[1].merge_scanlines = alphablend_scanlines;
1120 }
1121 PRINT_BACKGROUND_OP_TIME;
1122 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height,
1123 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
1124 if (layers[1].im != bgPixmap.original_asim)
1125 destroy_asimage (&(layers[1].im));
1126 free (layers);
1127
1128 if (merged_im != NULL)
1129 {
1130 destroy_asimage (&back_im);
1131 back_im = merged_im;
1132 }
1133 PRINT_BACKGROUND_OP_TIME;
1134 }
1135 else if (tint != TINT_LEAVE_SAME)
1136 {
1137 ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
1138 if (tmp)
1139 {
1140 destroy_asimage (&back_im);
1141 back_im = tmp;
1142 }
1143 PRINT_BACKGROUND_OP_TIME;
1144 }
1145 asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True);
1146 destroy_asimage (&back_im); 1228 destroy_asimage (&back_im);
1229
1147 } /* back_im != NULL */ 1230 } /* back_im != NULL */
1148 else 1231 else
1149 success = False; 1232 success = False;
1150 } 1233 }
1151#else /* HAVE_AFTERIMAGE */ 1234#else /* HAVE_AFTERIMAGE */
1168#endif /* HAVE_AFTERIMAGE */ 1251#endif /* HAVE_AFTERIMAGE */
1169 PRINT_BACKGROUND_OP_TIME; 1252 PRINT_BACKGROUND_OP_TIME;
1170 1253
1171 if (gc != NULL) 1254 if (gc != NULL)
1172 XFreeGC (dpy, gc); 1255 XFreeGC (dpy, gc);
1173 1256
1257 bgPixmap.apply_background();
1174 if (!success) 1258 if (!success)
1175 {
1176 if (am_transparent && am_pixmap_trans)
1177 {
1178 pchanged = 1;
1179 if (bgPixmap.pixmap != None)
1180 {
1181 XFreePixmap (dpy, bgPixmap.pixmap);
1182 bgPixmap.pixmap = None;
1183 }
1184 }
1185
1186 am_pixmap_trans = 0; 1259 am_pixmap_trans = 0;
1187 }
1188 else 1260 else
1189 { 1261 {
1190 XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap);
1191 XClearWindow (dpy, parent[0]);
1192
1193 if (!am_transparent || !am_pixmap_trans)
1194 pchanged = 1;
1195
1196 am_transparent = am_pixmap_trans = 1; 1262 am_transparent = am_pixmap_trans = 1;
1197 } 1263 }
1198 } /* rootpixmap != None */ 1264 } /* rootpixmap != None */
1199 1265
1200 if (am_pixmap_trans) 1266 if (am_pixmap_trans)
1201 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
1202 else
1203 {
1204 unsigned int n;
1205 /*
1206 * InheritPixmap transparency
1207 */
1208 for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1209 {
1210 oldp = parent[i];
1211 XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n);
1212 XFree (list);
1213
1214 if (parent[i] == display->root)
1215 {
1216 if (oldp != None)
1217 pchanged = 1;
1218
1219 break;
1220 }
1221
1222 if (oldp != parent[i])
1223 pchanged = 1;
1224 }
1225
1226 n = 0;
1227
1228 if (pchanged)
1229 for (; n < (unsigned int)i; n++)
1230 {
1231 XGetWindowAttributes (dpy, parent[n], &wattr);
1232
1233 if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
1234 {
1235 n = (int) (sizeof (parent) / sizeof (Window)) + 1;
1236 break;
1237 }
1238 }
1239
1240 if (n > (sizeof (parent) / sizeof (parent[0])))
1241 {
1242 XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]);
1243 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
1244 am_transparent = 0;
1245 /* XXX: also turn off Opt_transparent? */
1246 }
1247 else
1248 {
1249 for (n = 0; n < (unsigned int)i; n++)
1250 {
1251 XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative);
1252 XClearWindow (dpy, parent[n]);
1253 }
1254
1255 XSetWindowBackgroundPixmap (dpy, vt, ParentRelative);
1256 am_transparent = 1;
1257 }
1258
1259 for (; i < (int) (sizeof (parent) / sizeof (Window)); i++)
1260 parent[i] = None;
1261 } 1267 {
1262
1263 if (scrollBar.win) 1268 if (scrollBar.win)
1264 { 1269 {
1265 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
1266 scrollBar.setIdle (); 1270 scrollBar.setIdle ();
1267 scrollbar_show (0); 1271 scrollbar_show (0);
1268 } 1272 }
1269 1273
1270 if (am_transparent) 1274 if (am_transparent)
1271 { 1275 {
1272 want_refresh = want_full_refresh = 1; 1276 want_refresh = want_full_refresh = 1;
1273 if (am_pixmap_trans) 1277 if (am_pixmap_trans)
1274 flush (); 1278 flush ();
1279 }
1275 } 1280 }
1276
1277// return pchanged;
1278} 1281}
1279#endif 1282#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines