… | |
… | |
141 | return ((align + 100) * smaller / 100) - image_size; |
141 | return ((align + 100) * smaller / 100) - image_size; |
142 | return 0; |
142 | return 0; |
143 | } |
143 | } |
144 | |
144 | |
145 | static inline void |
145 | static inline void |
146 | make_clip_rectangle (int pos, int size, int target_size, short &clip_pos, unsigned short &clip_size) |
146 | make_clip_rectangle (int pos, int size, int target_size, int &clip_pos, int &clip_size) |
147 | { |
147 | { |
|
|
148 | if (size <= 0) |
|
|
149 | { /* special case - tiling */ |
|
|
150 | clip_pos = pos; |
|
|
151 | clip_size = target_size; |
|
|
152 | } |
148 | if (pos < 0) |
153 | else if (pos < 0) |
149 | { |
154 | { |
150 | clip_pos = 0; |
155 | clip_pos = 0; |
151 | clip_size = MIN (target_size, size + pos); |
156 | clip_size = MIN (target_size, size + pos); |
152 | } |
157 | } |
153 | else |
158 | else |
… | |
… | |
351 | // flags, h_scale, v_scale, h_align, v_align); |
356 | // flags, h_scale, v_scale, h_align, v_align); |
352 | return (changed > 0); |
357 | return (changed > 0); |
353 | } |
358 | } |
354 | |
359 | |
355 | #ifdef HAVE_AFTERIMAGE |
360 | #ifdef HAVE_AFTERIMAGE |
356 | ASImage * |
361 | bool |
357 | bgPixmap_t::resize_asim (rxvt_term *target, ASImage *background, XRectangle &dst_rect) |
362 | bgPixmap_t::render_asim (rxvt_term *target, ASImage *background, ARGB32 background_tint) |
358 | { |
363 | { |
359 | if (original_asim == NULL || target == NULL) |
364 | if (target == NULL) |
360 | return NULL; |
365 | return false; |
361 | |
366 | |
362 | int target_width = (int)target->szHint.width; |
367 | int target_width = (int)target->szHint.width; |
363 | int target_height = (int)target->szHint.height; |
368 | int target_height = (int)target->szHint.height; |
|
|
369 | int new_pmap_width = target_width, new_pmap_height = target_height; |
|
|
370 | ASImage *result = NULL; |
|
|
371 | |
|
|
372 | int x = 0; |
|
|
373 | int y = 0; |
364 | int w = h_scale * target_width / 100; |
374 | int w = h_scale * target_width / 100; |
365 | int h = v_scale * target_height / 100; |
375 | int h = v_scale * target_height / 100; |
366 | int x = make_align_position (h_align, target_width, w); |
|
|
367 | int y = make_align_position (v_align, target_height, h); |
|
|
368 | |
376 | |
|
|
377 | if (original_asim) |
|
|
378 | { |
|
|
379 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
380 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
|
|
381 | } |
|
|
382 | |
|
|
383 | int dst_x, dst_y; |
|
|
384 | int clip_width, clip_height; |
|
|
385 | |
369 | make_clip_rectangle (x, w, target_width, dst_rect.x, dst_rect.width); |
386 | make_clip_rectangle (x, w, target_width, dst_x, clip_width); |
370 | make_clip_rectangle (y, h, target_height, dst_rect.y, dst_rect.height); |
387 | make_clip_rectangle (y, h, target_height, dst_y, clip_height); |
371 | |
388 | |
372 | /* TODO : actuall scaling code :) */ |
389 | /* TODO : actuall scaling code :) */ |
|
|
390 | if (dst_x >= target_width || dst_y >= target_height |
|
|
391 | || clip_width <= 0 || clip_height <= 0 || original_asim == NULL) |
|
|
392 | { |
|
|
393 | result = background; |
|
|
394 | dst_x = dst_y = 0; |
|
|
395 | if (background) |
|
|
396 | { |
|
|
397 | new_pmap_width = clip_width = background->width; |
|
|
398 | new_pmap_height = clip_height = background->height; |
|
|
399 | } |
|
|
400 | else |
|
|
401 | new_pmap_width = new_pmap_height = 0; |
|
|
402 | } |
|
|
403 | else |
|
|
404 | { |
|
|
405 | result = original_asim; |
|
|
406 | if ((w > 0 && w != original_asim->width) |
|
|
407 | || (h > 0 && h != original_asim->height)) |
|
|
408 | { |
|
|
409 | result = scale_asimage (target->asv, original_asim, |
|
|
410 | w > 0 ? w : original_asim->width, |
|
|
411 | h > 0 ? h : original_asim->height, |
|
|
412 | background ? ASA_ASImage : ASA_XImage, |
|
|
413 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
414 | } |
|
|
415 | if (background == NULL) |
|
|
416 | {/* if tiling - pixmap has to be sized exactly as the image */ |
|
|
417 | if (h_scale == 0) |
|
|
418 | new_pmap_width = result->width; |
|
|
419 | if (v_scale == 0) |
|
|
420 | new_pmap_height = result->height; |
|
|
421 | } |
|
|
422 | else |
|
|
423 | {/* if blending background and image - pixmap has to be sized same as target window */ |
|
|
424 | ASImageLayer *layers = create_image_layers (2); |
|
|
425 | ASImage *merged_im = NULL; |
373 | |
426 | |
|
|
427 | layers[0].im = background; |
|
|
428 | layers[0].clip_width = target_width; |
|
|
429 | layers[0].clip_height = target_height; |
|
|
430 | layers[0].tint = background_tint; |
|
|
431 | layers[1].im = result; |
|
|
432 | if (w <= 0) |
|
|
433 | {/* tile horizontally */ |
|
|
434 | layers[1].dst_x = dst_x - (int)result->width; |
|
|
435 | layers[1].clip_width = result->width; |
|
|
436 | } |
|
|
437 | else |
|
|
438 | {/* clip horizontally */ |
|
|
439 | layers[1].dst_x = dst_x; |
|
|
440 | layers[1].clip_width = clip_width; |
|
|
441 | } |
|
|
442 | if (h <= 0) |
|
|
443 | { |
|
|
444 | layers[1].dst_y = dst_y - (int)result->height; |
|
|
445 | layers[1].clip_height = result->height; |
|
|
446 | } |
|
|
447 | else |
|
|
448 | { |
|
|
449 | layers[1].dst_y = dst_y; |
|
|
450 | layers[1].clip_height = clip_height; |
|
|
451 | } |
|
|
452 | if (target->rs[Rs_blendtype]) |
|
|
453 | { |
|
|
454 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
|
|
455 | if (layers[1].merge_scanlines == NULL) |
|
|
456 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
457 | } |
|
|
458 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
|
|
459 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
460 | if (tmp) |
|
|
461 | { |
|
|
462 | if (result != original_asim) |
|
|
463 | destroy_asimage (&result); |
|
|
464 | result = tmp; |
|
|
465 | dst_x = dst_y = 0; |
|
|
466 | clip_width = target_width; |
|
|
467 | clip_height = target_height; |
|
|
468 | } |
|
|
469 | free (layers); |
|
|
470 | } |
|
|
471 | } |
|
|
472 | |
|
|
473 | if (pixmap) |
|
|
474 | { |
|
|
475 | if (result == NULL |
|
|
476 | || pmap_width != new_pmap_width |
|
|
477 | || pmap_height != new_pmap_height |
|
|
478 | || pmap_depth != target->depth) |
|
|
479 | { |
|
|
480 | XFreePixmap (target->dpy, pixmap); |
|
|
481 | pixmap = None; |
|
|
482 | } |
|
|
483 | } |
|
|
484 | |
|
|
485 | if (result) |
|
|
486 | { |
|
|
487 | XGCValues gcv; |
|
|
488 | GC gc; |
|
|
489 | |
|
|
490 | /* create Pixmap */ |
|
|
491 | if (pixmap == None) |
|
|
492 | { |
|
|
493 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
|
|
494 | pmap_width = new_pmap_width; |
|
|
495 | pmap_height = new_pmap_height; |
|
|
496 | pmap_depth = target->depth; |
|
|
497 | } |
|
|
498 | /* fill with background color ( if result's not completely overlapping it)*/ |
|
|
499 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
500 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
501 | |
|
|
502 | if (dst_x > 0 || dst_y > 0 |
|
|
503 | || dst_x + clip_width < new_pmap_width |
|
|
504 | || dst_y + clip_height < new_pmap_height) |
|
|
505 | { |
|
|
506 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
507 | } |
|
|
508 | /* put result on pixmap */ |
|
|
509 | asimage2drawable (target->asv, pixmap, result, gc, 0, 0, dst_x, dst_y, clip_width, clip_height, True); |
|
|
510 | |
|
|
511 | /* set target's background to pixmap */ |
|
|
512 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
513 | |
|
|
514 | XFreeGC (target->dpy, gc); |
|
|
515 | } |
|
|
516 | else |
|
|
517 | { |
|
|
518 | /* set target background to a pixel */ |
|
|
519 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
520 | } |
|
|
521 | |
|
|
522 | return true; |
374 | } |
523 | } |
375 | #endif |
524 | #endif |
376 | |
525 | |
377 | void |
526 | void |
378 | rxvt_term::resize_pixmap () |
527 | rxvt_term::resize_pixmap () |
… | |
… | |
812 | i = (xa[XA_ESETROOT_PMAP_ID] |
961 | i = (xa[XA_ESETROOT_PMAP_ID] |
813 | && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], |
962 | && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], |
814 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
963 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
815 | &nitems, &bytes_after, &prop) == Success); |
964 | &nitems, &bytes_after, &prop) == Success); |
816 | |
965 | |
817 | /* TODO: the below logic needs to be cleaned up */ |
|
|
818 | if (!i || prop == NULL |
966 | if (!i || prop == NULL) |
819 | || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL |
|
|
820 | #ifdef HAVE_AFTERIMAGE |
|
|
821 | && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL |
|
|
822 | #endif |
|
|
823 | ) |
|
|
824 | ) |
|
|
825 | rootpixmap = None; |
967 | rootpixmap = None; |
826 | else |
968 | else |
827 | { |
969 | { |
828 | int junk; |
970 | int junk; |
829 | unsigned int ujunk; |
971 | unsigned int ujunk; |
… | |
… | |
1049 | } /* rootpixmap != None */ |
1191 | } /* rootpixmap != None */ |
1050 | |
1192 | |
1051 | if (am_pixmap_trans) |
1193 | if (am_pixmap_trans) |
1052 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
1194 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
1053 | else |
1195 | else |
1054 | { |
1196 | return; |
1055 | unsigned int n; |
|
|
1056 | /* |
|
|
1057 | * InheritPixmap transparency |
|
|
1058 | */ |
|
|
1059 | for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
|
|
1060 | { |
|
|
1061 | oldp = parent[i]; |
|
|
1062 | XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n); |
|
|
1063 | XFree (list); |
|
|
1064 | |
|
|
1065 | if (parent[i] == display->root) |
|
|
1066 | { |
|
|
1067 | if (oldp != None) |
|
|
1068 | pchanged = 1; |
|
|
1069 | |
|
|
1070 | break; |
|
|
1071 | } |
|
|
1072 | |
|
|
1073 | if (oldp != parent[i]) |
|
|
1074 | pchanged = 1; |
|
|
1075 | } |
|
|
1076 | |
|
|
1077 | n = 0; |
|
|
1078 | |
|
|
1079 | if (pchanged) |
|
|
1080 | for (; n < (unsigned int)i; n++) |
|
|
1081 | { |
|
|
1082 | XGetWindowAttributes (dpy, parent[n], &wattr); |
|
|
1083 | |
|
|
1084 | if (wattr.depth != rootdepth || wattr.c_class == InputOnly) |
|
|
1085 | { |
|
|
1086 | n = (int) (sizeof (parent) / sizeof (Window)) + 1; |
|
|
1087 | break; |
|
|
1088 | } |
|
|
1089 | } |
|
|
1090 | |
|
|
1091 | if (n > (sizeof (parent) / sizeof (parent[0]))) |
|
|
1092 | { |
|
|
1093 | XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]); |
|
|
1094 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
|
|
1095 | am_transparent = 0; |
|
|
1096 | /* XXX: also turn off Opt_transparent? */ |
|
|
1097 | } |
|
|
1098 | else |
|
|
1099 | { |
|
|
1100 | for (n = 0; n < (unsigned int)i; n++) |
|
|
1101 | { |
|
|
1102 | XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative); |
|
|
1103 | XClearWindow (dpy, parent[n]); |
|
|
1104 | } |
|
|
1105 | |
|
|
1106 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
|
|
1107 | am_transparent = 1; |
|
|
1108 | } |
|
|
1109 | |
|
|
1110 | for (; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
|
|
1111 | parent[i] = None; |
|
|
1112 | } |
|
|
1113 | |
1197 | |
1114 | if (scrollBar.win) |
1198 | if (scrollBar.win) |
1115 | { |
1199 | { |
1116 | XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); |
1200 | XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); |
1117 | scrollBar.setIdle (); |
1201 | scrollBar.setIdle (); |