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.102 by sf-exg, Sun Oct 31 09:34:23 2010 UTC vs.
Revision 1.113 by sf-exg, Sat Nov 6 17:51:11 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
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>
108 h_scale = v_scale = 0; 112 h_scale = v_scale = 0;
109 h_align = v_align = 0; 113 h_align = v_align = 0;
110#endif 114#endif
111#ifdef ENABLE_TRANSPARENCY 115#ifdef ENABLE_TRANSPARENCY
112 shade = 100; 116 shade = 100;
113 recoded_root_pmap = None;
114#endif 117#endif
115 flags = 0; 118 flags = 0;
116 pixmap = None; 119 pixmap = None;
117 valid_since = invalid_since = 0; 120 valid_since = invalid_since = 0;
118 target = 0; 121 target = 0;
127#endif 130#endif
128 131
129#ifdef HAVE_PIXBUF 132#ifdef HAVE_PIXBUF
130 if (pixbuf) 133 if (pixbuf)
131 g_object_unref (pixbuf); 134 g_object_unref (pixbuf);
132#endif
133
134#ifdef ENABLE_TRANSPARENCY
135 if (recoded_root_pmap && target)
136 XFreePixmap (target->dpy, recoded_root_pmap);
137#endif 135#endif
138 136
139 if (pixmap && target) 137 if (pixmap && target)
140 XFreePixmap (target->dpy, pixmap); 138 XFreePixmap (target->dpy, pixmap);
141} 139}
256} 254}
257 255
258bool 256bool
259bgPixmap_t::set_geometry (const char *geom) 257bgPixmap_t::set_geometry (const char *geom)
260{ 258{
259 bool changed = false;
261 int geom_flags = 0, changed = 0; 260 int geom_flags = 0;
262 int x = 0, y = 0; 261 int x = 0, y = 0;
263 unsigned int w = 0, h = 0; 262 unsigned int w = 0, h = 0;
264 unsigned int n; 263 unsigned int n;
265 unsigned long new_flags = (flags & (~geometryFlags)); 264 unsigned long new_flags = (flags & (~geometryFlags));
266 const char *p; 265 const char *p;
422 421
423 while (*ops != ':' && *ops != '\0') ++ops; 422 while (*ops != ':' && *ops != '\0') ++ops;
424 } /* done parsing ops */ 423 } /* done parsing ops */
425 } 424 }
426 425
427 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;
428 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;
429 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;
430 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;
431 } 430 }
432 431
433 if (new_flags != flags) 432 if (new_flags != flags)
434 { 433 {
435 flags = new_flags; 434 flags = new_flags;
436 changed++; 435 changed = true;
437 } 436 }
438 437
439 return (changed > 0); 438 return changed;
440} 439}
441 440
442void 441void
443bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 442bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
444{ 443{
735 return false; 734 return false;
736 735
737 if (!pixbuf) 736 if (!pixbuf)
738 return false; 737 return false;
739 738
740#if !XRENDER
741 if (background_flags) 739 if (background_flags
740 && !(flags & HAS_RENDER))
742 return false; 741 return false;
743#endif
744 742
745 GdkPixbuf *result; 743 GdkPixbuf *result;
746 744
747 int image_width = gdk_pixbuf_get_width (pixbuf); 745 int image_width = gdk_pixbuf_get_width (pixbuf);
748 int image_height = gdk_pixbuf_get_height (pixbuf); 746 int image_height = gdk_pixbuf_get_height (pixbuf);
915# endif /* HAVE_PIXBUF */ 913# endif /* HAVE_PIXBUF */
916 914
917bool 915bool
918bgPixmap_t::set_file (const char *file) 916bgPixmap_t::set_file (const char *file)
919{ 917{
920 assert (file); 918 if (!file || !*file)
919 return false;
921 920
922 if (*file)
923 {
924 if (const char *p = strchr (file, ';')) 921 if (const char *p = strchr (file, ';'))
925 { 922 {
926 size_t len = p - file; 923 size_t len = p - file;
927 char *f = rxvt_temp_buf<char> (len + 1); 924 char *f = rxvt_temp_buf<char> (len + 1);
928 memcpy (f, file, len); 925 memcpy (f, file, len);
929 f[len] = '\0'; 926 f[len] = '\0';
930 file = f; 927 file = f;
931 } 928 }
932 929
933# ifdef HAVE_AFTERIMAGE 930# ifdef HAVE_AFTERIMAGE
934 if (!target->asimman) 931 if (!target->asimman)
935 target->asimman = create_generic_imageman (target->rs[Rs_path]); 932 target->asimman = create_generic_imageman (target->rs[Rs_path]);
936 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); 933 ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
937 if (image) 934 if (image)
938 { 935 {
939 if (original_asim) 936 if (original_asim)
940 safe_asimage_destroy (original_asim); 937 safe_asimage_destroy (original_asim);
941 original_asim = image; 938 original_asim = image;
942 have_image = true; 939 have_image = true;
943 return true; 940 return true;
944 } 941 }
945# endif 942# endif
946 943
947# ifdef HAVE_PIXBUF 944# ifdef HAVE_PIXBUF
948 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); 945 GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL);
949 if (image) 946 if (image)
950 { 947 {
951 if (pixbuf) 948 if (pixbuf)
952 g_object_unref (pixbuf); 949 g_object_unref (pixbuf);
953 pixbuf = image; 950 pixbuf = image;
954 have_image = true; 951 have_image = true;
955 return true; 952 return true;
956 } 953 }
957# endif 954# endif
958 }
959 955
960 return false; 956 return false;
961} 957}
962 958
963# endif /* BG_IMAGE_FROM_FILE */ 959# endif /* BG_IMAGE_FROM_FILE */
976} 972}
977 973
978bool 974bool
979bgPixmap_t::set_blur_radius (const char *geom) 975bgPixmap_t::set_blur_radius (const char *geom)
980{ 976{
981 int changed = 0; 977 bool changed = false;
982 unsigned int hr, vr; 978 unsigned int hr, vr;
983 int junk; 979 int junk;
984 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); 980 int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr);
985 981
986 if (!(geom_flags & WidthValue)) 982 if (!(geom_flags & WidthValue))
991 min_it (hr, 128); 987 min_it (hr, 128);
992 min_it (vr, 128); 988 min_it (vr, 128);
993 989
994 if (h_blurRadius != hr) 990 if (h_blurRadius != hr)
995 { 991 {
996 ++changed; 992 changed = true;
997 h_blurRadius = hr; 993 h_blurRadius = hr;
998 } 994 }
999 995
1000 if (v_blurRadius != vr) 996 if (v_blurRadius != vr)
1001 { 997 {
1002 ++changed; 998 changed = true;
1003 v_blurRadius = vr; 999 v_blurRadius = vr;
1004 } 1000 }
1005 1001
1006 if (v_blurRadius == 0 && h_blurRadius == 0) 1002 if (v_blurRadius == 0 && h_blurRadius == 0)
1007 flags &= ~blurNeeded; 1003 flags &= ~blurNeeded;
1008 else 1004 else
1009 flags |= blurNeeded; 1005 flags |= blurNeeded;
1010 1006
1011#if XRENDER
1012 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1013 if (filters)
1014 {
1015 for (int i = 0; i < filters->nfilter; i++)
1016 if (!strcmp (filters->filter[i], FilterConvolution))
1017 flags |= bgPixmap_t::blurServerSide;
1018
1019 XFree (filters);
1020 }
1021#endif
1022
1023 return (changed > 0); 1007 return changed;
1024} 1008}
1025 1009
1026static inline unsigned long 1010static inline unsigned long
1027compute_tint_shade_flags (rxvt_color *tint, int shade) 1011compute_tint_shade_flags (rxvt_color *tint, int shade)
1028{ 1012{
1047 { 1031 {
1048 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) 1032 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
1049 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) 1033 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
1050 { 1034 {
1051 flags |= bgPixmap_t::tintNeeded; 1035 flags |= bgPixmap_t::tintNeeded;
1052 }
1053 }
1054
1055 if (flags & bgPixmap_t::tintNeeded)
1056 {
1057 if (flags & bgPixmap_t::tintWholesome)
1058 flags |= bgPixmap_t::tintServerSide;
1059 else
1060 {
1061#if XRENDER
1062 flags |= bgPixmap_t::tintServerSide;
1063#endif
1064 } 1036 }
1065 } 1037 }
1066 1038
1067 return flags; 1039 return flags;
1068} 1040}
1307 /* 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
1308 * be always up-to-date, so let's use it : 1280 * be always up-to-date, so let's use it :
1309 */ 1281 */
1310 int screen = target->display->screen; 1282 int screen = target->display->screen;
1311 Display *dpy = target->dpy; 1283 Display *dpy = target->dpy;
1284 int root_depth = DefaultDepth (dpy, screen);
1312 int root_width = DisplayWidth (dpy, screen); 1285 int root_width = DisplayWidth (dpy, screen);
1313 int root_height = DisplayHeight (dpy, screen); 1286 int root_height = DisplayHeight (dpy, screen);
1287 unsigned int root_pmap_width, root_pmap_height;
1314 int window_width = target->szHint.width; 1288 int window_width = target->szHint.width;
1315 int window_height = target->szHint.height; 1289 int window_height = target->szHint.height;
1316 int sx, sy; 1290 int sx, sy;
1317 XGCValues gcv; 1291 XGCValues gcv;
1318 GC gc; 1292 GC gc;
1322 /* 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 : */
1323 if (sx + window_width <= 0 || sy + window_height <= 0 1297 if (sx + window_width <= 0 || sy + window_height <= 0
1324 || sx >= root_width || sy >= root_height) 1298 || sx >= root_width || sy >= root_height)
1325 return 0; 1299 return 0;
1326 1300
1301 // validate root pixmap and get its size
1302 if (root_pixmap != None)
1303 {
1304 Window wdummy;
1305 int idummy;
1306 unsigned int udummy;
1307
1308 target->allowedxerror = -1;
1309
1310 if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy))
1311 root_pixmap = None;
1312
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;
1346 }
1347
1327 if (root_pixmap == None) 1348 if (root_pixmap == None)
1328 return 0; 1349 return 0;
1329 1350
1330 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); 1351 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
1331 1352
1332 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1353 if (tiled_root_pmap == None) /* something really bad happened - abort */
1333 return 0; 1354 return 0;
1334 1355
1335 /* straightforward pixmap copy */ 1356 /* straightforward pixmap copy */
1336 gcv.tile = root_pixmap; 1357 gcv.tile = recoded_root_pmap;
1337 gcv.fill_style = FillTiled; 1358 gcv.fill_style = FillTiled;
1338 1359
1339 while (sx < 0) sx += (int)root_width; 1360 while (sx < 0) sx += (int)root_width;
1340 while (sy < 0) sy += (int)root_height; 1361 while (sy < 0) sy += (int)root_height;
1341 1362
1352 1373
1353 if (tiled_root_pmap != None) 1374 if (tiled_root_pmap != None)
1354 { 1375 {
1355 if (!need_client_side_rendering ()) 1376 if (!need_client_side_rendering ())
1356 { 1377 {
1357 if (flags & (blurNeeded | blurServerSide)) 1378 if ((flags & blurNeeded)
1379 && (flags & HAS_RENDER_CONV))
1358 { 1380 {
1359 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1381 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1360 result |= transpPmapBlurred; 1382 result |= transpPmapBlurred;
1361 } 1383 }
1362 if (flags & (tintNeeded | tintServerSide)) 1384 if ((flags & tintNeeded)
1385 && (flags & (tintWholesome | HAS_RENDER)))
1363 { 1386 {
1364 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) 1387 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1365 result |= transpPmapTinted; 1388 result |= transpPmapTinted;
1366 } 1389 }
1367 } /* server side rendering completed */ 1390 } /* server side rendering completed */
1373 pmap_width = window_width; 1396 pmap_width = window_width;
1374 pmap_height = window_height; 1397 pmap_height = window_height;
1375 pmap_depth = target->depth; 1398 pmap_depth = target->depth;
1376 } 1399 }
1377 1400
1401 if (recoded_root_pmap != root_pixmap)
1402 XFreePixmap (dpy, recoded_root_pmap);
1403
1378 return result; 1404 return result;
1379} 1405}
1380 1406
1381void 1407void
1382bgPixmap_t::set_root_pixmap () 1408bgPixmap_t::set_root_pixmap ()
1384 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1410 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1385 if (new_root_pixmap == None) 1411 if (new_root_pixmap == None)
1386 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1412 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1387 1413
1388 root_pixmap = new_root_pixmap; 1414 root_pixmap = new_root_pixmap;
1389
1390 unsigned int width, height;
1391 int depth = DefaultDepth (target->dpy, target->display->screen);
1392
1393 // validate root pixmap
1394 if (root_pixmap != None)
1395 {
1396 Window wdummy;
1397 int idummy;
1398 unsigned int udummy;
1399
1400 target->allowedxerror = -1;
1401
1402 if (!XGetGeometry (target->dpy, root_pixmap, &wdummy, &idummy, &idummy, &width, &height, &udummy, &udummy))
1403 root_pixmap = None;
1404
1405 target->allowedxerror = 0;
1406 }
1407
1408 if (root_pixmap != None && depth != target->depth)
1409 {
1410#if XRENDER
1411 Display *dpy = target->dpy;
1412 XRenderPictureAttributes pa;
1413
1414 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen));
1415 Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa);
1416
1417 if (recoded_root_pmap)
1418 XFreePixmap (dpy, recoded_root_pmap);
1419 recoded_root_pmap = XCreatePixmap (dpy, target->vt, width, height, target->depth);
1420 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
1421 Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa);
1422
1423 if (src && dst)
1424 {
1425 XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, width, height);
1426 root_pixmap = recoded_root_pmap;
1427 }
1428 else
1429 root_pixmap = None;
1430
1431 XRenderFreePicture (dpy, src);
1432 XRenderFreePicture (dpy, dst);
1433#else
1434 root_pixmap = None;
1435#endif
1436 }
1437} 1415}
1438# endif /* ENABLE_TRANSPARENCY */ 1416# endif /* ENABLE_TRANSPARENCY */
1439 1417
1440# ifndef HAVE_AFTERIMAGE 1418#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1441static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1419static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c);
1442# endif 1420# endif
1443 1421
1444bool 1422bool
1445bgPixmap_t::render () 1423bgPixmap_t::render ()
1446{ 1424{
1469 if (render_image (background_flags)) 1447 if (render_image (background_flags))
1470 flags = flags & ~isInvalid; 1448 flags = flags & ~isInvalid;
1471 } 1449 }
1472# endif 1450# endif
1473 1451
1452# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1474 XImage *result = NULL; 1453 XImage *result = NULL;
1475 1454
1476 if (background_flags && (flags & isInvalid)) 1455 if (background_flags && (flags & isInvalid))
1477 { 1456 {
1478 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);
1479 } 1458 }
1480 1459
1481 if (result) 1460 if (result)
1482 { 1461 {
1483# if !defined(HAVE_AFTERIMAGE) && !XRENDER
1484 /* our own client-side tinting */ 1462 /* our own client-side tinting */
1485 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1463 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1486 { 1464 {
1487 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1465 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1488 if (flags & tintSet) 1466 if (flags & tintSet)
1489 tint.get (c); 1467 tint.get (c);
1490 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);
1491 } 1469 }
1492# endif
1493 1470
1494 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1471 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1495 1472
1496 if (gc) 1473 if (gc)
1497 { 1474 {
1501 flags = flags & ~isInvalid; 1478 flags = flags & ~isInvalid;
1502 } 1479 }
1503 1480
1504 XDestroyImage (result); 1481 XDestroyImage (result);
1505 } 1482 }
1483# endif
1506 1484
1507 if (flags & isInvalid) 1485 if (flags & isInvalid)
1508 { 1486 {
1509 if (pixmap != None) 1487 if (pixmap != None)
1510 { 1488 {
1518 valid_since = ev::now (); 1496 valid_since = ev::now ();
1519 1497
1520 return true; 1498 return true;
1521} 1499}
1522 1500
1523bool 1501void
1524bgPixmap_t::set_target (rxvt_term *new_target) 1502bgPixmap_t::set_target (rxvt_term *new_target)
1525{ 1503{
1526 if (new_target)
1527 if (target != new_target)
1528 {
1529 target = new_target; 1504 target = new_target;
1530 return true; 1505
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);
1531 } 1519 }
1532 1520#endif
1533 return false;
1534} 1521}
1535 1522
1536void 1523void
1537bgPixmap_t::apply () 1524bgPixmap_t::apply ()
1538{ 1525{
1539 if (target) 1526 if (target == NULL)
1540 { 1527 return;
1528
1541 if (pixmap != None) 1529 if (pixmap != None)
1542 { 1530 {
1543 /* set target's background to pixmap */ 1531 /* set target's background to pixmap */
1544# ifdef ENABLE_TRANSPARENCY 1532# ifdef ENABLE_TRANSPARENCY
1545 if (flags & isTransparent) 1533 if (flags & isTransparent)
1546 { 1534 {
1547 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1535 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1548 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1536 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1549 1537
1550 if (target->scrollBar.win) 1538 if (target->scrollBar.win)
1551 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1539 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1552 } 1540 }
1553 else 1541 else
1554# endif 1542# endif
1555 { 1543 {
1556 /* force old pixmap dereference in case it was transparent before :*/ 1544 /* force old pixmap dereference in case it was transparent before :*/
1557 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1558 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1559 /* do we also need to set scrollbar's background here ? */
1560
1561 if (target->scrollBar.win)
1562 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1563 }
1564 }
1565 else
1566 {
1567 /* set target background to a pixel */
1568 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1545 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1569 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1546 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1570 /* do we also need to set scrollbar's background here ? */ 1547 /* do we also need to set scrollbar's background here ? */
1548
1571 if (target->scrollBar.win) 1549 if (target->scrollBar.win)
1572 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1550 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1573 } 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 }
1574 1562
1575 /* 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
1576 scr_touch or we get a great deal of flicker otherwise: */ 1564 scr_touch or we get a great deal of flicker otherwise: */
1577 XClearWindow (target->dpy, target->parent[0]); 1565 XClearWindow (target->dpy, target->parent[0]);
1578 1566
1579 if (target->scrollBar.state && target->scrollBar.win) 1567 if (target->scrollBar.state && target->scrollBar.win)
1580 { 1568 {
1581 target->scrollBar.state = STATE_IDLE; 1569 target->scrollBar.state = STATE_IDLE;
1582 target->scrollBar.show (0); 1570 target->scrollBar.show (0);
1583 } 1571 }
1584 1572
1585 target->want_refresh = 1; 1573 target->want_refresh = 1;
1586 flags |= hasChanged; 1574 flags |= hasChanged;
1587 }
1588} 1575}
1589 1576
1590#endif /* HAVE_BG_PIXMAP */ 1577#endif /* HAVE_BG_PIXMAP */
1591 1578
1592#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER 1579#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1593/* taken from aterm-0.4.2 */ 1580/* taken from aterm-0.4.2 */
1594 1581
1595static void 1582static void
1596ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1583ShadeXImage(Visual *visual, XImage *srcImage, int shade, const rgba &c)
1597{ 1584{
1598 int sh_r, sh_g, sh_b; 1585 int sh_r, sh_g, sh_b;
1599 uint32_t mask_r, mask_g, mask_b; 1586 uint32_t mask_r, mask_g, mask_b;
1600 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; 1587 uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b;
1601 unsigned int lower_lim_r, lower_lim_g, lower_lim_b; 1588 rgba low;
1602 unsigned int upper_lim_r, upper_lim_g, upper_lim_b; 1589 rgba high;
1603 int i; 1590 int i;
1604 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; 1591 int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst;
1605 1592
1606 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; 1593 if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return;
1607 1594
1672 /* prepare limits for color transformation (each channel is handled separately) */ 1659 /* prepare limits for color transformation (each channel is handled separately) */
1673 if (shade > 100) 1660 if (shade > 100)
1674 { 1661 {
1675 shade = 200 - shade; 1662 shade = 200 - shade;
1676 1663
1677 lower_lim_r = 65535-rm; 1664 high.r = (65535 - c.r) * shade / 100;
1678 lower_lim_g = 65535-gm; 1665 high.g = (65535 - c.g) * shade / 100;
1679 lower_lim_b = 65535-bm; 1666 high.b = (65535 - c.b) * shade / 100;
1680 1667
1681 lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); 1668 low.r = 65535 - high.r;
1682 lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); 1669 low.g = 65535 - high.g;
1683 lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); 1670 low.b = 65535 - high.b;
1684
1685 upper_lim_r = upper_lim_g = upper_lim_b = 65535;
1686 } 1671 }
1687 else 1672 else
1688 { 1673 {
1674 high.r = c.r * shade / 100;
1675 high.g = c.g * shade / 100;
1676 high.b = c.b * shade / 100;
1689 1677
1690 lower_lim_r = lower_lim_g = lower_lim_b = 0; 1678 low.r = low.g = low.b = 0;
1691
1692 upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100);
1693 upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100);
1694 upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100);
1695 } 1679 }
1696 1680
1697 /* fill our lookup tables */ 1681 /* fill our lookup tables */
1698 for (i = 0; i <= mask_r>>sh_r; i++) 1682 for (i = 0; i <= mask_r>>sh_r; i++)
1699 { 1683 {
1700 uint32_t tmp; 1684 uint32_t tmp;
1701 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); 1685 tmp = i * high.r;
1702 tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); 1686 tmp += (mask_r>>sh_r) * low.r;
1703 lookup_r[i] = (tmp/65535)<<sh_r; 1687 lookup_r[i] = (tmp/65535)<<sh_r;
1704 } 1688 }
1705 for (i = 0; i <= mask_g>>sh_g; i++) 1689 for (i = 0; i <= mask_g>>sh_g; i++)
1706 { 1690 {
1707 uint32_t tmp; 1691 uint32_t tmp;
1708 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); 1692 tmp = i * high.g;
1709 tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); 1693 tmp += (mask_g>>sh_g) * low.g;
1710 lookup_g[i] = (tmp/65535)<<sh_g; 1694 lookup_g[i] = (tmp/65535)<<sh_g;
1711 } 1695 }
1712 for (i = 0; i <= mask_b>>sh_b; i++) 1696 for (i = 0; i <= mask_b>>sh_b; i++)
1713 { 1697 {
1714 uint32_t tmp; 1698 uint32_t tmp;
1715 tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); 1699 tmp = i * high.b;
1716 tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); 1700 tmp += (mask_b>>sh_b) * low.b;
1717 lookup_b[i] = (tmp/65535)<<sh_b; 1701 lookup_b[i] = (tmp/65535)<<sh_b;
1718 } 1702 }
1719 1703
1720 /* apply table to input image (replacing colors by newly calculated ones) */ 1704 /* apply table to input image (replacing colors by newly calculated ones) */
1721 if (srcImage->bits_per_pixel == 32 1705 if (srcImage->bits_per_pixel == 32

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines