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.95 by sf-exg, Fri Oct 22 16:21:05 2010 UTC vs.
Revision 1.102 by sf-exg, Sun Oct 31 09:34:23 2010 UTC

108 h_scale = v_scale = 0; 108 h_scale = v_scale = 0;
109 h_align = v_align = 0; 109 h_align = v_align = 0;
110#endif 110#endif
111#ifdef ENABLE_TRANSPARENCY 111#ifdef ENABLE_TRANSPARENCY
112 shade = 100; 112 shade = 100;
113 recoded_root_pmap = None;
113#endif 114#endif
114 flags = 0; 115 flags = 0;
115 pixmap = None; 116 pixmap = None;
116 valid_since = invalid_since = 0; 117 valid_since = invalid_since = 0;
117 target = 0; 118 target = 0;
126#endif 127#endif
127 128
128#ifdef HAVE_PIXBUF 129#ifdef HAVE_PIXBUF
129 if (pixbuf) 130 if (pixbuf)
130 g_object_unref (pixbuf); 131 g_object_unref (pixbuf);
132#endif
133
134#ifdef ENABLE_TRANSPARENCY
135 if (recoded_root_pmap && target)
136 XFreePixmap (target->dpy, recoded_root_pmap);
131#endif 137#endif
132 138
133 if (pixmap && target) 139 if (pixmap && target)
134 XFreePixmap (target->dpy, pixmap); 140 XFreePixmap (target->dpy, pixmap);
135} 141}
428 { 434 {
429 flags = new_flags; 435 flags = new_flags;
430 changed++; 436 changed++;
431 } 437 }
432 438
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); 439 return (changed > 0);
436} 440}
437 441
438void 442void
439bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 443bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
731 return false; 735 return false;
732 736
733 if (!pixbuf) 737 if (!pixbuf)
734 return false; 738 return false;
735 739
736#if !XFT 740#if !XRENDER
737 if (background_flags) 741 if (background_flags)
738 return false; 742 return false;
739#endif 743#endif
740 744
741 GdkPixbuf *result; 745 GdkPixbuf *result;
858 dst_width, dst_height, 862 dst_width, dst_height,
859 XLIB_RGB_DITHER_NONE, 863 XLIB_RGB_DITHER_NONE,
860 0, 0); 864 0, 0);
861 } 865 }
862 866
863#if XFT 867#if XRENDER
864 if (background_flags) 868 if (background_flags)
865 { 869 {
866 Display *dpy = target->dpy; 870 Display *dpy = target->dpy;
867 XRenderPictureAttributes pa; 871 XRenderPictureAttributes pa;
868 872
869 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); 873 XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual);
870 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); 874 Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa);
871 875
872 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); 876 XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual);
873 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); 877 Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa);
874 878
1002 if (v_blurRadius == 0 && h_blurRadius == 0) 1006 if (v_blurRadius == 0 && h_blurRadius == 0)
1003 flags &= ~blurNeeded; 1007 flags &= ~blurNeeded;
1004 else 1008 else
1005 flags |= blurNeeded; 1009 flags |= blurNeeded;
1006 1010
1007#if XFT 1011#if XRENDER
1008 XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); 1012 XFilters *filters = XRenderQueryFilters (target->dpy, target->vt);
1009 if (filters) 1013 if (filters)
1010 { 1014 {
1011 for (int i = 0; i < filters->nfilter; i++) 1015 for (int i = 0; i < filters->nfilter; i++)
1012 if (!strcmp (filters->filter[i], FilterConvolution)) 1016 if (!strcmp (filters->filter[i], FilterConvolution))
1013 flags |= bgPixmap_t::blurServerSide; 1017 flags |= bgPixmap_t::blurServerSide;
1052 { 1056 {
1053 if (flags & bgPixmap_t::tintWholesome) 1057 if (flags & bgPixmap_t::tintWholesome)
1054 flags |= bgPixmap_t::tintServerSide; 1058 flags |= bgPixmap_t::tintServerSide;
1055 else 1059 else
1056 { 1060 {
1057#if XFT 1061#if XRENDER
1058 flags |= bgPixmap_t::tintServerSide; 1062 flags |= bgPixmap_t::tintServerSide;
1059#endif 1063#endif
1060 } 1064 }
1061 } 1065 }
1062 1066
1109 } 1113 }
1110 1114
1111 return false; 1115 return false;
1112} 1116}
1113 1117
1114#if XFT 1118#if XRENDER
1115static void 1119static void
1116get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) 1120get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params)
1117{ 1121{
1118 double sigma = radius / 2.0; 1122 double sigma = radius / 2.0;
1119 double scale = sqrt (2.0 * M_PI) * sigma; 1123 double scale = sqrt (2.0 * M_PI) * sigma;
1136 1140
1137bool 1141bool
1138bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) 1142bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height)
1139{ 1143{
1140 bool ret = false; 1144 bool ret = false;
1141#if XFT 1145#if XRENDER
1142 int size = max (h_blurRadius, v_blurRadius) * 2 + 1; 1146 int size = max (h_blurRadius, v_blurRadius) * 2 + 1;
1143 double *kernel = (double *)malloc (size * sizeof (double)); 1147 double *kernel = (double *)malloc (size * sizeof (double));
1144 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); 1148 XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed));
1145 1149
1146 Display *dpy = target->dpy; 1150 Display *dpy = target->dpy;
1223 XFreeGC (dpy, gc); 1227 XFreeGC (dpy, gc);
1224 } 1228 }
1225 } 1229 }
1226 else 1230 else
1227 { 1231 {
1228# if XFT 1232# if XRENDER
1229 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1233 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1230 1234
1231 if (flags & tintSet) 1235 if (flags & tintSet)
1232 tint.get (c); 1236 tint.get (c);
1233 1237
1286 1290
1287 return ret; 1291 return ret;
1288} 1292}
1289 1293
1290/* make_transparency_pixmap() 1294/* make_transparency_pixmap()
1291 * Builds a pixmap sized the same as terminal window, with depth same as the root window 1295 * 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 1296 * the tiled portion of the root pixmap that is supposed to be covered by
1293 * our window. 1297 * our window.
1294 */ 1298 */
1295unsigned long 1299unsigned long
1296bgPixmap_t::make_transparency_pixmap () 1300bgPixmap_t::make_transparency_pixmap ()
1297{ 1301{
1301 return 0; 1305 return 0;
1302 1306
1303 /* root dimensions may change from call to call - but Display structure should 1307 /* root dimensions may change from call to call - but Display structure should
1304 * be always up-to-date, so let's use it : 1308 * be always up-to-date, so let's use it :
1305 */ 1309 */
1306 Window root = target->display->root;
1307 int screen = target->display->screen; 1310 int screen = target->display->screen;
1308 Display *dpy = target->dpy; 1311 Display *dpy = target->dpy;
1309 int root_width = DisplayWidth (dpy, screen); 1312 int root_width = DisplayWidth (dpy, screen);
1310 int root_height = DisplayHeight (dpy, screen); 1313 int root_height = DisplayHeight (dpy, screen);
1311 unsigned int root_pmap_width, root_pmap_height;
1312 int window_width = target->szHint.width; 1314 int window_width = target->szHint.width;
1313 int window_height = target->szHint.height; 1315 int window_height = target->szHint.height;
1314 int sx, sy; 1316 int sx, sy;
1315 XGCValues gcv; 1317 XGCValues gcv;
1316 GC gc; 1318 GC gc;
1320 /* check if we are outside of the visible part of the virtual screen : */ 1322 /* check if we are outside of the visible part of the virtual screen : */
1321 if (sx + window_width <= 0 || sy + window_height <= 0 1323 if (sx + window_width <= 0 || sy + window_height <= 0
1322 || sx >= root_width || sy >= root_height) 1324 || sx >= root_width || sy >= root_height)
1323 return 0; 1325 return 0;
1324 1326
1325 if (root_pixmap != None)
1326 {
1327 /* we want to validate the pixmap and get its size at the same time : */
1328 int junk;
1329 unsigned int ujunk;
1330 /* root pixmap may be bad - allow a error */
1331 target->allowedxerror = -1;
1332
1333 if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk))
1334 root_pixmap = None;
1335
1336 target->allowedxerror = 0;
1337 }
1338
1339 if (root_pixmap == None) 1327 if (root_pixmap == None)
1340 return 0; 1328 return 0;
1341 1329
1342 Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); 1330 Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth);
1343 1331
1344 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1332 if (tiled_root_pmap == None) /* something really bad happened - abort */
1345 return 0; 1333 return 0;
1346 1334
1347 /* straightforward pixmap copy */ 1335 /* straightforward pixmap copy */
1351 while (sx < 0) sx += (int)root_width; 1339 while (sx < 0) sx += (int)root_width;
1352 while (sy < 0) sy += (int)root_height; 1340 while (sy < 0) sy += (int)root_height;
1353 1341
1354 gcv.ts_x_origin = -sx; 1342 gcv.ts_x_origin = -sx;
1355 gcv.ts_y_origin = -sy; 1343 gcv.ts_y_origin = -sy;
1356 gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1344 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1357 1345
1358 if (gc) 1346 if (gc)
1359 { 1347 {
1360 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); 1348 XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height);
1361 result |= transpPmapTiled; 1349 result |= transpPmapTiled;
1366 { 1354 {
1367 if (!need_client_side_rendering ()) 1355 if (!need_client_side_rendering ())
1368 { 1356 {
1369 if (flags & (blurNeeded | blurServerSide)) 1357 if (flags & (blurNeeded | blurServerSide))
1370 { 1358 {
1371 if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1359 if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1372 result |= transpPmapBlurred; 1360 result |= transpPmapBlurred;
1373 } 1361 }
1374 if (flags & (tintNeeded | tintServerSide)) 1362 if (flags & (tintNeeded | tintServerSide))
1375 { 1363 {
1376 if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, screen), window_width, window_height)) 1364 if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height))
1377 result |= transpPmapTinted; 1365 result |= transpPmapTinted;
1378 } 1366 }
1379 } /* server side rendering completed */ 1367 } /* server side rendering completed */
1380 1368
1381 if (pixmap) 1369 if (pixmap)
1382 XFreePixmap (dpy, pixmap); 1370 XFreePixmap (dpy, pixmap);
1383 1371
1384 pixmap = tiled_root_pmap; 1372 pixmap = tiled_root_pmap;
1385 pmap_width = window_width; 1373 pmap_width = window_width;
1386 pmap_height = window_height; 1374 pmap_height = window_height;
1387 pmap_depth = root_depth; 1375 pmap_depth = target->depth;
1388 } 1376 }
1389 1377
1390 return result; 1378 return result;
1391} 1379}
1392 1380
1393bool 1381void
1394bgPixmap_t::set_root_pixmap () 1382bgPixmap_t::set_root_pixmap ()
1395{ 1383{
1396 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); 1384 Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID);
1397 if (new_root_pixmap == None) 1385 if (new_root_pixmap == None)
1398 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); 1386 new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID);
1399 1387
1400 if (new_root_pixmap != root_pixmap)
1401 {
1402 root_pixmap = new_root_pixmap; 1388 root_pixmap = new_root_pixmap;
1403 return true; 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)
1404 } 1395 {
1396 Window wdummy;
1397 int idummy;
1398 unsigned int udummy;
1405 1399
1406 return false; 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 }
1407} 1437}
1408# endif /* ENABLE_TRANSPARENCY */ 1438# endif /* ENABLE_TRANSPARENCY */
1409 1439
1410# ifndef HAVE_AFTERIMAGE 1440# ifndef HAVE_AFTERIMAGE
1411static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); 1441static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm);
1425 { 1455 {
1426 /* we need to re-generate transparency pixmap in that case ! */ 1456 /* we need to re-generate transparency pixmap in that case ! */
1427 background_flags = make_transparency_pixmap (); 1457 background_flags = make_transparency_pixmap ();
1428 if (background_flags == 0) 1458 if (background_flags == 0)
1429 return false; 1459 return false;
1430 else if ((background_flags & transpTransformations) == (flags & transpTransformations) 1460 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1431 && pmap_depth == target->depth)
1432 flags = flags & ~isInvalid; 1461 flags = flags & ~isInvalid;
1433 } 1462 }
1434# endif 1463# endif
1435 1464
1436# ifdef BG_IMAGE_FROM_FILE 1465# ifdef BG_IMAGE_FROM_FILE
1449 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1478 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1450 } 1479 }
1451 1480
1452 if (result) 1481 if (result)
1453 { 1482 {
1454# if !defined(HAVE_AFTERIMAGE) && !XFT 1483# if !defined(HAVE_AFTERIMAGE) && !XRENDER
1455 /* our own client-side tinting */ 1484 /* 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)) 1485 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1459 { 1486 {
1460 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1487 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1461 if (flags & tintSet) 1488 if (flags & tintSet)
1462 tint.get (c); 1489 tint.get (c);
1466 1493
1467 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); 1494 GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL);
1468 1495
1469 if (gc) 1496 if (gc)
1470 { 1497 {
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); 1498 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1500 1499
1501 XFreeGC (target->dpy, gc); 1500 XFreeGC (target->dpy, gc);
1502 flags = flags & ~isInvalid; 1501 flags = flags & ~isInvalid;
1503 } 1502 }
1504 1503
1526{ 1525{
1527 if (new_target) 1526 if (new_target)
1528 if (target != new_target) 1527 if (target != new_target)
1529 { 1528 {
1530 target = new_target; 1529 target = new_target;
1531# ifdef ENABLE_TRANSPARENCY
1532 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1533# endif
1534 return true; 1530 return true;
1535 } 1531 }
1536 1532
1537 return false; 1533 return false;
1538} 1534}
1540void 1536void
1541bgPixmap_t::apply () 1537bgPixmap_t::apply ()
1542{ 1538{
1543 if (target) 1539 if (target)
1544 { 1540 {
1545 flags &= ~isVtOrigin;
1546
1547 if (pixmap != None) 1541 if (pixmap != None)
1548 { 1542 {
1549 /* set target's background to pixmap */ 1543 /* set target's background to pixmap */
1550# ifdef ENABLE_TRANSPARENCY 1544# ifdef ENABLE_TRANSPARENCY
1551 if (flags & isTransparent) 1545 if (flags & isTransparent)
1557 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1551 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1558 } 1552 }
1559 else 1553 else
1560# endif 1554# endif
1561 { 1555 {
1562 flags |= isVtOrigin;
1563 /* force old pixmap dereference in case it was transparent before :*/ 1556 /* force old pixmap dereference in case it was transparent before :*/
1564 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1557 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1565 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1558 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1566 /* do we also need to set scrollbar's background here ? */ 1559 /* do we also need to set scrollbar's background here ? */
1567 1560
1594 } 1587 }
1595} 1588}
1596 1589
1597#endif /* HAVE_BG_PIXMAP */ 1590#endif /* HAVE_BG_PIXMAP */
1598 1591
1599#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT 1592#if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER
1600/* taken from aterm-0.4.2 */ 1593/* taken from aterm-0.4.2 */
1601 1594
1602static void 1595static void
1603ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) 1596ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm)
1604{ 1597{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines