… | |
… | |
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 |
63 | # ifdef BG_IMAGE_FROM_FILE |
64 | if (pixbuf) |
64 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
65 | g_object_unref (pixbuf); |
65 | bg_image->destroy (); |
66 | #endif |
66 | # endif |
67 | |
67 | |
68 | if (bg_pixmap) |
68 | if (bg_pixmap) |
69 | XFreePixmap (dpy, bg_pixmap); |
69 | XFreePixmap (dpy, bg_pixmap); |
70 | } |
70 | } |
71 | |
71 | |
… | |
… | |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
91 | return true; |
92 | # endif |
92 | # endif |
93 | |
93 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
94 | # ifdef BG_IMAGE_FROM_FILE |
95 | if (bg_flags & BG_IS_FROM_FILE) |
95 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
96 | { |
96 | { |
97 | if (bg_flags & BG_IS_SIZE_SENSITIVE) |
97 | if ((bg_image->flags & IM_IS_SIZE_SENSITIVE) |
|
|
98 | || bg_image->width () > szHint.width |
|
|
99 | || bg_image->height () > szHint.height) |
98 | return true; |
100 | return true; |
99 | } |
101 | } |
100 | # endif |
102 | # endif |
101 | |
103 | |
102 | return false; |
104 | return false; |
… | |
… | |
109 | if (bg_flags & BG_IS_TRANSPARENT) |
111 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | return true; |
112 | return true; |
111 | # endif |
113 | # endif |
112 | |
114 | |
113 | # ifdef BG_IMAGE_FROM_FILE |
115 | # ifdef BG_IMAGE_FROM_FILE |
114 | if (bg_flags & BG_IS_FROM_FILE) |
116 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
115 | { |
117 | { |
116 | if (bg_flags & BG_ROOT_ALIGN) |
118 | if (bg_image->flags & IM_ROOT_ALIGN) |
117 | return true; |
119 | return true; |
118 | } |
120 | } |
119 | # endif |
121 | # endif |
120 | |
122 | |
121 | return false; |
123 | return false; |
… | |
… | |
148 | |
150 | |
149 | min_it (dst_size, target_size - dst_pos); |
151 | min_it (dst_size, target_size - dst_pos); |
150 | return src_pos; |
152 | return src_pos; |
151 | } |
153 | } |
152 | |
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 | |
153 | bool |
190 | bool |
154 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
191 | rxvt_image::set_geometry (const char *geom, bool update) |
155 | { |
192 | { |
156 | bool changed = false; |
193 | bool changed = false; |
157 | int geom_flags = 0; |
194 | int geom_flags = 0; |
158 | int x = h_align; |
195 | int x = h_align; |
159 | int y = v_align; |
196 | int y = v_align; |
160 | unsigned int w = h_scale; |
197 | unsigned int w = h_scale; |
161 | unsigned int h = v_scale; |
198 | unsigned int h = v_scale; |
162 | unsigned long new_flags = 0; |
199 | uint8_t new_flags = 0; |
163 | |
200 | |
164 | if (geom == NULL) |
201 | if (geom == NULL) |
165 | return false; |
202 | return false; |
166 | |
203 | |
167 | if (geom[0]) |
204 | if (geom[0]) |
168 | { |
205 | { |
169 | char **arr = rxvt_strsplit (':', geom); |
206 | char **arr = rxvt_strsplit (':', geom); |
170 | |
207 | |
171 | for (int i = 0; arr[i]; i++) |
208 | for (int i = 0; arr[i]; i++) |
172 | { |
209 | { |
173 | if (!strcasecmp (arr[i], "style=tiled")) |
210 | if (!strncasecmp (arr[i], "style=", 6)) |
174 | { |
211 | { |
175 | new_flags = BG_TILE; |
212 | 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; |
213 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
179 | } |
214 | } |
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")) |
215 | else if (!strcasecmp (arr[i], "op=tile")) |
207 | new_flags |= BG_TILE; |
216 | new_flags |= IM_TILE; |
208 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
217 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
209 | new_flags |= BG_KEEP_ASPECT; |
218 | new_flags |= IM_KEEP_ASPECT; |
210 | else if (!strcasecmp (arr[i], "op=root-align")) |
219 | else if (!strcasecmp (arr[i], "op=root-align")) |
211 | new_flags |= BG_ROOT_ALIGN; |
220 | new_flags |= IM_ROOT_ALIGN; |
212 | |
221 | |
213 | // deprecated |
222 | // deprecated |
214 | else if (!strcasecmp (arr[i], "tile")) |
223 | else if (!strcasecmp (arr[i], "tile")) |
215 | { |
224 | { |
216 | new_flags |= BG_TILE; |
225 | new_flags |= IM_TILE; |
217 | w = h = noScale; |
226 | w = h = noScale; |
218 | geom_flags |= WidthValue|HeightValue; |
227 | geom_flags |= WidthValue|HeightValue; |
219 | } |
228 | } |
220 | else if (!strcasecmp (arr[i], "propscale")) |
229 | else if (!strcasecmp (arr[i], "propscale")) |
221 | { |
230 | { |
222 | new_flags |= BG_KEEP_ASPECT; |
231 | new_flags |= IM_KEEP_ASPECT; |
223 | w = h = windowScale; |
232 | w = h = windowScale; |
224 | geom_flags |= WidthValue|HeightValue; |
233 | geom_flags |= WidthValue|HeightValue; |
225 | } |
234 | } |
226 | else if (!strcasecmp (arr[i], "hscale")) |
235 | else if (!strcasecmp (arr[i], "hscale")) |
227 | { |
236 | { |
228 | new_flags |= BG_TILE; |
237 | new_flags |= IM_TILE; |
229 | w = windowScale; |
238 | w = windowScale; |
230 | h = noScale; |
239 | h = noScale; |
231 | geom_flags |= WidthValue|HeightValue; |
240 | geom_flags |= WidthValue|HeightValue; |
232 | } |
241 | } |
233 | else if (!strcasecmp (arr[i], "vscale")) |
242 | else if (!strcasecmp (arr[i], "vscale")) |
234 | { |
243 | { |
235 | new_flags |= BG_TILE; |
244 | new_flags |= IM_TILE; |
236 | h = windowScale; |
245 | h = windowScale; |
237 | w = noScale; |
246 | w = noScale; |
238 | geom_flags |= WidthValue|HeightValue; |
247 | geom_flags |= WidthValue|HeightValue; |
239 | } |
248 | } |
240 | else if (!strcasecmp (arr[i], "scale")) |
249 | else if (!strcasecmp (arr[i], "scale")) |
… | |
… | |
248 | x = y = centerAlign; |
257 | x = y = centerAlign; |
249 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
258 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
250 | } |
259 | } |
251 | else if (!strcasecmp (arr[i], "root")) |
260 | else if (!strcasecmp (arr[i], "root")) |
252 | { |
261 | { |
253 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
262 | new_flags |= IM_TILE|IM_ROOT_ALIGN; |
254 | w = h = noScale; |
263 | w = h = noScale; |
255 | geom_flags |= WidthValue|HeightValue; |
264 | geom_flags |= WidthValue|HeightValue; |
256 | } |
265 | } |
257 | |
266 | |
258 | else |
267 | else |
… | |
… | |
260 | } /* done parsing ops */ |
269 | } /* done parsing ops */ |
261 | |
270 | |
262 | rxvt_free_strsplit (arr); |
271 | rxvt_free_strsplit (arr); |
263 | } |
272 | } |
264 | |
273 | |
265 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
274 | new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
266 | |
275 | |
267 | if (!update) |
276 | if (!update) |
268 | { |
277 | { |
269 | if (!(geom_flags & XValue)) |
278 | if (!(geom_flags & XValue)) |
270 | x = y = defaultAlign; |
279 | x = y = defaultAlign; |
… | |
… | |
277 | h = w; |
286 | h = w; |
278 | else if (!(geom_flags & WidthValue)) |
287 | else if (!(geom_flags & WidthValue)) |
279 | w = h; |
288 | w = h; |
280 | } |
289 | } |
281 | |
290 | |
282 | min_it (w, 1000); |
|
|
283 | min_it (h, 1000); |
|
|
284 | clamp_it (x, -100, 200); |
291 | clamp_it (x, -100, 200); |
285 | clamp_it (y, -100, 200); |
292 | clamp_it (y, -100, 200); |
286 | |
293 | |
287 | if (bg_flags != new_flags |
294 | if (flags != new_flags |
288 | || h_scale != w |
295 | || h_scale != w |
289 | || v_scale != h |
296 | || v_scale != h |
290 | || h_align != x |
297 | || h_align != x |
291 | || v_align != y) |
298 | || v_align != y) |
292 | { |
299 | { |
293 | bg_flags = new_flags; |
300 | flags = new_flags; |
294 | h_scale = w; |
301 | h_scale = w; |
295 | v_scale = h; |
302 | v_scale = h; |
296 | h_align = x; |
303 | h_align = x; |
297 | v_align = y; |
304 | v_align = y; |
298 | changed = true; |
305 | changed = true; |
299 | } |
306 | } |
300 | |
307 | |
|
|
308 | if (!(flags & IM_TILE) |
|
|
309 | || h_scale || v_scale |
|
|
310 | || (!(flags & IM_ROOT_ALIGN) && (h_align || v_align))) |
|
|
311 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
312 | else |
|
|
313 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
314 | |
301 | return changed; |
315 | return changed; |
302 | } |
316 | } |
303 | |
317 | |
304 | void |
318 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
319 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
320 | { |
|
|
321 | int image_width = image.width (); |
|
|
322 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
323 | int target_width = szHint.width; |
308 | 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); |
309 | |
327 | |
310 | w = h_scale * target_width / 100; |
328 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
329 | h = v_scale * target_height / 100; |
312 | |
330 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
331 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
332 | { |
315 | float scale = (float)w / image_width; |
333 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
334 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
335 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
336 | h = image_height * scale + 0.5; |
319 | } |
337 | } |
320 | |
338 | |
321 | if (!w) w = image_width; |
339 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
340 | if (!h) h = image_height; |
323 | |
341 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
342 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
343 | { |
326 | x = -target_x; |
344 | x = -target_x; |
327 | y = -target_y; |
345 | y = -target_y; |
328 | } |
346 | } |
329 | else |
347 | else |
330 | { |
348 | { |
331 | x = make_align_position (h_align, target_width, w); |
349 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
350 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
351 | } |
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 | } |
352 | } |
343 | |
353 | |
344 | # ifdef HAVE_PIXBUF |
354 | # ifdef HAVE_PIXBUF |
345 | bool |
355 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
356 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | 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, |
348 | unsigned int width, unsigned int height) |
358 | unsigned int width, unsigned int height, bool argb) |
349 | { |
359 | { |
350 | XImage *ximage; |
360 | XImage *ximage; |
351 | char *line; |
361 | char *line; |
352 | int width_r, width_g, width_b, width_a; |
362 | int width_r, width_g, width_b, width_a; |
353 | int sh_r, sh_g, sh_b, sh_a; |
363 | int sh_r, sh_g, sh_b, sh_a; |
354 | uint32_t alpha_mask; |
364 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
355 | int rowstride; |
365 | int rowstride; |
356 | int channels; |
366 | int channels; |
357 | unsigned char *row; |
367 | unsigned char *row; |
358 | |
368 | |
359 | if (visual->c_class != TrueColor) |
369 | if (visual->c_class != TrueColor) |
360 | return false; |
370 | return false; |
361 | |
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; |
362 | #if XRENDER |
384 | #if XRENDER |
363 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
385 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
364 | if (format) |
386 | if (format) |
365 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
387 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
366 | else |
388 | else |
367 | #endif |
389 | #endif |
368 | alpha_mask = 0; |
390 | alpha_mask = 0; |
|
|
391 | } |
369 | |
392 | |
370 | width_r = ecb_popcount32 (visual->red_mask); |
393 | width_r = ecb_popcount32 (red_mask); |
371 | width_g = ecb_popcount32 (visual->green_mask); |
394 | width_g = ecb_popcount32 (green_mask); |
372 | width_b = ecb_popcount32 (visual->blue_mask); |
395 | width_b = ecb_popcount32 (blue_mask); |
373 | width_a = ecb_popcount32 (alpha_mask); |
396 | width_a = ecb_popcount32 (alpha_mask); |
374 | |
397 | |
375 | 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) |
376 | return false; |
399 | return false; |
377 | |
400 | |
378 | sh_r = ecb_ctz32 (visual->red_mask); |
401 | sh_r = ecb_ctz32 (red_mask); |
379 | sh_g = ecb_ctz32 (visual->green_mask); |
402 | sh_g = ecb_ctz32 (green_mask); |
380 | sh_b = ecb_ctz32 (visual->blue_mask); |
403 | sh_b = ecb_ctz32 (blue_mask); |
381 | sh_a = ecb_ctz32 (alpha_mask); |
404 | sh_a = ecb_ctz32 (alpha_mask); |
382 | |
405 | |
383 | if (width > 32767 || height > 32767) |
406 | if (width > 32767 || height > 32767) |
384 | return false; |
407 | return false; |
385 | |
408 | |
386 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0, |
409 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
387 | width, height, 32, 0); |
410 | width, height, 32, 0); |
388 | if (!ximage) |
411 | if (!ximage) |
389 | return false; |
412 | return false; |
390 | |
413 | |
391 | if (height > INT_MAX / ximage->bytes_per_line |
414 | if (height > INT_MAX / ximage->bytes_per_line |
… | |
… | |
454 | XDestroyImage (ximage); |
477 | XDestroyImage (ximage); |
455 | return true; |
478 | return true; |
456 | } |
479 | } |
457 | |
480 | |
458 | bool |
481 | bool |
459 | rxvt_term::render_image (bool transparent) |
482 | rxvt_term::render_image (rxvt_image &image) |
460 | { |
483 | { |
|
|
484 | GdkPixbuf *pixbuf = image.pixbuf; |
461 | if (!pixbuf) |
485 | if (!pixbuf) |
462 | return false; |
486 | return false; |
463 | |
487 | |
464 | if (transparent |
488 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
489 | |
|
|
490 | if (need_blend |
465 | && !(bg_flags & BG_HAS_RENDER)) |
491 | && !(bg_flags & BG_HAS_RENDER)) |
466 | return false; |
492 | return false; |
467 | |
493 | |
468 | GdkPixbuf *result; |
494 | GdkPixbuf *result; |
469 | |
495 | |
… | |
… | |
478 | int x = 0; |
504 | int x = 0; |
479 | int y = 0; |
505 | int y = 0; |
480 | int w = 0; |
506 | int w = 0; |
481 | int h = 0; |
507 | int h = 0; |
482 | |
508 | |
483 | get_image_geometry (image_width, image_height, w, h, x, y); |
509 | get_image_geometry (image, w, h, x, y); |
484 | |
510 | |
485 | if (!(bg_flags & BG_ROOT_ALIGN) |
511 | if (!(image.flags & IM_ROOT_ALIGN) |
486 | && (x >= target_width |
512 | && (x >= target_width |
487 | || y >= target_height |
513 | || y >= target_height |
488 | || x + w <= 0 |
514 | || x + w <= 0 |
489 | || y + h <= 0)) |
515 | || y + h <= 0)) |
490 | return false; |
516 | return false; |
… | |
… | |
504 | |
530 | |
505 | bool ret = false; |
531 | bool ret = false; |
506 | |
532 | |
507 | XGCValues gcv; |
533 | XGCValues gcv; |
508 | GC gc; |
534 | GC gc; |
509 | Pixmap root_pmap; |
535 | Pixmap tmp_pixmap; |
510 | |
536 | |
511 | image_width = gdk_pixbuf_get_width (result); |
537 | image_width = gdk_pixbuf_get_width (result); |
512 | image_height = gdk_pixbuf_get_height (result); |
538 | image_height = gdk_pixbuf_get_height (result); |
513 | |
539 | |
514 | if (transparent) |
540 | if (need_blend) |
515 | { |
541 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
516 | root_pmap = bg_pixmap; |
|
|
517 | bg_pixmap = None; |
|
|
518 | } |
|
|
519 | else |
542 | else |
520 | { |
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. |
521 | if (bg_flags & BG_TILE) |
547 | if ((image.flags & IM_TILE) |
|
|
548 | && image_vec.size () == 1) |
522 | { |
549 | { |
523 | new_pmap_width = min (image_width, target_width); |
550 | new_pmap_width = min (image_width, target_width); |
524 | new_pmap_height = min (image_height, target_height); |
551 | new_pmap_height = min (image_height, target_height); |
525 | } |
552 | } |
526 | } |
|
|
527 | |
553 | |
528 | if (bg_pixmap == None |
554 | if (bg_pixmap == None |
529 | || bg_pmap_width != new_pmap_width |
555 | || bg_pmap_width != new_pmap_width |
530 | || bg_pmap_height != new_pmap_height) |
556 | || bg_pmap_height != new_pmap_height) |
531 | { |
557 | { |
532 | if (bg_pixmap) |
558 | if (bg_pixmap) |
533 | XFreePixmap (dpy, bg_pixmap); |
559 | XFreePixmap (dpy, bg_pixmap); |
534 | 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); |
535 | bg_pmap_width = new_pmap_width; |
561 | bg_pmap_width = new_pmap_width; |
536 | bg_pmap_height = new_pmap_height; |
562 | bg_pmap_height = new_pmap_height; |
|
|
563 | } |
|
|
564 | |
|
|
565 | tmp_pixmap = bg_pixmap; |
537 | } |
566 | } |
538 | |
567 | |
539 | gcv.foreground = pix_colors[Color_bg]; |
568 | gcv.foreground = pix_colors[Color_bg]; |
540 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
569 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
541 | |
570 | |
542 | if (gc) |
571 | if (gc) |
543 | { |
572 | { |
544 | if (bg_flags & BG_TILE) |
573 | if (image.flags & IM_TILE) |
545 | { |
574 | { |
546 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
575 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
547 | pixbuf_to_pixmap (result, tile, gc, |
576 | pixbuf_to_pixmap (result, tile, gc, |
548 | 0, 0, |
577 | 0, 0, |
549 | 0, 0, |
578 | 0, 0, |
550 | image_width, image_height); |
579 | image_width, image_height, need_blend); |
551 | |
580 | |
552 | gcv.tile = tile; |
581 | gcv.tile = tile; |
553 | gcv.fill_style = FillTiled; |
582 | gcv.fill_style = FillTiled; |
554 | gcv.ts_x_origin = x; |
583 | gcv.ts_x_origin = x; |
555 | gcv.ts_y_origin = y; |
584 | gcv.ts_y_origin = y; |
556 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
585 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
557 | |
586 | |
558 | 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); |
559 | XFreePixmap (dpy, tile); |
588 | XFreePixmap (dpy, tile); |
560 | } |
589 | } |
561 | else |
590 | else |
562 | { |
591 | { |
563 | int src_x, src_y, dst_x, dst_y; |
592 | 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); |
596 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
568 | |
597 | |
569 | if (dst_x > 0 || dst_y > 0 |
598 | if (dst_x > 0 || dst_y > 0 |
570 | || dst_x + dst_width < new_pmap_width |
599 | || dst_x + dst_width < new_pmap_width |
571 | || dst_y + dst_height < new_pmap_height) |
600 | || dst_y + dst_height < new_pmap_height) |
572 | 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); |
573 | |
602 | |
574 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
603 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
575 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
604 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
576 | src_x, src_y, |
605 | src_x, src_y, |
577 | dst_x, dst_y, |
606 | dst_x, dst_y, |
578 | dst_width, dst_height); |
607 | dst_width, dst_height, need_blend); |
579 | } |
608 | } |
580 | |
609 | |
581 | #if XRENDER |
610 | #if XRENDER |
582 | if (transparent) |
611 | if (need_blend) |
583 | { |
612 | { |
|
|
613 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
584 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
614 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
585 | |
615 | |
586 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
616 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
587 | |
617 | |
588 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
618 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
589 | |
619 | |
590 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
620 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
591 | |
621 | |
592 | XRenderColor mask_c; |
622 | XRenderColor mask_c; |
593 | |
623 | |
594 | mask_c.alpha = 0x8000; |
624 | mask_c.alpha = image.alpha; |
595 | mask_c.red = |
625 | mask_c.red = |
596 | mask_c.green = |
626 | mask_c.green = |
597 | mask_c.blue = 0; |
627 | mask_c.blue = 0; |
598 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
628 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
599 | |
629 | |
… | |
… | |
611 | } |
641 | } |
612 | |
642 | |
613 | if (result != pixbuf) |
643 | if (result != pixbuf) |
614 | g_object_unref (result); |
644 | g_object_unref (result); |
615 | |
645 | |
616 | if (transparent) |
646 | if (need_blend) |
617 | XFreePixmap (dpy, root_pmap); |
647 | XFreePixmap (dpy, tmp_pixmap); |
618 | |
648 | |
619 | return ret; |
649 | return ret; |
620 | } |
650 | } |
621 | # endif /* HAVE_PIXBUF */ |
651 | # endif /* HAVE_PIXBUF */ |
622 | |
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 = 0xffff; |
|
|
689 | flags = 0; |
|
|
690 | h_scale = |
|
|
691 | v_scale = defaultScale; |
|
|
692 | h_align = |
|
|
693 | v_align = defaultAlign; |
|
|
694 | |
|
|
695 | # ifdef HAVE_PIXBUF |
|
|
696 | pixbuf = 0; |
|
|
697 | # endif |
|
|
698 | } |
|
|
699 | |
623 | bool |
700 | bool |
624 | rxvt_term::bg_set_file (const char *file) |
701 | rxvt_image::set_file_geometry (const char *file) |
625 | { |
702 | { |
626 | if (!file || !*file) |
703 | if (!file || !*file) |
627 | return false; |
704 | return false; |
628 | |
705 | |
629 | bool ret = false; |
|
|
630 | const char *p = strchr (file, ';'); |
706 | const char *p = strchr (file, ';'); |
631 | |
707 | |
632 | if (p) |
708 | if (p) |
633 | { |
709 | { |
634 | size_t len = p - file; |
710 | size_t len = p - file; |
… | |
… | |
636 | memcpy (f, file, len); |
712 | memcpy (f, file, len); |
637 | f[len] = '\0'; |
713 | f[len] = '\0'; |
638 | file = f; |
714 | file = f; |
639 | } |
715 | } |
640 | |
716 | |
|
|
717 | bool ret = set_file (file); |
|
|
718 | alpha = 0x8000; |
|
|
719 | if (ret) |
|
|
720 | set_geometry (p ? p + 1 : ""); |
|
|
721 | return ret; |
|
|
722 | } |
|
|
723 | |
|
|
724 | bool |
|
|
725 | rxvt_image::set_file (const char *file) |
|
|
726 | { |
|
|
727 | bool ret = false; |
|
|
728 | |
641 | # ifdef HAVE_PIXBUF |
729 | # ifdef HAVE_PIXBUF |
642 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
730 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
643 | if (image) |
731 | if (image) |
644 | { |
732 | { |
645 | if (pixbuf) |
733 | if (pixbuf) |
646 | g_object_unref (pixbuf); |
734 | g_object_unref (pixbuf); |
647 | pixbuf = image; |
735 | pixbuf = image; |
648 | bg_flags |= BG_IS_FROM_FILE; |
|
|
649 | ret = true; |
736 | ret = true; |
650 | } |
737 | } |
651 | # endif |
738 | # endif |
652 | |
739 | |
653 | if (ret) |
740 | if (ret) |
654 | { |
741 | flags |= IM_IS_SET; |
655 | if (p) |
|
|
656 | bg_set_geometry (p + 1); |
|
|
657 | else |
|
|
658 | bg_set_default_geometry (); |
|
|
659 | } |
|
|
660 | |
742 | |
661 | return ret; |
743 | return ret; |
662 | } |
744 | } |
663 | |
745 | |
664 | # endif /* BG_IMAGE_FROM_FILE */ |
746 | # endif /* BG_IMAGE_FROM_FILE */ |
… | |
… | |
758 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
840 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
759 | } |
841 | } |
760 | #endif |
842 | #endif |
761 | |
843 | |
762 | bool |
844 | bool |
763 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
845 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
764 | { |
846 | { |
765 | bool ret = false; |
847 | bool ret = false; |
766 | #if XRENDER |
848 | #if XRENDER |
767 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
849 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
768 | return false; |
850 | return false; |
… | |
… | |
823 | #endif |
905 | #endif |
824 | return ret; |
906 | return ret; |
825 | } |
907 | } |
826 | |
908 | |
827 | bool |
909 | bool |
828 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
910 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
829 | { |
911 | { |
830 | bool ret = false; |
912 | bool ret = false; |
831 | |
913 | |
832 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
914 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
833 | { |
915 | { |
… | |
… | |
1020 | |
1102 | |
1021 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1103 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1022 | { |
1104 | { |
1023 | if (need_blur) |
1105 | if (need_blur) |
1024 | { |
1106 | { |
1025 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1107 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
1026 | need_blur = false; |
1108 | need_blur = false; |
1027 | } |
1109 | } |
1028 | if (need_tint) |
1110 | if (need_tint) |
1029 | { |
1111 | { |
1030 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1112 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1031 | need_tint = false; |
1113 | need_tint = false; |
1032 | } |
1114 | } |
1033 | if (need_tint) |
1115 | if (need_tint) |
1034 | { |
1116 | { |
1035 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1117 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1036 | if (ximage) |
1118 | if (ximage) |
1037 | { |
1119 | { |
1038 | /* our own client-side tinting */ |
1120 | /* our own client-side tinting */ |
1039 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
1121 | tint_ximage (ximage); |
1040 | |
1122 | |
1041 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1123 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1042 | XDestroyImage (ximage); |
1124 | XDestroyImage (ximage); |
1043 | } |
1125 | } |
1044 | } |
1126 | } |
… | |
… | |
1065 | # endif /* ENABLE_TRANSPARENCY */ |
1147 | # endif /* ENABLE_TRANSPARENCY */ |
1066 | |
1148 | |
1067 | bool |
1149 | bool |
1068 | rxvt_term::bg_render () |
1150 | rxvt_term::bg_render () |
1069 | { |
1151 | { |
1070 | bool transparent = false; |
|
|
1071 | |
|
|
1072 | bg_invalidate (); |
1152 | bg_invalidate (); |
1073 | # ifdef ENABLE_TRANSPARENCY |
1153 | # ifdef ENABLE_TRANSPARENCY |
1074 | if (bg_flags & BG_IS_TRANSPARENT) |
1154 | if (bg_flags & BG_IS_TRANSPARENT) |
1075 | { |
1155 | { |
1076 | /* we need to re-generate transparency pixmap in that case ! */ |
1156 | /* we need to re-generate transparency pixmap in that case ! */ |
1077 | transparent = make_transparency_pixmap (); |
1157 | if (make_transparency_pixmap ()) |
1078 | if (transparent) |
|
|
1079 | bg_flags |= BG_IS_VALID; |
1158 | bg_flags |= BG_IS_VALID; |
1080 | } |
1159 | } |
1081 | # endif |
1160 | # endif |
1082 | |
1161 | |
1083 | # ifdef BG_IMAGE_FROM_FILE |
1162 | # ifdef BG_IMAGE_FROM_FILE |
1084 | if (bg_flags & BG_IS_FROM_FILE) |
1163 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1085 | { |
1164 | { |
1086 | if (render_image (transparent)) |
1165 | if (render_image (*bg_image)) |
1087 | bg_flags |= BG_IS_VALID; |
1166 | bg_flags |= BG_IS_VALID; |
1088 | } |
1167 | } |
1089 | # endif |
1168 | # endif |
1090 | |
1169 | |
1091 | if (!(bg_flags & BG_IS_VALID)) |
1170 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1125 | bg_flags |= BG_HAS_RENDER_CONV; |
1204 | bg_flags |= BG_HAS_RENDER_CONV; |
1126 | |
1205 | |
1127 | XFree (filters); |
1206 | XFree (filters); |
1128 | } |
1207 | } |
1129 | #endif |
1208 | #endif |
|
|
1209 | |
|
|
1210 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1211 | if (rs[Rs_backgroundPixmap]) |
|
|
1212 | { |
|
|
1213 | rxvt_image *image = new_image (); |
|
|
1214 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1215 | image_vec.pop_back (); |
|
|
1216 | } |
|
|
1217 | |
|
|
1218 | # ifndef NO_RESOURCES |
|
|
1219 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1220 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1221 | while (bg_image != image_vec.end ()) |
|
|
1222 | { |
|
|
1223 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1224 | bg_image = image_vec.erase (bg_image); |
|
|
1225 | else |
|
|
1226 | bg_image++; |
|
|
1227 | } |
|
|
1228 | # endif |
|
|
1229 | |
|
|
1230 | if (image_vec.size () > 0 |
|
|
1231 | && !bg_window_position_sensitive ()) |
|
|
1232 | update_background (); |
|
|
1233 | #endif |
1130 | } |
1234 | } |
1131 | |
1235 | |
1132 | #endif /* HAVE_BG_PIXMAP */ |
1236 | #endif /* HAVE_BG_PIXMAP */ |
1133 | |
1237 | |
1134 | #ifdef ENABLE_TRANSPARENCY |
1238 | #ifdef ENABLE_TRANSPARENCY |
… | |
… | |
1145 | lookup[i] = (tmp / 0xffff) << sh; |
1249 | lookup[i] = (tmp / 0xffff) << sh; |
1146 | } |
1250 | } |
1147 | } |
1251 | } |
1148 | |
1252 | |
1149 | void |
1253 | void |
1150 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1254 | rxvt_term::tint_ximage (XImage *ximage) |
1151 | { |
1255 | { |
1152 | unsigned int size_r, size_g, size_b; |
1256 | unsigned int size_r, size_g, size_b; |
1153 | int sh_r, sh_g, sh_b; |
1257 | int sh_r, sh_g, sh_b; |
1154 | uint32_t mask_r, mask_g, mask_b; |
1258 | uint32_t mask_r, mask_g, mask_b; |
1155 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1259 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |