… | |
… | |
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 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
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 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
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 | { |
|
|
539 | // optimise bg pixmap size when tiling, but only if there are no |
|
|
540 | // other pixbufs to render. Otherwise, the bg pixmap size must |
|
|
541 | // be equal to the window size. |
521 | if (bg_flags & BG_TILE) |
542 | if ((image.flags & IM_TILE) |
|
|
543 | && image_vec.size () == 1) |
522 | { |
544 | { |
523 | new_pmap_width = min (image_width, target_width); |
545 | new_pmap_width = min (image_width, target_width); |
524 | new_pmap_height = min (image_height, target_height); |
546 | new_pmap_height = min (image_height, target_height); |
525 | } |
547 | } |
526 | } |
|
|
527 | |
548 | |
528 | if (bg_pixmap == None |
549 | if (bg_pixmap == None |
529 | || bg_pmap_width != new_pmap_width |
550 | || bg_pmap_width != new_pmap_width |
530 | || bg_pmap_height != new_pmap_height) |
551 | || bg_pmap_height != new_pmap_height) |
531 | { |
552 | { |
532 | if (bg_pixmap) |
553 | if (bg_pixmap) |
533 | XFreePixmap (dpy, bg_pixmap); |
554 | XFreePixmap (dpy, bg_pixmap); |
534 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
555 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
535 | bg_pmap_width = new_pmap_width; |
556 | bg_pmap_width = new_pmap_width; |
536 | bg_pmap_height = new_pmap_height; |
557 | bg_pmap_height = new_pmap_height; |
|
|
558 | } |
|
|
559 | |
|
|
560 | tmp_pixmap = bg_pixmap; |
537 | } |
561 | } |
538 | |
562 | |
539 | gcv.foreground = pix_colors[Color_bg]; |
563 | gcv.foreground = pix_colors[Color_bg]; |
540 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
564 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
541 | |
565 | |
542 | if (gc) |
566 | if (gc) |
543 | { |
567 | { |
544 | if (bg_flags & BG_TILE) |
568 | if (image.flags & IM_TILE) |
545 | { |
569 | { |
546 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
570 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
547 | pixbuf_to_pixmap (result, tile, gc, |
571 | pixbuf_to_pixmap (result, tile, gc, |
548 | 0, 0, |
572 | 0, 0, |
549 | 0, 0, |
573 | 0, 0, |
550 | image_width, image_height); |
574 | image_width, image_height, need_blend); |
551 | |
575 | |
552 | gcv.tile = tile; |
576 | gcv.tile = tile; |
553 | gcv.fill_style = FillTiled; |
577 | gcv.fill_style = FillTiled; |
554 | gcv.ts_x_origin = x; |
578 | gcv.ts_x_origin = x; |
555 | gcv.ts_y_origin = y; |
579 | gcv.ts_y_origin = y; |
556 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
580 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
557 | |
581 | |
558 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
582 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
559 | XFreePixmap (dpy, tile); |
583 | XFreePixmap (dpy, tile); |
560 | } |
584 | } |
561 | else |
585 | else |
562 | { |
586 | { |
563 | int src_x, src_y, dst_x, dst_y; |
587 | 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); |
591 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
568 | |
592 | |
569 | if (dst_x > 0 || dst_y > 0 |
593 | if (dst_x > 0 || dst_y > 0 |
570 | || dst_x + dst_width < new_pmap_width |
594 | || dst_x + dst_width < new_pmap_width |
571 | || dst_y + dst_height < new_pmap_height) |
595 | || dst_y + dst_height < new_pmap_height) |
572 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
596 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
573 | |
597 | |
574 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
598 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
575 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
599 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
576 | src_x, src_y, |
600 | src_x, src_y, |
577 | dst_x, dst_y, |
601 | dst_x, dst_y, |
578 | dst_width, dst_height); |
602 | dst_width, dst_height, need_blend); |
579 | } |
603 | } |
580 | |
604 | |
581 | #if XRENDER |
605 | #if XRENDER |
582 | if (transparent) |
606 | if (need_blend) |
583 | { |
607 | { |
|
|
608 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
584 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
609 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
585 | |
610 | |
586 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
611 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
587 | |
612 | |
588 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
613 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
589 | |
614 | |
590 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
615 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
591 | |
616 | |
592 | XRenderColor mask_c; |
617 | XRenderColor mask_c; |
593 | |
618 | |
594 | mask_c.alpha = 0x8000; |
619 | mask_c.alpha = gdk_pixbuf_get_has_alpha (image.pixbuf) ? 0xffff : image.alpha; |
595 | mask_c.red = |
620 | mask_c.red = |
596 | mask_c.green = |
621 | mask_c.green = |
597 | mask_c.blue = 0; |
622 | mask_c.blue = 0; |
598 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
623 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
599 | |
624 | |
… | |
… | |
611 | } |
636 | } |
612 | |
637 | |
613 | if (result != pixbuf) |
638 | if (result != pixbuf) |
614 | g_object_unref (result); |
639 | g_object_unref (result); |
615 | |
640 | |
616 | if (transparent) |
641 | if (need_blend) |
617 | XFreePixmap (dpy, root_pmap); |
642 | XFreePixmap (dpy, tmp_pixmap); |
618 | |
643 | |
619 | return ret; |
644 | return ret; |
620 | } |
645 | } |
621 | # endif /* HAVE_PIXBUF */ |
646 | # endif /* HAVE_PIXBUF */ |
622 | |
647 | |
|
|
648 | # ifndef NO_RESOURCES |
|
|
649 | static int |
|
|
650 | rxvt_define_image (XrmDatabase *database ecb_unused, |
|
|
651 | XrmBindingList bindings ecb_unused, |
|
|
652 | XrmQuarkList quarks, |
|
|
653 | XrmRepresentation *type ecb_unused, |
|
|
654 | XrmValue *value, |
|
|
655 | XPointer closure ecb_unused) |
|
|
656 | { |
|
|
657 | int size; |
|
|
658 | |
|
|
659 | for (size = 0; quarks[size] != NULLQUARK; size++) |
|
|
660 | ; |
|
|
661 | |
|
|
662 | if (size >= 2) |
|
|
663 | { |
|
|
664 | int id = strtol (XrmQuarkToString (quarks[size-2]), 0, 0); |
|
|
665 | if (id >= 1) |
|
|
666 | GET_R->parse_image (id, XrmQuarkToString (quarks[size-1]), (char *)value->addr); |
|
|
667 | } |
|
|
668 | return False; |
|
|
669 | } |
|
|
670 | |
|
|
671 | void |
|
|
672 | rxvt_term::parse_image (int id, const char *type, const char *arg) |
|
|
673 | { |
|
|
674 | rxvt_image *image; |
|
|
675 | |
|
|
676 | for (image = image_vec.begin (); image < image_vec.end (); image++) |
|
|
677 | if (image->id == id) |
|
|
678 | break; |
|
|
679 | |
|
|
680 | if (image == image_vec.end ()) |
|
|
681 | { |
|
|
682 | image = new_image (); |
|
|
683 | image->id = id; |
|
|
684 | } |
|
|
685 | } |
|
|
686 | # endif |
|
|
687 | |
|
|
688 | rxvt_image::rxvt_image () |
|
|
689 | { |
|
|
690 | id = |
|
|
691 | alpha = |
|
|
692 | flags = |
|
|
693 | h_scale = |
|
|
694 | v_scale = |
|
|
695 | h_align = |
|
|
696 | v_align = 0; |
|
|
697 | |
|
|
698 | # ifdef HAVE_PIXBUF |
|
|
699 | pixbuf.reset (0); |
|
|
700 | # endif |
|
|
701 | } |
|
|
702 | |
623 | bool |
703 | bool |
624 | rxvt_term::bg_set_file (const char *file) |
704 | rxvt_image::set_file_geometry (const char *file) |
625 | { |
705 | { |
626 | if (!file || !*file) |
706 | if (!file || !*file) |
627 | return false; |
707 | return false; |
628 | |
708 | |
629 | bool ret = false; |
|
|
630 | const char *p = strchr (file, ';'); |
709 | const char *p = strchr (file, ';'); |
631 | |
710 | |
632 | if (p) |
711 | if (p) |
633 | { |
712 | { |
634 | size_t len = p - file; |
713 | size_t len = p - file; |
… | |
… | |
636 | memcpy (f, file, len); |
715 | memcpy (f, file, len); |
637 | f[len] = '\0'; |
716 | f[len] = '\0'; |
638 | file = f; |
717 | file = f; |
639 | } |
718 | } |
640 | |
719 | |
|
|
720 | bool ret = set_file (file); |
|
|
721 | alpha = 0x8000; |
|
|
722 | if (ret && p) |
|
|
723 | set_geometry (p + 1); |
|
|
724 | return ret; |
|
|
725 | } |
|
|
726 | |
|
|
727 | bool |
|
|
728 | rxvt_image::set_file (const char *file) |
|
|
729 | { |
|
|
730 | bool ret = false; |
|
|
731 | |
641 | # ifdef HAVE_PIXBUF |
732 | # ifdef HAVE_PIXBUF |
642 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
733 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
643 | if (image) |
734 | if (image) |
644 | { |
735 | { |
645 | if (pixbuf) |
736 | if (pixbuf) |
646 | g_object_unref (pixbuf); |
737 | g_object_unref (pixbuf); |
647 | pixbuf = image; |
738 | pixbuf.reset (image); |
648 | bg_flags |= BG_IS_FROM_FILE; |
|
|
649 | ret = true; |
739 | ret = true; |
650 | } |
740 | } |
651 | # endif |
741 | # endif |
652 | |
742 | |
653 | if (ret) |
743 | if (ret) |
654 | { |
744 | { |
655 | if (p) |
745 | alpha = 0xffff; |
656 | bg_set_geometry (p + 1); |
746 | flags = IM_IS_SET | IM_IS_SIZE_SENSITIVE; |
657 | else |
747 | h_scale = v_scale = defaultScale; |
658 | bg_set_default_geometry (); |
748 | h_align = v_align = defaultAlign; |
659 | } |
749 | } |
660 | |
750 | |
661 | return ret; |
751 | return ret; |
662 | } |
752 | } |
663 | |
753 | |
… | |
… | |
758 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
848 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
759 | } |
849 | } |
760 | #endif |
850 | #endif |
761 | |
851 | |
762 | bool |
852 | bool |
763 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
853 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height) |
764 | { |
854 | { |
765 | bool ret = false; |
855 | bool ret = false; |
766 | #if XRENDER |
856 | #if XRENDER |
767 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
857 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
768 | return false; |
858 | return false; |
… | |
… | |
823 | #endif |
913 | #endif |
824 | return ret; |
914 | return ret; |
825 | } |
915 | } |
826 | |
916 | |
827 | bool |
917 | bool |
828 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
918 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height) |
829 | { |
919 | { |
830 | bool ret = false; |
920 | bool ret = false; |
831 | |
921 | |
832 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
922 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
833 | { |
923 | { |
… | |
… | |
1020 | |
1110 | |
1021 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1111 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1022 | { |
1112 | { |
1023 | if (need_blur) |
1113 | if (need_blur) |
1024 | { |
1114 | { |
1025 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1115 | if (blur_pixmap (bg_pixmap, window_width, window_height)) |
1026 | need_blur = false; |
1116 | need_blur = false; |
1027 | } |
1117 | } |
1028 | if (need_tint) |
1118 | if (need_tint) |
1029 | { |
1119 | { |
1030 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1120 | if (tint_pixmap (bg_pixmap, window_width, window_height)) |
1031 | need_tint = false; |
1121 | need_tint = false; |
1032 | } |
1122 | } |
1033 | if (need_tint) |
1123 | if (need_tint) |
1034 | { |
1124 | { |
1035 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1125 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1036 | if (ximage) |
1126 | if (ximage) |
1037 | { |
1127 | { |
1038 | /* our own client-side tinting */ |
1128 | /* our own client-side tinting */ |
1039 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
1129 | tint_ximage (ximage); |
1040 | |
1130 | |
1041 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1131 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
1042 | XDestroyImage (ximage); |
1132 | XDestroyImage (ximage); |
1043 | } |
1133 | } |
1044 | } |
1134 | } |
… | |
… | |
1065 | # endif /* ENABLE_TRANSPARENCY */ |
1155 | # endif /* ENABLE_TRANSPARENCY */ |
1066 | |
1156 | |
1067 | bool |
1157 | bool |
1068 | rxvt_term::bg_render () |
1158 | rxvt_term::bg_render () |
1069 | { |
1159 | { |
1070 | bool transparent = false; |
|
|
1071 | |
|
|
1072 | bg_invalidate (); |
1160 | bg_invalidate (); |
1073 | # ifdef ENABLE_TRANSPARENCY |
1161 | # ifdef ENABLE_TRANSPARENCY |
1074 | if (bg_flags & BG_IS_TRANSPARENT) |
1162 | if (bg_flags & BG_IS_TRANSPARENT) |
1075 | { |
1163 | { |
1076 | /* we need to re-generate transparency pixmap in that case ! */ |
1164 | /* we need to re-generate transparency pixmap in that case ! */ |
1077 | transparent = make_transparency_pixmap (); |
1165 | if (make_transparency_pixmap ()) |
1078 | if (transparent) |
|
|
1079 | bg_flags |= BG_IS_VALID; |
1166 | bg_flags |= BG_IS_VALID; |
1080 | } |
1167 | } |
1081 | # endif |
1168 | # endif |
1082 | |
1169 | |
1083 | # ifdef BG_IMAGE_FROM_FILE |
1170 | # ifdef BG_IMAGE_FROM_FILE |
1084 | if (bg_flags & BG_IS_FROM_FILE) |
1171 | for (vector<rxvt_image>::iterator bg_image = image_vec.begin (); bg_image < image_vec.end (); bg_image++) |
1085 | { |
1172 | { |
1086 | if (render_image (transparent)) |
1173 | if (render_image (*bg_image)) |
1087 | bg_flags |= BG_IS_VALID; |
1174 | bg_flags |= BG_IS_VALID; |
1088 | } |
1175 | } |
1089 | # endif |
1176 | # endif |
1090 | |
1177 | |
1091 | if (!(bg_flags & BG_IS_VALID)) |
1178 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1125 | bg_flags |= BG_HAS_RENDER_CONV; |
1212 | bg_flags |= BG_HAS_RENDER_CONV; |
1126 | |
1213 | |
1127 | XFree (filters); |
1214 | XFree (filters); |
1128 | } |
1215 | } |
1129 | #endif |
1216 | #endif |
|
|
1217 | |
|
|
1218 | #ifdef BG_IMAGE_FROM_FILE |
|
|
1219 | if (rs[Rs_backgroundPixmap]) |
|
|
1220 | { |
|
|
1221 | rxvt_image *image = new_image (); |
|
|
1222 | if (!image->set_file_geometry (rs[Rs_backgroundPixmap])) |
|
|
1223 | image_vec.pop_back (); |
|
|
1224 | } |
|
|
1225 | |
|
|
1226 | # ifndef NO_RESOURCES |
|
|
1227 | find_resources ("image", "Image", XrmEnumAllLevels, rxvt_define_image); |
|
|
1228 | vector<rxvt_image>::iterator bg_image = image_vec.begin (); |
|
|
1229 | while (bg_image != image_vec.end ()) |
|
|
1230 | { |
|
|
1231 | if (!(bg_image->flags & IM_IS_SET)) |
|
|
1232 | bg_image = image_vec.erase (bg_image); |
|
|
1233 | else |
|
|
1234 | bg_image++; |
|
|
1235 | } |
|
|
1236 | # endif |
|
|
1237 | |
|
|
1238 | if (image_vec.size () > 0 |
|
|
1239 | && !bg_window_position_sensitive ()) |
|
|
1240 | update_background (); |
|
|
1241 | #endif |
1130 | } |
1242 | } |
1131 | |
1243 | |
1132 | #endif /* HAVE_BG_PIXMAP */ |
1244 | #endif /* HAVE_BG_PIXMAP */ |
1133 | |
1245 | |
1134 | #ifdef ENABLE_TRANSPARENCY |
1246 | #ifdef ENABLE_TRANSPARENCY |
… | |
… | |
1145 | lookup[i] = (tmp / 0xffff) << sh; |
1257 | lookup[i] = (tmp / 0xffff) << sh; |
1146 | } |
1258 | } |
1147 | } |
1259 | } |
1148 | |
1260 | |
1149 | void |
1261 | void |
1150 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1262 | rxvt_term::tint_ximage (XImage *ximage) |
1151 | { |
1263 | { |
1152 | unsigned int size_r, size_g, size_b; |
1264 | unsigned int size_r, size_g, size_b; |
1153 | int sh_r, sh_g, sh_b; |
1265 | int sh_r, sh_g, sh_b; |
1154 | uint32_t mask_r, mask_g, mask_b; |
1266 | uint32_t mask_r, mask_g, mask_b; |
1155 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1267 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |