… | |
… | |
20 | * You should have received a copy of the GNU General Public License |
20 | * You should have received a copy of the GNU General Public License |
21 | * along with this program; if not, write to the Free Software |
21 | * along with this program; if not, write to the Free Software |
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 | *---------------------------------------------------------------------*/ |
23 | *---------------------------------------------------------------------*/ |
24 | |
24 | |
25 | #include <cmath> |
25 | #include <math.h> |
26 | #include "../config.h" /* NECESSARY */ |
26 | #include "../config.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
27 | #include "rxvt.h" /* NECESSARY */ |
28 | |
28 | |
29 | #if XRENDER |
29 | #if XRENDER |
30 | # include <X11/extensions/Xrender.h> |
30 | # include <X11/extensions/Xrender.h> |
… | |
… | |
58 | # endif |
58 | # endif |
59 | |
59 | |
60 | void |
60 | void |
61 | rxvt_term::bg_destroy () |
61 | rxvt_term::bg_destroy () |
62 | { |
62 | { |
63 | #ifdef HAVE_AFTERIMAGE |
|
|
64 | if (original_asim) |
|
|
65 | safe_asimage_destroy (original_asim); |
|
|
66 | if (asv) |
|
|
67 | destroy_asvisual (asv, 0); |
|
|
68 | if (asimman) |
|
|
69 | destroy_image_manager (asimman, 0); |
|
|
70 | #endif |
|
|
71 | |
|
|
72 | #ifdef HAVE_PIXBUF |
63 | #ifdef HAVE_PIXBUF |
73 | if (pixbuf) |
64 | if (pixbuf) |
74 | g_object_unref (pixbuf); |
65 | g_object_unref (pixbuf); |
75 | #endif |
66 | #endif |
76 | |
67 | |
… | |
… | |
129 | |
120 | |
130 | return false; |
121 | return false; |
131 | } |
122 | } |
132 | |
123 | |
133 | # ifdef BG_IMAGE_FROM_FILE |
124 | # ifdef BG_IMAGE_FROM_FILE |
134 | static inline bool |
|
|
135 | check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) |
|
|
136 | { |
|
|
137 | if (geom_flags & flag) |
|
|
138 | { |
|
|
139 | if (new_value > 1000) |
|
|
140 | new_value = 1000; |
|
|
141 | if (new_value != scale) |
|
|
142 | { |
|
|
143 | scale = new_value; |
|
|
144 | return true; |
|
|
145 | } |
|
|
146 | } |
|
|
147 | return false; |
|
|
148 | } |
|
|
149 | |
|
|
150 | static inline bool |
|
|
151 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
|
|
152 | { |
|
|
153 | if (geom_flags & flag) |
|
|
154 | { |
|
|
155 | if (new_value < -100) |
|
|
156 | new_value = -100; |
|
|
157 | else if (new_value > 200) |
|
|
158 | new_value = 200; |
|
|
159 | if (new_value != align) |
|
|
160 | { |
|
|
161 | align = new_value; |
|
|
162 | return true; |
|
|
163 | } |
|
|
164 | } |
|
|
165 | return false; |
|
|
166 | } |
|
|
167 | |
|
|
168 | static inline int |
125 | static inline int |
169 | make_align_position (int align, int window_size, int image_size) |
126 | make_align_position (int align, int window_size, int image_size) |
170 | { |
127 | { |
171 | int diff = window_size - image_size; |
128 | int diff = window_size - image_size; |
172 | int smaller = min (image_size, window_size); |
129 | int smaller = min (image_size, window_size); |
173 | |
130 | |
174 | if (align >= 0 && align <= 100) |
131 | if (align >= 0 && align <= 100) |
175 | return diff * align / 100; |
132 | return diff * align / 100; |
176 | else if (align > 100 && align <= 200) |
133 | else if (align > 100) |
177 | return (align - 100) * smaller / 100 + window_size - smaller; |
134 | return (align - 100) * smaller / 100 + window_size - smaller; |
178 | else if (align >= -100 && align < 0) |
135 | else |
179 | return (align + 100) * smaller / 100 - image_size; |
136 | return (align + 100) * smaller / 100 - image_size; |
180 | return 0; |
|
|
181 | } |
137 | } |
182 | |
138 | |
183 | static inline int |
139 | static inline int |
184 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
140 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
185 | { |
141 | { |
… | |
… | |
200 | bool |
156 | bool |
201 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
157 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
202 | { |
158 | { |
203 | bool changed = false; |
159 | bool changed = false; |
204 | int geom_flags = 0; |
160 | int geom_flags = 0; |
205 | int x = 0, y = 0; |
161 | int x = h_align; |
|
|
162 | int y = v_align; |
206 | unsigned int w = 0, h = 0; |
163 | unsigned int w = h_scale; |
|
|
164 | unsigned int h = v_scale; |
207 | unsigned long new_flags = 0; |
165 | unsigned long new_flags = 0; |
208 | |
166 | |
209 | if (geom == NULL) |
167 | if (geom == NULL) |
210 | return false; |
168 | return false; |
211 | |
169 | |
… | |
… | |
320 | w = h = defaultScale; |
278 | w = h = defaultScale; |
321 | else if (!(geom_flags & HeightValue)) |
279 | else if (!(geom_flags & HeightValue)) |
322 | h = w; |
280 | h = w; |
323 | else if (!(geom_flags & WidthValue)) |
281 | else if (!(geom_flags & WidthValue)) |
324 | w = h; |
282 | w = h; |
325 | |
|
|
326 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
327 | } |
283 | } |
328 | |
284 | |
329 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
285 | min_it (w, 1000); |
330 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
286 | min_it (h, 1000); |
331 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
287 | clamp_it (x, -100, 200); |
332 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
288 | clamp_it (y, -100, 200); |
333 | |
289 | |
334 | if (new_flags != bg_flags) |
290 | if (bg_flags != new_flags |
|
|
291 | || h_scale != w |
|
|
292 | || v_scale != h |
|
|
293 | || h_align != x |
|
|
294 | || v_align != y) |
335 | { |
295 | { |
336 | bg_flags = new_flags; |
296 | bg_flags = new_flags; |
|
|
297 | h_scale = w; |
|
|
298 | v_scale = h; |
|
|
299 | h_align = x; |
|
|
300 | v_align = y; |
337 | changed = true; |
301 | changed = true; |
338 | } |
302 | } |
339 | |
303 | |
340 | return changed; |
304 | return changed; |
341 | } |
305 | } |
… | |
… | |
369 | { |
333 | { |
370 | x = make_align_position (h_align, target_width, w); |
334 | x = make_align_position (h_align, target_width, w); |
371 | y = make_align_position (v_align, target_height, h); |
335 | y = make_align_position (v_align, target_height, h); |
372 | } |
336 | } |
373 | |
337 | |
374 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
|
|
375 | if (!(bg_flags & BG_TILE) |
338 | if (!(bg_flags & BG_TILE) |
376 | || h_scale || v_scale |
339 | || h_scale || v_scale |
377 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
340 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
378 | || w > target_width || h > target_height) |
341 | || image_width > target_width || image_height > target_height) |
379 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
342 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
380 | } |
|
|
381 | |
|
|
382 | # ifdef HAVE_AFTERIMAGE |
|
|
383 | bool |
|
|
384 | rxvt_term::render_image (unsigned long tr_flags) |
|
|
385 | { |
|
|
386 | init_asv (); |
|
|
387 | |
|
|
388 | ASImage *background = NULL; |
|
|
389 | ARGB32 background_tint = TINT_LEAVE_SAME; |
|
|
390 | |
|
|
391 | # ifdef ENABLE_TRANSPARENCY |
|
|
392 | if (tr_flags) |
|
|
393 | background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100); |
|
|
394 | |
|
|
395 | if (tr_flags & BG_NEEDS_TINT) |
|
|
396 | { |
|
|
397 | ShadingInfo as_shade; |
|
|
398 | as_shade.shading = shade; |
|
|
399 | |
|
|
400 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
401 | if (bg_flags & BG_TINT_SET) |
|
|
402 | tint.get (c); |
|
|
403 | as_shade.tintColor.red = c.r; |
|
|
404 | as_shade.tintColor.green = c.g; |
|
|
405 | as_shade.tintColor.blue = c.b; |
|
|
406 | |
|
|
407 | background_tint = shading2tint32 (&as_shade); |
|
|
408 | } |
|
|
409 | |
|
|
410 | if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) |
|
|
411 | { |
|
|
412 | ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
413 | ASA_XImage, |
|
|
414 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
415 | if (tmp) |
|
|
416 | { |
|
|
417 | destroy_asimage (&background); |
|
|
418 | background = tmp; |
|
|
419 | } |
|
|
420 | } |
|
|
421 | # endif |
|
|
422 | |
|
|
423 | ASImage *result = 0; |
|
|
424 | |
|
|
425 | int target_width = szHint.width; |
|
|
426 | int target_height = szHint.height; |
|
|
427 | int new_pmap_width = target_width; |
|
|
428 | int new_pmap_height = target_height; |
|
|
429 | |
|
|
430 | int x = 0; |
|
|
431 | int y = 0; |
|
|
432 | int w = 0; |
|
|
433 | int h = 0; |
|
|
434 | |
|
|
435 | if (original_asim) |
|
|
436 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
|
|
437 | |
|
|
438 | if (!original_asim |
|
|
439 | || (!(bg_flags & BG_ROOT_ALIGN) |
|
|
440 | && (x >= target_width |
|
|
441 | || y >= target_height |
|
|
442 | || x + w <= 0 |
|
|
443 | || y + h <= 0))) |
|
|
444 | { |
|
|
445 | if (background) |
|
|
446 | { |
|
|
447 | new_pmap_width = background->width; |
|
|
448 | new_pmap_height = background->height; |
|
|
449 | result = background; |
|
|
450 | |
|
|
451 | if (background_tint != TINT_LEAVE_SAME) |
|
|
452 | { |
|
|
453 | ASImage *tmp = tile_asimage (asv, background, 0, 0, |
|
|
454 | target_width, target_height, background_tint, |
|
|
455 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
456 | if (tmp) |
|
|
457 | result = tmp; |
|
|
458 | } |
|
|
459 | } |
|
|
460 | else |
|
|
461 | new_pmap_width = new_pmap_height = 0; |
|
|
462 | } |
|
|
463 | else |
343 | else |
464 | { |
344 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
465 | result = original_asim; |
|
|
466 | |
|
|
467 | if (w != original_asim->width |
|
|
468 | || h != original_asim->height) |
|
|
469 | { |
|
|
470 | result = scale_asimage (asv, original_asim, |
|
|
471 | w, h, |
|
|
472 | ASA_XImage, |
|
|
473 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
474 | } |
|
|
475 | |
|
|
476 | if (background == NULL) |
|
|
477 | { |
|
|
478 | if (bg_flags & BG_TILE) |
|
|
479 | { |
|
|
480 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
481 | but there is no need to make it bigger than the window! */ |
|
|
482 | new_pmap_width = min (result->width, target_width); |
|
|
483 | new_pmap_height = min (result->height, target_height); |
|
|
484 | |
|
|
485 | /* we also need to tile our image in both directions */ |
|
|
486 | ASImage *tmp = tile_asimage (asv, result, |
|
|
487 | (int)result->width - x, |
|
|
488 | (int)result->height - y, |
|
|
489 | new_pmap_width, |
|
|
490 | new_pmap_height, |
|
|
491 | TINT_LEAVE_SAME, ASA_XImage, |
|
|
492 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
493 | if (tmp) |
|
|
494 | { |
|
|
495 | if (result != original_asim) |
|
|
496 | destroy_asimage (&result); |
|
|
497 | |
|
|
498 | result = tmp; |
|
|
499 | } |
|
|
500 | } |
|
|
501 | } |
|
|
502 | else |
|
|
503 | { |
|
|
504 | /* if blending background and image - pixmap has to be sized same as target window */ |
|
|
505 | ASImageLayer *layers = create_image_layers (2); |
|
|
506 | |
|
|
507 | layers[0].im = background; |
|
|
508 | layers[0].clip_width = target_width; |
|
|
509 | layers[0].clip_height = target_height; |
|
|
510 | layers[0].tint = background_tint; |
|
|
511 | layers[1].im = result; |
|
|
512 | |
|
|
513 | if (bg_flags & BG_TILE) |
|
|
514 | { |
|
|
515 | /* tile horizontally */ |
|
|
516 | while (x > 0) x -= (int)result->width; |
|
|
517 | layers[1].dst_x = x; |
|
|
518 | layers[1].clip_width = result->width+target_width; |
|
|
519 | } |
|
|
520 | else |
|
|
521 | { |
|
|
522 | /* clip horizontally */ |
|
|
523 | layers[1].dst_x = x; |
|
|
524 | layers[1].clip_width = result->width; |
|
|
525 | } |
|
|
526 | |
|
|
527 | if (bg_flags & BG_TILE) |
|
|
528 | { |
|
|
529 | while (y > 0) y -= (int)result->height; |
|
|
530 | layers[1].dst_y = y; |
|
|
531 | layers[1].clip_height = result->height + target_height; |
|
|
532 | } |
|
|
533 | else |
|
|
534 | { |
|
|
535 | layers[1].dst_y = y; |
|
|
536 | layers[1].clip_height = result->height; |
|
|
537 | } |
|
|
538 | |
|
|
539 | if (rs[Rs_blendtype]) |
|
|
540 | { |
|
|
541 | layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); |
|
|
542 | if (layers[1].merge_scanlines == NULL) |
|
|
543 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
544 | } |
|
|
545 | |
|
|
546 | ASImage *tmp = merge_layers (asv, layers, 2, target_width, target_height, |
|
|
547 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
548 | |
|
|
549 | if (tmp) |
|
|
550 | { |
|
|
551 | if (result != original_asim) |
|
|
552 | destroy_asimage (&result); |
|
|
553 | |
|
|
554 | result = tmp; |
|
|
555 | } |
|
|
556 | |
|
|
557 | free (layers); |
|
|
558 | } |
|
|
559 | } |
|
|
560 | |
|
|
561 | bool ret = false; |
|
|
562 | |
|
|
563 | if (result) |
|
|
564 | { |
|
|
565 | XGCValues gcv; |
|
|
566 | GC gc; |
|
|
567 | |
|
|
568 | /* create Pixmap */ |
|
|
569 | if (bg_pixmap == None |
|
|
570 | || bg_pmap_width != new_pmap_width |
|
|
571 | || bg_pmap_height != new_pmap_height) |
|
|
572 | { |
|
|
573 | if (bg_pixmap) |
|
|
574 | XFreePixmap (dpy, bg_pixmap); |
|
|
575 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
|
|
576 | bg_pmap_width = new_pmap_width; |
|
|
577 | bg_pmap_height = new_pmap_height; |
|
|
578 | } |
|
|
579 | /* fill with background color (if result's not completely overlapping it) */ |
|
|
580 | gcv.foreground = pix_colors[Color_bg]; |
|
|
581 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
|
|
582 | |
|
|
583 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
|
|
584 | int dst_width = result->width, dst_height = result->height; |
|
|
585 | if (background == NULL) |
|
|
586 | { |
|
|
587 | if (!(bg_flags & BG_TILE)) |
|
|
588 | { |
|
|
589 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
|
|
590 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
|
|
591 | } |
|
|
592 | |
|
|
593 | if (dst_x > 0 || dst_y > 0 |
|
|
594 | || dst_x + dst_width < new_pmap_width |
|
|
595 | || dst_y + dst_height < new_pmap_height) |
|
|
596 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
597 | } |
|
|
598 | |
|
|
599 | /* put result on pixmap */ |
|
|
600 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
|
|
601 | asimage2drawable (asv, bg_pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
|
|
602 | |
|
|
603 | if (result != background && result != original_asim) |
|
|
604 | destroy_asimage (&result); |
|
|
605 | |
|
|
606 | XFreeGC (dpy, gc); |
|
|
607 | |
|
|
608 | ret = true; |
|
|
609 | } |
|
|
610 | |
|
|
611 | if (background) |
|
|
612 | destroy_asimage (&background); |
|
|
613 | |
|
|
614 | return ret; |
|
|
615 | } |
345 | } |
616 | # endif /* HAVE_AFTERIMAGE */ |
|
|
617 | |
346 | |
618 | # ifdef HAVE_PIXBUF |
347 | # ifdef HAVE_PIXBUF |
619 | bool |
348 | bool |
620 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
349 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
621 | int src_x, int src_y, int dst_x, int dst_y, |
350 | int src_x, int src_y, int dst_x, int dst_y, |
… | |
… | |
698 | XDestroyImage (ximage); |
427 | XDestroyImage (ximage); |
699 | return true; |
428 | return true; |
700 | } |
429 | } |
701 | |
430 | |
702 | bool |
431 | bool |
703 | rxvt_term::render_image (unsigned long tr_flags) |
432 | rxvt_term::render_image (bool transparent) |
704 | { |
433 | { |
705 | if (!pixbuf) |
434 | if (!pixbuf) |
706 | return false; |
435 | return false; |
707 | |
436 | |
708 | if (tr_flags |
437 | if (transparent |
709 | && !(bg_flags & BG_HAS_RENDER)) |
438 | && !(bg_flags & BG_HAS_RENDER)) |
710 | return false; |
439 | return false; |
711 | |
440 | |
712 | GdkPixbuf *result; |
441 | GdkPixbuf *result; |
713 | |
442 | |
… | |
… | |
753 | Pixmap root_pmap; |
482 | Pixmap root_pmap; |
754 | |
483 | |
755 | image_width = gdk_pixbuf_get_width (result); |
484 | image_width = gdk_pixbuf_get_width (result); |
756 | image_height = gdk_pixbuf_get_height (result); |
485 | image_height = gdk_pixbuf_get_height (result); |
757 | |
486 | |
758 | if (tr_flags) |
487 | if (transparent) |
759 | { |
488 | { |
760 | root_pmap = bg_pixmap; |
489 | root_pmap = bg_pixmap; |
761 | bg_pixmap = None; |
490 | bg_pixmap = None; |
762 | } |
491 | } |
763 | else |
492 | else |
… | |
… | |
821 | dst_x, dst_y, |
550 | dst_x, dst_y, |
822 | dst_width, dst_height); |
551 | dst_width, dst_height); |
823 | } |
552 | } |
824 | |
553 | |
825 | #if XRENDER |
554 | #if XRENDER |
826 | if (tr_flags) |
555 | if (transparent) |
827 | { |
556 | { |
828 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
557 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
829 | |
558 | |
830 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
559 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
831 | |
560 | |
… | |
… | |
855 | } |
584 | } |
856 | |
585 | |
857 | if (result != pixbuf) |
586 | if (result != pixbuf) |
858 | g_object_unref (result); |
587 | g_object_unref (result); |
859 | |
588 | |
860 | if (tr_flags) |
589 | if (transparent) |
861 | XFreePixmap (dpy, root_pmap); |
590 | XFreePixmap (dpy, root_pmap); |
862 | |
591 | |
863 | return ret; |
592 | return ret; |
864 | } |
593 | } |
865 | # endif /* HAVE_PIXBUF */ |
594 | # endif /* HAVE_PIXBUF */ |
… | |
… | |
880 | memcpy (f, file, len); |
609 | memcpy (f, file, len); |
881 | f[len] = '\0'; |
610 | f[len] = '\0'; |
882 | file = f; |
611 | file = f; |
883 | } |
612 | } |
884 | |
613 | |
885 | # ifdef HAVE_AFTERIMAGE |
|
|
886 | if (!asimman) |
|
|
887 | asimman = create_generic_imageman (rs[Rs_path]); |
|
|
888 | ASImage *image = get_asimage (asimman, file, 0xFFFFFFFF, 100); |
|
|
889 | if (image) |
|
|
890 | { |
|
|
891 | if (original_asim) |
|
|
892 | safe_asimage_destroy (original_asim); |
|
|
893 | original_asim = image; |
|
|
894 | bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; |
|
|
895 | ret = true; |
|
|
896 | } |
|
|
897 | # endif |
|
|
898 | |
|
|
899 | # ifdef HAVE_PIXBUF |
614 | # ifdef HAVE_PIXBUF |
900 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
615 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
901 | if (image) |
616 | if (image) |
902 | { |
617 | { |
903 | if (pixbuf) |
618 | if (pixbuf) |
… | |
… | |
960 | { |
675 | { |
961 | changed = true; |
676 | changed = true; |
962 | v_blurRadius = vr; |
677 | v_blurRadius = vr; |
963 | } |
678 | } |
964 | |
679 | |
965 | if (h_blurRadius == 0 || v_blurRadius == 0) |
680 | if (h_blurRadius && v_blurRadius) |
|
|
681 | bg_flags |= BG_NEEDS_BLUR; |
|
|
682 | else |
966 | bg_flags &= ~BG_NEEDS_BLUR; |
683 | bg_flags &= ~BG_NEEDS_BLUR; |
967 | else |
|
|
968 | bg_flags |= BG_NEEDS_BLUR; |
|
|
969 | |
684 | |
970 | return changed; |
685 | return changed; |
971 | } |
686 | } |
972 | |
687 | |
973 | void |
688 | void |
974 | rxvt_term::set_tint_shade_flags () |
689 | rxvt_term::set_tint_shade_flags () |
975 | { |
690 | { |
|
|
691 | if (shade != 100 || (bg_flags & BG_TINT_SET)) |
|
|
692 | bg_flags |= BG_NEEDS_TINT; |
|
|
693 | else |
|
|
694 | bg_flags &= ~BG_NEEDS_TINT; |
|
|
695 | } |
|
|
696 | |
|
|
697 | bool |
|
|
698 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
|
|
699 | { |
|
|
700 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
|
|
701 | { |
|
|
702 | tint = new_tint; |
|
|
703 | bg_flags |= BG_TINT_SET; |
|
|
704 | |
976 | rgba c; |
705 | rgba c; |
977 | bool has_shade = shade != 100; |
|
|
978 | |
|
|
979 | bg_flags &= ~BG_TINT_FLAGS; |
|
|
980 | |
|
|
981 | if (bg_flags & BG_TINT_SET) |
|
|
982 | { |
|
|
983 | tint.get (c); |
706 | tint.get (c); |
984 | if (!has_shade |
|
|
985 | && (c.r <= 0x00ff || c.r >= 0xff00) |
707 | if ((c.r <= 0x00ff || c.r >= 0xff00) |
986 | && (c.g <= 0x00ff || c.g >= 0xff00) |
708 | && (c.g <= 0x00ff || c.g >= 0xff00) |
987 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
709 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
988 | bg_flags |= BG_TINT_BITAND; |
710 | bg_flags |= BG_TINT_BITAND; |
989 | } |
711 | else |
990 | |
|
|
991 | if (has_shade || (bg_flags & BG_TINT_SET)) |
|
|
992 | bg_flags |= BG_NEEDS_TINT; |
|
|
993 | } |
|
|
994 | |
|
|
995 | bool |
|
|
996 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
|
|
997 | { |
|
|
998 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
|
|
999 | { |
|
|
1000 | tint = new_tint; |
|
|
1001 | bg_flags |= BG_TINT_SET; |
712 | bg_flags &= ~BG_TINT_BITAND; |
|
|
713 | |
1002 | set_tint_shade_flags (); |
714 | set_tint_shade_flags (); |
1003 | return true; |
715 | return true; |
1004 | } |
716 | } |
1005 | |
717 | |
1006 | return false; |
718 | return false; |
… | |
… | |
1116 | bool |
828 | bool |
1117 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
829 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1118 | { |
830 | { |
1119 | bool ret = false; |
831 | bool ret = false; |
1120 | |
832 | |
1121 | if (bg_flags & BG_TINT_BITAND) |
833 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
1122 | { |
834 | { |
1123 | XGCValues gcv; |
835 | XGCValues gcv; |
1124 | GC gc; |
836 | GC gc; |
1125 | |
837 | |
1126 | /* In this case we can tint image server-side getting significant |
838 | /* In this case we can tint image server-side getting significant |
… | |
… | |
1207 | /* |
919 | /* |
1208 | * Builds a pixmap of the same size as the terminal window that contains |
920 | * Builds a pixmap of the same size as the terminal window that contains |
1209 | * the tiled portion of the root pixmap that is supposed to be covered by |
921 | * the tiled portion of the root pixmap that is supposed to be covered by |
1210 | * our window. |
922 | * our window. |
1211 | */ |
923 | */ |
1212 | unsigned long |
924 | bool |
1213 | rxvt_term::make_transparency_pixmap () |
925 | rxvt_term::make_transparency_pixmap () |
1214 | { |
926 | { |
1215 | unsigned long result = 0; |
927 | bool ret = false; |
1216 | |
928 | |
1217 | /* root dimensions may change from call to call - but Display structure should |
929 | /* root dimensions may change from call to call - but Display structure should |
1218 | * be always up-to-date, so let's use it : |
930 | * be always up-to-date, so let's use it : |
1219 | */ |
931 | */ |
1220 | int screen = display->screen; |
932 | int screen = display->screen; |
… | |
… | |
1301 | gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1013 | gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1302 | |
1014 | |
1303 | if (gc) |
1015 | if (gc) |
1304 | { |
1016 | { |
1305 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1017 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1306 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1018 | ret = true; |
|
|
1019 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1307 | |
1020 | |
1308 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1021 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1309 | { |
1022 | { |
1310 | if (bg_flags & BG_NEEDS_BLUR) |
1023 | if (bg_flags & BG_NEEDS_BLUR) |
1311 | { |
1024 | { |
1312 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1025 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1313 | result &= ~BG_NEEDS_BLUR; |
1026 | tr_flags &= ~BG_NEEDS_BLUR; |
1314 | } |
1027 | } |
1315 | if (bg_flags & BG_NEEDS_TINT) |
1028 | if (bg_flags & BG_NEEDS_TINT) |
1316 | { |
1029 | { |
1317 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1030 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1318 | result &= ~BG_NEEDS_TINT; |
1031 | tr_flags &= ~BG_NEEDS_TINT; |
1319 | } |
1032 | } |
1320 | # ifndef HAVE_AFTERIMAGE |
|
|
1321 | if (result & BG_NEEDS_TINT) |
1033 | if (tr_flags & BG_NEEDS_TINT) |
1322 | { |
1034 | { |
1323 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1035 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1324 | if (ximage) |
1036 | if (ximage) |
1325 | { |
1037 | { |
1326 | /* our own client-side tinting */ |
1038 | /* our own client-side tinting */ |
… | |
… | |
1328 | |
1040 | |
1329 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1041 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1330 | XDestroyImage (ximage); |
1042 | XDestroyImage (ximage); |
1331 | } |
1043 | } |
1332 | } |
1044 | } |
1333 | # endif |
|
|
1334 | } /* server side rendering completed */ |
1045 | } /* server side rendering completed */ |
1335 | |
1046 | |
1336 | XFreeGC (dpy, gc); |
1047 | XFreeGC (dpy, gc); |
1337 | } |
1048 | } |
1338 | |
1049 | |
1339 | if (recoded_root_pmap != root_pixmap) |
1050 | if (recoded_root_pmap != root_pixmap) |
1340 | XFreePixmap (dpy, recoded_root_pmap); |
1051 | XFreePixmap (dpy, recoded_root_pmap); |
1341 | |
1052 | |
1342 | return result; |
1053 | return ret; |
1343 | } |
1054 | } |
1344 | |
1055 | |
1345 | void |
1056 | void |
1346 | rxvt_term::bg_set_root_pixmap () |
1057 | rxvt_term::bg_set_root_pixmap () |
1347 | { |
1058 | { |
… | |
… | |
1354 | # endif /* ENABLE_TRANSPARENCY */ |
1065 | # endif /* ENABLE_TRANSPARENCY */ |
1355 | |
1066 | |
1356 | bool |
1067 | bool |
1357 | rxvt_term::bg_render () |
1068 | rxvt_term::bg_render () |
1358 | { |
1069 | { |
1359 | unsigned long tr_flags = 0; |
1070 | bool transparent = false; |
1360 | |
1071 | |
1361 | bg_invalidate (); |
1072 | bg_invalidate (); |
1362 | # ifdef ENABLE_TRANSPARENCY |
1073 | # ifdef ENABLE_TRANSPARENCY |
1363 | if (bg_flags & BG_IS_TRANSPARENT) |
1074 | if (bg_flags & BG_IS_TRANSPARENT) |
1364 | { |
1075 | { |
1365 | /* we need to re-generate transparency pixmap in that case ! */ |
1076 | /* we need to re-generate transparency pixmap in that case ! */ |
1366 | tr_flags = make_transparency_pixmap (); |
1077 | transparent = make_transparency_pixmap (); |
1367 | if (tr_flags == 0) |
1078 | if (transparent) |
1368 | return false; |
|
|
1369 | bg_flags |= BG_IS_VALID; |
1079 | bg_flags |= BG_IS_VALID; |
1370 | } |
1080 | } |
1371 | # endif |
1081 | # endif |
1372 | |
1082 | |
1373 | # ifdef BG_IMAGE_FROM_FILE |
1083 | # ifdef BG_IMAGE_FROM_FILE |
1374 | if ((bg_flags & BG_IS_FROM_FILE) |
1084 | if (bg_flags & BG_IS_FROM_FILE) |
1375 | || (tr_flags & BG_EFFECTS_FLAGS)) |
|
|
1376 | { |
1085 | { |
1377 | if (render_image (tr_flags)) |
1086 | if (render_image (transparent)) |
1378 | bg_flags |= BG_IS_VALID; |
1087 | bg_flags |= BG_IS_VALID; |
1379 | } |
1088 | } |
1380 | # endif |
1089 | # endif |
1381 | |
1090 | |
1382 | if (!(bg_flags & BG_IS_VALID)) |
1091 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1420 | #endif |
1129 | #endif |
1421 | } |
1130 | } |
1422 | |
1131 | |
1423 | #endif /* HAVE_BG_PIXMAP */ |
1132 | #endif /* HAVE_BG_PIXMAP */ |
1424 | |
1133 | |
1425 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1134 | #ifdef ENABLE_TRANSPARENCY |
1426 | /* based on code from aterm-0.4.2 */ |
1135 | /* based on code from aterm-0.4.2 */ |
1427 | |
1136 | |
1428 | static inline void |
1137 | static inline void |
1429 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1138 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1430 | { |
1139 | { |
… | |
… | |
1576 | } |
1285 | } |
1577 | } |
1286 | } |
1578 | |
1287 | |
1579 | free (lookup); |
1288 | free (lookup); |
1580 | } |
1289 | } |
1581 | #endif /* defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) */ |
1290 | #endif /* ENABLE_TRANSPARENCY */ |