… | |
… | |
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 | # if BG_IMAGE_FROM_FILE |
64 | if (pixbuf) |
64 | fimage.destroy (); |
65 | g_object_unref (pixbuf); |
|
|
66 | #endif |
65 | # endif |
67 | |
66 | |
68 | if (bg_pixmap) |
67 | if (bg_pixmap) |
69 | XFreePixmap (dpy, bg_pixmap); |
68 | XFreePixmap (dpy, bg_pixmap); |
70 | } |
69 | } |
71 | |
70 | |
… | |
… | |
84 | } |
83 | } |
85 | |
84 | |
86 | bool |
85 | bool |
87 | rxvt_term::bg_window_size_sensitive () |
86 | rxvt_term::bg_window_size_sensitive () |
88 | { |
87 | { |
89 | # ifdef ENABLE_TRANSPARENCY |
88 | # if ENABLE_TRANSPARENCY |
90 | if (bg_flags & BG_IS_TRANSPARENT) |
89 | if (bg_flags & BG_IS_TRANSPARENT) |
91 | return true; |
90 | return true; |
92 | # endif |
91 | # endif |
93 | |
92 | |
94 | # ifdef BG_IMAGE_FROM_FILE |
93 | # if BG_IMAGE_FROM_FILE |
95 | if (bg_flags & BG_IS_FROM_FILE) |
94 | if (fimage.flags & IM_IS_SET) |
96 | { |
95 | { |
97 | if (bg_flags & BG_IS_SIZE_SENSITIVE) |
96 | if ((fimage.flags & IM_IS_SIZE_SENSITIVE) |
|
|
97 | || fimage.width () > szHint.width |
|
|
98 | || fimage.height () > szHint.height) |
98 | return true; |
99 | return true; |
99 | } |
100 | } |
100 | # endif |
101 | # endif |
101 | |
102 | |
102 | return false; |
103 | return false; |
103 | } |
104 | } |
104 | |
105 | |
105 | bool |
106 | bool |
106 | rxvt_term::bg_window_position_sensitive () |
107 | rxvt_term::bg_window_position_sensitive () |
107 | { |
108 | { |
108 | # ifdef ENABLE_TRANSPARENCY |
109 | # if ENABLE_TRANSPARENCY |
109 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | if (bg_flags & BG_IS_TRANSPARENT) |
110 | return true; |
111 | return true; |
111 | # endif |
112 | # endif |
112 | |
113 | |
113 | # ifdef BG_IMAGE_FROM_FILE |
114 | # if BG_IMAGE_FROM_FILE |
114 | if (bg_flags & BG_IS_FROM_FILE) |
115 | if (fimage.flags & IM_IS_SET) |
115 | { |
116 | { |
116 | if (bg_flags & BG_ROOT_ALIGN) |
117 | if (fimage.flags & IM_ROOT_ALIGN) |
117 | return true; |
118 | return true; |
118 | } |
119 | } |
119 | # endif |
120 | # endif |
120 | |
121 | |
121 | return false; |
122 | return false; |
122 | } |
123 | } |
123 | |
124 | |
124 | # ifdef BG_IMAGE_FROM_FILE |
125 | # if BG_IMAGE_FROM_FILE |
125 | static inline int |
126 | static inline int |
126 | make_align_position (int align, int window_size, int image_size) |
127 | make_align_position (int align, int window_size, int image_size) |
127 | { |
128 | { |
128 | if (align >= 0 && align <= 100) |
129 | if (align >= 0 && align <= 100) |
129 | return lerp (0, window_size - image_size, align); |
130 | return lerp (0, window_size - image_size, align); |
… | |
… | |
148 | |
149 | |
149 | min_it (dst_size, target_size - dst_pos); |
150 | min_it (dst_size, target_size - dst_pos); |
150 | return src_pos; |
151 | return src_pos; |
151 | } |
152 | } |
152 | |
153 | |
|
|
154 | static void |
|
|
155 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
|
|
156 | { |
|
|
157 | if (!strcasecmp (style, "tiled")) |
|
|
158 | { |
|
|
159 | flags = IM_TILE; |
|
|
160 | w = h = noScale; |
|
|
161 | x = y = 0; |
|
|
162 | } |
|
|
163 | else if (!strcasecmp (style, "aspect-stretched")) |
|
|
164 | { |
|
|
165 | flags = IM_KEEP_ASPECT; |
|
|
166 | w = h = windowScale; |
|
|
167 | x = y = centerAlign; |
|
|
168 | } |
|
|
169 | else if (!strcasecmp (style, "stretched")) |
|
|
170 | { |
|
|
171 | flags = 0; |
|
|
172 | w = h = windowScale; |
|
|
173 | x = y = centerAlign; |
|
|
174 | } |
|
|
175 | else if (!strcasecmp (style, "centered")) |
|
|
176 | { |
|
|
177 | flags = 0; |
|
|
178 | w = h = noScale; |
|
|
179 | x = y = centerAlign; |
|
|
180 | } |
|
|
181 | else if (!strcasecmp (style, "root-tiled")) |
|
|
182 | { |
|
|
183 | flags = IM_TILE|IM_ROOT_ALIGN; |
|
|
184 | w = h = noScale; |
|
|
185 | x = y = 0; |
|
|
186 | } |
|
|
187 | } |
|
|
188 | |
153 | bool |
189 | bool |
154 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
190 | rxvt_image::set_geometry (const char *geom, bool update) |
155 | { |
191 | { |
156 | bool changed = false; |
192 | bool changed = false; |
157 | int geom_flags = 0; |
193 | int geom_flags = 0; |
158 | int x = h_align; |
194 | int x = h_align; |
159 | int y = v_align; |
195 | int y = v_align; |
160 | unsigned int w = h_scale; |
196 | unsigned int w = h_scale; |
161 | unsigned int h = v_scale; |
197 | unsigned int h = v_scale; |
162 | unsigned long new_flags = 0; |
198 | uint8_t new_flags = 0; |
163 | |
199 | |
164 | if (geom == NULL) |
200 | if (geom == NULL) |
165 | return false; |
201 | return false; |
166 | |
202 | |
167 | if (geom[0]) |
203 | if (geom[0]) |
168 | { |
204 | { |
169 | char **arr = rxvt_strsplit (':', geom); |
205 | char **arr = rxvt_strsplit (':', geom); |
170 | |
206 | |
171 | for (int i = 0; arr[i]; i++) |
207 | for (int i = 0; arr[i]; i++) |
172 | { |
208 | { |
173 | if (!strcasecmp (arr[i], "style=tiled")) |
209 | if (!strncasecmp (arr[i], "style=", 6)) |
174 | { |
210 | { |
175 | new_flags = BG_TILE; |
211 | 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; |
212 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
179 | } |
213 | } |
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")) |
214 | else if (!strcasecmp (arr[i], "op=tile")) |
207 | new_flags |= BG_TILE; |
215 | new_flags |= IM_TILE; |
208 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
216 | else if (!strcasecmp (arr[i], "op=keep-aspect")) |
209 | new_flags |= BG_KEEP_ASPECT; |
217 | new_flags |= IM_KEEP_ASPECT; |
210 | else if (!strcasecmp (arr[i], "op=root-align")) |
218 | else if (!strcasecmp (arr[i], "op=root-align")) |
211 | new_flags |= BG_ROOT_ALIGN; |
219 | new_flags |= IM_ROOT_ALIGN; |
212 | |
220 | |
213 | // deprecated |
221 | // deprecated |
214 | else if (!strcasecmp (arr[i], "tile")) |
222 | else if (!strcasecmp (arr[i], "tile")) |
215 | { |
223 | { |
216 | new_flags |= BG_TILE; |
224 | new_flags |= IM_TILE; |
217 | w = h = noScale; |
225 | w = h = noScale; |
218 | geom_flags |= WidthValue|HeightValue; |
226 | geom_flags |= WidthValue|HeightValue; |
219 | } |
227 | } |
220 | else if (!strcasecmp (arr[i], "propscale")) |
228 | else if (!strcasecmp (arr[i], "propscale")) |
221 | { |
229 | { |
222 | new_flags |= BG_KEEP_ASPECT; |
230 | new_flags |= IM_KEEP_ASPECT; |
223 | w = h = windowScale; |
231 | w = h = windowScale; |
224 | geom_flags |= WidthValue|HeightValue; |
232 | geom_flags |= WidthValue|HeightValue; |
225 | } |
233 | } |
226 | else if (!strcasecmp (arr[i], "hscale")) |
234 | else if (!strcasecmp (arr[i], "hscale")) |
227 | { |
235 | { |
228 | new_flags |= BG_TILE; |
236 | new_flags |= IM_TILE; |
229 | w = windowScale; |
237 | w = windowScale; |
230 | h = noScale; |
238 | h = noScale; |
231 | geom_flags |= WidthValue|HeightValue; |
239 | geom_flags |= WidthValue|HeightValue; |
232 | } |
240 | } |
233 | else if (!strcasecmp (arr[i], "vscale")) |
241 | else if (!strcasecmp (arr[i], "vscale")) |
234 | { |
242 | { |
235 | new_flags |= BG_TILE; |
243 | new_flags |= IM_TILE; |
236 | h = windowScale; |
244 | h = windowScale; |
237 | w = noScale; |
245 | w = noScale; |
238 | geom_flags |= WidthValue|HeightValue; |
246 | geom_flags |= WidthValue|HeightValue; |
239 | } |
247 | } |
240 | else if (!strcasecmp (arr[i], "scale")) |
248 | else if (!strcasecmp (arr[i], "scale")) |
… | |
… | |
248 | x = y = centerAlign; |
256 | x = y = centerAlign; |
249 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
257 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
250 | } |
258 | } |
251 | else if (!strcasecmp (arr[i], "root")) |
259 | else if (!strcasecmp (arr[i], "root")) |
252 | { |
260 | { |
253 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
261 | new_flags |= IM_TILE|IM_ROOT_ALIGN; |
254 | w = h = noScale; |
262 | w = h = noScale; |
255 | geom_flags |= WidthValue|HeightValue; |
263 | geom_flags |= WidthValue|HeightValue; |
256 | } |
264 | } |
257 | |
265 | |
258 | else |
266 | else |
… | |
… | |
260 | } /* done parsing ops */ |
268 | } /* done parsing ops */ |
261 | |
269 | |
262 | rxvt_free_strsplit (arr); |
270 | rxvt_free_strsplit (arr); |
263 | } |
271 | } |
264 | |
272 | |
265 | new_flags |= bg_flags & ~BG_GEOMETRY_FLAGS; |
273 | new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
266 | |
274 | |
267 | if (!update) |
275 | if (!update) |
268 | { |
276 | { |
269 | if (!(geom_flags & XValue)) |
277 | if (!(geom_flags & XValue)) |
270 | x = y = defaultAlign; |
278 | x = y = defaultAlign; |
… | |
… | |
277 | h = w; |
285 | h = w; |
278 | else if (!(geom_flags & WidthValue)) |
286 | else if (!(geom_flags & WidthValue)) |
279 | w = h; |
287 | w = h; |
280 | } |
288 | } |
281 | |
289 | |
282 | min_it (w, 1000); |
|
|
283 | min_it (h, 1000); |
|
|
284 | clamp_it (x, -100, 200); |
290 | clamp_it (x, -100, 200); |
285 | clamp_it (y, -100, 200); |
291 | clamp_it (y, -100, 200); |
286 | |
292 | |
287 | if (bg_flags != new_flags |
293 | if (flags != new_flags |
288 | || h_scale != w |
294 | || h_scale != w |
289 | || v_scale != h |
295 | || v_scale != h |
290 | || h_align != x |
296 | || h_align != x |
291 | || v_align != y) |
297 | || v_align != y) |
292 | { |
298 | { |
293 | bg_flags = new_flags; |
299 | flags = new_flags; |
294 | h_scale = w; |
300 | h_scale = w; |
295 | v_scale = h; |
301 | v_scale = h; |
296 | h_align = x; |
302 | h_align = x; |
297 | v_align = y; |
303 | v_align = y; |
298 | changed = true; |
304 | changed = true; |
299 | } |
305 | } |
300 | |
306 | |
|
|
307 | if (is_size_sensitive ()) |
|
|
308 | flags |= IM_IS_SIZE_SENSITIVE; |
|
|
309 | else |
|
|
310 | flags &= ~IM_IS_SIZE_SENSITIVE; |
|
|
311 | |
301 | return changed; |
312 | return changed; |
302 | } |
313 | } |
303 | |
314 | |
304 | void |
315 | void |
305 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
316 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
306 | { |
317 | { |
|
|
318 | int image_width = image.width (); |
|
|
319 | int image_height = image.height (); |
307 | int target_width = szHint.width; |
320 | int target_width = szHint.width; |
308 | int target_height = szHint.height; |
321 | int target_height = szHint.height; |
|
|
322 | int h_scale = min (image.h_scale, 32767 * 100 / target_width); |
|
|
323 | int v_scale = min (image.v_scale, 32767 * 100 / target_height); |
309 | |
324 | |
310 | w = h_scale * target_width / 100; |
325 | w = h_scale * target_width / 100; |
311 | h = v_scale * target_height / 100; |
326 | h = v_scale * target_height / 100; |
312 | |
327 | |
313 | if (bg_flags & BG_KEEP_ASPECT) |
328 | if (image.flags & IM_KEEP_ASPECT) |
314 | { |
329 | { |
315 | float scale = (float)w / image_width; |
330 | float scale = (float)w / image_width; |
316 | min_it (scale, (float)h / image_height); |
331 | min_it (scale, (float)h / image_height); |
317 | w = image_width * scale + 0.5; |
332 | w = image_width * scale + 0.5; |
318 | h = image_height * scale + 0.5; |
333 | h = image_height * scale + 0.5; |
319 | } |
334 | } |
320 | |
335 | |
321 | if (!w) w = image_width; |
336 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
337 | if (!h) h = image_height; |
323 | |
338 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
339 | if (image.flags & IM_ROOT_ALIGN) |
325 | { |
340 | { |
326 | x = -target_x; |
341 | x = -target_x; |
327 | y = -target_y; |
342 | y = -target_y; |
328 | } |
343 | } |
329 | else |
344 | else |
330 | { |
345 | { |
331 | x = make_align_position (h_align, target_width, w); |
346 | x = make_align_position (image.h_align, target_width, w); |
332 | y = make_align_position (v_align, target_height, h); |
347 | y = make_align_position (image.v_align, target_height, h); |
333 | } |
348 | } |
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 | } |
349 | } |
343 | |
350 | |
344 | # ifdef HAVE_PIXBUF |
351 | # if HAVE_PIXBUF |
345 | bool |
352 | bool |
346 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
353 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
347 | int src_x, int src_y, int dst_x, int dst_y, |
354 | int src_x, int src_y, int dst_x, int dst_y, |
348 | unsigned int width, unsigned int height) |
355 | unsigned int width, unsigned int height, bool argb) |
349 | { |
356 | { |
350 | XImage *ximage; |
357 | XImage *ximage; |
351 | char *line; |
358 | char *line; |
352 | int width_r, width_g, width_b, width_a; |
359 | int width_r, width_g, width_b, width_a; |
353 | int sh_r, sh_g, sh_b, sh_a; |
360 | int sh_r, sh_g, sh_b, sh_a; |
354 | uint32_t alpha_mask; |
361 | uint32_t red_mask, green_mask, blue_mask, alpha_mask; |
355 | int rowstride; |
362 | int rowstride; |
356 | int channels; |
363 | int channels; |
357 | unsigned char *row; |
364 | unsigned char *row; |
358 | |
365 | |
359 | if (visual->c_class != TrueColor) |
366 | if (visual->c_class != TrueColor) |
360 | return false; |
367 | return false; |
361 | |
368 | |
|
|
369 | if (argb) |
|
|
370 | { |
|
|
371 | red_mask = 0xff << 16; |
|
|
372 | green_mask = 0xff << 8; |
|
|
373 | blue_mask = 0xff; |
|
|
374 | alpha_mask = 0xff << 24; |
|
|
375 | } |
|
|
376 | else |
|
|
377 | { |
|
|
378 | red_mask = visual->red_mask; |
|
|
379 | green_mask = visual->green_mask; |
|
|
380 | blue_mask = visual->blue_mask; |
362 | #if XRENDER |
381 | #if XRENDER |
363 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
382 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
364 | if (format) |
383 | if (format) |
365 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
384 | alpha_mask = (uint32_t)format->direct.alphaMask << format->direct.alpha; |
366 | else |
385 | else |
367 | #endif |
386 | #endif |
368 | alpha_mask = 0; |
387 | alpha_mask = 0; |
|
|
388 | } |
369 | |
389 | |
370 | width_r = ecb_popcount32 (visual->red_mask); |
390 | width_r = ecb_popcount32 (red_mask); |
371 | width_g = ecb_popcount32 (visual->green_mask); |
391 | width_g = ecb_popcount32 (green_mask); |
372 | width_b = ecb_popcount32 (visual->blue_mask); |
392 | width_b = ecb_popcount32 (blue_mask); |
373 | width_a = ecb_popcount32 (alpha_mask); |
393 | width_a = ecb_popcount32 (alpha_mask); |
374 | |
394 | |
375 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
395 | if (width_r > 8 || width_g > 8 || width_b > 8 || width_a > 8) |
376 | return false; |
396 | return false; |
377 | |
397 | |
378 | sh_r = ecb_ctz32 (visual->red_mask); |
398 | sh_r = ecb_ctz32 (red_mask); |
379 | sh_g = ecb_ctz32 (visual->green_mask); |
399 | sh_g = ecb_ctz32 (green_mask); |
380 | sh_b = ecb_ctz32 (visual->blue_mask); |
400 | sh_b = ecb_ctz32 (blue_mask); |
381 | sh_a = ecb_ctz32 (alpha_mask); |
401 | sh_a = ecb_ctz32 (alpha_mask); |
382 | |
402 | |
383 | if (width > 32767 || height > 32767) |
403 | if (width > 32767 || height > 32767) |
384 | return false; |
404 | return false; |
385 | |
405 | |
386 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, 0, |
406 | ximage = XCreateImage (dpy, visual, argb ? 32 : depth, ZPixmap, 0, 0, |
387 | width, height, 32, 0); |
407 | width, height, 32, 0); |
388 | if (!ximage) |
408 | if (!ximage) |
389 | return false; |
409 | return false; |
390 | |
410 | |
391 | if (height > INT_MAX / ximage->bytes_per_line |
411 | if (height > INT_MAX / ximage->bytes_per_line |
… | |
… | |
454 | XDestroyImage (ximage); |
474 | XDestroyImage (ximage); |
455 | return true; |
475 | return true; |
456 | } |
476 | } |
457 | |
477 | |
458 | bool |
478 | bool |
459 | rxvt_term::render_image (bool transparent) |
479 | rxvt_term::render_image (rxvt_image &image) |
460 | { |
480 | { |
|
|
481 | GdkPixbuf *pixbuf = image.pixbuf; |
461 | if (!pixbuf) |
482 | if (!pixbuf) |
462 | return false; |
483 | return false; |
463 | |
484 | |
464 | if (transparent |
485 | bool need_blend = bg_flags & BG_IS_VALID; |
|
|
486 | |
|
|
487 | if (need_blend |
465 | && !(bg_flags & BG_HAS_RENDER)) |
488 | && !(display->flags & DISPLAY_HAS_RENDER)) |
466 | return false; |
489 | return false; |
467 | |
490 | |
468 | GdkPixbuf *result; |
491 | GdkPixbuf *result; |
469 | |
492 | |
470 | int image_width = gdk_pixbuf_get_width (pixbuf); |
493 | int image_width = gdk_pixbuf_get_width (pixbuf); |
… | |
… | |
478 | int x = 0; |
501 | int x = 0; |
479 | int y = 0; |
502 | int y = 0; |
480 | int w = 0; |
503 | int w = 0; |
481 | int h = 0; |
504 | int h = 0; |
482 | |
505 | |
483 | get_image_geometry (image_width, image_height, w, h, x, y); |
506 | get_image_geometry (image, w, h, x, y); |
484 | |
507 | |
485 | if (!(bg_flags & BG_ROOT_ALIGN) |
508 | if (!(image.flags & IM_ROOT_ALIGN) |
486 | && (x >= target_width |
509 | && (x >= target_width |
487 | || y >= target_height |
510 | || y >= target_height |
488 | || x + w <= 0 |
511 | || x + w <= 0 |
489 | || y + h <= 0)) |
512 | || y + h <= 0)) |
490 | return false; |
513 | return false; |
… | |
… | |
504 | |
527 | |
505 | bool ret = false; |
528 | bool ret = false; |
506 | |
529 | |
507 | XGCValues gcv; |
530 | XGCValues gcv; |
508 | GC gc; |
531 | GC gc; |
509 | Pixmap root_pmap; |
532 | Pixmap tmp_pixmap; |
510 | |
533 | |
511 | image_width = gdk_pixbuf_get_width (result); |
534 | image_width = gdk_pixbuf_get_width (result); |
512 | image_height = gdk_pixbuf_get_height (result); |
535 | image_height = gdk_pixbuf_get_height (result); |
513 | |
536 | |
514 | if (transparent) |
537 | if (need_blend) |
515 | { |
538 | tmp_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, 32); |
516 | root_pmap = bg_pixmap; |
|
|
517 | bg_pixmap = None; |
|
|
518 | } |
|
|
519 | else |
539 | else |
520 | { |
540 | { |
521 | if (bg_flags & BG_TILE) |
541 | if (image.flags & IM_TILE) |
522 | { |
542 | { |
523 | new_pmap_width = min (image_width, target_width); |
543 | new_pmap_width = min (image_width, target_width); |
524 | new_pmap_height = min (image_height, target_height); |
544 | new_pmap_height = min (image_height, target_height); |
525 | } |
545 | } |
526 | } |
|
|
527 | |
546 | |
528 | if (bg_pixmap == None |
547 | if (bg_pixmap == None |
529 | || bg_pmap_width != new_pmap_width |
548 | || bg_pmap_width != new_pmap_width |
530 | || bg_pmap_height != new_pmap_height) |
549 | || bg_pmap_height != new_pmap_height) |
531 | { |
550 | { |
532 | if (bg_pixmap) |
551 | if (bg_pixmap) |
533 | XFreePixmap (dpy, bg_pixmap); |
552 | XFreePixmap (dpy, bg_pixmap); |
534 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
553 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
535 | bg_pmap_width = new_pmap_width; |
554 | bg_pmap_width = new_pmap_width; |
536 | bg_pmap_height = new_pmap_height; |
555 | bg_pmap_height = new_pmap_height; |
|
|
556 | } |
|
|
557 | |
|
|
558 | tmp_pixmap = bg_pixmap; |
537 | } |
559 | } |
538 | |
560 | |
539 | gcv.foreground = pix_colors[Color_bg]; |
561 | gcv.foreground = pix_colors[Color_bg]; |
540 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
562 | gc = XCreateGC (dpy, tmp_pixmap, GCForeground, &gcv); |
541 | |
563 | |
542 | if (gc) |
564 | if (gc) |
543 | { |
565 | { |
544 | if (bg_flags & BG_TILE) |
566 | if (image.flags & IM_TILE) |
545 | { |
567 | { |
546 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
568 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, need_blend ? 32 : depth); |
547 | pixbuf_to_pixmap (result, tile, gc, |
569 | pixbuf_to_pixmap (result, tile, gc, |
548 | 0, 0, |
570 | 0, 0, |
549 | 0, 0, |
571 | 0, 0, |
550 | image_width, image_height); |
572 | image_width, image_height, need_blend); |
551 | |
573 | |
552 | gcv.tile = tile; |
574 | gcv.tile = tile; |
553 | gcv.fill_style = FillTiled; |
575 | gcv.fill_style = FillTiled; |
554 | gcv.ts_x_origin = x; |
576 | gcv.ts_x_origin = x; |
555 | gcv.ts_y_origin = y; |
577 | gcv.ts_y_origin = y; |
556 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
578 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
557 | |
579 | |
558 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
580 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
559 | XFreePixmap (dpy, tile); |
581 | XFreePixmap (dpy, tile); |
560 | } |
582 | } |
561 | else |
583 | else |
562 | { |
584 | { |
563 | int src_x, src_y, dst_x, dst_y; |
585 | 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); |
589 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
568 | |
590 | |
569 | if (dst_x > 0 || dst_y > 0 |
591 | if (dst_x > 0 || dst_y > 0 |
570 | || dst_x + dst_width < new_pmap_width |
592 | || dst_x + dst_width < new_pmap_width |
571 | || dst_y + dst_height < new_pmap_height) |
593 | || dst_y + dst_height < new_pmap_height) |
572 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
594 | XFillRectangle (dpy, tmp_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
573 | |
595 | |
574 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
596 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
575 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
597 | pixbuf_to_pixmap (result, tmp_pixmap, gc, |
576 | src_x, src_y, |
598 | src_x, src_y, |
577 | dst_x, dst_y, |
599 | dst_x, dst_y, |
578 | dst_width, dst_height); |
600 | dst_width, dst_height, need_blend); |
579 | } |
601 | } |
|
|
602 | |
|
|
603 | if (image.need_blur ()) |
|
|
604 | blur_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.h_blurRadius, image.v_blurRadius); |
|
|
605 | if (image.need_tint ()) |
|
|
606 | tint_pixmap (tmp_pixmap, new_pmap_width, new_pmap_height, need_blend, image.tint, image.tint_set, image.shade); |
580 | |
607 | |
581 | #if XRENDER |
608 | #if XRENDER |
582 | if (transparent) |
609 | if (need_blend) |
583 | { |
610 | { |
|
|
611 | XRenderPictFormat *argb_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
584 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
612 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
585 | |
613 | |
586 | Picture src = XRenderCreatePicture (dpy, root_pmap, format, 0, 0); |
614 | Picture src = XRenderCreatePicture (dpy, tmp_pixmap, argb_format, 0, 0); |
587 | |
615 | |
588 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
616 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, format, 0, 0); |
589 | |
617 | |
590 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
618 | Picture mask = create_xrender_mask (dpy, vt, False, False); |
591 | |
619 | |
592 | XRenderColor mask_c; |
620 | XRenderColor mask_c; |
593 | |
621 | |
594 | mask_c.alpha = 0x8000; |
622 | mask_c.alpha = image.alpha; |
595 | mask_c.red = |
623 | mask_c.red = |
596 | mask_c.green = |
624 | mask_c.green = |
597 | mask_c.blue = 0; |
625 | mask_c.blue = 0; |
598 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
626 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
599 | |
627 | |
… | |
… | |
611 | } |
639 | } |
612 | |
640 | |
613 | if (result != pixbuf) |
641 | if (result != pixbuf) |
614 | g_object_unref (result); |
642 | g_object_unref (result); |
615 | |
643 | |
616 | if (transparent) |
644 | if (need_blend) |
617 | XFreePixmap (dpy, root_pmap); |
645 | XFreePixmap (dpy, tmp_pixmap); |
618 | |
646 | |
619 | return ret; |
647 | return ret; |
620 | } |
648 | } |
621 | # endif /* HAVE_PIXBUF */ |
649 | # endif /* HAVE_PIXBUF */ |
622 | |
650 | |
|
|
651 | rxvt_image::rxvt_image () |
|
|
652 | { |
|
|
653 | alpha = 0xffff; |
|
|
654 | flags = 0; |
|
|
655 | h_scale = |
|
|
656 | v_scale = defaultScale; |
|
|
657 | h_align = |
|
|
658 | v_align = defaultAlign; |
|
|
659 | |
|
|
660 | # if HAVE_PIXBUF |
|
|
661 | pixbuf = 0; |
|
|
662 | # endif |
|
|
663 | } |
|
|
664 | |
623 | bool |
665 | bool |
624 | rxvt_term::bg_set_file (const char *file) |
666 | rxvt_image::set_file_geometry (const char *file) |
625 | { |
667 | { |
626 | if (!file || !*file) |
668 | if (!file || !*file) |
627 | return false; |
669 | return false; |
628 | |
670 | |
629 | bool ret = false; |
|
|
630 | const char *p = strchr (file, ';'); |
671 | const char *p = strchr (file, ';'); |
631 | |
672 | |
632 | if (p) |
673 | if (p) |
633 | { |
674 | { |
634 | size_t len = p - file; |
675 | size_t len = p - file; |
… | |
… | |
636 | memcpy (f, file, len); |
677 | memcpy (f, file, len); |
637 | f[len] = '\0'; |
678 | f[len] = '\0'; |
638 | file = f; |
679 | file = f; |
639 | } |
680 | } |
640 | |
681 | |
|
|
682 | bool ret = set_file (file); |
|
|
683 | alpha = 0x8000; |
|
|
684 | if (ret) |
|
|
685 | set_geometry (p ? p + 1 : ""); |
|
|
686 | return ret; |
|
|
687 | } |
|
|
688 | |
|
|
689 | bool |
|
|
690 | rxvt_image::set_file (const char *file) |
|
|
691 | { |
|
|
692 | bool ret = false; |
|
|
693 | |
641 | # ifdef HAVE_PIXBUF |
694 | # if HAVE_PIXBUF |
642 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
695 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
643 | if (image) |
696 | if (image) |
644 | { |
697 | { |
645 | if (pixbuf) |
698 | if (pixbuf) |
646 | g_object_unref (pixbuf); |
699 | g_object_unref (pixbuf); |
647 | pixbuf = image; |
700 | pixbuf = image; |
648 | bg_flags |= BG_IS_FROM_FILE; |
|
|
649 | ret = true; |
701 | ret = true; |
650 | } |
702 | } |
651 | # endif |
703 | # endif |
652 | |
704 | |
653 | if (ret) |
705 | if (ret) |
654 | { |
706 | flags |= IM_IS_SET; |
655 | if (p) |
|
|
656 | bg_set_geometry (p + 1); |
|
|
657 | else |
|
|
658 | bg_set_default_geometry (); |
|
|
659 | } |
|
|
660 | |
707 | |
661 | return ret; |
708 | return ret; |
662 | } |
709 | } |
663 | |
710 | |
664 | # endif /* BG_IMAGE_FROM_FILE */ |
711 | # endif /* BG_IMAGE_FROM_FILE */ |
665 | |
712 | |
666 | # ifdef ENABLE_TRANSPARENCY |
|
|
667 | bool |
713 | bool |
668 | rxvt_term::bg_set_transparent () |
714 | image_effects::set_blur (const char *geom) |
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 |
|
|
680 | rxvt_term::bg_set_blur (const char *geom) |
|
|
681 | { |
715 | { |
682 | bool changed = false; |
716 | bool changed = false; |
683 | unsigned int hr, vr; |
717 | unsigned int hr, vr; |
684 | int junk; |
718 | int junk; |
685 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
719 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
… | |
… | |
702 | { |
736 | { |
703 | changed = true; |
737 | changed = true; |
704 | v_blurRadius = vr; |
738 | v_blurRadius = vr; |
705 | } |
739 | } |
706 | |
740 | |
707 | if (h_blurRadius && v_blurRadius) |
|
|
708 | bg_flags |= BG_NEEDS_BLUR; |
|
|
709 | else |
|
|
710 | bg_flags &= ~BG_NEEDS_BLUR; |
|
|
711 | |
|
|
712 | return changed; |
741 | return changed; |
713 | } |
742 | } |
714 | |
743 | |
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 | } |
|
|
723 | |
|
|
724 | bool |
744 | bool |
725 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
745 | image_effects::set_tint (const rxvt_color &new_tint) |
726 | { |
746 | { |
727 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
747 | if (!tint_set || tint != new_tint) |
728 | { |
748 | { |
729 | tint = new_tint; |
749 | tint = new_tint; |
730 | bg_flags |= BG_TINT_SET; |
750 | tint_set = true; |
731 | |
751 | |
732 | rgba c; |
|
|
733 | tint.get (c); |
|
|
734 | if ((c.r <= 0x00ff || c.r >= 0xff00) |
|
|
735 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
736 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
|
|
737 | bg_flags |= BG_TINT_BITAND; |
|
|
738 | else |
|
|
739 | bg_flags &= ~BG_TINT_BITAND; |
|
|
740 | |
|
|
741 | set_tint_shade_flags (); |
|
|
742 | return true; |
752 | return true; |
743 | } |
753 | } |
744 | |
754 | |
745 | return false; |
755 | return false; |
746 | } |
756 | } |
747 | |
757 | |
748 | bool |
758 | bool |
749 | rxvt_term::bg_set_shade (const char *shade_str) |
759 | image_effects::set_shade (const char *shade_str) |
750 | { |
760 | { |
751 | int new_shade = atoi (shade_str); |
761 | int new_shade = atoi (shade_str); |
752 | |
762 | |
753 | clamp_it (new_shade, -100, 200); |
763 | clamp_it (new_shade, -100, 200); |
754 | if (new_shade < 0) |
764 | if (new_shade < 0) |
755 | new_shade = 200 - (100 + new_shade); |
765 | new_shade = 200 - (100 + new_shade); |
756 | |
766 | |
757 | if (new_shade != shade) |
767 | if (new_shade != shade) |
758 | { |
768 | { |
759 | shade = new_shade; |
769 | shade = new_shade; |
760 | set_tint_shade_flags (); |
|
|
761 | return true; |
770 | return true; |
762 | } |
771 | } |
763 | |
772 | |
764 | return false; |
773 | return false; |
765 | } |
774 | } |
… | |
… | |
786 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
795 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
787 | } |
796 | } |
788 | #endif |
797 | #endif |
789 | |
798 | |
790 | bool |
799 | bool |
791 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height, int depth) |
800 | rxvt_term::blur_pixmap (Pixmap pixmap, int width, int height, bool argb, int h_blurRadius, int v_blurRadius) |
792 | { |
801 | { |
793 | bool ret = false; |
802 | bool ret = false; |
794 | #if XRENDER |
803 | #if XRENDER |
795 | if (!(bg_flags & BG_HAS_RENDER_CONV)) |
804 | if (!(display->flags & DISPLAY_HAS_RENDER_CONV)) |
796 | return false; |
805 | return false; |
797 | |
806 | |
798 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
807 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
799 | double *kernel = (double *)malloc (size * sizeof (double)); |
808 | double *kernel = (double *)malloc (size * sizeof (double)); |
800 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
809 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
801 | |
810 | |
802 | XRenderPictureAttributes pa; |
811 | XRenderPictureAttributes pa; |
803 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
812 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
813 | : XRenderFindVisualFormat (dpy, visual); |
804 | |
814 | |
805 | pa.repeat = RepeatPad; |
815 | pa.repeat = RepeatPad; |
806 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
816 | Picture src = XRenderCreatePicture (dpy, pixmap, format, CPRepeat, &pa); |
807 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
817 | Pixmap tmp = XCreatePixmap (dpy, pixmap, width, height, depth); |
808 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
818 | Picture dst = XRenderCreatePicture (dpy, tmp, format, CPRepeat, &pa); |
… | |
… | |
851 | #endif |
861 | #endif |
852 | return ret; |
862 | return ret; |
853 | } |
863 | } |
854 | |
864 | |
855 | bool |
865 | bool |
856 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
866 | rxvt_term::tint_pixmap (Pixmap pixmap, int width, int height, bool argb, rxvt_color &tint, bool tint_set, int shade) |
857 | { |
867 | { |
858 | bool ret = false; |
868 | bool ret = false; |
859 | |
869 | |
860 | if (shade == 100 && (bg_flags & BG_TINT_BITAND)) |
870 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
871 | |
|
|
872 | if (tint_set) |
|
|
873 | tint.get (c); |
|
|
874 | |
|
|
875 | if (shade == 100 |
|
|
876 | && (c.r <= 0x00ff || c.r >= 0xff00) |
|
|
877 | && (c.g <= 0x00ff || c.g >= 0xff00) |
|
|
878 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
861 | { |
879 | { |
862 | XGCValues gcv; |
880 | XGCValues gcv; |
863 | GC gc; |
881 | GC gc; |
864 | |
882 | |
865 | /* In this case we can tint image server-side getting significant |
883 | /* In this case we can tint image server-side getting significant |
… | |
… | |
875 | ret = true; |
893 | ret = true; |
876 | XFreeGC (dpy, gc); |
894 | XFreeGC (dpy, gc); |
877 | } |
895 | } |
878 | } |
896 | } |
879 | # if XRENDER |
897 | # if XRENDER |
880 | else if (bg_flags & BG_HAS_RENDER) |
898 | else if (display->flags & DISPLAY_HAS_RENDER) |
881 | { |
899 | { |
882 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
|
|
883 | |
|
|
884 | if (bg_flags & BG_TINT_SET) |
|
|
885 | tint.get (c); |
|
|
886 | |
|
|
887 | if (shade <= 100) |
900 | if (shade <= 100) |
888 | { |
901 | { |
889 | c.r = c.r * shade / 100; |
902 | c.r = c.r * shade / 100; |
890 | c.g = c.g * shade / 100; |
903 | c.g = c.g * shade / 100; |
891 | c.b = c.b * shade / 100; |
904 | c.b = c.b * shade / 100; |
… | |
… | |
895 | c.r = c.r * (200 - shade) / 100; |
908 | c.r = c.r * (200 - shade) / 100; |
896 | c.g = c.g * (200 - shade) / 100; |
909 | c.g = c.g * (200 - shade) / 100; |
897 | c.b = c.b * (200 - shade) / 100; |
910 | c.b = c.b * (200 - shade) / 100; |
898 | } |
911 | } |
899 | |
912 | |
900 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
913 | XRenderPictFormat *format = argb ? XRenderFindStandardFormat (dpy, PictStandardARGB32) |
|
|
914 | : XRenderFindVisualFormat (dpy, visual); |
901 | |
915 | |
902 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
916 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, 0); |
903 | |
917 | |
904 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
918 | Picture overlay_pic = create_xrender_mask (dpy, pixmap, True, False); |
905 | |
919 | |
… | |
… | |
941 | # endif |
955 | # endif |
942 | |
956 | |
943 | return ret; |
957 | return ret; |
944 | } |
958 | } |
945 | |
959 | |
|
|
960 | # if ENABLE_TRANSPARENCY |
946 | /* |
961 | /* |
947 | * Builds a pixmap of the same size as the terminal window that contains |
962 | * Builds a pixmap of the same size as the terminal window that contains |
948 | * the tiled portion of the root pixmap that is supposed to be covered by |
963 | * the tiled portion of the root pixmap that is supposed to be covered by |
949 | * our window. |
964 | * our window. |
950 | */ |
965 | */ |
951 | bool |
966 | bool |
952 | rxvt_term::make_transparency_pixmap () |
967 | rxvt_term::render_root_image () |
953 | { |
968 | { |
954 | bool ret = false; |
969 | bool ret = false; |
955 | |
970 | |
956 | /* root dimensions may change from call to call - but Display structure should |
971 | /* root dimensions may change from call to call - but Display structure should |
957 | * be always up-to-date, so let's use it : |
972 | * be always up-to-date, so let's use it : |
… | |
… | |
993 | Pixmap recoded_root_pmap = root_pixmap; |
1008 | Pixmap recoded_root_pmap = root_pixmap; |
994 | |
1009 | |
995 | if (root_pixmap != None && root_depth != depth) |
1010 | if (root_pixmap != None && root_depth != depth) |
996 | { |
1011 | { |
997 | #if XRENDER |
1012 | #if XRENDER |
998 | if (bg_flags & BG_HAS_RENDER) |
1013 | if (display->flags & DISPLAY_HAS_RENDER) |
999 | { |
1014 | { |
1000 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1015 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
1001 | |
1016 | |
1002 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1017 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1003 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
1018 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, 0); |
… | |
… | |
1041 | |
1056 | |
1042 | if (gc) |
1057 | if (gc) |
1043 | { |
1058 | { |
1044 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1059 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1045 | ret = true; |
1060 | ret = true; |
1046 | unsigned long tr_flags = bg_flags & BG_EFFECTS_FLAGS; |
1061 | bool need_blur = root_effects.need_blur (); |
|
|
1062 | bool need_tint = root_effects.need_tint (); |
1047 | |
1063 | |
1048 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1064 | if (need_blur) |
|
|
1065 | { |
|
|
1066 | if (blur_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1067 | root_effects.h_blurRadius, root_effects.v_blurRadius)) |
|
|
1068 | need_blur = false; |
1049 | { |
1069 | } |
1050 | if (bg_flags & BG_NEEDS_BLUR) |
1070 | if (need_tint) |
|
|
1071 | { |
|
|
1072 | if (tint_pixmap (bg_pixmap, window_width, window_height, false, |
|
|
1073 | root_effects.tint, root_effects.tint_set, root_effects.shade)) |
|
|
1074 | need_tint = false; |
|
|
1075 | } |
|
|
1076 | if (need_tint) |
|
|
1077 | { |
|
|
1078 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1079 | if (ximage) |
1051 | { |
1080 | { |
1052 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height, depth)) |
1081 | /* our own client-side tinting */ |
1053 | tr_flags &= ~BG_NEEDS_BLUR; |
1082 | tint_ximage (ximage, root_effects.tint, root_effects.tint_set, root_effects.shade); |
|
|
1083 | |
|
|
1084 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1085 | XDestroyImage (ximage); |
1054 | } |
1086 | } |
1055 | if (bg_flags & BG_NEEDS_TINT) |
|
|
1056 | { |
|
|
1057 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
|
|
1058 | tr_flags &= ~BG_NEEDS_TINT; |
|
|
1059 | } |
1087 | } |
1060 | if (tr_flags & BG_NEEDS_TINT) |
|
|
1061 | { |
|
|
1062 | XImage *ximage = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
|
|
1063 | if (ximage) |
|
|
1064 | { |
|
|
1065 | /* our own client-side tinting */ |
|
|
1066 | tint_ximage (DefaultVisual (dpy, display->screen), ximage); |
|
|
1067 | |
|
|
1068 | XPutImage (dpy, bg_pixmap, gc, ximage, 0, 0, 0, 0, ximage->width, ximage->height); |
|
|
1069 | XDestroyImage (ximage); |
|
|
1070 | } |
|
|
1071 | } |
|
|
1072 | } /* server side rendering completed */ |
|
|
1073 | |
1088 | |
1074 | XFreeGC (dpy, gc); |
1089 | XFreeGC (dpy, gc); |
1075 | } |
1090 | } |
1076 | |
1091 | |
1077 | if (recoded_root_pmap != root_pixmap) |
1092 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1081 | } |
1096 | } |
1082 | |
1097 | |
1083 | void |
1098 | void |
1084 | rxvt_term::bg_set_root_pixmap () |
1099 | rxvt_term::bg_set_root_pixmap () |
1085 | { |
1100 | { |
1086 | Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1101 | Pixmap new_root_pixmap = display->get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1087 | if (new_root_pixmap == None) |
1102 | if (new_root_pixmap == None) |
1088 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1103 | new_root_pixmap = display->get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1089 | |
1104 | |
1090 | root_pixmap = new_root_pixmap; |
1105 | root_pixmap = new_root_pixmap; |
1091 | } |
1106 | } |
1092 | # endif /* ENABLE_TRANSPARENCY */ |
1107 | # endif /* ENABLE_TRANSPARENCY */ |
1093 | |
1108 | |
1094 | bool |
1109 | void |
1095 | rxvt_term::bg_render () |
1110 | rxvt_term::bg_render () |
1096 | { |
1111 | { |
1097 | bool transparent = false; |
|
|
1098 | |
|
|
1099 | bg_invalidate (); |
1112 | bg_invalidate (); |
1100 | # ifdef ENABLE_TRANSPARENCY |
1113 | # if ENABLE_TRANSPARENCY |
1101 | if (bg_flags & BG_IS_TRANSPARENT) |
1114 | if (bg_flags & BG_IS_TRANSPARENT) |
1102 | { |
1115 | { |
1103 | /* we need to re-generate transparency pixmap in that case ! */ |
1116 | /* we need to re-generate transparency pixmap in that case ! */ |
1104 | transparent = make_transparency_pixmap (); |
1117 | if (render_root_image ()) |
1105 | if (transparent) |
|
|
1106 | bg_flags |= BG_IS_VALID; |
1118 | bg_flags |= BG_IS_VALID; |
1107 | } |
1119 | } |
1108 | # endif |
1120 | # endif |
1109 | |
1121 | |
1110 | # ifdef BG_IMAGE_FROM_FILE |
1122 | # if BG_IMAGE_FROM_FILE |
1111 | if (bg_flags & BG_IS_FROM_FILE) |
1123 | if (fimage.flags & IM_IS_SET) |
1112 | { |
1124 | { |
1113 | if (render_image (transparent)) |
1125 | if (render_image (fimage)) |
1114 | bg_flags |= BG_IS_VALID; |
1126 | bg_flags |= BG_IS_VALID; |
1115 | } |
1127 | } |
1116 | # endif |
1128 | # endif |
1117 | |
1129 | |
1118 | if (!(bg_flags & BG_IS_VALID)) |
1130 | if (!(bg_flags & BG_IS_VALID)) |
… | |
… | |
1126 | |
1138 | |
1127 | scr_recolour (false); |
1139 | scr_recolour (false); |
1128 | bg_flags |= BG_NEEDS_REFRESH; |
1140 | bg_flags |= BG_NEEDS_REFRESH; |
1129 | |
1141 | |
1130 | bg_valid_since = ev::now (); |
1142 | bg_valid_since = ev::now (); |
1131 | |
|
|
1132 | return true; |
|
|
1133 | } |
1143 | } |
1134 | |
1144 | |
1135 | void |
1145 | void |
1136 | rxvt_term::bg_init () |
1146 | rxvt_term::bg_init () |
1137 | { |
1147 | { |
1138 | #ifdef ENABLE_TRANSPARENCY |
1148 | #if BG_IMAGE_FROM_FILE |
1139 | shade = 100; |
1149 | if (rs[Rs_backgroundPixmap]) |
|
|
1150 | { |
|
|
1151 | if (fimage.set_file_geometry (rs[Rs_backgroundPixmap]) |
|
|
1152 | && !bg_window_position_sensitive ()) |
|
|
1153 | update_background (); |
|
|
1154 | } |
1140 | #endif |
1155 | #endif |
1141 | |
|
|
1142 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
|
|
1143 | #if XRENDER |
|
|
1144 | int major, minor; |
|
|
1145 | if (XRenderQueryVersion (dpy, &major, &minor)) |
|
|
1146 | bg_flags |= BG_HAS_RENDER; |
|
|
1147 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
|
|
1148 | if (filters) |
|
|
1149 | { |
|
|
1150 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1151 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1152 | bg_flags |= BG_HAS_RENDER_CONV; |
|
|
1153 | |
|
|
1154 | XFree (filters); |
|
|
1155 | } |
|
|
1156 | #endif |
|
|
1157 | } |
1156 | } |
1158 | |
1157 | |
1159 | #endif /* HAVE_BG_PIXMAP */ |
|
|
1160 | |
|
|
1161 | #ifdef ENABLE_TRANSPARENCY |
|
|
1162 | /* based on code from aterm-0.4.2 */ |
1158 | /* based on code from aterm-0.4.2 */ |
1163 | |
1159 | |
1164 | static inline void |
1160 | static inline void |
1165 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1161 | fill_lut (uint32_t *lookup, uint32_t mask, int sh, unsigned short low, unsigned short high) |
1166 | { |
1162 | { |
… | |
… | |
1172 | lookup[i] = (tmp / 0xffff) << sh; |
1168 | lookup[i] = (tmp / 0xffff) << sh; |
1173 | } |
1169 | } |
1174 | } |
1170 | } |
1175 | |
1171 | |
1176 | void |
1172 | void |
1177 | rxvt_term::tint_ximage (Visual *visual, XImage *ximage) |
1173 | rxvt_term::tint_ximage (XImage *ximage, rxvt_color &tint, bool tint_set, int shade) |
1178 | { |
1174 | { |
1179 | unsigned int size_r, size_g, size_b; |
1175 | unsigned int size_r, size_g, size_b; |
1180 | int sh_r, sh_g, sh_b; |
1176 | int sh_r, sh_g, sh_b; |
1181 | uint32_t mask_r, mask_g, mask_b; |
1177 | uint32_t mask_r, mask_g, mask_b; |
1182 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1178 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
… | |
… | |
1207 | lookup_g = lookup + size_r; |
1203 | lookup_g = lookup + size_r; |
1208 | lookup_b = lookup + size_r + size_g; |
1204 | lookup_b = lookup + size_r + size_g; |
1209 | |
1205 | |
1210 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1206 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1211 | |
1207 | |
1212 | if (bg_flags & BG_TINT_SET) |
1208 | if (tint_set) |
1213 | tint.get (c); |
1209 | tint.get (c); |
1214 | |
1210 | |
1215 | /* prepare limits for color transformation (each channel is handled separately) */ |
1211 | /* prepare limits for color transformation (each channel is handled separately) */ |
1216 | if (shade > 100) |
1212 | if (shade > 100) |
1217 | { |
1213 | { |
… | |
… | |
1267 | } |
1263 | } |
1268 | } |
1264 | } |
1269 | |
1265 | |
1270 | free (lookup); |
1266 | free (lookup); |
1271 | } |
1267 | } |
1272 | #endif /* ENABLE_TRANSPARENCY */ |
1268 | |
|
|
1269 | #endif /* HAVE_BG_PIXMAP */ |