… | |
… | |
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_PIXBUF |
|
|
64 | if (pixbuf) |
|
|
65 | g_object_unref (pixbuf); |
|
|
66 | #endif |
|
|
67 | |
|
|
68 | if (bg_pixmap) |
63 | if (bg_pixmap) |
69 | XFreePixmap (dpy, bg_pixmap); |
64 | XFreePixmap (dpy, bg_pixmap); |
70 | } |
65 | } |
71 | |
66 | |
72 | bool |
67 | bool |
… | |
… | |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
85 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
86 | return true; |
92 | # endif |
87 | # endif |
93 | |
88 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
89 | # ifdef BG_IMAGE_FROM_FILE |
95 | if (bg_flags & BG_IS_FROM_FILE) |
90 | if (bg_image.flags & IM_IS_SET) |
96 | { |
91 | { |
97 | if (bg_flags & BG_IS_SIZE_SENSITIVE) |
92 | if ((bg_image.flags & IM_IS_SIZE_SENSITIVE) |
|
|
93 | || bg_image.width () > szHint.width |
|
|
94 | || bg_image.height () > szHint.height) |
98 | return true; |
95 | return true; |
99 | } |
96 | } |
100 | # endif |
97 | # endif |
101 | |
98 | |
102 | return false; |
99 | return false; |
… | |
… | |
109 | if (bg_flags & BG_IS_TRANSPARENT) |
106 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | return true; |
107 | return true; |
111 | # endif |
108 | # endif |
112 | |
109 | |
113 | # ifdef BG_IMAGE_FROM_FILE |
110 | # ifdef BG_IMAGE_FROM_FILE |
114 | if (bg_flags & BG_IS_FROM_FILE) |
111 | if (bg_image.flags & IM_IS_SET) |
115 | { |
112 | { |
116 | if (bg_flags & BG_ROOT_ALIGN) |
113 | if (bg_image.flags & IM_ROOT_ALIGN) |
117 | return true; |
114 | return true; |
118 | } |
115 | } |
119 | # endif |
116 | # endif |
120 | |
117 | |
121 | return false; |
118 | return false; |
… | |
… | |
149 | min_it (dst_size, target_size - dst_pos); |
146 | min_it (dst_size, target_size - dst_pos); |
150 | return src_pos; |
147 | return src_pos; |
151 | } |
148 | } |
152 | |
149 | |
153 | bool |
150 | bool |
154 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
151 | rxvt_image::set_geometry (const char *geom, bool update) |
155 | { |
152 | { |
156 | bool changed = false; |
153 | bool changed = false; |
157 | int geom_flags = 0; |
154 | int geom_flags = 0; |
158 | int x = h_align; |
155 | int x = h_align; |
159 | int y = v_align; |
156 | int y = v_align; |
… | |
… | |
170 | |
167 | |
171 | for (int i = 0; arr[i]; i++) |
168 | for (int i = 0; arr[i]; i++) |
172 | { |
169 | { |
173 | if (!strcasecmp (arr[i], "style=tiled")) |
170 | if (!strcasecmp (arr[i], "style=tiled")) |
174 | { |
171 | { |
175 | new_flags = BG_TILE; |
172 | new_flags = IM_TILE; |
176 | w = h = noScale; |
173 | w = h = noScale; |
177 | x = y = 0; |
174 | x = y = 0; |
178 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
175 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
179 | } |
176 | } |
180 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
177 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
181 | { |
178 | { |
182 | new_flags = BG_KEEP_ASPECT; |
179 | new_flags = IM_KEEP_ASPECT; |
183 | w = h = windowScale; |
180 | w = h = windowScale; |
184 | x = y = centerAlign; |
181 | x = y = centerAlign; |
185 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
182 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
186 | } |
183 | } |
187 | else if (!strcasecmp (arr[i], "style=stretched")) |
184 | else if (!strcasecmp (arr[i], "style=stretched")) |
… | |
… | |
197 | x = y = centerAlign; |
194 | x = y = centerAlign; |
198 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
195 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
199 | } |
196 | } |
200 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
197 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
201 | { |
198 | { |
202 | new_flags = BG_TILE|BG_ROOT_ALIGN; |
199 | new_flags = IM_TILE|IM_ROOT_ALIGN; |
203 | w = h = noScale; |
200 | w = h = noScale; |
204 | geom_flags = WidthValue|HeightValue; |
201 | geom_flags = WidthValue|HeightValue; |
205 | } |
202 | } |
206 | else if (!strcasecmp (arr[i], "op=tile")) |
203 | else if (!strcasecmp (arr[i], "op=tile")) |
207 | new_flags |= BG_TILE; |
204 | new_flags |= IM_TILE; |
208 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
205 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
209 | new_flags |= BG_KEEP_ASPECT; |
206 | new_flags |= IM_KEEP_ASPECT; |
210 | else if (!strcasecmp (arr[i], "op=root-align")) |
207 | else if (!strcasecmp (arr[i], "op=root-align")) |
211 | new_flags |= BG_ROOT_ALIGN; |
208 | new_flags |= IM_ROOT_ALIGN; |
212 | |
209 | |
213 | // deprecated |
210 | // deprecated |
214 | else if (!strcasecmp (arr[i], "tile")) |
211 | else if (!strcasecmp (arr[i], "tile")) |
215 | { |
212 | { |
216 | new_flags |= BG_TILE; |
213 | new_flags |= IM_TILE; |
217 | w = h = noScale; |
214 | w = h = noScale; |
218 | geom_flags |= WidthValue|HeightValue; |
215 | geom_flags |= WidthValue|HeightValue; |
219 | } |
216 | } |
220 | else if (!strcasecmp (arr[i], "propscale")) |
217 | else if (!strcasecmp (arr[i], "propscale")) |
221 | { |
218 | { |
222 | new_flags |= BG_KEEP_ASPECT; |
219 | new_flags |= IM_KEEP_ASPECT; |
223 | w = h = windowScale; |
220 | w = h = windowScale; |
224 | geom_flags |= WidthValue|HeightValue; |
221 | geom_flags |= WidthValue|HeightValue; |
225 | } |
222 | } |
226 | else if (!strcasecmp (arr[i], "hscale")) |
223 | else if (!strcasecmp (arr[i], "hscale")) |
227 | { |
224 | { |
228 | new_flags |= BG_TILE; |
225 | new_flags |= IM_TILE; |
229 | w = windowScale; |
226 | w = windowScale; |
230 | h = noScale; |
227 | h = noScale; |
231 | geom_flags |= WidthValue|HeightValue; |
228 | geom_flags |= WidthValue|HeightValue; |
232 | } |
229 | } |
233 | else if (!strcasecmp (arr[i], "vscale")) |
230 | else if (!strcasecmp (arr[i], "vscale")) |
234 | { |
231 | { |
235 | new_flags |= BG_TILE; |
232 | new_flags |= IM_TILE; |
236 | h = windowScale; |
233 | h = windowScale; |
237 | w = noScale; |
234 | w = noScale; |
238 | geom_flags |= WidthValue|HeightValue; |
235 | geom_flags |= WidthValue|HeightValue; |
239 | } |
236 | } |
240 | else if (!strcasecmp (arr[i], "scale")) |
237 | else if (!strcasecmp (arr[i], "scale")) |
… | |
… | |
248 | x = y = centerAlign; |
245 | x = y = centerAlign; |
249 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
246 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
250 | } |
247 | } |
251 | else if (!strcasecmp (arr[i], "root")) |
248 | else if (!strcasecmp (arr[i], "root")) |
252 | { |
249 | { |
253 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
250 | new_flags |= IM_TILE|IM_ROOT_ALIGN; |
254 | w = h = noScale; |
251 | w = h = noScale; |
255 | geom_flags |= WidthValue|HeightValue; |
252 | geom_flags |= WidthValue|HeightValue; |
256 | } |
253 | } |
257 | |
254 | |
258 | else |
255 | else |
… | |
… | |
260 | } /* done parsing ops */ |
257 | } /* done parsing ops */ |
261 | |
258 | |
262 | rxvt_free_strsplit (arr); |
259 | rxvt_free_strsplit (arr); |
263 | } |
260 | } |
264 | |
261 | |
265 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
262 | new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
266 | |
263 | |
267 | if (!update) |
264 | if (!update) |
268 | { |
265 | { |
269 | if (!(geom_flags & XValue)) |
266 | if (!(geom_flags & XValue)) |
270 | x = y = defaultAlign; |
267 | x = y = defaultAlign; |
… | |
… | |
277 | h = w; |
274 | h = w; |
278 | else if (!(geom_flags & WidthValue)) |
275 | else if (!(geom_flags & WidthValue)) |
279 | w = h; |
276 | w = h; |
280 | } |
277 | } |
281 | |
278 | |
282 | min_it (w, 1000); |
|
|
283 | min_it (h, 1000); |
|
|
284 | clamp_it (x, -100, 200); |
279 | clamp_it (x, -100, 200); |
285 | clamp_it (y, -100, 200); |
280 | clamp_it (y, -100, 200); |
286 | |
281 | |
287 | if (bg_flags != new_flags |
282 | if (flags != new_flags |
288 | || h_scale != w |
283 | || h_scale != w |
289 | || v_scale != h |
284 | || v_scale != h |
290 | || h_align != x |
285 | || h_align != x |
291 | || v_align != y) |
286 | || v_align != y) |
292 | { |
287 | { |
293 | bg_flags = new_flags; |
288 | flags = new_flags; |
294 | h_scale = w; |
289 | h_scale = w; |
295 | v_scale = h; |
290 | v_scale = h; |
296 | h_align = x; |
291 | h_align = x; |
297 | v_align = y; |
292 | v_align = y; |
298 | changed = true; |
293 | changed = true; |
299 | } |
294 | } |
300 | |
295 | |
|
|
296 | if (!(flags & IM_TILE) |
|
|
297 | || h_scale || v_scale |
|
|
298 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
299 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
300 | else |
|
|
301 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
302 | |
301 | return changed; |
303 | return changed; |
302 | } |
304 | } |
303 | |
305 | |
304 | void |
306 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
307 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
308 | { |
|
|
309 | int image_width = image.width (); |
|
|
310 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
311 | int target_width = szHint.width; |
308 | int target_height = szHint.height; |
312 | int target_height = szHint.height; |
|
|
313 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
314 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
309 | |
315 | |
310 | w = h_scale * target_width / 100; |
316 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
317 | h = v_scale * target_height / 100; |
312 | |
318 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
319 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
320 | { |
315 | float scale = (float)w / image_width; |
321 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
322 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
323 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
324 | h = image_height * scale + 0.5; |
319 | } |
325 | } |
320 | |
326 | |
321 | if (!w) w = image_width; |
327 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
328 | if (!h) h = image_height; |
323 | |
329 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
330 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
331 | { |
326 | x = -target_x; |
332 | x = -target_x; |
327 | y = -target_y; |
333 | y = -target_y; |
328 | } |
334 | } |
329 | else |
335 | else |
330 | { |
336 | { |
331 | x = make_align_position (h_align, target_width, w); |
337 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
338 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
339 | } |
334 | |
|
|
335 | if (!(bg_flags & BG_TILE) |
|
|
336 | || h_scale || v_scale |
|
|
337 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
|
|
338 | || image_width > target_width || image_height > target_height) |
|
|
339 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
|
|
340 | else |
|
|
341 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
|
|
342 | } |
340 | } |
343 | |
341 | |
344 | # ifdef HAVE_PIXBUF |
342 | # ifdef HAVE_PIXBUF |
345 | bool |
343 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
344 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | int src_x, int src_y, int dst_x, int dst_y, |
345 | int src_x, int src_y, int dst_x, int dst_y, |
348 | unsigned int width, unsigned int height) |
346 | unsigned int width, unsigned int height, bool argb) |
349 | { |
347 | { |
350 | XImage *ximage; |
348 | XImage *ximage; |
351 | char *line; |
349 | char *line; |
352 | int width_r, width_g, width_b, width_a; |
350 | int width_r, width_g, width_b, width_a; |
353 | int sh_r, sh_g, sh_b, sh_a; |
351 | int sh_r, sh_g, sh_b, sh_a; |
354 | uint32_t alpha_mask; |
352 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
355 | int rowstride; |
353 | int rowstride; |
356 | int channels; |
354 | int channels; |
357 | unsigned char *row; |
355 | unsigned char *row; |
358 | |
356 | |
359 | if (visual->c_class != TrueColor) |
357 | if (visual->c_class != TrueColor) |
360 | return false; |
358 | return false; |
361 | |
359 | |
|
|
360 | if (argb) |
|
|
361 | { |
|
|
362 | red_mask = 0xff << 16; |
|
|
363 | green_mask = 0xff << 8; |
|
|
364 | blue_mask = 0xff; |
|
|
365 | alpha_mask = 0xff << 24; |
|
|
366 | } |
|
|
367 | else |
|
|
368 | { |
|
|
369 | red_mask = visual->red_mask; |
|
|
370 | green_mask = visual->green_mask; |
|
|
371 | blue_mask = visual->blue_mask; |
362 | #if XRENDER |
372 | #if XRENDER |
363 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
373 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
364 | if (format) |
374 | if (format) |
365 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
375 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
366 | else |
376 | else |
367 | #endif |
377 | #endif |
368 | alpha_mask = 0; |
378 | alpha_mask = 0; |
|
|
379 | } |
369 | |
380 | |
370 | width_r = ecb_popcount32 (visual->red_mask); |
381 | width_r = ecb_popcount32 (red_mask); |
371 | width_g = ecb_popcount32 (visual->green_mask); |
382 | width_g = ecb_popcount32 (green_mask); |
372 | width_b = ecb_popcount32 (visual->blue_mask); |
383 | width_b = ecb_popcount32 (blue_mask); |
373 | width_a = ecb_popcount32 (alpha_mask); |
384 | width_a = ecb_popcount32 (alpha_mask); |
374 | |
385 | |
375 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
386 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
376 | return false; |
387 | return false; |
377 | |
388 | |
378 | sh_r = ecb_ctz32 (visual->red_mask); |
389 | sh_r = ecb_ctz32 (red_mask); |
379 | sh_g = ecb_ctz32 (visual->green_mask); |
390 | sh_g = ecb_ctz32 (green_mask); |
380 | sh_b = ecb_ctz32 (visual->blue_mask); |
391 | sh_b = ecb_ctz32 (blue_mask); |
381 | sh_a = ecb_ctz32 (alpha_mask); |
392 | sh_a = ecb_ctz32 (alpha_mask); |
382 | |
393 | |
383 | if (width > 32767 || height > 32767) |
394 | if (width > 32767 || height > 32767) |
384 | return false; |
395 | return false; |
385 | |
396 | |
386 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0, |
397 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
387 | width, height, 32, 0); |
398 | width, height, 32, 0); |
388 | if (!ximage) |
399 | if (!ximage) |
389 | return false; |
400 | return false; |
390 | |
401 | |
391 | if (height > INT_MAX / ximage->bytes_per_line |
402 | if (height > INT_MAX / ximage->bytes_per_line |
… | |
… | |
454 | XDestroyImage (ximage); |
465 | XDestroyImage (ximage); |
455 | return true; |
466 | return true; |
456 | } |
467 | } |
457 | |
468 | |
458 | bool |
469 | bool |
459 | rxvt_term::render_image (bool transparent) |
470 | rxvt_term::render_image (rxvt_image &image) |
460 | { |
471 | { |
|
|
472 | GdkPixbuf *pixbuf = image.pixbuf; |
461 | if (!pixbuf) |
473 | if (!pixbuf) |
462 | return false; |
474 | return false; |
463 | |
475 | |
464 | if (transparent |
476 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
477 | |
|
|
478 | if (need_blend |
465 | && !(bg_flags & BG_HAS_RENDER)) |
479 | && !(bg_flags & BG_HAS_RENDER)) |
466 | return false; |
480 | return false; |
467 | |
481 | |
468 | GdkPixbuf *result; |
482 | GdkPixbuf *result; |
469 | |
483 | |
… | |
… | |
478 | int x = 0; |
492 | int x = 0; |
479 | int y = 0; |
493 | int y = 0; |
480 | int w = 0; |
494 | int w = 0; |
481 | int h = 0; |
495 | int h = 0; |
482 | |
496 | |
483 | get_image_geometry (image_width, image_height, w, h, x, y); |
497 | get_image_geometry (image, w, h, x, y); |
484 | |
498 | |
485 | if (!(bg_flags & BG_ROOT_ALIGN) |
499 | if (!(image.flags & IM_ROOT_ALIGN) |
486 | && (x >= target_width |
500 | && (x >= target_width |
487 | || y >= target_height |
501 | || y >= target_height |
488 | || x + w <= 0 |
502 | || x + w <= 0 |
489 | || y + h <= 0)) |
503 | || y + h <= 0)) |
490 | return false; |
504 | return false; |
… | |
… | |
504 | |
518 | |
505 | bool ret = false; |
519 | bool ret = false; |
506 | |
520 | |
507 | XGCValues gcv; |
521 | XGCValues gcv; |
508 | GC gc; |
522 | GC gc; |
509 | Pixmap root_pmap; |
523 | Pixmap tmp_pixmap; |
510 | |
524 | |
511 | image_width = gdk_pixbuf_get_width (result); |
525 | image_width = gdk_pixbuf_get_width (result); |
512 | image_height = gdk_pixbuf_get_height (result); |
526 | image_height = gdk_pixbuf_get_height (result); |
513 | |
527 | |
514 | if (transparent) |
528 | if (need_blend) |
515 | { |
529 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
516 | root_pmap = bg_pixmap; |
|
|
517 | bg_pixmap = None; |
|
|
518 | } |
|
|
519 | else |
530 | else |
520 | { |
531 | { |
521 | if (bg_flags & BG_TILE) |
532 | if (image.flags & IM_TILE) |
522 | { |
533 | { |
523 | new_pmap_width = min (image_width, target_width); |
534 | new_pmap_width = min (image_width, target_width); |
524 | new_pmap_height = min (image_height, target_height); |
535 | new_pmap_height = min (image_height, target_height); |
525 | } |
536 | } |
526 | } |
|
|
527 | |
537 | |
528 | if (bg_pixmap == None |
538 | if (bg_pixmap == None |
529 | || bg_pmap_width != new_pmap_width |
539 | || bg_pmap_width != new_pmap_width |
530 | || bg_pmap_height != new_pmap_height) |
540 | || bg_pmap_height != new_pmap_height) |
531 | { |
541 | { |
532 | if (bg_pixmap) |
542 | if (bg_pixmap) |
533 | XFreePixmap (dpy, bg_pixmap); |
543 | XFreePixmap (dpy, bg_pixmap); |
534 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
544 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
535 | bg_pmap_width = new_pmap_width; |
545 | bg_pmap_width = new_pmap_width; |
536 | bg_pmap_height = new_pmap_height; |
546 | bg_pmap_height = new_pmap_height; |
|
|
547 | } |
|
|
548 | |
|
|
549 | tmp_pixmap = bg_pixmap; |
537 | } |
550 | } |
538 | |
551 | |
539 | gcv.foreground = pix_colors[Color_bg]; |
552 | gcv.foreground = pix_colors[Color_bg]; |
540 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
553 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
541 | |
554 | |
542 | if (gc) |
555 | if (gc) |
543 | { |
556 | { |
544 | if (bg_flags & BG_TILE) |
557 | if (image.flags & IM_TILE) |
545 | { |
558 | { |
546 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
559 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
547 | pixbuf_to_pixmap (result, tile, gc, |
560 | pixbuf_to_pixmap (result, tile, gc, |
548 | 0, 0, |
561 | 0, 0, |
549 | 0, 0, |
562 | 0, 0, |
550 | image_width, image_height); |
563 | image_width, image_height, need_blend); |
551 | |
564 | |
552 | gcv.tile = tile; |
565 | gcv.tile = tile; |
553 | gcv.fill_style = FillTiled; |
566 | gcv.fill_style = FillTiled; |
554 | gcv.ts_x_origin = x; |
567 | gcv.ts_x_origin = x; |
555 | gcv.ts_y_origin = y; |
568 | gcv.ts_y_origin = y; |
556 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
569 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
557 | |
570 | |
558 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
571 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
559 | XFreePixmap (dpy, tile); |
572 | XFreePixmap (dpy, tile); |
560 | } |
573 | } |
561 | else |
574 | else |
562 | { |
575 | { |
563 | int src_x, src_y, dst_x, dst_y; |
576 | int src_x, src_y, dst_x, dst_y; |
… | |
… | |
567 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
580 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
568 | |
581 | |
569 | if (dst_x > 0 || dst_y > 0 |
582 | if (dst_x > 0 || dst_y > 0 |
570 | || dst_x + dst_width < new_pmap_width |
583 | || dst_x + dst_width < new_pmap_width |
571 | || dst_y + dst_height < new_pmap_height) |
584 | || dst_y + dst_height < new_pmap_height) |
572 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
585 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
573 | |
586 | |
574 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
587 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
575 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
588 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
576 | src_x, src_y, |
589 | src_x, src_y, |
577 | dst_x, dst_y, |
590 | dst_x, dst_y, |
578 | dst_width, dst_height); |
591 | dst_width, dst_height, need_blend); |
579 | } |
592 | } |
580 | |
593 | |
581 | #if XRENDER |
594 | #if XRENDER |
582 | if (transparent) |
595 | if (need_blend) |
583 | { |
596 | { |
|
|
597 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
584 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
598 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
585 | |
599 | |
586 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
600 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
587 | |
601 | |
588 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
602 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
589 | |
603 | |
590 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
604 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
591 | |
605 | |
… | |
… | |
611 | } |
625 | } |
612 | |
626 | |
613 | if (result != pixbuf) |
627 | if (result != pixbuf) |
614 | g_object_unref (result); |
628 | g_object_unref (result); |
615 | |
629 | |
616 | if (transparent) |
630 | if (need_blend) |
617 | XFreePixmap (dpy, root_pmap); |
631 | XFreePixmap (dpy, tmp_pixmap); |
618 | |
632 | |
619 | return ret; |
633 | return ret; |
620 | } |
634 | } |
621 | # endif /* HAVE_PIXBUF */ |
635 | # endif /* HAVE_PIXBUF */ |
622 | |
636 | |
623 | bool |
637 | bool |
624 | rxvt_term::bg_set_file (const char *file) |
638 | rxvt_image::set_file (const char *file) |
625 | { |
639 | { |
626 | if (!file || !*file) |
640 | if (!file || !*file) |
627 | return false; |
641 | return false; |
628 | |
642 | |
629 | bool ret = false; |
643 | bool ret = false; |
… | |
… | |
643 | if (image) |
657 | if (image) |
644 | { |
658 | { |
645 | if (pixbuf) |
659 | if (pixbuf) |
646 | g_object_unref (pixbuf); |
660 | g_object_unref (pixbuf); |
647 | pixbuf = image; |
661 | pixbuf = image; |
648 | bg_flags |= BG_IS_FROM_FILE; |
|
|
649 | ret = true; |
662 | ret = true; |
650 | } |
663 | } |
651 | # endif |
664 | # endif |
652 | |
665 | |
653 | if (ret) |
666 | if (ret) |
654 | { |
667 | { |
|
|
668 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
|
|
669 | h_scale = v_scale = defaultScale; |
|
|
670 | h_align = v_align = defaultAlign; |
|
|
671 | |
655 | if (p) |
672 | if (p) |
656 | bg_set_geometry (p + 1); |
673 | set_geometry (p + 1); |
657 | else |
|
|
658 | bg_set_default_geometry (); |
|
|
659 | } |
674 | } |
660 | |
675 | |
661 | return ret; |
676 | return ret; |
662 | } |
677 | } |
663 | |
678 | |
… | |
… | |
690 | { |
705 | { |
691 | changed = true; |
706 | changed = true; |
692 | v_blurRadius = vr; |
707 | v_blurRadius = vr; |
693 | } |
708 | } |
694 | |
709 | |
695 | if (h_blurRadius && v_blurRadius) |
|
|
696 | bg_flags |= BG_NEEDS_BLUR; |
|
|
697 | else |
|
|
698 | bg_flags &= ~BG_NEEDS_BLUR; |
|
|
699 | |
|
|
700 | return changed; |
710 | return changed; |
701 | } |
|
|
702 | |
|
|
703 | void |
|
|
704 | rxvt_term::set_tint_shade_flags () |
|
|
705 | { |
|
|
706 | if (shade != 100 || (bg_flags & BG_TINT_SET)) |
|
|
707 | bg_flags |= BG_NEEDS_TINT; |
|
|
708 | else |
|
|
709 | bg_flags &= ~BG_NEEDS_TINT; |
|
|
710 | } |
711 | } |
711 | |
712 | |
712 | bool |
713 | bool |
713 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
714 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
714 | { |
715 | { |
… | |
… | |
724 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
725 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
725 | bg_flags |= BG_TINT_BITAND; |
726 | bg_flags |= BG_TINT_BITAND; |
726 | else |
727 | else |
727 | bg_flags &= ~BG_TINT_BITAND; |
728 | bg_flags &= ~BG_TINT_BITAND; |
728 | |
729 | |
729 | set_tint_shade_flags (); |
|
|
730 | return true; |
730 | return true; |
731 | } |
731 | } |
732 | |
732 | |
733 | return false; |
733 | return false; |
734 | } |
734 | } |
… | |
… | |
743 | new_shade = 200 - (100 + new_shade); |
743 | new_shade = 200 - (100 + new_shade); |
744 | |
744 | |
745 | if (new_shade != shade) |
745 | if (new_shade != shade) |
746 | { |
746 | { |
747 | shade = new_shade; |
747 | shade = new_shade; |
748 | set_tint_shade_flags (); |
|
|
749 | return true; |
748 | return true; |
750 | } |
749 | } |
751 | |
750 | |
752 | return false; |
751 | return false; |
753 | } |
752 | } |
… | |
… | |
774 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
773 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
775 | } |
774 | } |
776 | #endif |
775 | #endif |
777 | |
776 | |
778 | bool |
777 | bool |
779 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
778 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
780 | { |
779 | { |
781 | bool ret = false; |
780 | bool ret = false; |
782 | #if XRENDER |
781 | #if XRENDER |
783 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
782 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
784 | return false; |
783 | return false; |
… | |
… | |
839 | #endif |
838 | #endif |
840 | return ret; |
839 | return ret; |
841 | } |
840 | } |
842 | |
841 | |
843 | bool |
842 | bool |
844 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
843 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
845 | { |
844 | { |
846 | bool ret = false; |
845 | bool ret = false; |
847 | |
846 | |
848 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
847 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
849 | { |
848 | { |
… | |
… | |
1029 | |
1028 | |
1030 | if (gc) |
1029 | if (gc) |
1031 | { |
1030 | { |
1032 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1031 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1033 | ret = true; |
1032 | ret = true; |
1034 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1033 | bool need_blur = h_blurRadius && v_blurRadius; |
|
|
1034 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1035 | |
1035 | |
1036 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1036 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1037 | { |
1037 | { |
1038 | if (bg_flags & BG_NEEDS_BLUR) |
1038 | if (need_blur) |
1039 | { |
|
|
1040 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
|
|
1041 | tr_flags &= ~BG_NEEDS_BLUR; |
|
|
1042 | } |
1039 | { |
1043 | if (bg_flags & BG_NEEDS_TINT) |
1040 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
|
|
1041 | need_blur = false; |
1044 | { |
1042 | } |
|
|
1043 | if (need_tint) |
|
|
1044 | { |
1045 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1045 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1046 | tr_flags &= ~BG_NEEDS_TINT; |
1046 | need_tint = false; |
1047 | } |
1047 | } |
1048 | if (tr_flags & BG_NEEDS_TINT) |
1048 | if (need_tint) |
1049 | { |
1049 | { |
1050 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1050 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1051 | if (ximage) |
1051 | if (ximage) |
1052 | { |
1052 | { |
1053 | /* our own client-side tinting */ |
1053 | /* our own client-side tinting */ |
1054 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
1054 | tint_ximage (ximage); |
1055 | |
1055 | |
1056 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1056 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1057 | XDestroyImage (ximage); |
1057 | XDestroyImage (ximage); |
1058 | } |
1058 | } |
1059 | } |
1059 | } |
… | |
… | |
1080 | # endif /* ENABLE_TRANSPARENCY */ |
1080 | # endif /* ENABLE_TRANSPARENCY */ |
1081 | |
1081 | |
1082 | bool |
1082 | bool |
1083 | rxvt_term::bg_render () |
1083 | rxvt_term::bg_render () |
1084 | { |
1084 | { |
1085 | bool transparent = false; |
|
|
1086 | |
|
|
1087 | bg_invalidate (); |
1085 | bg_invalidate (); |
1088 | # ifdef ENABLE_TRANSPARENCY |
1086 | # ifdef ENABLE_TRANSPARENCY |
1089 | if (bg_flags & BG_IS_TRANSPARENT) |
1087 | if (bg_flags & BG_IS_TRANSPARENT) |
1090 | { |
1088 | { |
1091 | /* we need to re-generate transparency pixmap in that case ! */ |
1089 | /* we need to re-generate transparency pixmap in that case ! */ |
1092 | transparent = make_transparency_pixmap (); |
1090 | if (make_transparency_pixmap ()) |
1093 | if (transparent) |
|
|
1094 | bg_flags |= BG_IS_VALID; |
1091 | bg_flags |= BG_IS_VALID; |
1095 | } |
1092 | } |
1096 | # endif |
1093 | # endif |
1097 | |
1094 | |
1098 | # ifdef BG_IMAGE_FROM_FILE |
1095 | # ifdef BG_IMAGE_FROM_FILE |
1099 | if (bg_flags & BG_IS_FROM_FILE) |
1096 | if (bg_image.flags & IM_IS_SET) |
1100 | { |
1097 | { |
1101 | if (render_image (transparent)) |
1098 | if (render_image (bg_image)) |
1102 | bg_flags |= BG_IS_VALID; |
1099 | bg_flags |= BG_IS_VALID; |
1103 | } |
1100 | } |
1104 | # endif |
1101 | # endif |
1105 | |
1102 | |
1106 | if (!(bg_flags & BG_IS_VALID)) |
1103 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1160 | lookup[i] = (tmp / 0xffff) << sh; |
1157 | lookup[i] = (tmp / 0xffff) << sh; |
1161 | } |
1158 | } |
1162 | } |
1159 | } |
1163 | |
1160 | |
1164 | void |
1161 | void |
1165 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1162 | rxvt_term::tint_ximage (XImage *ximage) |
1166 | { |
1163 | { |
1167 | unsigned int size_r, size_g, size_b; |
1164 | unsigned int size_r, size_g, size_b; |
1168 | int sh_r, sh_g, sh_b; |
1165 | int sh_r, sh_g, sh_b; |
1169 | uint32_t mask_r, mask_g, mask_b; |
1166 | uint32_t mask_r, mask_g, mask_b; |
1170 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1167 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |