… | |
… | |
58 | # endif |
58 | # endif |
59 | |
59 | |
60 | void |
60 | void |
61 | rxvt_term::bg_destroy () |
61 | rxvt_term::bg_destroy () |
62 | { |
62 | { |
|
|
63 | # ifdef BG_IMAGE_FROM_FILE |
|
|
64 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
|
|
65 | bg_image->destroy (); |
|
|
66 | # endif |
|
|
67 | |
63 | if (bg_pixmap) |
68 | if (bg_pixmap) |
64 | XFreePixmap (dpy, bg_pixmap); |
69 | XFreePixmap (dpy, bg_pixmap); |
65 | } |
70 | } |
66 | |
71 | |
67 | bool |
72 | bool |
… | |
… | |
85 | if (bg_flags & BG_IS_TRANSPARENT) |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
86 | return true; |
91 | return true; |
87 | # endif |
92 | # endif |
88 | |
93 | |
89 | # ifdef BG_IMAGE_FROM_FILE |
94 | # ifdef BG_IMAGE_FROM_FILE |
90 | if (bg_image.flags & IM_IS_SET) |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
91 | { |
96 | { |
92 | if ((bg_image.flags & IM_IS_SIZE_SENSITIVE) |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
93 | || bg_image.width () > szHint.width |
98 | || bg_image->width () > szHint.width |
94 | || bg_image.height () > szHint.height) |
99 | || bg_image->height () > szHint.height) |
95 | return true; |
100 | return true; |
96 | } |
101 | } |
97 | # endif |
102 | # endif |
98 | |
103 | |
99 | return false; |
104 | return false; |
… | |
… | |
106 | if (bg_flags & BG_IS_TRANSPARENT) |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
107 | return true; |
112 | return true; |
108 | # endif |
113 | # endif |
109 | |
114 | |
110 | # ifdef BG_IMAGE_FROM_FILE |
115 | # ifdef BG_IMAGE_FROM_FILE |
111 | if (bg_image.flags & IM_IS_SET) |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
112 | { |
117 | { |
113 | if (bg_image.flags & IM_ROOT_ALIGN) |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
114 | return true; |
119 | return true; |
115 | } |
120 | } |
116 | # endif |
121 | # endif |
117 | |
122 | |
118 | return false; |
123 | return false; |
… | |
… | |
145 | |
150 | |
146 | min_it (dst_size, target_size - dst_pos); |
151 | min_it (dst_size, target_size - dst_pos); |
147 | return src_pos; |
152 | return src_pos; |
148 | } |
153 | } |
149 | |
154 | |
|
|
155 | static void |
|
|
156 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
|
|
157 | { |
|
|
158 | if (!strcasecmp (style, "tiled")) |
|
|
159 | { |
|
|
160 | flags = IM_TILE; |
|
|
161 | w = h = noScale; |
|
|
162 | x = y = 0; |
|
|
163 | } |
|
|
164 | else if (!strcasecmp (style, "aspect-stretched")) |
|
|
165 | { |
|
|
166 | flags = IM_KEEP_ASPECT; |
|
|
167 | w = h = windowScale; |
|
|
168 | x = y = centerAlign; |
|
|
169 | } |
|
|
170 | else if (!strcasecmp (style, "stretched")) |
|
|
171 | { |
|
|
172 | flags = 0; |
|
|
173 | w = h = windowScale; |
|
|
174 | x = y = centerAlign; |
|
|
175 | } |
|
|
176 | else if (!strcasecmp (style, "centered")) |
|
|
177 | { |
|
|
178 | flags = 0; |
|
|
179 | w = h = noScale; |
|
|
180 | x = y = centerAlign; |
|
|
181 | } |
|
|
182 | else if (!strcasecmp (style, "root-tiled")) |
|
|
183 | { |
|
|
184 | flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
185 | w = h = noScale; |
|
|
186 | x = y = 0; |
|
|
187 | } |
|
|
188 | } |
|
|
189 | |
150 | bool |
190 | bool |
151 | rxvt_image::set_geometry (const char *geom, bool update) |
191 | rxvt_image::set_geometry (const char *geom, bool update) |
152 | { |
192 | { |
153 | bool changed = false; |
193 | bool changed = false; |
154 | int geom_flags = 0; |
194 | int geom_flags = 0; |
155 | int x = h_align; |
195 | int x = h_align; |
156 | int y = v_align; |
196 | int y = v_align; |
157 | unsigned int w = h_scale; |
197 | unsigned int w = h_scale; |
158 | unsigned int h = v_scale; |
198 | unsigned int h = v_scale; |
159 | unsigned long new_flags = 0; |
199 | uint8_t new_flags = 0; |
160 | |
200 | |
161 | if (geom == NULL) |
201 | if (geom == NULL) |
162 | return false; |
202 | return false; |
163 | |
203 | |
164 | if (geom[0]) |
204 | if (geom[0]) |
165 | { |
205 | { |
166 | char **arr = rxvt_strsplit (':', geom); |
206 | char **arr = rxvt_strsplit (':', geom); |
167 | |
207 | |
168 | for (int i = 0; arr[i]; i++) |
208 | for (int i = 0; arr[i]; i++) |
169 | { |
209 | { |
170 | if (!strcasecmp (arr[i], "style=tiled")) |
210 | if (!strncasecmp (arr[i], "style=", 6)) |
171 | { |
211 | { |
172 | new_flags = IM_TILE; |
212 | parse_style (arr[i] + 6, x, y, w, h, new_flags); |
173 | w = h = noScale; |
|
|
174 | x = y = 0; |
|
|
175 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
213 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
176 | } |
|
|
177 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
|
|
178 | { |
|
|
179 | new_flags = IM_KEEP_ASPECT; |
|
|
180 | w = h = windowScale; |
|
|
181 | x = y = centerAlign; |
|
|
182 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
183 | } |
|
|
184 | else if (!strcasecmp (arr[i], "style=stretched")) |
|
|
185 | { |
|
|
186 | new_flags = 0; |
|
|
187 | w = h = windowScale; |
|
|
188 | geom_flags = WidthValue|HeightValue; |
|
|
189 | } |
|
|
190 | else if (!strcasecmp (arr[i], "style=centered")) |
|
|
191 | { |
|
|
192 | new_flags = 0; |
|
|
193 | w = h = noScale; |
|
|
194 | x = y = centerAlign; |
|
|
195 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
196 | } |
|
|
197 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
|
|
198 | { |
|
|
199 | new_flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
200 | w = h = noScale; |
|
|
201 | geom_flags = WidthValue|HeightValue; |
|
|
202 | } |
214 | } |
203 | else if (!strcasecmp (arr[i], "op=tile")) |
215 | else if (!strcasecmp (arr[i], "op=tile")) |
204 | new_flags |= IM_TILE; |
216 | new_flags |= IM_TILE; |
205 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
217 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
206 | new_flags |= IM_KEEP_ASPECT; |
218 | new_flags |= IM_KEEP_ASPECT; |
… | |
… | |
274 | h = w; |
286 | h = w; |
275 | else if (!(geom_flags & WidthValue)) |
287 | else if (!(geom_flags & WidthValue)) |
276 | w = h; |
288 | w = h; |
277 | } |
289 | } |
278 | |
290 | |
279 | min_it (w, 1000); |
|
|
280 | min_it (h, 1000); |
|
|
281 | clamp_it (x, -100, 200); |
291 | clamp_it (x, -100, 200); |
282 | clamp_it (y, -100, 200); |
292 | clamp_it (y, -100, 200); |
283 | |
293 | |
284 | if (flags != new_flags |
294 | if (flags != new_flags |
285 | || h_scale != w |
295 | || h_scale != w |
… | |
… | |
310 | { |
320 | { |
311 | int image_width = image.width (); |
321 | int image_width = image.width (); |
312 | int image_height = image.height (); |
322 | int image_height = image.height (); |
313 | int target_width = szHint.width; |
323 | int target_width = szHint.width; |
314 | int target_height = szHint.height; |
324 | int target_height = szHint.height; |
|
|
325 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
326 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
315 | |
327 | |
316 | w = image.h_scale * target_width / 100; |
328 | w = h_scale * target_width / 100; |
317 | h = image.v_scale * target_height / 100; |
329 | h = v_scale * target_height / 100; |
318 | |
330 | |
319 | if (image.flags & IM_KEEP_ASPECT) |
331 | if (image.flags & IM_KEEP_ASPECT) |
320 | { |
332 | { |
321 | float scale = (float)w / image_width; |
333 | float scale = (float)w / image_width; |
322 | min_it (scale, (float)h / image_height); |
334 | min_it (scale, (float)h / image_height); |
… | |
… | |
341 | |
353 | |
342 | # ifdef HAVE_PIXBUF |
354 | # ifdef HAVE_PIXBUF |
343 | bool |
355 | bool |
344 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
356 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
345 | int src_x, int src_y, int dst_x, int dst_y, |
357 | int src_x, int src_y, int dst_x, int dst_y, |
346 | unsigned int width, unsigned int height) |
358 | unsigned int width, unsigned int height, bool argb) |
347 | { |
359 | { |
348 | XImage *ximage; |
360 | XImage *ximage; |
349 | char *line; |
361 | char *line; |
350 | int width_r, width_g, width_b, width_a; |
362 | int width_r, width_g, width_b, width_a; |
351 | int sh_r, sh_g, sh_b, sh_a; |
363 | int sh_r, sh_g, sh_b, sh_a; |
352 | uint32_t alpha_mask; |
364 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
353 | int rowstride; |
365 | int rowstride; |
354 | int channels; |
366 | int channels; |
355 | unsigned char *row; |
367 | unsigned char *row; |
356 | |
368 | |
357 | if (visual->c_class != TrueColor) |
369 | if (visual->c_class != TrueColor) |
358 | return false; |
370 | return false; |
359 | |
371 | |
|
|
372 | if (argb) |
|
|
373 | { |
|
|
374 | red_mask = 0xff << 16; |
|
|
375 | green_mask = 0xff << 8; |
|
|
376 | blue_mask = 0xff; |
|
|
377 | alpha_mask = 0xff << 24; |
|
|
378 | } |
|
|
379 | else |
|
|
380 | { |
|
|
381 | red_mask = visual->red_mask; |
|
|
382 | green_mask = visual->green_mask; |
|
|
383 | blue_mask = visual->blue_mask; |
360 | #if XRENDER |
384 | #if XRENDER |
361 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
385 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
362 | if (format) |
386 | if (format) |
363 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
387 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
364 | else |
388 | else |
365 | #endif |
389 | #endif |
366 | alpha_mask = 0; |
390 | alpha_mask = 0; |
|
|
391 | } |
367 | |
392 | |
368 | width_r = ecb_popcount32 (visual->red_mask); |
393 | width_r = ecb_popcount32 (red_mask); |
369 | width_g = ecb_popcount32 (visual->green_mask); |
394 | width_g = ecb_popcount32 (green_mask); |
370 | width_b = ecb_popcount32 (visual->blue_mask); |
395 | width_b = ecb_popcount32 (blue_mask); |
371 | width_a = ecb_popcount32 (alpha_mask); |
396 | width_a = ecb_popcount32 (alpha_mask); |
372 | |
397 | |
373 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
398 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
374 | return false; |
399 | return false; |
375 | |
400 | |
376 | sh_r = ecb_ctz32 (visual->red_mask); |
401 | sh_r = ecb_ctz32 (red_mask); |
377 | sh_g = ecb_ctz32 (visual->green_mask); |
402 | sh_g = ecb_ctz32 (green_mask); |
378 | sh_b = ecb_ctz32 (visual->blue_mask); |
403 | sh_b = ecb_ctz32 (blue_mask); |
379 | sh_a = ecb_ctz32 (alpha_mask); |
404 | sh_a = ecb_ctz32 (alpha_mask); |
380 | |
405 | |
381 | if (width > 32767 || height > 32767) |
406 | if (width > 32767 || height > 32767) |
382 | return false; |
407 | return false; |
383 | |
408 | |
384 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0, |
409 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
385 | width, height, 32, 0); |
410 | width, height, 32, 0); |
386 | if (!ximage) |
411 | if (!ximage) |
387 | return false; |
412 | return false; |
388 | |
413 | |
389 | if (height > INT_MAX / ximage->bytes_per_line |
414 | if (height > INT_MAX / ximage->bytes_per_line |
… | |
… | |
452 | XDestroyImage (ximage); |
477 | XDestroyImage (ximage); |
453 | return true; |
478 | return true; |
454 | } |
479 | } |
455 | |
480 | |
456 | bool |
481 | bool |
457 | rxvt_term::render_image (rxvt_image &image, bool transparent) |
482 | rxvt_term::render_image (rxvt_image &image) |
458 | { |
483 | { |
459 | GdkPixbuf *pixbuf = image.pixbuf; |
484 | GdkPixbuf *pixbuf = image.pixbuf; |
460 | if (!pixbuf) |
485 | if (!pixbuf) |
461 | return false; |
486 | return false; |
462 | |
487 | |
463 | if (transparent |
488 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
489 | |
|
|
490 | if (need_blend |
464 | && !(bg_flags & BG_HAS_RENDER)) |
491 | && !(bg_flags & BG_HAS_RENDER)) |
465 | return false; |
492 | return false; |
466 | |
493 | |
467 | GdkPixbuf *result; |
494 | GdkPixbuf *result; |
468 | |
495 | |
… | |
… | |
503 | |
530 | |
504 | bool ret = false; |
531 | bool ret = false; |
505 | |
532 | |
506 | XGCValues gcv; |
533 | XGCValues gcv; |
507 | GC gc; |
534 | GC gc; |
508 | Pixmap root_pmap; |
535 | Pixmap tmp_pixmap; |
509 | |
536 | |
510 | image_width = gdk_pixbuf_get_width (result); |
537 | image_width = gdk_pixbuf_get_width (result); |
511 | image_height = gdk_pixbuf_get_height (result); |
538 | image_height = gdk_pixbuf_get_height (result); |
512 | |
539 | |
513 | if (transparent) |
540 | if (need_blend) |
514 | { |
541 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
515 | root_pmap = bg_pixmap; |
|
|
516 | bg_pixmap = None; |
|
|
517 | } |
|
|
518 | else |
542 | else |
519 | { |
543 | { |
|
|
544 | // optimise bg pixmap size when tiling, but only if there are no |
|
|
545 | // other pixbufs to render. Otherwise, the bg pixmap size must |
|
|
546 | // be equal to the window size. |
520 | if (image.flags & IM_TILE) |
547 | if ((image.flags & IM_TILE) |
|
|
548 | && image_vec.size () == 1) |
521 | { |
549 | { |
522 | new_pmap_width = min (image_width, target_width); |
550 | new_pmap_width = min (image_width, target_width); |
523 | new_pmap_height = min (image_height, target_height); |
551 | new_pmap_height = min (image_height, target_height); |
524 | } |
552 | } |
525 | } |
|
|
526 | |
553 | |
527 | if (bg_pixmap == None |
554 | if (bg_pixmap == None |
528 | || bg_pmap_width != new_pmap_width |
555 | || bg_pmap_width != new_pmap_width |
529 | || bg_pmap_height != new_pmap_height) |
556 | || bg_pmap_height != new_pmap_height) |
530 | { |
557 | { |
531 | if (bg_pixmap) |
558 | if (bg_pixmap) |
532 | XFreePixmap (dpy, bg_pixmap); |
559 | XFreePixmap (dpy, bg_pixmap); |
533 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
560 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
534 | bg_pmap_width = new_pmap_width; |
561 | bg_pmap_width = new_pmap_width; |
535 | bg_pmap_height = new_pmap_height; |
562 | bg_pmap_height = new_pmap_height; |
|
|
563 | } |
|
|
564 | |
|
|
565 | tmp_pixmap = bg_pixmap; |
536 | } |
566 | } |
537 | |
567 | |
538 | gcv.foreground = pix_colors[Color_bg]; |
568 | gcv.foreground = pix_colors[Color_bg]; |
539 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
569 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
540 | |
570 | |
541 | if (gc) |
571 | if (gc) |
542 | { |
572 | { |
543 | if (image.flags & IM_TILE) |
573 | if (image.flags & IM_TILE) |
544 | { |
574 | { |
545 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
575 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
546 | pixbuf_to_pixmap (result, tile, gc, |
576 | pixbuf_to_pixmap (result, tile, gc, |
547 | 0, 0, |
577 | 0, 0, |
548 | 0, 0, |
578 | 0, 0, |
549 | image_width, image_height); |
579 | image_width, image_height, need_blend); |
550 | |
580 | |
551 | gcv.tile = tile; |
581 | gcv.tile = tile; |
552 | gcv.fill_style = FillTiled; |
582 | gcv.fill_style = FillTiled; |
553 | gcv.ts_x_origin = x; |
583 | gcv.ts_x_origin = x; |
554 | gcv.ts_y_origin = y; |
584 | gcv.ts_y_origin = y; |
555 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
585 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
556 | |
586 | |
557 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
587 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
558 | XFreePixmap (dpy, tile); |
588 | XFreePixmap (dpy, tile); |
559 | } |
589 | } |
560 | else |
590 | else |
561 | { |
591 | { |
562 | int src_x, src_y, dst_x, dst_y; |
592 | int src_x, src_y, dst_x, dst_y; |
… | |
… | |
566 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
596 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
567 | |
597 | |
568 | if (dst_x > 0 || dst_y > 0 |
598 | if (dst_x > 0 || dst_y > 0 |
569 | || dst_x + dst_width < new_pmap_width |
599 | || dst_x + dst_width < new_pmap_width |
570 | || dst_y + dst_height < new_pmap_height) |
600 | || dst_y + dst_height < new_pmap_height) |
571 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
601 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
572 | |
602 | |
573 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
603 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
574 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
604 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
575 | src_x, src_y, |
605 | src_x, src_y, |
576 | dst_x, dst_y, |
606 | dst_x, dst_y, |
577 | dst_width, dst_height); |
607 | dst_width, dst_height, need_blend); |
578 | } |
608 | } |
579 | |
609 | |
580 | #if XRENDER |
610 | #if XRENDER |
581 | if (transparent) |
611 | if (need_blend) |
582 | { |
612 | { |
|
|
613 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
583 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
614 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
584 | |
615 | |
585 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
616 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
586 | |
617 | |
587 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
618 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
588 | |
619 | |
589 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
620 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
590 | |
621 | |
591 | XRenderColor mask_c; |
622 | XRenderColor mask_c; |
592 | |
623 | |
593 | mask_c.alpha = 0x8000; |
624 | mask_c.alpha = image.alpha; |
594 | mask_c.red = |
625 | mask_c.red = |
595 | mask_c.green = |
626 | mask_c.green = |
596 | mask_c.blue = 0; |
627 | mask_c.blue = 0; |
597 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
628 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
598 | |
629 | |
… | |
… | |
610 | } |
641 | } |
611 | |
642 | |
612 | if (result != pixbuf) |
643 | if (result != pixbuf) |
613 | g_object_unref (result); |
644 | g_object_unref (result); |
614 | |
645 | |
615 | if (transparent) |
646 | if (need_blend) |
616 | XFreePixmap (dpy, root_pmap); |
647 | XFreePixmap (dpy, tmp_pixmap); |
617 | |
648 | |
618 | return ret; |
649 | return ret; |
619 | } |
650 | } |
620 | # endif /* HAVE_PIXBUF */ |
651 | # endif /* HAVE_PIXBUF */ |
621 | |
652 | |
|
|
653 | # ifndef NO_RESOURCES |
|
|
654 | static int |
|
|
655 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
656 | XrmBindingList bindings ecb_unused, |
|
|
657 | XrmQuarkList quarks, |
|
|
658 | XrmRepresentation *type ecb_unused, |
|
|
659 | XrmValue *value, |
|
|
660 | XPointer closure ecb_unused) |
|
|
661 | { |
|
|
662 | int size; |
|
|
663 | |
|
|
664 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
665 | ; |
|
|
666 | |
|
|
667 | if (size >= 2) |
|
|
668 | { |
|
|
669 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
670 | if (id >= 1) |
|
|
671 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
672 | } |
|
|
673 | return False; |
|
|
674 | } |
|
|
675 | |
|
|
676 | void |
|
|
677 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
678 | { |
|
|
679 | if (image_vec.size () < id + 1) |
|
|
680 | image_vec.resize (id + 1); |
|
|
681 | |
|
|
682 | rxvt_image *image = &image_vec[id]; |
|
|
683 | } |
|
|
684 | # endif |
|
|
685 | |
|
|
686 | rxvt_image::rxvt_image () |
|
|
687 | { |
|
|
688 | alpha = |
|
|
689 | flags = |
|
|
690 | h_scale = |
|
|
691 | v_scale = |
|
|
692 | h_align = |
|
|
693 | v_align = 0; |
|
|
694 | |
|
|
695 | # ifdef HAVE_PIXBUF |
|
|
696 | pixbuf = 0; |
|
|
697 | # endif |
|
|
698 | } |
|
|
699 | |
622 | bool |
700 | bool |
623 | rxvt_image::set_file (const char *file) |
701 | rxvt_image::set_file_geometry (const char *file) |
624 | { |
702 | { |
625 | if (!file || !*file) |
703 | if (!file || !*file) |
626 | return false; |
704 | return false; |
627 | |
705 | |
628 | bool ret = false; |
|
|
629 | const char *p = strchr (file, ';'); |
706 | const char *p = strchr (file, ';'); |
630 | |
707 | |
631 | if (p) |
708 | if (p) |
632 | { |
709 | { |
633 | size_t len = p - file; |
710 | size_t len = p - file; |
… | |
… | |
635 | memcpy (f, file, len); |
712 | memcpy (f, file, len); |
636 | f[len] = '\0'; |
713 | f[len] = '\0'; |
637 | file = f; |
714 | file = f; |
638 | } |
715 | } |
639 | |
716 | |
|
|
717 | bool ret = set_file (file); |
|
|
718 | alpha = 0x8000; |
|
|
719 | if (ret && p) |
|
|
720 | set_geometry (p + 1); |
|
|
721 | return ret; |
|
|
722 | } |
|
|
723 | |
|
|
724 | bool |
|
|
725 | rxvt_image::set_file (const char *file) |
|
|
726 | { |
|
|
727 | bool ret = false; |
|
|
728 | |
640 | # ifdef HAVE_PIXBUF |
729 | # ifdef HAVE_PIXBUF |
641 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
730 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
642 | if (image) |
731 | if (image) |
643 | { |
732 | { |
644 | if (pixbuf) |
733 | if (pixbuf) |
645 | g_object_unref (pixbuf); |
734 | g_object_unref (pixbuf); |
646 | pixbuf = image; |
735 | pixbuf = image; |
647 | flags |= IM_IS_SET; |
|
|
648 | ret = true; |
736 | ret = true; |
649 | } |
737 | } |
650 | # endif |
738 | # endif |
651 | |
739 | |
652 | if (ret) |
740 | if (ret) |
653 | { |
741 | { |
654 | if (p) |
742 | alpha = 0xffff; |
655 | set_geometry (p + 1); |
743 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
656 | else |
744 | h_scale = v_scale = defaultScale; |
657 | set_default_geometry (); |
745 | h_align = v_align = defaultAlign; |
658 | } |
746 | } |
659 | |
747 | |
660 | return ret; |
748 | return ret; |
661 | } |
749 | } |
662 | |
750 | |
… | |
… | |
1064 | # endif /* ENABLE_TRANSPARENCY */ |
1152 | # endif /* ENABLE_TRANSPARENCY */ |
1065 | |
1153 | |
1066 | bool |
1154 | bool |
1067 | rxvt_term::bg_render () |
1155 | rxvt_term::bg_render () |
1068 | { |
1156 | { |
1069 | bool transparent = false; |
|
|
1070 | |
|
|
1071 | bg_invalidate (); |
1157 | bg_invalidate (); |
1072 | # ifdef ENABLE_TRANSPARENCY |
1158 | # ifdef ENABLE_TRANSPARENCY |
1073 | if (bg_flags & BG_IS_TRANSPARENT) |
1159 | if (bg_flags & BG_IS_TRANSPARENT) |
1074 | { |
1160 | { |
1075 | /* we need to re-generate transparency pixmap in that case ! */ |
1161 | /* we need to re-generate transparency pixmap in that case ! */ |
1076 | transparent = make_transparency_pixmap (); |
1162 | if (make_transparency_pixmap ()) |
1077 | if (transparent) |
|
|
1078 | bg_flags |= BG_IS_VALID; |
1163 | bg_flags |= BG_IS_VALID; |
1079 | } |
1164 | } |
1080 | # endif |
1165 | # endif |
1081 | |
1166 | |
1082 | # ifdef BG_IMAGE_FROM_FILE |
1167 | # ifdef BG_IMAGE_FROM_FILE |
1083 | if (bg_image.flags & IM_IS_SET) |
1168 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1084 | { |
1169 | { |
1085 | if (render_image (bg_image, transparent)) |
1170 | if (render_image (*bg_image)) |
1086 | bg_flags |= BG_IS_VALID; |
1171 | bg_flags |= BG_IS_VALID; |
1087 | } |
1172 | } |
1088 | # endif |
1173 | # endif |
1089 | |
1174 | |
1090 | if (!(bg_flags & BG_IS_VALID)) |
1175 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1123 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1208 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1124 | bg_flags |= BG_HAS_RENDER_CONV; |
1209 | bg_flags |= BG_HAS_RENDER_CONV; |
1125 | |
1210 | |
1126 | XFree (filters); |
1211 | XFree (filters); |
1127 | } |
1212 | } |
|
|
1213 | #endif |
|
|
1214 | |
|
|
1215 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1216 | if (rs[Rs_backgroundPixmap]) |
|
|
1217 | { |
|
|
1218 | rxvt_image *image = new_image (); |
|
|
1219 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1220 | image_vec.pop_back (); |
|
|
1221 | } |
|
|
1222 | |
|
|
1223 | # ifndef NO_RESOURCES |
|
|
1224 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1225 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1226 | while (bg_image != image_vec.end ()) |
|
|
1227 | { |
|
|
1228 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1229 | bg_image = image_vec.erase (bg_image); |
|
|
1230 | else |
|
|
1231 | bg_image++; |
|
|
1232 | } |
|
|
1233 | # endif |
|
|
1234 | |
|
|
1235 | if (image_vec.size () > 0 |
|
|
1236 | && !bg_window_position_sensitive ()) |
|
|
1237 | update_background (); |
1128 | #endif |
1238 | #endif |
1129 | } |
1239 | } |
1130 | |
1240 | |
1131 | #endif /* HAVE_BG_PIXMAP */ |
1241 | #endif /* HAVE_BG_PIXMAP */ |
1132 | |
1242 | |