ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.132 by sf-exg, Mon Jan 10 20:46:20 2011 UTC vs.
Revision 1.144 by sf-exg, Fri Jan 28 00:20:47 2011 UTC

30# include <X11/extensions/Xrender.h> 30# include <X11/extensions/Xrender.h>
31#endif 31#endif
32 32
33#ifndef FilterConvolution 33#ifndef FilterConvolution
34#define FilterConvolution "convolution" 34#define FilterConvolution "convolution"
35#endif
36
37#define DO_TIMING_TEST 0
38
39#if DO_TIMING_TEST
40# include <sys/time.h>
41#define TIMING_TEST_START(id) \
42 struct timeval timing_test_##id##_stv; \
43 gettimeofday (&timing_test_##id##_stv, NULL);
44
45#define TIMING_TEST_PRINT_RESULT(id) \
46 do { \
47 struct timeval tv; \
48 gettimeofday (&tv, NULL); \
49 tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \
50 fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \
51 tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \
52 } while (0)
53
54#else
55#define TIMING_TEST_START(id) do {} while (0)
56#define TIMING_TEST_PRINT_RESULT(id) do {} while (0)
57#endif 35#endif
58 36
59/* 37/*
60 * Pixmap geometry string interpretation : 38 * Pixmap geometry string interpretation :
61 * Each geometry string contains zero or one scale/position 39 * Each geometry string contains zero or one scale/position
81 * scale Scale both up and down 59 * scale Scale both up and down
82 * auto Same as 100x100+50+50 60 * auto Same as 100x100+50+50
83 */ 61 */
84 62
85#ifdef HAVE_BG_PIXMAP 63#ifdef HAVE_BG_PIXMAP
86bgPixmap_t::bgPixmap_t ()
87{
88 // this is basically redundant as bgPixmap_t is only used in
89 // zero_initialised-derived structs
90#ifdef HAVE_AFTERIMAGE
91 original_asim = NULL;
92#endif
93#ifdef HAVE_PIXBUF
94 pixbuf = NULL;
95#endif
96#ifdef BG_IMAGE_FROM_FILE
97 have_image = false;
98 h_scale = v_scale = 0;
99 h_align = v_align = 0;
100#endif
101#ifdef ENABLE_TRANSPARENCY
102 shade = 100;
103#endif
104 flags = 0;
105 pixmap = None;
106 valid_since = invalid_since = 0;
107 target = 0;
108 target_x = target_y = 0;
109}
110
111void 64void
112bgPixmap_t::destroy () 65rxvt_term::bg_destroy ()
113{ 66{
114#ifdef HAVE_AFTERIMAGE 67#ifdef HAVE_AFTERIMAGE
115 if (original_asim) 68 if (original_asim)
116 safe_asimage_destroy (original_asim); 69 safe_asimage_destroy (original_asim);
117#endif 70#endif
119#ifdef HAVE_PIXBUF 72#ifdef HAVE_PIXBUF
120 if (pixbuf) 73 if (pixbuf)
121 g_object_unref (pixbuf); 74 g_object_unref (pixbuf);
122#endif 75#endif
123 76
124 if (pixmap && target) 77 if (bg_pixmap)
125 XFreePixmap (target->dpy, pixmap); 78 XFreePixmap (dpy, bg_pixmap);
126} 79}
127 80
128bool 81bool
129bgPixmap_t::set_position (int x, int y) 82rxvt_term::bg_set_position (int x, int y)
130{ 83{
131 84
132 if (target_x != x 85 if (target_x != x
133 || target_y != y) 86 || target_y != y)
134 { 87 {
138 } 91 }
139 return false; 92 return false;
140} 93}
141 94
142bool 95bool
143bgPixmap_t::window_size_sensitive () 96rxvt_term::bg_window_size_sensitive ()
144{ 97{
145# ifdef ENABLE_TRANSPARENCY 98# ifdef ENABLE_TRANSPARENCY
146 if (flags & isTransparent) 99 if (bg_flags & BG_IS_TRANSPARENT)
147 return true; 100 return true;
148# endif 101# endif
149 102
150# ifdef BG_IMAGE_FROM_FILE 103# ifdef BG_IMAGE_FROM_FILE
151 if (have_image) 104 if (bg_flags & BG_IS_FROM_FILE)
152 { 105 {
153 if (flags & sizeSensitive) 106 if (bg_flags & BG_IS_SIZE_SENSITIVE)
154 return true; 107 return true;
155 } 108 }
156# endif 109# endif
157 110
158 return false; 111 return false;
159} 112}
160 113
161bool 114bool
162bgPixmap_t::window_position_sensitive () 115rxvt_term::bg_window_position_sensitive ()
163{ 116{
164# ifdef ENABLE_TRANSPARENCY 117# ifdef ENABLE_TRANSPARENCY
165 if (flags & isTransparent) 118 if (bg_flags & BG_IS_TRANSPARENT)
166 return true; 119 return true;
167# endif 120# endif
168 121
169# ifdef BG_IMAGE_FROM_FILE 122# ifdef BG_IMAGE_FROM_FILE
170 if (have_image) 123 if (bg_flags & BG_IS_FROM_FILE)
171 { 124 {
172 if (flags & rootAlign) 125 if (bg_flags & BG_ROOT_ALIGN)
173 return true; 126 return true;
174 } 127 }
175# endif 128# endif
176 129
177 return false; 130 return false;
244 dst_size = target_size - dst_pos; 197 dst_size = target_size - dst_pos;
245 return src_pos; 198 return src_pos;
246} 199}
247 200
248bool 201bool
249bgPixmap_t::set_geometry (const char *geom, bool update) 202rxvt_term::bg_set_geometry (const char *geom, bool update)
250{ 203{
251 bool changed = false; 204 bool changed = false;
252 int geom_flags = 0; 205 int geom_flags = 0;
253 int x = 0, y = 0; 206 int x = 0, y = 0;
254 unsigned int w = 0, h = 0; 207 unsigned int w = 0, h = 0;
255 unsigned int n; 208 unsigned int n;
256 unsigned long new_flags = (flags & (~geometryFlags)); 209 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS));
257 const char *ops; 210 const char *ops;
258# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
259 211
260 if (geom == NULL) 212 if (geom == NULL)
261 return false; 213 return false;
262 214
263 char str[MAXLEN_GEOM]; 215 char str[256];
264 216
265 ops = strchr (geom, ':'); 217 ops = strchr (geom, ':');
266 if (ops == NULL) 218 if (ops == NULL)
267 n = strlen (geom); 219 n = strlen (geom);
268 else 220 else
269 n = ops - geom; 221 n = ops - geom;
270 222
271 if (n >= MAXLEN_GEOM) 223 if (n >= sizeof (str))
272 return false; 224 return false;
273 225
274 memcpy (str, geom, n); 226 memcpy (str, geom, n);
275 str[n] = '\0'; 227 str[n] = '\0';
276 rxvt_strtrim (str); 228 rxvt_strtrim (str);
302 { 254 {
303 char **arr = rxvt_strsplit (':', ops + 1); 255 char **arr = rxvt_strsplit (':', ops + 1);
304 256
305 for (int i = 0; arr[i]; i++) 257 for (int i = 0; arr[i]; i++)
306 { 258 {
307# define CHECK_GEOM_OPS(op_str) (strcasecmp (arr[i], (op_str)) == 0) 259 if (!strcasecmp (arr[i], "tile"))
308 if (CHECK_GEOM_OPS ("tile"))
309 { 260 {
310 w = h = noScale; 261 w = h = noScale;
311 geom_flags |= WidthValue|HeightValue; 262 geom_flags |= WidthValue|HeightValue;
312 } 263 }
313 else if (CHECK_GEOM_OPS ("propscale")) 264 else if (!strcasecmp (arr[i], "propscale"))
314 {
315 new_flags |= propScale;
316 } 265 {
317 else if (CHECK_GEOM_OPS ("hscale")) 266 new_flags |= BG_PROP_SCALE;
267 }
268 else if (!strcasecmp (arr[i], "hscale"))
318 { 269 {
319 if (w == 0) w = windowScale; 270 if (w == 0) w = windowScale;
320 271
321 h = noScale; 272 h = noScale;
322 geom_flags |= WidthValue|HeightValue; 273 geom_flags |= WidthValue|HeightValue;
323 } 274 }
324 else if (CHECK_GEOM_OPS ("vscale")) 275 else if (!strcasecmp (arr[i], "vscale"))
325 { 276 {
326 if (h == 0) h = windowScale; 277 if (h == 0) h = windowScale;
327 278
328 w = noScale; 279 w = noScale;
329 geom_flags |= WidthValue|HeightValue; 280 geom_flags |= WidthValue|HeightValue;
330 } 281 }
331 else if (CHECK_GEOM_OPS ("scale")) 282 else if (!strcasecmp (arr[i], "scale"))
332 { 283 {
333 if (h == 0) h = windowScale; 284 if (h == 0) h = windowScale;
334 if (w == 0) w = windowScale; 285 if (w == 0) w = windowScale;
335 286
336 geom_flags |= WidthValue|HeightValue; 287 geom_flags |= WidthValue|HeightValue;
337 } 288 }
338 else if (CHECK_GEOM_OPS ("auto")) 289 else if (!strcasecmp (arr[i], "auto"))
339 { 290 {
340 w = h = windowScale; 291 w = h = windowScale;
341 x = y = centerAlign; 292 x = y = centerAlign;
342 geom_flags |= WidthValue|HeightValue|XValue|YValue; 293 geom_flags |= WidthValue|HeightValue|XValue|YValue;
343 } 294 }
344 else if (CHECK_GEOM_OPS ("root")) 295 else if (!strcasecmp (arr[i], "root"))
345 { 296 {
346 new_flags |= rootAlign; 297 new_flags |= BG_ROOT_ALIGN;
347 w = h = noScale; 298 w = h = noScale;
348 geom_flags |= WidthValue|HeightValue; 299 geom_flags |= WidthValue|HeightValue;
349 } 300 }
350# undef CHECK_GEOM_OPS
351 } /* done parsing ops */ 301 } /* done parsing ops */
352 302
353 rxvt_free_strsplit (arr); 303 rxvt_free_strsplit (arr);
354 } 304 }
355 305
356 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 306 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
357 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 307 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
358 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 308 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
359 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 309 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
360 310
361 if (new_flags != flags) 311 if (new_flags != bg_flags)
362 { 312 {
363 flags = new_flags; 313 bg_flags = new_flags;
364 changed = true; 314 changed = true;
365 } 315 }
366 316
367 return changed; 317 return changed;
368} 318}
369 319
370void 320void
371bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 321rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
372{ 322{
373 int target_width = target->szHint.width; 323 int target_width = szHint.width;
374 int target_height = target->szHint.height; 324 int target_height = szHint.height;
375 325
376 if (flags & propScale) 326 if (bg_flags & BG_PROP_SCALE)
377 { 327 {
378 float scale = (float)target_width / image_width; 328 float scale = (float)target_width / image_width;
379 min_it (scale, (float)target_height / image_height); 329 min_it (scale, (float)target_height / image_height);
380 w = image_width * scale + 0.5; 330 w = image_width * scale + 0.5;
381 h = image_height * scale + 0.5; 331 h = image_height * scale + 0.5;
387 } 337 }
388 338
389 if (!w) w = image_width; 339 if (!w) w = image_width;
390 if (!h) h = image_height; 340 if (!h) h = image_height;
391 341
392 if (flags & rootAlign) 342 if (bg_flags & BG_ROOT_ALIGN)
393 { 343 {
394 x = -target_x; 344 x = -target_x;
395 y = -target_y; 345 y = -target_y;
396 } 346 }
397 else 347 else
398 { 348 {
399 x = make_align_position (h_align, target_width, w); 349 x = make_align_position (h_align, target_width, w);
400 y = make_align_position (v_align, target_height, h); 350 y = make_align_position (v_align, target_height, h);
401 } 351 }
402 352
403 flags &= ~sizeSensitive; 353 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
404 if ((flags & propScale) || h_scale || v_scale 354 if ((bg_flags & BG_PROP_SCALE) || h_scale || v_scale
405 || (!(flags & rootAlign) && (h_align || v_align)) 355 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
406 || w > target_width || h > target_height) 356 || w > target_width || h > target_height)
407 flags |= sizeSensitive; 357 bg_flags |= BG_IS_SIZE_SENSITIVE;
408} 358}
409 359
410# ifdef HAVE_AFTERIMAGE 360# ifdef HAVE_AFTERIMAGE
411bool 361bool
412bgPixmap_t::render_image (unsigned long background_flags) 362rxvt_term::render_image (unsigned long tr_flags)
413{ 363{
414 if (target == NULL)
415 return false;
416
417 target->init_asv (); 364 init_asv ();
418 365
419 ASImage *background = NULL; 366 ASImage *background = NULL;
420 ARGB32 background_tint = TINT_LEAVE_SAME; 367 ARGB32 background_tint = TINT_LEAVE_SAME;
421 368
422# ifdef ENABLE_TRANSPARENCY 369# ifdef ENABLE_TRANSPARENCY
423 if (background_flags) 370 if (tr_flags)
424 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 371 background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100);
425 372
426 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 373 if (tr_flags & BG_NEEDS_TINT)
427 { 374 {
428 ShadingInfo as_shade; 375 ShadingInfo as_shade;
429 as_shade.shading = shade; 376 as_shade.shading = shade;
430 377
431 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 378 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
432 if (flags & tintSet) 379 if (bg_flags & BG_TINT_SET)
433 tint.get (c); 380 tint.get (c);
434 as_shade.tintColor.red = c.r; 381 as_shade.tintColor.red = c.r;
435 as_shade.tintColor.green = c.g; 382 as_shade.tintColor.green = c.g;
436 as_shade.tintColor.blue = c.b; 383 as_shade.tintColor.blue = c.b;
437 384
438 background_tint = shading2tint32 (&as_shade); 385 background_tint = shading2tint32 (&as_shade);
439 } 386 }
440 387
441 if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL) 388 if ((tr_flags & BG_NEEDS_BLUR) && background != NULL)
442 { 389 {
443 ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 390 ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
444 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, 391 (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage,
445 100, ASIMAGE_QUALITY_DEFAULT); 392 100, ASIMAGE_QUALITY_DEFAULT);
446 if (tmp) 393 if (tmp)
447 { 394 {
448 destroy_asimage (&background); 395 destroy_asimage (&background);
451 } 398 }
452# endif 399# endif
453 400
454 ASImage *result = 0; 401 ASImage *result = 0;
455 402
456 int target_width = target->szHint.width; 403 int target_width = szHint.width;
457 int target_height = target->szHint.height; 404 int target_height = szHint.height;
458 int new_pmap_width = target_width; 405 int new_pmap_width = target_width;
459 int new_pmap_height = target_height; 406 int new_pmap_height = target_height;
460 407
461 int x = 0; 408 int x = 0;
462 int y = 0; 409 int y = 0;
465 412
466 if (original_asim) 413 if (original_asim)
467 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); 414 get_image_geometry (original_asim->width, original_asim->height, w, h, x, y);
468 415
469 if (!original_asim 416 if (!original_asim
470 || (!(flags & rootAlign) 417 || (!(bg_flags & BG_ROOT_ALIGN)
471 && (x >= target_width 418 && (x >= target_width
472 || y >= target_height 419 || y >= target_height
473 || (x + w <= 0) 420 || (x + w <= 0)
474 || (y + h <= 0)))) 421 || (y + h <= 0))))
475 { 422 {
479 new_pmap_height = background->height; 426 new_pmap_height = background->height;
480 result = background; 427 result = background;
481 428
482 if (background_tint != TINT_LEAVE_SAME) 429 if (background_tint != TINT_LEAVE_SAME)
483 { 430 {
484 ASImage *tmp = tile_asimage (target->asv, background, 0, 0, 431 ASImage *tmp = tile_asimage (asv, background, 0, 0,
485 target_width, target_height, background_tint, 432 target_width, target_height, background_tint,
486 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); 433 ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT);
487 if (tmp) 434 if (tmp)
488 result = tmp; 435 result = tmp;
489 } 436 }
496 result = original_asim; 443 result = original_asim;
497 444
498 if ((w != original_asim->width) 445 if ((w != original_asim->width)
499 || (h != original_asim->height)) 446 || (h != original_asim->height))
500 { 447 {
501 result = scale_asimage (target->asv, original_asim, 448 result = scale_asimage (asv, original_asim,
502 w, h, 449 w, h,
503 background ? ASA_ASImage : ASA_XImage, 450 background ? ASA_ASImage : ASA_XImage,
504 100, ASIMAGE_QUALITY_DEFAULT); 451 100, ASIMAGE_QUALITY_DEFAULT);
505 } 452 }
506 453
512 but there is no need to make it bigger than the window! */ 459 but there is no need to make it bigger than the window! */
513 new_pmap_width = min (result->width, target_width); 460 new_pmap_width = min (result->width, target_width);
514 new_pmap_height = min (result->height, target_height); 461 new_pmap_height = min (result->height, target_height);
515 462
516 /* we also need to tile our image in both directions */ 463 /* we also need to tile our image in both directions */
517 ASImage *tmp = tile_asimage (target->asv, result, 464 ASImage *tmp = tile_asimage (asv, result,
518 (int)result->width - x, 465 (int)result->width - x,
519 (int)result->height - y, 466 (int)result->height - y,
520 new_pmap_width, 467 new_pmap_width,
521 new_pmap_height, 468 new_pmap_height,
522 TINT_LEAVE_SAME, ASA_XImage, 469 TINT_LEAVE_SAME, ASA_XImage,
565 { 512 {
566 layers[1].dst_y = y; 513 layers[1].dst_y = y;
567 layers[1].clip_height = result->height; 514 layers[1].clip_height = result->height;
568 } 515 }
569 516
570 if (target->rs[Rs_blendtype]) 517 if (rs[Rs_blendtype])
571 { 518 {
572 layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); 519 layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]);
573 if (layers[1].merge_scanlines == NULL) 520 if (layers[1].merge_scanlines == NULL)
574 layers[1].merge_scanlines = alphablend_scanlines; 521 layers[1].merge_scanlines = alphablend_scanlines;
575 } 522 }
576 523
577 ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, 524 ASImage *tmp = merge_layers (asv, layers, 2, target_width, target_height,
578 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 525 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
579 526
580 if (tmp) 527 if (tmp)
581 { 528 {
582 if (result != original_asim) 529 if (result != original_asim)
595 { 542 {
596 XGCValues gcv; 543 XGCValues gcv;
597 GC gc; 544 GC gc;
598 545
599 /* create Pixmap */ 546 /* create Pixmap */
600 if (pixmap == None 547 if (bg_pixmap == None
601 || pmap_width != new_pmap_width 548 || bg_pmap_width != new_pmap_width
602 || pmap_height != new_pmap_height 549 || bg_pmap_height != new_pmap_height)
603 || pmap_depth != target->depth)
604 { 550 {
605 if (pixmap) 551 if (bg_pixmap)
606 XFreePixmap (target->dpy, pixmap); 552 XFreePixmap (dpy, bg_pixmap);
607 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 553 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
608 pmap_width = new_pmap_width; 554 bg_pmap_width = new_pmap_width;
609 pmap_height = new_pmap_height; 555 bg_pmap_height = new_pmap_height;
610 pmap_depth = target->depth;
611 } 556 }
612 /* fill with background color (if result's not completely overlapping it) */ 557 /* fill with background color (if result's not completely overlapping it) */
613 gcv.foreground = target->pix_colors[Color_bg]; 558 gcv.foreground = pix_colors[Color_bg];
614 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 559 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
615 560
616 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 561 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
617 int dst_width = result->width, dst_height = result->height; 562 int dst_width = result->width, dst_height = result->height;
618 if (background == NULL) 563 if (background == NULL)
619 { 564 {
624 } 569 }
625 570
626 if (dst_x > 0 || dst_y > 0 571 if (dst_x > 0 || dst_y > 0
627 || dst_x + dst_width < new_pmap_width 572 || dst_x + dst_width < new_pmap_width
628 || dst_y + dst_height < new_pmap_height) 573 || dst_y + dst_height < new_pmap_height)
629 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 574 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
630 } 575 }
631 576
632 /* put result on pixmap */ 577 /* put result on pixmap */
633 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 578 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
634 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 579 asimage2drawable (asv, bg_pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
635 580
636 if (result != background && result != original_asim) 581 if (result != background && result != original_asim)
637 destroy_asimage (&result); 582 destroy_asimage (&result);
638 583
639 XFreeGC (target->dpy, gc); 584 XFreeGC (dpy, gc);
640 585
641 ret = true; 586 ret = true;
642 } 587 }
643 588
644 if (background) 589 if (background)
648} 593}
649# endif /* HAVE_AFTERIMAGE */ 594# endif /* HAVE_AFTERIMAGE */
650 595
651# ifdef HAVE_PIXBUF 596# ifdef HAVE_PIXBUF
652bool 597bool
653bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, 598rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc,
654 int src_x, int src_y, int dst_x, int dst_y, 599 int src_x, int src_y, int dst_x, int dst_y,
655 unsigned int width, unsigned int height) 600 unsigned int width, unsigned int height)
656{ 601{
657 XImage *ximage; 602 XImage *ximage;
658 char *data, *line; 603 char *data, *line;
659 int bytes_per_pixel; 604 int bytes_per_pixel;
660 int width_r, width_g, width_b; 605 int width_r, width_g, width_b;
661 int sh_r, sh_g, sh_b; 606 int sh_r, sh_g, sh_b;
662 int rowstride; 607 int rowstride;
663 int channels; 608 int channels;
664 unsigned char *row; 609 unsigned char *row;
665 Visual *visual = target->visual;
666 int depth = target->depth;
667 610
668 if (visual->c_class != TrueColor) 611 if (visual->c_class != TrueColor)
669 return false; 612 return false;
670 613
671 if (depth == 24 || depth == 32) 614 if (depth == 24 || depth == 32)
691 634
692 data = (char *)malloc (width * height * bytes_per_pixel); 635 data = (char *)malloc (width * height * bytes_per_pixel);
693 if (!data) 636 if (!data)
694 return false; 637 return false;
695 638
696 ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data, 639 ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data,
697 width, height, bytes_per_pixel * 8, 0); 640 width, height, bytes_per_pixel * 8, 0);
698 if (!ximage) 641 if (!ximage)
699 { 642 {
700 free (data); 643 free (data);
701 return false; 644 return false;
727 670
728 row += rowstride; 671 row += rowstride;
729 line += ximage->bytes_per_line; 672 line += ximage->bytes_per_line;
730 } 673 }
731 674
732 XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height); 675 XPutImage (dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height);
733 XDestroyImage (ximage); 676 XDestroyImage (ximage);
734 return true; 677 return true;
735} 678}
736 679
737bool 680bool
738bgPixmap_t::render_image (unsigned long background_flags) 681rxvt_term::render_image (unsigned long tr_flags)
739{ 682{
740 if (target == NULL)
741 return false;
742
743 if (!pixbuf) 683 if (!pixbuf)
744 return false; 684 return false;
745 685
746 if (background_flags 686 if (tr_flags
747 && !(flags & HAS_RENDER)) 687 && !(bg_flags & BG_HAS_RENDER))
748 return false; 688 return false;
749 689
750 GdkPixbuf *result; 690 GdkPixbuf *result;
751 691
752 int image_width = gdk_pixbuf_get_width (pixbuf); 692 int image_width = gdk_pixbuf_get_width (pixbuf);
753 int image_height = gdk_pixbuf_get_height (pixbuf); 693 int image_height = gdk_pixbuf_get_height (pixbuf);
754 694
755 int target_width = target->szHint.width; 695 int target_width = szHint.width;
756 int target_height = target->szHint.height; 696 int target_height = szHint.height;
757 int new_pmap_width = target_width; 697 int new_pmap_width = target_width;
758 int new_pmap_height = target_height; 698 int new_pmap_height = target_height;
759 699
760 int x = 0; 700 int x = 0;
761 int y = 0; 701 int y = 0;
762 int w = 0; 702 int w = 0;
763 int h = 0; 703 int h = 0;
764 704
765 get_image_geometry (image_width, image_height, w, h, x, y); 705 get_image_geometry (image_width, image_height, w, h, x, y);
766 706
767 if (!(flags & rootAlign) 707 if (!(bg_flags & BG_ROOT_ALIGN)
768 && (x >= target_width 708 && (x >= target_width
769 || y >= target_height 709 || y >= target_height
770 || (x + w <= 0) 710 || (x + w <= 0)
771 || (y + h <= 0))) 711 || (y + h <= 0)))
772 return false; 712 return false;
790 Pixmap root_pmap; 730 Pixmap root_pmap;
791 731
792 image_width = gdk_pixbuf_get_width (result); 732 image_width = gdk_pixbuf_get_width (result);
793 image_height = gdk_pixbuf_get_height (result); 733 image_height = gdk_pixbuf_get_height (result);
794 734
795 if (background_flags) 735 if (tr_flags)
796 { 736 {
797 root_pmap = pixmap; 737 root_pmap = bg_pixmap;
798 pixmap = None; 738 bg_pixmap = None;
799 } 739 }
800 else 740 else
801 { 741 {
802 if (h_scale == 0 || v_scale == 0) 742 if (h_scale == 0 || v_scale == 0)
803 { 743 {
804 new_pmap_width = min (image_width, target_width); 744 new_pmap_width = min (image_width, target_width);
805 new_pmap_height = min (image_height, target_height); 745 new_pmap_height = min (image_height, target_height);
806 } 746 }
807 } 747 }
808 748
809 if (pixmap == None 749 if (bg_pixmap == None
810 || pmap_width != new_pmap_width 750 || bg_pmap_width != new_pmap_width
811 || pmap_height != new_pmap_height 751 || bg_pmap_height != new_pmap_height)
812 || pmap_depth != target->depth)
813 { 752 {
814 if (pixmap) 753 if (bg_pixmap)
815 XFreePixmap (target->dpy, pixmap); 754 XFreePixmap (dpy, bg_pixmap);
816 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 755 bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth);
817 pmap_width = new_pmap_width; 756 bg_pmap_width = new_pmap_width;
818 pmap_height = new_pmap_height; 757 bg_pmap_height = new_pmap_height;
819 pmap_depth = target->depth;
820 } 758 }
821 759
822 gcv.foreground = target->pix_colors[Color_bg]; 760 gcv.foreground = pix_colors[Color_bg];
823 gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); 761 gc = XCreateGC (dpy, vt, GCForeground, &gcv);
824 762
825 if (h_scale == 0 || v_scale == 0) 763 if (h_scale == 0 || v_scale == 0)
826 { 764 {
827 Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); 765 Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth);
828 pixbuf_to_pixmap (result, tile, gc, 766 pixbuf_to_pixmap (result, tile, gc,
829 0, 0, 767 0, 0,
830 0, 0, 768 0, 0,
831 image_width, image_height); 769 image_width, image_height);
832 770
833 gcv.tile = tile; 771 gcv.tile = tile;
834 gcv.fill_style = FillTiled; 772 gcv.fill_style = FillTiled;
835 gcv.ts_x_origin = x; 773 gcv.ts_x_origin = x;
836 gcv.ts_y_origin = y; 774 gcv.ts_y_origin = y;
837 XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 775 XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
838 776
839 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 777 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
840 XFreePixmap (target->dpy, tile); 778 XFreePixmap (dpy, tile);
841 } 779 }
842 else 780 else
843 { 781 {
844 int src_x, src_y, dst_x, dst_y; 782 int src_x, src_y, dst_x, dst_y;
845 int dst_width, dst_height; 783 int dst_width, dst_height;
848 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); 786 src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height);
849 787
850 if (dst_x > 0 || dst_y > 0 788 if (dst_x > 0 || dst_y > 0
851 || dst_x + dst_width < new_pmap_width 789 || dst_x + dst_width < new_pmap_width
852 || dst_y + dst_height < new_pmap_height) 790 || dst_y + dst_height < new_pmap_height)
853 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 791 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
854 792
855 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 793 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
856 pixbuf_to_pixmap (result, pixmap, gc, 794 pixbuf_to_pixmap (result, bg_pixmap, gc,
857 src_x, src_y, 795 src_x, src_y,
858 dst_x, dst_y, 796 dst_x, dst_y,
859 dst_width, dst_height); 797 dst_width, dst_height);
860 } 798 }
861 799
862#if XRENDER 800#if XRENDER
863 if (background_flags) 801 if (tr_flags)
864 { 802 {
865 Display *dpy = target->dpy;
866 XRenderPictureAttributes pa; 803 XRenderPictureAttributes pa;
867 804
868 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); 805 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual);
869 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 806 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
870 807
871 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 808 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
872 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 809 Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa);
873 810
874 pa.repeat = True; 811 pa.repeat = True;
875 Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8); 812 Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8);
876 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); 813 XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8);
877 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); 814 Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa);
878 XFreePixmap (dpy, mask_pmap); 815 XFreePixmap (dpy, mask_pmap);
879 816
880 if (src && dst && mask) 817 if (src && dst && mask)
898#endif 835#endif
899 836
900 if (result != pixbuf) 837 if (result != pixbuf)
901 g_object_unref (result); 838 g_object_unref (result);
902 839
903 XFreeGC (target->dpy, gc); 840 XFreeGC (dpy, gc);
904 841
905 ret = true; 842 ret = true;
906 } 843 }
907 844
908 return ret; 845 return ret;
909} 846}
910# endif /* HAVE_PIXBUF */ 847# endif /* HAVE_PIXBUF */
911 848
912bool 849bool
913bgPixmap_t::set_file (const char *file) 850rxvt_term::bg_set_file (const char *file)
914{ 851{
915 if (!file || !*file) 852 if (!file || !*file)
916 return false; 853 return false;
917 854
918 if (const char *p = strchr (file, ';')) 855 if (const char *p = strchr (file, ';'))
923 f[len] = '\0'; 860 f[len] = '\0';
924 file = f; 861 file = f;
925 } 862 }
926 863
927# ifdef HAVE_AFTERIMAGE 864# ifdef HAVE_AFTERIMAGE
928 if (!target->asimman) 865 if (!asimman)
929 target->asimman = create_generic_imageman (target->rs[Rs_path]); 866 asimman = create_generic_imageman (rs[Rs_path]);
930 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 867 ASImage *image = get_asimage (asimman, file, 0xFFFFFFFF, 100);
931 if (image) 868 if (image)
932 { 869 {
933 if (original_asim) 870 if (original_asim)
934 safe_asimage_destroy (original_asim); 871 safe_asimage_destroy (original_asim);
935 original_asim = image; 872 original_asim = image;
936 flags |= CLIENT_RENDER; 873 bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER;
937 have_image = true;
938 return true; 874 return true;
939 } 875 }
940# endif 876# endif
941 877
942# ifdef HAVE_PIXBUF 878# ifdef HAVE_PIXBUF
944 if (image) 880 if (image)
945 { 881 {
946 if (pixbuf) 882 if (pixbuf)
947 g_object_unref (pixbuf); 883 g_object_unref (pixbuf);
948 pixbuf = image; 884 pixbuf = image;
949 have_image = true; 885 bg_flags |= BG_IS_FROM_FILE;
950 return true; 886 return true;
951 } 887 }
952# endif 888# endif
953 889
954 return false; 890 return false;
956 892
957# endif /* BG_IMAGE_FROM_FILE */ 893# endif /* BG_IMAGE_FROM_FILE */
958 894
959# ifdef ENABLE_TRANSPARENCY 895# ifdef ENABLE_TRANSPARENCY
960bool 896bool
961bgPixmap_t::set_transparent () 897rxvt_term::bg_set_transparent ()
962{ 898{
963 if (!(flags & isTransparent)) 899 if (!(bg_flags & BG_IS_TRANSPARENT))
964 { 900 {
965 flags |= isTransparent; 901 bg_flags |= BG_IS_TRANSPARENT;
966 return true; 902 return true;
967 } 903 }
968 904
969 return false; 905 return false;
970} 906}
971 907
972bool 908bool
973bgPixmap_t::set_blur_radius (const char *geom) 909rxvt_term::bg_set_blur (const char *geom)
974{ 910{
975 bool changed = false; 911 bool changed = false;
976 unsigned int hr, vr; 912 unsigned int hr, vr;
977 int junk; 913 int junk;
978 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 914 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
996 changed = true; 932 changed = true;
997 v_blurRadius = vr; 933 v_blurRadius = vr;
998 } 934 }
999 935
1000 if (v_blurRadius == 0 && h_blurRadius == 0) 936 if (v_blurRadius == 0 && h_blurRadius == 0)
1001 flags &= ~blurNeeded; 937 bg_flags &= ~BG_NEEDS_BLUR;
1002 else 938 else
1003 flags |= blurNeeded; 939 bg_flags |= BG_NEEDS_BLUR;
1004 940
1005 return changed; 941 return changed;
1006} 942}
1007 943
1008static inline unsigned long 944static inline unsigned long
1013 bool has_shade = shade != 100; 949 bool has_shade = shade != 100;
1014 950
1015 if (tint) 951 if (tint)
1016 { 952 {
1017 tint->get (c); 953 tint->get (c);
1018# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x00ff || (cmp) >= 0xff00)
1019 if (!has_shade 954 if (!has_shade
1020 && IS_COMPONENT_WHOLESOME (c.r) 955 && (c.r <= 0x00ff || c.r >= 0xff00)
1021 && IS_COMPONENT_WHOLESOME (c.g) 956 && (c.g <= 0x00ff || c.g >= 0xff00)
1022 && IS_COMPONENT_WHOLESOME (c.b)) 957 && (c.b <= 0x00ff || c.b >= 0xff00))
1023 flags |= bgPixmap_t::tintWholesome; 958 flags |= rxvt_term::BG_TINT_BITAND;
1024# undef IS_COMPONENT_WHOLESOME
1025 } 959 }
1026 960
1027 if (has_shade || tint) 961 if (has_shade || tint)
1028 flags |= bgPixmap_t::tintNeeded; 962 flags |= rxvt_term::BG_NEEDS_TINT;
1029 963
1030 return flags; 964 return flags;
1031} 965}
1032 966
1033bool 967bool
1034bgPixmap_t::set_tint (rxvt_color &new_tint) 968rxvt_term::bg_set_tint (rxvt_color &new_tint)
1035{ 969{
1036 if (!(flags & tintSet) || tint != new_tint) 970 if (!(bg_flags & BG_TINT_SET) || tint != new_tint)
1037 { 971 {
1038 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); 972 unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade);
1039 tint = new_tint; 973 tint = new_tint;
1040 flags = (flags & ~tintFlags) | new_flags | tintSet; 974 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET;
1041 return true; 975 return true;
1042 } 976 }
1043 977
1044 return false; 978 return false;
1045} 979}
1046 980
1047bool 981bool
1048bgPixmap_t::set_shade (const char *shade_str) 982rxvt_term::bg_set_shade (const char *shade_str)
1049{ 983{
1050 int new_shade = (shade_str) ? atoi (shade_str) : 100; 984 int new_shade = (shade_str) ? atoi (shade_str) : 100;
1051 985
1052 clamp_it (new_shade, -100, 200); 986 clamp_it (new_shade, -100, 200);
1053 if (new_shade < 0) 987 if (new_shade < 0)
1054 new_shade = 200 - (100 + new_shade); 988 new_shade = 200 - (100 + new_shade);
1055 989
1056 if (new_shade != shade) 990 if (new_shade != shade)
1057 { 991 {
1058 unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); 992 unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade);
1059 shade = new_shade; 993 shade = new_shade;
1060 flags = (flags & (~tintFlags | tintSet)) | new_flags; 994 bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags;
1061 return true; 995 return true;
1062 } 996 }
1063 997
1064 return false; 998 return false;
1065} 999}
1086 params[i+2] = XDoubleToFixed (kernel[i] / sum); 1020 params[i+2] = XDoubleToFixed (kernel[i] / sum);
1087} 1021}
1088#endif 1022#endif
1089 1023
1090bool 1024bool
1091bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1025rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1092{ 1026{
1093 bool ret = false; 1027 bool ret = false;
1094#if XRENDER 1028#if XRENDER
1095 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1029 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1096 double *kernel = (double *)malloc (size * sizeof (double)); 1030 double *kernel = (double *)malloc (size * sizeof (double));
1097 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1031 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1098 1032
1099 Display *dpy = target->dpy;
1100 XRenderPictureAttributes pa; 1033 XRenderPictureAttributes pa;
1101 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 1034 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
1102 1035
1103 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1036 Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1104 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); 1037 Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa);
1124 1057
1125 if (v_blurRadius) 1058 if (v_blurRadius)
1126 { 1059 {
1127 size = v_blurRadius * 2 + 1; 1060 size = v_blurRadius * 2 + 1;
1128 get_gaussian_kernel (v_blurRadius, size, kernel, params); 1061 get_gaussian_kernel (v_blurRadius, size, kernel, params);
1129 swap (params[0], params[1]); 1062 ::swap (params[0], params[1]);
1130 1063
1131 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); 1064 XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2);
1132 XRenderComposite (dpy, 1065 XRenderComposite (dpy,
1133 PictOpSrc, 1066 PictOpSrc,
1134 src, 1067 src,
1150#endif 1083#endif
1151 return ret; 1084 return ret;
1152} 1085}
1153 1086
1154bool 1087bool
1155bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1088rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1156{ 1089{
1157 Display *dpy = target->dpy;
1158 bool ret = false; 1090 bool ret = false;
1159 1091
1160 if (flags & tintWholesome) 1092 if (bg_flags & BG_TINT_BITAND)
1161 { 1093 {
1162 XGCValues gcv; 1094 XGCValues gcv;
1163 GC gc; 1095 GC gc;
1164 1096
1165 /* In this case we can tint image server-side getting significant 1097 /* In this case we can tint image server-side getting significant
1179 else 1111 else
1180 { 1112 {
1181# if XRENDER 1113# if XRENDER
1182 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1114 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1183 1115
1184 if (flags & tintSet) 1116 if (bg_flags & BG_TINT_SET)
1185 tint.get (c); 1117 tint.get (c);
1186 1118
1187 if (shade <= 100) 1119 if (shade <= 100)
1188 { 1120 {
1189 c.r = (c.r * shade) / 100; 1121 c.r = (c.r * shade) / 100;
1254 * Builds a pixmap of the same size as the terminal window that contains 1186 * Builds a pixmap of the same size as the terminal window that contains
1255 * the tiled portion of the root pixmap that is supposed to be covered by 1187 * the tiled portion of the root pixmap that is supposed to be covered by
1256 * our window. 1188 * our window.
1257 */ 1189 */
1258unsigned long 1190unsigned long
1259bgPixmap_t::make_transparency_pixmap () 1191rxvt_term::make_transparency_pixmap ()
1260{ 1192{
1261 unsigned long result = 0; 1193 unsigned long result = 0;
1262
1263 if (target == NULL)
1264 return 0;
1265 1194
1266 /* root dimensions may change from call to call - but Display structure should 1195 /* root dimensions may change from call to call - but Display structure should
1267 * be always up-to-date, so let's use it : 1196 * be always up-to-date, so let's use it :
1268 */ 1197 */
1269 int screen = target->display->screen; 1198 int screen = display->screen;
1270 Display *dpy = target->dpy;
1271 int root_depth = DefaultDepth (dpy, screen); 1199 int root_depth = DefaultDepth (dpy, screen);
1272 int root_width = DisplayWidth (dpy, screen); 1200 int root_width = DisplayWidth (dpy, screen);
1273 int root_height = DisplayHeight (dpy, screen); 1201 int root_height = DisplayHeight (dpy, screen);
1274 unsigned int root_pmap_width, root_pmap_height; 1202 unsigned int root_pmap_width, root_pmap_height;
1275 int window_width = target->szHint.width; 1203 int window_width = szHint.width;
1276 int window_height = target->szHint.height; 1204 int window_height = szHint.height;
1277 int sx, sy; 1205 int sx, sy;
1278 XGCValues gcv; 1206 XGCValues gcv;
1279 GC gc; 1207 GC gc;
1280 1208
1281 sx = target_x; 1209 sx = target_x;
1291 { 1219 {
1292 Window wdummy; 1220 Window wdummy;
1293 int idummy; 1221 int idummy;
1294 unsigned int udummy; 1222 unsigned int udummy;
1295 1223
1296 target->allowedxerror = -1; 1224 allowedxerror = -1;
1297 1225
1298 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) 1226 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1299 root_pixmap = None; 1227 root_pixmap = None;
1300 1228
1301 target->allowedxerror = 0; 1229 allowedxerror = 0;
1302 } 1230 }
1303 1231
1304 Pixmap recoded_root_pmap = root_pixmap; 1232 Pixmap recoded_root_pmap = root_pixmap;
1305 1233
1306 if (root_pixmap != None && root_depth != target->depth) 1234 if (root_pixmap != None && root_depth != depth)
1307 { 1235 {
1308#if XRENDER 1236#if XRENDER
1309 if (flags & HAS_RENDER) 1237 if (bg_flags & BG_HAS_RENDER)
1310 { 1238 {
1311 XRenderPictureAttributes pa; 1239 XRenderPictureAttributes pa;
1312 1240
1313 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1241 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1314 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1242 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1315 1243
1316 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); 1244 recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth);
1317 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 1245 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual);
1318 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1246 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1319 1247
1320 if (src && dst) 1248 if (src && dst)
1321 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1249 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1322 else 1250 else
1334 } 1262 }
1335 1263
1336 if (root_pixmap == None) 1264 if (root_pixmap == None)
1337 return 0; 1265 return 0;
1338 1266
1267 if (bg_pixmap == None
1268 || bg_pmap_width != window_width
1269 || bg_pmap_height != window_height)
1270 {
1271 if (bg_pixmap)
1272 XFreePixmap (dpy, bg_pixmap);
1339 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); 1273 bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth);
1274 bg_pmap_width = window_width;
1275 bg_pmap_height = window_height;
1276 }
1340 1277
1341 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1278 if (bg_pixmap == None)
1342 return 0; 1279 return 0;
1343 1280
1344 /* straightforward pixmap copy */ 1281 /* straightforward pixmap copy */
1345 while (sx < 0) sx += (int)root_width; 1282 while (sx < 0) sx += (int)root_width;
1346 while (sy < 0) sy += (int)root_height; 1283 while (sy < 0) sy += (int)root_height;
1347 1284
1348 gcv.tile = recoded_root_pmap; 1285 gcv.tile = recoded_root_pmap;
1349 gcv.fill_style = FillTiled; 1286 gcv.fill_style = FillTiled;
1350 gcv.ts_x_origin = -sx; 1287 gcv.ts_x_origin = -sx;
1351 gcv.ts_y_origin = -sy; 1288 gcv.ts_y_origin = -sy;
1352 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1289 gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1353 1290
1354 if (gc) 1291 if (gc)
1355 { 1292 {
1356 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1293 XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height);
1357 result |= transpPmapTiled; 1294 result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS);
1358 XFreeGC (dpy, gc); 1295 XFreeGC (dpy, gc);
1359 1296
1360 if (!(flags & CLIENT_RENDER)) 1297 if (!(bg_flags & BG_CLIENT_RENDER))
1361 { 1298 {
1362 if ((flags & blurNeeded) 1299 if ((bg_flags & BG_NEEDS_BLUR)
1363 && (flags & HAS_RENDER_CONV)) 1300 && (bg_flags & BG_HAS_RENDER_CONV))
1364 {
1365 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1366 result |= transpPmapBlurred;
1367 } 1301 {
1368 if ((flags & tintNeeded) 1302 if (blur_pixmap (bg_pixmap, visual, window_width, window_height))
1369 && (flags & (tintWholesome | HAS_RENDER))) 1303 result &= ~BG_NEEDS_BLUR;
1370 { 1304 }
1305 if ((bg_flags & BG_NEEDS_TINT)
1306 && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER)))
1307 {
1371 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1308 if (tint_pixmap (bg_pixmap, visual, window_width, window_height))
1372 result |= transpPmapTinted; 1309 result &= ~BG_NEEDS_TINT;
1373 } 1310 }
1374 } /* server side rendering completed */ 1311 } /* server side rendering completed */
1375
1376 if (pixmap)
1377 XFreePixmap (dpy, pixmap);
1378
1379 pixmap = tiled_root_pmap;
1380 pmap_width = window_width;
1381 pmap_height = window_height;
1382 pmap_depth = target->depth;
1383 } 1312 }
1384 else
1385 XFreePixmap (dpy, tiled_root_pmap);
1386 1313
1387 if (recoded_root_pmap != root_pixmap) 1314 if (recoded_root_pmap != root_pixmap)
1388 XFreePixmap (dpy, recoded_root_pmap); 1315 XFreePixmap (dpy, recoded_root_pmap);
1389 1316
1390 return result; 1317 return result;
1391} 1318}
1392 1319
1393void 1320void
1394bgPixmap_t::set_root_pixmap () 1321rxvt_term::bg_set_root_pixmap ()
1395{ 1322{
1396 Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]); 1323 Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]);
1397 if (new_root_pixmap == None) 1324 if (new_root_pixmap == None)
1398 new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]); 1325 new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]);
1399 1326
1400 root_pixmap = new_root_pixmap; 1327 root_pixmap = new_root_pixmap;
1401} 1328}
1402# endif /* ENABLE_TRANSPARENCY */ 1329# endif /* ENABLE_TRANSPARENCY */
1403 1330
1404#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1331#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1405static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); 1332static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c);
1406# endif 1333# endif
1407 1334
1408bool 1335bool
1409bgPixmap_t::render () 1336rxvt_term::bg_render ()
1410{ 1337{
1411 unsigned long background_flags = 0; 1338 unsigned long tr_flags = 0;
1412 1339
1413 if (target == NULL)
1414 return false;
1415
1416 invalidate (); 1340 bg_invalidate ();
1417# ifdef ENABLE_TRANSPARENCY 1341# ifdef ENABLE_TRANSPARENCY
1418 if (flags & isTransparent) 1342 if (bg_flags & BG_IS_TRANSPARENT)
1419 { 1343 {
1420 /* we need to re-generate transparency pixmap in that case ! */ 1344 /* we need to re-generate transparency pixmap in that case ! */
1421 background_flags = make_transparency_pixmap (); 1345 tr_flags = make_transparency_pixmap ();
1422 if (background_flags == 0) 1346 if (tr_flags == 0)
1423 return false; 1347 return false;
1424 else if ((background_flags & transpTransformations) == (flags & transpTransformations)) 1348 else if (!(tr_flags & BG_EFFECTS_FLAGS))
1425 flags &= ~isInvalid; 1349 bg_flags |= BG_IS_VALID;
1426 } 1350 }
1427# endif 1351# endif
1428 1352
1429# ifdef BG_IMAGE_FROM_FILE 1353# ifdef BG_IMAGE_FROM_FILE
1430 if (have_image 1354 if ((bg_flags & BG_IS_FROM_FILE)
1431 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1355 || (tr_flags & BG_EFFECTS_FLAGS))
1432 { 1356 {
1433 if (render_image (background_flags)) 1357 if (render_image (tr_flags))
1434 flags &= ~isInvalid; 1358 bg_flags |= BG_IS_VALID;
1435 } 1359 }
1436# endif 1360# endif
1437 1361
1438# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1362# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1439 XImage *result = NULL; 1363 XImage *result = NULL;
1440 1364
1441 if (background_flags && (flags & isInvalid)) 1365 if (tr_flags && !(bg_flags & BG_IS_VALID))
1442 { 1366 {
1443 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1367 result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap);
1444 } 1368 }
1445 1369
1446 if (result) 1370 if (result)
1447 { 1371 {
1448 /* our own client-side tinting */ 1372 /* our own client-side tinting */
1449 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1373 if (tr_flags & BG_NEEDS_TINT)
1450 { 1374 {
1451 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1375 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1452 if (flags & tintSet) 1376 if (bg_flags & BG_TINT_SET)
1453 tint.get (c); 1377 tint.get (c);
1454 shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); 1378 shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c);
1455 } 1379 }
1456 1380
1457 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1381 GC gc = XCreateGC (dpy, vt, 0UL, NULL);
1458 1382
1459 if (gc) 1383 if (gc)
1460 { 1384 {
1461 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1385 XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1462 1386
1463 XFreeGC (target->dpy, gc); 1387 XFreeGC (dpy, gc);
1464 flags &= ~isInvalid; 1388 bg_flags |= BG_IS_VALID;
1465 } 1389 }
1466 1390
1467 XDestroyImage (result); 1391 XDestroyImage (result);
1468 } 1392 }
1469# endif 1393# endif
1470 1394
1471 if (flags & isInvalid) 1395 if (!(bg_flags & BG_IS_VALID))
1472 { 1396 {
1473 if (pixmap != None) 1397 if (bg_pixmap != None)
1474 { 1398 {
1475 XFreePixmap (target->dpy, pixmap); 1399 XFreePixmap (dpy, bg_pixmap);
1476 pixmap = None; 1400 bg_pixmap = None;
1477 } 1401 }
1478 } 1402 }
1479 1403
1480 apply (); 1404 scr_recolour (false);
1405 bg_flags |= BG_NEEDS_REFRESH;
1481 1406
1482 valid_since = ev::now (); 1407 bg_valid_since = ev::now ();
1483 1408
1484 return true; 1409 return true;
1485} 1410}
1486 1411
1487void 1412void
1488bgPixmap_t::set_target (rxvt_term *new_target) 1413rxvt_term::bg_init ()
1489{ 1414{
1490 target = new_target; 1415#ifdef ENABLE_TRANSPARENCY
1416 shade = 100;
1417#endif
1491 1418
1492 flags &= ~(HAS_RENDER | HAS_RENDER_CONV); 1419 bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV);
1493#if XRENDER 1420#if XRENDER
1494 int major, minor; 1421 int major, minor;
1495 if (XRenderQueryVersion (target->dpy, &major, &minor)) 1422 if (XRenderQueryVersion (dpy, &major, &minor))
1496 flags |= HAS_RENDER; 1423 bg_flags |= BG_HAS_RENDER;
1497 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); 1424 XFilters *filters = XRenderQueryFilters (dpy, vt);
1498 if (filters) 1425 if (filters)
1499 { 1426 {
1500 for (int i = 0; i < filters->nfilter; i++) 1427 for (int i = 0; i < filters->nfilter; i++)
1501 if (!strcmp (filters->filter[i], FilterConvolution)) 1428 if (!strcmp (filters->filter[i], FilterConvolution))
1502 flags |= HAS_RENDER_CONV; 1429 bg_flags |= BG_HAS_RENDER_CONV;
1503 1430
1504 XFree (filters); 1431 XFree (filters);
1505 } 1432 }
1506#endif 1433#endif
1507}
1508
1509void
1510bgPixmap_t::apply ()
1511{
1512 if (target == NULL)
1513 return;
1514
1515 if (pixmap != None)
1516 {
1517 /* set target's background to pixmap */
1518# ifdef ENABLE_TRANSPARENCY
1519 if (flags & isTransparent)
1520 {
1521 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1522 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1523
1524 if (target->scrollBar.win)
1525 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1526 }
1527 else
1528# endif
1529 {
1530 /* force old pixmap dereference in case it was transparent before :*/
1531 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1532 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1533 /* do we also need to set scrollbar's background here ? */
1534
1535 if (target->scrollBar.win)
1536 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1537 }
1538 }
1539 else
1540 {
1541 /* set target background to a pixel */
1542 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1543 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1544 /* do we also need to set scrollbar's background here ? */
1545 if (target->scrollBar.win)
1546 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1547 }
1548
1549 /* don't want Expose on the parent or vt. It is better to use
1550 scr_touch or we get a great deal of flicker otherwise: */
1551 XClearWindow (target->dpy, target->parent[0]);
1552
1553 if (target->scrollBar.state && target->scrollBar.win)
1554 {
1555 target->scrollBar.state = STATE_IDLE;
1556 target->scrollBar.show (0);
1557 }
1558
1559 target->want_refresh = 1;
1560 flags |= hasChanged;
1561} 1434}
1562 1435
1563#endif /* HAVE_BG_PIXMAP */ 1436#endif /* HAVE_BG_PIXMAP */
1564 1437
1565#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1438#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines