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 | void |
54 | void |
65 | rxvt_term::bg_destroy () |
55 | rxvt_term::bg_destroy () |
66 | { |
56 | { |
67 | #ifdef HAVE_AFTERIMAGE |
57 | #ifdef HAVE_AFTERIMAGE |
68 | if (original_asim) |
58 | if (original_asim) |
69 | 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); |
70 | #endif |
64 | #endif |
71 | |
65 | |
72 | #ifdef HAVE_PIXBUF |
66 | #ifdef HAVE_PIXBUF |
73 | if (pixbuf) |
67 | if (pixbuf) |
74 | g_object_unref (pixbuf); |
68 | g_object_unref (pixbuf); |
… | |
… | |
94 | |
88 | |
95 | bool |
89 | bool |
96 | rxvt_term::bg_window_size_sensitive () |
90 | rxvt_term::bg_window_size_sensitive () |
97 | { |
91 | { |
98 | # ifdef ENABLE_TRANSPARENCY |
92 | # ifdef ENABLE_TRANSPARENCY |
99 | if (bg_flags & isTransparent) |
93 | if (bg_flags & BG_IS_TRANSPARENT) |
100 | return true; |
94 | return true; |
101 | # endif |
95 | # endif |
102 | |
96 | |
103 | # ifdef BG_IMAGE_FROM_FILE |
97 | # ifdef BG_IMAGE_FROM_FILE |
104 | if (have_image) |
98 | if (bg_flags & BG_IS_FROM_FILE) |
105 | { |
99 | { |
106 | if (bg_flags & sizeSensitive) |
100 | if (bg_flags & BG_IS_SIZE_SENSITIVE) |
107 | return true; |
101 | return true; |
108 | } |
102 | } |
109 | # endif |
103 | # endif |
110 | |
104 | |
111 | return false; |
105 | return false; |
… | |
… | |
113 | |
107 | |
114 | bool |
108 | bool |
115 | rxvt_term::bg_window_position_sensitive () |
109 | rxvt_term::bg_window_position_sensitive () |
116 | { |
110 | { |
117 | # ifdef ENABLE_TRANSPARENCY |
111 | # ifdef ENABLE_TRANSPARENCY |
118 | if (bg_flags & isTransparent) |
112 | if (bg_flags & BG_IS_TRANSPARENT) |
119 | return true; |
113 | return true; |
120 | # endif |
114 | # endif |
121 | |
115 | |
122 | # ifdef BG_IMAGE_FROM_FILE |
116 | # ifdef BG_IMAGE_FROM_FILE |
123 | if (have_image) |
117 | if (bg_flags & BG_IS_FROM_FILE) |
124 | { |
118 | { |
125 | if (bg_flags & rootAlign) |
119 | if (bg_flags & BG_ROOT_ALIGN) |
126 | return true; |
120 | return true; |
127 | } |
121 | } |
128 | # endif |
122 | # endif |
129 | |
123 | |
130 | return false; |
124 | return false; |
… | |
… | |
203 | { |
197 | { |
204 | bool changed = false; |
198 | bool changed = false; |
205 | int geom_flags = 0; |
199 | int geom_flags = 0; |
206 | int x = 0, y = 0; |
200 | int x = 0, y = 0; |
207 | unsigned int w = 0, h = 0; |
201 | unsigned int w = 0, h = 0; |
208 | unsigned int n; |
|
|
209 | unsigned long new_flags = (bg_flags & (~geometryFlags)); |
202 | unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); |
210 | const char *ops; |
|
|
211 | |
203 | |
212 | if (geom == NULL) |
204 | if (geom == NULL) |
213 | return false; |
205 | return false; |
214 | |
206 | |
215 | char str[256]; |
207 | if (geom[0]) |
216 | |
|
|
217 | ops = strchr (geom, ':'); |
|
|
218 | if (ops == NULL) |
|
|
219 | n = strlen (geom); |
|
|
220 | else |
|
|
221 | n = ops - geom; |
|
|
222 | |
|
|
223 | if (n >= sizeof (str)) |
|
|
224 | return false; |
|
|
225 | |
|
|
226 | memcpy (str, geom, n); |
|
|
227 | str[n] = '\0'; |
|
|
228 | rxvt_strtrim (str); |
|
|
229 | |
|
|
230 | if (str[0]) |
|
|
231 | { |
208 | { |
232 | /* we have geometry string - let's handle it prior to applying ops */ |
209 | char **arr = rxvt_strsplit (':', geom); |
|
|
210 | |
|
|
211 | for (int i = 0; arr[i]; i++) |
|
|
212 | { |
|
|
213 | if (!strcasecmp (arr[i], "style=tiled")) |
|
|
214 | { |
|
|
215 | new_flags = BG_TILE; |
|
|
216 | w = h = noScale; |
|
|
217 | x = y = 0; |
|
|
218 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
219 | } |
|
|
220 | else if (!strcasecmp (arr[i], "style=aspect-stretched")) |
|
|
221 | { |
|
|
222 | new_flags = BG_PROP_SCALE; |
|
|
223 | w = h = windowScale; |
|
|
224 | x = y = centerAlign; |
|
|
225 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
226 | } |
|
|
227 | else if (!strcasecmp (arr[i], "style=stretched")) |
|
|
228 | { |
|
|
229 | new_flags = 0; |
|
|
230 | w = h = windowScale; |
|
|
231 | geom_flags = WidthValue|HeightValue; |
|
|
232 | } |
|
|
233 | else if (!strcasecmp (arr[i], "style=centered")) |
|
|
234 | { |
|
|
235 | new_flags = 0; |
|
|
236 | w = h = noScale; |
|
|
237 | x = y = centerAlign; |
|
|
238 | geom_flags = WidthValue|HeightValue|XValue|YValue; |
|
|
239 | } |
|
|
240 | else if (!strcasecmp (arr[i], "style=root-tiled")) |
|
|
241 | { |
|
|
242 | new_flags = BG_TILE|BG_ROOT_ALIGN; |
|
|
243 | w = h = noScale; |
|
|
244 | geom_flags = WidthValue|HeightValue; |
|
|
245 | } |
|
|
246 | else if (!strcasecmp (arr[i], "op=tile")) |
|
|
247 | new_flags |= BG_TILE; |
|
|
248 | else if (!strcasecmp (arr[i], "op=pscale")) |
|
|
249 | new_flags |= BG_PROP_SCALE; |
|
|
250 | else if (!strcasecmp (arr[i], "op=root")) |
|
|
251 | new_flags |= BG_ROOT_ALIGN; |
|
|
252 | |
|
|
253 | // deprecated |
|
|
254 | else if (!strcasecmp (arr[i], "tile")) |
|
|
255 | { |
|
|
256 | new_flags |= BG_TILE; |
|
|
257 | w = h = noScale; |
|
|
258 | geom_flags |= WidthValue|HeightValue; |
|
|
259 | } |
|
|
260 | else if (!strcasecmp (arr[i], "propscale")) |
|
|
261 | { |
|
|
262 | new_flags |= BG_PROP_SCALE; |
|
|
263 | } |
|
|
264 | else if (!strcasecmp (arr[i], "hscale")) |
|
|
265 | { |
|
|
266 | new_flags |= BG_TILE; |
|
|
267 | w = windowScale; |
|
|
268 | h = noScale; |
|
|
269 | geom_flags |= WidthValue|HeightValue; |
|
|
270 | } |
|
|
271 | else if (!strcasecmp (arr[i], "vscale")) |
|
|
272 | { |
|
|
273 | new_flags |= BG_TILE; |
|
|
274 | h = windowScale; |
|
|
275 | w = noScale; |
|
|
276 | geom_flags |= WidthValue|HeightValue; |
|
|
277 | } |
|
|
278 | else if (!strcasecmp (arr[i], "scale")) |
|
|
279 | { |
|
|
280 | w = h = windowScale; |
|
|
281 | geom_flags |= WidthValue|HeightValue; |
|
|
282 | } |
|
|
283 | else if (!strcasecmp (arr[i], "auto")) |
|
|
284 | { |
|
|
285 | w = h = windowScale; |
|
|
286 | x = y = centerAlign; |
|
|
287 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
288 | } |
|
|
289 | else if (!strcasecmp (arr[i], "root")) |
|
|
290 | { |
|
|
291 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
|
|
292 | w = h = noScale; |
|
|
293 | geom_flags |= WidthValue|HeightValue; |
|
|
294 | } |
|
|
295 | |
|
|
296 | else |
233 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
297 | geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); |
234 | } /* done parsing geometry string */ |
298 | } /* done parsing ops */ |
|
|
299 | |
|
|
300 | rxvt_free_strsplit (arr); |
|
|
301 | } |
235 | |
302 | |
236 | if (!update) |
303 | if (!update) |
237 | { |
304 | { |
238 | if (!(geom_flags & XValue)) |
305 | if (!(geom_flags & XValue)) |
239 | x = y = defaultAlign; |
306 | x = y = defaultAlign; |
… | |
… | |
248 | w = h; |
315 | w = h; |
249 | |
316 | |
250 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
317 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
251 | } |
318 | } |
252 | |
319 | |
253 | if (ops) |
|
|
254 | { |
|
|
255 | char **arr = rxvt_strsplit (':', ops + 1); |
|
|
256 | |
|
|
257 | for (int i = 0; arr[i]; i++) |
|
|
258 | { |
|
|
259 | if (!strcasecmp (arr[i], "tile")) |
|
|
260 | { |
|
|
261 | w = h = noScale; |
|
|
262 | geom_flags |= WidthValue|HeightValue; |
|
|
263 | } |
|
|
264 | else if (!strcasecmp (arr[i], "propscale")) |
|
|
265 | { |
|
|
266 | new_flags |= propScale; |
|
|
267 | } |
|
|
268 | else if (!strcasecmp (arr[i], "hscale")) |
|
|
269 | { |
|
|
270 | if (w == 0) w = windowScale; |
|
|
271 | |
|
|
272 | h = noScale; |
|
|
273 | geom_flags |= WidthValue|HeightValue; |
|
|
274 | } |
|
|
275 | else if (!strcasecmp (arr[i], "vscale")) |
|
|
276 | { |
|
|
277 | if (h == 0) h = windowScale; |
|
|
278 | |
|
|
279 | w = noScale; |
|
|
280 | geom_flags |= WidthValue|HeightValue; |
|
|
281 | } |
|
|
282 | else if (!strcasecmp (arr[i], "scale")) |
|
|
283 | { |
|
|
284 | if (h == 0) h = windowScale; |
|
|
285 | if (w == 0) w = windowScale; |
|
|
286 | |
|
|
287 | geom_flags |= WidthValue|HeightValue; |
|
|
288 | } |
|
|
289 | else if (!strcasecmp (arr[i], "auto")) |
|
|
290 | { |
|
|
291 | w = h = windowScale; |
|
|
292 | x = y = centerAlign; |
|
|
293 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
294 | } |
|
|
295 | else if (!strcasecmp (arr[i], "root")) |
|
|
296 | { |
|
|
297 | new_flags |= rootAlign; |
|
|
298 | w = h = noScale; |
|
|
299 | geom_flags |= WidthValue|HeightValue; |
|
|
300 | } |
|
|
301 | } /* done parsing ops */ |
|
|
302 | |
|
|
303 | rxvt_free_strsplit (arr); |
|
|
304 | } |
|
|
305 | |
|
|
306 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
320 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
307 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
321 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
308 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
322 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
309 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
323 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
310 | |
324 | |
… | |
… | |
321 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
335 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
322 | { |
336 | { |
323 | int target_width = szHint.width; |
337 | int target_width = szHint.width; |
324 | int target_height = szHint.height; |
338 | int target_height = szHint.height; |
325 | |
339 | |
326 | if (bg_flags & propScale) |
340 | w = h_scale * target_width / 100; |
|
|
341 | h = v_scale * target_height / 100; |
|
|
342 | |
|
|
343 | if (bg_flags & BG_PROP_SCALE) |
327 | { |
344 | { |
328 | float scale = (float)target_width / image_width; |
345 | float scale = (float)w / image_width; |
329 | min_it (scale, (float)target_height / image_height); |
346 | min_it (scale, (float)h / image_height); |
330 | w = image_width * scale + 0.5; |
347 | w = image_width * scale + 0.5; |
331 | h = image_height * scale + 0.5; |
348 | h = image_height * scale + 0.5; |
332 | } |
349 | } |
333 | else |
|
|
334 | { |
|
|
335 | w = h_scale * target_width / 100; |
|
|
336 | h = v_scale * target_height / 100; |
|
|
337 | } |
|
|
338 | |
350 | |
339 | if (!w) w = image_width; |
351 | if (!w) w = image_width; |
340 | if (!h) h = image_height; |
352 | if (!h) h = image_height; |
341 | |
353 | |
342 | if (bg_flags & rootAlign) |
354 | if (bg_flags & BG_ROOT_ALIGN) |
343 | { |
355 | { |
344 | x = -target_x; |
356 | x = -target_x; |
345 | y = -target_y; |
357 | y = -target_y; |
346 | } |
358 | } |
347 | else |
359 | else |
348 | { |
360 | { |
349 | x = make_align_position (h_align, target_width, w); |
361 | x = make_align_position (h_align, target_width, w); |
350 | y = make_align_position (v_align, target_height, h); |
362 | y = make_align_position (v_align, target_height, h); |
351 | } |
363 | } |
352 | |
364 | |
353 | bg_flags &= ~sizeSensitive; |
365 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
354 | if ((bg_flags & propScale) || h_scale || v_scale |
366 | if (!(bg_flags & BG_TILE) |
|
|
367 | || h_scale || v_scale |
355 | || (!(bg_flags & rootAlign) && (h_align || v_align)) |
368 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
356 | || w > target_width || h > target_height) |
369 | || w > target_width || h > target_height) |
357 | bg_flags |= sizeSensitive; |
370 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
358 | } |
371 | } |
359 | |
372 | |
360 | # ifdef HAVE_AFTERIMAGE |
373 | # ifdef HAVE_AFTERIMAGE |
361 | bool |
374 | bool |
362 | rxvt_term::render_image (unsigned long tr_flags) |
375 | rxvt_term::render_image (unsigned long tr_flags) |
… | |
… | |
368 | |
381 | |
369 | # ifdef ENABLE_TRANSPARENCY |
382 | # ifdef ENABLE_TRANSPARENCY |
370 | if (tr_flags) |
383 | if (tr_flags) |
371 | background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100); |
384 | background = pixmap2ximage (asv, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, 100); |
372 | |
385 | |
373 | if (tr_flags & tintNeeded) |
386 | if (tr_flags & BG_NEEDS_TINT) |
374 | { |
387 | { |
375 | ShadingInfo as_shade; |
388 | ShadingInfo as_shade; |
376 | as_shade.shading = shade; |
389 | as_shade.shading = shade; |
377 | |
390 | |
378 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
391 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
379 | if (bg_flags & tintSet) |
392 | if (bg_flags & BG_TINT_SET) |
380 | tint.get (c); |
393 | tint.get (c); |
381 | as_shade.tintColor.red = c.r; |
394 | as_shade.tintColor.red = c.r; |
382 | as_shade.tintColor.green = c.g; |
395 | as_shade.tintColor.green = c.g; |
383 | as_shade.tintColor.blue = c.b; |
396 | as_shade.tintColor.blue = c.b; |
384 | |
397 | |
385 | background_tint = shading2tint32 (&as_shade); |
398 | background_tint = shading2tint32 (&as_shade); |
386 | } |
399 | } |
387 | |
400 | |
388 | if ((tr_flags & blurNeeded) && background != NULL) |
401 | if ((tr_flags & BG_NEEDS_BLUR) && background != NULL) |
389 | { |
402 | { |
390 | ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
403 | ASImage *tmp = blur_asimage_gauss (asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
391 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
404 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
392 | 100, ASIMAGE_QUALITY_DEFAULT); |
405 | 100, ASIMAGE_QUALITY_DEFAULT); |
393 | if (tmp) |
406 | if (tmp) |
… | |
… | |
412 | |
425 | |
413 | if (original_asim) |
426 | if (original_asim) |
414 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
427 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
415 | |
428 | |
416 | if (!original_asim |
429 | if (!original_asim |
417 | || (!(bg_flags & rootAlign) |
430 | || (!(bg_flags & BG_ROOT_ALIGN) |
418 | && (x >= target_width |
431 | && (x >= target_width |
419 | || y >= target_height |
432 | || y >= target_height |
420 | || (x + w <= 0) |
433 | || (x + w <= 0) |
421 | || (y + h <= 0)))) |
434 | || (y + h <= 0)))) |
422 | { |
435 | { |
… | |
… | |
451 | 100, ASIMAGE_QUALITY_DEFAULT); |
464 | 100, ASIMAGE_QUALITY_DEFAULT); |
452 | } |
465 | } |
453 | |
466 | |
454 | if (background == NULL) |
467 | if (background == NULL) |
455 | { |
468 | { |
456 | if (h_scale == 0 || v_scale == 0) |
469 | if (bg_flags & BG_TILE) |
457 | { |
470 | { |
458 | /* if tiling - pixmap has to be sized exactly as the image, |
471 | /* if tiling - pixmap has to be sized exactly as the image, |
459 | but there is no need to make it bigger than the window! */ |
472 | but there is no need to make it bigger than the window! */ |
460 | new_pmap_width = min (result->width, target_width); |
473 | new_pmap_width = min (result->width, target_width); |
461 | new_pmap_height = min (result->height, target_height); |
474 | new_pmap_height = min (result->height, target_height); |
… | |
… | |
486 | layers[0].clip_width = target_width; |
499 | layers[0].clip_width = target_width; |
487 | layers[0].clip_height = target_height; |
500 | layers[0].clip_height = target_height; |
488 | layers[0].tint = background_tint; |
501 | layers[0].tint = background_tint; |
489 | layers[1].im = result; |
502 | layers[1].im = result; |
490 | |
503 | |
491 | if (h_scale == 0 || v_scale == 0) |
504 | if (bg_flags & BG_TILE) |
492 | { |
505 | { |
493 | /* tile horizontally */ |
506 | /* tile horizontally */ |
494 | while (x > 0) x -= (int)result->width; |
507 | while (x > 0) x -= (int)result->width; |
495 | layers[1].dst_x = x; |
508 | layers[1].dst_x = x; |
496 | layers[1].clip_width = result->width+target_width; |
509 | layers[1].clip_width = result->width+target_width; |
… | |
… | |
500 | /* clip horizontally */ |
513 | /* clip horizontally */ |
501 | layers[1].dst_x = x; |
514 | layers[1].dst_x = x; |
502 | layers[1].clip_width = result->width; |
515 | layers[1].clip_width = result->width; |
503 | } |
516 | } |
504 | |
517 | |
505 | if (h_scale == 0 || v_scale == 0) |
518 | if (bg_flags & BG_TILE) |
506 | { |
519 | { |
507 | while (y > 0) y -= (int)result->height; |
520 | while (y > 0) y -= (int)result->height; |
508 | layers[1].dst_y = y; |
521 | layers[1].dst_y = y; |
509 | layers[1].clip_height = result->height + target_height; |
522 | layers[1].clip_height = result->height + target_height; |
510 | } |
523 | } |
… | |
… | |
560 | |
573 | |
561 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
574 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
562 | int dst_width = result->width, dst_height = result->height; |
575 | int dst_width = result->width, dst_height = result->height; |
563 | if (background == NULL) |
576 | if (background == NULL) |
564 | { |
577 | { |
565 | if (!(h_scale == 0 || v_scale == 0)) |
578 | if (!(bg_flags & BG_TILE)) |
566 | { |
579 | { |
567 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
580 | src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
568 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
581 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
569 | } |
582 | } |
570 | |
583 | |
… | |
… | |
616 | else if (depth == 15 || depth == 16) |
629 | else if (depth == 15 || depth == 16) |
617 | bytes_per_pixel = 2; |
630 | bytes_per_pixel = 2; |
618 | else |
631 | else |
619 | return false; |
632 | return false; |
620 | |
633 | |
621 | width_r = rxvt_popcount (visual->red_mask); |
634 | width_r = ecb_popcount32 (visual->red_mask); |
622 | width_g = rxvt_popcount (visual->green_mask); |
635 | width_g = ecb_popcount32 (visual->green_mask); |
623 | width_b = rxvt_popcount (visual->blue_mask); |
636 | width_b = ecb_popcount32 (visual->blue_mask); |
624 | |
637 | |
625 | if (width_r > 8 || width_g > 8 || width_b > 8) |
638 | if (width_r > 8 || width_g > 8 || width_b > 8) |
626 | return false; |
639 | return false; |
627 | |
640 | |
628 | sh_r = rxvt_ctz (visual->red_mask); |
641 | sh_r = ecb_ctz32 (visual->red_mask); |
629 | sh_g = rxvt_ctz (visual->green_mask); |
642 | sh_g = ecb_ctz32 (visual->green_mask); |
630 | sh_b = rxvt_ctz (visual->blue_mask); |
643 | sh_b = ecb_ctz32 (visual->blue_mask); |
631 | |
644 | |
632 | if (width > INT_MAX / height / bytes_per_pixel) |
645 | if (width > INT_MAX / height / bytes_per_pixel) |
633 | return false; |
646 | return false; |
634 | |
647 | |
635 | data = (char *)malloc (width * height * bytes_per_pixel); |
648 | data = (char *)malloc (width * height * bytes_per_pixel); |
… | |
… | |
642 | { |
655 | { |
643 | free (data); |
656 | free (data); |
644 | return false; |
657 | return false; |
645 | } |
658 | } |
646 | |
659 | |
647 | ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
660 | ximage->byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
648 | |
661 | |
649 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
662 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
650 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
663 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
651 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
664 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
652 | line = data; |
665 | line = data; |
… | |
… | |
682 | { |
695 | { |
683 | if (!pixbuf) |
696 | if (!pixbuf) |
684 | return false; |
697 | return false; |
685 | |
698 | |
686 | if (tr_flags |
699 | if (tr_flags |
687 | && !(bg_flags & HAS_RENDER)) |
700 | && !(bg_flags & BG_HAS_RENDER)) |
688 | return false; |
701 | return false; |
689 | |
702 | |
690 | GdkPixbuf *result; |
703 | GdkPixbuf *result; |
691 | |
704 | |
692 | int image_width = gdk_pixbuf_get_width (pixbuf); |
705 | int image_width = gdk_pixbuf_get_width (pixbuf); |
… | |
… | |
702 | int w = 0; |
715 | int w = 0; |
703 | int h = 0; |
716 | int h = 0; |
704 | |
717 | |
705 | get_image_geometry (image_width, image_height, w, h, x, y); |
718 | get_image_geometry (image_width, image_height, w, h, x, y); |
706 | |
719 | |
707 | if (!(bg_flags & rootAlign) |
720 | if (!(bg_flags & BG_ROOT_ALIGN) |
708 | && (x >= target_width |
721 | && (x >= target_width |
709 | || y >= target_height |
722 | || y >= target_height |
710 | || (x + w <= 0) |
723 | || (x + w <= 0) |
711 | || (y + h <= 0))) |
724 | || (y + h <= 0))) |
712 | return false; |
725 | return false; |
… | |
… | |
719 | result = gdk_pixbuf_scale_simple (pixbuf, |
732 | result = gdk_pixbuf_scale_simple (pixbuf, |
720 | w, h, |
733 | w, h, |
721 | GDK_INTERP_BILINEAR); |
734 | GDK_INTERP_BILINEAR); |
722 | } |
735 | } |
723 | |
736 | |
|
|
737 | if (!result) |
|
|
738 | return false; |
|
|
739 | |
724 | bool ret = false; |
740 | bool ret = false; |
725 | |
741 | |
726 | if (result) |
|
|
727 | { |
|
|
728 | XGCValues gcv; |
742 | XGCValues gcv; |
729 | GC gc; |
743 | GC gc; |
730 | Pixmap root_pmap; |
744 | Pixmap root_pmap; |
731 | |
745 | |
732 | image_width = gdk_pixbuf_get_width (result); |
746 | image_width = gdk_pixbuf_get_width (result); |
733 | image_height = gdk_pixbuf_get_height (result); |
747 | image_height = gdk_pixbuf_get_height (result); |
734 | |
748 | |
735 | if (tr_flags) |
749 | if (tr_flags) |
736 | { |
750 | { |
737 | root_pmap = bg_pixmap; |
751 | root_pmap = bg_pixmap; |
738 | bg_pixmap = None; |
752 | bg_pixmap = None; |
|
|
753 | } |
|
|
754 | else |
|
|
755 | { |
|
|
756 | if (bg_flags & BG_TILE) |
739 | } |
757 | { |
740 | else |
|
|
741 | { |
|
|
742 | if (h_scale == 0 || v_scale == 0) |
|
|
743 | { |
|
|
744 | new_pmap_width = min (image_width, target_width); |
758 | new_pmap_width = min (image_width, target_width); |
745 | new_pmap_height = min (image_height, target_height); |
759 | new_pmap_height = min (image_height, target_height); |
746 | } |
760 | } |
747 | } |
761 | } |
748 | |
762 | |
749 | if (bg_pixmap == None |
763 | if (bg_pixmap == None |
750 | || bg_pmap_width != new_pmap_width |
764 | || bg_pmap_width != new_pmap_width |
751 | || bg_pmap_height != new_pmap_height) |
765 | || bg_pmap_height != new_pmap_height) |
752 | { |
766 | { |
753 | if (bg_pixmap) |
767 | if (bg_pixmap) |
754 | XFreePixmap (dpy, bg_pixmap); |
768 | XFreePixmap (dpy, bg_pixmap); |
755 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
769 | bg_pixmap = XCreatePixmap (dpy, vt, new_pmap_width, new_pmap_height, depth); |
756 | bg_pmap_width = new_pmap_width; |
770 | bg_pmap_width = new_pmap_width; |
757 | bg_pmap_height = new_pmap_height; |
771 | bg_pmap_height = new_pmap_height; |
758 | } |
772 | } |
759 | |
773 | |
760 | gcv.foreground = pix_colors[Color_bg]; |
774 | gcv.foreground = pix_colors[Color_bg]; |
761 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
775 | gc = XCreateGC (dpy, vt, GCForeground, &gcv); |
762 | |
776 | |
763 | if (h_scale == 0 || v_scale == 0) |
777 | if (gc) |
|
|
778 | { |
|
|
779 | if (bg_flags & BG_TILE) |
764 | { |
780 | { |
765 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
781 | Pixmap tile = XCreatePixmap (dpy, vt, image_width, image_height, depth); |
766 | pixbuf_to_pixmap (result, tile, gc, |
782 | pixbuf_to_pixmap (result, tile, gc, |
767 | 0, 0, |
783 | 0, 0, |
768 | 0, 0, |
784 | 0, 0, |
… | |
… | |
812 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
828 | Pixmap mask_pmap = XCreatePixmap (dpy, vt, 1, 1, 8); |
813 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
829 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
814 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
830 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
815 | XFreePixmap (dpy, mask_pmap); |
831 | XFreePixmap (dpy, mask_pmap); |
816 | |
832 | |
817 | if (src && dst && mask) |
|
|
818 | { |
|
|
819 | XRenderColor mask_c; |
833 | XRenderColor mask_c; |
820 | |
834 | |
821 | mask_c.alpha = 0x8000; |
835 | mask_c.alpha = 0x8000; |
822 | mask_c.red = 0; |
836 | mask_c.red = 0; |
823 | mask_c.green = 0; |
837 | mask_c.green = 0; |
824 | mask_c.blue = 0; |
838 | mask_c.blue = 0; |
825 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
839 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
826 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
840 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
827 | } |
|
|
828 | |
841 | |
829 | XRenderFreePicture (dpy, src); |
842 | XRenderFreePicture (dpy, src); |
830 | XRenderFreePicture (dpy, dst); |
843 | XRenderFreePicture (dpy, dst); |
831 | XRenderFreePicture (dpy, mask); |
844 | XRenderFreePicture (dpy, mask); |
832 | |
|
|
833 | XFreePixmap (dpy, root_pmap); |
|
|
834 | } |
845 | } |
835 | #endif |
846 | #endif |
836 | |
847 | |
837 | if (result != pixbuf) |
|
|
838 | g_object_unref (result); |
|
|
839 | |
|
|
840 | XFreeGC (dpy, gc); |
848 | XFreeGC (dpy, gc); |
841 | |
849 | |
842 | ret = true; |
850 | ret = true; |
843 | } |
851 | } |
|
|
852 | |
|
|
853 | if (result != pixbuf) |
|
|
854 | g_object_unref (result); |
|
|
855 | |
|
|
856 | if (tr_flags) |
|
|
857 | XFreePixmap (dpy, root_pmap); |
844 | |
858 | |
845 | return ret; |
859 | return ret; |
846 | } |
860 | } |
847 | # endif /* HAVE_PIXBUF */ |
861 | # endif /* HAVE_PIXBUF */ |
848 | |
862 | |
… | |
… | |
868 | if (image) |
882 | if (image) |
869 | { |
883 | { |
870 | if (original_asim) |
884 | if (original_asim) |
871 | safe_asimage_destroy (original_asim); |
885 | safe_asimage_destroy (original_asim); |
872 | original_asim = image; |
886 | original_asim = image; |
873 | bg_flags |= CLIENT_RENDER; |
887 | bg_flags |= BG_IS_FROM_FILE | BG_CLIENT_RENDER; |
874 | have_image = true; |
|
|
875 | return true; |
888 | return true; |
876 | } |
889 | } |
877 | # endif |
890 | # endif |
878 | |
891 | |
879 | # ifdef HAVE_PIXBUF |
892 | # ifdef HAVE_PIXBUF |
… | |
… | |
881 | if (image) |
894 | if (image) |
882 | { |
895 | { |
883 | if (pixbuf) |
896 | if (pixbuf) |
884 | g_object_unref (pixbuf); |
897 | g_object_unref (pixbuf); |
885 | pixbuf = image; |
898 | pixbuf = image; |
886 | have_image = true; |
899 | bg_flags |= BG_IS_FROM_FILE; |
887 | return true; |
900 | return true; |
888 | } |
901 | } |
889 | # endif |
902 | # endif |
890 | |
903 | |
891 | return false; |
904 | return false; |
… | |
… | |
895 | |
908 | |
896 | # ifdef ENABLE_TRANSPARENCY |
909 | # ifdef ENABLE_TRANSPARENCY |
897 | bool |
910 | bool |
898 | rxvt_term::bg_set_transparent () |
911 | rxvt_term::bg_set_transparent () |
899 | { |
912 | { |
900 | if (!(bg_flags & isTransparent)) |
913 | if (!(bg_flags & BG_IS_TRANSPARENT)) |
901 | { |
914 | { |
902 | bg_flags |= isTransparent; |
915 | bg_flags |= BG_IS_TRANSPARENT; |
903 | return true; |
916 | return true; |
904 | } |
917 | } |
905 | |
918 | |
906 | return false; |
919 | return false; |
907 | } |
920 | } |
… | |
… | |
933 | changed = true; |
946 | changed = true; |
934 | v_blurRadius = vr; |
947 | v_blurRadius = vr; |
935 | } |
948 | } |
936 | |
949 | |
937 | if (v_blurRadius == 0 && h_blurRadius == 0) |
950 | if (v_blurRadius == 0 && h_blurRadius == 0) |
938 | bg_flags &= ~blurNeeded; |
951 | bg_flags &= ~BG_NEEDS_BLUR; |
939 | else |
952 | else |
940 | bg_flags |= blurNeeded; |
953 | bg_flags |= BG_NEEDS_BLUR; |
941 | |
954 | |
942 | return changed; |
955 | return changed; |
943 | } |
956 | } |
944 | |
957 | |
945 | static inline unsigned long |
958 | void |
946 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
959 | rxvt_term::set_tint_shade_flags () |
947 | { |
960 | { |
948 | unsigned long flags = 0; |
|
|
949 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
961 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
950 | bool has_shade = shade != 100; |
962 | bool has_shade = shade != 100; |
951 | |
963 | |
952 | if (tint) |
964 | bg_flags &= ~BG_TINT_FLAGS; |
|
|
965 | |
|
|
966 | if (bg_flags & BG_TINT_SET) |
953 | { |
967 | { |
954 | tint->get (c); |
968 | tint.get (c); |
955 | if (!has_shade |
969 | if (!has_shade |
956 | && (c.r <= 0x00ff || c.r >= 0xff00) |
970 | && (c.r <= 0x00ff || c.r >= 0xff00) |
957 | && (c.g <= 0x00ff || c.g >= 0xff00) |
971 | && (c.g <= 0x00ff || c.g >= 0xff00) |
958 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
972 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
959 | flags |= rxvt_term::tintWholesome; |
973 | bg_flags |= BG_TINT_BITAND; |
960 | } |
974 | } |
961 | |
975 | |
962 | if (has_shade || tint) |
976 | if (has_shade || (bg_flags & BG_TINT_SET)) |
963 | flags |= rxvt_term::tintNeeded; |
977 | bg_flags |= BG_NEEDS_TINT; |
964 | |
|
|
965 | return flags; |
|
|
966 | } |
978 | } |
967 | |
979 | |
968 | bool |
980 | bool |
969 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
981 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
970 | { |
982 | { |
971 | if (!(bg_flags & tintSet) || tint != new_tint) |
983 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
972 | { |
984 | { |
973 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
|
|
974 | tint = new_tint; |
985 | tint = new_tint; |
975 | bg_flags = (bg_flags & ~tintFlags) | new_flags | tintSet; |
986 | bg_flags |= BG_TINT_SET; |
|
|
987 | set_tint_shade_flags (); |
976 | return true; |
988 | return true; |
977 | } |
989 | } |
978 | |
990 | |
979 | return false; |
991 | return false; |
980 | } |
992 | } |
… | |
… | |
988 | if (new_shade < 0) |
1000 | if (new_shade < 0) |
989 | new_shade = 200 - (100 + new_shade); |
1001 | new_shade = 200 - (100 + new_shade); |
990 | |
1002 | |
991 | if (new_shade != shade) |
1003 | if (new_shade != shade) |
992 | { |
1004 | { |
993 | unsigned long new_flags = compute_tint_shade_flags ((bg_flags & tintSet) ? &tint : NULL, new_shade); |
|
|
994 | shade = new_shade; |
1005 | shade = new_shade; |
995 | bg_flags = (bg_flags & ~tintFlags) | new_flags; |
1006 | set_tint_shade_flags (); |
996 | return true; |
1007 | return true; |
997 | } |
1008 | } |
998 | |
1009 | |
999 | return false; |
1010 | return false; |
1000 | } |
1011 | } |
… | |
… | |
1035 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1046 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1036 | |
1047 | |
1037 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1048 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1038 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1049 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
1039 | |
1050 | |
1040 | if (kernel && params && src && dst) |
1051 | if (kernel && params) |
1041 | { |
1052 | { |
1042 | if (h_blurRadius) |
1053 | if (h_blurRadius) |
1043 | { |
1054 | { |
1044 | size = h_blurRadius * 2 + 1; |
1055 | size = h_blurRadius * 2 + 1; |
1045 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
1056 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
… | |
… | |
1088 | bool |
1099 | bool |
1089 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1100 | rxvt_term::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
1090 | { |
1101 | { |
1091 | bool ret = false; |
1102 | bool ret = false; |
1092 | |
1103 | |
1093 | if (bg_flags & tintWholesome) |
1104 | if (bg_flags & BG_TINT_BITAND) |
1094 | { |
1105 | { |
1095 | XGCValues gcv; |
1106 | XGCValues gcv; |
1096 | GC gc; |
1107 | GC gc; |
1097 | |
1108 | |
1098 | /* In this case we can tint image server-side getting significant |
1109 | /* In this case we can tint image server-side getting significant |
… | |
… | |
1110 | } |
1121 | } |
1111 | } |
1122 | } |
1112 | else |
1123 | else |
1113 | { |
1124 | { |
1114 | # if XRENDER |
1125 | # if XRENDER |
1115 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1126 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1116 | |
1127 | |
1117 | if (bg_flags & tintSet) |
1128 | if (bg_flags & BG_TINT_SET) |
1118 | tint.get (c); |
1129 | tint.get (c); |
1119 | |
1130 | |
1120 | if (shade <= 100) |
1131 | if (shade <= 100) |
1121 | { |
1132 | { |
1122 | c.r = (c.r * shade) / 100; |
1133 | c.r = c.r * shade / 100; |
1123 | c.g = (c.g * shade) / 100; |
1134 | c.g = c.g * shade / 100; |
1124 | c.b = (c.b * shade) / 100; |
1135 | c.b = c.b * shade / 100; |
1125 | } |
1136 | } |
1126 | else |
1137 | else |
1127 | { |
1138 | { |
1128 | c.r = (c.r * (200 - shade)) / 100; |
1139 | c.r = c.r * (200 - shade) / 100; |
1129 | c.g = (c.g * (200 - shade)) / 100; |
1140 | c.g = c.g * (200 - shade) / 100; |
1130 | c.b = (c.b * (200 - shade)) / 100; |
1141 | c.b = c.b * (200 - shade) / 100; |
1131 | } |
1142 | } |
1132 | |
1143 | |
1133 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1144 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1134 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1145 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1135 | XRenderPictureAttributes pa; |
1146 | XRenderPictureAttributes pa; |
… | |
… | |
1142 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1153 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1143 | XFreePixmap (dpy, overlay_pmap); |
1154 | XFreePixmap (dpy, overlay_pmap); |
1144 | |
1155 | |
1145 | pa.component_alpha = True; |
1156 | pa.component_alpha = True; |
1146 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1157 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1147 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
1158 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); |
1148 | XFreePixmap (dpy, mask_pmap); |
1159 | XFreePixmap (dpy, mask_pmap); |
1149 | |
1160 | |
1150 | if (mask_pic && overlay_pic && back_pic) |
|
|
1151 | { |
|
|
1152 | XRenderColor mask_c; |
1161 | XRenderColor mask_c; |
1153 | |
1162 | |
1154 | mask_c.red = mask_c.green = mask_c.blue = 0; |
|
|
1155 | mask_c.alpha = 0xffff; |
1163 | mask_c.alpha = 0xffff; |
|
|
1164 | mask_c.red = |
|
|
1165 | mask_c.green = |
|
|
1166 | mask_c.blue = 0; |
|
|
1167 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1168 | |
|
|
1169 | mask_c.alpha = 0; |
|
|
1170 | mask_c.red = 0xffff - c.r; |
|
|
1171 | mask_c.green = 0xffff - c.g; |
|
|
1172 | mask_c.blue = 0xffff - c.b; |
|
|
1173 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1174 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1175 | |
|
|
1176 | if (shade > 100) |
|
|
1177 | { |
|
|
1178 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1179 | mask_c.alpha = 0; |
1156 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1180 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1157 | |
1181 | |
1158 | mask_c.alpha = 0; |
|
|
1159 | mask_c.red = 0xffff - c.r; |
|
|
1160 | mask_c.green = 0xffff - c.g; |
|
|
1161 | mask_c.blue = 0xffff - c.b; |
|
|
1162 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1163 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1164 | |
|
|
1165 | if (shade > 100) |
|
|
1166 | { |
|
|
1167 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1168 | mask_c.alpha = 0; |
|
|
1169 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1170 | |
|
|
1171 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1182 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1172 | } |
1183 | } |
1173 | |
1184 | |
1174 | ret = true; |
1185 | ret = true; |
1175 | } |
|
|
1176 | |
1186 | |
1177 | XRenderFreePicture (dpy, mask_pic); |
1187 | XRenderFreePicture (dpy, mask_pic); |
1178 | XRenderFreePicture (dpy, overlay_pic); |
1188 | XRenderFreePicture (dpy, overlay_pic); |
1179 | XRenderFreePicture (dpy, back_pic); |
1189 | XRenderFreePicture (dpy, back_pic); |
1180 | # endif |
1190 | # endif |
1181 | } |
1191 | } |
1182 | |
1192 | |
1183 | return ret; |
1193 | return ret; |
1184 | } |
1194 | } |
1185 | |
1195 | |
1186 | /* make_transparency_pixmap() |
1196 | /* |
1187 | * Builds a pixmap of the same size as the terminal window that contains |
1197 | * Builds a pixmap of the same size as the terminal window that contains |
1188 | * the tiled portion of the root pixmap that is supposed to be covered by |
1198 | * the tiled portion of the root pixmap that is supposed to be covered by |
1189 | * our window. |
1199 | * our window. |
1190 | */ |
1200 | */ |
1191 | unsigned long |
1201 | unsigned long |
… | |
… | |
1233 | Pixmap recoded_root_pmap = root_pixmap; |
1243 | Pixmap recoded_root_pmap = root_pixmap; |
1234 | |
1244 | |
1235 | if (root_pixmap != None && root_depth != depth) |
1245 | if (root_pixmap != None && root_depth != depth) |
1236 | { |
1246 | { |
1237 | #if XRENDER |
1247 | #if XRENDER |
1238 | if (bg_flags & HAS_RENDER) |
1248 | if (bg_flags & BG_HAS_RENDER) |
1239 | { |
1249 | { |
|
|
1250 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
|
|
1251 | |
1240 | XRenderPictureAttributes pa; |
1252 | XRenderPictureAttributes pa; |
1241 | |
1253 | |
1242 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1254 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, screen)); |
1243 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1255 | Picture src = XRenderCreatePicture (dpy, root_pixmap, src_format, 0, &pa); |
1244 | |
1256 | |
1245 | recoded_root_pmap = XCreatePixmap (dpy, vt, root_pmap_width, root_pmap_height, depth); |
|
|
1246 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1257 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, visual); |
1247 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1258 | Picture dst = XRenderCreatePicture (dpy, recoded_root_pmap, dst_format, 0, &pa); |
1248 | |
1259 | |
1249 | if (src && dst) |
|
|
1250 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1260 | XRenderComposite (dpy, PictOpSrc, src, None, dst, 0, 0, 0, 0, 0, 0, root_pmap_width, root_pmap_height); |
1251 | else |
|
|
1252 | { |
|
|
1253 | XFreePixmap (dpy, recoded_root_pmap); |
|
|
1254 | root_pixmap = None; |
|
|
1255 | } |
|
|
1256 | |
1261 | |
1257 | XRenderFreePicture (dpy, src); |
1262 | XRenderFreePicture (dpy, src); |
1258 | XRenderFreePicture (dpy, dst); |
1263 | XRenderFreePicture (dpy, dst); |
1259 | } |
1264 | } |
1260 | else |
1265 | else |
1261 | #endif |
1266 | #endif |
1262 | root_pixmap = None; |
1267 | recoded_root_pmap = None; |
1263 | } |
1268 | } |
1264 | |
1269 | |
1265 | if (root_pixmap == None) |
1270 | if (recoded_root_pmap == None) |
1266 | return 0; |
1271 | return 0; |
1267 | |
1272 | |
1268 | if (bg_pixmap == None |
1273 | if (bg_pixmap == None |
1269 | || bg_pmap_width != window_width |
1274 | || bg_pmap_width != window_width |
1270 | || bg_pmap_height != window_height) |
1275 | || bg_pmap_height != window_height) |
… | |
… | |
1274 | bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); |
1279 | bg_pixmap = XCreatePixmap (dpy, vt, window_width, window_height, depth); |
1275 | bg_pmap_width = window_width; |
1280 | bg_pmap_width = window_width; |
1276 | bg_pmap_height = window_height; |
1281 | bg_pmap_height = window_height; |
1277 | } |
1282 | } |
1278 | |
1283 | |
1279 | if (bg_pixmap == None) |
|
|
1280 | return 0; |
|
|
1281 | |
|
|
1282 | /* straightforward pixmap copy */ |
1284 | /* straightforward pixmap copy */ |
1283 | while (sx < 0) sx += (int)root_width; |
1285 | while (sx < 0) sx += root_width; |
1284 | while (sy < 0) sy += (int)root_height; |
1286 | while (sy < 0) sy += root_height; |
1285 | |
1287 | |
1286 | gcv.tile = recoded_root_pmap; |
1288 | gcv.tile = recoded_root_pmap; |
1287 | gcv.fill_style = FillTiled; |
1289 | gcv.fill_style = FillTiled; |
1288 | gcv.ts_x_origin = -sx; |
1290 | gcv.ts_x_origin = -sx; |
1289 | gcv.ts_y_origin = -sy; |
1291 | gcv.ts_y_origin = -sy; |
1290 | gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1292 | gc = XCreateGC (dpy, vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1291 | |
1293 | |
1292 | if (gc) |
1294 | if (gc) |
1293 | { |
1295 | { |
1294 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1296 | XFillRectangle (dpy, bg_pixmap, gc, 0, 0, window_width, window_height); |
1295 | result |= isValid | (bg_flags & effectsFlags); |
1297 | result |= BG_IS_VALID | (bg_flags & BG_EFFECTS_FLAGS); |
1296 | XFreeGC (dpy, gc); |
1298 | XFreeGC (dpy, gc); |
1297 | |
1299 | |
1298 | if (!(bg_flags & CLIENT_RENDER)) |
1300 | if (!(bg_flags & BG_CLIENT_RENDER)) |
1299 | { |
1301 | { |
1300 | if ((bg_flags & blurNeeded) |
1302 | if ((bg_flags & BG_NEEDS_BLUR) |
1301 | && (bg_flags & HAS_RENDER_CONV)) |
1303 | && (bg_flags & BG_HAS_RENDER_CONV)) |
1302 | { |
1304 | { |
1303 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) |
1305 | if (blur_pixmap (bg_pixmap, visual, window_width, window_height)) |
1304 | result &= ~blurNeeded; |
1306 | result &= ~BG_NEEDS_BLUR; |
1305 | } |
1307 | } |
1306 | if ((bg_flags & tintNeeded) |
1308 | if ((bg_flags & BG_NEEDS_TINT) |
1307 | && (bg_flags & (tintWholesome | HAS_RENDER))) |
1309 | && (bg_flags & (BG_TINT_BITAND | BG_HAS_RENDER))) |
1308 | { |
1310 | { |
1309 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1311 | if (tint_pixmap (bg_pixmap, visual, window_width, window_height)) |
1310 | result &= ~tintNeeded; |
1312 | result &= ~BG_NEEDS_TINT; |
1311 | } |
1313 | } |
1312 | } /* server side rendering completed */ |
1314 | } /* server side rendering completed */ |
1313 | } |
1315 | } |
1314 | |
1316 | |
1315 | if (recoded_root_pmap != root_pixmap) |
1317 | if (recoded_root_pmap != root_pixmap) |
… | |
… | |
1338 | { |
1340 | { |
1339 | unsigned long tr_flags = 0; |
1341 | unsigned long tr_flags = 0; |
1340 | |
1342 | |
1341 | bg_invalidate (); |
1343 | bg_invalidate (); |
1342 | # ifdef ENABLE_TRANSPARENCY |
1344 | # ifdef ENABLE_TRANSPARENCY |
1343 | if (bg_flags & isTransparent) |
1345 | if (bg_flags & BG_IS_TRANSPARENT) |
1344 | { |
1346 | { |
1345 | /* we need to re-generate transparency pixmap in that case ! */ |
1347 | /* we need to re-generate transparency pixmap in that case ! */ |
1346 | tr_flags = make_transparency_pixmap (); |
1348 | tr_flags = make_transparency_pixmap (); |
1347 | if (tr_flags == 0) |
1349 | if (tr_flags == 0) |
1348 | return false; |
1350 | return false; |
1349 | else if (!(tr_flags & effectsFlags)) |
1351 | else if (!(tr_flags & BG_EFFECTS_FLAGS)) |
1350 | bg_flags |= isValid; |
1352 | bg_flags |= BG_IS_VALID; |
1351 | } |
1353 | } |
1352 | # endif |
1354 | # endif |
1353 | |
1355 | |
1354 | # ifdef BG_IMAGE_FROM_FILE |
1356 | # ifdef BG_IMAGE_FROM_FILE |
1355 | if (have_image |
1357 | if ((bg_flags & BG_IS_FROM_FILE) |
1356 | || (tr_flags & effectsFlags)) |
1358 | || (tr_flags & BG_EFFECTS_FLAGS)) |
1357 | { |
1359 | { |
1358 | if (render_image (tr_flags)) |
1360 | if (render_image (tr_flags)) |
1359 | bg_flags |= isValid; |
1361 | bg_flags |= BG_IS_VALID; |
1360 | } |
1362 | } |
1361 | # endif |
1363 | # endif |
1362 | |
1364 | |
1363 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1365 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1364 | XImage *result = NULL; |
1366 | XImage *result = NULL; |
1365 | |
1367 | |
1366 | if (tr_flags && !(bg_flags & isValid)) |
1368 | if (tr_flags && !(bg_flags & BG_IS_VALID)) |
1367 | { |
1369 | { |
1368 | result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1370 | result = XGetImage (dpy, bg_pixmap, 0, 0, bg_pmap_width, bg_pmap_height, AllPlanes, ZPixmap); |
1369 | } |
1371 | } |
1370 | |
1372 | |
1371 | if (result) |
1373 | if (result) |
1372 | { |
1374 | { |
1373 | /* our own client-side tinting */ |
1375 | /* our own client-side tinting */ |
1374 | if (tr_flags & tintNeeded) |
1376 | if (tr_flags & BG_NEEDS_TINT) |
1375 | { |
1377 | { |
1376 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1378 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1377 | if (bg_flags & tintSet) |
1379 | if (bg_flags & BG_TINT_SET) |
1378 | tint.get (c); |
1380 | tint.get (c); |
1379 | shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); |
1381 | shade_ximage (DefaultVisual (dpy, display->screen), result, shade, c); |
1380 | } |
1382 | } |
1381 | |
1383 | |
1382 | GC gc = XCreateGC (dpy, vt, 0UL, NULL); |
1384 | GC gc = XCreateGC (dpy, vt, 0UL, NULL); |
… | |
… | |
1384 | if (gc) |
1386 | if (gc) |
1385 | { |
1387 | { |
1386 | XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1388 | XPutImage (dpy, bg_pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1387 | |
1389 | |
1388 | XFreeGC (dpy, gc); |
1390 | XFreeGC (dpy, gc); |
1389 | bg_flags |= isValid; |
1391 | bg_flags |= BG_IS_VALID; |
1390 | } |
1392 | } |
1391 | |
1393 | |
1392 | XDestroyImage (result); |
1394 | XDestroyImage (result); |
1393 | } |
1395 | } |
1394 | # endif |
1396 | # endif |
1395 | |
1397 | |
1396 | if (!(bg_flags & isValid)) |
1398 | if (!(bg_flags & BG_IS_VALID)) |
1397 | { |
1399 | { |
1398 | if (bg_pixmap != None) |
1400 | if (bg_pixmap != None) |
1399 | { |
1401 | { |
1400 | XFreePixmap (dpy, bg_pixmap); |
1402 | XFreePixmap (dpy, bg_pixmap); |
1401 | bg_pixmap = None; |
1403 | bg_pixmap = None; |
1402 | } |
1404 | } |
1403 | } |
1405 | } |
1404 | |
1406 | |
1405 | scr_recolour (false); |
1407 | scr_recolour (false); |
1406 | bg_flags |= hasChanged; |
1408 | bg_flags |= BG_NEEDS_REFRESH; |
1407 | |
1409 | |
1408 | bg_valid_since = ev::now (); |
1410 | bg_valid_since = ev::now (); |
1409 | |
1411 | |
1410 | return true; |
1412 | return true; |
1411 | } |
1413 | } |
… | |
… | |
1415 | { |
1417 | { |
1416 | #ifdef ENABLE_TRANSPARENCY |
1418 | #ifdef ENABLE_TRANSPARENCY |
1417 | shade = 100; |
1419 | shade = 100; |
1418 | #endif |
1420 | #endif |
1419 | |
1421 | |
1420 | bg_flags &= ~(HAS_RENDER | HAS_RENDER_CONV); |
1422 | bg_flags &= ~(BG_HAS_RENDER | BG_HAS_RENDER_CONV); |
1421 | #if XRENDER |
1423 | #if XRENDER |
1422 | int major, minor; |
1424 | int major, minor; |
1423 | if (XRenderQueryVersion (dpy, &major, &minor)) |
1425 | if (XRenderQueryVersion (dpy, &major, &minor)) |
1424 | bg_flags |= HAS_RENDER; |
1426 | bg_flags |= BG_HAS_RENDER; |
1425 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
1427 | XFilters *filters = XRenderQueryFilters (dpy, vt); |
1426 | if (filters) |
1428 | if (filters) |
1427 | { |
1429 | { |
1428 | for (int i = 0; i < filters->nfilter; i++) |
1430 | for (int i = 0; i < filters->nfilter; i++) |
1429 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1431 | if (!strcmp (filters->filter[i], FilterConvolution)) |
1430 | bg_flags |= HAS_RENDER_CONV; |
1432 | bg_flags |= BG_HAS_RENDER_CONV; |
1431 | |
1433 | |
1432 | XFree (filters); |
1434 | XFree (filters); |
1433 | } |
1435 | } |
1434 | #endif |
1436 | #endif |
1435 | } |
1437 | } |
… | |
… | |
1446 | uint32_t mask_r, mask_g, mask_b; |
1448 | uint32_t mask_r, mask_g, mask_b; |
1447 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1449 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1448 | rgba low; |
1450 | rgba low; |
1449 | rgba high; |
1451 | rgba high; |
1450 | int i; |
1452 | int i; |
1451 | int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
1453 | int host_byte_order = ecb_big_endian () ? MSBFirst : LSBFirst; |
1452 | |
1454 | |
1453 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1455 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1454 | |
1456 | |
1455 | /* for convenience */ |
1457 | /* for convenience */ |
1456 | mask_r = visual->red_mask; |
1458 | mask_r = visual->red_mask; |