… | |
… | |
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; |
… | |
… | |
148 | |
145 | |
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 | |
|
|
150 | static void |
|
|
151 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
|
|
152 | { |
|
|
153 | if (!strcasecmp (style, "tiled")) |
|
|
154 | { |
|
|
155 | flags = IM_TILE; |
|
|
156 | w = h = noScale; |
|
|
157 | x = y = 0; |
|
|
158 | } |
|
|
159 | else if (!strcasecmp (style, "aspect-stretched")) |
|
|
160 | { |
|
|
161 | flags = IM_KEEP_ASPECT; |
|
|
162 | w = h = windowScale; |
|
|
163 | x = y = centerAlign; |
|
|
164 | } |
|
|
165 | else if (!strcasecmp (style, "stretched")) |
|
|
166 | { |
|
|
167 | flags = 0; |
|
|
168 | w = h = windowScale; |
|
|
169 | x = y = centerAlign; |
|
|
170 | } |
|
|
171 | else if (!strcasecmp (style, "centered")) |
|
|
172 | { |
|
|
173 | flags = 0; |
|
|
174 | w = h = noScale; |
|
|
175 | x = y = centerAlign; |
|
|
176 | } |
|
|
177 | else if (!strcasecmp (style, "root-tiled")) |
|
|
178 | { |
|
|
179 | flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
180 | w = h = noScale; |
|
|
181 | x = y = 0; |
|
|
182 | } |
|
|
183 | } |
|
|
184 | |
153 | bool |
185 | bool |
154 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
186 | rxvt_image::set_geometry (const char *geom, bool update) |
155 | { |
187 | { |
156 | bool changed = false; |
188 | bool changed = false; |
157 | int geom_flags = 0; |
189 | int geom_flags = 0; |
158 | int x = h_align; |
190 | int x = h_align; |
159 | int y = v_align; |
191 | int y = v_align; |
160 | unsigned int w = h_scale; |
192 | unsigned int w = h_scale; |
161 | unsigned int h = v_scale; |
193 | unsigned int h = v_scale; |
162 | unsigned long new_flags = 0; |
194 | uint8_t new_flags = 0; |
163 | |
195 | |
164 | if (geom == NULL) |
196 | if (geom == NULL) |
165 | return false; |
197 | return false; |
166 | |
198 | |
167 | if (geom[0]) |
199 | if (geom[0]) |
168 | { |
200 | { |
169 | char **arr = rxvt_strsplit (':', geom); |
201 | char **arr = rxvt_strsplit (':', geom); |
170 | |
202 | |
171 | for (int i = 0; arr[i]; i++) |
203 | for (int i = 0; arr[i]; i++) |
172 | { |
204 | { |
173 | if (!strcasecmp (arr[i], "style=tiled")) |
205 | if (!strncasecmp (arr[i], "style=", 6)) |
174 | { |
206 | { |
175 | new_flags = BG_TILE; |
207 | parse_style (arr[i] + 6, x, y, w, h, new_flags); |
176 | w = h = noScale; |
|
|
177 | x = y = 0; |
|
|
178 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
208 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
179 | } |
209 | } |
180 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
|
|
181 | { |
|
|
182 | new_flags = BG_KEEP_ASPECT; |
|
|
183 | w = h = windowScale; |
|
|
184 | x = y = centerAlign; |
|
|
185 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
186 | } |
|
|
187 | else if (!strcasecmp (arr[i], "style=stretched")) |
|
|
188 | { |
|
|
189 | new_flags = 0; |
|
|
190 | w = h = windowScale; |
|
|
191 | geom_flags = WidthValue|HeightValue; |
|
|
192 | } |
|
|
193 | else if (!strcasecmp (arr[i], "style=centered")) |
|
|
194 | { |
|
|
195 | new_flags = 0; |
|
|
196 | w = h = noScale; |
|
|
197 | x = y = centerAlign; |
|
|
198 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
199 | } |
|
|
200 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
|
|
201 | { |
|
|
202 | new_flags = BG_TILE|BG_ROOT_ALIGN; |
|
|
203 | w = h = noScale; |
|
|
204 | geom_flags = WidthValue|HeightValue; |
|
|
205 | } |
|
|
206 | else if (!strcasecmp (arr[i], "op=tile")) |
210 | else if (!strcasecmp (arr[i], "op=tile")) |
207 | new_flags |= BG_TILE; |
211 | new_flags |= IM_TILE; |
208 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
212 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
209 | new_flags |= BG_KEEP_ASPECT; |
213 | new_flags |= IM_KEEP_ASPECT; |
210 | else if (!strcasecmp (arr[i], "op=root-align")) |
214 | else if (!strcasecmp (arr[i], "op=root-align")) |
211 | new_flags |= BG_ROOT_ALIGN; |
215 | new_flags |= IM_ROOT_ALIGN; |
212 | |
216 | |
213 | // deprecated |
217 | // deprecated |
214 | else if (!strcasecmp (arr[i], "tile")) |
218 | else if (!strcasecmp (arr[i], "tile")) |
215 | { |
219 | { |
216 | new_flags |= BG_TILE; |
220 | new_flags |= IM_TILE; |
217 | w = h = noScale; |
221 | w = h = noScale; |
218 | geom_flags |= WidthValue|HeightValue; |
222 | geom_flags |= WidthValue|HeightValue; |
219 | } |
223 | } |
220 | else if (!strcasecmp (arr[i], "propscale")) |
224 | else if (!strcasecmp (arr[i], "propscale")) |
221 | { |
225 | { |
222 | new_flags |= BG_KEEP_ASPECT; |
226 | new_flags |= IM_KEEP_ASPECT; |
223 | w = h = windowScale; |
227 | w = h = windowScale; |
224 | geom_flags |= WidthValue|HeightValue; |
228 | geom_flags |= WidthValue|HeightValue; |
225 | } |
229 | } |
226 | else if (!strcasecmp (arr[i], "hscale")) |
230 | else if (!strcasecmp (arr[i], "hscale")) |
227 | { |
231 | { |
228 | new_flags |= BG_TILE; |
232 | new_flags |= IM_TILE; |
229 | w = windowScale; |
233 | w = windowScale; |
230 | h = noScale; |
234 | h = noScale; |
231 | geom_flags |= WidthValue|HeightValue; |
235 | geom_flags |= WidthValue|HeightValue; |
232 | } |
236 | } |
233 | else if (!strcasecmp (arr[i], "vscale")) |
237 | else if (!strcasecmp (arr[i], "vscale")) |
234 | { |
238 | { |
235 | new_flags |= BG_TILE; |
239 | new_flags |= IM_TILE; |
236 | h = windowScale; |
240 | h = windowScale; |
237 | w = noScale; |
241 | w = noScale; |
238 | geom_flags |= WidthValue|HeightValue; |
242 | geom_flags |= WidthValue|HeightValue; |
239 | } |
243 | } |
240 | else if (!strcasecmp (arr[i], "scale")) |
244 | else if (!strcasecmp (arr[i], "scale")) |
… | |
… | |
248 | x = y = centerAlign; |
252 | x = y = centerAlign; |
249 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
253 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
250 | } |
254 | } |
251 | else if (!strcasecmp (arr[i], "root")) |
255 | else if (!strcasecmp (arr[i], "root")) |
252 | { |
256 | { |
253 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
257 | new_flags |= IM_TILE|IM_ROOT_ALIGN; |
254 | w = h = noScale; |
258 | w = h = noScale; |
255 | geom_flags |= WidthValue|HeightValue; |
259 | geom_flags |= WidthValue|HeightValue; |
256 | } |
260 | } |
257 | |
261 | |
258 | else |
262 | else |
… | |
… | |
260 | } /* done parsing ops */ |
264 | } /* done parsing ops */ |
261 | |
265 | |
262 | rxvt_free_strsplit (arr); |
266 | rxvt_free_strsplit (arr); |
263 | } |
267 | } |
264 | |
268 | |
265 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
269 | new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
266 | |
270 | |
267 | if (!update) |
271 | if (!update) |
268 | { |
272 | { |
269 | if (!(geom_flags & XValue)) |
273 | if (!(geom_flags & XValue)) |
270 | x = y = defaultAlign; |
274 | x = y = defaultAlign; |
… | |
… | |
277 | h = w; |
281 | h = w; |
278 | else if (!(geom_flags & WidthValue)) |
282 | else if (!(geom_flags & WidthValue)) |
279 | w = h; |
283 | w = h; |
280 | } |
284 | } |
281 | |
285 | |
282 | min_it (w, 1000); |
|
|
283 | min_it (h, 1000); |
|
|
284 | clamp_it (x, -100, 200); |
286 | clamp_it (x, -100, 200); |
285 | clamp_it (y, -100, 200); |
287 | clamp_it (y, -100, 200); |
286 | |
288 | |
287 | if (bg_flags != new_flags |
289 | if (flags != new_flags |
288 | || h_scale != w |
290 | || h_scale != w |
289 | || v_scale != h |
291 | || v_scale != h |
290 | || h_align != x |
292 | || h_align != x |
291 | || v_align != y) |
293 | || v_align != y) |
292 | { |
294 | { |
293 | bg_flags = new_flags; |
295 | flags = new_flags; |
294 | h_scale = w; |
296 | h_scale = w; |
295 | v_scale = h; |
297 | v_scale = h; |
296 | h_align = x; |
298 | h_align = x; |
297 | v_align = y; |
299 | v_align = y; |
298 | changed = true; |
300 | changed = true; |
299 | } |
301 | } |
300 | |
302 | |
|
|
303 | if (!(flags & IM_TILE) |
|
|
304 | || h_scale || v_scale |
|
|
305 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
306 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
307 | else |
|
|
308 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
309 | |
301 | return changed; |
310 | return changed; |
302 | } |
311 | } |
303 | |
312 | |
304 | void |
313 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
314 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
315 | { |
|
|
316 | int image_width = image.width (); |
|
|
317 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
318 | int target_width = szHint.width; |
308 | int target_height = szHint.height; |
319 | int target_height = szHint.height; |
|
|
320 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
321 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
309 | |
322 | |
310 | w = h_scale * target_width / 100; |
323 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
324 | h = v_scale * target_height / 100; |
312 | |
325 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
326 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
327 | { |
315 | float scale = (float)w / image_width; |
328 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
329 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
330 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
331 | h = image_height * scale + 0.5; |
319 | } |
332 | } |
320 | |
333 | |
321 | if (!w) w = image_width; |
334 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
335 | if (!h) h = image_height; |
323 | |
336 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
337 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
338 | { |
326 | x = -target_x; |
339 | x = -target_x; |
327 | y = -target_y; |
340 | y = -target_y; |
328 | } |
341 | } |
329 | else |
342 | else |
330 | { |
343 | { |
331 | x = make_align_position (h_align, target_width, w); |
344 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
345 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
346 | } |
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 | } |
347 | } |
343 | |
348 | |
344 | # ifdef HAVE_PIXBUF |
349 | # ifdef HAVE_PIXBUF |
345 | bool |
350 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
351 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | int src_x, int src_y, int dst_x, int dst_y, |
352 | int src_x, int src_y, int dst_x, int dst_y, |
348 | unsigned int width, unsigned int height) |
353 | unsigned int width, unsigned int height, bool argb) |
349 | { |
354 | { |
350 | XImage *ximage; |
355 | XImage *ximage; |
351 | char *line; |
356 | char *line; |
352 | int width_r, width_g, width_b, width_a; |
357 | int width_r, width_g, width_b, width_a; |
353 | int sh_r, sh_g, sh_b, sh_a; |
358 | int sh_r, sh_g, sh_b, sh_a; |
354 | uint32_t alpha_mask; |
359 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
355 | int rowstride; |
360 | int rowstride; |
356 | int channels; |
361 | int channels; |
357 | unsigned char *row; |
362 | unsigned char *row; |
358 | |
363 | |
359 | if (visual->c_class != TrueColor) |
364 | if (visual->c_class != TrueColor) |
360 | return false; |
365 | return false; |
361 | |
366 | |
|
|
367 | if (argb) |
|
|
368 | { |
|
|
369 | red_mask = 0xff << 16; |
|
|
370 | green_mask = 0xff << 8; |
|
|
371 | blue_mask = 0xff; |
|
|
372 | alpha_mask = 0xff << 24; |
|
|
373 | } |
|
|
374 | else |
|
|
375 | { |
|
|
376 | red_mask = visual->red_mask; |
|
|
377 | green_mask = visual->green_mask; |
|
|
378 | blue_mask = visual->blue_mask; |
362 | #if XRENDER |
379 | #if XRENDER |
363 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
380 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
364 | if (format) |
381 | if (format) |
365 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
382 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
366 | else |
383 | else |
367 | #endif |
384 | #endif |
368 | alpha_mask = 0; |
385 | alpha_mask = 0; |
|
|
386 | } |
369 | |
387 | |
370 | width_r = ecb_popcount32 (visual->red_mask); |
388 | width_r = ecb_popcount32 (red_mask); |
371 | width_g = ecb_popcount32 (visual->green_mask); |
389 | width_g = ecb_popcount32 (green_mask); |
372 | width_b = ecb_popcount32 (visual->blue_mask); |
390 | width_b = ecb_popcount32 (blue_mask); |
373 | width_a = ecb_popcount32 (alpha_mask); |
391 | width_a = ecb_popcount32 (alpha_mask); |
374 | |
392 | |
375 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
393 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
376 | return false; |
394 | return false; |
377 | |
395 | |
378 | sh_r = ecb_ctz32 (visual->red_mask); |
396 | sh_r = ecb_ctz32 (red_mask); |
379 | sh_g = ecb_ctz32 (visual->green_mask); |
397 | sh_g = ecb_ctz32 (green_mask); |
380 | sh_b = ecb_ctz32 (visual->blue_mask); |
398 | sh_b = ecb_ctz32 (blue_mask); |
381 | sh_a = ecb_ctz32 (alpha_mask); |
399 | sh_a = ecb_ctz32 (alpha_mask); |
382 | |
400 | |
383 | if (width > 32767 || height > 32767) |
401 | if (width > 32767 || height > 32767) |
384 | return false; |
402 | return false; |
385 | |
403 | |
386 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0, |
404 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
387 | width, height, 32, 0); |
405 | width, height, 32, 0); |
388 | if (!ximage) |
406 | if (!ximage) |
389 | return false; |
407 | return false; |
390 | |
408 | |
391 | if (height > INT_MAX / ximage->bytes_per_line |
409 | if (height > INT_MAX / ximage->bytes_per_line |
… | |
… | |
454 | XDestroyImage (ximage); |
472 | XDestroyImage (ximage); |
455 | return true; |
473 | return true; |
456 | } |
474 | } |
457 | |
475 | |
458 | bool |
476 | bool |
459 | rxvt_term::render_image (bool transparent) |
477 | rxvt_term::render_image (rxvt_image &image) |
460 | { |
478 | { |
|
|
479 | GdkPixbuf *pixbuf = image.pixbuf; |
461 | if (!pixbuf) |
480 | if (!pixbuf) |
462 | return false; |
481 | return false; |
463 | |
482 | |
464 | if (transparent |
483 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
484 | |
|
|
485 | if (need_blend |
465 | && !(bg_flags & BG_HAS_RENDER)) |
486 | && !(bg_flags & BG_HAS_RENDER)) |
466 | return false; |
487 | return false; |
467 | |
488 | |
468 | GdkPixbuf *result; |
489 | GdkPixbuf *result; |
469 | |
490 | |
… | |
… | |
478 | int x = 0; |
499 | int x = 0; |
479 | int y = 0; |
500 | int y = 0; |
480 | int w = 0; |
501 | int w = 0; |
481 | int h = 0; |
502 | int h = 0; |
482 | |
503 | |
483 | get_image_geometry (image_width, image_height, w, h, x, y); |
504 | get_image_geometry (image, w, h, x, y); |
484 | |
505 | |
485 | if (!(bg_flags & BG_ROOT_ALIGN) |
506 | if (!(image.flags & IM_ROOT_ALIGN) |
486 | && (x >= target_width |
507 | && (x >= target_width |
487 | || y >= target_height |
508 | || y >= target_height |
488 | || x + w <= 0 |
509 | || x + w <= 0 |
489 | || y + h <= 0)) |
510 | || y + h <= 0)) |
490 | return false; |
511 | return false; |
… | |
… | |
504 | |
525 | |
505 | bool ret = false; |
526 | bool ret = false; |
506 | |
527 | |
507 | XGCValues gcv; |
528 | XGCValues gcv; |
508 | GC gc; |
529 | GC gc; |
509 | Pixmap root_pmap; |
530 | Pixmap tmp_pixmap; |
510 | |
531 | |
511 | image_width = gdk_pixbuf_get_width (result); |
532 | image_width = gdk_pixbuf_get_width (result); |
512 | image_height = gdk_pixbuf_get_height (result); |
533 | image_height = gdk_pixbuf_get_height (result); |
513 | |
534 | |
514 | if (transparent) |
535 | if (need_blend) |
515 | { |
536 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
516 | root_pmap = bg_pixmap; |
|
|
517 | bg_pixmap = None; |
|
|
518 | } |
|
|
519 | else |
537 | else |
520 | { |
538 | { |
521 | if (bg_flags & BG_TILE) |
539 | if (image.flags & IM_TILE) |
522 | { |
540 | { |
523 | new_pmap_width = min (image_width, target_width); |
541 | new_pmap_width = min (image_width, target_width); |
524 | new_pmap_height = min (image_height, target_height); |
542 | new_pmap_height = min (image_height, target_height); |
525 | } |
543 | } |
526 | } |
|
|
527 | |
544 | |
528 | if (bg_pixmap == None |
545 | if (bg_pixmap == None |
529 | || bg_pmap_width != new_pmap_width |
546 | || bg_pmap_width != new_pmap_width |
530 | || bg_pmap_height != new_pmap_height) |
547 | || bg_pmap_height != new_pmap_height) |
531 | { |
548 | { |
532 | if (bg_pixmap) |
549 | if (bg_pixmap) |
533 | XFreePixmap (dpy, bg_pixmap); |
550 | XFreePixmap (dpy, bg_pixmap); |
534 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
551 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
535 | bg_pmap_width = new_pmap_width; |
552 | bg_pmap_width = new_pmap_width; |
536 | bg_pmap_height = new_pmap_height; |
553 | bg_pmap_height = new_pmap_height; |
|
|
554 | } |
|
|
555 | |
|
|
556 | tmp_pixmap = bg_pixmap; |
537 | } |
557 | } |
538 | |
558 | |
539 | gcv.foreground = pix_colors[Color_bg]; |
559 | gcv.foreground = pix_colors[Color_bg]; |
540 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
560 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
541 | |
561 | |
542 | if (gc) |
562 | if (gc) |
543 | { |
563 | { |
544 | if (bg_flags & BG_TILE) |
564 | if (image.flags & IM_TILE) |
545 | { |
565 | { |
546 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
566 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
547 | pixbuf_to_pixmap (result, tile, gc, |
567 | pixbuf_to_pixmap (result, tile, gc, |
548 | 0, 0, |
568 | 0, 0, |
549 | 0, 0, |
569 | 0, 0, |
550 | image_width, image_height); |
570 | image_width, image_height, need_blend); |
551 | |
571 | |
552 | gcv.tile = tile; |
572 | gcv.tile = tile; |
553 | gcv.fill_style = FillTiled; |
573 | gcv.fill_style = FillTiled; |
554 | gcv.ts_x_origin = x; |
574 | gcv.ts_x_origin = x; |
555 | gcv.ts_y_origin = y; |
575 | gcv.ts_y_origin = y; |
556 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
576 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
557 | |
577 | |
558 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
578 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
559 | XFreePixmap (dpy, tile); |
579 | XFreePixmap (dpy, tile); |
560 | } |
580 | } |
561 | else |
581 | else |
562 | { |
582 | { |
563 | int src_x, src_y, dst_x, dst_y; |
583 | 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); |
587 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
568 | |
588 | |
569 | if (dst_x > 0 || dst_y > 0 |
589 | if (dst_x > 0 || dst_y > 0 |
570 | || dst_x + dst_width < new_pmap_width |
590 | || dst_x + dst_width < new_pmap_width |
571 | || dst_y + dst_height < new_pmap_height) |
591 | || dst_y + dst_height < new_pmap_height) |
572 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
592 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
573 | |
593 | |
574 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
594 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
575 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
595 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
576 | src_x, src_y, |
596 | src_x, src_y, |
577 | dst_x, dst_y, |
597 | dst_x, dst_y, |
578 | dst_width, dst_height); |
598 | dst_width, dst_height, need_blend); |
579 | } |
599 | } |
580 | |
600 | |
581 | #if XRENDER |
601 | #if XRENDER |
582 | if (transparent) |
602 | if (need_blend) |
583 | { |
603 | { |
|
|
604 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
584 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
605 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
585 | |
606 | |
586 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
607 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
587 | |
608 | |
588 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
609 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
589 | |
610 | |
590 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
611 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
591 | |
612 | |
… | |
… | |
611 | } |
632 | } |
612 | |
633 | |
613 | if (result != pixbuf) |
634 | if (result != pixbuf) |
614 | g_object_unref (result); |
635 | g_object_unref (result); |
615 | |
636 | |
616 | if (transparent) |
637 | if (need_blend) |
617 | XFreePixmap (dpy, root_pmap); |
638 | XFreePixmap (dpy, tmp_pixmap); |
618 | |
639 | |
619 | return ret; |
640 | return ret; |
620 | } |
641 | } |
621 | # endif /* HAVE_PIXBUF */ |
642 | # endif /* HAVE_PIXBUF */ |
622 | |
643 | |
623 | bool |
644 | bool |
624 | rxvt_term::bg_set_file (const char *file) |
645 | rxvt_image::set_file (const char *file) |
625 | { |
646 | { |
626 | if (!file || !*file) |
647 | if (!file || !*file) |
627 | return false; |
648 | return false; |
628 | |
649 | |
629 | bool ret = false; |
650 | bool ret = false; |
… | |
… | |
643 | if (image) |
664 | if (image) |
644 | { |
665 | { |
645 | if (pixbuf) |
666 | if (pixbuf) |
646 | g_object_unref (pixbuf); |
667 | g_object_unref (pixbuf); |
647 | pixbuf = image; |
668 | pixbuf = image; |
648 | bg_flags |= BG_IS_FROM_FILE; |
|
|
649 | ret = true; |
669 | ret = true; |
650 | } |
670 | } |
651 | # endif |
671 | # endif |
652 | |
672 | |
653 | if (ret) |
673 | if (ret) |
654 | { |
674 | { |
|
|
675 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
|
|
676 | h_scale = v_scale = defaultScale; |
|
|
677 | h_align = v_align = defaultAlign; |
|
|
678 | |
655 | if (p) |
679 | if (p) |
656 | bg_set_geometry (p + 1); |
680 | set_geometry (p + 1); |
657 | else |
|
|
658 | bg_set_default_geometry (); |
|
|
659 | } |
681 | } |
660 | |
682 | |
661 | return ret; |
683 | return ret; |
662 | } |
684 | } |
663 | |
685 | |
664 | # endif /* BG_IMAGE_FROM_FILE */ |
686 | # endif /* BG_IMAGE_FROM_FILE */ |
665 | |
687 | |
666 | # ifdef ENABLE_TRANSPARENCY |
688 | # ifdef ENABLE_TRANSPARENCY |
667 | bool |
|
|
668 | rxvt_term::bg_set_transparent () |
|
|
669 | { |
|
|
670 | if (!(bg_flags & BG_IS_TRANSPARENT)) |
|
|
671 | { |
|
|
672 | bg_flags |= BG_IS_TRANSPARENT; |
|
|
673 | return true; |
|
|
674 | } |
|
|
675 | |
|
|
676 | return false; |
|
|
677 | } |
|
|
678 | |
|
|
679 | bool |
689 | bool |
680 | rxvt_term::bg_set_blur (const char *geom) |
690 | rxvt_term::bg_set_blur (const char *geom) |
681 | { |
691 | { |
682 | bool changed = false; |
692 | bool changed = false; |
683 | unsigned int hr, vr; |
693 | unsigned int hr, vr; |
… | |
… | |
702 | { |
712 | { |
703 | changed = true; |
713 | changed = true; |
704 | v_blurRadius = vr; |
714 | v_blurRadius = vr; |
705 | } |
715 | } |
706 | |
716 | |
707 | if (h_blurRadius && v_blurRadius) |
|
|
708 | bg_flags |= BG_NEEDS_BLUR; |
|
|
709 | else |
|
|
710 | bg_flags &= ~BG_NEEDS_BLUR; |
|
|
711 | |
|
|
712 | return changed; |
717 | return changed; |
713 | } |
|
|
714 | |
|
|
715 | void |
|
|
716 | rxvt_term::set_tint_shade_flags () |
|
|
717 | { |
|
|
718 | if (shade != 100 || (bg_flags & BG_TINT_SET)) |
|
|
719 | bg_flags |= BG_NEEDS_TINT; |
|
|
720 | else |
|
|
721 | bg_flags &= ~BG_NEEDS_TINT; |
|
|
722 | } |
718 | } |
723 | |
719 | |
724 | bool |
720 | bool |
725 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
721 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
726 | { |
722 | { |
… | |
… | |
736 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
732 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
737 | bg_flags |= BG_TINT_BITAND; |
733 | bg_flags |= BG_TINT_BITAND; |
738 | else |
734 | else |
739 | bg_flags &= ~BG_TINT_BITAND; |
735 | bg_flags &= ~BG_TINT_BITAND; |
740 | |
736 | |
741 | set_tint_shade_flags (); |
|
|
742 | return true; |
737 | return true; |
743 | } |
738 | } |
744 | |
739 | |
745 | return false; |
740 | return false; |
746 | } |
741 | } |
… | |
… | |
755 | new_shade = 200 - (100 + new_shade); |
750 | new_shade = 200 - (100 + new_shade); |
756 | |
751 | |
757 | if (new_shade != shade) |
752 | if (new_shade != shade) |
758 | { |
753 | { |
759 | shade = new_shade; |
754 | shade = new_shade; |
760 | set_tint_shade_flags (); |
|
|
761 | return true; |
755 | return true; |
762 | } |
756 | } |
763 | |
757 | |
764 | return false; |
758 | return false; |
765 | } |
759 | } |
… | |
… | |
786 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
780 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
787 | } |
781 | } |
788 | #endif |
782 | #endif |
789 | |
783 | |
790 | bool |
784 | bool |
791 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
785 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
792 | { |
786 | { |
793 | bool ret = false; |
787 | bool ret = false; |
794 | #if XRENDER |
788 | #if XRENDER |
795 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
789 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
796 | return false; |
790 | return false; |
… | |
… | |
851 | #endif |
845 | #endif |
852 | return ret; |
846 | return ret; |
853 | } |
847 | } |
854 | |
848 | |
855 | bool |
849 | bool |
856 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
850 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
857 | { |
851 | { |
858 | bool ret = false; |
852 | bool ret = false; |
859 | |
853 | |
860 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
854 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
861 | { |
855 | { |
… | |
… | |
1041 | |
1035 | |
1042 | if (gc) |
1036 | if (gc) |
1043 | { |
1037 | { |
1044 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1038 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1045 | ret = true; |
1039 | ret = true; |
1046 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1040 | bool need_blur = h_blurRadius && v_blurRadius; |
|
|
1041 | bool need_tint = shade != 100 || (bg_flags & BG_TINT_SET); |
1047 | |
1042 | |
1048 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1043 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1049 | { |
1044 | { |
1050 | if (bg_flags & BG_NEEDS_BLUR) |
1045 | if (need_blur) |
1051 | { |
|
|
1052 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
|
|
1053 | tr_flags &= ~BG_NEEDS_BLUR; |
|
|
1054 | } |
1046 | { |
1055 | if (bg_flags & BG_NEEDS_TINT) |
1047 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
|
|
1048 | need_blur = false; |
1056 | { |
1049 | } |
|
|
1050 | if (need_tint) |
|
|
1051 | { |
1057 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1052 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1058 | tr_flags &= ~BG_NEEDS_TINT; |
1053 | need_tint = false; |
1059 | } |
1054 | } |
1060 | if (tr_flags & BG_NEEDS_TINT) |
1055 | if (need_tint) |
1061 | { |
1056 | { |
1062 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1057 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1063 | if (ximage) |
1058 | if (ximage) |
1064 | { |
1059 | { |
1065 | /* our own client-side tinting */ |
1060 | /* our own client-side tinting */ |
1066 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
1061 | tint_ximage (ximage); |
1067 | |
1062 | |
1068 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1063 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1069 | XDestroyImage (ximage); |
1064 | XDestroyImage (ximage); |
1070 | } |
1065 | } |
1071 | } |
1066 | } |
… | |
… | |
1092 | # endif /* ENABLE_TRANSPARENCY */ |
1087 | # endif /* ENABLE_TRANSPARENCY */ |
1093 | |
1088 | |
1094 | bool |
1089 | bool |
1095 | rxvt_term::bg_render () |
1090 | rxvt_term::bg_render () |
1096 | { |
1091 | { |
1097 | bool transparent = false; |
|
|
1098 | |
|
|
1099 | bg_invalidate (); |
1092 | bg_invalidate (); |
1100 | # ifdef ENABLE_TRANSPARENCY |
1093 | # ifdef ENABLE_TRANSPARENCY |
1101 | if (bg_flags & BG_IS_TRANSPARENT) |
1094 | if (bg_flags & BG_IS_TRANSPARENT) |
1102 | { |
1095 | { |
1103 | /* we need to re-generate transparency pixmap in that case ! */ |
1096 | /* we need to re-generate transparency pixmap in that case ! */ |
1104 | transparent = make_transparency_pixmap (); |
1097 | if (make_transparency_pixmap ()) |
1105 | if (transparent) |
|
|
1106 | bg_flags |= BG_IS_VALID; |
1098 | bg_flags |= BG_IS_VALID; |
1107 | } |
1099 | } |
1108 | # endif |
1100 | # endif |
1109 | |
1101 | |
1110 | # ifdef BG_IMAGE_FROM_FILE |
1102 | # ifdef BG_IMAGE_FROM_FILE |
1111 | if (bg_flags & BG_IS_FROM_FILE) |
1103 | if (bg_image.flags & IM_IS_SET) |
1112 | { |
1104 | { |
1113 | if (render_image (transparent)) |
1105 | if (render_image (bg_image)) |
1114 | bg_flags |= BG_IS_VALID; |
1106 | bg_flags |= BG_IS_VALID; |
1115 | } |
1107 | } |
1116 | # endif |
1108 | # endif |
1117 | |
1109 | |
1118 | if (!(bg_flags & BG_IS_VALID)) |
1110 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1172 | lookup[i] = (tmp / 0xffff) << sh; |
1164 | lookup[i] = (tmp / 0xffff) << sh; |
1173 | } |
1165 | } |
1174 | } |
1166 | } |
1175 | |
1167 | |
1176 | void |
1168 | void |
1177 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1169 | rxvt_term::tint_ximage (XImage *ximage) |
1178 | { |
1170 | { |
1179 | unsigned int size_r, size_g, size_b; |
1171 | unsigned int size_r, size_g, size_b; |
1180 | int sh_r, sh_g, sh_b; |
1172 | int sh_r, sh_g, sh_b; |
1181 | uint32_t mask_r, mask_g, mask_b; |
1173 | uint32_t mask_r, mask_g, mask_b; |
1182 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1174 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |