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.25 by root, Sat Jan 19 00:21:59 2008 UTC vs.
Revision 1.32 by root, Tue Nov 4 14:38:29 2008 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xpm.C 2 * File: background.C - former xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * 4 *
5 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> 6 * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or 11 * the Free Software Foundation; either version 2 of the License, or
370 if (ops) 370 if (ops)
371 { 371 {
372 while (*ops) 372 while (*ops)
373 { 373 {
374 while (*ops == ':' || isspace(*ops)) ++ops; 374 while (*ops == ':' || isspace(*ops)) ++ops;
375
375# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) 376# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
376 if (CHECK_GEOM_OPS("tile")) 377 if (CHECK_GEOM_OPS ("tile"))
377 { 378 {
378 w = h = noScale; 379 w = h = noScale;
379 geom_flags |= WidthValue|HeightValue; 380 geom_flags |= WidthValue|HeightValue;
380 } 381 }
381 else if (CHECK_GEOM_OPS("propscale")) 382 else if (CHECK_GEOM_OPS ("propscale"))
382 { 383 {
383 if (w == 0 && h == 0) 384 if (w == 0 && h == 0)
384 { 385 {
385 w = windowScale; 386 w = windowScale;
386 geom_flags |= WidthValue; 387 geom_flags |= WidthValue;
387 } 388 }
388 new_flags |= propScale; 389 new_flags |= propScale;
389 } 390 }
390 else if (CHECK_GEOM_OPS("hscale")) 391 else if (CHECK_GEOM_OPS ("hscale"))
391 { 392 {
392 if (w == 0)
393 w = windowScale; 393 if (w == 0) w = windowScale;
394
394 h = noScale; 395 h = noScale;
395 geom_flags |= WidthValue|HeightValue; 396 geom_flags |= WidthValue|HeightValue;
396 } 397 }
397 else if (CHECK_GEOM_OPS("vscale")) 398 else if (CHECK_GEOM_OPS ("vscale"))
398 { 399 {
399 if (h == 0)
400 h = windowScale; 400 if (h == 0) h = windowScale;
401
401 w = noScale; 402 w = noScale;
402 geom_flags |= WidthValue|HeightValue; 403 geom_flags |= WidthValue|HeightValue;
403 } 404 }
404 else if (CHECK_GEOM_OPS("scale")) 405 else if (CHECK_GEOM_OPS ("scale"))
405 { 406 {
406 if (h == 0)
407 h = windowScale; 407 if (h == 0) h = windowScale;
408 if (w == 0)
409 w = windowScale; 408 if (w == 0) w = windowScale;
409
410 geom_flags |= WidthValue|HeightValue; 410 geom_flags |= WidthValue|HeightValue;
411 } 411 }
412 else if (CHECK_GEOM_OPS("auto")) 412 else if (CHECK_GEOM_OPS ("auto"))
413 { 413 {
414 w = h = windowScale; 414 w = h = windowScale;
415 x = y = centerAlign; 415 x = y = centerAlign;
416 geom_flags |= WidthValue|HeightValue|XValue|YValue; 416 geom_flags |= WidthValue|HeightValue|XValue|YValue;
417 } 417 }
418 else if (CHECK_GEOM_OPS("root")) 418 else if (CHECK_GEOM_OPS ("root"))
419 { 419 {
420 w = h = noScale; 420 w = h = noScale;
421 x = y = rootAlign; 421 x = y = rootAlign;
422 geom_flags |= WidthValue|HeightValue|XValue|YValue; 422 geom_flags |= WidthValue|HeightValue|XValue|YValue;
423 } 423 }
424# undef CHECK_GEOM_OPS 424# undef CHECK_GEOM_OPS
425
425 while (*ops != ':' && *ops != '\0') ++ops; 426 while (*ops != ':' && *ops != '\0') ++ops;
426 } /* done parsing ops */ 427 } /* done parsing ops */
427 } 428 }
428 429
429 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) 430 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed;
430 ++changed;
431 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) 431 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed;
432 ++changed;
433 if (check_set_align_value (geom_flags, XValue, h_align, x)) 432 if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed;
434 ++changed;
435 if (check_set_align_value (geom_flags, YValue, v_align, y)) 433 if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed;
436 ++changed;
437 } 434 }
438 435
439 if (new_flags != flags) 436 if (new_flags != flags)
440 { 437 {
441 flags = new_flags; 438 flags = new_flags;
442 changed++; 439 changed++;
443 } 440 }
441
444//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", 442//fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
445// flags, h_scale, v_scale, h_align, v_align); 443// flags, h_scale, v_scale, h_align, v_align);
446 return (changed > 0); 444 return (changed > 0);
447} 445}
448 446
451bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) 449bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint)
452{ 450{
453 if (target == NULL) 451 if (target == NULL)
454 return false; 452 return false;
455 453
454 target->init_asv ();
455
456 ASImage *result = 0;
457
456 int target_width = (int)target->szHint.width; 458 int target_width = target->szHint.width;
457 int target_height = (int)target->szHint.height; 459 int target_height = target->szHint.height;
458 int new_pmap_width = target_width, new_pmap_height = target_height; 460 int new_pmap_width = target_width;
459 ASImage *result = NULL; 461 int new_pmap_height = target_height;
460 462
461 int x = 0; 463 int x = 0;
462 int y = 0; 464 int y = 0;
463 int w = h_scale * target_width / 100; 465 int w = h_scale * target_width / 100;
464 int h = v_scale * target_height / 100; 466 int h = v_scale * target_height / 100;
638 640
639 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; 641 int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0;
640 int dst_width = result->width, dst_height = result->height; 642 int dst_width = result->width, dst_height = result->height;
641 if (background == NULL) 643 if (background == NULL)
642 { 644 {
643 if (h_scale > 0)
644 src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); 645 if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width );
645 if (v_scale > 0)
646 src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); 646 if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height);
647 647
648 if (dst_x > 0 || dst_y > 0 648 if (dst_x > 0 || dst_y > 0
649 || dst_x + dst_width < new_pmap_width 649 || dst_x + dst_width < new_pmap_width
650 || dst_y + dst_height < new_pmap_height) 650 || dst_y + dst_height < new_pmap_height)
651 {
652 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); 651 XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height);
653 }
654 } 652 }
655 653
656 /* put result on pixmap */ 654 /* put result on pixmap */
657 if (dst_x < new_pmap_width && dst_y < new_pmap_height) 655 if (dst_x < new_pmap_width && dst_y < new_pmap_height)
658 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); 656 asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True);
669# endif /* HAVE_AFTERIMAGE */ 667# endif /* HAVE_AFTERIMAGE */
670 668
671bool 669bool
672bgPixmap_t::set_file (const char *file) 670bgPixmap_t::set_file (const char *file)
673{ 671{
674 char *f;
675
676 assert (file); 672 assert (file);
677 673
678 if (*file) 674 if (*file)
679 { 675 {
680# ifdef HAVE_AFTERIMAGE 676# ifdef HAVE_AFTERIMAGE
681 if (target->asimman == NULL) 677 if (!target->asimman)
682 target->asimman = create_generic_imageman (target->rs[Rs_path]); 678 target->asimman = create_generic_imageman (target->rs[Rs_path]);
683 679
684 if ((f = strchr (file, ';')) == NULL) 680 if (char *f = strchr (file, ';'))
685 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
686 else
687 { 681 {
688 size_t len = f - file; 682 size_t len = f - file;
689 f = (char *)malloc (len + 1); 683 f = (char *)malloc (len + 1);
690 memcpy (f, file, len); 684 memcpy (f, file, len);
691 f[len] = '\0'; 685 f[len] = '\0';
692 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); 686 original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100);
693 free (f); 687 free (f);
694 } 688 }
689 else
690 original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100);
695 691
696 return original_asim; 692 return original_asim;
697# endif 693# endif
698 } 694 }
699 695
1125 if (target == NULL) 1121 if (target == NULL)
1126 return false; 1122 return false;
1127 1123
1128 TIMING_TEST_START (tp); 1124 TIMING_TEST_START (tp);
1129 1125
1130 invalidate(); 1126 invalidate ();
1131# ifdef ENABLE_TRANSPARENCY 1127# ifdef ENABLE_TRANSPARENCY
1132 if (flags & isTransparent) 1128 if (flags & isTransparent)
1133 { 1129 {
1134 /* we need to re-generate transparency pixmap in that case ! */ 1130 /* we need to re-generate transparency pixmap in that case ! */
1135 background_flags = make_transparency_pixmap (); 1131 background_flags = make_transparency_pixmap ();
1141 } 1137 }
1142# endif 1138# endif
1143 1139
1144 XImage *result = NULL; 1140 XImage *result = NULL;
1145# ifdef HAVE_AFTERIMAGE 1141# ifdef HAVE_AFTERIMAGE
1142 target->init_asv ();
1143
1146 if (original_asim 1144 if (original_asim
1147 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1145 || (background_flags & transpTransformations) != (flags & transpTransformations))
1148 { 1146 {
1149 ASImage *background = NULL; 1147 ASImage *background = NULL;
1150 ARGB32 as_tint = TINT_LEAVE_SAME; 1148 ARGB32 as_tint = TINT_LEAVE_SAME;
1151 if (background_flags) 1149 if (background_flags)
1152 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); 1150 background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100);
1153 1151
1154# ifdef ENABLE_TRANSPARENCY 1152# ifdef ENABLE_TRANSPARENCY
1155 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1153 if (!(background_flags & transpPmapTinted) && (flags & tintNeeded))
1156 { 1154 {
1157 ShadingInfo as_shade; 1155 ShadingInfo as_shade;
1164 as_shade.tintColor.green = c.g; 1162 as_shade.tintColor.green = c.g;
1165 as_shade.tintColor.blue = c.b; 1163 as_shade.tintColor.blue = c.b;
1166 1164
1167 as_tint = shading2tint32 (&as_shade); 1165 as_tint = shading2tint32 (&as_shade);
1168 } 1166 }
1167
1169 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) 1168 if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL)
1170 { 1169 {
1171 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, 1170 ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF,
1172 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, 1171 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
1173 100, ASIMAGE_QUALITY_DEFAULT); 1172 100, ASIMAGE_QUALITY_DEFAULT);
1180# endif 1179# endif
1181 1180
1182 if (render_asim (background, as_tint)) 1181 if (render_asim (background, as_tint))
1183 flags = flags & ~isInvalid; 1182 flags = flags & ~isInvalid;
1184 if (background) 1183 if (background)
1185 destroy_asimage (&background); 1184 destroy_asimage (&background);
1186 } 1185 }
1187 else if (background_flags && pmap_depth != target->depth) 1186 else if (background_flags && pmap_depth != target->depth)
1188 {
1189 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1187 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1190 }
1191 1188
1192# elif !XFT /* our own client-side tinting */ 1189# elif !XFT /* our own client-side tinting */
1193 1190
1194 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side. 1191 /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side.
1195 This may need to be changed in need_client_side_rendering() logic is altered !!! */ 1192 This may need to be changed in need_client_side_rendering() logic is altered !!! */
1196 1193
1197 if (background_flags && (flags & isInvalid)) 1194 if (background_flags && (flags & isInvalid))
1198 { 1195 {
1199 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); 1196 result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap);
1197
1200 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) 1198 if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded))
1201 { 1199 {
1202 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); 1200 rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC);
1203 if (flags & tintSet) 1201 if (flags & tintSet)
1204 tint.get (c); 1202 tint.get (c);
1279# ifdef ENABLE_TRANSPARENCY 1277# ifdef ENABLE_TRANSPARENCY
1280 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); 1278 root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen));
1281# endif 1279# endif
1282 return true; 1280 return true;
1283 } 1281 }
1282
1284 return false; 1283 return false;
1285} 1284}
1286 1285
1287void 1286void
1288bgPixmap_t::apply () 1287bgPixmap_t::apply ()
1289{ 1288{
1290 if (target) 1289 if (target)
1291 { 1290 {
1292 flags &= ~isVtOrigin; 1291 flags &= ~isVtOrigin;
1292
1293 if (pixmap != None) 1293 if (pixmap != None)
1294 { 1294 {
1295 /* set target's background to pixmap */ 1295 /* set target's background to pixmap */
1296# ifdef ENABLE_TRANSPARENCY 1296# ifdef ENABLE_TRANSPARENCY
1297 if (flags & isTransparent) 1297 if (flags & isTransparent)
1298 { 1298 {
1299 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); 1299 XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap);
1300 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); 1300 XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative);
1301# if HAVE_SCROLLBARS 1301
1302 if (target->scrollBar.win) 1302 if (target->scrollBar.win)
1303 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); 1303 XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative);
1304# endif
1305 } 1304 }
1306 else 1305 else
1307# endif 1306# endif
1308 { 1307 {
1309 flags |= isVtOrigin; 1308 flags |= isVtOrigin;
1310 /* force old pixmap dereference in case it was transparent before :*/ 1309 /* force old pixmap dereference in case it was transparent before :*/
1311 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1310 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1312 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); 1311 XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap);
1313 /* do we also need to set scrollbar's background here ? */ 1312 /* do we also need to set scrollbar's background here ? */
1314# if HAVE_SCROLLBARS 1313
1315 if (target->scrollBar.win) 1314 if (target->scrollBar.win)
1316 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1315 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1317# endif
1318 } 1316 }
1319 } 1317 }
1320 else 1318 else
1321 { 1319 {
1322 /* set target background to a pixel */ 1320 /* set target background to a pixel */
1323 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); 1321 XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]);
1324 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); 1322 XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]);
1325 /* do we also need to set scrollbar's background here ? */ 1323 /* do we also need to set scrollbar's background here ? */
1326# if HAVE_SCROLLBARS
1327 if (target->scrollBar.win) 1324 if (target->scrollBar.win)
1328 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); 1325 XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]);
1329# endif
1330 } 1326 }
1327
1331 /* don't want Expose on the parent or vt. It is better to use 1328 /* don't want Expose on the parent or vt. It is better to use
1332 scr_touch or we get a great deal of flicker otherwise: */ 1329 scr_touch or we get a great deal of flicker otherwise: */
1333 XClearWindow (target->dpy, target->parent[0]); 1330 XClearWindow (target->dpy, target->parent[0]);
1334 1331
1335# if HAVE_SCROLLBARS
1336 if (target->scrollBar.win) 1332 if (target->scrollBar.win)
1337 { 1333 {
1338 target->scrollBar.setIdle (); 1334 target->scrollBar.state = STATE_IDLE;
1339 target->scrollbar_show (0); 1335 target->scrollBar.show (0);
1340 } 1336 }
1341# endif
1342 1337
1343 target->want_refresh = 1; 1338 target->want_refresh = 1;
1344 flags |= hasChanged; 1339 flags |= hasChanged;
1345 } 1340 }
1346} 1341}

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines