… | |
… | |
23 | *---------------------------------------------------------------------*/ |
23 | *---------------------------------------------------------------------*/ |
24 | |
24 | |
25 | #include <cmath> |
25 | #include <cmath> |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
|
|
28 | |
|
|
29 | #if XRENDER |
|
|
30 | # include <X11/extensions/Xrender.h> |
|
|
31 | #endif |
28 | |
32 | |
29 | #define DO_TIMING_TEST 0 |
33 | #define DO_TIMING_TEST 0 |
30 | |
34 | |
31 | #if DO_TIMING_TEST |
35 | #if DO_TIMING_TEST |
32 | # include <sys/time.h> |
36 | # include <sys/time.h> |
… | |
… | |
250 | } |
254 | } |
251 | |
255 | |
252 | bool |
256 | bool |
253 | bgPixmap_t::set_geometry (const char *geom) |
257 | bgPixmap_t::set_geometry (const char *geom) |
254 | { |
258 | { |
|
|
259 | bool changed = false; |
255 | int geom_flags = 0, changed = 0; |
260 | int geom_flags = 0; |
256 | int x = 0, y = 0; |
261 | int x = 0, y = 0; |
257 | unsigned int w = 0, h = 0; |
262 | unsigned int w = 0, h = 0; |
258 | unsigned int n; |
263 | unsigned int n; |
259 | unsigned long new_flags = (flags & (~geometryFlags)); |
264 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | const char *p; |
265 | const char *p; |
… | |
… | |
416 | |
421 | |
417 | while (*ops != ':' && *ops != '\0') ++ops; |
422 | while (*ops != ':' && *ops != '\0') ++ops; |
418 | } /* done parsing ops */ |
423 | } /* done parsing ops */ |
419 | } |
424 | } |
420 | |
425 | |
421 | 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; |
422 | 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; |
423 | 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; |
424 | 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; |
425 | } |
430 | } |
426 | |
431 | |
427 | if (new_flags != flags) |
432 | if (new_flags != flags) |
428 | { |
433 | { |
429 | flags = new_flags; |
434 | flags = new_flags; |
430 | changed++; |
435 | changed = true; |
431 | } |
436 | } |
432 | |
437 | |
433 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
|
|
434 | // flags, h_scale, v_scale, h_align, v_align); |
|
|
435 | return (changed > 0); |
438 | return changed; |
436 | } |
439 | } |
437 | |
440 | |
438 | void |
441 | void |
439 | 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) |
440 | { |
443 | { |
… | |
… | |
731 | return false; |
734 | return false; |
732 | |
735 | |
733 | if (!pixbuf) |
736 | if (!pixbuf) |
734 | return false; |
737 | return false; |
735 | |
738 | |
736 | #if !XFT |
|
|
737 | if (background_flags) |
739 | if (background_flags |
|
|
740 | && !(flags & HAS_RENDER)) |
738 | return false; |
741 | return false; |
739 | #endif |
|
|
740 | |
742 | |
741 | GdkPixbuf *result; |
743 | GdkPixbuf *result; |
742 | |
744 | |
743 | int image_width = gdk_pixbuf_get_width (pixbuf); |
745 | int image_width = gdk_pixbuf_get_width (pixbuf); |
744 | int image_height = gdk_pixbuf_get_height (pixbuf); |
746 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
858 | dst_width, dst_height, |
860 | dst_width, dst_height, |
859 | XLIB_RGB_DITHER_NONE, |
861 | XLIB_RGB_DITHER_NONE, |
860 | 0, 0); |
862 | 0, 0); |
861 | } |
863 | } |
862 | |
864 | |
863 | #if XFT |
865 | #if XRENDER |
864 | if (background_flags) |
866 | if (background_flags) |
865 | { |
867 | { |
866 | Display *dpy = target->dpy; |
868 | Display *dpy = target->dpy; |
867 | XRenderPictureAttributes pa; |
869 | XRenderPictureAttributes pa; |
868 | |
870 | |
869 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); |
871 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); |
870 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
872 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
871 | |
873 | |
872 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
874 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
873 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
875 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
874 | |
876 | |
… | |
… | |
911 | # endif /* HAVE_PIXBUF */ |
913 | # endif /* HAVE_PIXBUF */ |
912 | |
914 | |
913 | bool |
915 | bool |
914 | bgPixmap_t::set_file (const char *file) |
916 | bgPixmap_t::set_file (const char *file) |
915 | { |
917 | { |
916 | assert (file); |
918 | if (!file || !*file) |
|
|
919 | return false; |
917 | |
920 | |
918 | if (*file) |
|
|
919 | { |
|
|
920 | if (const char *p = strchr (file, ';')) |
921 | if (const char *p = strchr (file, ';')) |
921 | { |
922 | { |
922 | size_t len = p - file; |
923 | size_t len = p - file; |
923 | char *f = rxvt_temp_buf<char> (len + 1); |
924 | char *f = rxvt_temp_buf<char> (len + 1); |
924 | memcpy (f, file, len); |
925 | memcpy (f, file, len); |
925 | f[len] = '\0'; |
926 | f[len] = '\0'; |
926 | file = f; |
927 | file = f; |
927 | } |
928 | } |
928 | |
929 | |
929 | # ifdef HAVE_AFTERIMAGE |
930 | # ifdef HAVE_AFTERIMAGE |
930 | if (!target->asimman) |
931 | if (!target->asimman) |
931 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
932 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
932 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
933 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
933 | if (image) |
934 | if (image) |
934 | { |
935 | { |
935 | if (original_asim) |
936 | if (original_asim) |
936 | safe_asimage_destroy (original_asim); |
937 | safe_asimage_destroy (original_asim); |
937 | original_asim = image; |
938 | original_asim = image; |
938 | have_image = true; |
939 | have_image = true; |
939 | return true; |
940 | return true; |
940 | } |
941 | } |
941 | # endif |
942 | # endif |
942 | |
943 | |
943 | # ifdef HAVE_PIXBUF |
944 | # ifdef HAVE_PIXBUF |
944 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
945 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
945 | if (image) |
946 | if (image) |
946 | { |
947 | { |
947 | if (pixbuf) |
948 | if (pixbuf) |
948 | g_object_unref (pixbuf); |
949 | g_object_unref (pixbuf); |
949 | pixbuf = image; |
950 | pixbuf = image; |
950 | have_image = true; |
951 | have_image = true; |
951 | return true; |
952 | return true; |
952 | } |
953 | } |
953 | # endif |
954 | # endif |
954 | } |
|
|
955 | |
955 | |
956 | return false; |
956 | return false; |
957 | } |
957 | } |
958 | |
958 | |
959 | # endif /* BG_IMAGE_FROM_FILE */ |
959 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
972 | } |
972 | } |
973 | |
973 | |
974 | bool |
974 | bool |
975 | bgPixmap_t::set_blur_radius (const char *geom) |
975 | bgPixmap_t::set_blur_radius (const char *geom) |
976 | { |
976 | { |
977 | int changed = 0; |
977 | bool changed = false; |
978 | unsigned int hr, vr; |
978 | unsigned int hr, vr; |
979 | int junk; |
979 | int junk; |
980 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
980 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
981 | |
981 | |
982 | if (!(geom_flags & WidthValue)) |
982 | if (!(geom_flags & WidthValue)) |
… | |
… | |
987 | min_it (hr, 128); |
987 | min_it (hr, 128); |
988 | min_it (vr, 128); |
988 | min_it (vr, 128); |
989 | |
989 | |
990 | if (h_blurRadius != hr) |
990 | if (h_blurRadius != hr) |
991 | { |
991 | { |
992 | ++changed; |
992 | changed = true; |
993 | h_blurRadius = hr; |
993 | h_blurRadius = hr; |
994 | } |
994 | } |
995 | |
995 | |
996 | if (v_blurRadius != vr) |
996 | if (v_blurRadius != vr) |
997 | { |
997 | { |
998 | ++changed; |
998 | changed = true; |
999 | v_blurRadius = vr; |
999 | v_blurRadius = vr; |
1000 | } |
1000 | } |
1001 | |
1001 | |
1002 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1002 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1003 | flags &= ~blurNeeded; |
1003 | flags &= ~blurNeeded; |
1004 | else |
1004 | else |
1005 | flags |= blurNeeded; |
1005 | flags |= blurNeeded; |
1006 | |
1006 | |
1007 | #if XFT |
|
|
1008 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
|
|
1009 | if (filters) |
|
|
1010 | { |
|
|
1011 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1012 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1013 | flags |= bgPixmap_t::blurServerSide; |
|
|
1014 | |
|
|
1015 | XFree (filters); |
|
|
1016 | } |
|
|
1017 | #endif |
|
|
1018 | |
|
|
1019 | return (changed > 0); |
1007 | return changed; |
1020 | } |
1008 | } |
1021 | |
1009 | |
1022 | static inline unsigned long |
1010 | static inline unsigned long |
1023 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1011 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1024 | { |
1012 | { |
… | |
… | |
1046 | { |
1034 | { |
1047 | flags |= bgPixmap_t::tintNeeded; |
1035 | flags |= bgPixmap_t::tintNeeded; |
1048 | } |
1036 | } |
1049 | } |
1037 | } |
1050 | |
1038 | |
1051 | if (flags & bgPixmap_t::tintNeeded) |
|
|
1052 | { |
|
|
1053 | if (flags & bgPixmap_t::tintWholesome) |
|
|
1054 | flags |= bgPixmap_t::tintServerSide; |
|
|
1055 | else |
|
|
1056 | { |
|
|
1057 | #if XFT |
|
|
1058 | flags |= bgPixmap_t::tintServerSide; |
|
|
1059 | #endif |
|
|
1060 | } |
|
|
1061 | } |
|
|
1062 | |
|
|
1063 | return flags; |
1039 | return flags; |
1064 | } |
1040 | } |
1065 | |
1041 | |
1066 | bool |
1042 | bool |
1067 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
1043 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
… | |
… | |
1109 | } |
1085 | } |
1110 | |
1086 | |
1111 | return false; |
1087 | return false; |
1112 | } |
1088 | } |
1113 | |
1089 | |
1114 | #if XFT |
1090 | #if XRENDER |
1115 | static void |
1091 | static void |
1116 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1092 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1117 | { |
1093 | { |
1118 | double sigma = radius / 2.0; |
1094 | double sigma = radius / 2.0; |
1119 | double scale = sqrt (2.0 * M_PI) * sigma; |
1095 | double scale = sqrt (2.0 * M_PI) * sigma; |
… | |
… | |
1136 | |
1112 | |
1137 | bool |
1113 | bool |
1138 | 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) |
1139 | { |
1115 | { |
1140 | bool ret = false; |
1116 | bool ret = false; |
1141 | #if XFT |
1117 | #if XRENDER |
1142 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1118 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1143 | double *kernel = (double *)malloc (size * sizeof (double)); |
1119 | double *kernel = (double *)malloc (size * sizeof (double)); |
1144 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1120 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1145 | |
1121 | |
1146 | Display *dpy = target->dpy; |
1122 | Display *dpy = target->dpy; |
… | |
… | |
1223 | XFreeGC (dpy, gc); |
1199 | XFreeGC (dpy, gc); |
1224 | } |
1200 | } |
1225 | } |
1201 | } |
1226 | else |
1202 | else |
1227 | { |
1203 | { |
1228 | # if XFT |
1204 | # if XRENDER |
1229 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1205 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1230 | |
1206 | |
1231 | if (flags & tintSet) |
1207 | if (flags & tintSet) |
1232 | tint.get (c); |
1208 | tint.get (c); |
1233 | |
1209 | |
… | |
… | |
1286 | |
1262 | |
1287 | return ret; |
1263 | return ret; |
1288 | } |
1264 | } |
1289 | |
1265 | |
1290 | /* make_transparency_pixmap() |
1266 | /* make_transparency_pixmap() |
1291 | * 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 |
1292 | * 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 |
1293 | * our window. |
1269 | * our window. |
1294 | */ |
1270 | */ |
1295 | unsigned long |
1271 | unsigned long |
1296 | bgPixmap_t::make_transparency_pixmap () |
1272 | bgPixmap_t::make_transparency_pixmap () |
1297 | { |
1273 | { |
… | |
… | |
1301 | return 0; |
1277 | return 0; |
1302 | |
1278 | |
1303 | /* 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 |
1304 | * be always up-to-date, so let's use it : |
1280 | * be always up-to-date, so let's use it : |
1305 | */ |
1281 | */ |
1306 | Window root = target->display->root; |
|
|
1307 | int screen = target->display->screen; |
1282 | int screen = target->display->screen; |
1308 | Display *dpy = target->dpy; |
1283 | Display *dpy = target->dpy; |
|
|
1284 | int root_depth = DefaultDepth (dpy, screen); |
1309 | int root_width = DisplayWidth (dpy, screen); |
1285 | int root_width = DisplayWidth (dpy, screen); |
1310 | int root_height = DisplayHeight (dpy, screen); |
1286 | int root_height = DisplayHeight (dpy, screen); |
1311 | unsigned int root_pmap_width, root_pmap_height; |
1287 | unsigned int root_pmap_width, root_pmap_height; |
1312 | int window_width = target->szHint.width; |
1288 | int window_width = target->szHint.width; |
1313 | int window_height = target->szHint.height; |
1289 | int window_height = target->szHint.height; |
… | |
… | |
1320 | /* 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 : */ |
1321 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1297 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1322 | || sx >= root_width || sy >= root_height) |
1298 | || sx >= root_width || sy >= root_height) |
1323 | return 0; |
1299 | return 0; |
1324 | |
1300 | |
|
|
1301 | // validate root pixmap and get its size |
1325 | if (root_pixmap != None) |
1302 | if (root_pixmap != None) |
1326 | { |
1303 | { |
1327 | /* we want to validate the pixmap and get its size at the same time : */ |
1304 | Window wdummy; |
1328 | int junk; |
1305 | int idummy; |
1329 | unsigned int ujunk; |
1306 | unsigned int udummy; |
1330 | /* root pixmap may be bad - allow a error */ |
1307 | |
1331 | target->allowedxerror = -1; |
1308 | target->allowedxerror = -1; |
1332 | |
1309 | |
1333 | 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)) |
1334 | root_pixmap = None; |
1311 | root_pixmap = None; |
1335 | |
1312 | |
1336 | 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; |
1337 | } |
1346 | } |
1338 | |
1347 | |
1339 | if (root_pixmap == None) |
1348 | if (root_pixmap == None) |
1340 | return 0; |
1349 | return 0; |
1341 | |
1350 | |
1342 | 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); |
1343 | |
1352 | |
1344 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1353 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1345 | return 0; |
1354 | return 0; |
1346 | |
1355 | |
1347 | /* straightforward pixmap copy */ |
1356 | /* straightforward pixmap copy */ |
1348 | gcv.tile = root_pixmap; |
1357 | gcv.tile = recoded_root_pmap; |
1349 | gcv.fill_style = FillTiled; |
1358 | gcv.fill_style = FillTiled; |
1350 | |
1359 | |
1351 | while (sx < 0) sx += (int)root_width; |
1360 | while (sx < 0) sx += (int)root_width; |
1352 | while (sy < 0) sy += (int)root_height; |
1361 | while (sy < 0) sy += (int)root_height; |
1353 | |
1362 | |
1354 | gcv.ts_x_origin = -sx; |
1363 | gcv.ts_x_origin = -sx; |
1355 | gcv.ts_y_origin = -sy; |
1364 | gcv.ts_y_origin = -sy; |
1356 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1365 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1357 | |
1366 | |
1358 | if (gc) |
1367 | if (gc) |
1359 | { |
1368 | { |
1360 | 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); |
1361 | result |= transpPmapTiled; |
1370 | result |= transpPmapTiled; |
… | |
… | |
1364 | |
1373 | |
1365 | if (tiled_root_pmap != None) |
1374 | if (tiled_root_pmap != None) |
1366 | { |
1375 | { |
1367 | if (!need_client_side_rendering ()) |
1376 | if (!need_client_side_rendering ()) |
1368 | { |
1377 | { |
1369 | if (flags & (blurNeeded | blurServerSide)) |
1378 | if ((flags & blurNeeded) |
|
|
1379 | && (flags & HAS_RENDER_CONV)) |
1370 | { |
1380 | { |
1371 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1381 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1372 | result |= transpPmapBlurred; |
1382 | result |= transpPmapBlurred; |
1373 | } |
1383 | } |
1374 | if (flags & (tintNeeded | tintServerSide)) |
1384 | if ((flags & tintNeeded) |
|
|
1385 | && (flags & (tintWholesome | HAS_RENDER))) |
1375 | { |
1386 | { |
1376 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1387 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1377 | result |= transpPmapTinted; |
1388 | result |= transpPmapTinted; |
1378 | } |
1389 | } |
1379 | } /* server side rendering completed */ |
1390 | } /* server side rendering completed */ |
1380 | |
1391 | |
1381 | if (pixmap) |
1392 | if (pixmap) |
1382 | XFreePixmap (dpy, pixmap); |
1393 | XFreePixmap (dpy, pixmap); |
1383 | |
1394 | |
1384 | pixmap = tiled_root_pmap; |
1395 | pixmap = tiled_root_pmap; |
1385 | pmap_width = window_width; |
1396 | pmap_width = window_width; |
1386 | pmap_height = window_height; |
1397 | pmap_height = window_height; |
1387 | pmap_depth = root_depth; |
1398 | pmap_depth = target->depth; |
1388 | } |
1399 | } |
|
|
1400 | |
|
|
1401 | if (recoded_root_pmap != root_pixmap) |
|
|
1402 | XFreePixmap (dpy, recoded_root_pmap); |
1389 | |
1403 | |
1390 | return result; |
1404 | return result; |
1391 | } |
1405 | } |
1392 | |
1406 | |
1393 | bool |
1407 | void |
1394 | bgPixmap_t::set_root_pixmap () |
1408 | bgPixmap_t::set_root_pixmap () |
1395 | { |
1409 | { |
1396 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1410 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1397 | if (new_root_pixmap == None) |
1411 | if (new_root_pixmap == None) |
1398 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1412 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1399 | |
1413 | |
1400 | if (new_root_pixmap != root_pixmap) |
|
|
1401 | { |
|
|
1402 | root_pixmap = new_root_pixmap; |
1414 | root_pixmap = new_root_pixmap; |
1403 | return true; |
|
|
1404 | } |
|
|
1405 | |
|
|
1406 | return false; |
|
|
1407 | } |
1415 | } |
1408 | # endif /* ENABLE_TRANSPARENCY */ |
1416 | # endif /* ENABLE_TRANSPARENCY */ |
1409 | |
1417 | |
1410 | # ifndef HAVE_AFTERIMAGE |
1418 | # ifndef HAVE_AFTERIMAGE |
1411 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1419 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
… | |
… | |
1425 | { |
1433 | { |
1426 | /* we need to re-generate transparency pixmap in that case ! */ |
1434 | /* we need to re-generate transparency pixmap in that case ! */ |
1427 | background_flags = make_transparency_pixmap (); |
1435 | background_flags = make_transparency_pixmap (); |
1428 | if (background_flags == 0) |
1436 | if (background_flags == 0) |
1429 | return false; |
1437 | return false; |
1430 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1438 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1431 | && pmap_depth == target->depth) |
|
|
1432 | flags = flags & ~isInvalid; |
1439 | flags = flags & ~isInvalid; |
1433 | } |
1440 | } |
1434 | # endif |
1441 | # endif |
1435 | |
1442 | |
1436 | # ifdef BG_IMAGE_FROM_FILE |
1443 | # ifdef BG_IMAGE_FROM_FILE |
… | |
… | |
1440 | if (render_image (background_flags)) |
1447 | if (render_image (background_flags)) |
1441 | flags = flags & ~isInvalid; |
1448 | flags = flags & ~isInvalid; |
1442 | } |
1449 | } |
1443 | # endif |
1450 | # endif |
1444 | |
1451 | |
|
|
1452 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1445 | XImage *result = NULL; |
1453 | XImage *result = NULL; |
1446 | |
1454 | |
1447 | if (background_flags && (flags & isInvalid)) |
1455 | if (background_flags && (flags & isInvalid)) |
1448 | { |
1456 | { |
1449 | 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); |
1450 | } |
1458 | } |
1451 | |
1459 | |
1452 | if (result) |
1460 | if (result) |
1453 | { |
1461 | { |
1454 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
|
|
1455 | /* our own client-side tinting */ |
1462 | /* our own client-side tinting */ |
1456 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
|
|
1457 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
|
|
1458 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1463 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1459 | { |
1464 | { |
1460 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1465 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1461 | if (flags & tintSet) |
1466 | if (flags & tintSet) |
1462 | tint.get (c); |
1467 | tint.get (c); |
1463 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1468 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1464 | } |
1469 | } |
1465 | # endif |
|
|
1466 | |
1470 | |
1467 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1471 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1468 | |
1472 | |
1469 | if (gc) |
1473 | if (gc) |
1470 | { |
1474 | { |
1471 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
|
|
1472 | { |
|
|
1473 | XFreePixmap (target->dpy, pixmap); |
|
|
1474 | pixmap = None; |
|
|
1475 | } |
|
|
1476 | |
|
|
1477 | if (pixmap == None) |
|
|
1478 | { |
|
|
1479 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
|
|
1480 | pmap_width = result->width; |
|
|
1481 | pmap_height = result->height; |
|
|
1482 | pmap_depth = target->depth; |
|
|
1483 | } |
|
|
1484 | |
|
|
1485 | if (pmap_depth != result->depth) |
|
|
1486 | { |
|
|
1487 | /* Bad Match error will ensue ! stupid X !!!! */ |
|
|
1488 | if (result->depth == 24 && pmap_depth == 32) |
|
|
1489 | result->depth = 32; |
|
|
1490 | else if (result->depth == 32 && pmap_depth == 24) |
|
|
1491 | result->depth = 24; |
|
|
1492 | else |
|
|
1493 | { |
|
|
1494 | /* TODO: implement image recoding */ |
|
|
1495 | } |
|
|
1496 | } |
|
|
1497 | |
|
|
1498 | if (pmap_depth == result->depth) |
|
|
1499 | 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); |
1500 | |
1476 | |
1501 | XFreeGC (target->dpy, gc); |
1477 | XFreeGC (target->dpy, gc); |
1502 | flags = flags & ~isInvalid; |
1478 | flags = flags & ~isInvalid; |
1503 | } |
1479 | } |
1504 | |
1480 | |
1505 | XDestroyImage (result); |
1481 | XDestroyImage (result); |
1506 | } |
1482 | } |
|
|
1483 | # endif |
1507 | |
1484 | |
1508 | if (flags & isInvalid) |
1485 | if (flags & isInvalid) |
1509 | { |
1486 | { |
1510 | if (pixmap != None) |
1487 | if (pixmap != None) |
1511 | { |
1488 | { |
… | |
… | |
1519 | valid_since = ev::now (); |
1496 | valid_since = ev::now (); |
1520 | |
1497 | |
1521 | return true; |
1498 | return true; |
1522 | } |
1499 | } |
1523 | |
1500 | |
1524 | bool |
1501 | void |
1525 | bgPixmap_t::set_target (rxvt_term *new_target) |
1502 | bgPixmap_t::set_target (rxvt_term *new_target) |
1526 | { |
1503 | { |
1527 | if (new_target) |
|
|
1528 | if (target != new_target) |
|
|
1529 | { |
|
|
1530 | target = new_target; |
1504 | target = new_target; |
1531 | # ifdef ENABLE_TRANSPARENCY |
1505 | |
1532 | 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 | } |
1533 | # endif |
1520 | #endif |
1534 | return true; |
|
|
1535 | } |
|
|
1536 | |
|
|
1537 | return false; |
|
|
1538 | } |
1521 | } |
1539 | |
1522 | |
1540 | void |
1523 | void |
1541 | bgPixmap_t::apply () |
1524 | bgPixmap_t::apply () |
1542 | { |
1525 | { |
1543 | if (target) |
1526 | if (target == NULL) |
1544 | { |
1527 | return; |
1545 | flags &= ~isVtOrigin; |
|
|
1546 | |
1528 | |
1547 | if (pixmap != None) |
1529 | if (pixmap != None) |
1548 | { |
1530 | { |
1549 | /* set target's background to pixmap */ |
1531 | /* set target's background to pixmap */ |
1550 | # ifdef ENABLE_TRANSPARENCY |
1532 | # ifdef ENABLE_TRANSPARENCY |
1551 | if (flags & isTransparent) |
1533 | if (flags & isTransparent) |
1552 | { |
1534 | { |
1553 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1535 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1554 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1536 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1555 | |
1537 | |
1556 | if (target->scrollBar.win) |
1538 | if (target->scrollBar.win) |
1557 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1539 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1558 | } |
1540 | } |
1559 | else |
1541 | else |
1560 | # endif |
1542 | # endif |
1561 | { |
1543 | { |
1562 | flags |= isVtOrigin; |
|
|
1563 | /* force old pixmap dereference in case it was transparent before :*/ |
1544 | /* force old pixmap dereference in case it was transparent before :*/ |
1564 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1565 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1566 | /* do we also need to set scrollbar's background here ? */ |
|
|
1567 | |
|
|
1568 | if (target->scrollBar.win) |
|
|
1569 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1570 | } |
|
|
1571 | } |
|
|
1572 | else |
|
|
1573 | { |
|
|
1574 | /* set target background to a pixel */ |
|
|
1575 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1545 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1576 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1546 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1577 | /* do we also need to set scrollbar's background here ? */ |
1547 | /* do we also need to set scrollbar's background here ? */ |
|
|
1548 | |
1578 | if (target->scrollBar.win) |
1549 | if (target->scrollBar.win) |
1579 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1550 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1580 | } |
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 | } |
1581 | |
1562 | |
1582 | /* 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 |
1583 | scr_touch or we get a great deal of flicker otherwise: */ |
1564 | scr_touch or we get a great deal of flicker otherwise: */ |
1584 | XClearWindow (target->dpy, target->parent[0]); |
1565 | XClearWindow (target->dpy, target->parent[0]); |
1585 | |
1566 | |
1586 | if (target->scrollBar.state && target->scrollBar.win) |
1567 | if (target->scrollBar.state && target->scrollBar.win) |
1587 | { |
1568 | { |
1588 | target->scrollBar.state = STATE_IDLE; |
1569 | target->scrollBar.state = STATE_IDLE; |
1589 | target->scrollBar.show (0); |
1570 | target->scrollBar.show (0); |
1590 | } |
1571 | } |
1591 | |
1572 | |
1592 | target->want_refresh = 1; |
1573 | target->want_refresh = 1; |
1593 | flags |= hasChanged; |
1574 | flags |= hasChanged; |
1594 | } |
|
|
1595 | } |
1575 | } |
1596 | |
1576 | |
1597 | #endif /* HAVE_BG_PIXMAP */ |
1577 | #endif /* HAVE_BG_PIXMAP */ |
1598 | |
1578 | |
1599 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1579 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1600 | /* taken from aterm-0.4.2 */ |
1580 | /* taken from aterm-0.4.2 */ |
1601 | |
1581 | |
1602 | static void |
1582 | static void |
1603 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1583 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1604 | { |
1584 | { |