1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: background.C - former xpm.C |
2 | * File: background.C - former xpm.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
8 | * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> |
9 | * |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License as published by |
11 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
46 | * W and H are percentages of the terminal window size. |
46 | * W and H are percentages of the terminal window size. |
47 | * X and Y are also percentages; e.g., +50+50 centers |
47 | * X and Y are also percentages; e.g., +50+50 centers |
48 | * the image in the window. |
48 | * the image in the window. |
49 | * |
49 | * |
50 | * Pixmap Operations : (should be prepended by a colon) |
50 | * Pixmap Operations : (should be prepended by a colon) |
51 | * tile Tile image. Scaling/position modifiers above will affect |
|
|
52 | * the tile size and origin. |
|
|
53 | * propscale When scaling, scale proportionally. That is, maintain the |
|
|
54 | * proper aspect ratio for the image. Any portion of the |
|
|
55 | * background not covered by the image is filled with the |
|
|
56 | * current background color. |
|
|
57 | * hscale Scale horizontally, tile vertically ? |
|
|
58 | * vscale Tile horizontally, scale vertically ? |
|
|
59 | * scale Scale both up and down |
|
|
60 | * auto Same as 100x100+50+50 |
|
|
61 | */ |
51 | */ |
62 | |
52 | |
63 | #ifdef HAVE_BG_PIXMAP |
53 | #ifdef HAVE_BG_PIXMAP |
64 | void |
54 | void |
65 | rxvt_term::bg_destroy () |
55 | rxvt_term::bg_destroy () |
66 | { |
56 | { |
67 | #ifdef HAVE_AFTERIMAGE |
57 | #ifdef HAVE_AFTERIMAGE |
68 | if (original_asim) |
58 | if (original_asim) |
69 | safe_asimage_destroy (original_asim); |
59 | safe_asimage_destroy (original_asim); |
|
|
60 | if (asv) |
|
|
61 | destroy_asvisual (asv, 0); |
|
|
62 | if (asimman) |
|
|
63 | destroy_image_manager (asimman, 0); |
70 | #endif |
64 | #endif |
71 | |
65 | |
72 | #ifdef HAVE_PIXBUF |
66 | #ifdef HAVE_PIXBUF |
73 | if (pixbuf) |
67 | if (pixbuf) |
74 | g_object_unref (pixbuf); |
68 | g_object_unref (pixbuf); |
… | |
… | |
254 | { |
248 | { |
255 | char **arr = rxvt_strsplit (':', ops + 1); |
249 | char **arr = rxvt_strsplit (':', ops + 1); |
256 | |
250 | |
257 | for (int i = 0; arr[i]; i++) |
251 | for (int i = 0; arr[i]; i++) |
258 | { |
252 | { |
|
|
253 | if (!strcasecmp (arr[i], "style=tiled")) |
|
|
254 | { |
|
|
255 | new_flags = BG_TILE; |
|
|
256 | w = h = noScale; |
|
|
257 | x = y = 0; |
|
|
258 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
259 | } |
|
|
260 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
|
|
261 | { |
|
|
262 | new_flags = BG_PROP_SCALE; |
|
|
263 | x = y = centerAlign; |
|
|
264 | geom_flags = XValue|YValue; |
|
|
265 | } |
|
|
266 | else if (!strcasecmp (arr[i], "style=stretched")) |
|
|
267 | { |
|
|
268 | new_flags = 0; |
|
|
269 | w = h = windowScale; |
|
|
270 | geom_flags = WidthValue|HeightValue; |
|
|
271 | } |
|
|
272 | else if (!strcasecmp (arr[i], "style=centered")) |
|
|
273 | { |
|
|
274 | new_flags = 0; |
|
|
275 | w = h = noScale; |
|
|
276 | x = y = centerAlign; |
|
|
277 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
278 | } |
|
|
279 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
|
|
280 | { |
|
|
281 | new_flags = BG_TILE|BG_ROOT_ALIGN; |
|
|
282 | w = h = noScale; |
|
|
283 | geom_flags = WidthValue|HeightValue; |
|
|
284 | } |
|
|
285 | else if (!strcasecmp (arr[i], "op=tile")) |
|
|
286 | new_flags |= BG_TILE; |
|
|
287 | else if (!strcasecmp (arr[i], "op=pscale")) |
|
|
288 | new_flags |= BG_PROP_SCALE; |
|
|
289 | else if (!strcasecmp (arr[i], "op=root")) |
|
|
290 | new_flags |= BG_ROOT_ALIGN; |
|
|
291 | |
|
|
292 | // deprecated |
259 | if (!strcasecmp (arr[i], "tile")) |
293 | else if (!strcasecmp (arr[i], "tile")) |
260 | { |
294 | { |
|
|
295 | new_flags |= BG_TILE; |
261 | w = h = noScale; |
296 | w = h = noScale; |
262 | geom_flags |= WidthValue|HeightValue; |
297 | geom_flags |= WidthValue|HeightValue; |
263 | } |
298 | } |
264 | else if (!strcasecmp (arr[i], "propscale")) |
299 | else if (!strcasecmp (arr[i], "propscale")) |
265 | { |
300 | { |
266 | new_flags |= BG_PROP_SCALE; |
301 | new_flags |= BG_PROP_SCALE; |
267 | } |
302 | } |
268 | else if (!strcasecmp (arr[i], "hscale")) |
303 | else if (!strcasecmp (arr[i], "hscale")) |
269 | { |
304 | { |
|
|
305 | new_flags |= BG_TILE; |
270 | if (w == 0) w = windowScale; |
306 | w = windowScale; |
271 | |
|
|
272 | h = noScale; |
307 | h = noScale; |
273 | geom_flags |= WidthValue|HeightValue; |
308 | geom_flags |= WidthValue|HeightValue; |
274 | } |
309 | } |
275 | else if (!strcasecmp (arr[i], "vscale")) |
310 | else if (!strcasecmp (arr[i], "vscale")) |
276 | { |
311 | { |
|
|
312 | new_flags |= BG_TILE; |
277 | if (h == 0) h = windowScale; |
313 | h = windowScale; |
278 | |
|
|
279 | w = noScale; |
314 | w = noScale; |
280 | geom_flags |= WidthValue|HeightValue; |
315 | geom_flags |= WidthValue|HeightValue; |
281 | } |
316 | } |
282 | else if (!strcasecmp (arr[i], "scale")) |
317 | else if (!strcasecmp (arr[i], "scale")) |
283 | { |
318 | { |
284 | if (h == 0) h = windowScale; |
|
|
285 | if (w == 0) w = windowScale; |
319 | w = h = windowScale; |
286 | |
|
|
287 | geom_flags |= WidthValue|HeightValue; |
320 | geom_flags |= WidthValue|HeightValue; |
288 | } |
321 | } |
289 | else if (!strcasecmp (arr[i], "auto")) |
322 | else if (!strcasecmp (arr[i], "auto")) |
290 | { |
323 | { |
291 | w = h = windowScale; |
324 | w = h = windowScale; |
292 | x = y = centerAlign; |
325 | x = y = centerAlign; |
293 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
326 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
294 | } |
327 | } |
295 | else if (!strcasecmp (arr[i], "root")) |
328 | else if (!strcasecmp (arr[i], "root")) |
296 | { |
329 | { |
297 | new_flags |= BG_ROOT_ALIGN; |
330 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
298 | w = h = noScale; |
331 | w = h = noScale; |
299 | geom_flags |= WidthValue|HeightValue; |
332 | geom_flags |= WidthValue|HeightValue; |
300 | } |
333 | } |
301 | } /* done parsing ops */ |
334 | } /* done parsing ops */ |
302 | |
335 | |
… | |
… | |
349 | x = make_align_position (h_align, target_width, w); |
382 | x = make_align_position (h_align, target_width, w); |
350 | y = make_align_position (v_align, target_height, h); |
383 | y = make_align_position (v_align, target_height, h); |
351 | } |
384 | } |
352 | |
385 | |
353 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
386 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
|
|
387 | if (!(bg_flags & BG_TILE) |
354 | if ((bg_flags & BG_PROP_SCALE) || h_scale || v_scale |
388 | || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale |
355 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
389 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
356 | || w > target_width || h > target_height) |
390 | || w > target_width || h > target_height) |
357 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
391 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
358 | } |
392 | } |
359 | |
393 | |
… | |
… | |
451 | 100, ASIMAGE_QUALITY_DEFAULT); |
485 | 100, ASIMAGE_QUALITY_DEFAULT); |
452 | } |
486 | } |
453 | |
487 | |
454 | if (background == NULL) |
488 | if (background == NULL) |
455 | { |
489 | { |
456 | if (h_scale == 0 || v_scale == 0) |
490 | if (bg_flags & BG_TILE) |
457 | { |
491 | { |
458 | /* if tiling - pixmap has to be sized exactly as the image, |
492 | /* if tiling - pixmap has to be sized exactly as the image, |
459 | but there is no need to make it bigger than the window! */ |
493 | but there is no need to make it bigger than the window! */ |
460 | new_pmap_width = min (result->width, target_width); |
494 | new_pmap_width = min (result->width, target_width); |
461 | new_pmap_height = min (result->height, target_height); |
495 | new_pmap_height = min (result->height, target_height); |
… | |
… | |
486 | layers[0].clip_width = target_width; |
520 | layers[0].clip_width = target_width; |
487 | layers[0].clip_height = target_height; |
521 | layers[0].clip_height = target_height; |
488 | layers[0].tint = background_tint; |
522 | layers[0].tint = background_tint; |
489 | layers[1].im = result; |
523 | layers[1].im = result; |
490 | |
524 | |
491 | if (h_scale == 0 || v_scale == 0) |
525 | if (bg_flags & BG_TILE) |
492 | { |
526 | { |
493 | /* tile horizontally */ |
527 | /* tile horizontally */ |
494 | while (x > 0) x -= (int)result->width; |
528 | while (x > 0) x -= (int)result->width; |
495 | layers[1].dst_x = x; |
529 | layers[1].dst_x = x; |
496 | layers[1].clip_width = result->width+target_width; |
530 | layers[1].clip_width = result->width+target_width; |
… | |
… | |
500 | /* clip horizontally */ |
534 | /* clip horizontally */ |
501 | layers[1].dst_x = x; |
535 | layers[1].dst_x = x; |
502 | layers[1].clip_width = result->width; |
536 | layers[1].clip_width = result->width; |
503 | } |
537 | } |
504 | |
538 | |
505 | if (h_scale == 0 || v_scale == 0) |
539 | if (bg_flags & BG_TILE) |
506 | { |
540 | { |
507 | while (y > 0) y -= (int)result->height; |
541 | while (y > 0) y -= (int)result->height; |
508 | layers[1].dst_y = y; |
542 | layers[1].dst_y = y; |
509 | layers[1].clip_height = result->height + target_height; |
543 | layers[1].clip_height = result->height + target_height; |
510 | } |
544 | } |
… | |
… | |
560 | |
594 | |
561 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
595 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
562 | int dst_width = result->width, dst_height = result->height; |
596 | int dst_width = result->width, dst_height = result->height; |
563 | if (background == NULL) |
597 | if (background == NULL) |
564 | { |
598 | { |
565 | if (!(h_scale == 0 || v_scale == 0)) |
599 | if (!(bg_flags & BG_TILE)) |
566 | { |
600 | { |
567 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
601 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
568 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
602 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
569 | } |
603 | } |
570 | |
604 | |
… | |
… | |
616 | else if (depth == 15 || depth == 16) |
650 | else if (depth == 15 || depth == 16) |
617 | bytes_per_pixel = 2; |
651 | bytes_per_pixel = 2; |
618 | else |
652 | else |
619 | return false; |
653 | return false; |
620 | |
654 | |
621 | width_r = rxvt_popcount (visual->red_mask); |
655 | width_r = ecb_popcount32 (visual->red_mask); |
622 | width_g = rxvt_popcount (visual->green_mask); |
656 | width_g = ecb_popcount32 (visual->green_mask); |
623 | width_b = rxvt_popcount (visual->blue_mask); |
657 | width_b = ecb_popcount32 (visual->blue_mask); |
624 | |
658 | |
625 | if (width_r > 8 || width_g > 8 || width_b > 8) |
659 | if (width_r > 8 || width_g > 8 || width_b > 8) |
626 | return false; |
660 | return false; |
627 | |
661 | |
628 | sh_r = rxvt_ctz (visual->red_mask); |
662 | sh_r = ecb_ctz32 (visual->red_mask); |
629 | sh_g = rxvt_ctz (visual->green_mask); |
663 | sh_g = ecb_ctz32 (visual->green_mask); |
630 | sh_b = rxvt_ctz (visual->blue_mask); |
664 | sh_b = ecb_ctz32 (visual->blue_mask); |
631 | |
665 | |
632 | if (width > INT_MAX / height / bytes_per_pixel) |
666 | if (width > INT_MAX / height / bytes_per_pixel) |
633 | return false; |
667 | return false; |
634 | |
668 | |
635 | data = (char *)malloc (width * height * bytes_per_pixel); |
669 | data = (char *)malloc (width * height * bytes_per_pixel); |
… | |
… | |
642 | { |
676 | { |
643 | free (data); |
677 | free (data); |
644 | return false; |
678 | return false; |
645 | } |
679 | } |
646 | |
680 | |
647 | ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
681 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
648 | |
682 | |
649 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
683 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
650 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
684 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
651 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
685 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
652 | line = data; |
686 | line = data; |
… | |
… | |
719 | result = gdk_pixbuf_scale_simple (pixbuf, |
753 | result = gdk_pixbuf_scale_simple (pixbuf, |
720 | w, h, |
754 | w, h, |
721 | GDK_INTERP_BILINEAR); |
755 | GDK_INTERP_BILINEAR); |
722 | } |
756 | } |
723 | |
757 | |
|
|
758 | if (!result) |
|
|
759 | return false; |
|
|
760 | |
724 | bool ret = false; |
761 | bool ret = false; |
725 | |
762 | |
726 | if (result) |
|
|
727 | { |
|
|
728 | XGCValues gcv; |
763 | XGCValues gcv; |
729 | GC gc; |
764 | GC gc; |
730 | Pixmap root_pmap; |
765 | Pixmap root_pmap; |
731 | |
766 | |
732 | image_width = gdk_pixbuf_get_width (result); |
767 | image_width = gdk_pixbuf_get_width (result); |
733 | image_height = gdk_pixbuf_get_height (result); |
768 | image_height = gdk_pixbuf_get_height (result); |
734 | |
769 | |
735 | if (tr_flags) |
770 | if (tr_flags) |
736 | { |
771 | { |
737 | root_pmap = bg_pixmap; |
772 | root_pmap = bg_pixmap; |
738 | bg_pixmap = None; |
773 | bg_pixmap = None; |
|
|
774 | } |
|
|
775 | else |
|
|
776 | { |
|
|
777 | if (bg_flags & BG_TILE) |
739 | } |
778 | { |
740 | else |
|
|
741 | { |
|
|
742 | if (h_scale == 0 || v_scale == 0) |
|
|
743 | { |
|
|
744 | new_pmap_width = min (image_width, target_width); |
779 | new_pmap_width = min (image_width, target_width); |
745 | new_pmap_height = min (image_height, target_height); |
780 | new_pmap_height = min (image_height, target_height); |
746 | } |
781 | } |
747 | } |
782 | } |
748 | |
783 | |
749 | if (bg_pixmap == None |
784 | if (bg_pixmap == None |
750 | || bg_pmap_width != new_pmap_width |
785 | || bg_pmap_width != new_pmap_width |
751 | || bg_pmap_height != new_pmap_height) |
786 | || bg_pmap_height != new_pmap_height) |
752 | { |
787 | { |
753 | if (bg_pixmap) |
788 | if (bg_pixmap) |
754 | XFreePixmap (dpy, bg_pixmap); |
789 | XFreePixmap (dpy, bg_pixmap); |
755 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
790 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
756 | bg_pmap_width = new_pmap_width; |
791 | bg_pmap_width = new_pmap_width; |
757 | bg_pmap_height = new_pmap_height; |
792 | bg_pmap_height = new_pmap_height; |
758 | } |
793 | } |
759 | |
794 | |
760 | gcv.foreground = pix_colors[Color_bg]; |
795 | gcv.foreground = pix_colors[Color_bg]; |
761 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
796 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
762 | |
797 | |
763 | if (h_scale == 0 || v_scale == 0) |
798 | if (gc) |
|
|
799 | { |
|
|
800 | if (bg_flags & BG_TILE) |
764 | { |
801 | { |
765 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
802 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
766 | pixbuf_to_pixmap (result, tile, gc, |
803 | pixbuf_to_pixmap (result, tile, gc, |
767 | 0, 0, |
804 | 0, 0, |
768 | 0, 0, |
805 | 0, 0, |
… | |
… | |
812 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
849 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
813 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
850 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
814 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
851 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
815 | XFreePixmap (dpy, mask_pmap); |
852 | XFreePixmap (dpy, mask_pmap); |
816 | |
853 | |
817 | if (src && dst && mask) |
|
|
818 | { |
|
|
819 | XRenderColor mask_c; |
854 | XRenderColor mask_c; |
820 | |
855 | |
821 | mask_c.alpha = 0x8000; |
856 | mask_c.alpha = 0x8000; |
822 | mask_c.red = 0; |
857 | mask_c.red = 0; |
823 | mask_c.green = 0; |
858 | mask_c.green = 0; |
824 | mask_c.blue = 0; |
859 | mask_c.blue = 0; |
825 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
860 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
826 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
861 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
827 | } |
|
|
828 | |
862 | |
829 | XRenderFreePicture (dpy, src); |
863 | XRenderFreePicture (dpy, src); |
830 | XRenderFreePicture (dpy, dst); |
864 | XRenderFreePicture (dpy, dst); |
831 | XRenderFreePicture (dpy, mask); |
865 | XRenderFreePicture (dpy, mask); |
832 | |
|
|
833 | XFreePixmap (dpy, root_pmap); |
|
|
834 | } |
866 | } |
835 | #endif |
867 | #endif |
836 | |
868 | |
837 | if (result != pixbuf) |
|
|
838 | g_object_unref (result); |
|
|
839 | |
|
|
840 | XFreeGC (dpy, gc); |
869 | XFreeGC (dpy, gc); |
841 | |
870 | |
842 | ret = true; |
871 | ret = true; |
843 | } |
872 | } |
|
|
873 | |
|
|
874 | if (result != pixbuf) |
|
|
875 | g_object_unref (result); |
|
|
876 | |
|
|
877 | if (tr_flags) |
|
|
878 | XFreePixmap (dpy, root_pmap); |
844 | |
879 | |
845 | return ret; |
880 | return ret; |
846 | } |
881 | } |
847 | # endif /* HAVE_PIXBUF */ |
882 | # endif /* HAVE_PIXBUF */ |
848 | |
883 | |
… | |
… | |
939 | bg_flags |= BG_NEEDS_BLUR; |
974 | bg_flags |= BG_NEEDS_BLUR; |
940 | |
975 | |
941 | return changed; |
976 | return changed; |
942 | } |
977 | } |
943 | |
978 | |
944 | static inline unsigned long |
979 | void |
945 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
980 | rxvt_term::set_tint_shade_flags () |
946 | { |
981 | { |
947 | unsigned long flags = 0; |
|
|
948 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
982 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
949 | bool has_shade = shade != 100; |
983 | bool has_shade = shade != 100; |
950 | |
984 | |
951 | if (tint) |
985 | bg_flags &= ~BG_TINT_FLAGS; |
|
|
986 | |
|
|
987 | if (bg_flags & BG_TINT_SET) |
952 | { |
988 | { |
953 | tint->get (c); |
989 | tint.get (c); |
954 | if (!has_shade |
990 | if (!has_shade |
955 | && (c.r <= 0x00ff || c.r >= 0xff00) |
991 | && (c.r <= 0x00ff || c.r >= 0xff00) |
956 | && (c.g <= 0x00ff || c.g >= 0xff00) |
992 | && (c.g <= 0x00ff || c.g >= 0xff00) |
957 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
993 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
958 | flags |= rxvt_term::BG_TINT_BITAND; |
994 | bg_flags |= BG_TINT_BITAND; |
959 | } |
995 | } |
960 | |
996 | |
961 | if (has_shade || tint) |
997 | if (has_shade || (bg_flags & BG_TINT_SET)) |
962 | flags |= rxvt_term::BG_NEEDS_TINT; |
998 | bg_flags |= BG_NEEDS_TINT; |
963 | |
|
|
964 | return flags; |
|
|
965 | } |
999 | } |
966 | |
1000 | |
967 | bool |
1001 | bool |
968 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
1002 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
969 | { |
1003 | { |
970 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
1004 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
971 | { |
1005 | { |
972 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
|
|
973 | tint = new_tint; |
1006 | tint = new_tint; |
974 | bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET; |
1007 | bg_flags |= BG_TINT_SET; |
|
|
1008 | set_tint_shade_flags (); |
975 | return true; |
1009 | return true; |
976 | } |
1010 | } |
977 | |
1011 | |
978 | return false; |
1012 | return false; |
979 | } |
1013 | } |
… | |
… | |
987 | if (new_shade < 0) |
1021 | if (new_shade < 0) |
988 | new_shade = 200 - (100 + new_shade); |
1022 | new_shade = 200 - (100 + new_shade); |
989 | |
1023 | |
990 | if (new_shade != shade) |
1024 | if (new_shade != shade) |
991 | { |
1025 | { |
992 | unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade); |
|
|
993 | shade = new_shade; |
1026 | shade = new_shade; |
994 | bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags; |
1027 | set_tint_shade_flags (); |
995 | return true; |
1028 | return true; |
996 | } |
1029 | } |
997 | |
1030 | |
998 | return false; |
1031 | return false; |
999 | } |
1032 | } |
… | |
… | |
1034 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1067 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1035 | |
1068 | |
1036 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1069 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1037 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1070 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1038 | |
1071 | |
1039 | if (kernel && params && src && dst) |
1072 | if (kernel && params) |
1040 | { |
1073 | { |
1041 | if (h_blurRadius) |
1074 | if (h_blurRadius) |
1042 | { |
1075 | { |
1043 | size = h_blurRadius * 2 + 1; |
1076 | size = h_blurRadius * 2 + 1; |
1044 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
1077 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
… | |
… | |
1109 | } |
1142 | } |
1110 | } |
1143 | } |
1111 | else |
1144 | else |
1112 | { |
1145 | { |
1113 | # if XRENDER |
1146 | # if XRENDER |
1114 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1147 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1115 | |
1148 | |
1116 | if (bg_flags & BG_TINT_SET) |
1149 | if (bg_flags & BG_TINT_SET) |
1117 | tint.get (c); |
1150 | tint.get (c); |
1118 | |
1151 | |
1119 | if (shade <= 100) |
1152 | if (shade <= 100) |
1120 | { |
1153 | { |
1121 | c.r = (c.r * shade) / 100; |
1154 | c.r = c.r * shade / 100; |
1122 | c.g = (c.g * shade) / 100; |
1155 | c.g = c.g * shade / 100; |
1123 | c.b = (c.b * shade) / 100; |
1156 | c.b = c.b * shade / 100; |
1124 | } |
1157 | } |
1125 | else |
1158 | else |
1126 | { |
1159 | { |
1127 | c.r = (c.r * (200 - shade)) / 100; |
1160 | c.r = c.r * (200 - shade) / 100; |
1128 | c.g = (c.g * (200 - shade)) / 100; |
1161 | c.g = c.g * (200 - shade) / 100; |
1129 | c.b = (c.b * (200 - shade)) / 100; |
1162 | c.b = c.b * (200 - shade) / 100; |
1130 | } |
1163 | } |
1131 | |
1164 | |
1132 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1165 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1133 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1166 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1134 | XRenderPictureAttributes pa; |
1167 | XRenderPictureAttributes pa; |
… | |
… | |
1141 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1174 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1142 | XFreePixmap (dpy, overlay_pmap); |
1175 | XFreePixmap (dpy, overlay_pmap); |
1143 | |
1176 | |
1144 | pa.component_alpha = True; |
1177 | pa.component_alpha = True; |
1145 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1178 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1146 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
1179 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); |
1147 | XFreePixmap (dpy, mask_pmap); |
1180 | XFreePixmap (dpy, mask_pmap); |
1148 | |
1181 | |
1149 | if (mask_pic && overlay_pic && back_pic) |
|
|
1150 | { |
|
|
1151 | XRenderColor mask_c; |
1182 | XRenderColor mask_c; |
1152 | |
1183 | |
1153 | mask_c.red = mask_c.green = mask_c.blue = 0; |
|
|
1154 | mask_c.alpha = 0xffff; |
1184 | mask_c.alpha = 0xffff; |
|
|
1185 | mask_c.red = |
|
|
1186 | mask_c.green = |
|
|
1187 | mask_c.blue = 0; |
|
|
1188 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1189 | |
|
|
1190 | mask_c.alpha = 0; |
|
|
1191 | mask_c.red = 0xffff - c.r; |
|
|
1192 | mask_c.green = 0xffff - c.g; |
|
|
1193 | mask_c.blue = 0xffff - c.b; |
|
|
1194 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1195 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1196 | |
|
|
1197 | if (shade > 100) |
|
|
1198 | { |
|
|
1199 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1200 | mask_c.alpha = 0; |
1155 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1201 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1156 | |
1202 | |
1157 | mask_c.alpha = 0; |
|
|
1158 | mask_c.red = 0xffff - c.r; |
|
|
1159 | mask_c.green = 0xffff - c.g; |
|
|
1160 | mask_c.blue = 0xffff - c.b; |
|
|
1161 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1162 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1163 | |
|
|
1164 | if (shade > 100) |
|
|
1165 | { |
|
|
1166 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1167 | mask_c.alpha = 0; |
|
|
1168 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1169 | |
|
|
1170 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1203 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1171 | } |
1204 | } |
1172 | |
1205 | |
1173 | ret = true; |
1206 | ret = true; |
1174 | } |
|
|
1175 | |
1207 | |
1176 | XRenderFreePicture (dpy, mask_pic); |
1208 | XRenderFreePicture (dpy, mask_pic); |
1177 | XRenderFreePicture (dpy, overlay_pic); |
1209 | XRenderFreePicture (dpy, overlay_pic); |
1178 | XRenderFreePicture (dpy, back_pic); |
1210 | XRenderFreePicture (dpy, back_pic); |
1179 | # endif |
1211 | # endif |
1180 | } |
1212 | } |
1181 | |
1213 | |
1182 | return ret; |
1214 | return ret; |
1183 | } |
1215 | } |
1184 | |
1216 | |
1185 | /* make_transparency_pixmap() |
1217 | /* |
1186 | * Builds a pixmap of the same size as the terminal window that contains |
1218 | * Builds a pixmap of the same size as the terminal window that contains |
1187 | * the tiled portion of the root pixmap that is supposed to be covered by |
1219 | * the tiled portion of the root pixmap that is supposed to be covered by |
1188 | * our window. |
1220 | * our window. |
1189 | */ |
1221 | */ |
1190 | unsigned long |
1222 | unsigned long |
… | |
… | |
1234 | if (root_pixmap != None && root_depth != depth) |
1266 | if (root_pixmap != None && root_depth != depth) |
1235 | { |
1267 | { |
1236 | #if XRENDER |
1268 | #if XRENDER |
1237 | if (bg_flags & BG_HAS_RENDER) |
1269 | if (bg_flags & BG_HAS_RENDER) |
1238 | { |
1270 | { |
|
|
1271 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
|
|
1272 | |
1239 | XRenderPictureAttributes pa; |
1273 | XRenderPictureAttributes pa; |
1240 | |
1274 | |
1241 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1275 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1242 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1276 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1243 | |
1277 | |
1244 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
|
|
1245 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1278 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1246 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1279 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1247 | |
1280 | |
1248 | if (src && dst) |
|
|
1249 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1281 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1250 | else |
|
|
1251 | { |
|
|
1252 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1253 | root_pixmap = None; |
|
|
1254 | } |
|
|
1255 | |
1282 | |
1256 | XRenderFreePicture (dpy, src); |
1283 | XRenderFreePicture (dpy, src); |
1257 | XRenderFreePicture (dpy, dst); |
1284 | XRenderFreePicture (dpy, dst); |
1258 | } |
1285 | } |
1259 | else |
1286 | else |
1260 | #endif |
1287 | #endif |
1261 | root_pixmap = None; |
1288 | recoded_root_pmap = None; |
1262 | } |
1289 | } |
1263 | |
1290 | |
1264 | if (root_pixmap == None) |
1291 | if (recoded_root_pmap == None) |
1265 | return 0; |
1292 | return 0; |
1266 | |
1293 | |
1267 | if (bg_pixmap == None |
1294 | if (bg_pixmap == None |
1268 | || bg_pmap_width != window_width |
1295 | || bg_pmap_width != window_width |
1269 | || bg_pmap_height != window_height) |
1296 | || bg_pmap_height != window_height) |
… | |
… | |
1273 | bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); |
1300 | bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); |
1274 | bg_pmap_width = window_width; |
1301 | bg_pmap_width = window_width; |
1275 | bg_pmap_height = window_height; |
1302 | bg_pmap_height = window_height; |
1276 | } |
1303 | } |
1277 | |
1304 | |
1278 | if (bg_pixmap == None) |
|
|
1279 | return 0; |
|
|
1280 | |
|
|
1281 | /* straightforward pixmap copy */ |
1305 | /* straightforward pixmap copy */ |
1282 | while (sx < 0) sx += (int)root_width; |
1306 | while (sx < 0) sx += root_width; |
1283 | while (sy < 0) sy += (int)root_height; |
1307 | while (sy < 0) sy += root_height; |
1284 | |
1308 | |
1285 | gcv.tile = recoded_root_pmap; |
1309 | gcv.tile = recoded_root_pmap; |
1286 | gcv.fill_style = FillTiled; |
1310 | gcv.fill_style = FillTiled; |
1287 | gcv.ts_x_origin = -sx; |
1311 | gcv.ts_x_origin = -sx; |
1288 | gcv.ts_y_origin = -sy; |
1312 | gcv.ts_y_origin = -sy; |
… | |
… | |
1445 | uint32_t mask_r, mask_g, mask_b; |
1469 | uint32_t mask_r, mask_g, mask_b; |
1446 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1470 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1447 | rgba low; |
1471 | rgba low; |
1448 | rgba high; |
1472 | rgba high; |
1449 | int i; |
1473 | int i; |
1450 | int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
1474 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1451 | |
1475 | |
1452 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1476 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1453 | |
1477 | |
1454 | /* for convenience */ |
1478 | /* for convenience */ |
1455 | mask_r = visual->red_mask; |
1479 | mask_r = visual->red_mask; |