… | |
… | |
59 | * scale Scale both up and down |
59 | * scale Scale both up and down |
60 | * auto Same as 100x100+50+50 |
60 | * auto Same as 100x100+50+50 |
61 | */ |
61 | */ |
62 | |
62 | |
63 | #ifdef HAVE_BG_PIXMAP |
63 | #ifdef HAVE_BG_PIXMAP |
64 | bgPixmap_t::bgPixmap_t () |
|
|
65 | { |
|
|
66 | // this is basically redundant as bgPixmap_t is only used in |
|
|
67 | // zero_initialised-derived structs |
|
|
68 | #ifdef HAVE_AFTERIMAGE |
|
|
69 | original_asim = NULL; |
|
|
70 | #endif |
|
|
71 | #ifdef HAVE_PIXBUF |
|
|
72 | pixbuf = NULL; |
|
|
73 | #endif |
|
|
74 | #ifdef BG_IMAGE_FROM_FILE |
|
|
75 | have_image = false; |
|
|
76 | h_scale = v_scale = 0; |
|
|
77 | h_align = v_align = 0; |
|
|
78 | #endif |
|
|
79 | #ifdef ENABLE_TRANSPARENCY |
|
|
80 | shade = 100; |
|
|
81 | #endif |
|
|
82 | flags = 0; |
|
|
83 | pixmap = None; |
|
|
84 | valid_since = 0; |
|
|
85 | target = 0; |
|
|
86 | target_x = target_y = 0; |
|
|
87 | } |
|
|
88 | |
|
|
89 | void |
64 | void |
90 | bgPixmap_t::destroy () |
65 | rxvt_term::bg_destroy () |
91 | { |
66 | { |
92 | #ifdef HAVE_AFTERIMAGE |
67 | #ifdef HAVE_AFTERIMAGE |
93 | if (original_asim) |
68 | if (original_asim) |
94 | safe_asimage_destroy (original_asim); |
69 | safe_asimage_destroy (original_asim); |
95 | #endif |
70 | #endif |
… | |
… | |
97 | #ifdef HAVE_PIXBUF |
72 | #ifdef HAVE_PIXBUF |
98 | if (pixbuf) |
73 | if (pixbuf) |
99 | g_object_unref (pixbuf); |
74 | g_object_unref (pixbuf); |
100 | #endif |
75 | #endif |
101 | |
76 | |
102 | if (pixmap && target) |
77 | if (bg_pixmap) |
103 | XFreePixmap (target->dpy, pixmap); |
78 | XFreePixmap (dpy, bg_pixmap); |
104 | } |
79 | } |
105 | |
80 | |
106 | bool |
81 | bool |
107 | bgPixmap_t::set_position (int x, int y) |
82 | rxvt_term::bg_set_position (int x, int y) |
108 | { |
83 | { |
109 | |
84 | |
110 | if (target_x != x |
85 | if (target_x != x |
111 | || target_y != y) |
86 | || target_y != y) |
112 | { |
87 | { |
… | |
… | |
116 | } |
91 | } |
117 | return false; |
92 | return false; |
118 | } |
93 | } |
119 | |
94 | |
120 | bool |
95 | bool |
121 | bgPixmap_t::window_size_sensitive () |
96 | rxvt_term::bg_window_size_sensitive () |
122 | { |
97 | { |
123 | # ifdef ENABLE_TRANSPARENCY |
98 | # ifdef ENABLE_TRANSPARENCY |
124 | if (flags & isTransparent) |
99 | if (bg_flags & isTransparent) |
125 | return true; |
100 | return true; |
126 | # endif |
101 | # endif |
127 | |
102 | |
128 | # ifdef BG_IMAGE_FROM_FILE |
103 | # ifdef BG_IMAGE_FROM_FILE |
129 | if (have_image) |
104 | if (have_image) |
130 | { |
105 | { |
131 | if (flags & sizeSensitive) |
106 | if (bg_flags & sizeSensitive) |
132 | return true; |
107 | return true; |
133 | } |
108 | } |
134 | # endif |
109 | # endif |
135 | |
110 | |
136 | return false; |
111 | return false; |
137 | } |
112 | } |
138 | |
113 | |
139 | bool |
114 | bool |
140 | bgPixmap_t::window_position_sensitive () |
115 | rxvt_term::bg_window_position_sensitive () |
141 | { |
116 | { |
142 | # ifdef ENABLE_TRANSPARENCY |
117 | # ifdef ENABLE_TRANSPARENCY |
143 | if (flags & isTransparent) |
118 | if (bg_flags & isTransparent) |
144 | return true; |
119 | return true; |
145 | # endif |
120 | # endif |
146 | |
121 | |
147 | # ifdef BG_IMAGE_FROM_FILE |
122 | # ifdef BG_IMAGE_FROM_FILE |
148 | if (have_image) |
123 | if (have_image) |
149 | { |
124 | { |
150 | if (flags & rootAlign) |
125 | if (bg_flags & rootAlign) |
151 | return true; |
126 | return true; |
152 | } |
127 | } |
153 | # endif |
128 | # endif |
154 | |
129 | |
155 | return false; |
130 | return false; |
… | |
… | |
222 | dst_size = target_size - dst_pos; |
197 | dst_size = target_size - dst_pos; |
223 | return src_pos; |
198 | return src_pos; |
224 | } |
199 | } |
225 | |
200 | |
226 | bool |
201 | bool |
227 | bgPixmap_t::set_geometry (const char *geom, bool update) |
202 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
228 | { |
203 | { |
229 | bool changed = false; |
204 | bool changed = false; |
230 | int geom_flags = 0; |
205 | int geom_flags = 0; |
231 | int x = 0, y = 0; |
206 | int x = 0, y = 0; |
232 | unsigned int w = 0, h = 0; |
207 | unsigned int w = 0, h = 0; |
233 | unsigned int n; |
208 | unsigned int n; |
234 | unsigned long new_flags = (flags & (~geometryFlags)); |
209 | unsigned long new_flags = (bg_flags & (~geometryFlags)); |
235 | const char *ops; |
210 | const char *ops; |
236 | |
211 | |
237 | if (geom == NULL) |
212 | if (geom == NULL) |
238 | return false; |
213 | return false; |
239 | |
214 | |
… | |
… | |
331 | 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; |
332 | 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; |
333 | 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; |
334 | 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; |
335 | |
310 | |
336 | if (new_flags != flags) |
311 | if (new_flags != bg_flags) |
337 | { |
312 | { |
338 | flags = new_flags; |
313 | bg_flags = new_flags; |
339 | changed = true; |
314 | changed = true; |
340 | } |
315 | } |
341 | |
316 | |
342 | return changed; |
317 | return changed; |
343 | } |
318 | } |
344 | |
319 | |
345 | void |
320 | void |
346 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
321 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
347 | { |
322 | { |
348 | int target_width = target->szHint.width; |
323 | int target_width = szHint.width; |
349 | int target_height = target->szHint.height; |
324 | int target_height = szHint.height; |
350 | |
325 | |
351 | if (flags & propScale) |
326 | if (bg_flags & propScale) |
352 | { |
327 | { |
353 | float scale = (float)target_width / image_width; |
328 | float scale = (float)target_width / image_width; |
354 | min_it (scale, (float)target_height / image_height); |
329 | min_it (scale, (float)target_height / image_height); |
355 | w = image_width * scale + 0.5; |
330 | w = image_width * scale + 0.5; |
356 | h = image_height * scale + 0.5; |
331 | h = image_height * scale + 0.5; |
… | |
… | |
362 | } |
337 | } |
363 | |
338 | |
364 | if (!w) w = image_width; |
339 | if (!w) w = image_width; |
365 | if (!h) h = image_height; |
340 | if (!h) h = image_height; |
366 | |
341 | |
367 | if (flags & rootAlign) |
342 | if (bg_flags & rootAlign) |
368 | { |
343 | { |
369 | x = -target_x; |
344 | x = -target_x; |
370 | y = -target_y; |
345 | y = -target_y; |
371 | } |
346 | } |
372 | else |
347 | else |
373 | { |
348 | { |
374 | x = make_align_position (h_align, target_width, w); |
349 | x = make_align_position (h_align, target_width, w); |
375 | y = make_align_position (v_align, target_height, h); |
350 | y = make_align_position (v_align, target_height, h); |
376 | } |
351 | } |
377 | |
352 | |
378 | flags &= ~sizeSensitive; |
353 | bg_flags &= ~sizeSensitive; |
379 | if ((flags & propScale) || h_scale || v_scale |
354 | if ((bg_flags & propScale) || h_scale || v_scale |
380 | || (!(flags & rootAlign) && (h_align || v_align)) |
355 | || (!(bg_flags & rootAlign) && (h_align || v_align)) |
381 | || w > target_width || h > target_height) |
356 | || w > target_width || h > target_height) |
382 | flags |= sizeSensitive; |
357 | bg_flags |= sizeSensitive; |
383 | } |
358 | } |
384 | |
359 | |
385 | # ifdef HAVE_AFTERIMAGE |
360 | # ifdef HAVE_AFTERIMAGE |
386 | bool |
361 | bool |
387 | bgPixmap_t::render_image (unsigned long background_flags) |
362 | rxvt_term::render_image (unsigned long tr_flags) |
388 | { |
363 | { |
389 | if (target == NULL) |
|
|
390 | return false; |
|
|
391 | |
|
|
392 | target->init_asv (); |
364 | init_asv (); |
393 | |
365 | |
394 | ASImage *background = NULL; |
366 | ASImage *background = NULL; |
395 | ARGB32 background_tint = TINT_LEAVE_SAME; |
367 | ARGB32 background_tint = TINT_LEAVE_SAME; |
396 | |
368 | |
397 | # ifdef ENABLE_TRANSPARENCY |
369 | # ifdef ENABLE_TRANSPARENCY |
398 | if (background_flags) |
370 | if (tr_flags) |
399 | 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); |
400 | |
372 | |
401 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
373 | if (tr_flags & tintNeeded) |
402 | { |
374 | { |
403 | ShadingInfo as_shade; |
375 | ShadingInfo as_shade; |
404 | as_shade.shading = shade; |
376 | as_shade.shading = shade; |
405 | |
377 | |
406 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
378 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
407 | if (flags & tintSet) |
379 | if (bg_flags & tintSet) |
408 | tint.get (c); |
380 | tint.get (c); |
409 | as_shade.tintColor.red = c.r; |
381 | as_shade.tintColor.red = c.r; |
410 | as_shade.tintColor.green = c.g; |
382 | as_shade.tintColor.green = c.g; |
411 | as_shade.tintColor.blue = c.b; |
383 | as_shade.tintColor.blue = c.b; |
412 | |
384 | |
413 | background_tint = shading2tint32 (&as_shade); |
385 | background_tint = shading2tint32 (&as_shade); |
414 | } |
386 | } |
415 | |
387 | |
416 | if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL) |
388 | if ((tr_flags & blurNeeded) && background != NULL) |
417 | { |
389 | { |
418 | 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, |
419 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
391 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
420 | 100, ASIMAGE_QUALITY_DEFAULT); |
392 | 100, ASIMAGE_QUALITY_DEFAULT); |
421 | if (tmp) |
393 | if (tmp) |
422 | { |
394 | { |
423 | destroy_asimage (&background); |
395 | destroy_asimage (&background); |
… | |
… | |
426 | } |
398 | } |
427 | # endif |
399 | # endif |
428 | |
400 | |
429 | ASImage *result = 0; |
401 | ASImage *result = 0; |
430 | |
402 | |
431 | int target_width = target->szHint.width; |
403 | int target_width = szHint.width; |
432 | int target_height = target->szHint.height; |
404 | int target_height = szHint.height; |
433 | int new_pmap_width = target_width; |
405 | int new_pmap_width = target_width; |
434 | int new_pmap_height = target_height; |
406 | int new_pmap_height = target_height; |
435 | |
407 | |
436 | int x = 0; |
408 | int x = 0; |
437 | int y = 0; |
409 | int y = 0; |
… | |
… | |
440 | |
412 | |
441 | if (original_asim) |
413 | if (original_asim) |
442 | 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); |
443 | |
415 | |
444 | if (!original_asim |
416 | if (!original_asim |
445 | || (!(flags & rootAlign) |
417 | || (!(bg_flags & rootAlign) |
446 | && (x >= target_width |
418 | && (x >= target_width |
447 | || y >= target_height |
419 | || y >= target_height |
448 | || (x + w <= 0) |
420 | || (x + w <= 0) |
449 | || (y + h <= 0)))) |
421 | || (y + h <= 0)))) |
450 | { |
422 | { |
… | |
… | |
454 | new_pmap_height = background->height; |
426 | new_pmap_height = background->height; |
455 | result = background; |
427 | result = background; |
456 | |
428 | |
457 | if (background_tint != TINT_LEAVE_SAME) |
429 | if (background_tint != TINT_LEAVE_SAME) |
458 | { |
430 | { |
459 | ASImage *tmp = tile_asimage (target->asv, background, 0, 0, |
431 | ASImage *tmp = tile_asimage (asv, background, 0, 0, |
460 | target_width, target_height, background_tint, |
432 | target_width, target_height, background_tint, |
461 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
433 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
462 | if (tmp) |
434 | if (tmp) |
463 | result = tmp; |
435 | result = tmp; |
464 | } |
436 | } |
… | |
… | |
471 | result = original_asim; |
443 | result = original_asim; |
472 | |
444 | |
473 | if ((w != original_asim->width) |
445 | if ((w != original_asim->width) |
474 | || (h != original_asim->height)) |
446 | || (h != original_asim->height)) |
475 | { |
447 | { |
476 | result = scale_asimage (target->asv, original_asim, |
448 | result = scale_asimage (asv, original_asim, |
477 | w, h, |
449 | w, h, |
478 | background ? ASA_ASImage : ASA_XImage, |
450 | background ? ASA_ASImage : ASA_XImage, |
479 | 100, ASIMAGE_QUALITY_DEFAULT); |
451 | 100, ASIMAGE_QUALITY_DEFAULT); |
480 | } |
452 | } |
481 | |
453 | |
… | |
… | |
487 | 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! */ |
488 | new_pmap_width = min (result->width, target_width); |
460 | new_pmap_width = min (result->width, target_width); |
489 | new_pmap_height = min (result->height, target_height); |
461 | new_pmap_height = min (result->height, target_height); |
490 | |
462 | |
491 | /* we also need to tile our image in both directions */ |
463 | /* we also need to tile our image in both directions */ |
492 | ASImage *tmp = tile_asimage (target->asv, result, |
464 | ASImage *tmp = tile_asimage (asv, result, |
493 | (int)result->width - x, |
465 | (int)result->width - x, |
494 | (int)result->height - y, |
466 | (int)result->height - y, |
495 | new_pmap_width, |
467 | new_pmap_width, |
496 | new_pmap_height, |
468 | new_pmap_height, |
497 | TINT_LEAVE_SAME, ASA_XImage, |
469 | TINT_LEAVE_SAME, ASA_XImage, |
… | |
… | |
540 | { |
512 | { |
541 | layers[1].dst_y = y; |
513 | layers[1].dst_y = y; |
542 | layers[1].clip_height = result->height; |
514 | layers[1].clip_height = result->height; |
543 | } |
515 | } |
544 | |
516 | |
545 | if (target->rs[Rs_blendtype]) |
517 | if (rs[Rs_blendtype]) |
546 | { |
518 | { |
547 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
519 | layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); |
548 | if (layers[1].merge_scanlines == NULL) |
520 | if (layers[1].merge_scanlines == NULL) |
549 | layers[1].merge_scanlines = alphablend_scanlines; |
521 | layers[1].merge_scanlines = alphablend_scanlines; |
550 | } |
522 | } |
551 | |
523 | |
552 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
524 | ASImage *tmp = merge_layers (asv, layers, 2, target_width, target_height, |
553 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
525 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
554 | |
526 | |
555 | if (tmp) |
527 | if (tmp) |
556 | { |
528 | { |
557 | if (result != original_asim) |
529 | if (result != original_asim) |
… | |
… | |
570 | { |
542 | { |
571 | XGCValues gcv; |
543 | XGCValues gcv; |
572 | GC gc; |
544 | GC gc; |
573 | |
545 | |
574 | /* create Pixmap */ |
546 | /* create Pixmap */ |
575 | if (pixmap == None |
547 | if (bg_pixmap == None |
576 | || pmap_width != new_pmap_width |
548 | || bg_pmap_width != new_pmap_width |
577 | || pmap_height != new_pmap_height) |
549 | || bg_pmap_height != new_pmap_height) |
578 | { |
550 | { |
579 | if (pixmap) |
551 | if (bg_pixmap) |
580 | XFreePixmap (target->dpy, pixmap); |
552 | XFreePixmap (dpy, bg_pixmap); |
581 | 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); |
582 | pmap_width = new_pmap_width; |
554 | bg_pmap_width = new_pmap_width; |
583 | pmap_height = new_pmap_height; |
555 | bg_pmap_height = new_pmap_height; |
584 | } |
556 | } |
585 | /* fill with background color (if result's not completely overlapping it) */ |
557 | /* fill with background color (if result's not completely overlapping it) */ |
586 | gcv.foreground = target->pix_colors[Color_bg]; |
558 | gcv.foreground = pix_colors[Color_bg]; |
587 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
559 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
588 | |
560 | |
589 | 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; |
590 | int dst_width = result->width, dst_height = result->height; |
562 | int dst_width = result->width, dst_height = result->height; |
591 | if (background == NULL) |
563 | if (background == NULL) |
592 | { |
564 | { |
… | |
… | |
597 | } |
569 | } |
598 | |
570 | |
599 | if (dst_x > 0 || dst_y > 0 |
571 | if (dst_x > 0 || dst_y > 0 |
600 | || dst_x + dst_width < new_pmap_width |
572 | || dst_x + dst_width < new_pmap_width |
601 | || dst_y + dst_height < new_pmap_height) |
573 | || dst_y + dst_height < new_pmap_height) |
602 | 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); |
603 | } |
575 | } |
604 | |
576 | |
605 | /* put result on pixmap */ |
577 | /* put result on pixmap */ |
606 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
578 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
607 | 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); |
608 | |
580 | |
609 | if (result != background && result != original_asim) |
581 | if (result != background && result != original_asim) |
610 | destroy_asimage (&result); |
582 | destroy_asimage (&result); |
611 | |
583 | |
612 | XFreeGC (target->dpy, gc); |
584 | XFreeGC (dpy, gc); |
613 | |
585 | |
614 | ret = true; |
586 | ret = true; |
615 | } |
587 | } |
616 | |
588 | |
617 | if (background) |
589 | if (background) |
… | |
… | |
621 | } |
593 | } |
622 | # endif /* HAVE_AFTERIMAGE */ |
594 | # endif /* HAVE_AFTERIMAGE */ |
623 | |
595 | |
624 | # ifdef HAVE_PIXBUF |
596 | # ifdef HAVE_PIXBUF |
625 | bool |
597 | bool |
626 | bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
598 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
627 | 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, |
628 | unsigned int width, unsigned int height) |
600 | unsigned int width, unsigned int height) |
629 | { |
601 | { |
630 | XImage *ximage; |
602 | XImage *ximage; |
631 | char *data, *line; |
603 | char *data, *line; |
632 | int bytes_per_pixel; |
604 | int bytes_per_pixel; |
633 | int width_r, width_g, width_b; |
605 | int width_r, width_g, width_b; |
634 | int sh_r, sh_g, sh_b; |
606 | int sh_r, sh_g, sh_b; |
635 | int rowstride; |
607 | int rowstride; |
636 | int channels; |
608 | int channels; |
637 | unsigned char *row; |
609 | unsigned char *row; |
638 | Visual *visual = target->visual; |
|
|
639 | int depth = target->depth; |
|
|
640 | |
610 | |
641 | if (visual->c_class != TrueColor) |
611 | if (visual->c_class != TrueColor) |
642 | return false; |
612 | return false; |
643 | |
613 | |
644 | if (depth == 24 || depth == 32) |
614 | if (depth == 24 || depth == 32) |
… | |
… | |
664 | |
634 | |
665 | data = (char *)malloc (width * height * bytes_per_pixel); |
635 | data = (char *)malloc (width * height * bytes_per_pixel); |
666 | if (!data) |
636 | if (!data) |
667 | return false; |
637 | return false; |
668 | |
638 | |
669 | ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data, |
639 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data, |
670 | width, height, bytes_per_pixel * 8, 0); |
640 | width, height, bytes_per_pixel * 8, 0); |
671 | if (!ximage) |
641 | if (!ximage) |
672 | { |
642 | { |
673 | free (data); |
643 | free (data); |
674 | return false; |
644 | return false; |
… | |
… | |
700 | |
670 | |
701 | row += rowstride; |
671 | row += rowstride; |
702 | line += ximage->bytes_per_line; |
672 | line += ximage->bytes_per_line; |
703 | } |
673 | } |
704 | |
674 | |
705 | 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); |
706 | XDestroyImage (ximage); |
676 | XDestroyImage (ximage); |
707 | return true; |
677 | return true; |
708 | } |
678 | } |
709 | |
679 | |
710 | bool |
680 | bool |
711 | bgPixmap_t::render_image (unsigned long background_flags) |
681 | rxvt_term::render_image (unsigned long tr_flags) |
712 | { |
682 | { |
713 | if (target == NULL) |
|
|
714 | return false; |
|
|
715 | |
|
|
716 | if (!pixbuf) |
683 | if (!pixbuf) |
717 | return false; |
684 | return false; |
718 | |
685 | |
719 | if (background_flags |
686 | if (tr_flags |
720 | && !(flags & HAS_RENDER)) |
687 | && !(bg_flags & HAS_RENDER)) |
721 | return false; |
688 | return false; |
722 | |
689 | |
723 | GdkPixbuf *result; |
690 | GdkPixbuf *result; |
724 | |
691 | |
725 | int image_width = gdk_pixbuf_get_width (pixbuf); |
692 | int image_width = gdk_pixbuf_get_width (pixbuf); |
726 | int image_height = gdk_pixbuf_get_height (pixbuf); |
693 | int image_height = gdk_pixbuf_get_height (pixbuf); |
727 | |
694 | |
728 | int target_width = target->szHint.width; |
695 | int target_width = szHint.width; |
729 | int target_height = target->szHint.height; |
696 | int target_height = szHint.height; |
730 | int new_pmap_width = target_width; |
697 | int new_pmap_width = target_width; |
731 | int new_pmap_height = target_height; |
698 | int new_pmap_height = target_height; |
732 | |
699 | |
733 | int x = 0; |
700 | int x = 0; |
734 | int y = 0; |
701 | int y = 0; |
735 | int w = 0; |
702 | int w = 0; |
736 | int h = 0; |
703 | int h = 0; |
737 | |
704 | |
738 | get_image_geometry (image_width, image_height, w, h, x, y); |
705 | get_image_geometry (image_width, image_height, w, h, x, y); |
739 | |
706 | |
740 | if (!(flags & rootAlign) |
707 | if (!(bg_flags & rootAlign) |
741 | && (x >= target_width |
708 | && (x >= target_width |
742 | || y >= target_height |
709 | || y >= target_height |
743 | || (x + w <= 0) |
710 | || (x + w <= 0) |
744 | || (y + h <= 0))) |
711 | || (y + h <= 0))) |
745 | return false; |
712 | return false; |
… | |
… | |
763 | Pixmap root_pmap; |
730 | Pixmap root_pmap; |
764 | |
731 | |
765 | image_width = gdk_pixbuf_get_width (result); |
732 | image_width = gdk_pixbuf_get_width (result); |
766 | image_height = gdk_pixbuf_get_height (result); |
733 | image_height = gdk_pixbuf_get_height (result); |
767 | |
734 | |
768 | if (background_flags) |
735 | if (tr_flags) |
769 | { |
736 | { |
770 | root_pmap = pixmap; |
737 | root_pmap = bg_pixmap; |
771 | pixmap = None; |
738 | bg_pixmap = None; |
772 | } |
739 | } |
773 | else |
740 | else |
774 | { |
741 | { |
775 | if (h_scale == 0 || v_scale == 0) |
742 | if (h_scale == 0 || v_scale == 0) |
776 | { |
743 | { |
777 | new_pmap_width = min (image_width, target_width); |
744 | new_pmap_width = min (image_width, target_width); |
778 | new_pmap_height = min (image_height, target_height); |
745 | new_pmap_height = min (image_height, target_height); |
779 | } |
746 | } |
780 | } |
747 | } |
781 | |
748 | |
782 | if (pixmap == None |
749 | if (bg_pixmap == None |
783 | || pmap_width != new_pmap_width |
750 | || bg_pmap_width != new_pmap_width |
784 | || pmap_height != new_pmap_height) |
751 | || bg_pmap_height != new_pmap_height) |
785 | { |
752 | { |
786 | if (pixmap) |
753 | if (bg_pixmap) |
787 | XFreePixmap (target->dpy, pixmap); |
754 | XFreePixmap (dpy, bg_pixmap); |
788 | 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); |
789 | pmap_width = new_pmap_width; |
756 | bg_pmap_width = new_pmap_width; |
790 | pmap_height = new_pmap_height; |
757 | bg_pmap_height = new_pmap_height; |
791 | } |
758 | } |
792 | |
759 | |
793 | gcv.foreground = target->pix_colors[Color_bg]; |
760 | gcv.foreground = pix_colors[Color_bg]; |
794 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
761 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
795 | |
762 | |
796 | if (h_scale == 0 || v_scale == 0) |
763 | if (h_scale == 0 || v_scale == 0) |
797 | { |
764 | { |
798 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
765 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
799 | pixbuf_to_pixmap (result, tile, gc, |
766 | pixbuf_to_pixmap (result, tile, gc, |
800 | 0, 0, |
767 | 0, 0, |
801 | 0, 0, |
768 | 0, 0, |
802 | image_width, image_height); |
769 | image_width, image_height); |
803 | |
770 | |
804 | gcv.tile = tile; |
771 | gcv.tile = tile; |
805 | gcv.fill_style = FillTiled; |
772 | gcv.fill_style = FillTiled; |
806 | gcv.ts_x_origin = x; |
773 | gcv.ts_x_origin = x; |
807 | gcv.ts_y_origin = y; |
774 | gcv.ts_y_origin = y; |
808 | XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
775 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
809 | |
776 | |
810 | 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); |
811 | XFreePixmap (target->dpy, tile); |
778 | XFreePixmap (dpy, tile); |
812 | } |
779 | } |
813 | else |
780 | else |
814 | { |
781 | { |
815 | int src_x, src_y, dst_x, dst_y; |
782 | int src_x, src_y, dst_x, dst_y; |
816 | int dst_width, dst_height; |
783 | int dst_width, dst_height; |
… | |
… | |
819 | 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); |
820 | |
787 | |
821 | if (dst_x > 0 || dst_y > 0 |
788 | if (dst_x > 0 || dst_y > 0 |
822 | || dst_x + dst_width < new_pmap_width |
789 | || dst_x + dst_width < new_pmap_width |
823 | || dst_y + dst_height < new_pmap_height) |
790 | || dst_y + dst_height < new_pmap_height) |
824 | 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); |
825 | |
792 | |
826 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
793 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
827 | pixbuf_to_pixmap (result, pixmap, gc, |
794 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
828 | src_x, src_y, |
795 | src_x, src_y, |
829 | dst_x, dst_y, |
796 | dst_x, dst_y, |
830 | dst_width, dst_height); |
797 | dst_width, dst_height); |
831 | } |
798 | } |
832 | |
799 | |
833 | #if XRENDER |
800 | #if XRENDER |
834 | if (background_flags) |
801 | if (tr_flags) |
835 | { |
802 | { |
836 | Display *dpy = target->dpy; |
|
|
837 | XRenderPictureAttributes pa; |
803 | XRenderPictureAttributes pa; |
838 | |
804 | |
839 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); |
805 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); |
840 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
806 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
841 | |
807 | |
842 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
808 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
843 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
809 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); |
844 | |
810 | |
845 | pa.repeat = True; |
811 | pa.repeat = True; |
846 | Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8); |
812 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
847 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
813 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
848 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
814 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
849 | XFreePixmap (dpy, mask_pmap); |
815 | XFreePixmap (dpy, mask_pmap); |
850 | |
816 | |
851 | if (src && dst && mask) |
817 | if (src && dst && mask) |
… | |
… | |
869 | #endif |
835 | #endif |
870 | |
836 | |
871 | if (result != pixbuf) |
837 | if (result != pixbuf) |
872 | g_object_unref (result); |
838 | g_object_unref (result); |
873 | |
839 | |
874 | XFreeGC (target->dpy, gc); |
840 | XFreeGC (dpy, gc); |
875 | |
841 | |
876 | ret = true; |
842 | ret = true; |
877 | } |
843 | } |
878 | |
844 | |
879 | return ret; |
845 | return ret; |
880 | } |
846 | } |
881 | # endif /* HAVE_PIXBUF */ |
847 | # endif /* HAVE_PIXBUF */ |
882 | |
848 | |
883 | bool |
849 | bool |
884 | bgPixmap_t::set_file (const char *file) |
850 | rxvt_term::bg_set_file (const char *file) |
885 | { |
851 | { |
886 | if (!file || !*file) |
852 | if (!file || !*file) |
887 | return false; |
853 | return false; |
888 | |
854 | |
889 | if (const char *p = strchr (file, ';')) |
855 | if (const char *p = strchr (file, ';')) |
… | |
… | |
894 | f[len] = '\0'; |
860 | f[len] = '\0'; |
895 | file = f; |
861 | file = f; |
896 | } |
862 | } |
897 | |
863 | |
898 | # ifdef HAVE_AFTERIMAGE |
864 | # ifdef HAVE_AFTERIMAGE |
899 | if (!target->asimman) |
865 | if (!asimman) |
900 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
866 | asimman = create_generic_imageman (rs[Rs_path]); |
901 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
867 | ASImage *image = get_asimage (asimman, file, 0xFFFFFFFF, 100); |
902 | if (image) |
868 | if (image) |
903 | { |
869 | { |
904 | if (original_asim) |
870 | if (original_asim) |
905 | safe_asimage_destroy (original_asim); |
871 | safe_asimage_destroy (original_asim); |
906 | original_asim = image; |
872 | original_asim = image; |
907 | flags |= CLIENT_RENDER; |
873 | bg_flags |= CLIENT_RENDER; |
908 | have_image = true; |
874 | have_image = true; |
909 | return true; |
875 | return true; |
910 | } |
876 | } |
911 | # endif |
877 | # endif |
912 | |
878 | |
… | |
… | |
927 | |
893 | |
928 | # endif /* BG_IMAGE_FROM_FILE */ |
894 | # endif /* BG_IMAGE_FROM_FILE */ |
929 | |
895 | |
930 | # ifdef ENABLE_TRANSPARENCY |
896 | # ifdef ENABLE_TRANSPARENCY |
931 | bool |
897 | bool |
932 | bgPixmap_t::set_transparent () |
898 | rxvt_term::bg_set_transparent () |
933 | { |
899 | { |
934 | if (!(flags & isTransparent)) |
900 | if (!(bg_flags & isTransparent)) |
935 | { |
901 | { |
936 | flags |= isTransparent; |
902 | bg_flags |= isTransparent; |
937 | return true; |
903 | return true; |
938 | } |
904 | } |
939 | |
905 | |
940 | return false; |
906 | return false; |
941 | } |
907 | } |
942 | |
908 | |
943 | bool |
909 | bool |
944 | bgPixmap_t::set_blur_radius (const char *geom) |
910 | rxvt_term::bg_set_blur (const char *geom) |
945 | { |
911 | { |
946 | bool changed = false; |
912 | bool changed = false; |
947 | unsigned int hr, vr; |
913 | unsigned int hr, vr; |
948 | int junk; |
914 | int junk; |
949 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
915 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
… | |
… | |
967 | changed = true; |
933 | changed = true; |
968 | v_blurRadius = vr; |
934 | v_blurRadius = vr; |
969 | } |
935 | } |
970 | |
936 | |
971 | if (v_blurRadius == 0 && h_blurRadius == 0) |
937 | if (v_blurRadius == 0 && h_blurRadius == 0) |
972 | flags &= ~blurNeeded; |
938 | bg_flags &= ~blurNeeded; |
973 | else |
939 | else |
974 | flags |= blurNeeded; |
940 | bg_flags |= blurNeeded; |
975 | |
941 | |
976 | return changed; |
942 | return changed; |
977 | } |
943 | } |
978 | |
944 | |
979 | static inline unsigned long |
945 | static inline unsigned long |
… | |
… | |
988 | tint->get (c); |
954 | tint->get (c); |
989 | if (!has_shade |
955 | if (!has_shade |
990 | && (c.r <= 0x00ff || c.r >= 0xff00) |
956 | && (c.r <= 0x00ff || c.r >= 0xff00) |
991 | && (c.g <= 0x00ff || c.g >= 0xff00) |
957 | && (c.g <= 0x00ff || c.g >= 0xff00) |
992 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
958 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
993 | flags |= bgPixmap_t::tintWholesome; |
959 | flags |= rxvt_term::tintWholesome; |
994 | } |
960 | } |
995 | |
961 | |
996 | if (has_shade || tint) |
962 | if (has_shade || tint) |
997 | flags |= bgPixmap_t::tintNeeded; |
963 | flags |= rxvt_term::tintNeeded; |
998 | |
964 | |
999 | return flags; |
965 | return flags; |
1000 | } |
966 | } |
1001 | |
967 | |
1002 | bool |
968 | bool |
1003 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
969 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
1004 | { |
970 | { |
1005 | if (!(flags & tintSet) || tint != new_tint) |
971 | if (!(bg_flags & tintSet) || tint != new_tint) |
1006 | { |
972 | { |
1007 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
973 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
1008 | tint = new_tint; |
974 | tint = new_tint; |
1009 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
975 | bg_flags = (bg_flags & ~tintFlags) | new_flags | tintSet; |
1010 | return true; |
976 | return true; |
1011 | } |
977 | } |
1012 | |
978 | |
1013 | return false; |
979 | return false; |
1014 | } |
980 | } |
1015 | |
981 | |
1016 | bool |
982 | bool |
1017 | bgPixmap_t::set_shade (const char *shade_str) |
983 | rxvt_term::bg_set_shade (const char *shade_str) |
1018 | { |
984 | { |
1019 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
985 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
1020 | |
986 | |
1021 | clamp_it (new_shade, -100, 200); |
987 | clamp_it (new_shade, -100, 200); |
1022 | if (new_shade < 0) |
988 | if (new_shade < 0) |
1023 | new_shade = 200 - (100 + new_shade); |
989 | new_shade = 200 - (100 + new_shade); |
1024 | |
990 | |
1025 | if (new_shade != shade) |
991 | if (new_shade != shade) |
1026 | { |
992 | { |
1027 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
993 | unsigned long new_flags = compute_tint_shade_flags ((bg_flags & tintSet) ? &tint : NULL, new_shade); |
1028 | shade = new_shade; |
994 | shade = new_shade; |
1029 | flags = (flags & ~tintFlags) | new_flags; |
995 | bg_flags = (bg_flags & ~tintFlags) | new_flags; |
1030 | return true; |
996 | return true; |
1031 | } |
997 | } |
1032 | |
998 | |
1033 | return false; |
999 | return false; |
1034 | } |
1000 | } |
… | |
… | |
1055 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1021 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1056 | } |
1022 | } |
1057 | #endif |
1023 | #endif |
1058 | |
1024 | |
1059 | bool |
1025 | bool |
1060 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1026 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1061 | { |
1027 | { |
1062 | bool ret = false; |
1028 | bool ret = false; |
1063 | #if XRENDER |
1029 | #if XRENDER |
1064 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1030 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1065 | double *kernel = (double *)malloc (size * sizeof (double)); |
1031 | double *kernel = (double *)malloc (size * sizeof (double)); |
1066 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1032 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1067 | |
1033 | |
1068 | Display *dpy = target->dpy; |
|
|
1069 | XRenderPictureAttributes pa; |
1034 | XRenderPictureAttributes pa; |
1070 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1035 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1071 | |
1036 | |
1072 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1037 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1073 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1038 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
… | |
… | |
1093 | |
1058 | |
1094 | if (v_blurRadius) |
1059 | if (v_blurRadius) |
1095 | { |
1060 | { |
1096 | size = v_blurRadius * 2 + 1; |
1061 | size = v_blurRadius * 2 + 1; |
1097 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1062 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1098 | swap (params[0], params[1]); |
1063 | ::swap (params[0], params[1]); |
1099 | |
1064 | |
1100 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1065 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1101 | XRenderComposite (dpy, |
1066 | XRenderComposite (dpy, |
1102 | PictOpSrc, |
1067 | PictOpSrc, |
1103 | src, |
1068 | src, |
… | |
… | |
1119 | #endif |
1084 | #endif |
1120 | return ret; |
1085 | return ret; |
1121 | } |
1086 | } |
1122 | |
1087 | |
1123 | bool |
1088 | bool |
1124 | bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1089 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1125 | { |
1090 | { |
1126 | Display *dpy = target->dpy; |
|
|
1127 | bool ret = false; |
1091 | bool ret = false; |
1128 | |
1092 | |
1129 | if (flags & tintWholesome) |
1093 | if (bg_flags & tintWholesome) |
1130 | { |
1094 | { |
1131 | XGCValues gcv; |
1095 | XGCValues gcv; |
1132 | GC gc; |
1096 | GC gc; |
1133 | |
1097 | |
1134 | /* In this case we can tint image server-side getting significant |
1098 | /* In this case we can tint image server-side getting significant |
… | |
… | |
1148 | else |
1112 | else |
1149 | { |
1113 | { |
1150 | # if XRENDER |
1114 | # if XRENDER |
1151 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1115 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1152 | |
1116 | |
1153 | if (flags & tintSet) |
1117 | if (bg_flags & tintSet) |
1154 | tint.get (c); |
1118 | tint.get (c); |
1155 | |
1119 | |
1156 | if (shade <= 100) |
1120 | if (shade <= 100) |
1157 | { |
1121 | { |
1158 | c.r = (c.r * shade) / 100; |
1122 | c.r = (c.r * shade) / 100; |
… | |
… | |
1223 | * Builds a pixmap of the same size as the terminal window that contains |
1187 | * Builds a pixmap of the same size as the terminal window that contains |
1224 | * the tiled portion of the root pixmap that is supposed to be covered by |
1188 | * the tiled portion of the root pixmap that is supposed to be covered by |
1225 | * our window. |
1189 | * our window. |
1226 | */ |
1190 | */ |
1227 | unsigned long |
1191 | unsigned long |
1228 | bgPixmap_t::make_transparency_pixmap () |
1192 | rxvt_term::make_transparency_pixmap () |
1229 | { |
1193 | { |
1230 | unsigned long result = 0; |
1194 | unsigned long result = 0; |
1231 | |
|
|
1232 | if (target == NULL) |
|
|
1233 | return 0; |
|
|
1234 | |
1195 | |
1235 | /* root dimensions may change from call to call - but Display structure should |
1196 | /* root dimensions may change from call to call - but Display structure should |
1236 | * be always up-to-date, so let's use it : |
1197 | * be always up-to-date, so let's use it : |
1237 | */ |
1198 | */ |
1238 | int screen = target->display->screen; |
1199 | int screen = display->screen; |
1239 | Display *dpy = target->dpy; |
|
|
1240 | int root_depth = DefaultDepth (dpy, screen); |
1200 | int root_depth = DefaultDepth (dpy, screen); |
1241 | int root_width = DisplayWidth (dpy, screen); |
1201 | int root_width = DisplayWidth (dpy, screen); |
1242 | int root_height = DisplayHeight (dpy, screen); |
1202 | int root_height = DisplayHeight (dpy, screen); |
1243 | unsigned int root_pmap_width, root_pmap_height; |
1203 | unsigned int root_pmap_width, root_pmap_height; |
1244 | int window_width = target->szHint.width; |
1204 | int window_width = szHint.width; |
1245 | int window_height = target->szHint.height; |
1205 | int window_height = szHint.height; |
1246 | int sx, sy; |
1206 | int sx, sy; |
1247 | XGCValues gcv; |
1207 | XGCValues gcv; |
1248 | GC gc; |
1208 | GC gc; |
1249 | |
1209 | |
1250 | sx = target_x; |
1210 | sx = target_x; |
… | |
… | |
1260 | { |
1220 | { |
1261 | Window wdummy; |
1221 | Window wdummy; |
1262 | int idummy; |
1222 | int idummy; |
1263 | unsigned int udummy; |
1223 | unsigned int udummy; |
1264 | |
1224 | |
1265 | target->allowedxerror = -1; |
1225 | allowedxerror = -1; |
1266 | |
1226 | |
1267 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
1227 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
1268 | root_pixmap = None; |
1228 | root_pixmap = None; |
1269 | |
1229 | |
1270 | target->allowedxerror = 0; |
1230 | allowedxerror = 0; |
1271 | } |
1231 | } |
1272 | |
1232 | |
1273 | Pixmap recoded_root_pmap = root_pixmap; |
1233 | Pixmap recoded_root_pmap = root_pixmap; |
1274 | |
1234 | |
1275 | if (root_pixmap != None && root_depth != target->depth) |
1235 | if (root_pixmap != None && root_depth != depth) |
1276 | { |
1236 | { |
1277 | #if XRENDER |
1237 | #if XRENDER |
1278 | if (flags & HAS_RENDER) |
1238 | if (bg_flags & HAS_RENDER) |
1279 | { |
1239 | { |
1280 | XRenderPictureAttributes pa; |
1240 | XRenderPictureAttributes pa; |
1281 | |
1241 | |
1282 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1242 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1283 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1243 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1284 | |
1244 | |
1285 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
1245 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1286 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
1246 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1287 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1247 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1288 | |
1248 | |
1289 | if (src && dst) |
1249 | if (src && dst) |
1290 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1250 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1291 | else |
1251 | else |
… | |
… | |
1303 | } |
1263 | } |
1304 | |
1264 | |
1305 | if (root_pixmap == None) |
1265 | if (root_pixmap == None) |
1306 | return 0; |
1266 | return 0; |
1307 | |
1267 | |
1308 | if (pixmap == None |
1268 | if (bg_pixmap == None |
1309 | || pmap_width != window_width |
1269 | || bg_pmap_width != window_width |
1310 | || pmap_height != window_height) |
1270 | || bg_pmap_height != window_height) |
1311 | { |
1271 | { |
1312 | if (pixmap) |
1272 | if (bg_pixmap) |
1313 | XFreePixmap (target->dpy, pixmap); |
1273 | XFreePixmap (dpy, bg_pixmap); |
1314 | pixmap = XCreatePixmap (target->dpy, target->vt, window_width, window_height, target->depth); |
1274 | bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); |
1315 | pmap_width = window_width; |
1275 | bg_pmap_width = window_width; |
1316 | pmap_height = window_height; |
1276 | bg_pmap_height = window_height; |
1317 | } |
1277 | } |
1318 | |
1278 | |
1319 | if (pixmap == None) |
1279 | if (bg_pixmap == None) |
1320 | return 0; |
1280 | return 0; |
1321 | |
1281 | |
1322 | /* straightforward pixmap copy */ |
1282 | /* straightforward pixmap copy */ |
1323 | while (sx < 0) sx += (int)root_width; |
1283 | while (sx < 0) sx += (int)root_width; |
1324 | while (sy < 0) sy += (int)root_height; |
1284 | while (sy < 0) sy += (int)root_height; |
1325 | |
1285 | |
1326 | gcv.tile = recoded_root_pmap; |
1286 | gcv.tile = recoded_root_pmap; |
1327 | gcv.fill_style = FillTiled; |
1287 | gcv.fill_style = FillTiled; |
1328 | gcv.ts_x_origin = -sx; |
1288 | gcv.ts_x_origin = -sx; |
1329 | gcv.ts_y_origin = -sy; |
1289 | gcv.ts_y_origin = -sy; |
1330 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1290 | gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1331 | |
1291 | |
1332 | if (gc) |
1292 | if (gc) |
1333 | { |
1293 | { |
1334 | XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height); |
1294 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1335 | result |= transpPmapTiled; |
1295 | result |= isValid | (bg_flags & effectsFlags); |
1336 | XFreeGC (dpy, gc); |
1296 | XFreeGC (dpy, gc); |
1337 | |
1297 | |
1338 | if (!(flags & CLIENT_RENDER)) |
1298 | if (!(bg_flags & CLIENT_RENDER)) |
1339 | { |
1299 | { |
1340 | if ((flags & blurNeeded) |
1300 | if ((bg_flags & blurNeeded) |
1341 | && (flags & HAS_RENDER_CONV)) |
1301 | && (bg_flags & HAS_RENDER_CONV)) |
1342 | { |
1302 | { |
1343 | if (blur_pixmap (pixmap, target->visual, window_width, window_height)) |
1303 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) |
1344 | result |= transpPmapBlurred; |
1304 | result &= ~blurNeeded; |
1345 | } |
1305 | } |
1346 | if ((flags & tintNeeded) |
1306 | if ((bg_flags & tintNeeded) |
1347 | && (flags & (tintWholesome | HAS_RENDER))) |
1307 | && (bg_flags & (tintWholesome | HAS_RENDER))) |
1348 | { |
1308 | { |
1349 | if (tint_pixmap (pixmap, target->visual, window_width, window_height)) |
1309 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1350 | result |= transpPmapTinted; |
1310 | result &= ~tintNeeded; |
1351 | } |
1311 | } |
1352 | } /* server side rendering completed */ |
1312 | } /* server side rendering completed */ |
1353 | } |
1313 | } |
1354 | |
1314 | |
1355 | if (recoded_root_pmap != root_pixmap) |
1315 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1357 | |
1317 | |
1358 | return result; |
1318 | return result; |
1359 | } |
1319 | } |
1360 | |
1320 | |
1361 | void |
1321 | void |
1362 | bgPixmap_t::set_root_pixmap () |
1322 | rxvt_term::bg_set_root_pixmap () |
1363 | { |
1323 | { |
1364 | Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]); |
1324 | Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1365 | if (new_root_pixmap == None) |
1325 | if (new_root_pixmap == None) |
1366 | new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]); |
1326 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1367 | |
1327 | |
1368 | root_pixmap = new_root_pixmap; |
1328 | root_pixmap = new_root_pixmap; |
1369 | } |
1329 | } |
1370 | # endif /* ENABLE_TRANSPARENCY */ |
1330 | # endif /* ENABLE_TRANSPARENCY */ |
1371 | |
1331 | |
1372 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1332 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1373 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
1333 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
1374 | # endif |
1334 | # endif |
1375 | |
1335 | |
1376 | bool |
1336 | bool |
1377 | bgPixmap_t::render () |
1337 | rxvt_term::bg_render () |
1378 | { |
1338 | { |
1379 | unsigned long background_flags = 0; |
1339 | unsigned long tr_flags = 0; |
1380 | |
1340 | |
1381 | if (target == NULL) |
|
|
1382 | return false; |
|
|
1383 | |
|
|
1384 | invalidate (); |
1341 | bg_invalidate (); |
1385 | # ifdef ENABLE_TRANSPARENCY |
1342 | # ifdef ENABLE_TRANSPARENCY |
1386 | if (flags & isTransparent) |
1343 | if (bg_flags & isTransparent) |
1387 | { |
1344 | { |
1388 | /* we need to re-generate transparency pixmap in that case ! */ |
1345 | /* we need to re-generate transparency pixmap in that case ! */ |
1389 | background_flags = make_transparency_pixmap (); |
1346 | tr_flags = make_transparency_pixmap (); |
1390 | if (background_flags == 0) |
1347 | if (tr_flags == 0) |
1391 | return false; |
1348 | return false; |
1392 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1349 | else if (!(tr_flags & effectsFlags)) |
1393 | flags |= isValid; |
1350 | bg_flags |= isValid; |
1394 | } |
1351 | } |
1395 | # endif |
1352 | # endif |
1396 | |
1353 | |
1397 | # ifdef BG_IMAGE_FROM_FILE |
1354 | # ifdef BG_IMAGE_FROM_FILE |
1398 | if (have_image |
1355 | if (have_image |
1399 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1356 | || (tr_flags & effectsFlags)) |
1400 | { |
1357 | { |
1401 | if (render_image (background_flags)) |
1358 | if (render_image (tr_flags)) |
1402 | flags |= isValid; |
1359 | bg_flags |= isValid; |
1403 | } |
1360 | } |
1404 | # endif |
1361 | # endif |
1405 | |
1362 | |
1406 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1363 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1407 | XImage *result = NULL; |
1364 | XImage *result = NULL; |
1408 | |
1365 | |
1409 | if (background_flags && !(flags & isValid)) |
1366 | if (tr_flags && !(bg_flags & isValid)) |
1410 | { |
1367 | { |
1411 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1368 | result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1412 | } |
1369 | } |
1413 | |
1370 | |
1414 | if (result) |
1371 | if (result) |
1415 | { |
1372 | { |
1416 | /* our own client-side tinting */ |
1373 | /* our own client-side tinting */ |
1417 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1374 | if (tr_flags & tintNeeded) |
1418 | { |
1375 | { |
1419 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1376 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1420 | if (flags & tintSet) |
1377 | if (bg_flags & tintSet) |
1421 | tint.get (c); |
1378 | tint.get (c); |
1422 | shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1379 | shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); |
1423 | } |
1380 | } |
1424 | |
1381 | |
1425 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1382 | GC gc = XCreateGC (dpy, vt, 0UL, NULL); |
1426 | |
1383 | |
1427 | if (gc) |
1384 | if (gc) |
1428 | { |
1385 | { |
1429 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1386 | XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1430 | |
1387 | |
1431 | XFreeGC (target->dpy, gc); |
1388 | XFreeGC (dpy, gc); |
1432 | flags |= isValid; |
1389 | bg_flags |= isValid; |
1433 | } |
1390 | } |
1434 | |
1391 | |
1435 | XDestroyImage (result); |
1392 | XDestroyImage (result); |
1436 | } |
1393 | } |
1437 | # endif |
1394 | # endif |
1438 | |
1395 | |
1439 | if (!(flags & isValid)) |
1396 | if (!(bg_flags & isValid)) |
1440 | { |
1397 | { |
1441 | if (pixmap != None) |
1398 | if (bg_pixmap != None) |
1442 | { |
1399 | { |
1443 | XFreePixmap (target->dpy, pixmap); |
1400 | XFreePixmap (dpy, bg_pixmap); |
1444 | pixmap = None; |
1401 | bg_pixmap = None; |
1445 | } |
1402 | } |
1446 | } |
1403 | } |
1447 | |
1404 | |
1448 | target->scr_recolour (false); |
1405 | scr_recolour (false); |
1449 | flags |= hasChanged; |
1406 | bg_flags |= hasChanged; |
1450 | |
1407 | |
1451 | valid_since = ev::now (); |
1408 | bg_valid_since = ev::now (); |
1452 | |
1409 | |
1453 | return true; |
1410 | return true; |
1454 | } |
1411 | } |
1455 | |
1412 | |
1456 | void |
1413 | void |
1457 | bgPixmap_t::set_target (rxvt_term *new_target) |
1414 | rxvt_term::bg_init () |
1458 | { |
1415 | { |
1459 | target = new_target; |
1416 | #ifdef ENABLE_TRANSPARENCY |
|
|
1417 | shade = 100; |
|
|
1418 | #endif |
1460 | |
1419 | |
1461 | flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
1420 | bg_flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
1462 | #if XRENDER |
1421 | #if XRENDER |
1463 | int major, minor; |
1422 | int major, minor; |
1464 | if (XRenderQueryVersion (target->dpy, &major, &minor)) |
1423 | if (XRenderQueryVersion (dpy, &major, &minor)) |
1465 | flags |= HAS_RENDER; |
1424 | bg_flags |= HAS_RENDER; |
1466 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
1425 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
1467 | if (filters) |
1426 | if (filters) |
1468 | { |
1427 | { |
1469 | for (int i = 0; i < filters->nfilter; i++) |
1428 | for (int i = 0; i < filters->nfilter; i++) |
1470 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1429 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1471 | flags |= HAS_RENDER_CONV; |
1430 | bg_flags |= HAS_RENDER_CONV; |
1472 | |
1431 | |
1473 | XFree (filters); |
1432 | XFree (filters); |
1474 | } |
1433 | } |
1475 | #endif |
1434 | #endif |
1476 | } |
1435 | } |