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.65 by sasha, Fri Aug 10 22:10:36 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 */
683bool
684bgPixmap_t::make_transparency_pixmap ()
685{
686 if (target == NULL)
687 return false;
688
689 /* root dimentions may change from call to call - but Display structure should
690 * be always up-to-date, so let's use it :
691 */
692 Window root = target->display->root;
693 int screen = target->display->screen;
694 Display *dpy = target->dpy;
695 int root_width = DisplayWidth (dpy, screen);
696 int root_height = DisplayHeight (dpy, screen);
697 unsigned int root_pmap_width, root_pmap_height;
698 int window_width = target->szHint.width;
699 int window_height = target->szHint.height;
700 int sx, sy;
701 XGCValues gcv;
702
703 target->get_window_origin (sx, sy);
704
705 /* check if we are outside of the visible part of the virtual screen : */
706 if (sx + window_width <= 0 || sy + window_height <= 0
707 || sx >= root_width || sy >= root_height)
708 return false;
709
710 if (root_pixmap != None)
711 {/* we want to validate the pixmap and get it's size at the same time : */
712 int junk;
713 unsigned int ujunk;
714 /* root pixmap may be bad - allow a error */
715 target->allowedxerror = -1;
716 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk))
717 root_pixmap = None;
718 target->allowedxerror = 0;
719 }
720
721 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth);
722 GC gc = NULL;
723
724 if (tiled_root_pmap == None) /* something really bad happened - abort */
725 return false;
726
727 if (root_pixmap == None)
728 { /* use tricks to obtain the root background image :*/
729 /* we want to create Overrideredirect window overlapping out window
730 with background type of Parent Relative and then grab it */
731 XSetWindowAttributes attr;
732 Window src;
733 bool success = false;
734
735 attr.background_pixmap = ParentRelative;
736 attr.backing_store = Always;
737 attr.event_mask = ExposureMask;
738 attr.override_redirect = True;
739 src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0,
740 CopyFromParent, CopyFromParent, CopyFromParent,
741 CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask,
742 &attr);
743
744 if (src != None)
745 {
746 XEvent event;
747 int ev_count = 0;
748 XGrabServer (dpy);
749 XMapRaised (dpy, src);
750 XSync (dpy, False);
751 /* XSync should get window where it's properly exposed,
752 * but to be on the safe side - let's check for the actuall event to arrive : */
753 while (XCheckWindowEvent (dpy, src, ExposureMask, &event))
754 ++ev_count;
755 if (ev_count > 0);
756 { /* hooray! - we can grab the image! */
757 gc = XCreateGC (dpy, root, 0, NULL);
758 XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0);
759 success = true;
760 }
761 XDestroyWindow (dpy, src);
762 XUngrabServer (dpy);
763 //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count);
764 }
765 if (!success)
766 {
767 XFreePixmap (dpy, tiled_root_pmap);
768 tiled_root_pmap = None;
769 }
770 }
771 else
772 {/* strightforward pixmap copy */
773 gcv.tile = root_pixmap;
774 gcv.fill_style = FillTiled;
775 while (sx < 0) sx += (int)window_width;
776 while (sy < 0) sy += (int)window_height;
777 gcv.ts_x_origin = -sx;
778 gcv.ts_y_origin = -sy;
779 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
780 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
781 }
782
783 if (tiled_root_pmap != None)
784 {
785 if (flags & tintNeeded)
786 {
787 if ((flags & tintServerSide)
788 && h_blurRadius <= 1 && v_blurRadius <= 1
789# ifdef HAVE_AFTERIMAGE
790 && original_asim == NULL
791# endif
792 )
793 { /* In this case we can tint image server-side getting significant
794 * performance improvements, as we eliminate XImage transfer
795 */
796 gcv.foreground = Pixel (tint);
797 gcv.function = GXand;
798 gcv.fill_style = FillSolid;
799 if (gc)
800 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv);
801 else
802 gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv);
803 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
804 }
805 }
806 if (pixmap)
807 XFreePixmap (dpy, pixmap);
808 pixmap = tiled_root_pmap;
809 pmap_width = window_width;
810 pmap_height = window_height;
811 pmap_depth = root_depth;
812 }
813
814 if (gc)
815 XFreeGC (dpy, gc);
816}
817
818bool
819bgPixmap_t::set_root_pixmap ()
820{
821 Pixmap new_root_pixmap = None;
822
823 new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
824 if (new_root_pixmap == None)
825 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
826
827 if (new_root_pixmap != root_pixmap)
828 {
829 root_pixmap = new_root_pixmap;
830 return true;
831 }
832 return false;
833}
834# endif /* ENABLE_TRANSPARENCY */
835
836bool
837bgPixmap_t::render_background ()
838{
839 /* TODO: temporary implementation - need to move check_parents stuff in here */
840# ifdef ENABLE_TRANSPARENCY
841 if (flags & isTransparent)
842 {
843 /* we need to re-generate transparency pixmap in that case ! */
844 target->check_our_parents ();
845 return true;
846 }
847# endif
848# ifdef HAVE_AFTERIMAGE
849 render_asim (NULL, TINT_LEAVE_SAME);
850 apply_background ();
851 return true;
852# endif
853 return false;
854}
855
856bool
857bgPixmap_t::set_target (rxvt_term *new_target)
858{
859 if (new_target)
860 if (target != new_target)
861 {
862 target = new_target;
863# ifdef ENABLE_TRANSPARENCY
864 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
865# endif
866 return true;
867 }
868 return false;
869}
870
871void
872bgPixmap_t::apply_background()
873{
874 if (target)
875 {
876 if (pixmap != None)
877 { /* set target's background to pixmap */
878# ifdef ENABLE_TRANSPARENCY
879 if (flags & isTransparent)
880 {
881 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
882 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
883 if (target->scrollBar.win)
884 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
885 }
886 else
887# endif
888 {
889 /* force old pixmap dereference in case it was transparent before :*/
890 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]);
891 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
892 /* do we also need to set scrollbar's background here ? */
893 }
894 }
895 else
896 { /* set target background to a pixel */
897 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]);
898 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
899 /* do we also need to set scrollbar's background here ? */
900 }
901 /* don't want Expose on the parent */
902 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False);
903 /* do want Expose on the vt */
904 XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True);
905 }
906}
647#endif /* HAVE_BG_PIXMAP */ 907#endif /* HAVE_BG_PIXMAP */
908
909
910void
911rxvt_term::get_window_origin (int &x, int &y)
912{
913 Window cr;
914 XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr);
915}
916
917Pixmap
918rxvt_term::get_pixmap_property (int prop_id)
919{
920 if (prop_id > 0 && prop_id < NUM_XA)
921 if (xa[prop_id])
922 {
923 int aformat, rootdepth;
924 unsigned long nitems, bytes_after;
925 Atom atype;
926 unsigned char *prop = NULL;
927 int result = XGetWindowProperty (dpy, display->root, xa[prop_id],
928 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
929 &nitems, &bytes_after, &prop);
930 if (result == Success && prop && atype == XA_PIXMAP)
931 {
932 return *(Pixmap *)prop;
933 }
934 }
935 return None;
936}
937
648 938
649#ifdef ENABLE_TRANSPARENCY 939#ifdef ENABLE_TRANSPARENCY
650#ifndef HAVE_AFTERIMAGE 940#ifndef HAVE_AFTERIMAGE
651/* taken from aterm-0.4.2 */ 941/* taken from aterm-0.4.2 */
652 942
892} 1182}
893 1183
894void 1184void
895rxvt_term::check_our_parents_cb (time_watcher &w) 1185rxvt_term::check_our_parents_cb (time_watcher &w)
896{ 1186{
897 int i, pchanged, aformat, rootdepth; 1187 int i, aformat, rootdepth;
898 unsigned long nitems, bytes_after; 1188 unsigned long nitems, bytes_after;
899 Atom atype; 1189 Atom atype;
900 unsigned char *prop = NULL; 1190 unsigned char *prop = NULL;
901 Window root, oldp, *list; 1191 Window root, oldp, *list;
902 Pixmap rootpixmap = None; 1192 Pixmap rootpixmap = None;
903 XWindowAttributes wattr, wrootattr; 1193 XWindowAttributes wattr, wrootattr;
904 int sx, sy; 1194 int sx, sy;
905 Window cr; 1195 Window cr;
906 unsigned int rootpixmap_w = 0, rootpixmap_h = 0; 1196 unsigned int rootpixmap_w = 0, rootpixmap_h = 0;
907 1197
908 pchanged = 0;
909
910 if (!option (Opt_transparent)) 1198 if (!option (Opt_transparent))
911 return /*pchanged*/; /* Don't try any more */ 1199 return; /* Don't try any more */
912
913#if 0 1200#if 0
914 struct timeval stv; 1201 struct timeval stv;
915 gettimeofday (&stv,NULL); 1202 gettimeofday (&stv,NULL);
916#define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ 1203#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__,\ 1204 fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\
928 1215
929 if (rootdepth != wattr.depth) 1216 if (rootdepth != wattr.depth)
930 { 1217 {
931 if (am_transparent) 1218 if (am_transparent)
932 { 1219 {
933 pchanged = 1;
934 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); 1220 XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]);
935 am_transparent = am_pixmap_trans = 0; 1221 am_transparent = am_pixmap_trans = 0;
936 } 1222 }
937 1223
938 return /*pchanged*/; /* Don't try any more */ 1224 return; /* Don't try any more */
939 } 1225 }
940 1226
941 /* Get all X ops out of the queue so that our information is up-to-date. */ 1227 /* Get all X ops out of the queue so that our information is up-to-date. */
942 XSync (dpy, False); 1228 XSync (dpy, False);
943 1229
961 i = (xa[XA_ESETROOT_PMAP_ID] 1247 i = (xa[XA_ESETROOT_PMAP_ID]
962 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], 1248 && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID],
963 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 1249 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
964 &nitems, &bytes_after, &prop) == Success); 1250 &nitems, &bytes_after, &prop) == Success);
965 1251
966 /* TODO: the below logic needs to be cleaned up */
967 if (!i || prop == NULL 1252 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; 1253 rootpixmap = None;
975 else 1254 else
976 { 1255 {
977 int junk; 1256 int junk;
978 unsigned int ujunk; 1257 unsigned int ujunk;
1008 whole_tint = (IS_COMPONENT_WHOLESOME(c.r) 1287 whole_tint = (IS_COMPONENT_WHOLESOME(c.r)
1009 && IS_COMPONENT_WHOLESOME(c.g) 1288 && IS_COMPONENT_WHOLESOME(c.g)
1010 && IS_COMPONENT_WHOLESOME(c.b)); 1289 && IS_COMPONENT_WHOLESOME(c.b));
1011 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); 1290 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
1012#undef IS_COMPONENT_WHOLESOME 1291#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 1292
1021#if 0 /* TODO : identify cases where this will be detrimental to performance : */ 1293 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 1294
1037 if (whole_tint && !no_tint) 1295 if (whole_tint && !no_tint)
1038 { 1296 {
1039 /* In this case we can tint image server-side getting significant
1040 * performance improvements, as we eliminate XImage transfer
1041 */
1042 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
1043 gcvalue.function = GXand;
1044 gcvalue.fill_style = FillSolid;
1045 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
1046 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
1047 } 1297 }
1048 success = True; 1298 success = True;
1049#ifdef HAVE_AFTERIMAGE 1299#ifdef HAVE_AFTERIMAGE
1050 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) 1300 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
1051 { 1301 {
1082 { 1332 {
1083 destroy_asimage (&back_im); 1333 destroy_asimage (&back_im);
1084 back_im = tmp; 1334 back_im = tmp;
1085 } 1335 }
1086 } 1336 }
1087 1337 /* TODO: temporary fix - redo the logic, so that same function can do both
1088 if (bgPixmap.original_asim != NULL) 1338 transparency and non-transparency */
1089 { 1339 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); 1340 destroy_asimage (&back_im);
1341
1147 } /* back_im != NULL */ 1342 } /* back_im != NULL */
1148 else 1343 else
1149 success = False; 1344 success = False;
1150 } 1345 }
1151#else /* HAVE_AFTERIMAGE */ 1346#else /* HAVE_AFTERIMAGE */
1168#endif /* HAVE_AFTERIMAGE */ 1363#endif /* HAVE_AFTERIMAGE */
1169 PRINT_BACKGROUND_OP_TIME; 1364 PRINT_BACKGROUND_OP_TIME;
1170 1365
1171 if (gc != NULL) 1366 if (gc != NULL)
1172 XFreeGC (dpy, gc); 1367 XFreeGC (dpy, gc);
1173 1368
1369 bgPixmap.apply_background();
1174 if (!success) 1370 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; 1371 am_pixmap_trans = 0;
1187 }
1188 else 1372 else
1189 { 1373 {
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; 1374 am_transparent = am_pixmap_trans = 1;
1197 } 1375 }
1198 } /* rootpixmap != None */ 1376 } /* rootpixmap != None */
1199 1377
1200 if (am_pixmap_trans) 1378 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 } 1379 {
1262
1263 if (scrollBar.win) 1380 if (scrollBar.win)
1264 { 1381 {
1265 XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative);
1266 scrollBar.setIdle (); 1382 scrollBar.setIdle ();
1267 scrollbar_show (0); 1383 scrollbar_show (0);
1268 } 1384 }
1269 1385
1270 if (am_transparent) 1386 if (am_transparent)
1271 { 1387 {
1272 want_refresh = want_full_refresh = 1; 1388 want_refresh = want_full_refresh = 1;
1273 if (am_pixmap_trans) 1389 if (am_pixmap_trans)
1274 flush (); 1390 flush ();
1391 }
1275 } 1392 }
1276
1277// return pchanged;
1278} 1393}
1279#endif 1394#endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines