… | |
… | |
52 | * adjustment and may optionally be followed by a colon and one or more |
52 | * adjustment and may optionally be followed by a colon and one or more |
53 | * colon-delimited pixmap operations. |
53 | * colon-delimited pixmap operations. |
54 | * The following table shows the valid geometry strings and their |
54 | * The following table shows the valid geometry strings and their |
55 | * effects on the background image : |
55 | * effects on the background image : |
56 | * |
56 | * |
57 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
57 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
58 | * W and H are percentages of the terminal window size. |
58 | * W and H are percentages of the terminal window size. |
59 | * X and Y are also percentages; e.g., +50+50 centers |
59 | * X and Y are also percentages; e.g., +50+50 centers |
60 | * the image in the window. |
60 | * the image in the window. |
61 | * WxH+X Assumes Y == X |
61 | * WxH+X Assumes Y == X |
62 | * WxH Assumes Y == X == 50 (centers the image) |
62 | * WxH Assumes Y == X == 50 (centers the image) |
63 | * W+X+Y Assumes H == W |
63 | * W+X+Y Assumes H == W |
64 | * W+X Assumes H == W and Y == X |
64 | * W+X Assumes H == W and Y == X |
65 | * W Assumes H == W and Y == X == 50 |
65 | * W Assumes H == W and Y == X == 50 |
66 | * |
66 | * |
67 | * Adjusting position only : |
67 | * Adjusting position only : |
68 | * =+X+Y Set position to X% by Y% (absolute). |
68 | * =+X+Y Set position to X% by Y% (absolute). |
69 | * =+X Set position to X% by X%. |
69 | * =+X Set position to X% by X%. |
70 | * +X+Y Adjust position horizontally X% and vertically Y% |
70 | * +X+Y Adjust position horizontally X% and vertically Y% |
71 | * from current position (relative). |
71 | * from current position (relative). |
72 | * +X Adjust position horizontally X% and vertically X% |
72 | * +X Adjust position horizontally X% and vertically X% |
73 | * from current position. |
73 | * from current position. |
74 | * |
74 | * |
75 | * Adjusting scale only : |
75 | * Adjusting scale only : |
76 | * Wx0 Multiply horizontal scaling factor by W% |
76 | * Wx0 Multiply horizontal scaling factor by W% |
77 | * 0xH Multiply vertical scaling factor by H% |
77 | * 0xH Multiply vertical scaling factor by H% |
78 | * 0x0 No scaling (show image at normal size). |
78 | * 0x0 No scaling (show image at normal size). |
79 | * |
79 | * |
80 | * Pixmap Operations : (should be prepended by a colon) |
80 | * Pixmap Operations : (should be prepended by a colon) |
81 | * tile Tile image. Scaling/position modifiers above will affect |
81 | * tile Tile image. Scaling/position modifiers above will affect |
82 | * the tile size and origin. |
82 | * the tile size and origin. |
83 | * propscale When scaling, scale proportionally. That is, maintain the |
83 | * propscale When scaling, scale proportionally. That is, maintain the |
84 | * proper aspect ratio for the image. Any portion of the |
84 | * proper aspect ratio for the image. Any portion of the |
85 | * background not covered by the image is filled with the |
85 | * background not covered by the image is filled with the |
86 | * current background color. |
86 | * current background color. |
87 | * hscale Scale horizontally, tile vertically ? |
87 | * hscale Scale horizontally, tile vertically ? |
88 | * vscale Tile horizontally, scale vertically ? |
88 | * vscale Tile horizontally, scale vertically ? |
… | |
… | |
96 | // this is basically redundant as bgPixmap_t is only used in |
96 | // this is basically redundant as bgPixmap_t is only used in |
97 | // zero_initialised-derived structs |
97 | // zero_initialised-derived structs |
98 | #ifdef HAVE_AFTERIMAGE |
98 | #ifdef HAVE_AFTERIMAGE |
99 | original_asim = NULL; |
99 | original_asim = NULL; |
100 | #endif |
100 | #endif |
|
|
101 | #ifdef HAVE_PIXBUF |
|
|
102 | pixbuf = NULL; |
|
|
103 | #endif |
101 | #ifdef BG_IMAGE_FROM_FILE |
104 | #ifdef BG_IMAGE_FROM_FILE |
|
|
105 | have_image = false; |
102 | h_scale = v_scale = 0; |
106 | h_scale = v_scale = 0; |
103 | h_align = v_align = 0; |
107 | h_align = v_align = 0; |
104 | #endif |
108 | #endif |
105 | flags = 0; |
109 | flags = 0; |
106 | pixmap = None; |
110 | pixmap = None; |
… | |
… | |
114 | #ifdef HAVE_AFTERIMAGE |
118 | #ifdef HAVE_AFTERIMAGE |
115 | if (original_asim) |
119 | if (original_asim) |
116 | safe_asimage_destroy (original_asim); |
120 | safe_asimage_destroy (original_asim); |
117 | #endif |
121 | #endif |
118 | |
122 | |
|
|
123 | #ifdef HAVE_PIXBUF |
|
|
124 | if (pixbuf) |
|
|
125 | g_object_unref (pixbuf); |
|
|
126 | #endif |
|
|
127 | |
119 | if (pixmap && target) |
128 | if (pixmap && target) |
120 | XFreePixmap (target->dpy, pixmap); |
129 | XFreePixmap (target->dpy, pixmap); |
121 | } |
130 | } |
122 | |
131 | |
123 | bool |
132 | bool |
… | |
… | |
127 | if (flags & isTransparent) |
136 | if (flags & isTransparent) |
128 | return true; |
137 | return true; |
129 | # endif |
138 | # endif |
130 | |
139 | |
131 | # ifdef BG_IMAGE_FROM_FILE |
140 | # ifdef BG_IMAGE_FROM_FILE |
132 | # ifdef HAVE_AFTERIMAGE |
141 | if (have_image) |
133 | if (original_asim) |
|
|
134 | # endif |
|
|
135 | { |
142 | { |
136 | if (h_scale != 0 || v_scale != 0 |
143 | if (flags & sizeSensitive) |
137 | || h_align != 0 || v_align != 0) |
|
|
138 | return true; |
144 | return true; |
139 | } |
145 | } |
140 | # endif |
146 | # endif |
141 | |
147 | |
142 | return false; |
148 | return false; |
… | |
… | |
149 | if (flags & isTransparent) |
155 | if (flags & isTransparent) |
150 | return true; |
156 | return true; |
151 | # endif |
157 | # endif |
152 | |
158 | |
153 | # ifdef BG_IMAGE_FROM_FILE |
159 | # ifdef BG_IMAGE_FROM_FILE |
154 | # ifdef HAVE_AFTERIMAGE |
160 | if (have_image) |
155 | if (original_asim) |
|
|
156 | # endif |
|
|
157 | { |
161 | { |
158 | if (h_align == rootAlign || v_align == rootAlign) |
162 | if (h_align == rootAlign || v_align == rootAlign) |
159 | return true; |
163 | return true; |
160 | } |
164 | } |
161 | # endif |
165 | # endif |
… | |
… | |
223 | |
227 | |
224 | static inline int |
228 | static inline int |
225 | make_align_position (int align, int window_size, int image_size) |
229 | make_align_position (int align, int window_size, int image_size) |
226 | { |
230 | { |
227 | int diff = window_size - image_size; |
231 | int diff = window_size - image_size; |
228 | int smaller = MIN (image_size,window_size); |
232 | int smaller = min (image_size, window_size); |
229 | |
233 | |
230 | if (align >= 0 && align <= 50) |
234 | if (align >= 0 && align <= 50) |
231 | return diff * align / 100; |
235 | return diff * align / 100; |
232 | else if (align > 50 && align <= 100) |
236 | else if (align > 50 && align <= 100) |
233 | return window_size - image_size - diff * (100 - align) / 100; |
237 | return window_size - image_size - diff * (100 - align) / 100; |
… | |
… | |
242 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
246 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
243 | { |
247 | { |
244 | int src_pos = 0; |
248 | int src_pos = 0; |
245 | dst_pos = 0; |
249 | dst_pos = 0; |
246 | dst_size = size; |
250 | dst_size = size; |
247 | if (pos < 0 && size > target_size) |
251 | if (pos < 0) |
248 | { |
252 | { |
249 | src_pos = -pos; |
253 | src_pos = -pos; |
250 | dst_size += pos; |
254 | dst_size += pos; |
251 | } |
255 | } |
252 | else if (pos > 0) |
256 | else if (pos > 0) |
… | |
… | |
383 | w = h = noScale; |
387 | w = h = noScale; |
384 | geom_flags |= WidthValue|HeightValue; |
388 | geom_flags |= WidthValue|HeightValue; |
385 | } |
389 | } |
386 | else if (CHECK_GEOM_OPS ("propscale")) |
390 | else if (CHECK_GEOM_OPS ("propscale")) |
387 | { |
391 | { |
388 | if (w == 0 && h == 0) |
|
|
389 | { |
|
|
390 | w = windowScale; |
|
|
391 | geom_flags |= WidthValue; |
|
|
392 | } |
|
|
393 | new_flags |= propScale; |
392 | new_flags |= propScale; |
394 | } |
393 | } |
395 | else if (CHECK_GEOM_OPS ("hscale")) |
394 | else if (CHECK_GEOM_OPS ("hscale")) |
396 | { |
395 | { |
397 | if (w == 0) w = windowScale; |
396 | if (w == 0) w = windowScale; |
… | |
… | |
441 | { |
440 | { |
442 | flags = new_flags; |
441 | flags = new_flags; |
443 | changed++; |
442 | changed++; |
444 | } |
443 | } |
445 | |
444 | |
446 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
445 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
447 | // flags, h_scale, v_scale, h_align, v_align); |
446 | // flags, h_scale, v_scale, h_align, v_align); |
448 | return (changed > 0); |
447 | return (changed > 0); |
|
|
448 | } |
|
|
449 | |
|
|
450 | void |
|
|
451 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
|
|
452 | { |
|
|
453 | int target_width = target->szHint.width; |
|
|
454 | int target_height = target->szHint.height; |
|
|
455 | |
|
|
456 | if (flags & propScale) |
|
|
457 | { |
|
|
458 | float scale = (float)target_width / image_width; |
|
|
459 | min_it (scale, (float)target_height / image_height); |
|
|
460 | w = image_width * scale + 0.5; |
|
|
461 | h = image_height * scale + 0.5; |
|
|
462 | } |
|
|
463 | else |
|
|
464 | { |
|
|
465 | w = h_scale * target_width / 100; |
|
|
466 | h = v_scale * target_height / 100; |
|
|
467 | } |
|
|
468 | |
|
|
469 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
470 | { |
|
|
471 | target->get_window_origin (x, y); |
|
|
472 | x = -x; |
|
|
473 | y = -y; |
|
|
474 | } |
|
|
475 | |
|
|
476 | if (h_align != rootAlign) |
|
|
477 | x = make_align_position (h_align, target_width, w > 0 ? w : image_width); |
|
|
478 | |
|
|
479 | if (v_align != rootAlign) |
|
|
480 | y = make_align_position (v_align, target_height, h > 0 ? h : image_height); |
|
|
481 | |
|
|
482 | flags &= ~sizeSensitive; |
|
|
483 | if (h_scale != 0 || v_scale != 0 |
|
|
484 | || h_align != 0 || v_align != 0 |
|
|
485 | || image_width > target_width || image_height > target_height) |
|
|
486 | flags |= sizeSensitive; |
449 | } |
487 | } |
450 | |
488 | |
451 | # ifdef HAVE_AFTERIMAGE |
489 | # ifdef HAVE_AFTERIMAGE |
452 | bool |
490 | bool |
453 | bgPixmap_t::render_asim (unsigned long background_flags) |
491 | bgPixmap_t::render_image (unsigned long background_flags) |
454 | { |
492 | { |
455 | if (target == NULL) |
493 | if (target == NULL) |
456 | return false; |
494 | return false; |
457 | |
495 | |
458 | target->init_asv (); |
496 | target->init_asv (); |
… | |
… | |
480 | } |
518 | } |
481 | |
519 | |
482 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
520 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
483 | { |
521 | { |
484 | ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
522 | ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
485 | (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, |
523 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
486 | 100, ASIMAGE_QUALITY_DEFAULT); |
524 | 100, ASIMAGE_QUALITY_DEFAULT); |
487 | if (tmp) |
525 | if (tmp) |
488 | { |
526 | { |
489 | destroy_asimage (&background); |
527 | destroy_asimage (&background); |
490 | background = tmp; |
528 | background = tmp; |
… | |
… | |
499 | int new_pmap_width = target_width; |
537 | int new_pmap_width = target_width; |
500 | int new_pmap_height = target_height; |
538 | int new_pmap_height = target_height; |
501 | |
539 | |
502 | int x = 0; |
540 | int x = 0; |
503 | int y = 0; |
541 | int y = 0; |
504 | int w = h_scale * target_width / 100; |
542 | int w = 0; |
505 | int h = v_scale * target_height / 100; |
543 | int h = 0; |
506 | |
544 | |
507 | TIMING_TEST_START (asim); |
545 | TIMING_TEST_START (asim); |
508 | |
546 | |
509 | if (original_asim) |
547 | if (original_asim) |
510 | { |
548 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
511 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
512 | { |
|
|
513 | target->get_window_origin(x, y); |
|
|
514 | x = -x; |
|
|
515 | y = -y; |
|
|
516 | } |
|
|
517 | |
|
|
518 | if (h_align != rootAlign) |
|
|
519 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
520 | |
|
|
521 | if (v_align != rootAlign) |
|
|
522 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
|
|
523 | } |
|
|
524 | |
549 | |
525 | if (!original_asim |
550 | if (!original_asim |
526 | || x >= target_width |
551 | || x >= target_width |
527 | || y >= target_height |
552 | || y >= target_height |
528 | || (w > 0 && x + w <= 0) |
553 | || (w > 0 && x + w <= 0) |
… | |
… | |
560 | 100, ASIMAGE_QUALITY_DEFAULT); |
585 | 100, ASIMAGE_QUALITY_DEFAULT); |
561 | } |
586 | } |
562 | |
587 | |
563 | if (background == NULL) |
588 | if (background == NULL) |
564 | { |
589 | { |
565 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
566 | but there is no need to make it bigger than the window! */ |
|
|
567 | if (h_scale == 0) |
|
|
568 | new_pmap_width = min (result->width, target_width); |
|
|
569 | if (v_scale == 0) |
|
|
570 | new_pmap_height = min (result->height, target_height); |
|
|
571 | /* we also need to tile our image in one or both directions */ |
|
|
572 | if (h_scale == 0 || v_scale == 0) |
590 | if (h_scale == 0 || v_scale == 0) |
573 | { |
591 | { |
|
|
592 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
593 | but there is no need to make it bigger than the window! */ |
|
|
594 | new_pmap_width = min (result->width, target_width); |
|
|
595 | new_pmap_height = min (result->height, target_height); |
|
|
596 | |
|
|
597 | /* we also need to tile our image in both directions */ |
574 | ASImage *tmp = tile_asimage (target->asv, result, |
598 | ASImage *tmp = tile_asimage (target->asv, result, |
575 | (h_scale > 0) ? 0 : (int)result->width - x, |
599 | (int)result->width - x, |
576 | (v_scale > 0) ? 0 : (int)result->height - y, |
600 | (int)result->height - y, |
577 | new_pmap_width, |
601 | new_pmap_width, |
578 | new_pmap_height, |
602 | new_pmap_height, |
579 | TINT_LEAVE_SAME, ASA_XImage, |
603 | TINT_LEAVE_SAME, ASA_XImage, |
580 | 100, ASIMAGE_QUALITY_DEFAULT); |
604 | 100, ASIMAGE_QUALITY_DEFAULT); |
581 | if (tmp) |
605 | if (tmp) |
… | |
… | |
645 | free (layers); |
669 | free (layers); |
646 | } |
670 | } |
647 | } |
671 | } |
648 | TIMING_TEST_PRINT_RESULT (asim); |
672 | TIMING_TEST_PRINT_RESULT (asim); |
649 | |
673 | |
650 | if (pixmap) |
674 | bool ret = false; |
651 | { |
|
|
652 | if (result == NULL |
|
|
653 | || pmap_width != new_pmap_width |
|
|
654 | || pmap_height != new_pmap_height |
|
|
655 | || pmap_depth != target->depth) |
|
|
656 | { |
|
|
657 | XFreePixmap (target->dpy, pixmap); |
|
|
658 | pixmap = None; |
|
|
659 | } |
|
|
660 | } |
|
|
661 | |
675 | |
662 | if (result) |
676 | if (result) |
663 | { |
677 | { |
664 | XGCValues gcv; |
678 | XGCValues gcv; |
665 | GC gc; |
679 | GC gc; |
|
|
680 | |
|
|
681 | if (pixmap) |
|
|
682 | { |
|
|
683 | if (pmap_width != new_pmap_width |
|
|
684 | || pmap_height != new_pmap_height |
|
|
685 | || pmap_depth != target->depth) |
|
|
686 | { |
|
|
687 | XFreePixmap (target->dpy, pixmap); |
|
|
688 | pixmap = None; |
|
|
689 | } |
|
|
690 | } |
666 | |
691 | |
667 | /* create Pixmap */ |
692 | /* create Pixmap */ |
668 | if (pixmap == None) |
693 | if (pixmap == None) |
669 | { |
694 | { |
670 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
695 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
671 | pmap_width = new_pmap_width; |
696 | pmap_width = new_pmap_width; |
672 | pmap_height = new_pmap_height; |
697 | pmap_height = new_pmap_height; |
673 | pmap_depth = target->depth; |
698 | pmap_depth = target->depth; |
674 | } |
699 | } |
675 | /* fill with background color ( if result's not completely overlapping it)*/ |
700 | /* fill with background color (if result's not completely overlapping it) */ |
676 | gcv.foreground = target->pix_colors[Color_bg]; |
701 | gcv.foreground = target->pix_colors[Color_bg]; |
677 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
702 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
678 | |
703 | |
679 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
704 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
680 | int dst_width = result->width, dst_height = result->height; |
705 | int dst_width = result->width, dst_height = result->height; |
681 | if (background == NULL) |
706 | if (background == NULL) |
682 | { |
707 | { |
|
|
708 | if (!(h_scale == 0 || v_scale == 0)) |
|
|
709 | { |
683 | if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
710 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
684 | if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
711 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
|
|
712 | } |
685 | |
713 | |
686 | if (dst_x > 0 || dst_y > 0 |
714 | if (dst_x > 0 || dst_y > 0 |
687 | || dst_x + dst_width < new_pmap_width |
715 | || dst_x + dst_width < new_pmap_width |
688 | || dst_y + dst_height < new_pmap_height) |
716 | || dst_y + dst_height < new_pmap_height) |
689 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
717 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
… | |
… | |
696 | if (result != background && result != original_asim) |
724 | if (result != background && result != original_asim) |
697 | destroy_asimage (&result); |
725 | destroy_asimage (&result); |
698 | |
726 | |
699 | XFreeGC (target->dpy, gc); |
727 | XFreeGC (target->dpy, gc); |
700 | TIMING_TEST_PRINT_RESULT (asim); |
728 | TIMING_TEST_PRINT_RESULT (asim); |
|
|
729 | |
|
|
730 | ret = true; |
701 | } |
731 | } |
702 | |
732 | |
703 | if (background) |
733 | if (background) |
704 | destroy_asimage (&background); |
734 | destroy_asimage (&background); |
705 | |
735 | |
706 | return true; |
736 | return ret; |
707 | } |
737 | } |
708 | # endif /* HAVE_AFTERIMAGE */ |
738 | # endif /* HAVE_AFTERIMAGE */ |
|
|
739 | |
|
|
740 | # ifdef HAVE_PIXBUF |
|
|
741 | bool |
|
|
742 | bgPixmap_t::render_image (unsigned long background_flags) |
|
|
743 | { |
|
|
744 | if (target == NULL) |
|
|
745 | return false; |
|
|
746 | |
|
|
747 | if (!pixbuf) |
|
|
748 | return false; |
|
|
749 | |
|
|
750 | // TODO: add alpha blending |
|
|
751 | if (background_flags) |
|
|
752 | return false; |
|
|
753 | |
|
|
754 | GdkPixbuf *result; |
|
|
755 | |
|
|
756 | int image_width = gdk_pixbuf_get_width (pixbuf); |
|
|
757 | int image_height = gdk_pixbuf_get_height (pixbuf); |
|
|
758 | |
|
|
759 | int target_width = target->szHint.width; |
|
|
760 | int target_height = target->szHint.height; |
|
|
761 | int new_pmap_width = target_width; |
|
|
762 | int new_pmap_height = target_height; |
|
|
763 | |
|
|
764 | int x = 0; |
|
|
765 | int y = 0; |
|
|
766 | int w = 0; |
|
|
767 | int h = 0; |
|
|
768 | |
|
|
769 | get_image_geometry (image_width, image_height, w, h, x, y); |
|
|
770 | |
|
|
771 | if (x >= target_width |
|
|
772 | || y >= target_height |
|
|
773 | || (w > 0 && x + w <= 0) |
|
|
774 | || (h > 0 && y + h <= 0)) |
|
|
775 | return false; |
|
|
776 | |
|
|
777 | result = pixbuf; |
|
|
778 | |
|
|
779 | if ((w > 0 && w != image_width) |
|
|
780 | || (h > 0 && h != image_height)) |
|
|
781 | { |
|
|
782 | result = gdk_pixbuf_scale_simple (pixbuf, |
|
|
783 | w > 0 ? w : image_width, |
|
|
784 | h > 0 ? h : image_height, |
|
|
785 | GDK_INTERP_BILINEAR); |
|
|
786 | } |
|
|
787 | |
|
|
788 | bool ret = false; |
|
|
789 | |
|
|
790 | if (result) |
|
|
791 | { |
|
|
792 | XGCValues gcv; |
|
|
793 | GC gc; |
|
|
794 | |
|
|
795 | image_width = gdk_pixbuf_get_width (result); |
|
|
796 | image_height = gdk_pixbuf_get_height (result); |
|
|
797 | |
|
|
798 | if (h_scale == 0 || v_scale == 0) |
|
|
799 | { |
|
|
800 | new_pmap_width = min (image_width, target_width); |
|
|
801 | new_pmap_height = min (image_height, target_height); |
|
|
802 | } |
|
|
803 | |
|
|
804 | if (pixmap) |
|
|
805 | { |
|
|
806 | if (pmap_width != new_pmap_width |
|
|
807 | || pmap_height != new_pmap_height |
|
|
808 | || pmap_depth != target->depth) |
|
|
809 | { |
|
|
810 | XFreePixmap (target->dpy, pixmap); |
|
|
811 | pixmap = None; |
|
|
812 | } |
|
|
813 | } |
|
|
814 | |
|
|
815 | if (pixmap == None) |
|
|
816 | { |
|
|
817 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
|
|
818 | pmap_width = new_pmap_width; |
|
|
819 | pmap_height = new_pmap_height; |
|
|
820 | pmap_depth = target->depth; |
|
|
821 | } |
|
|
822 | |
|
|
823 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
824 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
825 | |
|
|
826 | if (h_scale == 0 || v_scale == 0) |
|
|
827 | { |
|
|
828 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
|
|
829 | gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, |
|
|
830 | 0, 0, |
|
|
831 | 0, 0, |
|
|
832 | image_width, image_height, |
|
|
833 | XLIB_RGB_DITHER_NONE, |
|
|
834 | 0, 0); |
|
|
835 | |
|
|
836 | gcv.tile = tile; |
|
|
837 | gcv.fill_style = FillTiled; |
|
|
838 | gcv.ts_x_origin = x; |
|
|
839 | gcv.ts_y_origin = y; |
|
|
840 | XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
|
|
841 | |
|
|
842 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
843 | XFreePixmap (target->dpy, tile); |
|
|
844 | } |
|
|
845 | else |
|
|
846 | { |
|
|
847 | int src_x, src_y, dst_x, dst_y; |
|
|
848 | int dst_width, dst_height; |
|
|
849 | |
|
|
850 | src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width ); |
|
|
851 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
|
|
852 | |
|
|
853 | if (dst_x > 0 || dst_y > 0 |
|
|
854 | || dst_x + dst_width < new_pmap_width |
|
|
855 | || dst_y + dst_height < new_pmap_height) |
|
|
856 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
857 | |
|
|
858 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
|
|
859 | gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, |
|
|
860 | src_x, src_y, |
|
|
861 | dst_x, dst_y, |
|
|
862 | dst_width, dst_height, |
|
|
863 | XLIB_RGB_DITHER_NONE, |
|
|
864 | 0, 0); |
|
|
865 | } |
|
|
866 | |
|
|
867 | if (result != pixbuf) |
|
|
868 | g_object_unref (result); |
|
|
869 | |
|
|
870 | XFreeGC (target->dpy, gc); |
|
|
871 | |
|
|
872 | ret = true; |
|
|
873 | } |
|
|
874 | |
|
|
875 | return ret; |
|
|
876 | } |
|
|
877 | # endif /* HAVE_PIXBUF */ |
709 | |
878 | |
710 | bool |
879 | bool |
711 | bgPixmap_t::set_file (const char *file) |
880 | bgPixmap_t::set_file (const char *file) |
712 | { |
881 | { |
713 | assert (file); |
882 | assert (file); |
… | |
… | |
725 | |
894 | |
726 | # ifdef HAVE_AFTERIMAGE |
895 | # ifdef HAVE_AFTERIMAGE |
727 | if (!target->asimman) |
896 | if (!target->asimman) |
728 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
897 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
729 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
898 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
730 | return original_asim; |
899 | if (original_asim) |
|
|
900 | have_image = true; |
|
|
901 | return have_image; |
|
|
902 | # endif |
|
|
903 | |
|
|
904 | # ifdef HAVE_PIXBUF |
|
|
905 | pixbuf = gdk_pixbuf_new_from_file (file, NULL); |
|
|
906 | if (pixbuf) |
|
|
907 | have_image = true; |
|
|
908 | return have_image; |
731 | # endif |
909 | # endif |
732 | } |
910 | } |
733 | |
911 | |
734 | return false; |
912 | return false; |
735 | } |
913 | } |
… | |
… | |
755 | int changed = 0; |
933 | int changed = 0; |
756 | unsigned int hr, vr; |
934 | unsigned int hr, vr; |
757 | int junk; |
935 | int junk; |
758 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
936 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
759 | |
937 | |
760 | if (!(geom_flags&WidthValue)) |
938 | if (!(geom_flags & WidthValue)) |
761 | hr = 1; |
939 | hr = 1; |
762 | if (!(geom_flags&HeightValue)) |
940 | if (!(geom_flags & HeightValue)) |
763 | vr = hr; |
941 | vr = hr; |
764 | |
942 | |
765 | if (h_blurRadius != hr) |
943 | if (h_blurRadius != hr) |
766 | { |
944 | { |
767 | ++changed; |
945 | ++changed; |
… | |
… | |
777 | if (v_blurRadius == 0 && h_blurRadius == 0) |
955 | if (v_blurRadius == 0 && h_blurRadius == 0) |
778 | flags &= ~blurNeeded; |
956 | flags &= ~blurNeeded; |
779 | else |
957 | else |
780 | flags |= blurNeeded; |
958 | flags |= blurNeeded; |
781 | |
959 | |
782 | return (changed>0); |
960 | return (changed > 0); |
783 | } |
961 | } |
784 | |
962 | |
785 | static inline unsigned long |
963 | static inline unsigned long |
786 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
964 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
787 | { |
965 | { |
… | |
… | |
804 | flags |= bgPixmap_t::tintNeeded; |
982 | flags |= bgPixmap_t::tintNeeded; |
805 | else if (tint) |
983 | else if (tint) |
806 | { |
984 | { |
807 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
985 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
808 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
986 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
809 | { |
987 | { |
810 | flags |= bgPixmap_t::tintNeeded; |
988 | flags |= bgPixmap_t::tintNeeded; |
811 | } |
989 | } |
812 | } |
990 | } |
813 | |
991 | |
814 | if (flags & bgPixmap_t::tintNeeded) |
992 | if (flags & bgPixmap_t::tintNeeded) |
815 | { |
993 | { |
816 | if (flags & bgPixmap_t::tintWholesome) |
994 | if (flags & bgPixmap_t::tintWholesome) |
… | |
… | |
845 | { |
1023 | { |
846 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
1024 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
847 | |
1025 | |
848 | if (new_flags != (flags & tintFlags)) |
1026 | if (new_flags != (flags & tintFlags)) |
849 | { |
1027 | { |
850 | flags = (flags&~tintFlags)|new_flags; |
1028 | flags = (flags & ~tintFlags) | new_flags; |
851 | return true; |
1029 | return true; |
852 | } |
1030 | } |
853 | |
1031 | |
854 | return false; |
1032 | return false; |
855 | } |
1033 | } |
856 | |
1034 | |
… | |
… | |
941 | |
1119 | |
942 | attr.background_pixmap = ParentRelative; |
1120 | attr.background_pixmap = ParentRelative; |
943 | attr.backing_store = Always; |
1121 | attr.backing_store = Always; |
944 | attr.event_mask = ExposureMask; |
1122 | attr.event_mask = ExposureMask; |
945 | attr.override_redirect = True; |
1123 | attr.override_redirect = True; |
946 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
1124 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
947 | CopyFromParent, CopyFromParent, CopyFromParent, |
1125 | CopyFromParent, CopyFromParent, CopyFromParent, |
948 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
1126 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
949 | &attr); |
1127 | &attr); |
950 | |
1128 | |
951 | if (src != None) |
1129 | if (src != None) |
… | |
… | |
975 | XDestroyWindow (dpy, src); |
1153 | XDestroyWindow (dpy, src); |
976 | XUngrabServer (dpy); |
1154 | XUngrabServer (dpy); |
977 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
1155 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
978 | } |
1156 | } |
979 | |
1157 | |
980 | if (!success) |
1158 | if (!success) |
981 | { |
1159 | { |
982 | XFreePixmap (dpy, tiled_root_pmap); |
1160 | XFreePixmap (dpy, tiled_root_pmap); |
983 | tiled_root_pmap = None; |
1161 | tiled_root_pmap = None; |
984 | } |
1162 | } |
985 | else |
1163 | else |
986 | result |= transpPmapTiled; |
1164 | result |= transpPmapTiled; |
987 | } |
1165 | } |
988 | else |
1166 | else |
989 | { |
1167 | { |
990 | /* straightforward pixmap copy */ |
1168 | /* straightforward pixmap copy */ |
991 | gcv.tile = root_pixmap; |
1169 | gcv.tile = root_pixmap; |
… | |
… | |
1108 | # if DO_TIMING_TEST |
1286 | # if DO_TIMING_TEST |
1109 | XSync (dpy, False); |
1287 | XSync (dpy, False); |
1110 | # endif |
1288 | # endif |
1111 | # endif |
1289 | # endif |
1112 | } |
1290 | } |
1113 | } |
1291 | } |
1114 | } /* server side rendering completed */ |
1292 | } /* server side rendering completed */ |
1115 | |
1293 | |
1116 | if (pixmap) |
1294 | if (pixmap) |
1117 | XFreePixmap (dpy, pixmap); |
1295 | XFreePixmap (dpy, pixmap); |
1118 | |
1296 | |
… | |
… | |
1168 | /* we need to re-generate transparency pixmap in that case ! */ |
1346 | /* we need to re-generate transparency pixmap in that case ! */ |
1169 | background_flags = make_transparency_pixmap (); |
1347 | background_flags = make_transparency_pixmap (); |
1170 | if (background_flags == 0) |
1348 | if (background_flags == 0) |
1171 | return false; |
1349 | return false; |
1172 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1350 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1173 | && pmap_depth == target->depth) |
1351 | && pmap_depth == target->depth) |
1174 | flags = flags & ~isInvalid; |
1352 | flags = flags & ~isInvalid; |
1175 | } |
1353 | } |
1176 | # endif |
1354 | # endif |
1177 | |
1355 | |
1178 | # ifdef HAVE_AFTERIMAGE |
1356 | # ifdef BG_IMAGE_FROM_FILE |
1179 | if (original_asim |
1357 | if (have_image |
1180 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1358 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1181 | { |
1359 | { |
1182 | if (render_asim (background_flags)) |
1360 | if (render_image (background_flags)) |
1183 | flags = flags & ~isInvalid; |
1361 | flags = flags & ~isInvalid; |
1184 | } |
1362 | } |
1185 | # endif |
1363 | # endif |
1186 | |
1364 | |
1187 | XImage *result = NULL; |
1365 | XImage *result = NULL; |
1188 | |
1366 | |
1189 | if (background_flags && (flags & isInvalid)) |
1367 | if (background_flags && (flags & isInvalid)) |
1190 | { |
1368 | { |
1191 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1369 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
1370 | } |
1192 | |
1371 | |
|
|
1372 | if (result) |
|
|
1373 | { |
1193 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1374 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1194 | /* our own client-side tinting */ |
1375 | /* our own client-side tinting */ |
1195 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
1376 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
1196 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1377 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1197 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1378 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1198 | { |
1379 | { |
1199 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1380 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1200 | if (flags & tintSet) |
1381 | if (flags & tintSet) |
1201 | tint.get (c); |
1382 | tint.get (c); |
1202 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1383 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1203 | } |
1384 | } |
1204 | # endif |
1385 | # endif |
1205 | } |
|
|
1206 | |
1386 | |
1207 | if (result) |
|
|
1208 | { |
|
|
1209 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1387 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1210 | |
1388 | |
1211 | if (gc) |
1389 | if (gc) |
1212 | { |
1390 | { |
1213 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1391 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
… | |
… | |
1242 | |
1420 | |
1243 | XFreeGC (target->dpy, gc); |
1421 | XFreeGC (target->dpy, gc); |
1244 | flags = flags & ~isInvalid; |
1422 | flags = flags & ~isInvalid; |
1245 | } |
1423 | } |
1246 | |
1424 | |
1247 | XDestroyImage (result); |
1425 | XDestroyImage (result); |
1248 | } |
1426 | } |
1249 | |
1427 | |
1250 | if (flags & isInvalid) |
1428 | if (flags & isInvalid) |
1251 | { |
1429 | { |
1252 | if (pixmap != None) |
1430 | if (pixmap != None) |