… | |
… | |
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> |
… | |
… | |
428 | { |
432 | { |
429 | flags = new_flags; |
433 | flags = new_flags; |
430 | changed++; |
434 | changed++; |
431 | } |
435 | } |
432 | |
436 | |
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); |
437 | return (changed > 0); |
436 | } |
438 | } |
437 | |
439 | |
438 | void |
440 | void |
439 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
441 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
… | |
… | |
731 | return false; |
733 | return false; |
732 | |
734 | |
733 | if (!pixbuf) |
735 | if (!pixbuf) |
734 | return false; |
736 | return false; |
735 | |
737 | |
736 | #if !XFT |
|
|
737 | if (background_flags) |
738 | if (background_flags |
|
|
739 | && !(flags & HAS_RENDER)) |
738 | return false; |
740 | return false; |
739 | #endif |
|
|
740 | |
741 | |
741 | GdkPixbuf *result; |
742 | GdkPixbuf *result; |
742 | |
743 | |
743 | int image_width = gdk_pixbuf_get_width (pixbuf); |
744 | int image_width = gdk_pixbuf_get_width (pixbuf); |
744 | int image_height = gdk_pixbuf_get_height (pixbuf); |
745 | int image_height = gdk_pixbuf_get_height (pixbuf); |
… | |
… | |
858 | dst_width, dst_height, |
859 | dst_width, dst_height, |
859 | XLIB_RGB_DITHER_NONE, |
860 | XLIB_RGB_DITHER_NONE, |
860 | 0, 0); |
861 | 0, 0); |
861 | } |
862 | } |
862 | |
863 | |
863 | #if XFT |
864 | #if XRENDER |
864 | if (background_flags) |
865 | if (background_flags) |
865 | { |
866 | { |
866 | Display *dpy = target->dpy; |
867 | Display *dpy = target->dpy; |
867 | XRenderPictureAttributes pa; |
868 | XRenderPictureAttributes pa; |
868 | |
869 | |
869 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); |
870 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); |
870 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
871 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
871 | |
872 | |
872 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
873 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
873 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
874 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
874 | |
875 | |
… | |
… | |
911 | # endif /* HAVE_PIXBUF */ |
912 | # endif /* HAVE_PIXBUF */ |
912 | |
913 | |
913 | bool |
914 | bool |
914 | bgPixmap_t::set_file (const char *file) |
915 | bgPixmap_t::set_file (const char *file) |
915 | { |
916 | { |
916 | assert (file); |
917 | if (!file || !*file) |
|
|
918 | return false; |
917 | |
919 | |
918 | if (*file) |
|
|
919 | { |
|
|
920 | if (const char *p = strchr (file, ';')) |
920 | if (const char *p = strchr (file, ';')) |
921 | { |
921 | { |
922 | size_t len = p - file; |
922 | size_t len = p - file; |
923 | char *f = rxvt_temp_buf<char> (len + 1); |
923 | char *f = rxvt_temp_buf<char> (len + 1); |
924 | memcpy (f, file, len); |
924 | memcpy (f, file, len); |
925 | f[len] = '\0'; |
925 | f[len] = '\0'; |
926 | file = f; |
926 | file = f; |
927 | } |
927 | } |
928 | |
928 | |
929 | # ifdef HAVE_AFTERIMAGE |
929 | # ifdef HAVE_AFTERIMAGE |
930 | if (!target->asimman) |
930 | if (!target->asimman) |
931 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
931 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
932 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
932 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
933 | if (image) |
933 | if (image) |
934 | { |
934 | { |
935 | if (original_asim) |
935 | if (original_asim) |
936 | safe_asimage_destroy (original_asim); |
936 | safe_asimage_destroy (original_asim); |
937 | original_asim = image; |
937 | original_asim = image; |
938 | have_image = true; |
938 | have_image = true; |
939 | return true; |
939 | return true; |
940 | } |
940 | } |
941 | # endif |
941 | # endif |
942 | |
942 | |
943 | # ifdef HAVE_PIXBUF |
943 | # ifdef HAVE_PIXBUF |
944 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
944 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
945 | if (image) |
945 | if (image) |
946 | { |
946 | { |
947 | if (pixbuf) |
947 | if (pixbuf) |
948 | g_object_unref (pixbuf); |
948 | g_object_unref (pixbuf); |
949 | pixbuf = image; |
949 | pixbuf = image; |
950 | have_image = true; |
950 | have_image = true; |
951 | return true; |
951 | return true; |
952 | } |
952 | } |
953 | # endif |
953 | # endif |
954 | } |
|
|
955 | |
954 | |
956 | return false; |
955 | return false; |
957 | } |
956 | } |
958 | |
957 | |
959 | # endif /* BG_IMAGE_FROM_FILE */ |
958 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
1001 | |
1000 | |
1002 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1001 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1003 | flags &= ~blurNeeded; |
1002 | flags &= ~blurNeeded; |
1004 | else |
1003 | else |
1005 | flags |= blurNeeded; |
1004 | flags |= blurNeeded; |
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 | |
1005 | |
1019 | return (changed > 0); |
1006 | return (changed > 0); |
1020 | } |
1007 | } |
1021 | |
1008 | |
1022 | static inline unsigned long |
1009 | static inline unsigned long |
… | |
… | |
1046 | { |
1033 | { |
1047 | flags |= bgPixmap_t::tintNeeded; |
1034 | flags |= bgPixmap_t::tintNeeded; |
1048 | } |
1035 | } |
1049 | } |
1036 | } |
1050 | |
1037 | |
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; |
1038 | return flags; |
1064 | } |
1039 | } |
1065 | |
1040 | |
1066 | bool |
1041 | bool |
1067 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
1042 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
… | |
… | |
1109 | } |
1084 | } |
1110 | |
1085 | |
1111 | return false; |
1086 | return false; |
1112 | } |
1087 | } |
1113 | |
1088 | |
1114 | #if XFT |
1089 | #if XRENDER |
1115 | static void |
1090 | static void |
1116 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1091 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
1117 | { |
1092 | { |
1118 | double sigma = radius / 2.0; |
1093 | double sigma = radius / 2.0; |
1119 | double scale = sqrt (2.0 * M_PI) * sigma; |
1094 | double scale = sqrt (2.0 * M_PI) * sigma; |
… | |
… | |
1136 | |
1111 | |
1137 | bool |
1112 | bool |
1138 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1113 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1139 | { |
1114 | { |
1140 | bool ret = false; |
1115 | bool ret = false; |
1141 | #if XFT |
1116 | #if XRENDER |
1142 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1117 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1143 | double *kernel = (double *)malloc (size * sizeof (double)); |
1118 | double *kernel = (double *)malloc (size * sizeof (double)); |
1144 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1119 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1145 | |
1120 | |
1146 | Display *dpy = target->dpy; |
1121 | Display *dpy = target->dpy; |
… | |
… | |
1223 | XFreeGC (dpy, gc); |
1198 | XFreeGC (dpy, gc); |
1224 | } |
1199 | } |
1225 | } |
1200 | } |
1226 | else |
1201 | else |
1227 | { |
1202 | { |
1228 | # if XFT |
1203 | # if XRENDER |
1229 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1204 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1230 | |
1205 | |
1231 | if (flags & tintSet) |
1206 | if (flags & tintSet) |
1232 | tint.get (c); |
1207 | tint.get (c); |
1233 | |
1208 | |
… | |
… | |
1286 | |
1261 | |
1287 | return ret; |
1262 | return ret; |
1288 | } |
1263 | } |
1289 | |
1264 | |
1290 | /* make_transparency_pixmap() |
1265 | /* make_transparency_pixmap() |
1291 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
1266 | * 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 |
1267 | * the tiled portion of the root pixmap that is supposed to be covered by |
1293 | * our window. |
1268 | * our window. |
1294 | */ |
1269 | */ |
1295 | unsigned long |
1270 | unsigned long |
1296 | bgPixmap_t::make_transparency_pixmap () |
1271 | bgPixmap_t::make_transparency_pixmap () |
1297 | { |
1272 | { |
… | |
… | |
1301 | return 0; |
1276 | return 0; |
1302 | |
1277 | |
1303 | /* root dimensions may change from call to call - but Display structure should |
1278 | /* root dimensions may change from call to call - but Display structure should |
1304 | * be always up-to-date, so let's use it : |
1279 | * be always up-to-date, so let's use it : |
1305 | */ |
1280 | */ |
1306 | Window root = target->display->root; |
|
|
1307 | int screen = target->display->screen; |
1281 | int screen = target->display->screen; |
1308 | Display *dpy = target->dpy; |
1282 | Display *dpy = target->dpy; |
|
|
1283 | int root_depth = DefaultDepth (dpy, screen); |
1309 | int root_width = DisplayWidth (dpy, screen); |
1284 | int root_width = DisplayWidth (dpy, screen); |
1310 | int root_height = DisplayHeight (dpy, screen); |
1285 | int root_height = DisplayHeight (dpy, screen); |
1311 | unsigned int root_pmap_width, root_pmap_height; |
1286 | unsigned int root_pmap_width, root_pmap_height; |
1312 | int window_width = target->szHint.width; |
1287 | int window_width = target->szHint.width; |
1313 | int window_height = target->szHint.height; |
1288 | int window_height = target->szHint.height; |
… | |
… | |
1320 | /* check if we are outside of the visible part of the virtual screen : */ |
1295 | /* check if we are outside of the visible part of the virtual screen : */ |
1321 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1296 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1322 | || sx >= root_width || sy >= root_height) |
1297 | || sx >= root_width || sy >= root_height) |
1323 | return 0; |
1298 | return 0; |
1324 | |
1299 | |
|
|
1300 | // validate root pixmap and get its size |
1325 | if (root_pixmap != None) |
1301 | if (root_pixmap != None) |
1326 | { |
1302 | { |
1327 | /* we want to validate the pixmap and get its size at the same time : */ |
1303 | Window wdummy; |
1328 | int junk; |
1304 | int idummy; |
1329 | unsigned int ujunk; |
1305 | unsigned int udummy; |
1330 | /* root pixmap may be bad - allow a error */ |
1306 | |
1331 | target->allowedxerror = -1; |
1307 | target->allowedxerror = -1; |
1332 | |
1308 | |
1333 | if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) |
1309 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
1334 | root_pixmap = None; |
1310 | root_pixmap = None; |
1335 | |
1311 | |
1336 | target->allowedxerror = 0; |
1312 | target->allowedxerror = 0; |
|
|
1313 | } |
|
|
1314 | |
|
|
1315 | Pixmap recoded_root_pmap = root_pixmap; |
|
|
1316 | |
|
|
1317 | if (root_pixmap != None && root_depth != target->depth) |
|
|
1318 | { |
|
|
1319 | #if XRENDER |
|
|
1320 | if (flags & HAS_RENDER) |
|
|
1321 | { |
|
|
1322 | XRenderPictureAttributes pa; |
|
|
1323 | |
|
|
1324 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
|
|
1325 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
|
|
1326 | |
|
|
1327 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
|
|
1328 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
1329 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
|
|
1330 | |
|
|
1331 | if (src && dst) |
|
|
1332 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
|
|
1333 | else |
|
|
1334 | { |
|
|
1335 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1336 | root_pixmap = None; |
|
|
1337 | } |
|
|
1338 | |
|
|
1339 | XRenderFreePicture (dpy, src); |
|
|
1340 | XRenderFreePicture (dpy, dst); |
|
|
1341 | } |
|
|
1342 | else |
|
|
1343 | #endif |
|
|
1344 | root_pixmap = None; |
1337 | } |
1345 | } |
1338 | |
1346 | |
1339 | if (root_pixmap == None) |
1347 | if (root_pixmap == None) |
1340 | return 0; |
1348 | return 0; |
1341 | |
1349 | |
1342 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
1350 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); |
1343 | |
1351 | |
1344 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1352 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1345 | return 0; |
1353 | return 0; |
1346 | |
1354 | |
1347 | /* straightforward pixmap copy */ |
1355 | /* straightforward pixmap copy */ |
1348 | gcv.tile = root_pixmap; |
1356 | gcv.tile = recoded_root_pmap; |
1349 | gcv.fill_style = FillTiled; |
1357 | gcv.fill_style = FillTiled; |
1350 | |
1358 | |
1351 | while (sx < 0) sx += (int)root_width; |
1359 | while (sx < 0) sx += (int)root_width; |
1352 | while (sy < 0) sy += (int)root_height; |
1360 | while (sy < 0) sy += (int)root_height; |
1353 | |
1361 | |
1354 | gcv.ts_x_origin = -sx; |
1362 | gcv.ts_x_origin = -sx; |
1355 | gcv.ts_y_origin = -sy; |
1363 | gcv.ts_y_origin = -sy; |
1356 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1364 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1357 | |
1365 | |
1358 | if (gc) |
1366 | if (gc) |
1359 | { |
1367 | { |
1360 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1368 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1361 | result |= transpPmapTiled; |
1369 | result |= transpPmapTiled; |
… | |
… | |
1364 | |
1372 | |
1365 | if (tiled_root_pmap != None) |
1373 | if (tiled_root_pmap != None) |
1366 | { |
1374 | { |
1367 | if (!need_client_side_rendering ()) |
1375 | if (!need_client_side_rendering ()) |
1368 | { |
1376 | { |
1369 | if (flags & (blurNeeded | blurServerSide)) |
1377 | if ((flags & blurNeeded) |
|
|
1378 | && (flags & HAS_RENDER_CONV)) |
1370 | { |
1379 | { |
1371 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1380 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1372 | result |= transpPmapBlurred; |
1381 | result |= transpPmapBlurred; |
1373 | } |
1382 | } |
1374 | if (flags & (tintNeeded | tintServerSide)) |
1383 | if ((flags & tintNeeded) |
|
|
1384 | && (flags & (tintWholesome | HAS_RENDER))) |
1375 | { |
1385 | { |
1376 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) |
1386 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1377 | result |= transpPmapTinted; |
1387 | result |= transpPmapTinted; |
1378 | } |
1388 | } |
1379 | } /* server side rendering completed */ |
1389 | } /* server side rendering completed */ |
1380 | |
1390 | |
1381 | if (pixmap) |
1391 | if (pixmap) |
1382 | XFreePixmap (dpy, pixmap); |
1392 | XFreePixmap (dpy, pixmap); |
1383 | |
1393 | |
1384 | pixmap = tiled_root_pmap; |
1394 | pixmap = tiled_root_pmap; |
1385 | pmap_width = window_width; |
1395 | pmap_width = window_width; |
1386 | pmap_height = window_height; |
1396 | pmap_height = window_height; |
1387 | pmap_depth = root_depth; |
1397 | pmap_depth = target->depth; |
1388 | } |
1398 | } |
|
|
1399 | |
|
|
1400 | if (recoded_root_pmap != root_pixmap) |
|
|
1401 | XFreePixmap (dpy, recoded_root_pmap); |
1389 | |
1402 | |
1390 | return result; |
1403 | return result; |
1391 | } |
1404 | } |
1392 | |
1405 | |
1393 | bool |
1406 | void |
1394 | bgPixmap_t::set_root_pixmap () |
1407 | bgPixmap_t::set_root_pixmap () |
1395 | { |
1408 | { |
1396 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1409 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1397 | if (new_root_pixmap == None) |
1410 | if (new_root_pixmap == None) |
1398 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1411 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1399 | |
1412 | |
1400 | if (new_root_pixmap != root_pixmap) |
|
|
1401 | { |
|
|
1402 | root_pixmap = new_root_pixmap; |
1413 | root_pixmap = new_root_pixmap; |
1403 | return true; |
|
|
1404 | } |
|
|
1405 | |
|
|
1406 | return false; |
|
|
1407 | } |
1414 | } |
1408 | # endif /* ENABLE_TRANSPARENCY */ |
1415 | # endif /* ENABLE_TRANSPARENCY */ |
1409 | |
1416 | |
1410 | # ifndef HAVE_AFTERIMAGE |
1417 | # ifndef HAVE_AFTERIMAGE |
1411 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1418 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
… | |
… | |
1425 | { |
1432 | { |
1426 | /* we need to re-generate transparency pixmap in that case ! */ |
1433 | /* we need to re-generate transparency pixmap in that case ! */ |
1427 | background_flags = make_transparency_pixmap (); |
1434 | background_flags = make_transparency_pixmap (); |
1428 | if (background_flags == 0) |
1435 | if (background_flags == 0) |
1429 | return false; |
1436 | return false; |
1430 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1437 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1431 | && pmap_depth == target->depth) |
|
|
1432 | flags = flags & ~isInvalid; |
1438 | flags = flags & ~isInvalid; |
1433 | } |
1439 | } |
1434 | # endif |
1440 | # endif |
1435 | |
1441 | |
1436 | # ifdef BG_IMAGE_FROM_FILE |
1442 | # ifdef BG_IMAGE_FROM_FILE |
… | |
… | |
1449 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1455 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1450 | } |
1456 | } |
1451 | |
1457 | |
1452 | if (result) |
1458 | if (result) |
1453 | { |
1459 | { |
1454 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1460 | # if !defined(HAVE_AFTERIMAGE) && !XRENDER |
1455 | /* our own client-side tinting */ |
1461 | /* 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)) |
1462 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1459 | { |
1463 | { |
1460 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1464 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1461 | if (flags & tintSet) |
1465 | if (flags & tintSet) |
1462 | tint.get (c); |
1466 | tint.get (c); |
… | |
… | |
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 | |
… | |
… | |
1519 | valid_since = ev::now (); |
1495 | valid_since = ev::now (); |
1520 | |
1496 | |
1521 | return true; |
1497 | return true; |
1522 | } |
1498 | } |
1523 | |
1499 | |
1524 | bool |
1500 | void |
1525 | bgPixmap_t::set_target (rxvt_term *new_target) |
1501 | bgPixmap_t::set_target (rxvt_term *new_target) |
1526 | { |
1502 | { |
1527 | if (new_target) |
|
|
1528 | if (target != new_target) |
|
|
1529 | { |
|
|
1530 | target = new_target; |
1503 | target = new_target; |
1531 | # ifdef ENABLE_TRANSPARENCY |
1504 | |
1532 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1505 | flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
|
|
1506 | #if XRENDER |
|
|
1507 | int major, minor; |
|
|
1508 | if (XRenderQueryVersion (target->dpy, &major, &minor)) |
|
|
1509 | flags |= HAS_RENDER; |
|
|
1510 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
|
|
1511 | if (filters) |
|
|
1512 | { |
|
|
1513 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1514 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1515 | flags |= HAS_RENDER_CONV; |
|
|
1516 | |
|
|
1517 | XFree (filters); |
|
|
1518 | } |
1533 | # endif |
1519 | #endif |
1534 | return true; |
|
|
1535 | } |
|
|
1536 | |
|
|
1537 | return false; |
|
|
1538 | } |
1520 | } |
1539 | |
1521 | |
1540 | void |
1522 | void |
1541 | bgPixmap_t::apply () |
1523 | bgPixmap_t::apply () |
1542 | { |
1524 | { |
1543 | if (target) |
1525 | if (target == NULL) |
1544 | { |
1526 | return; |
1545 | flags &= ~isVtOrigin; |
|
|
1546 | |
1527 | |
1547 | if (pixmap != None) |
1528 | if (pixmap != None) |
1548 | { |
1529 | { |
1549 | /* set target's background to pixmap */ |
1530 | /* set target's background to pixmap */ |
1550 | # ifdef ENABLE_TRANSPARENCY |
1531 | # ifdef ENABLE_TRANSPARENCY |
1551 | if (flags & isTransparent) |
1532 | if (flags & isTransparent) |
1552 | { |
1533 | { |
1553 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1534 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1554 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1535 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1555 | |
1536 | |
1556 | if (target->scrollBar.win) |
1537 | if (target->scrollBar.win) |
1557 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1538 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1558 | } |
1539 | } |
1559 | else |
1540 | else |
1560 | # endif |
1541 | # endif |
1561 | { |
1542 | { |
1562 | flags |= isVtOrigin; |
|
|
1563 | /* force old pixmap dereference in case it was transparent before :*/ |
1543 | /* 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]); |
1544 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1576 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1545 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1577 | /* do we also need to set scrollbar's background here ? */ |
1546 | /* do we also need to set scrollbar's background here ? */ |
|
|
1547 | |
1578 | if (target->scrollBar.win) |
1548 | if (target->scrollBar.win) |
1579 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1549 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1580 | } |
1550 | } |
|
|
1551 | } |
|
|
1552 | else |
|
|
1553 | { |
|
|
1554 | /* set target background to a pixel */ |
|
|
1555 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1556 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
1557 | /* do we also need to set scrollbar's background here ? */ |
|
|
1558 | if (target->scrollBar.win) |
|
|
1559 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1560 | } |
1581 | |
1561 | |
1582 | /* don't want Expose on the parent or vt. It is better to use |
1562 | /* 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: */ |
1563 | scr_touch or we get a great deal of flicker otherwise: */ |
1584 | XClearWindow (target->dpy, target->parent[0]); |
1564 | XClearWindow (target->dpy, target->parent[0]); |
1585 | |
1565 | |
1586 | if (target->scrollBar.state && target->scrollBar.win) |
1566 | if (target->scrollBar.state && target->scrollBar.win) |
1587 | { |
1567 | { |
1588 | target->scrollBar.state = STATE_IDLE; |
1568 | target->scrollBar.state = STATE_IDLE; |
1589 | target->scrollBar.show (0); |
1569 | target->scrollBar.show (0); |
1590 | } |
1570 | } |
1591 | |
1571 | |
1592 | target->want_refresh = 1; |
1572 | target->want_refresh = 1; |
1593 | flags |= hasChanged; |
1573 | flags |= hasChanged; |
1594 | } |
|
|
1595 | } |
1574 | } |
1596 | |
1575 | |
1597 | #endif /* HAVE_BG_PIXMAP */ |
1576 | #endif /* HAVE_BG_PIXMAP */ |
1598 | |
1577 | |
1599 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1578 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1600 | /* taken from aterm-0.4.2 */ |
1579 | /* taken from aterm-0.4.2 */ |
1601 | |
1580 | |
1602 | static void |
1581 | static void |
1603 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1582 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1604 | { |
1583 | { |