1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: background.C - former xpm.C |
2 | * File: background.C - former xpm.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
8 | * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> |
9 | * |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License as published by |
11 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
46 | * W and H are percentages of the terminal window size. |
46 | * W and H are percentages of the terminal window size. |
47 | * X and Y are also percentages; e.g., +50+50 centers |
47 | * X and Y are also percentages; e.g., +50+50 centers |
48 | * the image in the window. |
48 | * the image in the window. |
49 | * |
49 | * |
50 | * Pixmap Operations : (should be prepended by a colon) |
50 | * Pixmap Operations : (should be prepended by a colon) |
51 | * tile Tile image. Scaling/position modifiers above will affect |
|
|
52 | * the tile size and origin. |
|
|
53 | * propscale When scaling, scale proportionally. That is, maintain the |
|
|
54 | * proper aspect ratio for the image. Any portion of the |
|
|
55 | * background not covered by the image is filled with the |
|
|
56 | * current background color. |
|
|
57 | * hscale Scale horizontally, tile vertically ? |
|
|
58 | * vscale Tile horizontally, scale vertically ? |
|
|
59 | * scale Scale both up and down |
|
|
60 | * auto Same as 100x100+50+50 |
|
|
61 | */ |
51 | */ |
62 | |
52 | |
63 | #ifdef HAVE_BG_PIXMAP |
53 | #ifdef HAVE_BG_PIXMAP |
64 | bgPixmap_t::bgPixmap_t () |
|
|
65 | { |
|
|
66 | // this is basically redundant as bgPixmap_t is only used in |
|
|
67 | // zero_initialised-derived structs |
|
|
68 | #ifdef HAVE_AFTERIMAGE |
|
|
69 | original_asim = NULL; |
|
|
70 | #endif |
|
|
71 | #ifdef HAVE_PIXBUF |
|
|
72 | pixbuf = NULL; |
|
|
73 | #endif |
|
|
74 | #ifdef BG_IMAGE_FROM_FILE |
|
|
75 | have_image = false; |
|
|
76 | h_scale = v_scale = 0; |
|
|
77 | h_align = v_align = 0; |
|
|
78 | #endif |
|
|
79 | #ifdef ENABLE_TRANSPARENCY |
|
|
80 | shade = 100; |
|
|
81 | #endif |
|
|
82 | flags = 0; |
|
|
83 | pixmap = None; |
|
|
84 | valid_since = 0; |
|
|
85 | target = 0; |
|
|
86 | target_x = target_y = 0; |
|
|
87 | } |
|
|
88 | |
|
|
89 | void |
54 | void |
90 | bgPixmap_t::destroy () |
55 | rxvt_term::bg_destroy () |
91 | { |
56 | { |
92 | #ifdef HAVE_AFTERIMAGE |
57 | #ifdef HAVE_AFTERIMAGE |
93 | if (original_asim) |
58 | if (original_asim) |
94 | safe_asimage_destroy (original_asim); |
59 | safe_asimage_destroy (original_asim); |
|
|
60 | if (asv) |
|
|
61 | destroy_asvisual (asv, 0); |
|
|
62 | if (asimman) |
|
|
63 | destroy_image_manager (asimman, 0); |
95 | #endif |
64 | #endif |
96 | |
65 | |
97 | #ifdef HAVE_PIXBUF |
66 | #ifdef HAVE_PIXBUF |
98 | if (pixbuf) |
67 | if (pixbuf) |
99 | g_object_unref (pixbuf); |
68 | g_object_unref (pixbuf); |
100 | #endif |
69 | #endif |
101 | |
70 | |
102 | if (pixmap && target) |
71 | if (bg_pixmap) |
103 | XFreePixmap (target->dpy, pixmap); |
72 | XFreePixmap (dpy, bg_pixmap); |
104 | } |
73 | } |
105 | |
74 | |
106 | bool |
75 | bool |
107 | bgPixmap_t::set_position (int x, int y) |
76 | rxvt_term::bg_set_position (int x, int y) |
108 | { |
77 | { |
109 | |
78 | |
110 | if (target_x != x |
79 | if (target_x != x |
111 | || target_y != y) |
80 | || target_y != y) |
112 | { |
81 | { |
… | |
… | |
116 | } |
85 | } |
117 | return false; |
86 | return false; |
118 | } |
87 | } |
119 | |
88 | |
120 | bool |
89 | bool |
121 | bgPixmap_t::window_size_sensitive () |
90 | rxvt_term::bg_window_size_sensitive () |
122 | { |
91 | { |
123 | # ifdef ENABLE_TRANSPARENCY |
92 | # ifdef ENABLE_TRANSPARENCY |
124 | if (flags & isTransparent) |
93 | if (bg_flags & BG_IS_TRANSPARENT) |
125 | return true; |
94 | return true; |
126 | # endif |
95 | # endif |
127 | |
96 | |
128 | # ifdef BG_IMAGE_FROM_FILE |
97 | # ifdef BG_IMAGE_FROM_FILE |
129 | if (have_image) |
98 | if (bg_flags & BG_IS_FROM_FILE) |
130 | { |
99 | { |
131 | if (flags & sizeSensitive) |
100 | if (bg_flags & BG_IS_SIZE_SENSITIVE) |
132 | return true; |
101 | return true; |
133 | } |
102 | } |
134 | # endif |
103 | # endif |
135 | |
104 | |
136 | return false; |
105 | return false; |
137 | } |
106 | } |
138 | |
107 | |
139 | bool |
108 | bool |
140 | bgPixmap_t::window_position_sensitive () |
109 | rxvt_term::bg_window_position_sensitive () |
141 | { |
110 | { |
142 | # ifdef ENABLE_TRANSPARENCY |
111 | # ifdef ENABLE_TRANSPARENCY |
143 | if (flags & isTransparent) |
112 | if (bg_flags & BG_IS_TRANSPARENT) |
144 | return true; |
113 | return true; |
145 | # endif |
114 | # endif |
146 | |
115 | |
147 | # ifdef BG_IMAGE_FROM_FILE |
116 | # ifdef BG_IMAGE_FROM_FILE |
148 | if (have_image) |
117 | if (bg_flags & BG_IS_FROM_FILE) |
149 | { |
118 | { |
150 | if (flags & rootAlign) |
119 | if (bg_flags & BG_ROOT_ALIGN) |
151 | return true; |
120 | return true; |
152 | } |
121 | } |
153 | # endif |
122 | # endif |
154 | |
123 | |
155 | return false; |
124 | return false; |
… | |
… | |
222 | dst_size = target_size - dst_pos; |
191 | dst_size = target_size - dst_pos; |
223 | return src_pos; |
192 | return src_pos; |
224 | } |
193 | } |
225 | |
194 | |
226 | bool |
195 | bool |
227 | bgPixmap_t::set_geometry (const char *geom, bool update) |
196 | rxvt_term::bg_set_geometry (const char *geom, bool update) |
228 | { |
197 | { |
229 | bool changed = false; |
198 | bool changed = false; |
230 | int geom_flags = 0; |
199 | int geom_flags = 0; |
231 | int x = 0, y = 0; |
200 | int x = 0, y = 0; |
232 | unsigned int w = 0, h = 0; |
201 | unsigned int w = 0, h = 0; |
233 | unsigned int n; |
202 | unsigned int n; |
234 | unsigned long new_flags = (flags & (~geometryFlags)); |
203 | unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); |
235 | const char *ops; |
204 | const char *ops; |
236 | |
205 | |
237 | if (geom == NULL) |
206 | if (geom == NULL) |
238 | return false; |
207 | return false; |
239 | |
208 | |
… | |
… | |
279 | { |
248 | { |
280 | char **arr = rxvt_strsplit (':', ops + 1); |
249 | char **arr = rxvt_strsplit (':', ops + 1); |
281 | |
250 | |
282 | for (int i = 0; arr[i]; i++) |
251 | for (int i = 0; arr[i]; i++) |
283 | { |
252 | { |
|
|
253 | if (!strcasecmp (arr[i], "style=tiled")) |
|
|
254 | { |
|
|
255 | new_flags = BG_TILE; |
|
|
256 | w = h = noScale; |
|
|
257 | x = y = 0; |
|
|
258 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
259 | } |
|
|
260 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
|
|
261 | { |
|
|
262 | new_flags = BG_PROP_SCALE; |
|
|
263 | x = y = centerAlign; |
|
|
264 | geom_flags = XValue|YValue; |
|
|
265 | } |
|
|
266 | else if (!strcasecmp (arr[i], "style=stretched")) |
|
|
267 | { |
|
|
268 | new_flags = 0; |
|
|
269 | w = h = windowScale; |
|
|
270 | geom_flags = WidthValue|HeightValue; |
|
|
271 | } |
|
|
272 | else if (!strcasecmp (arr[i], "style=centered")) |
|
|
273 | { |
|
|
274 | new_flags = 0; |
|
|
275 | w = h = noScale; |
|
|
276 | x = y = centerAlign; |
|
|
277 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
278 | } |
|
|
279 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
|
|
280 | { |
|
|
281 | new_flags = BG_TILE|BG_ROOT_ALIGN; |
|
|
282 | w = h = noScale; |
|
|
283 | geom_flags = WidthValue|HeightValue; |
|
|
284 | } |
|
|
285 | else if (!strcasecmp (arr[i], "op=tile")) |
|
|
286 | new_flags |= BG_TILE; |
|
|
287 | else if (!strcasecmp (arr[i], "op=pscale")) |
|
|
288 | new_flags |= BG_PROP_SCALE; |
|
|
289 | else if (!strcasecmp (arr[i], "op=root")) |
|
|
290 | new_flags |= BG_ROOT_ALIGN; |
|
|
291 | |
|
|
292 | // deprecated |
284 | if (!strcasecmp (arr[i], "tile")) |
293 | else if (!strcasecmp (arr[i], "tile")) |
285 | { |
294 | { |
|
|
295 | new_flags |= BG_TILE; |
286 | w = h = noScale; |
296 | w = h = noScale; |
287 | geom_flags |= WidthValue|HeightValue; |
297 | geom_flags |= WidthValue|HeightValue; |
288 | } |
298 | } |
289 | else if (!strcasecmp (arr[i], "propscale")) |
299 | else if (!strcasecmp (arr[i], "propscale")) |
290 | { |
300 | { |
291 | new_flags |= propScale; |
301 | new_flags |= BG_PROP_SCALE; |
292 | } |
|
|
293 | else if (!strcasecmp (arr[i], "hscale")) |
|
|
294 | { |
|
|
295 | if (w == 0) w = windowScale; |
|
|
296 | |
|
|
297 | h = noScale; |
|
|
298 | geom_flags |= WidthValue|HeightValue; |
|
|
299 | } |
|
|
300 | else if (!strcasecmp (arr[i], "vscale")) |
|
|
301 | { |
|
|
302 | if (h == 0) h = windowScale; |
|
|
303 | |
|
|
304 | w = noScale; |
|
|
305 | geom_flags |= WidthValue|HeightValue; |
|
|
306 | } |
302 | } |
307 | else if (!strcasecmp (arr[i], "scale")) |
303 | else if (!strcasecmp (arr[i], "scale")) |
308 | { |
304 | { |
309 | if (h == 0) h = windowScale; |
305 | if (h == 0) h = windowScale; |
310 | if (w == 0) w = windowScale; |
306 | if (w == 0) w = windowScale; |
311 | |
307 | |
312 | geom_flags |= WidthValue|HeightValue; |
308 | geom_flags |= WidthValue|HeightValue; |
313 | } |
309 | } |
314 | else if (!strcasecmp (arr[i], "auto")) |
|
|
315 | { |
|
|
316 | w = h = windowScale; |
|
|
317 | x = y = centerAlign; |
|
|
318 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
319 | } |
|
|
320 | else if (!strcasecmp (arr[i], "root")) |
310 | else if (!strcasecmp (arr[i], "root")) |
321 | { |
311 | { |
322 | new_flags |= rootAlign; |
312 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
323 | w = h = noScale; |
313 | w = h = noScale; |
324 | geom_flags |= WidthValue|HeightValue; |
314 | geom_flags |= WidthValue|HeightValue; |
325 | } |
315 | } |
326 | } /* done parsing ops */ |
316 | } /* done parsing ops */ |
327 | |
317 | |
… | |
… | |
331 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
321 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
332 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
322 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
333 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
323 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
334 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
324 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
335 | |
325 | |
336 | if (new_flags != flags) |
326 | if (new_flags != bg_flags) |
337 | { |
327 | { |
338 | flags = new_flags; |
328 | bg_flags = new_flags; |
339 | changed = true; |
329 | changed = true; |
340 | } |
330 | } |
341 | |
331 | |
342 | return changed; |
332 | return changed; |
343 | } |
333 | } |
344 | |
334 | |
345 | void |
335 | void |
346 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
336 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
347 | { |
337 | { |
348 | int target_width = target->szHint.width; |
338 | int target_width = szHint.width; |
349 | int target_height = target->szHint.height; |
339 | int target_height = szHint.height; |
350 | |
340 | |
351 | if (flags & propScale) |
341 | if (bg_flags & BG_PROP_SCALE) |
352 | { |
342 | { |
353 | float scale = (float)target_width / image_width; |
343 | float scale = (float)target_width / image_width; |
354 | min_it (scale, (float)target_height / image_height); |
344 | min_it (scale, (float)target_height / image_height); |
355 | w = image_width * scale + 0.5; |
345 | w = image_width * scale + 0.5; |
356 | h = image_height * scale + 0.5; |
346 | h = image_height * scale + 0.5; |
… | |
… | |
362 | } |
352 | } |
363 | |
353 | |
364 | if (!w) w = image_width; |
354 | if (!w) w = image_width; |
365 | if (!h) h = image_height; |
355 | if (!h) h = image_height; |
366 | |
356 | |
367 | if (flags & rootAlign) |
357 | if (bg_flags & BG_ROOT_ALIGN) |
368 | { |
358 | { |
369 | x = -target_x; |
359 | x = -target_x; |
370 | y = -target_y; |
360 | y = -target_y; |
371 | } |
361 | } |
372 | else |
362 | else |
373 | { |
363 | { |
374 | x = make_align_position (h_align, target_width, w); |
364 | x = make_align_position (h_align, target_width, w); |
375 | y = make_align_position (v_align, target_height, h); |
365 | y = make_align_position (v_align, target_height, h); |
376 | } |
366 | } |
377 | |
367 | |
378 | flags &= ~sizeSensitive; |
368 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
379 | if ((flags & propScale) || h_scale || v_scale |
369 | if (!(bg_flags & BG_TILE) |
|
|
370 | || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale |
380 | || (!(flags & rootAlign) && (h_align || v_align)) |
371 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
381 | || w > target_width || h > target_height) |
372 | || w > target_width || h > target_height) |
382 | flags |= sizeSensitive; |
373 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
383 | } |
374 | } |
384 | |
375 | |
385 | # ifdef HAVE_AFTERIMAGE |
376 | # ifdef HAVE_AFTERIMAGE |
386 | bool |
377 | bool |
387 | bgPixmap_t::render_image (unsigned long background_flags) |
378 | rxvt_term::render_image (unsigned long tr_flags) |
388 | { |
379 | { |
389 | if (target == NULL) |
|
|
390 | return false; |
|
|
391 | |
|
|
392 | target->init_asv (); |
380 | init_asv (); |
393 | |
381 | |
394 | ASImage *background = NULL; |
382 | ASImage *background = NULL; |
395 | ARGB32 background_tint = TINT_LEAVE_SAME; |
383 | ARGB32 background_tint = TINT_LEAVE_SAME; |
396 | |
384 | |
397 | # ifdef ENABLE_TRANSPARENCY |
385 | # ifdef ENABLE_TRANSPARENCY |
398 | if (background_flags) |
386 | if (tr_flags) |
399 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
387 | background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100); |
400 | |
388 | |
401 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
389 | if (tr_flags & BG_NEEDS_TINT) |
402 | { |
390 | { |
403 | ShadingInfo as_shade; |
391 | ShadingInfo as_shade; |
404 | as_shade.shading = shade; |
392 | as_shade.shading = shade; |
405 | |
393 | |
406 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
394 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
407 | if (flags & tintSet) |
395 | if (bg_flags & BG_TINT_SET) |
408 | tint.get (c); |
396 | tint.get (c); |
409 | as_shade.tintColor.red = c.r; |
397 | as_shade.tintColor.red = c.r; |
410 | as_shade.tintColor.green = c.g; |
398 | as_shade.tintColor.green = c.g; |
411 | as_shade.tintColor.blue = c.b; |
399 | as_shade.tintColor.blue = c.b; |
412 | |
400 | |
413 | background_tint = shading2tint32 (&as_shade); |
401 | background_tint = shading2tint32 (&as_shade); |
414 | } |
402 | } |
415 | |
403 | |
416 | if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL) |
404 | if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) |
417 | { |
405 | { |
418 | ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
406 | ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
419 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
407 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
420 | 100, ASIMAGE_QUALITY_DEFAULT); |
408 | 100, ASIMAGE_QUALITY_DEFAULT); |
421 | if (tmp) |
409 | if (tmp) |
422 | { |
410 | { |
423 | destroy_asimage (&background); |
411 | destroy_asimage (&background); |
… | |
… | |
426 | } |
414 | } |
427 | # endif |
415 | # endif |
428 | |
416 | |
429 | ASImage *result = 0; |
417 | ASImage *result = 0; |
430 | |
418 | |
431 | int target_width = target->szHint.width; |
419 | int target_width = szHint.width; |
432 | int target_height = target->szHint.height; |
420 | int target_height = szHint.height; |
433 | int new_pmap_width = target_width; |
421 | int new_pmap_width = target_width; |
434 | int new_pmap_height = target_height; |
422 | int new_pmap_height = target_height; |
435 | |
423 | |
436 | int x = 0; |
424 | int x = 0; |
437 | int y = 0; |
425 | int y = 0; |
… | |
… | |
440 | |
428 | |
441 | if (original_asim) |
429 | if (original_asim) |
442 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
430 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
443 | |
431 | |
444 | if (!original_asim |
432 | if (!original_asim |
445 | || (!(flags & rootAlign) |
433 | || (!(bg_flags & BG_ROOT_ALIGN) |
446 | && (x >= target_width |
434 | && (x >= target_width |
447 | || y >= target_height |
435 | || y >= target_height |
448 | || (x + w <= 0) |
436 | || (x + w <= 0) |
449 | || (y + h <= 0)))) |
437 | || (y + h <= 0)))) |
450 | { |
438 | { |
… | |
… | |
454 | new_pmap_height = background->height; |
442 | new_pmap_height = background->height; |
455 | result = background; |
443 | result = background; |
456 | |
444 | |
457 | if (background_tint != TINT_LEAVE_SAME) |
445 | if (background_tint != TINT_LEAVE_SAME) |
458 | { |
446 | { |
459 | ASImage *tmp = tile_asimage (target->asv, background, 0, 0, |
447 | ASImage *tmp = tile_asimage (asv, background, 0, 0, |
460 | target_width, target_height, background_tint, |
448 | target_width, target_height, background_tint, |
461 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
449 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
462 | if (tmp) |
450 | if (tmp) |
463 | result = tmp; |
451 | result = tmp; |
464 | } |
452 | } |
… | |
… | |
471 | result = original_asim; |
459 | result = original_asim; |
472 | |
460 | |
473 | if ((w != original_asim->width) |
461 | if ((w != original_asim->width) |
474 | || (h != original_asim->height)) |
462 | || (h != original_asim->height)) |
475 | { |
463 | { |
476 | result = scale_asimage (target->asv, original_asim, |
464 | result = scale_asimage (asv, original_asim, |
477 | w, h, |
465 | w, h, |
478 | background ? ASA_ASImage : ASA_XImage, |
466 | background ? ASA_ASImage : ASA_XImage, |
479 | 100, ASIMAGE_QUALITY_DEFAULT); |
467 | 100, ASIMAGE_QUALITY_DEFAULT); |
480 | } |
468 | } |
481 | |
469 | |
482 | if (background == NULL) |
470 | if (background == NULL) |
483 | { |
471 | { |
484 | if (h_scale == 0 || v_scale == 0) |
472 | if (bg_flags & BG_TILE) |
485 | { |
473 | { |
486 | /* if tiling - pixmap has to be sized exactly as the image, |
474 | /* if tiling - pixmap has to be sized exactly as the image, |
487 | but there is no need to make it bigger than the window! */ |
475 | but there is no need to make it bigger than the window! */ |
488 | new_pmap_width = min (result->width, target_width); |
476 | new_pmap_width = min (result->width, target_width); |
489 | new_pmap_height = min (result->height, target_height); |
477 | new_pmap_height = min (result->height, target_height); |
490 | |
478 | |
491 | /* we also need to tile our image in both directions */ |
479 | /* we also need to tile our image in both directions */ |
492 | ASImage *tmp = tile_asimage (target->asv, result, |
480 | ASImage *tmp = tile_asimage (asv, result, |
493 | (int)result->width - x, |
481 | (int)result->width - x, |
494 | (int)result->height - y, |
482 | (int)result->height - y, |
495 | new_pmap_width, |
483 | new_pmap_width, |
496 | new_pmap_height, |
484 | new_pmap_height, |
497 | TINT_LEAVE_SAME, ASA_XImage, |
485 | TINT_LEAVE_SAME, ASA_XImage, |
… | |
… | |
514 | layers[0].clip_width = target_width; |
502 | layers[0].clip_width = target_width; |
515 | layers[0].clip_height = target_height; |
503 | layers[0].clip_height = target_height; |
516 | layers[0].tint = background_tint; |
504 | layers[0].tint = background_tint; |
517 | layers[1].im = result; |
505 | layers[1].im = result; |
518 | |
506 | |
519 | if (h_scale == 0 || v_scale == 0) |
507 | if (bg_flags & BG_TILE) |
520 | { |
508 | { |
521 | /* tile horizontally */ |
509 | /* tile horizontally */ |
522 | while (x > 0) x -= (int)result->width; |
510 | while (x > 0) x -= (int)result->width; |
523 | layers[1].dst_x = x; |
511 | layers[1].dst_x = x; |
524 | layers[1].clip_width = result->width+target_width; |
512 | layers[1].clip_width = result->width+target_width; |
… | |
… | |
528 | /* clip horizontally */ |
516 | /* clip horizontally */ |
529 | layers[1].dst_x = x; |
517 | layers[1].dst_x = x; |
530 | layers[1].clip_width = result->width; |
518 | layers[1].clip_width = result->width; |
531 | } |
519 | } |
532 | |
520 | |
533 | if (h_scale == 0 || v_scale == 0) |
521 | if (bg_flags & BG_TILE) |
534 | { |
522 | { |
535 | while (y > 0) y -= (int)result->height; |
523 | while (y > 0) y -= (int)result->height; |
536 | layers[1].dst_y = y; |
524 | layers[1].dst_y = y; |
537 | layers[1].clip_height = result->height + target_height; |
525 | layers[1].clip_height = result->height + target_height; |
538 | } |
526 | } |
… | |
… | |
540 | { |
528 | { |
541 | layers[1].dst_y = y; |
529 | layers[1].dst_y = y; |
542 | layers[1].clip_height = result->height; |
530 | layers[1].clip_height = result->height; |
543 | } |
531 | } |
544 | |
532 | |
545 | if (target->rs[Rs_blendtype]) |
533 | if (rs[Rs_blendtype]) |
546 | { |
534 | { |
547 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
535 | layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); |
548 | if (layers[1].merge_scanlines == NULL) |
536 | if (layers[1].merge_scanlines == NULL) |
549 | layers[1].merge_scanlines = alphablend_scanlines; |
537 | layers[1].merge_scanlines = alphablend_scanlines; |
550 | } |
538 | } |
551 | |
539 | |
552 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
540 | ASImage *tmp = merge_layers (asv, layers, 2, target_width, target_height, |
553 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
541 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
554 | |
542 | |
555 | if (tmp) |
543 | if (tmp) |
556 | { |
544 | { |
557 | if (result != original_asim) |
545 | if (result != original_asim) |
… | |
… | |
570 | { |
558 | { |
571 | XGCValues gcv; |
559 | XGCValues gcv; |
572 | GC gc; |
560 | GC gc; |
573 | |
561 | |
574 | /* create Pixmap */ |
562 | /* create Pixmap */ |
575 | if (pixmap == None |
563 | if (bg_pixmap == None |
576 | || pmap_width != new_pmap_width |
564 | || bg_pmap_width != new_pmap_width |
577 | || pmap_height != new_pmap_height) |
565 | || bg_pmap_height != new_pmap_height) |
578 | { |
566 | { |
579 | if (pixmap) |
567 | if (bg_pixmap) |
580 | XFreePixmap (target->dpy, pixmap); |
568 | XFreePixmap (dpy, bg_pixmap); |
581 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
569 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
582 | pmap_width = new_pmap_width; |
570 | bg_pmap_width = new_pmap_width; |
583 | pmap_height = new_pmap_height; |
571 | bg_pmap_height = new_pmap_height; |
584 | } |
572 | } |
585 | /* fill with background color (if result's not completely overlapping it) */ |
573 | /* fill with background color (if result's not completely overlapping it) */ |
586 | gcv.foreground = target->pix_colors[Color_bg]; |
574 | gcv.foreground = pix_colors[Color_bg]; |
587 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
575 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
588 | |
576 | |
589 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
577 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
590 | int dst_width = result->width, dst_height = result->height; |
578 | int dst_width = result->width, dst_height = result->height; |
591 | if (background == NULL) |
579 | if (background == NULL) |
592 | { |
580 | { |
593 | if (!(h_scale == 0 || v_scale == 0)) |
581 | if (!(bg_flags & BG_TILE)) |
594 | { |
582 | { |
595 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
583 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
596 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
584 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
597 | } |
585 | } |
598 | |
586 | |
599 | if (dst_x > 0 || dst_y > 0 |
587 | if (dst_x > 0 || dst_y > 0 |
600 | || dst_x + dst_width < new_pmap_width |
588 | || dst_x + dst_width < new_pmap_width |
601 | || dst_y + dst_height < new_pmap_height) |
589 | || dst_y + dst_height < new_pmap_height) |
602 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
590 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
603 | } |
591 | } |
604 | |
592 | |
605 | /* put result on pixmap */ |
593 | /* put result on pixmap */ |
606 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
594 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
607 | asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
595 | asimage2drawable (asv, bg_pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
608 | |
596 | |
609 | if (result != background && result != original_asim) |
597 | if (result != background && result != original_asim) |
610 | destroy_asimage (&result); |
598 | destroy_asimage (&result); |
611 | |
599 | |
612 | XFreeGC (target->dpy, gc); |
600 | XFreeGC (dpy, gc); |
613 | |
601 | |
614 | ret = true; |
602 | ret = true; |
615 | } |
603 | } |
616 | |
604 | |
617 | if (background) |
605 | if (background) |
… | |
… | |
621 | } |
609 | } |
622 | # endif /* HAVE_AFTERIMAGE */ |
610 | # endif /* HAVE_AFTERIMAGE */ |
623 | |
611 | |
624 | # ifdef HAVE_PIXBUF |
612 | # ifdef HAVE_PIXBUF |
625 | bool |
613 | bool |
626 | bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
614 | rxvt_term::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
627 | int src_x, int src_y, int dst_x, int dst_y, |
615 | int src_x, int src_y, int dst_x, int dst_y, |
628 | unsigned int width, unsigned int height) |
616 | unsigned int width, unsigned int height) |
629 | { |
617 | { |
630 | XImage *ximage; |
618 | XImage *ximage; |
631 | char *data, *line; |
619 | char *data, *line; |
632 | int bytes_per_pixel; |
620 | int bytes_per_pixel; |
633 | int width_r, width_g, width_b; |
621 | int width_r, width_g, width_b; |
634 | int sh_r, sh_g, sh_b; |
622 | int sh_r, sh_g, sh_b; |
635 | int rowstride; |
623 | int rowstride; |
636 | int channels; |
624 | int channels; |
637 | unsigned char *row; |
625 | unsigned char *row; |
638 | Visual *visual = target->visual; |
|
|
639 | int depth = target->depth; |
|
|
640 | |
626 | |
641 | if (visual->c_class != TrueColor) |
627 | if (visual->c_class != TrueColor) |
642 | return false; |
628 | return false; |
643 | |
629 | |
644 | if (depth == 24 || depth == 32) |
630 | if (depth == 24 || depth == 32) |
… | |
… | |
646 | else if (depth == 15 || depth == 16) |
632 | else if (depth == 15 || depth == 16) |
647 | bytes_per_pixel = 2; |
633 | bytes_per_pixel = 2; |
648 | else |
634 | else |
649 | return false; |
635 | return false; |
650 | |
636 | |
651 | width_r = rxvt_popcount (visual->red_mask); |
637 | width_r = ecb_popcount32 (visual->red_mask); |
652 | width_g = rxvt_popcount (visual->green_mask); |
638 | width_g = ecb_popcount32 (visual->green_mask); |
653 | width_b = rxvt_popcount (visual->blue_mask); |
639 | width_b = ecb_popcount32 (visual->blue_mask); |
654 | |
640 | |
655 | if (width_r > 8 || width_g > 8 || width_b > 8) |
641 | if (width_r > 8 || width_g > 8 || width_b > 8) |
656 | return false; |
642 | return false; |
657 | |
643 | |
658 | sh_r = rxvt_ctz (visual->red_mask); |
644 | sh_r = ecb_ctz32 (visual->red_mask); |
659 | sh_g = rxvt_ctz (visual->green_mask); |
645 | sh_g = ecb_ctz32 (visual->green_mask); |
660 | sh_b = rxvt_ctz (visual->blue_mask); |
646 | sh_b = ecb_ctz32 (visual->blue_mask); |
661 | |
647 | |
662 | if (width > INT_MAX / height / bytes_per_pixel) |
648 | if (width > INT_MAX / height / bytes_per_pixel) |
663 | return false; |
649 | return false; |
664 | |
650 | |
665 | data = (char *)malloc (width * height * bytes_per_pixel); |
651 | data = (char *)malloc (width * height * bytes_per_pixel); |
666 | if (!data) |
652 | if (!data) |
667 | return false; |
653 | return false; |
668 | |
654 | |
669 | ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data, |
655 | ximage = XCreateImage (dpy, visual, depth, ZPixmap, 0, data, |
670 | width, height, bytes_per_pixel * 8, 0); |
656 | width, height, bytes_per_pixel * 8, 0); |
671 | if (!ximage) |
657 | if (!ximage) |
672 | { |
658 | { |
673 | free (data); |
659 | free (data); |
674 | return false; |
660 | return false; |
675 | } |
661 | } |
676 | |
662 | |
677 | ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
663 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
678 | |
664 | |
679 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
665 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
680 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
666 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
681 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
667 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
682 | line = data; |
668 | line = data; |
… | |
… | |
700 | |
686 | |
701 | row += rowstride; |
687 | row += rowstride; |
702 | line += ximage->bytes_per_line; |
688 | line += ximage->bytes_per_line; |
703 | } |
689 | } |
704 | |
690 | |
705 | XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height); |
691 | XPutImage (dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height); |
706 | XDestroyImage (ximage); |
692 | XDestroyImage (ximage); |
707 | return true; |
693 | return true; |
708 | } |
694 | } |
709 | |
695 | |
710 | bool |
696 | bool |
711 | bgPixmap_t::render_image (unsigned long background_flags) |
697 | rxvt_term::render_image (unsigned long tr_flags) |
712 | { |
698 | { |
713 | if (target == NULL) |
|
|
714 | return false; |
|
|
715 | |
|
|
716 | if (!pixbuf) |
699 | if (!pixbuf) |
717 | return false; |
700 | return false; |
718 | |
701 | |
719 | if (background_flags |
702 | if (tr_flags |
720 | && !(flags & HAS_RENDER)) |
703 | && !(bg_flags & BG_HAS_RENDER)) |
721 | return false; |
704 | return false; |
722 | |
705 | |
723 | GdkPixbuf *result; |
706 | GdkPixbuf *result; |
724 | |
707 | |
725 | int image_width = gdk_pixbuf_get_width (pixbuf); |
708 | int image_width = gdk_pixbuf_get_width (pixbuf); |
726 | int image_height = gdk_pixbuf_get_height (pixbuf); |
709 | int image_height = gdk_pixbuf_get_height (pixbuf); |
727 | |
710 | |
728 | int target_width = target->szHint.width; |
711 | int target_width = szHint.width; |
729 | int target_height = target->szHint.height; |
712 | int target_height = szHint.height; |
730 | int new_pmap_width = target_width; |
713 | int new_pmap_width = target_width; |
731 | int new_pmap_height = target_height; |
714 | int new_pmap_height = target_height; |
732 | |
715 | |
733 | int x = 0; |
716 | int x = 0; |
734 | int y = 0; |
717 | int y = 0; |
735 | int w = 0; |
718 | int w = 0; |
736 | int h = 0; |
719 | int h = 0; |
737 | |
720 | |
738 | get_image_geometry (image_width, image_height, w, h, x, y); |
721 | get_image_geometry (image_width, image_height, w, h, x, y); |
739 | |
722 | |
740 | if (!(flags & rootAlign) |
723 | if (!(bg_flags & BG_ROOT_ALIGN) |
741 | && (x >= target_width |
724 | && (x >= target_width |
742 | || y >= target_height |
725 | || y >= target_height |
743 | || (x + w <= 0) |
726 | || (x + w <= 0) |
744 | || (y + h <= 0))) |
727 | || (y + h <= 0))) |
745 | return false; |
728 | return false; |
… | |
… | |
752 | result = gdk_pixbuf_scale_simple (pixbuf, |
735 | result = gdk_pixbuf_scale_simple (pixbuf, |
753 | w, h, |
736 | w, h, |
754 | GDK_INTERP_BILINEAR); |
737 | GDK_INTERP_BILINEAR); |
755 | } |
738 | } |
756 | |
739 | |
|
|
740 | if (!result) |
|
|
741 | return false; |
|
|
742 | |
757 | bool ret = false; |
743 | bool ret = false; |
758 | |
744 | |
759 | if (result) |
|
|
760 | { |
|
|
761 | XGCValues gcv; |
745 | XGCValues gcv; |
762 | GC gc; |
746 | GC gc; |
763 | Pixmap root_pmap; |
747 | Pixmap root_pmap; |
764 | |
748 | |
765 | image_width = gdk_pixbuf_get_width (result); |
749 | image_width = gdk_pixbuf_get_width (result); |
766 | image_height = gdk_pixbuf_get_height (result); |
750 | image_height = gdk_pixbuf_get_height (result); |
767 | |
751 | |
768 | if (background_flags) |
752 | if (tr_flags) |
769 | { |
753 | { |
770 | root_pmap = pixmap; |
754 | root_pmap = bg_pixmap; |
771 | pixmap = None; |
755 | bg_pixmap = None; |
|
|
756 | } |
|
|
757 | else |
|
|
758 | { |
|
|
759 | if (bg_flags & BG_TILE) |
772 | } |
760 | { |
773 | else |
|
|
774 | { |
|
|
775 | if (h_scale == 0 || v_scale == 0) |
|
|
776 | { |
|
|
777 | new_pmap_width = min (image_width, target_width); |
761 | new_pmap_width = min (image_width, target_width); |
778 | new_pmap_height = min (image_height, target_height); |
762 | new_pmap_height = min (image_height, target_height); |
779 | } |
763 | } |
780 | } |
764 | } |
781 | |
765 | |
782 | if (pixmap == None |
766 | if (bg_pixmap == None |
783 | || pmap_width != new_pmap_width |
767 | || bg_pmap_width != new_pmap_width |
784 | || pmap_height != new_pmap_height) |
768 | || bg_pmap_height != new_pmap_height) |
785 | { |
769 | { |
786 | if (pixmap) |
770 | if (bg_pixmap) |
787 | XFreePixmap (target->dpy, pixmap); |
771 | XFreePixmap (dpy, bg_pixmap); |
788 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
772 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
789 | pmap_width = new_pmap_width; |
773 | bg_pmap_width = new_pmap_width; |
790 | pmap_height = new_pmap_height; |
774 | bg_pmap_height = new_pmap_height; |
|
|
775 | } |
|
|
776 | |
|
|
777 | gcv.foreground = pix_colors[Color_bg]; |
|
|
778 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
|
|
779 | |
|
|
780 | if (gc) |
|
|
781 | { |
|
|
782 | if (bg_flags & BG_TILE) |
791 | } |
783 | { |
792 | |
|
|
793 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
794 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
795 | |
|
|
796 | if (h_scale == 0 || v_scale == 0) |
|
|
797 | { |
|
|
798 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
784 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
799 | pixbuf_to_pixmap (result, tile, gc, |
785 | pixbuf_to_pixmap (result, tile, gc, |
800 | 0, 0, |
786 | 0, 0, |
801 | 0, 0, |
787 | 0, 0, |
802 | image_width, image_height); |
788 | image_width, image_height); |
803 | |
789 | |
804 | gcv.tile = tile; |
790 | gcv.tile = tile; |
805 | gcv.fill_style = FillTiled; |
791 | gcv.fill_style = FillTiled; |
806 | gcv.ts_x_origin = x; |
792 | gcv.ts_x_origin = x; |
807 | gcv.ts_y_origin = y; |
793 | gcv.ts_y_origin = y; |
808 | XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
794 | XChangeGC (dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
809 | |
795 | |
810 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
796 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
811 | XFreePixmap (target->dpy, tile); |
797 | XFreePixmap (dpy, tile); |
812 | } |
798 | } |
813 | else |
799 | else |
814 | { |
800 | { |
815 | int src_x, src_y, dst_x, dst_y; |
801 | int src_x, src_y, dst_x, dst_y; |
816 | int dst_width, dst_height; |
802 | int dst_width, dst_height; |
… | |
… | |
819 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
805 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
820 | |
806 | |
821 | if (dst_x > 0 || dst_y > 0 |
807 | if (dst_x > 0 || dst_y > 0 |
822 | || dst_x + dst_width < new_pmap_width |
808 | || dst_x + dst_width < new_pmap_width |
823 | || dst_y + dst_height < new_pmap_height) |
809 | || dst_y + dst_height < new_pmap_height) |
824 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
810 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
825 | |
811 | |
826 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
812 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
827 | pixbuf_to_pixmap (result, pixmap, gc, |
813 | pixbuf_to_pixmap (result, bg_pixmap, gc, |
828 | src_x, src_y, |
814 | src_x, src_y, |
829 | dst_x, dst_y, |
815 | dst_x, dst_y, |
830 | dst_width, dst_height); |
816 | dst_width, dst_height); |
831 | } |
817 | } |
832 | |
818 | |
833 | #if XRENDER |
819 | #if XRENDER |
834 | if (background_flags) |
820 | if (tr_flags) |
835 | { |
821 | { |
836 | Display *dpy = target->dpy; |
|
|
837 | XRenderPictureAttributes pa; |
822 | XRenderPictureAttributes pa; |
838 | |
823 | |
839 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, target->visual); |
824 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, visual); |
840 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
825 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
841 | |
826 | |
842 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
827 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
843 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
828 | Picture dst = XRenderCreatePicture (dpy, bg_pixmap, dst_format, 0, &pa); |
844 | |
829 | |
845 | pa.repeat = True; |
830 | pa.repeat = True; |
846 | Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8); |
831 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
847 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
832 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
848 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
833 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
849 | XFreePixmap (dpy, mask_pmap); |
834 | XFreePixmap (dpy, mask_pmap); |
850 | |
835 | |
851 | if (src && dst && mask) |
|
|
852 | { |
|
|
853 | XRenderColor mask_c; |
836 | XRenderColor mask_c; |
854 | |
837 | |
855 | mask_c.alpha = 0x8000; |
838 | mask_c.alpha = 0x8000; |
856 | mask_c.red = 0; |
839 | mask_c.red = 0; |
857 | mask_c.green = 0; |
840 | mask_c.green = 0; |
858 | mask_c.blue = 0; |
841 | mask_c.blue = 0; |
859 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
842 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
860 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
843 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
861 | } |
|
|
862 | |
844 | |
863 | XRenderFreePicture (dpy, src); |
845 | XRenderFreePicture (dpy, src); |
864 | XRenderFreePicture (dpy, dst); |
846 | XRenderFreePicture (dpy, dst); |
865 | XRenderFreePicture (dpy, mask); |
847 | XRenderFreePicture (dpy, mask); |
866 | |
|
|
867 | XFreePixmap (dpy, root_pmap); |
|
|
868 | } |
848 | } |
869 | #endif |
849 | #endif |
870 | |
850 | |
871 | if (result != pixbuf) |
|
|
872 | g_object_unref (result); |
|
|
873 | |
|
|
874 | XFreeGC (target->dpy, gc); |
851 | XFreeGC (dpy, gc); |
875 | |
852 | |
876 | ret = true; |
853 | ret = true; |
877 | } |
854 | } |
878 | |
855 | |
|
|
856 | if (result != pixbuf) |
|
|
857 | g_object_unref (result); |
|
|
858 | |
|
|
859 | if (tr_flags) |
|
|
860 | XFreePixmap (dpy, root_pmap); |
|
|
861 | |
879 | return ret; |
862 | return ret; |
880 | } |
863 | } |
881 | # endif /* HAVE_PIXBUF */ |
864 | # endif /* HAVE_PIXBUF */ |
882 | |
865 | |
883 | bool |
866 | bool |
884 | bgPixmap_t::set_file (const char *file) |
867 | rxvt_term::bg_set_file (const char *file) |
885 | { |
868 | { |
886 | if (!file || !*file) |
869 | if (!file || !*file) |
887 | return false; |
870 | return false; |
888 | |
871 | |
889 | if (const char *p = strchr (file, ';')) |
872 | if (const char *p = strchr (file, ';')) |
… | |
… | |
894 | f[len] = '\0'; |
877 | f[len] = '\0'; |
895 | file = f; |
878 | file = f; |
896 | } |
879 | } |
897 | |
880 | |
898 | # ifdef HAVE_AFTERIMAGE |
881 | # ifdef HAVE_AFTERIMAGE |
899 | if (!target->asimman) |
882 | if (!asimman) |
900 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
883 | asimman = create_generic_imageman (rs[Rs_path]); |
901 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
884 | ASImage *image = get_asimage (asimman, file, 0xFFFFFFFF, 100); |
902 | if (image) |
885 | if (image) |
903 | { |
886 | { |
904 | if (original_asim) |
887 | if (original_asim) |
905 | safe_asimage_destroy (original_asim); |
888 | safe_asimage_destroy (original_asim); |
906 | original_asim = image; |
889 | original_asim = image; |
907 | flags |= CLIENT_RENDER; |
890 | bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; |
908 | have_image = true; |
|
|
909 | return true; |
891 | return true; |
910 | } |
892 | } |
911 | # endif |
893 | # endif |
912 | |
894 | |
913 | # ifdef HAVE_PIXBUF |
895 | # ifdef HAVE_PIXBUF |
… | |
… | |
915 | if (image) |
897 | if (image) |
916 | { |
898 | { |
917 | if (pixbuf) |
899 | if (pixbuf) |
918 | g_object_unref (pixbuf); |
900 | g_object_unref (pixbuf); |
919 | pixbuf = image; |
901 | pixbuf = image; |
920 | have_image = true; |
902 | bg_flags |= BG_IS_FROM_FILE; |
921 | return true; |
903 | return true; |
922 | } |
904 | } |
923 | # endif |
905 | # endif |
924 | |
906 | |
925 | return false; |
907 | return false; |
… | |
… | |
927 | |
909 | |
928 | # endif /* BG_IMAGE_FROM_FILE */ |
910 | # endif /* BG_IMAGE_FROM_FILE */ |
929 | |
911 | |
930 | # ifdef ENABLE_TRANSPARENCY |
912 | # ifdef ENABLE_TRANSPARENCY |
931 | bool |
913 | bool |
932 | bgPixmap_t::set_transparent () |
914 | rxvt_term::bg_set_transparent () |
933 | { |
915 | { |
934 | if (!(flags & isTransparent)) |
916 | if (!(bg_flags & BG_IS_TRANSPARENT)) |
935 | { |
917 | { |
936 | flags |= isTransparent; |
918 | bg_flags |= BG_IS_TRANSPARENT; |
937 | return true; |
919 | return true; |
938 | } |
920 | } |
939 | |
921 | |
940 | return false; |
922 | return false; |
941 | } |
923 | } |
942 | |
924 | |
943 | bool |
925 | bool |
944 | bgPixmap_t::set_blur_radius (const char *geom) |
926 | rxvt_term::bg_set_blur (const char *geom) |
945 | { |
927 | { |
946 | bool changed = false; |
928 | bool changed = false; |
947 | unsigned int hr, vr; |
929 | unsigned int hr, vr; |
948 | int junk; |
930 | int junk; |
949 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
931 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
… | |
… | |
967 | changed = true; |
949 | changed = true; |
968 | v_blurRadius = vr; |
950 | v_blurRadius = vr; |
969 | } |
951 | } |
970 | |
952 | |
971 | if (v_blurRadius == 0 && h_blurRadius == 0) |
953 | if (v_blurRadius == 0 && h_blurRadius == 0) |
972 | flags &= ~blurNeeded; |
954 | bg_flags &= ~BG_NEEDS_BLUR; |
973 | else |
955 | else |
974 | flags |= blurNeeded; |
956 | bg_flags |= BG_NEEDS_BLUR; |
975 | |
957 | |
976 | return changed; |
958 | return changed; |
977 | } |
959 | } |
978 | |
960 | |
979 | static inline unsigned long |
961 | void |
980 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
962 | rxvt_term::set_tint_shade_flags () |
981 | { |
963 | { |
982 | unsigned long flags = 0; |
|
|
983 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
964 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
984 | bool has_shade = shade != 100; |
965 | bool has_shade = shade != 100; |
985 | |
966 | |
986 | if (tint) |
967 | bg_flags &= ~BG_TINT_FLAGS; |
|
|
968 | |
|
|
969 | if (bg_flags & BG_TINT_SET) |
987 | { |
970 | { |
988 | tint->get (c); |
971 | tint.get (c); |
989 | if (!has_shade |
972 | if (!has_shade |
990 | && (c.r <= 0x00ff || c.r >= 0xff00) |
973 | && (c.r <= 0x00ff || c.r >= 0xff00) |
991 | && (c.g <= 0x00ff || c.g >= 0xff00) |
974 | && (c.g <= 0x00ff || c.g >= 0xff00) |
992 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
975 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
993 | flags |= bgPixmap_t::tintWholesome; |
976 | bg_flags |= BG_TINT_BITAND; |
994 | } |
977 | } |
995 | |
978 | |
996 | if (has_shade || tint) |
979 | if (has_shade || (bg_flags & BG_TINT_SET)) |
997 | flags |= bgPixmap_t::tintNeeded; |
980 | bg_flags |= BG_NEEDS_TINT; |
998 | |
|
|
999 | return flags; |
|
|
1000 | } |
981 | } |
1001 | |
982 | |
1002 | bool |
983 | bool |
1003 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
984 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
1004 | { |
985 | { |
1005 | if (!(flags & tintSet) || tint != new_tint) |
986 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
1006 | { |
987 | { |
1007 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
|
|
1008 | tint = new_tint; |
988 | tint = new_tint; |
1009 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
989 | bg_flags |= BG_TINT_SET; |
|
|
990 | set_tint_shade_flags (); |
1010 | return true; |
991 | return true; |
1011 | } |
992 | } |
1012 | |
993 | |
1013 | return false; |
994 | return false; |
1014 | } |
995 | } |
1015 | |
996 | |
1016 | bool |
997 | bool |
1017 | bgPixmap_t::set_shade (const char *shade_str) |
998 | rxvt_term::bg_set_shade (const char *shade_str) |
1018 | { |
999 | { |
1019 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
1000 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
1020 | |
1001 | |
1021 | clamp_it (new_shade, -100, 200); |
1002 | clamp_it (new_shade, -100, 200); |
1022 | if (new_shade < 0) |
1003 | if (new_shade < 0) |
1023 | new_shade = 200 - (100 + new_shade); |
1004 | new_shade = 200 - (100 + new_shade); |
1024 | |
1005 | |
1025 | if (new_shade != shade) |
1006 | if (new_shade != shade) |
1026 | { |
1007 | { |
1027 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
|
|
1028 | shade = new_shade; |
1008 | shade = new_shade; |
1029 | flags = (flags & ~tintFlags) | new_flags; |
1009 | set_tint_shade_flags (); |
1030 | return true; |
1010 | return true; |
1031 | } |
1011 | } |
1032 | |
1012 | |
1033 | return false; |
1013 | return false; |
1034 | } |
1014 | } |
… | |
… | |
1055 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1035 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
1056 | } |
1036 | } |
1057 | #endif |
1037 | #endif |
1058 | |
1038 | |
1059 | bool |
1039 | bool |
1060 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1040 | rxvt_term::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1061 | { |
1041 | { |
1062 | bool ret = false; |
1042 | bool ret = false; |
1063 | #if XRENDER |
1043 | #if XRENDER |
1064 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1044 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
1065 | double *kernel = (double *)malloc (size * sizeof (double)); |
1045 | double *kernel = (double *)malloc (size * sizeof (double)); |
1066 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1046 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
1067 | |
1047 | |
1068 | Display *dpy = target->dpy; |
|
|
1069 | XRenderPictureAttributes pa; |
1048 | XRenderPictureAttributes pa; |
1070 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1049 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1071 | |
1050 | |
1072 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1051 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1073 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1052 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1074 | |
1053 | |
1075 | if (kernel && params && src && dst) |
1054 | if (kernel && params) |
1076 | { |
1055 | { |
1077 | if (h_blurRadius) |
1056 | if (h_blurRadius) |
1078 | { |
1057 | { |
1079 | size = h_blurRadius * 2 + 1; |
1058 | size = h_blurRadius * 2 + 1; |
1080 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
1059 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
… | |
… | |
1093 | |
1072 | |
1094 | if (v_blurRadius) |
1073 | if (v_blurRadius) |
1095 | { |
1074 | { |
1096 | size = v_blurRadius * 2 + 1; |
1075 | size = v_blurRadius * 2 + 1; |
1097 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1076 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
1098 | swap (params[0], params[1]); |
1077 | ::swap (params[0], params[1]); |
1099 | |
1078 | |
1100 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1079 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
1101 | XRenderComposite (dpy, |
1080 | XRenderComposite (dpy, |
1102 | PictOpSrc, |
1081 | PictOpSrc, |
1103 | src, |
1082 | src, |
… | |
… | |
1119 | #endif |
1098 | #endif |
1120 | return ret; |
1099 | return ret; |
1121 | } |
1100 | } |
1122 | |
1101 | |
1123 | bool |
1102 | bool |
1124 | bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1103 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1125 | { |
1104 | { |
1126 | Display *dpy = target->dpy; |
|
|
1127 | bool ret = false; |
1105 | bool ret = false; |
1128 | |
1106 | |
1129 | if (flags & tintWholesome) |
1107 | if (bg_flags & BG_TINT_BITAND) |
1130 | { |
1108 | { |
1131 | XGCValues gcv; |
1109 | XGCValues gcv; |
1132 | GC gc; |
1110 | GC gc; |
1133 | |
1111 | |
1134 | /* In this case we can tint image server-side getting significant |
1112 | /* In this case we can tint image server-side getting significant |
… | |
… | |
1146 | } |
1124 | } |
1147 | } |
1125 | } |
1148 | else |
1126 | else |
1149 | { |
1127 | { |
1150 | # if XRENDER |
1128 | # if XRENDER |
1151 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1129 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1152 | |
1130 | |
1153 | if (flags & tintSet) |
1131 | if (bg_flags & BG_TINT_SET) |
1154 | tint.get (c); |
1132 | tint.get (c); |
1155 | |
1133 | |
1156 | if (shade <= 100) |
1134 | if (shade <= 100) |
1157 | { |
1135 | { |
1158 | c.r = (c.r * shade) / 100; |
1136 | c.r = c.r * shade / 100; |
1159 | c.g = (c.g * shade) / 100; |
1137 | c.g = c.g * shade / 100; |
1160 | c.b = (c.b * shade) / 100; |
1138 | c.b = c.b * shade / 100; |
1161 | } |
1139 | } |
1162 | else |
1140 | else |
1163 | { |
1141 | { |
1164 | c.r = (c.r * (200 - shade)) / 100; |
1142 | c.r = c.r * (200 - shade) / 100; |
1165 | c.g = (c.g * (200 - shade)) / 100; |
1143 | c.g = c.g * (200 - shade) / 100; |
1166 | c.b = (c.b * (200 - shade)) / 100; |
1144 | c.b = c.b * (200 - shade) / 100; |
1167 | } |
1145 | } |
1168 | |
1146 | |
1169 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1147 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1170 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1148 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1171 | XRenderPictureAttributes pa; |
1149 | XRenderPictureAttributes pa; |
… | |
… | |
1178 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1156 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1179 | XFreePixmap (dpy, overlay_pmap); |
1157 | XFreePixmap (dpy, overlay_pmap); |
1180 | |
1158 | |
1181 | pa.component_alpha = True; |
1159 | pa.component_alpha = True; |
1182 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1160 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1183 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
1161 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); |
1184 | XFreePixmap (dpy, mask_pmap); |
1162 | XFreePixmap (dpy, mask_pmap); |
1185 | |
1163 | |
1186 | if (mask_pic && overlay_pic && back_pic) |
|
|
1187 | { |
|
|
1188 | XRenderColor mask_c; |
1164 | XRenderColor mask_c; |
1189 | |
1165 | |
1190 | mask_c.red = mask_c.green = mask_c.blue = 0; |
|
|
1191 | mask_c.alpha = 0xffff; |
1166 | mask_c.alpha = 0xffff; |
|
|
1167 | mask_c.red = |
|
|
1168 | mask_c.green = |
|
|
1169 | mask_c.blue = 0; |
|
|
1170 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1171 | |
|
|
1172 | mask_c.alpha = 0; |
|
|
1173 | mask_c.red = 0xffff - c.r; |
|
|
1174 | mask_c.green = 0xffff - c.g; |
|
|
1175 | mask_c.blue = 0xffff - c.b; |
|
|
1176 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1177 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1178 | |
|
|
1179 | if (shade > 100) |
|
|
1180 | { |
|
|
1181 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1182 | mask_c.alpha = 0; |
1192 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1183 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1193 | |
1184 | |
1194 | mask_c.alpha = 0; |
|
|
1195 | mask_c.red = 0xffff - c.r; |
|
|
1196 | mask_c.green = 0xffff - c.g; |
|
|
1197 | mask_c.blue = 0xffff - c.b; |
|
|
1198 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1199 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1200 | |
|
|
1201 | if (shade > 100) |
|
|
1202 | { |
|
|
1203 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1204 | mask_c.alpha = 0; |
|
|
1205 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1206 | |
|
|
1207 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1185 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1208 | } |
1186 | } |
1209 | |
1187 | |
1210 | ret = true; |
1188 | ret = true; |
1211 | } |
|
|
1212 | |
1189 | |
1213 | XRenderFreePicture (dpy, mask_pic); |
1190 | XRenderFreePicture (dpy, mask_pic); |
1214 | XRenderFreePicture (dpy, overlay_pic); |
1191 | XRenderFreePicture (dpy, overlay_pic); |
1215 | XRenderFreePicture (dpy, back_pic); |
1192 | XRenderFreePicture (dpy, back_pic); |
1216 | # endif |
1193 | # endif |
1217 | } |
1194 | } |
1218 | |
1195 | |
1219 | return ret; |
1196 | return ret; |
1220 | } |
1197 | } |
1221 | |
1198 | |
1222 | /* make_transparency_pixmap() |
1199 | /* |
1223 | * Builds a pixmap of the same size as the terminal window that contains |
1200 | * Builds a pixmap of the same size as the terminal window that contains |
1224 | * the tiled portion of the root pixmap that is supposed to be covered by |
1201 | * the tiled portion of the root pixmap that is supposed to be covered by |
1225 | * our window. |
1202 | * our window. |
1226 | */ |
1203 | */ |
1227 | unsigned long |
1204 | unsigned long |
1228 | bgPixmap_t::make_transparency_pixmap () |
1205 | rxvt_term::make_transparency_pixmap () |
1229 | { |
1206 | { |
1230 | unsigned long result = 0; |
1207 | unsigned long result = 0; |
1231 | |
|
|
1232 | if (target == NULL) |
|
|
1233 | return 0; |
|
|
1234 | |
1208 | |
1235 | /* root dimensions may change from call to call - but Display structure should |
1209 | /* root dimensions may change from call to call - but Display structure should |
1236 | * be always up-to-date, so let's use it : |
1210 | * be always up-to-date, so let's use it : |
1237 | */ |
1211 | */ |
1238 | int screen = target->display->screen; |
1212 | int screen = display->screen; |
1239 | Display *dpy = target->dpy; |
|
|
1240 | int root_depth = DefaultDepth (dpy, screen); |
1213 | int root_depth = DefaultDepth (dpy, screen); |
1241 | int root_width = DisplayWidth (dpy, screen); |
1214 | int root_width = DisplayWidth (dpy, screen); |
1242 | int root_height = DisplayHeight (dpy, screen); |
1215 | int root_height = DisplayHeight (dpy, screen); |
1243 | unsigned int root_pmap_width, root_pmap_height; |
1216 | unsigned int root_pmap_width, root_pmap_height; |
1244 | int window_width = target->szHint.width; |
1217 | int window_width = szHint.width; |
1245 | int window_height = target->szHint.height; |
1218 | int window_height = szHint.height; |
1246 | int sx, sy; |
1219 | int sx, sy; |
1247 | XGCValues gcv; |
1220 | XGCValues gcv; |
1248 | GC gc; |
1221 | GC gc; |
1249 | |
1222 | |
1250 | sx = target_x; |
1223 | sx = target_x; |
… | |
… | |
1260 | { |
1233 | { |
1261 | Window wdummy; |
1234 | Window wdummy; |
1262 | int idummy; |
1235 | int idummy; |
1263 | unsigned int udummy; |
1236 | unsigned int udummy; |
1264 | |
1237 | |
1265 | target->allowedxerror = -1; |
1238 | allowedxerror = -1; |
1266 | |
1239 | |
1267 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
1240 | if (!XGetGeometry (dpy, root_pixmap, &wdummy, &idummy, &idummy, &root_pmap_width, &root_pmap_height, &udummy, &udummy)) |
1268 | root_pixmap = None; |
1241 | root_pixmap = None; |
1269 | |
1242 | |
1270 | target->allowedxerror = 0; |
1243 | allowedxerror = 0; |
1271 | } |
1244 | } |
1272 | |
1245 | |
1273 | Pixmap recoded_root_pmap = root_pixmap; |
1246 | Pixmap recoded_root_pmap = root_pixmap; |
1274 | |
1247 | |
1275 | if (root_pixmap != None && root_depth != target->depth) |
1248 | if (root_pixmap != None && root_depth != depth) |
1276 | { |
1249 | { |
1277 | #if XRENDER |
1250 | #if XRENDER |
1278 | if (flags & HAS_RENDER) |
1251 | if (bg_flags & BG_HAS_RENDER) |
1279 | { |
1252 | { |
|
|
1253 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
|
|
1254 | |
1280 | XRenderPictureAttributes pa; |
1255 | XRenderPictureAttributes pa; |
1281 | |
1256 | |
1282 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1257 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1283 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1258 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1284 | |
1259 | |
1285 | recoded_root_pmap = XCreatePixmap (dpy, target->vt, root_pmap_width, root_pmap_height, target->depth); |
|
|
1286 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
1260 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1287 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1261 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1288 | |
1262 | |
1289 | if (src && dst) |
|
|
1290 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1263 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1291 | else |
|
|
1292 | { |
|
|
1293 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1294 | root_pixmap = None; |
|
|
1295 | } |
|
|
1296 | |
1264 | |
1297 | XRenderFreePicture (dpy, src); |
1265 | XRenderFreePicture (dpy, src); |
1298 | XRenderFreePicture (dpy, dst); |
1266 | XRenderFreePicture (dpy, dst); |
1299 | } |
1267 | } |
1300 | else |
1268 | else |
1301 | #endif |
1269 | #endif |
1302 | root_pixmap = None; |
1270 | recoded_root_pmap = None; |
1303 | } |
1271 | } |
1304 | |
1272 | |
1305 | if (root_pixmap == None) |
1273 | if (recoded_root_pmap == None) |
1306 | return 0; |
1274 | return 0; |
1307 | |
1275 | |
1308 | if (pixmap == None |
1276 | if (bg_pixmap == None |
1309 | || pmap_width != window_width |
1277 | || bg_pmap_width != window_width |
1310 | || pmap_height != window_height) |
1278 | || bg_pmap_height != window_height) |
1311 | { |
1279 | { |
1312 | if (pixmap) |
1280 | if (bg_pixmap) |
1313 | XFreePixmap (target->dpy, pixmap); |
1281 | XFreePixmap (dpy, bg_pixmap); |
1314 | pixmap = XCreatePixmap (target->dpy, target->vt, window_width, window_height, target->depth); |
1282 | bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); |
1315 | pmap_width = window_width; |
1283 | bg_pmap_width = window_width; |
1316 | pmap_height = window_height; |
1284 | bg_pmap_height = window_height; |
1317 | } |
1285 | } |
1318 | |
|
|
1319 | if (pixmap == None) |
|
|
1320 | return 0; |
|
|
1321 | |
1286 | |
1322 | /* straightforward pixmap copy */ |
1287 | /* straightforward pixmap copy */ |
1323 | while (sx < 0) sx += (int)root_width; |
1288 | while (sx < 0) sx += root_width; |
1324 | while (sy < 0) sy += (int)root_height; |
1289 | while (sy < 0) sy += root_height; |
1325 | |
1290 | |
1326 | gcv.tile = recoded_root_pmap; |
1291 | gcv.tile = recoded_root_pmap; |
1327 | gcv.fill_style = FillTiled; |
1292 | gcv.fill_style = FillTiled; |
1328 | gcv.ts_x_origin = -sx; |
1293 | gcv.ts_x_origin = -sx; |
1329 | gcv.ts_y_origin = -sy; |
1294 | gcv.ts_y_origin = -sy; |
1330 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1295 | gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1331 | |
1296 | |
1332 | if (gc) |
1297 | if (gc) |
1333 | { |
1298 | { |
1334 | XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height); |
1299 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1335 | result |= transpPmapTiled; |
1300 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1336 | XFreeGC (dpy, gc); |
1301 | XFreeGC (dpy, gc); |
1337 | |
1302 | |
1338 | if (!(flags & CLIENT_RENDER)) |
1303 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1339 | { |
1304 | { |
1340 | if ((flags & blurNeeded) |
1305 | if ((bg_flags & BG_NEEDS_BLUR) |
1341 | && (flags & HAS_RENDER_CONV)) |
1306 | && (bg_flags & BG_HAS_RENDER_CONV)) |
1342 | { |
1307 | { |
1343 | if (blur_pixmap (pixmap, target->visual, window_width, window_height)) |
1308 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) |
1344 | result |= transpPmapBlurred; |
1309 | result &= ~BG_NEEDS_BLUR; |
1345 | } |
|
|
1346 | if ((flags & tintNeeded) |
|
|
1347 | && (flags & (tintWholesome | HAS_RENDER))) |
|
|
1348 | { |
1310 | } |
|
|
1311 | if ((bg_flags & BG_NEEDS_TINT) |
|
|
1312 | && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) |
|
|
1313 | { |
1349 | if (tint_pixmap (pixmap, target->visual, window_width, window_height)) |
1314 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1350 | result |= transpPmapTinted; |
1315 | result &= ~BG_NEEDS_TINT; |
1351 | } |
1316 | } |
1352 | } /* server side rendering completed */ |
1317 | } /* server side rendering completed */ |
1353 | } |
1318 | } |
1354 | |
1319 | |
1355 | if (recoded_root_pmap != root_pixmap) |
1320 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1357 | |
1322 | |
1358 | return result; |
1323 | return result; |
1359 | } |
1324 | } |
1360 | |
1325 | |
1361 | void |
1326 | void |
1362 | bgPixmap_t::set_root_pixmap () |
1327 | rxvt_term::bg_set_root_pixmap () |
1363 | { |
1328 | { |
1364 | Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]); |
1329 | Pixmap new_root_pixmap = get_pixmap_property (xa[XA_XROOTPMAP_ID]); |
1365 | if (new_root_pixmap == None) |
1330 | if (new_root_pixmap == None) |
1366 | new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]); |
1331 | new_root_pixmap = get_pixmap_property (xa[XA_ESETROOT_PMAP_ID]); |
1367 | |
1332 | |
1368 | root_pixmap = new_root_pixmap; |
1333 | root_pixmap = new_root_pixmap; |
1369 | } |
1334 | } |
1370 | # endif /* ENABLE_TRANSPARENCY */ |
1335 | # endif /* ENABLE_TRANSPARENCY */ |
1371 | |
1336 | |
1372 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1337 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1373 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
1338 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
1374 | # endif |
1339 | # endif |
1375 | |
1340 | |
1376 | bool |
1341 | bool |
1377 | bgPixmap_t::render () |
1342 | rxvt_term::bg_render () |
1378 | { |
1343 | { |
1379 | unsigned long background_flags = 0; |
1344 | unsigned long tr_flags = 0; |
1380 | |
1345 | |
1381 | if (target == NULL) |
|
|
1382 | return false; |
|
|
1383 | |
|
|
1384 | invalidate (); |
1346 | bg_invalidate (); |
1385 | # ifdef ENABLE_TRANSPARENCY |
1347 | # ifdef ENABLE_TRANSPARENCY |
1386 | if (flags & isTransparent) |
1348 | if (bg_flags & BG_IS_TRANSPARENT) |
1387 | { |
1349 | { |
1388 | /* we need to re-generate transparency pixmap in that case ! */ |
1350 | /* we need to re-generate transparency pixmap in that case ! */ |
1389 | background_flags = make_transparency_pixmap (); |
1351 | tr_flags = make_transparency_pixmap (); |
1390 | if (background_flags == 0) |
1352 | if (tr_flags == 0) |
1391 | return false; |
1353 | return false; |
1392 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1354 | else if (!(tr_flags & BG_EFFECTS_FLAGS)) |
1393 | flags |= isValid; |
1355 | bg_flags |= BG_IS_VALID; |
1394 | } |
1356 | } |
1395 | # endif |
1357 | # endif |
1396 | |
1358 | |
1397 | # ifdef BG_IMAGE_FROM_FILE |
1359 | # ifdef BG_IMAGE_FROM_FILE |
1398 | if (have_image |
1360 | if ((bg_flags & BG_IS_FROM_FILE) |
1399 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1361 | || (tr_flags & BG_EFFECTS_FLAGS)) |
1400 | { |
1362 | { |
1401 | if (render_image (background_flags)) |
1363 | if (render_image (tr_flags)) |
1402 | flags |= isValid; |
1364 | bg_flags |= BG_IS_VALID; |
1403 | } |
1365 | } |
1404 | # endif |
1366 | # endif |
1405 | |
1367 | |
1406 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1368 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1407 | XImage *result = NULL; |
1369 | XImage *result = NULL; |
1408 | |
1370 | |
1409 | if (background_flags && !(flags & isValid)) |
1371 | if (tr_flags && !(bg_flags & BG_IS_VALID)) |
1410 | { |
1372 | { |
1411 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1373 | result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1412 | } |
1374 | } |
1413 | |
1375 | |
1414 | if (result) |
1376 | if (result) |
1415 | { |
1377 | { |
1416 | /* our own client-side tinting */ |
1378 | /* our own client-side tinting */ |
1417 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1379 | if (tr_flags & BG_NEEDS_TINT) |
1418 | { |
1380 | { |
1419 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1381 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1420 | if (flags & tintSet) |
1382 | if (bg_flags & BG_TINT_SET) |
1421 | tint.get (c); |
1383 | tint.get (c); |
1422 | shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1384 | shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); |
1423 | } |
1385 | } |
1424 | |
1386 | |
1425 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1387 | GC gc = XCreateGC (dpy, vt, 0UL, NULL); |
1426 | |
1388 | |
1427 | if (gc) |
1389 | if (gc) |
1428 | { |
1390 | { |
1429 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1391 | XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1430 | |
1392 | |
1431 | XFreeGC (target->dpy, gc); |
1393 | XFreeGC (dpy, gc); |
1432 | flags |= isValid; |
1394 | bg_flags |= BG_IS_VALID; |
1433 | } |
1395 | } |
1434 | |
1396 | |
1435 | XDestroyImage (result); |
1397 | XDestroyImage (result); |
1436 | } |
1398 | } |
1437 | # endif |
1399 | # endif |
1438 | |
1400 | |
1439 | if (!(flags & isValid)) |
1401 | if (!(bg_flags & BG_IS_VALID)) |
1440 | { |
1402 | { |
1441 | if (pixmap != None) |
1403 | if (bg_pixmap != None) |
1442 | { |
1404 | { |
1443 | XFreePixmap (target->dpy, pixmap); |
1405 | XFreePixmap (dpy, bg_pixmap); |
1444 | pixmap = None; |
1406 | bg_pixmap = None; |
1445 | } |
1407 | } |
1446 | } |
1408 | } |
1447 | |
1409 | |
1448 | target->scr_recolour (false); |
1410 | scr_recolour (false); |
1449 | flags |= hasChanged; |
1411 | bg_flags |= BG_NEEDS_REFRESH; |
1450 | |
1412 | |
1451 | valid_since = ev::now (); |
1413 | bg_valid_since = ev::now (); |
1452 | |
1414 | |
1453 | return true; |
1415 | return true; |
1454 | } |
1416 | } |
1455 | |
1417 | |
1456 | void |
1418 | void |
1457 | bgPixmap_t::set_target (rxvt_term *new_target) |
1419 | rxvt_term::bg_init () |
1458 | { |
1420 | { |
1459 | target = new_target; |
1421 | #ifdef ENABLE_TRANSPARENCY |
|
|
1422 | shade = 100; |
|
|
1423 | #endif |
1460 | |
1424 | |
1461 | flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
1425 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
1462 | #if XRENDER |
1426 | #if XRENDER |
1463 | int major, minor; |
1427 | int major, minor; |
1464 | if (XRenderQueryVersion (target->dpy, &major, &minor)) |
1428 | if (XRenderQueryVersion (dpy, &major, &minor)) |
1465 | flags |= HAS_RENDER; |
1429 | bg_flags |= BG_HAS_RENDER; |
1466 | XFilters *filters = XRenderQueryFilters (target->dpy, target->vt); |
1430 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
1467 | if (filters) |
1431 | if (filters) |
1468 | { |
1432 | { |
1469 | for (int i = 0; i < filters->nfilter; i++) |
1433 | for (int i = 0; i < filters->nfilter; i++) |
1470 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1434 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1471 | flags |= HAS_RENDER_CONV; |
1435 | bg_flags |= BG_HAS_RENDER_CONV; |
1472 | |
1436 | |
1473 | XFree (filters); |
1437 | XFree (filters); |
1474 | } |
1438 | } |
1475 | #endif |
1439 | #endif |
1476 | } |
1440 | } |
… | |
… | |
1487 | uint32_t mask_r, mask_g, mask_b; |
1451 | uint32_t mask_r, mask_g, mask_b; |
1488 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1452 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1489 | rgba low; |
1453 | rgba low; |
1490 | rgba high; |
1454 | rgba high; |
1491 | int i; |
1455 | int i; |
1492 | int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
1456 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1493 | |
1457 | |
1494 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1458 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1495 | |
1459 | |
1496 | /* for convenience */ |
1460 | /* for convenience */ |
1497 | mask_r = visual->red_mask; |
1461 | mask_r = visual->red_mask; |