… | |
… | |
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 <pcg@goof.com> |
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 | * |
9 | * |
9 | * 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 |
10 | * 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 |
11 | * the Free Software Foundation; either version 2 of the License, or |
12 | * the Free Software Foundation; either version 2 of the License, or |
12 | * (at your option) any later version. |
13 | * (at your option) any later version. |
… | |
… | |
22 | *---------------------------------------------------------------------*/ |
23 | *---------------------------------------------------------------------*/ |
23 | |
24 | |
24 | #include <cmath> |
25 | #include <cmath> |
25 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
|
|
28 | |
|
|
29 | #if XRENDER |
|
|
30 | # include <X11/extensions/Xrender.h> |
|
|
31 | #endif |
27 | |
32 | |
28 | #define DO_TIMING_TEST 0 |
33 | #define DO_TIMING_TEST 0 |
29 | |
34 | |
30 | #if DO_TIMING_TEST |
35 | #if DO_TIMING_TEST |
31 | # include <sys/time.h> |
36 | # include <sys/time.h> |
… | |
… | |
175 | { |
180 | { |
176 | # ifdef HAVE_AFTERIMAGE |
181 | # ifdef HAVE_AFTERIMAGE |
177 | if (original_asim) |
182 | if (original_asim) |
178 | return true; |
183 | return true; |
179 | # endif |
184 | # endif |
180 | # ifdef ENABLE_TRANSPARENCY |
|
|
181 | if (flags & isTransparent) |
|
|
182 | { |
|
|
183 | # ifdef HAVE_AFTERIMAGE |
|
|
184 | if ((flags & blurNeeded) && !(flags & blurServerSide)) |
|
|
185 | return true; |
|
|
186 | # endif |
|
|
187 | if ((flags & tintNeeded) && !(flags & tintServerSide)) |
|
|
188 | return true; |
|
|
189 | } |
|
|
190 | # endif |
|
|
191 | return false; |
185 | return false; |
192 | } |
186 | } |
193 | |
187 | |
194 | # ifdef BG_IMAGE_FROM_FILE |
188 | # ifdef BG_IMAGE_FROM_FILE |
195 | static inline bool |
189 | static inline bool |
… | |
… | |
232 | int diff = window_size - image_size; |
226 | int diff = window_size - image_size; |
233 | int smaller = min (image_size, window_size); |
227 | int smaller = min (image_size, window_size); |
234 | |
228 | |
235 | if (align >= 0 && align <= 100) |
229 | if (align >= 0 && align <= 100) |
236 | return diff * align / 100; |
230 | return diff * align / 100; |
237 | else if (align > 100 && align <= 200 ) |
231 | else if (align > 100 && align <= 200) |
238 | return ((align - 100) * smaller / 100) + window_size - smaller; |
232 | return ((align - 100) * smaller / 100) + window_size - smaller; |
239 | else if (align >= -100 && align < 0) |
233 | else if (align >= -100 && align < 0) |
240 | return ((align + 100) * smaller / 100) - image_size; |
234 | return ((align + 100) * smaller / 100) - image_size; |
241 | return 0; |
235 | return 0; |
242 | } |
236 | } |
… | |
… | |
260 | } |
254 | } |
261 | |
255 | |
262 | bool |
256 | bool |
263 | bgPixmap_t::set_geometry (const char *geom) |
257 | bgPixmap_t::set_geometry (const char *geom) |
264 | { |
258 | { |
|
|
259 | bool changed = false; |
265 | int geom_flags = 0, changed = 0; |
260 | int geom_flags = 0; |
266 | int x = 0, y = 0; |
261 | int x = 0, y = 0; |
267 | unsigned int w = 0, h = 0; |
262 | unsigned int w = 0, h = 0; |
268 | unsigned int n; |
263 | unsigned int n; |
269 | unsigned long new_flags = (flags & (~geometryFlags)); |
264 | unsigned long new_flags = (flags & (~geometryFlags)); |
270 | const char *p; |
265 | const char *p; |
… | |
… | |
426 | |
421 | |
427 | while (*ops != ':' && *ops != '\0') ++ops; |
422 | while (*ops != ':' && *ops != '\0') ++ops; |
428 | } /* done parsing ops */ |
423 | } /* done parsing ops */ |
429 | } |
424 | } |
430 | |
425 | |
431 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; |
426 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
432 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; |
427 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
433 | if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; |
428 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
434 | if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; |
429 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
435 | } |
430 | } |
436 | |
431 | |
437 | if (new_flags != flags) |
432 | if (new_flags != flags) |
438 | { |
433 | { |
439 | flags = new_flags; |
434 | flags = new_flags; |
440 | changed++; |
435 | changed = true; |
441 | } |
436 | } |
442 | |
437 | |
443 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
|
|
444 | // flags, h_scale, v_scale, h_align, v_align); |
|
|
445 | return (changed > 0); |
438 | return changed; |
446 | } |
439 | } |
447 | |
440 | |
448 | void |
441 | void |
449 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
442 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
450 | { |
443 | { |
… | |
… | |
478 | x = make_align_position (h_align, target_width, w); |
471 | x = make_align_position (h_align, target_width, w); |
479 | y = make_align_position (v_align, target_height, h); |
472 | y = make_align_position (v_align, target_height, h); |
480 | } |
473 | } |
481 | |
474 | |
482 | flags &= ~sizeSensitive; |
475 | flags &= ~sizeSensitive; |
483 | if (h_scale != 0 || v_scale != 0 |
476 | if ((flags & propScale) || h_scale || v_scale |
484 | || h_align != 0 || v_align != 0 |
477 | || (!(flags & rootAlign) && (h_align || v_align)) |
485 | || w > target_width || h > target_height) |
478 | || w > target_width || h > target_height) |
486 | flags |= sizeSensitive; |
479 | flags |= sizeSensitive; |
487 | } |
480 | } |
488 | |
481 | |
489 | # ifdef HAVE_AFTERIMAGE |
482 | # ifdef HAVE_AFTERIMAGE |
… | |
… | |
539 | |
532 | |
540 | int x = 0; |
533 | int x = 0; |
541 | int y = 0; |
534 | int y = 0; |
542 | int w = 0; |
535 | int w = 0; |
543 | int h = 0; |
536 | int h = 0; |
544 | |
|
|
545 | TIMING_TEST_START (asim); |
|
|
546 | |
537 | |
547 | if (original_asim) |
538 | if (original_asim) |
548 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
539 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
549 | |
540 | |
550 | if (!original_asim |
541 | if (!original_asim |
… | |
… | |
667 | } |
658 | } |
668 | |
659 | |
669 | free (layers); |
660 | free (layers); |
670 | } |
661 | } |
671 | } |
662 | } |
672 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
673 | |
663 | |
674 | bool ret = false; |
664 | bool ret = false; |
675 | |
665 | |
676 | if (result) |
666 | if (result) |
677 | { |
667 | { |
… | |
… | |
723 | |
713 | |
724 | if (result != background && result != original_asim) |
714 | if (result != background && result != original_asim) |
725 | destroy_asimage (&result); |
715 | destroy_asimage (&result); |
726 | |
716 | |
727 | XFreeGC (target->dpy, gc); |
717 | XFreeGC (target->dpy, gc); |
728 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
729 | |
718 | |
730 | ret = true; |
719 | ret = true; |
731 | } |
720 | } |
732 | |
721 | |
733 | if (background) |
722 | if (background) |
… | |
… | |
745 | return false; |
734 | return false; |
746 | |
735 | |
747 | if (!pixbuf) |
736 | if (!pixbuf) |
748 | return false; |
737 | return false; |
749 | |
738 | |
750 | #if !XFT |
|
|
751 | if (background_flags) |
739 | if (background_flags |
|
|
740 | && !(flags & HAS_RENDER)) |
752 | return false; |
741 | return false; |
753 | #endif |
|
|
754 | |
742 | |
755 | GdkPixbuf *result; |
743 | GdkPixbuf *result; |
756 | |
744 | |
757 | int image_width = gdk_pixbuf_get_width (pixbuf); |
745 | int image_width = gdk_pixbuf_get_width (pixbuf); |
758 | int image_height = gdk_pixbuf_get_height (pixbuf); |
746 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
872 | dst_width, dst_height, |
860 | dst_width, dst_height, |
873 | XLIB_RGB_DITHER_NONE, |
861 | XLIB_RGB_DITHER_NONE, |
874 | 0, 0); |
862 | 0, 0); |
875 | } |
863 | } |
876 | |
864 | |
877 | #if XFT |
865 | #if XRENDER |
878 | if (background_flags) |
866 | if (background_flags) |
879 | { |
867 | { |
880 | Display *dpy = target->dpy; |
868 | Display *dpy = target->dpy; |
881 | XRenderPictureAttributes pa; |
869 | XRenderPictureAttributes pa; |
882 | |
870 | |
883 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); |
871 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); |
884 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
872 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
885 | |
873 | |
886 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
874 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
887 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
875 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
888 | |
876 | |
… | |
… | |
925 | # endif /* HAVE_PIXBUF */ |
913 | # endif /* HAVE_PIXBUF */ |
926 | |
914 | |
927 | bool |
915 | bool |
928 | bgPixmap_t::set_file (const char *file) |
916 | bgPixmap_t::set_file (const char *file) |
929 | { |
917 | { |
930 | assert (file); |
918 | if (!file || !*file) |
|
|
919 | return false; |
931 | |
920 | |
932 | if (*file) |
|
|
933 | { |
|
|
934 | if (const char *p = strchr (file, ';')) |
921 | if (const char *p = strchr (file, ';')) |
935 | { |
922 | { |
936 | size_t len = p - file; |
923 | size_t len = p - file; |
937 | char *f = rxvt_temp_buf<char> (len + 1); |
924 | char *f = rxvt_temp_buf<char> (len + 1); |
938 | memcpy (f, file, len); |
925 | memcpy (f, file, len); |
939 | f[len] = '\0'; |
926 | f[len] = '\0'; |
940 | file = f; |
927 | file = f; |
941 | } |
928 | } |
942 | |
929 | |
943 | # ifdef HAVE_AFTERIMAGE |
930 | # ifdef HAVE_AFTERIMAGE |
944 | if (!target->asimman) |
931 | if (!target->asimman) |
945 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
932 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
946 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
933 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
947 | if (image) |
934 | if (image) |
948 | { |
935 | { |
949 | if (original_asim) |
936 | if (original_asim) |
950 | safe_asimage_destroy (original_asim); |
937 | safe_asimage_destroy (original_asim); |
951 | original_asim = image; |
938 | original_asim = image; |
952 | have_image = true; |
939 | have_image = true; |
953 | return true; |
940 | return true; |
954 | } |
941 | } |
955 | # endif |
942 | # endif |
956 | |
943 | |
957 | # ifdef HAVE_PIXBUF |
944 | # ifdef HAVE_PIXBUF |
958 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
945 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
959 | if (image) |
946 | if (image) |
960 | { |
947 | { |
961 | if (pixbuf) |
948 | if (pixbuf) |
962 | g_object_unref (pixbuf); |
949 | g_object_unref (pixbuf); |
963 | pixbuf = image; |
950 | pixbuf = image; |
964 | have_image = true; |
951 | have_image = true; |
965 | return true; |
952 | return true; |
966 | } |
953 | } |
967 | # endif |
954 | # endif |
968 | } |
|
|
969 | |
955 | |
970 | return false; |
956 | return false; |
971 | } |
957 | } |
972 | |
958 | |
973 | # endif /* BG_IMAGE_FROM_FILE */ |
959 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
986 | } |
972 | } |
987 | |
973 | |
988 | bool |
974 | bool |
989 | bgPixmap_t::set_blur_radius (const char *geom) |
975 | bgPixmap_t::set_blur_radius (const char *geom) |
990 | { |
976 | { |
991 | int changed = 0; |
977 | bool changed = false; |
992 | unsigned int hr, vr; |
978 | unsigned int hr, vr; |
993 | int junk; |
979 | int junk; |
994 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
980 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
995 | |
981 | |
996 | if (!(geom_flags & WidthValue)) |
982 | if (!(geom_flags & WidthValue)) |
… | |
… | |
1001 | min_it (hr, 128); |
987 | min_it (hr, 128); |
1002 | min_it (vr, 128); |
988 | min_it (vr, 128); |
1003 | |
989 | |
1004 | if (h_blurRadius != hr) |
990 | if (h_blurRadius != hr) |
1005 | { |
991 | { |
1006 | ++changed; |
992 | changed = true; |
1007 | h_blurRadius = hr; |
993 | h_blurRadius = hr; |
1008 | } |
994 | } |
1009 | |
995 | |
1010 | if (v_blurRadius != vr) |
996 | if (v_blurRadius != vr) |
1011 | { |
997 | { |
1012 | ++changed; |
998 | changed = true; |
1013 | v_blurRadius = vr; |
999 | v_blurRadius = vr; |
1014 | } |
1000 | } |
1015 | |
1001 | |
1016 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1002 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1017 | flags &= ~blurNeeded; |
1003 | flags &= ~blurNeeded; |
1018 | else |
1004 | else |
1019 | flags |= blurNeeded; |
1005 | flags |= blurNeeded; |
1020 | |
1006 | |
1021 | #if XFT |
|
|
1022 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
|
|
1023 | if (filters) |
|
|
1024 | { |
|
|
1025 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1026 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1027 | flags |= bgPixmap_t::blurServerSide; |
|
|
1028 | |
|
|
1029 | XFree (filters); |
|
|
1030 | } |
|
|
1031 | #endif |
|
|
1032 | |
|
|
1033 | return (changed > 0); |
1007 | return changed; |
1034 | } |
1008 | } |
1035 | |
1009 | |
1036 | static inline unsigned long |
1010 | static inline unsigned long |
1037 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1011 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1038 | { |
1012 | { |
… | |
… | |
1060 | { |
1034 | { |
1061 | flags |= bgPixmap_t::tintNeeded; |
1035 | flags |= bgPixmap_t::tintNeeded; |
1062 | } |
1036 | } |
1063 | } |
1037 | } |
1064 | |
1038 | |
1065 | if (flags & bgPixmap_t::tintNeeded) |
|
|
1066 | { |
|
|
1067 | if (flags & bgPixmap_t::tintWholesome) |
|
|
1068 | flags |= bgPixmap_t::tintServerSide; |
|
|
1069 | else |
|
|
1070 | { |
|
|
1071 | #if XFT |
|
|
1072 | flags |= bgPixmap_t::tintServerSide; |
|
|
1073 | #endif |
|
|
1074 | } |
|
|
1075 | } |
|
|
1076 | |
|
|
1077 | return flags; |
1039 | return flags; |
1078 | } |
1040 | } |
1079 | |
1041 | |
1080 | bool |
1042 | bool |
1081 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
1043 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
… | |
… | |
1123 | } |
1085 | } |
1124 | |
1086 | |
1125 | return false; |
1087 | return false; |
1126 | } |
1088 | } |
1127 | |
1089 | |
|
|
1090 | #if XRENDER |
1128 | static void |
1091 | static void |
1129 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1092 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1130 | { |
1093 | { |
1131 | double sigma = radius / 2.0; |
1094 | double sigma = radius / 2.0; |
1132 | double scale = sqrt (2.0 * M_PI) * sigma; |
1095 | double scale = sqrt (2.0 * M_PI) * sigma; |
1133 | double sum = 0.0; |
1096 | double sum = 0.0; |
1134 | |
1097 | |
1135 | for (int i = 0; i < width; i++) |
1098 | for (int i = 0; i < width; i++) |
1136 | { |
1099 | { |
1137 | double x = i - width / 2; |
1100 | double x = i - width / 2; |
1138 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1101 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
1139 | sum += kernel[i]; |
1102 | sum += kernel[i]; |
1140 | } |
1103 | } |
1141 | |
1104 | |
1142 | params[0] = XDoubleToFixed (width); |
1105 | params[0] = XDoubleToFixed (width); |
1143 | params[1] = XDoubleToFixed (1); |
1106 | params[1] = XDoubleToFixed (1); |
1144 | |
1107 | |
1145 | for (int i = 0; i < width; i++) |
1108 | for (int i = 0; i < width; i++) |
1146 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1109 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1147 | } |
1110 | } |
|
|
1111 | #endif |
1148 | |
1112 | |
1149 | bool |
1113 | bool |
1150 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1114 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1151 | { |
1115 | { |
1152 | bool ret = false; |
1116 | bool ret = false; |
1153 | #if XFT |
1117 | #if XRENDER |
1154 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1118 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1155 | double *kernel = (double *)malloc (size * sizeof (double)); |
1119 | double *kernel = (double *)malloc (size * sizeof (double)); |
1156 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1120 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1157 | |
1121 | |
1158 | Display *dpy = target->dpy; |
1122 | Display *dpy = target->dpy; |
1159 | XRenderPictureAttributes pa; |
1123 | XRenderPictureAttributes pa; |
1160 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); |
1124 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1161 | |
1125 | |
1162 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1126 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1163 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1127 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1164 | |
1128 | |
1165 | if (kernel && params && src && dst) |
1129 | if (kernel && params && src && dst) |
… | |
… | |
1235 | XFreeGC (dpy, gc); |
1199 | XFreeGC (dpy, gc); |
1236 | } |
1200 | } |
1237 | } |
1201 | } |
1238 | else |
1202 | else |
1239 | { |
1203 | { |
1240 | # if XFT |
1204 | # if XRENDER |
1241 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1205 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1242 | |
1206 | |
1243 | if (flags & tintSet) |
1207 | if (flags & tintSet) |
1244 | tint.get (c); |
1208 | tint.get (c); |
1245 | |
1209 | |
… | |
… | |
1291 | } |
1255 | } |
1292 | |
1256 | |
1293 | XRenderFreePicture (dpy, mask_pic); |
1257 | XRenderFreePicture (dpy, mask_pic); |
1294 | XRenderFreePicture (dpy, overlay_pic); |
1258 | XRenderFreePicture (dpy, overlay_pic); |
1295 | XRenderFreePicture (dpy, back_pic); |
1259 | XRenderFreePicture (dpy, back_pic); |
1296 | # if DO_TIMING_TEST |
|
|
1297 | XSync (dpy, False); |
|
|
1298 | # endif |
|
|
1299 | # endif |
1260 | # endif |
1300 | } |
1261 | } |
1301 | |
1262 | |
1302 | return ret; |
1263 | return ret; |
1303 | } |
1264 | } |
1304 | |
1265 | |
1305 | /* make_transparency_pixmap() |
1266 | /* make_transparency_pixmap() |
1306 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
1267 | * Builds a pixmap of the same size as the terminal window that contains |
1307 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
1268 | * the tiled portion of the root pixmap that is supposed to be covered by |
1308 | * our window. |
1269 | * our window. |
1309 | */ |
1270 | */ |
1310 | unsigned long |
1271 | unsigned long |
1311 | bgPixmap_t::make_transparency_pixmap () |
1272 | bgPixmap_t::make_transparency_pixmap () |
1312 | { |
1273 | { |
… | |
… | |
1316 | return 0; |
1277 | return 0; |
1317 | |
1278 | |
1318 | /* root dimensions may change from call to call - but Display structure should |
1279 | /* root dimensions may change from call to call - but Display structure should |
1319 | * be always up-to-date, so let's use it : |
1280 | * be always up-to-date, so let's use it : |
1320 | */ |
1281 | */ |
1321 | Window root = target->display->root; |
|
|
1322 | int screen = target->display->screen; |
1282 | int screen = target->display->screen; |
1323 | Display *dpy = target->dpy; |
1283 | Display *dpy = target->dpy; |
|
|
1284 | int root_depth = DefaultDepth (dpy, screen); |
1324 | int root_width = DisplayWidth (dpy, screen); |
1285 | int root_width = DisplayWidth (dpy, screen); |
1325 | int root_height = DisplayHeight (dpy, screen); |
1286 | int root_height = DisplayHeight (dpy, screen); |
1326 | unsigned int root_pmap_width, root_pmap_height; |
1287 | unsigned int root_pmap_width, root_pmap_height; |
1327 | int window_width = target->szHint.width; |
1288 | int window_width = target->szHint.width; |
1328 | int window_height = target->szHint.height; |
1289 | int window_height = target->szHint.height; |
1329 | int sx, sy; |
1290 | int sx, sy; |
1330 | XGCValues gcv; |
1291 | XGCValues gcv; |
1331 | GC gc; |
1292 | GC gc; |
1332 | |
1293 | |
1333 | TIMING_TEST_START (tp); |
|
|
1334 | target->get_window_origin (sx, sy); |
1294 | target->get_window_origin (sx, sy); |
1335 | |
1295 | |
1336 | /* check if we are outside of the visible part of the virtual screen : */ |
1296 | /* check if we are outside of the visible part of the virtual screen : */ |
1337 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1297 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1338 | || sx >= root_width || sy >= root_height) |
1298 | || sx >= root_width || sy >= root_height) |
1339 | return 0; |
1299 | return 0; |
1340 | |
1300 | |
|
|
1301 | // validate root pixmap and get its size |
1341 | if (root_pixmap != None) |
1302 | if (root_pixmap != None) |
1342 | { |
1303 | { |
1343 | /* we want to validate the pixmap and get its size at the same time : */ |
1304 | Window wdummy; |
1344 | int junk; |
1305 | int idummy; |
1345 | unsigned int ujunk; |
1306 | unsigned int udummy; |
1346 | /* root pixmap may be bad - allow a error */ |
1307 | |
1347 | target->allowedxerror = -1; |
1308 | target->allowedxerror = -1; |
1348 | |
1309 | |
1349 | if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) |
1310 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
1350 | root_pixmap = None; |
1311 | root_pixmap = None; |
1351 | |
1312 | |
1352 | target->allowedxerror = 0; |
1313 | target->allowedxerror = 0; |
|
|
1314 | } |
|
|
1315 | |
|
|
1316 | Pixmap recoded_root_pmap = root_pixmap; |
|
|
1317 | |
|
|
1318 | if (root_pixmap != None && root_depth != target->depth) |
|
|
1319 | { |
|
|
1320 | #if XRENDER |
|
|
1321 | if (flags & HAS_RENDER) |
|
|
1322 | { |
|
|
1323 | XRenderPictureAttributes pa; |
|
|
1324 | |
|
|
1325 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
|
|
1326 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
|
|
1327 | |
|
|
1328 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
|
|
1329 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
1330 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
|
|
1331 | |
|
|
1332 | if (src && dst) |
|
|
1333 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
|
|
1334 | else |
|
|
1335 | { |
|
|
1336 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1337 | root_pixmap = None; |
|
|
1338 | } |
|
|
1339 | |
|
|
1340 | XRenderFreePicture (dpy, src); |
|
|
1341 | XRenderFreePicture (dpy, dst); |
|
|
1342 | } |
|
|
1343 | else |
|
|
1344 | #endif |
|
|
1345 | root_pixmap = None; |
1353 | } |
1346 | } |
1354 | |
1347 | |
1355 | if (root_pixmap == None) |
1348 | if (root_pixmap == None) |
1356 | return 0; |
1349 | return 0; |
1357 | |
1350 | |
1358 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
1351 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); |
1359 | |
1352 | |
1360 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1353 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1361 | return 0; |
1354 | return 0; |
1362 | |
1355 | |
1363 | /* straightforward pixmap copy */ |
1356 | /* straightforward pixmap copy */ |
1364 | gcv.tile = root_pixmap; |
1357 | gcv.tile = recoded_root_pmap; |
1365 | gcv.fill_style = FillTiled; |
1358 | gcv.fill_style = FillTiled; |
1366 | |
1359 | |
1367 | while (sx < 0) sx += (int)root_width; |
1360 | while (sx < 0) sx += (int)root_width; |
1368 | while (sy < 0) sy += (int)root_height; |
1361 | while (sy < 0) sy += (int)root_height; |
1369 | |
1362 | |
1370 | gcv.ts_x_origin = -sx; |
1363 | gcv.ts_x_origin = -sx; |
1371 | gcv.ts_y_origin = -sy; |
1364 | gcv.ts_y_origin = -sy; |
1372 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1365 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1373 | |
1366 | |
1374 | if (gc) |
1367 | if (gc) |
1375 | { |
1368 | { |
1376 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1369 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1377 | result |= transpPmapTiled; |
1370 | result |= transpPmapTiled; |
1378 | XFreeGC (dpy, gc); |
1371 | XFreeGC (dpy, gc); |
1379 | } |
1372 | } |
1380 | TIMING_TEST_PRINT_RESULT (tp); |
|
|
1381 | |
1373 | |
1382 | if (tiled_root_pmap != None) |
1374 | if (tiled_root_pmap != None) |
1383 | { |
1375 | { |
1384 | if (!need_client_side_rendering ()) |
1376 | if (!need_client_side_rendering ()) |
1385 | { |
1377 | { |
1386 | if ((flags & blurNeeded)) |
1378 | if ((flags & blurNeeded) |
|
|
1379 | && (flags & HAS_RENDER_CONV)) |
1387 | { |
1380 | { |
1388 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1381 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1389 | result |= transpPmapBlurred; |
1382 | result |= transpPmapBlurred; |
1390 | } |
1383 | } |
1391 | if ((flags & tintNeeded)) |
1384 | if ((flags & tintNeeded) |
|
|
1385 | && (flags & (tintWholesome | HAS_RENDER))) |
1392 | { |
1386 | { |
1393 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
1387 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1394 | result |= transpPmapTinted; |
1388 | result |= transpPmapTinted; |
1395 | } |
1389 | } |
1396 | } /* server side rendering completed */ |
1390 | } /* server side rendering completed */ |
1397 | |
1391 | |
1398 | if (pixmap) |
1392 | if (pixmap) |
1399 | XFreePixmap (dpy, pixmap); |
1393 | XFreePixmap (dpy, pixmap); |
1400 | |
1394 | |
1401 | pixmap = tiled_root_pmap; |
1395 | pixmap = tiled_root_pmap; |
1402 | pmap_width = window_width; |
1396 | pmap_width = window_width; |
1403 | pmap_height = window_height; |
1397 | pmap_height = window_height; |
1404 | pmap_depth = root_depth; |
1398 | pmap_depth = target->depth; |
1405 | } |
1399 | } |
1406 | |
1400 | |
1407 | TIMING_TEST_PRINT_RESULT (tp); |
1401 | if (recoded_root_pmap != root_pixmap) |
|
|
1402 | XFreePixmap (dpy, recoded_root_pmap); |
1408 | |
1403 | |
1409 | return result; |
1404 | return result; |
1410 | } |
1405 | } |
1411 | |
1406 | |
1412 | bool |
1407 | void |
1413 | bgPixmap_t::set_root_pixmap () |
1408 | bgPixmap_t::set_root_pixmap () |
1414 | { |
1409 | { |
1415 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1410 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1416 | if (new_root_pixmap == None) |
1411 | if (new_root_pixmap == None) |
1417 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1412 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1418 | |
1413 | |
1419 | if (new_root_pixmap != root_pixmap) |
|
|
1420 | { |
|
|
1421 | root_pixmap = new_root_pixmap; |
1414 | root_pixmap = new_root_pixmap; |
1422 | return true; |
|
|
1423 | } |
|
|
1424 | |
|
|
1425 | return false; |
|
|
1426 | } |
1415 | } |
1427 | # endif /* ENABLE_TRANSPARENCY */ |
1416 | # endif /* ENABLE_TRANSPARENCY */ |
1428 | |
1417 | |
1429 | # ifndef HAVE_AFTERIMAGE |
1418 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1430 | static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); |
1419 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c); |
1431 | # endif |
1420 | # endif |
1432 | |
1421 | |
1433 | bool |
1422 | bool |
1434 | bgPixmap_t::render () |
1423 | bgPixmap_t::render () |
1435 | { |
1424 | { |
1436 | unsigned long background_flags = 0; |
1425 | unsigned long background_flags = 0; |
1437 | |
1426 | |
1438 | if (target == NULL) |
1427 | if (target == NULL) |
1439 | return false; |
1428 | return false; |
1440 | |
|
|
1441 | TIMING_TEST_START (tp); |
|
|
1442 | |
1429 | |
1443 | invalidate (); |
1430 | invalidate (); |
1444 | # ifdef ENABLE_TRANSPARENCY |
1431 | # ifdef ENABLE_TRANSPARENCY |
1445 | if (flags & isTransparent) |
1432 | if (flags & isTransparent) |
1446 | { |
1433 | { |
1447 | /* we need to re-generate transparency pixmap in that case ! */ |
1434 | /* we need to re-generate transparency pixmap in that case ! */ |
1448 | background_flags = make_transparency_pixmap (); |
1435 | background_flags = make_transparency_pixmap (); |
1449 | if (background_flags == 0) |
1436 | if (background_flags == 0) |
1450 | return false; |
1437 | return false; |
1451 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1438 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1452 | && pmap_depth == target->depth) |
|
|
1453 | flags = flags & ~isInvalid; |
1439 | flags = flags & ~isInvalid; |
1454 | } |
1440 | } |
1455 | # endif |
1441 | # endif |
1456 | |
1442 | |
1457 | # ifdef BG_IMAGE_FROM_FILE |
1443 | # ifdef BG_IMAGE_FROM_FILE |
… | |
… | |
1461 | if (render_image (background_flags)) |
1447 | if (render_image (background_flags)) |
1462 | flags = flags & ~isInvalid; |
1448 | flags = flags & ~isInvalid; |
1463 | } |
1449 | } |
1464 | # endif |
1450 | # endif |
1465 | |
1451 | |
|
|
1452 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1466 | XImage *result = NULL; |
1453 | XImage *result = NULL; |
1467 | |
1454 | |
1468 | if (background_flags && (flags & isInvalid)) |
1455 | if (background_flags && (flags & isInvalid)) |
1469 | { |
1456 | { |
1470 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1457 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1471 | } |
1458 | } |
1472 | |
1459 | |
1473 | if (result) |
1460 | if (result) |
1474 | { |
1461 | { |
1475 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
|
|
1476 | /* our own client-side tinting */ |
1462 | /* our own client-side tinting */ |
1477 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
|
|
1478 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
|
|
1479 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1463 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1480 | { |
1464 | { |
1481 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1465 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1482 | if (flags & tintSet) |
1466 | if (flags & tintSet) |
1483 | tint.get (c); |
1467 | tint.get (c); |
1484 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1468 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1485 | } |
1469 | } |
1486 | # endif |
|
|
1487 | |
1470 | |
1488 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1471 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1489 | |
1472 | |
1490 | if (gc) |
1473 | if (gc) |
1491 | { |
1474 | { |
1492 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
|
|
1493 | { |
|
|
1494 | XFreePixmap (target->dpy, pixmap); |
|
|
1495 | pixmap = None; |
|
|
1496 | } |
|
|
1497 | |
|
|
1498 | if (pixmap == None) |
|
|
1499 | { |
|
|
1500 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
|
|
1501 | pmap_width = result->width; |
|
|
1502 | pmap_height = result->height; |
|
|
1503 | pmap_depth = target->depth; |
|
|
1504 | } |
|
|
1505 | |
|
|
1506 | if (pmap_depth != result->depth) |
|
|
1507 | { |
|
|
1508 | /* Bad Match error will ensue ! stupid X !!!! */ |
|
|
1509 | if (result->depth == 24 && pmap_depth == 32) |
|
|
1510 | result->depth = 32; |
|
|
1511 | else if (result->depth == 32 && pmap_depth == 24) |
|
|
1512 | result->depth = 24; |
|
|
1513 | else |
|
|
1514 | { |
|
|
1515 | /* TODO: implement image recoding */ |
|
|
1516 | } |
|
|
1517 | } |
|
|
1518 | |
|
|
1519 | if (pmap_depth == result->depth) |
|
|
1520 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1475 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1521 | |
1476 | |
1522 | XFreeGC (target->dpy, gc); |
1477 | XFreeGC (target->dpy, gc); |
1523 | flags = flags & ~isInvalid; |
1478 | flags = flags & ~isInvalid; |
1524 | } |
1479 | } |
1525 | |
1480 | |
1526 | XDestroyImage (result); |
1481 | XDestroyImage (result); |
1527 | } |
1482 | } |
|
|
1483 | # endif |
1528 | |
1484 | |
1529 | if (flags & isInvalid) |
1485 | if (flags & isInvalid) |
1530 | { |
1486 | { |
1531 | if (pixmap != None) |
1487 | if (pixmap != None) |
1532 | { |
1488 | { |
… | |
… | |
1535 | } |
1491 | } |
1536 | } |
1492 | } |
1537 | |
1493 | |
1538 | apply (); |
1494 | apply (); |
1539 | |
1495 | |
1540 | XSync (target->dpy, False); |
|
|
1541 | valid_since = ev::now (); |
1496 | valid_since = ev::now (); |
1542 | |
1497 | |
1543 | TIMING_TEST_PRINT_RESULT (tp); |
|
|
1544 | |
|
|
1545 | return true; |
1498 | return true; |
1546 | } |
1499 | } |
1547 | |
1500 | |
1548 | bool |
1501 | void |
1549 | bgPixmap_t::set_target (rxvt_term *new_target) |
1502 | bgPixmap_t::set_target (rxvt_term *new_target) |
1550 | { |
1503 | { |
1551 | if (new_target) |
|
|
1552 | if (target != new_target) |
|
|
1553 | { |
|
|
1554 | target = new_target; |
1504 | target = new_target; |
1555 | # ifdef ENABLE_TRANSPARENCY |
1505 | |
1556 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1506 | flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
|
|
1507 | #if XRENDER |
|
|
1508 | int major, minor; |
|
|
1509 | if (XRenderQueryVersion (target->dpy, &major, &minor)) |
|
|
1510 | flags |= HAS_RENDER; |
|
|
1511 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1512 | if (filters) |
|
|
1513 | { |
|
|
1514 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1515 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1516 | flags |= HAS_RENDER_CONV; |
|
|
1517 | |
|
|
1518 | XFree (filters); |
|
|
1519 | } |
1557 | # endif |
1520 | #endif |
1558 | return true; |
|
|
1559 | } |
|
|
1560 | |
|
|
1561 | return false; |
|
|
1562 | } |
1521 | } |
1563 | |
1522 | |
1564 | void |
1523 | void |
1565 | bgPixmap_t::apply () |
1524 | bgPixmap_t::apply () |
1566 | { |
1525 | { |
1567 | if (target) |
1526 | if (target == NULL) |
1568 | { |
1527 | return; |
1569 | flags &= ~isVtOrigin; |
|
|
1570 | |
1528 | |
1571 | if (pixmap != None) |
1529 | if (pixmap != None) |
1572 | { |
1530 | { |
1573 | /* set target's background to pixmap */ |
1531 | /* set target's background to pixmap */ |
1574 | # ifdef ENABLE_TRANSPARENCY |
1532 | # ifdef ENABLE_TRANSPARENCY |
1575 | if (flags & isTransparent) |
1533 | if (flags & isTransparent) |
1576 | { |
1534 | { |
1577 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1535 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1578 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1536 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1579 | |
1537 | |
1580 | if (target->scrollBar.win) |
1538 | if (target->scrollBar.win) |
1581 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1539 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1582 | } |
1540 | } |
1583 | else |
1541 | else |
1584 | # endif |
1542 | # endif |
1585 | { |
1543 | { |
1586 | flags |= isVtOrigin; |
|
|
1587 | /* force old pixmap dereference in case it was transparent before :*/ |
1544 | /* force old pixmap dereference in case it was transparent before :*/ |
1588 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1589 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1590 | /* do we also need to set scrollbar's background here ? */ |
|
|
1591 | |
|
|
1592 | if (target->scrollBar.win) |
|
|
1593 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1594 | } |
|
|
1595 | } |
|
|
1596 | else |
|
|
1597 | { |
|
|
1598 | /* set target background to a pixel */ |
|
|
1599 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1545 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1600 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1546 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1601 | /* do we also need to set scrollbar's background here ? */ |
1547 | /* do we also need to set scrollbar's background here ? */ |
|
|
1548 | |
1602 | if (target->scrollBar.win) |
1549 | if (target->scrollBar.win) |
1603 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1550 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1604 | } |
1551 | } |
|
|
1552 | } |
|
|
1553 | else |
|
|
1554 | { |
|
|
1555 | /* set target background to a pixel */ |
|
|
1556 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1557 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
1558 | /* do we also need to set scrollbar's background here ? */ |
|
|
1559 | if (target->scrollBar.win) |
|
|
1560 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1561 | } |
1605 | |
1562 | |
1606 | /* don't want Expose on the parent or vt. It is better to use |
1563 | /* don't want Expose on the parent or vt. It is better to use |
1607 | scr_touch or we get a great deal of flicker otherwise: */ |
1564 | scr_touch or we get a great deal of flicker otherwise: */ |
1608 | XClearWindow (target->dpy, target->parent[0]); |
1565 | XClearWindow (target->dpy, target->parent[0]); |
1609 | |
1566 | |
1610 | if (target->scrollBar.state && target->scrollBar.win) |
1567 | if (target->scrollBar.state && target->scrollBar.win) |
1611 | { |
1568 | { |
1612 | target->scrollBar.state = STATE_IDLE; |
1569 | target->scrollBar.state = STATE_IDLE; |
1613 | target->scrollBar.show (0); |
1570 | target->scrollBar.show (0); |
1614 | } |
1571 | } |
1615 | |
1572 | |
1616 | target->want_refresh = 1; |
1573 | target->want_refresh = 1; |
1617 | flags |= hasChanged; |
1574 | flags |= hasChanged; |
1618 | } |
|
|
1619 | } |
1575 | } |
1620 | |
1576 | |
1621 | #endif /* HAVE_BG_PIXMAP */ |
1577 | #endif /* HAVE_BG_PIXMAP */ |
1622 | |
1578 | |
1623 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1579 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1624 | /* taken from aterm-0.4.2 */ |
1580 | /* taken from aterm-0.4.2 */ |
1625 | |
1581 | |
1626 | typedef uint32_t RUINT32T; |
|
|
1627 | |
|
|
1628 | static void |
1582 | static void |
1629 | ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) |
1583 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c) |
1630 | { |
1584 | { |
1631 | int sh_r, sh_g, sh_b; |
1585 | int sh_r, sh_g, sh_b; |
1632 | RUINT32T mask_r, mask_g, mask_b; |
1586 | uint32_t mask_r, mask_g, mask_b; |
1633 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1587 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1634 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1588 | rgba low; |
1635 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1589 | rgba high; |
1636 | int i; |
1590 | int i; |
|
|
1591 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1637 | |
1592 | |
1638 | Visual *visual = term->visual; |
|
|
1639 | |
|
|
1640 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
1593 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1641 | |
1594 | |
1642 | /* for convenience */ |
1595 | /* for convenience */ |
1643 | mask_r = visual->red_mask; |
1596 | mask_r = visual->red_mask; |
1644 | mask_g = visual->green_mask; |
1597 | mask_g = visual->green_mask; |
1645 | mask_b = visual->blue_mask; |
1598 | mask_b = visual->blue_mask; |
1646 | |
1599 | |
1647 | /* boring lookup table pre-initialization */ |
1600 | /* boring lookup table pre-initialization */ |
1648 | switch (srcImage->bits_per_pixel) { |
1601 | switch (srcImage->depth) |
|
|
1602 | { |
1649 | case 15: |
1603 | case 15: |
1650 | if ((mask_r != 0x7c00) || |
1604 | if ((mask_r != 0x7c00) || |
1651 | (mask_g != 0x03e0) || |
1605 | (mask_g != 0x03e0) || |
1652 | (mask_b != 0x001f)) |
1606 | (mask_b != 0x001f)) |
1653 | return; |
1607 | return; |
1654 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+32+32)); |
1608 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+32+32)); |
1655 | lookup_r = lookup; |
1609 | lookup_r = lookup; |
1656 | lookup_g = lookup+32; |
1610 | lookup_g = lookup+32; |
1657 | lookup_b = lookup+32+32; |
1611 | lookup_b = lookup+32+32; |
1658 | sh_r = 10; |
1612 | sh_r = 10; |
1659 | sh_g = 5; |
1613 | sh_g = 5; |
1660 | sh_b = 0; |
1614 | sh_b = 0; |
1661 | break; |
1615 | break; |
1662 | case 16: |
1616 | case 16: |
1663 | if ((mask_r != 0xf800) || |
1617 | if ((mask_r != 0xf800) || |
1664 | (mask_g != 0x07e0) || |
1618 | (mask_g != 0x07e0) || |
1665 | (mask_b != 0x001f)) |
1619 | (mask_b != 0x001f)) |
1666 | return; |
1620 | return; |
1667 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(32+64+32)); |
1621 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(32+64+32)); |
1668 | lookup_r = lookup; |
1622 | lookup_r = lookup; |
1669 | lookup_g = lookup+32; |
1623 | lookup_g = lookup+32; |
1670 | lookup_b = lookup+32+64; |
1624 | lookup_b = lookup+32+64; |
1671 | sh_r = 11; |
1625 | sh_r = 11; |
1672 | sh_g = 5; |
1626 | sh_g = 5; |
1673 | sh_b = 0; |
1627 | sh_b = 0; |
1674 | break; |
1628 | break; |
1675 | case 24: |
1629 | case 24: |
1676 | if ((mask_r != 0xff0000) || |
1630 | if ((mask_r != 0xff0000) || |
1677 | (mask_g != 0x00ff00) || |
1631 | (mask_g != 0x00ff00) || |
1678 | (mask_b != 0x0000ff)) |
1632 | (mask_b != 0x0000ff)) |
1679 | return; |
1633 | return; |
1680 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1634 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
1681 | lookup_r = lookup; |
1635 | lookup_r = lookup; |
1682 | lookup_g = lookup+256; |
1636 | lookup_g = lookup+256; |
1683 | lookup_b = lookup+256+256; |
1637 | lookup_b = lookup+256+256; |
1684 | sh_r = 16; |
1638 | sh_r = 16; |
1685 | sh_g = 8; |
1639 | sh_g = 8; |
1686 | sh_b = 0; |
1640 | sh_b = 0; |
1687 | break; |
1641 | break; |
1688 | case 32: |
1642 | case 32: |
1689 | if ((mask_r != 0xff0000) || |
1643 | if ((mask_r != 0xff0000) || |
1690 | (mask_g != 0x00ff00) || |
1644 | (mask_g != 0x00ff00) || |
1691 | (mask_b != 0x0000ff)) |
1645 | (mask_b != 0x0000ff)) |
1692 | return; |
1646 | return; |
1693 | lookup = (RUINT32T *) malloc (sizeof (RUINT32T)*(256+256+256)); |
1647 | lookup = (uint32_t *) malloc (sizeof (uint32_t)*(256+256+256)); |
1694 | lookup_r = lookup; |
1648 | lookup_r = lookup; |
1695 | lookup_g = lookup+256; |
1649 | lookup_g = lookup+256; |
1696 | lookup_b = lookup+256+256; |
1650 | lookup_b = lookup+256+256; |
1697 | sh_r = 16; |
1651 | sh_r = 16; |
1698 | sh_g = 8; |
1652 | sh_g = 8; |
1699 | sh_b = 0; |
1653 | sh_b = 0; |
1700 | break; |
1654 | break; |
1701 | default: |
1655 | default: |
1702 | return; /* we do not support this color depth */ |
1656 | return; /* we do not support this color depth */ |
1703 | } |
1657 | } |
1704 | |
1658 | |
1705 | /* prepare limits for color transformation (each channel is handled separately) */ |
1659 | /* prepare limits for color transformation (each channel is handled separately) */ |
1706 | if (shade > 100) { |
1660 | if (shade > 100) |
|
|
1661 | { |
1707 | shade = 200 - shade; |
1662 | shade = 200 - shade; |
1708 | |
1663 | |
1709 | lower_lim_r = 65535-rm; |
1664 | high.r = (65535 - c.r) * shade / 100; |
1710 | lower_lim_g = 65535-gm; |
1665 | high.g = (65535 - c.g) * shade / 100; |
1711 | lower_lim_b = 65535-bm; |
1666 | high.b = (65535 - c.b) * shade / 100; |
1712 | |
1667 | |
1713 | lower_lim_r = 65535-(unsigned int)(((RUINT32T)lower_lim_r)*((RUINT32T)shade)/100); |
1668 | low.r = 65535 - high.r; |
1714 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
1669 | low.g = 65535 - high.g; |
1715 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
1670 | low.b = 65535 - high.b; |
1716 | |
|
|
1717 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1718 | } else { |
|
|
1719 | |
|
|
1720 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
|
|
1721 | |
|
|
1722 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
|
|
1723 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
|
|
1724 | upper_lim_b = (unsigned int)((((RUINT32T)bm)*((RUINT32T)shade))/100); |
|
|
1725 | } |
1671 | } |
1726 | |
1672 | else |
1727 | /* switch red and blue bytes if necessary, we need it for some weird XServers like XFree86 3.3.3.1 */ |
|
|
1728 | if ((srcImage->bits_per_pixel == 24) && (mask_r >= 0xFF0000 )) |
|
|
1729 | { |
1673 | { |
1730 | unsigned int tmp; |
1674 | high.r = c.r * shade / 100; |
|
|
1675 | high.g = c.g * shade / 100; |
|
|
1676 | high.b = c.b * shade / 100; |
1731 | |
1677 | |
1732 | tmp = lower_lim_r; |
1678 | low.r = low.g = low.b = 0; |
1733 | lower_lim_r = lower_lim_b; |
|
|
1734 | lower_lim_b = tmp; |
|
|
1735 | |
|
|
1736 | tmp = upper_lim_r; |
|
|
1737 | upper_lim_r = upper_lim_b; |
|
|
1738 | upper_lim_b = tmp; |
|
|
1739 | } |
1679 | } |
1740 | |
1680 | |
1741 | /* fill our lookup tables */ |
1681 | /* fill our lookup tables */ |
1742 | for (i = 0; i <= mask_r>>sh_r; i++) |
1682 | for (i = 0; i <= mask_r>>sh_r; i++) |
1743 | { |
1683 | { |
1744 | RUINT32T tmp; |
1684 | uint32_t tmp; |
1745 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_r-lower_lim_r)); |
1685 | tmp = i * high.r; |
1746 | tmp += ((RUINT32T)(mask_r>>sh_r))*((RUINT32T)lower_lim_r); |
1686 | tmp += (mask_r>>sh_r) * low.r; |
1747 | lookup_r[i] = (tmp/65535)<<sh_r; |
1687 | lookup_r[i] = (tmp/65535)<<sh_r; |
1748 | } |
1688 | } |
1749 | for (i = 0; i <= mask_g>>sh_g; i++) |
1689 | for (i = 0; i <= mask_g>>sh_g; i++) |
1750 | { |
1690 | { |
1751 | RUINT32T tmp; |
1691 | uint32_t tmp; |
1752 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_g-lower_lim_g)); |
1692 | tmp = i * high.g; |
1753 | tmp += ((RUINT32T)(mask_g>>sh_g))*((RUINT32T)lower_lim_g); |
1693 | tmp += (mask_g>>sh_g) * low.g; |
1754 | lookup_g[i] = (tmp/65535)<<sh_g; |
1694 | lookup_g[i] = (tmp/65535)<<sh_g; |
1755 | } |
1695 | } |
1756 | for (i = 0; i <= mask_b>>sh_b; i++) |
1696 | for (i = 0; i <= mask_b>>sh_b; i++) |
1757 | { |
1697 | { |
1758 | RUINT32T tmp; |
1698 | uint32_t tmp; |
1759 | tmp = ((RUINT32T)i)*((RUINT32T)(upper_lim_b-lower_lim_b)); |
1699 | tmp = i * high.b; |
1760 | tmp += ((RUINT32T)(mask_b>>sh_b))*((RUINT32T)lower_lim_b); |
1700 | tmp += (mask_b>>sh_b) * low.b; |
1761 | lookup_b[i] = (tmp/65535)<<sh_b; |
1701 | lookup_b[i] = (tmp/65535)<<sh_b; |
1762 | } |
1702 | } |
1763 | |
1703 | |
1764 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1704 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1765 | switch (srcImage->bits_per_pixel) |
1705 | if (srcImage->bits_per_pixel == 32 |
|
|
1706 | && (srcImage->depth == 24 || srcImage->depth == 32) |
|
|
1707 | && srcImage->byte_order == host_byte_order) |
1766 | { |
1708 | { |
1767 | case 15: |
|
|
1768 | { |
|
|
1769 | unsigned short *p1, *pf, *p, *pl; |
1709 | uint32_t *p1, *pf, *p, *pl; |
1770 | p1 = (unsigned short *) srcImage->data; |
1710 | p1 = (uint32_t *) srcImage->data; |
1771 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1711 | pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1712 | |
1772 | while (p1 < pf) |
1713 | while (p1 < pf) |
1773 | { |
1714 | { |
1774 | p = p1; |
1715 | p = p1; |
1775 | pl = p1 + srcImage->width; |
1716 | pl = p1 + srcImage->width; |
1776 | for (; p < pl; p++) |
1717 | for (; p < pl; p++) |
1777 | { |
1718 | { |
1778 | *p = lookup_r[(*p & 0x7c00)>>10] | |
|
|
1779 | lookup_g[(*p & 0x03e0)>> 5] | |
|
|
1780 | lookup_b[(*p & 0x001f)]; |
|
|
1781 | } |
|
|
1782 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1783 | } |
|
|
1784 | break; |
|
|
1785 | } |
|
|
1786 | case 16: |
|
|
1787 | { |
|
|
1788 | unsigned short *p1, *pf, *p, *pl; |
|
|
1789 | p1 = (unsigned short *) srcImage->data; |
|
|
1790 | pf = (unsigned short *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1791 | while (p1 < pf) |
|
|
1792 | { |
|
|
1793 | p = p1; |
|
|
1794 | pl = p1 + srcImage->width; |
|
|
1795 | for (; p < pl; p++) |
|
|
1796 | { |
|
|
1797 | *p = lookup_r[(*p & 0xf800)>>11] | |
|
|
1798 | lookup_g[(*p & 0x07e0)>> 5] | |
|
|
1799 | lookup_b[(*p & 0x001f)]; |
|
|
1800 | } |
|
|
1801 | p1 = (unsigned short *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1802 | } |
|
|
1803 | break; |
|
|
1804 | } |
|
|
1805 | case 24: |
|
|
1806 | { |
|
|
1807 | unsigned char *p1, *pf, *p, *pl; |
|
|
1808 | p1 = (unsigned char *) srcImage->data; |
|
|
1809 | pf = (unsigned char *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1810 | while (p1 < pf) |
|
|
1811 | { |
|
|
1812 | p = p1; |
|
|
1813 | pl = p1 + srcImage->width * 3; |
|
|
1814 | for (; p < pl; p += 3) |
|
|
1815 | { |
|
|
1816 | p[0] = lookup_r[(p[0] & 0xff0000)>>16]; |
|
|
1817 | p[1] = lookup_r[(p[1] & 0x00ff00)>> 8]; |
|
|
1818 | p[2] = lookup_r[(p[2] & 0x0000ff)]; |
|
|
1819 | } |
|
|
1820 | p1 = (unsigned char *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1821 | } |
|
|
1822 | break; |
|
|
1823 | } |
|
|
1824 | case 32: |
|
|
1825 | { |
|
|
1826 | RUINT32T *p1, *pf, *p, *pl; |
|
|
1827 | p1 = (RUINT32T *) srcImage->data; |
|
|
1828 | pf = (RUINT32T *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
|
|
1829 | |
|
|
1830 | while (p1 < pf) |
|
|
1831 | { |
|
|
1832 | p = p1; |
|
|
1833 | pl = p1 + srcImage->width; |
|
|
1834 | for (; p < pl; p++) |
|
|
1835 | { |
|
|
1836 | *p = lookup_r[(*p & 0xff0000)>>16] | |
1719 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1837 | lookup_g[(*p & 0x00ff00)>> 8] | |
1720 | lookup_g[(*p & 0x00ff00) >> 8] | |
1838 | lookup_b[(*p & 0x0000ff)] | |
1721 | lookup_b[(*p & 0x0000ff)] | |
1839 | (*p & ~0xffffff); |
1722 | (*p & 0xff000000); |
|
|
1723 | } |
|
|
1724 | p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1725 | } |
|
|
1726 | } |
|
|
1727 | else |
|
|
1728 | { |
|
|
1729 | for (int y = 0; y < srcImage->height; y++) |
|
|
1730 | for (int x = 0; x < srcImage->width; x++) |
|
|
1731 | { |
|
|
1732 | unsigned long pixel = XGetPixel (srcImage, x, y); |
|
|
1733 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
|
|
1734 | lookup_g[(pixel & mask_g) >> sh_g] | |
|
|
1735 | lookup_b[(pixel & mask_b) >> sh_b]; |
|
|
1736 | XPutPixel (srcImage, x, y, pixel); |
1840 | } |
1737 | } |
1841 | p1 = (RUINT32T *) ((char *) p1 + srcImage->bytes_per_line); |
|
|
1842 | } |
1738 | } |
1843 | break; |
|
|
1844 | } |
|
|
1845 | } |
|
|
1846 | |
1739 | |
1847 | free (lookup); |
1740 | free (lookup); |
1848 | } |
1741 | } |
1849 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |
1742 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |