ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.104 by sf-exg, Sun Oct 31 17:44:39 2010 UTC vs.
Revision 1.118 by sf-exg, Tue Nov 16 15:49:56 2010 UTC

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
32
33#ifndef FilterConvolution
34#define FilterConvolution "convolution"
35#endif
28 36
29#define DO_TIMING_TEST 0 37#define DO_TIMING_TEST 0
30 38
31#if DO_TIMING_TEST 39#if DO_TIMING_TEST
32# include <sys/time.h> 40# include <sys/time.h>
168 return true; 176 return true;
169 } 177 }
170# endif 178# endif
171 179
172 return false; 180 return false;
173}; 181}
174 182
175bool bgPixmap_t::need_client_side_rendering () 183bool bgPixmap_t::need_client_side_rendering ()
176{ 184{
177# ifdef HAVE_AFTERIMAGE 185# ifdef HAVE_AFTERIMAGE
178 if (original_asim) 186 if (original_asim)
250} 258}
251 259
252bool 260bool
253bgPixmap_t::set_geometry (const char *geom) 261bgPixmap_t::set_geometry (const char *geom)
254{ 262{
263 bool changed = false;
255 int geom_flags = 0, changed = 0; 264 int geom_flags = 0;
256 int x = 0, y = 0; 265 int x = 0, y = 0;
257 unsigned int w = 0, h = 0; 266 unsigned int w = 0, h = 0;
258 unsigned int n; 267 unsigned int n;
259 unsigned long new_flags = (flags & (~geometryFlags)); 268 unsigned long new_flags = (flags & (~geometryFlags));
260 const char *p; 269 const char *p;
416 425
417 while (*ops != ':' && *ops != '\0') ++ops; 426 while (*ops != ':' && *ops != '\0') ++ops;
418 } /* done parsing ops */ 427 } /* done parsing ops */
419 } 428 }
420 429
421 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; 430 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; 431 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; 432 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; 433 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
425 } 434 }
426 435
427 if (new_flags != flags) 436 if (new_flags != flags)
428 { 437 {
429 flags = new_flags; 438 flags = new_flags;
430 changed++; 439 changed = true;
431 } 440 }
432 441
433 return (changed > 0); 442 return changed;
434} 443}
435 444
436void 445void
437bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 446bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
438{ 447{
661 if (result) 670 if (result)
662 { 671 {
663 XGCValues gcv; 672 XGCValues gcv;
664 GC gc; 673 GC gc;
665 674
666 if (pixmap)
667 {
668 if (pmap_width != new_pmap_width
669 || pmap_height != new_pmap_height
670 || pmap_depth != target->depth)
671 {
672 XFreePixmap (target->dpy, pixmap);
673 pixmap = None;
674 }
675 }
676
677 /* create Pixmap */ 675 /* create Pixmap */
678 if (pixmap == None) 676 if (pixmap == None
677 || pmap_width != new_pmap_width
678 || pmap_height != new_pmap_height
679 || pmap_depth != target->depth)
679 { 680 {
681 if (pixmap)
682 XFreePixmap (target->dpy, pixmap);
680 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 683 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
681 pmap_width = new_pmap_width; 684 pmap_width = new_pmap_width;
682 pmap_height = new_pmap_height; 685 pmap_height = new_pmap_height;
683 pmap_depth = target->depth; 686 pmap_depth = target->depth;
684 } 687 }
729 return false; 732 return false;
730 733
731 if (!pixbuf) 734 if (!pixbuf)
732 return false; 735 return false;
733 736
734#if !XRENDER
735 if (background_flags) 737 if (background_flags
738 && !(flags & HAS_RENDER))
736 return false; 739 return false;
737#endif
738 740
739 GdkPixbuf *result; 741 GdkPixbuf *result;
740 742
741 int image_width = gdk_pixbuf_get_width (pixbuf); 743 int image_width = gdk_pixbuf_get_width (pixbuf);
742 int image_height = gdk_pixbuf_get_height (pixbuf); 744 int image_height = gdk_pixbuf_get_height (pixbuf);
793 new_pmap_width = min (image_width, target_width); 795 new_pmap_width = min (image_width, target_width);
794 new_pmap_height = min (image_height, target_height); 796 new_pmap_height = min (image_height, target_height);
795 } 797 }
796 } 798 }
797 799
798 if (pixmap)
799 {
800 if (pmap_width != new_pmap_width
801 || pmap_height != new_pmap_height
802 || pmap_depth != target->depth)
803 {
804 XFreePixmap (target->dpy, pixmap);
805 pixmap = None;
806 }
807 }
808
809 if (pixmap == None) 800 if (pixmap == None
801 || pmap_width != new_pmap_width
802 || pmap_height != new_pmap_height
803 || pmap_depth != target->depth)
810 { 804 {
805 if (pixmap)
806 XFreePixmap (target->dpy, pixmap);
811 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); 807 pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth);
812 pmap_width = new_pmap_width; 808 pmap_width = new_pmap_width;
813 pmap_height = new_pmap_height; 809 pmap_height = new_pmap_height;
814 pmap_depth = target->depth; 810 pmap_depth = target->depth;
815 } 811 }
909# endif /* HAVE_PIXBUF */ 905# endif /* HAVE_PIXBUF */
910 906
911bool 907bool
912bgPixmap_t::set_file (const char *file) 908bgPixmap_t::set_file (const char *file)
913{ 909{
914 assert (file); 910 if (!file || !*file)
911 return false;
915 912
916 if (*file)
917 {
918 if (const char *p = strchr (file, ';')) 913 if (const char *p = strchr (file, ';'))
919 { 914 {
920 size_t len = p - file; 915 size_t len = p - file;
921 char *f = rxvt_temp_buf<char> (len + 1); 916 char *f = rxvt_temp_buf<char> (len + 1);
922 memcpy (f, file, len); 917 memcpy (f, file, len);
923 f[len] = '\0'; 918 f[len] = '\0';
924 file = f; 919 file = f;
925 } 920 }
926 921
927# ifdef HAVE_AFTERIMAGE 922# ifdef HAVE_AFTERIMAGE
928 if (!target->asimman) 923 if (!target->asimman)
929 target->asimman = create_generic_imageman (target->rs[Rs_path]); 924 target->asimman = create_generic_imageman (target->rs[Rs_path]);
930 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 925 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
931 if (image) 926 if (image)
932 { 927 {
933 if (original_asim) 928 if (original_asim)
934 safe_asimage_destroy (original_asim); 929 safe_asimage_destroy (original_asim);
935 original_asim = image; 930 original_asim = image;
936 have_image = true; 931 have_image = true;
937 return true; 932 return true;
938 } 933 }
939# endif 934# endif
940 935
941# ifdef HAVE_PIXBUF 936# ifdef HAVE_PIXBUF
942 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 937 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
943 if (image) 938 if (image)
944 { 939 {
945 if (pixbuf) 940 if (pixbuf)
946 g_object_unref (pixbuf); 941 g_object_unref (pixbuf);
947 pixbuf = image; 942 pixbuf = image;
948 have_image = true; 943 have_image = true;
949 return true; 944 return true;
950 } 945 }
951# endif 946# endif
952 }
953 947
954 return false; 948 return false;
955} 949}
956 950
957# endif /* BG_IMAGE_FROM_FILE */ 951# endif /* BG_IMAGE_FROM_FILE */
970} 964}
971 965
972bool 966bool
973bgPixmap_t::set_blur_radius (const char *geom) 967bgPixmap_t::set_blur_radius (const char *geom)
974{ 968{
975 int changed = 0; 969 bool changed = false;
976 unsigned int hr, vr; 970 unsigned int hr, vr;
977 int junk; 971 int junk;
978 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 972 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
979 973
980 if (!(geom_flags & WidthValue)) 974 if (!(geom_flags & WidthValue))
985 min_it (hr, 128); 979 min_it (hr, 128);
986 min_it (vr, 128); 980 min_it (vr, 128);
987 981
988 if (h_blurRadius != hr) 982 if (h_blurRadius != hr)
989 { 983 {
990 ++changed; 984 changed = true;
991 h_blurRadius = hr; 985 h_blurRadius = hr;
992 } 986 }
993 987
994 if (v_blurRadius != vr) 988 if (v_blurRadius != vr)
995 { 989 {
996 ++changed; 990 changed = true;
997 v_blurRadius = vr; 991 v_blurRadius = vr;
998 } 992 }
999 993
1000 if (v_blurRadius == 0 && h_blurRadius == 0) 994 if (v_blurRadius == 0 && h_blurRadius == 0)
1001 flags &= ~blurNeeded; 995 flags &= ~blurNeeded;
1002 else 996 else
1003 flags |= blurNeeded; 997 flags |= blurNeeded;
1004 998
1005#if XRENDER
1006 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1007 if (filters)
1008 {
1009 for (int i = 0; i < filters->nfilter; i++)
1010 if (!strcmp (filters->filter[i], FilterConvolution))
1011 flags |= bgPixmap_t::blurServerSide;
1012
1013 XFree (filters);
1014 }
1015#endif
1016
1017 return (changed > 0); 999 return changed;
1018} 1000}
1019 1001
1020static inline unsigned long 1002static inline unsigned long
1021compute_tint_shade_flags (rxvt_color *tint, int shade) 1003compute_tint_shade_flags (rxvt_color *tint, int shade)
1022{ 1004{
1041 { 1023 {
1042 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 1024 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
1043 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 1025 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
1044 { 1026 {
1045 flags |= bgPixmap_t::tintNeeded; 1027 flags |= bgPixmap_t::tintNeeded;
1046 }
1047 }
1048
1049 if (flags & bgPixmap_t::tintNeeded)
1050 {
1051 if (flags & bgPixmap_t::tintWholesome)
1052 flags |= bgPixmap_t::tintServerSide;
1053 else
1054 {
1055#if XRENDER
1056 flags |= bgPixmap_t::tintServerSide;
1057#endif
1058 } 1028 }
1059 } 1029 }
1060 1030
1061 return flags; 1031 return flags;
1062} 1032}
1261 1231
1262 if (mask_pic && overlay_pic && back_pic) 1232 if (mask_pic && overlay_pic && back_pic)
1263 { 1233 {
1264 XRenderColor mask_c; 1234 XRenderColor mask_c;
1265 1235
1266 memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); 1236 mask_c.red = mask_c.green = mask_c.blue = shade > 100 ? 0xffff : 0;
1267 mask_c.alpha = 0xffff; 1237 mask_c.alpha = 0xffff;
1268 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); 1238 XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1);
1269 1239
1270 mask_c.alpha = 0; 1240 mask_c.alpha = 0;
1271 mask_c.red = 0xffff - c.r; 1241 mask_c.red = 0xffff - c.r;
1338 Pixmap recoded_root_pmap = root_pixmap; 1308 Pixmap recoded_root_pmap = root_pixmap;
1339 1309
1340 if (root_pixmap != None && root_depth != target->depth) 1310 if (root_pixmap != None && root_depth != target->depth)
1341 { 1311 {
1342#if XRENDER 1312#if XRENDER
1313 if (flags & HAS_RENDER)
1314 {
1343 XRenderPictureAttributes pa; 1315 XRenderPictureAttributes pa;
1344 1316
1345 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); 1317 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen));
1346 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); 1318 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1347 1319
1348 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); 1320 recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth);
1349 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 1321 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1350 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); 1322 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1351 1323
1352 if (src && dst) 1324 if (src && dst)
1353 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); 1325 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height);
1326 else
1327 {
1328 XFreePixmap (dpy, recoded_root_pmap);
1329 root_pixmap = None;
1330 }
1331
1332 XRenderFreePicture (dpy, src);
1333 XRenderFreePicture (dpy, dst);
1334 }
1354 else 1335 else
1355 { 1336#endif
1356 XFreePixmap (dpy, recoded_root_pmap);
1357 root_pixmap = None;
1358 }
1359
1360 XRenderFreePicture (dpy, src);
1361 XRenderFreePicture (dpy, dst);
1362#else
1363 root_pixmap = None; 1337 root_pixmap = None;
1364#endif
1365 } 1338 }
1366 1339
1367 if (root_pixmap == None) 1340 if (root_pixmap == None)
1368 return 0; 1341 return 0;
1369 1342
1386 if (gc) 1359 if (gc)
1387 { 1360 {
1388 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1361 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1389 result |= transpPmapTiled; 1362 result |= transpPmapTiled;
1390 XFreeGC (dpy, gc); 1363 XFreeGC (dpy, gc);
1391 }
1392 1364
1393 if (tiled_root_pmap != None)
1394 {
1395 if (!need_client_side_rendering ()) 1365 if (!need_client_side_rendering ())
1396 { 1366 {
1397 if (flags & (blurNeeded | blurServerSide)) 1367 if ((flags & blurNeeded)
1368 && (flags & HAS_RENDER_CONV))
1398 { 1369 {
1399 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1370 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1400 result |= transpPmapBlurred; 1371 result |= transpPmapBlurred;
1401 } 1372 }
1402 if (flags & (tintNeeded | tintServerSide)) 1373 if ((flags & tintNeeded)
1374 && (flags & (tintWholesome | HAS_RENDER)))
1403 { 1375 {
1404 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1376 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1405 result |= transpPmapTinted; 1377 result |= transpPmapTinted;
1406 } 1378 }
1407 } /* server side rendering completed */ 1379 } /* server side rendering completed */
1412 pixmap = tiled_root_pmap; 1384 pixmap = tiled_root_pmap;
1413 pmap_width = window_width; 1385 pmap_width = window_width;
1414 pmap_height = window_height; 1386 pmap_height = window_height;
1415 pmap_depth = target->depth; 1387 pmap_depth = target->depth;
1416 } 1388 }
1389 else
1390 XFreePixmap (dpy, tiled_root_pmap);
1417 1391
1418 if (recoded_root_pmap != root_pixmap) 1392 if (recoded_root_pmap != root_pixmap)
1419 XFreePixmap (dpy, recoded_root_pmap); 1393 XFreePixmap (dpy, recoded_root_pmap);
1420 1394
1421 return result; 1395 return result;
1430 1404
1431 root_pixmap = new_root_pixmap; 1405 root_pixmap = new_root_pixmap;
1432} 1406}
1433# endif /* ENABLE_TRANSPARENCY */ 1407# endif /* ENABLE_TRANSPARENCY */
1434 1408
1435# ifndef HAVE_AFTERIMAGE 1409#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1436static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1410static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c);
1437# endif 1411# endif
1438 1412
1439bool 1413bool
1440bgPixmap_t::render () 1414bgPixmap_t::render ()
1441{ 1415{
1464 if (render_image (background_flags)) 1438 if (render_image (background_flags))
1465 flags = flags & ~isInvalid; 1439 flags = flags & ~isInvalid;
1466 } 1440 }
1467# endif 1441# endif
1468 1442
1443# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1469 XImage *result = NULL; 1444 XImage *result = NULL;
1470 1445
1471 if (background_flags && (flags & isInvalid)) 1446 if (background_flags && (flags & isInvalid))
1472 { 1447 {
1473 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1448 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1474 } 1449 }
1475 1450
1476 if (result) 1451 if (result)
1477 { 1452 {
1478# if !defined(HAVE_AFTERIMAGE) && !XRENDER
1479 /* our own client-side tinting */ 1453 /* our own client-side tinting */
1480 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1454 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1481 { 1455 {
1482 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1456 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1483 if (flags & tintSet) 1457 if (flags & tintSet)
1484 tint.get (c); 1458 tint.get (c);
1485 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); 1459 ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c);
1486 } 1460 }
1487# endif
1488 1461
1489 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1462 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1490 1463
1491 if (gc) 1464 if (gc)
1492 { 1465 {
1496 flags = flags & ~isInvalid; 1469 flags = flags & ~isInvalid;
1497 } 1470 }
1498 1471
1499 XDestroyImage (result); 1472 XDestroyImage (result);
1500 } 1473 }
1474# endif
1501 1475
1502 if (flags & isInvalid) 1476 if (flags & isInvalid)
1503 { 1477 {
1504 if (pixmap != None) 1478 if (pixmap != None)
1505 { 1479 {
1513 valid_since = ev::now (); 1487 valid_since = ev::now ();
1514 1488
1515 return true; 1489 return true;
1516} 1490}
1517 1491
1518bool 1492void
1519bgPixmap_t::set_target (rxvt_term *new_target) 1493bgPixmap_t::set_target (rxvt_term *new_target)
1520{ 1494{
1521 if (new_target)
1522 if (target != new_target)
1523 {
1524 target = new_target; 1495 target = new_target;
1525 return true; 1496
1497 flags &= ~(HAS_RENDER | HAS_RENDER_CONV);
1498#if XRENDER
1499 int major, minor;
1500 if (XRenderQueryVersion (target->dpy, &major, &minor))
1501 flags |= HAS_RENDER;
1502 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1503 if (filters)
1504 {
1505 for (int i = 0; i < filters->nfilter; i++)
1506 if (!strcmp (filters->filter[i], FilterConvolution))
1507 flags |= HAS_RENDER_CONV;
1508
1509 XFree (filters);
1526 } 1510 }
1527 1511#endif
1528 return false;
1529} 1512}
1530 1513
1531void 1514void
1532bgPixmap_t::apply () 1515bgPixmap_t::apply ()
1533{ 1516{
1534 if (target) 1517 if (target == NULL)
1535 { 1518 return;
1519
1536 if (pixmap != None) 1520 if (pixmap != None)
1537 { 1521 {
1538 /* set target's background to pixmap */ 1522 /* set target's background to pixmap */
1539# ifdef ENABLE_TRANSPARENCY 1523# ifdef ENABLE_TRANSPARENCY
1540 if (flags & isTransparent) 1524 if (flags & isTransparent)
1541 { 1525 {
1542 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1526 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1543 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1527 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1544 1528
1545 if (target->scrollBar.win) 1529 if (target->scrollBar.win)
1546 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1530 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1547 } 1531 }
1548 else 1532 else
1549# endif 1533# endif
1550 { 1534 {
1551 /* force old pixmap dereference in case it was transparent before :*/ 1535 /* force old pixmap dereference in case it was transparent before :*/
1552 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1553 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1554 /* do we also need to set scrollbar's background here ? */
1555
1556 if (target->scrollBar.win)
1557 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1558 }
1559 }
1560 else
1561 {
1562 /* set target background to a pixel */
1563 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1536 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1564 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1537 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1565 /* do we also need to set scrollbar's background here ? */ 1538 /* do we also need to set scrollbar's background here ? */
1539
1566 if (target->scrollBar.win) 1540 if (target->scrollBar.win)
1567 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1541 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1568 } 1542 }
1543 }
1544 else
1545 {
1546 /* set target background to a pixel */
1547 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1548 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1549 /* do we also need to set scrollbar's background here ? */
1550 if (target->scrollBar.win)
1551 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1552 }
1569 1553
1570 /* don't want Expose on the parent or vt. It is better to use 1554 /* don't want Expose on the parent or vt. It is better to use
1571 scr_touch or we get a great deal of flicker otherwise: */ 1555 scr_touch or we get a great deal of flicker otherwise: */
1572 XClearWindow (target->dpy, target->parent[0]); 1556 XClearWindow (target->dpy, target->parent[0]);
1573 1557
1574 if (target->scrollBar.state && target->scrollBar.win) 1558 if (target->scrollBar.state && target->scrollBar.win)
1575 { 1559 {
1576 target->scrollBar.state = STATE_IDLE; 1560 target->scrollBar.state = STATE_IDLE;
1577 target->scrollBar.show (0); 1561 target->scrollBar.show (0);
1578 } 1562 }
1579 1563
1580 target->want_refresh = 1; 1564 target->want_refresh = 1;
1581 flags |= hasChanged; 1565 flags |= hasChanged;
1582 }
1583} 1566}
1584 1567
1585#endif /* HAVE_BG_PIXMAP */ 1568#endif /* HAVE_BG_PIXMAP */
1586 1569
1587#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER 1570#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1588/* taken from aterm-0.4.2 */ 1571/* taken from aterm-0.4.2 */
1589 1572
1590static void 1573static void
1591ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1574ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c)
1592{ 1575{
1593 int sh_r, sh_g, sh_b; 1576 int sh_r, sh_g, sh_b;
1594 uint32_t mask_r, mask_g, mask_b; 1577 uint32_t mask_r, mask_g, mask_b;
1595 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1578 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1596 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1579 rgba low;
1597 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1580 rgba high;
1598 int i; 1581 int i;
1599 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; 1582 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1600 1583
1601 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; 1584 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1602 1585
1667 /* prepare limits for color transformation (each channel is handled separately) */ 1650 /* prepare limits for color transformation (each channel is handled separately) */
1668 if (shade > 100) 1651 if (shade > 100)
1669 { 1652 {
1670 shade = 200 - shade; 1653 shade = 200 - shade;
1671 1654
1672 lower_lim_r = 65535-rm; 1655 high.r = (65535 - c.r) * shade / 100;
1673 lower_lim_g = 65535-gm; 1656 high.g = (65535 - c.g) * shade / 100;
1674 lower_lim_b = 65535-bm; 1657 high.b = (65535 - c.b) * shade / 100;
1675 1658
1676 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); 1659 low.r = 65535 - high.r;
1677 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); 1660 low.g = 65535 - high.g;
1678 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); 1661 low.b = 65535 - high.b;
1679
1680 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1681 } 1662 }
1682 else 1663 else
1683 { 1664 {
1665 high.r = c.r * shade / 100;
1666 high.g = c.g * shade / 100;
1667 high.b = c.b * shade / 100;
1684 1668
1685 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1669 low.r = low.g = low.b = 0;
1686
1687 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1688 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1689 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1690 } 1670 }
1691 1671
1692 /* fill our lookup tables */ 1672 /* fill our lookup tables */
1693 for (i = 0; i <= mask_r>>sh_r; i++) 1673 for (i = 0; i <= mask_r>>sh_r; i++)
1694 { 1674 {
1695 uint32_t tmp; 1675 uint32_t tmp;
1696 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); 1676 tmp = i * high.r;
1697 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); 1677 tmp += (mask_r>>sh_r) * low.r;
1698 lookup_r[i] = (tmp/65535)<<sh_r; 1678 lookup_r[i] = (tmp/65535)<<sh_r;
1699 } 1679 }
1700 for (i = 0; i <= mask_g>>sh_g; i++) 1680 for (i = 0; i <= mask_g>>sh_g; i++)
1701 { 1681 {
1702 uint32_t tmp; 1682 uint32_t tmp;
1703 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); 1683 tmp = i * high.g;
1704 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); 1684 tmp += (mask_g>>sh_g) * low.g;
1705 lookup_g[i] = (tmp/65535)<<sh_g; 1685 lookup_g[i] = (tmp/65535)<<sh_g;
1706 } 1686 }
1707 for (i = 0; i <= mask_b>>sh_b; i++) 1687 for (i = 0; i <= mask_b>>sh_b; i++)
1708 { 1688 {
1709 uint32_t tmp; 1689 uint32_t tmp;
1710 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); 1690 tmp = i * high.b;
1711 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); 1691 tmp += (mask_b>>sh_b) * low.b;
1712 lookup_b[i] = (tmp/65535)<<sh_b; 1692 lookup_b[i] = (tmp/65535)<<sh_b;
1713 } 1693 }
1714 1694
1715 /* apply table to input image (replacing colors by newly calculated ones) */ 1695 /* apply table to input image (replacing colors by newly calculated ones) */
1716 if (srcImage->bits_per_pixel == 32 1696 if (srcImage->bits_per_pixel == 32

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines