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-2006 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
8 | * |
8 | * |
9 | * This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
11 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
27 | #define DO_TIMING_TEST 0 |
27 | #define DO_TIMING_TEST 0 |
28 | |
28 | |
29 | #if DO_TIMING_TEST |
29 | #if DO_TIMING_TEST |
30 | # include <sys/time.h> |
30 | # include <sys/time.h> |
31 | #define TIMING_TEST_START(id) \ |
31 | #define TIMING_TEST_START(id) \ |
32 | struct timeval timing_test_##id##_stv;\ |
32 | struct timeval timing_test_##id##_stv; \ |
33 | gettimeofday (&timing_test_##id##_stv, NULL); |
33 | gettimeofday (&timing_test_##id##_stv, NULL); |
34 | |
34 | |
35 | #define TIMING_TEST_PRINT_RESULT(id) \ |
35 | #define TIMING_TEST_PRINT_RESULT(id) \ |
36 | do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ |
36 | do { \ |
|
|
37 | struct timeval tv; \ |
|
|
38 | gettimeofday (&tv, NULL); \ |
|
|
39 | tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \ |
37 | fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ |
40 | fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \ |
38 | tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) |
41 | tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \ |
|
|
42 | } while (0) |
39 | |
43 | |
40 | #else |
44 | #else |
41 | #define TIMING_TEST_START(id) do{}while (0) |
45 | #define TIMING_TEST_START(id) do {} while (0) |
42 | #define TIMING_TEST_PRINT_RESULT(id) do{}while (0) |
46 | #define TIMING_TEST_PRINT_RESULT(id) do {} while (0) |
43 | #endif |
47 | #endif |
44 | |
48 | |
45 | /* |
49 | /* |
46 | * Pixmap geometry string interpretation : |
50 | * Pixmap geometry string interpretation : |
47 | * Each geometry string contains zero or one scale/position |
51 | * Each geometry string contains zero or one scale/position |
48 | * adjustment and may optionally be followed by a colon and one or more |
52 | * adjustment and may optionally be followed by a colon and one or more |
49 | * colon-delimited pixmap operations. |
53 | * colon-delimited pixmap operations. |
50 | * The following table shows the valid geometry strings and their |
54 | * The following table shows the valid geometry strings and their |
51 | * affects on the background image : |
55 | * effects on the background image : |
52 | * |
56 | * |
53 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
57 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
54 | * W and H are percentages of the terminal window size. |
58 | * W and H are percentages of the terminal window size. |
55 | * X and Y are also percentages; e.g., +50+50 centers |
59 | * X and Y are also percentages; e.g., +50+50 centers |
56 | * the image in the window. |
60 | * the image in the window. |
57 | * WxH+X Assumes Y == X |
61 | * WxH+X Assumes Y == X |
58 | * WxH Assumes Y == X == 50 (centers the image) |
62 | * WxH Assumes Y == X == 50 (centers the image) |
59 | * W+X+Y Assumes H == W |
63 | * W+X+Y Assumes H == W |
60 | * W+X Assumes H == W and Y == X |
64 | * W+X Assumes H == W and Y == X |
61 | * W Assumes H == W and Y == X == 50 |
65 | * W Assumes H == W and Y == X == 50 |
62 | * |
66 | * |
63 | * Adjusting position only : |
67 | * Adjusting position only : |
64 | * =+X+Y Set position to X% by Y% (absolute). |
68 | * =+X+Y Set position to X% by Y% (absolute). |
65 | * =+X Set position to X% by X%. |
69 | * =+X Set position to X% by X%. |
66 | * +X+Y Adjust position horizontally X% and vertically Y% |
70 | * +X+Y Adjust position horizontally X% and vertically Y% |
67 | * from current position (relative). |
71 | * from current position (relative). |
68 | * +X Adjust position horizontally X% and vertically X% |
72 | * +X Adjust position horizontally X% and vertically X% |
69 | * from current position. |
73 | * from current position. |
70 | * |
74 | * |
71 | * Adjusting scale only : |
75 | * Adjusting scale only : |
72 | * Wx0 Multiply horizontal scaling factor by W% |
76 | * Wx0 Multiply horizontal scaling factor by W% |
73 | * 0xH Multiply vertical scaling factor by H% |
77 | * 0xH Multiply vertical scaling factor by H% |
74 | * 0x0 No scaling (show image at normal size). |
78 | * 0x0 No scaling (show image at normal size). |
75 | * |
79 | * |
76 | * Pixmap Operations : (should be prepended by a colon) |
80 | * Pixmap Operations : (should be prepended by a colon) |
77 | * tile Tile image. Scaling/position modifiers above will affect |
81 | * tile Tile image. Scaling/position modifiers above will affect |
78 | * the tile size and origin. |
82 | * the tile size and origin. |
79 | * propscale When scaling, scale proportionally. That is, maintain the |
83 | * propscale When scaling, scale proportionally. That is, maintain the |
80 | * proper aspect ratio for the image. Any portion of the |
84 | * proper aspect ratio for the image. Any portion of the |
81 | * background not covered by the image is filled with the |
85 | * background not covered by the image is filled with the |
82 | * current background color. |
86 | * current background color. |
83 | * hscale Scale horizontally, tile vertically ? |
87 | * hscale Scale horizontally, tile vertically ? |
84 | * vscale Tile horizontally, scale vertically ? |
88 | * vscale Tile horizontally, scale vertically ? |
… | |
… | |
87 | */ |
91 | */ |
88 | |
92 | |
89 | #ifdef HAVE_BG_PIXMAP |
93 | #ifdef HAVE_BG_PIXMAP |
90 | bgPixmap_t::bgPixmap_t () |
94 | bgPixmap_t::bgPixmap_t () |
91 | { |
95 | { |
|
|
96 | // this is basically redundant as bgPixmap_t is only used in |
|
|
97 | // zero_initialised-derived structs |
92 | #ifdef HAVE_AFTERIMAGE |
98 | #ifdef HAVE_AFTERIMAGE |
93 | original_asim = NULL; |
99 | original_asim = NULL; |
94 | #endif |
100 | #endif |
95 | #ifdef BG_IMAGE_FROM_FILE |
101 | #ifdef BG_IMAGE_FROM_FILE |
|
|
102 | have_image = false; |
96 | h_scale = v_scale = 0; |
103 | h_scale = v_scale = 0; |
97 | h_align = v_align = 0; |
104 | h_align = v_align = 0; |
98 | #endif |
105 | #endif |
99 | flags = 0; |
106 | flags = 0; |
100 | pixmap = None; |
107 | pixmap = None; |
|
|
108 | valid_since = invalid_since = 0; |
|
|
109 | target = 0; |
101 | } |
110 | } |
102 | |
111 | |
103 | void |
112 | void |
104 | bgPixmap_t::destroy () |
113 | bgPixmap_t::destroy () |
105 | { |
114 | { |
… | |
… | |
119 | if (flags & isTransparent) |
128 | if (flags & isTransparent) |
120 | return true; |
129 | return true; |
121 | # endif |
130 | # endif |
122 | |
131 | |
123 | # ifdef BG_IMAGE_FROM_FILE |
132 | # ifdef BG_IMAGE_FROM_FILE |
124 | # ifdef HAVE_AFTERIMAGE |
133 | if (have_image) |
125 | if (original_asim != NULL) |
|
|
126 | # endif |
|
|
127 | { |
134 | { |
128 | if (h_scale != 0 || v_scale != 0 |
135 | if (h_scale != 0 || v_scale != 0 |
129 | || h_align != 0 || v_align != 0) |
136 | || h_align != 0 || v_align != 0) |
130 | return true; |
137 | return true; |
131 | } |
138 | } |
132 | # endif |
139 | # endif |
133 | |
140 | |
134 | return false; |
141 | return false; |
135 | } |
142 | } |
136 | |
143 | |
137 | bool |
144 | bool |
138 | bgPixmap_t::window_position_sensitive () |
145 | bgPixmap_t::window_position_sensitive () |
139 | { |
146 | { |
140 | # ifdef ENABLE_TRANSPARENCY |
147 | # ifdef ENABLE_TRANSPARENCY |
141 | if (flags & isTransparent) |
148 | if (flags & isTransparent) |
142 | return true; |
149 | return true; |
143 | # endif |
150 | # endif |
144 | |
151 | |
145 | # ifdef BG_IMAGE_FROM_FILE |
152 | # ifdef BG_IMAGE_FROM_FILE |
146 | # ifdef HAVE_AFTERIMAGE |
153 | if (have_image) |
147 | if (original_asim != NULL) |
|
|
148 | # endif |
|
|
149 | { |
154 | { |
150 | if (h_align == rootAlign || v_align == rootAlign) |
155 | if (h_align == rootAlign || v_align == rootAlign) |
151 | return true; |
156 | return true; |
152 | } |
157 | } |
153 | # endif |
158 | # endif |
… | |
… | |
156 | }; |
161 | }; |
157 | |
162 | |
158 | bool bgPixmap_t::need_client_side_rendering () |
163 | bool bgPixmap_t::need_client_side_rendering () |
159 | { |
164 | { |
160 | # ifdef HAVE_AFTERIMAGE |
165 | # ifdef HAVE_AFTERIMAGE |
161 | if (original_asim != NULL) |
166 | if (original_asim) |
162 | return true; |
167 | return true; |
163 | # endif |
168 | # endif |
164 | # ifdef ENABLE_TRANSPARENCY |
169 | # ifdef ENABLE_TRANSPARENCY |
165 | if (flags & isTransparent) |
170 | if (flags & isTransparent) |
166 | { |
171 | { |
… | |
… | |
255 | int geom_flags = 0, changed = 0; |
260 | int geom_flags = 0, changed = 0; |
256 | int x = 0, y = 0; |
261 | int x = 0, y = 0; |
257 | unsigned int w = 0, h = 0; |
262 | unsigned int w = 0, h = 0; |
258 | unsigned int n; |
263 | unsigned int n; |
259 | unsigned long new_flags = (flags & (~geometryFlags)); |
264 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | char *p; |
265 | const char *p; |
261 | # define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
266 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
262 | |
267 | |
263 | if (geom == NULL) |
268 | if (geom == NULL) |
264 | return false; |
269 | return false; |
265 | |
270 | |
266 | char str[MAXLEN_GEOM]; |
271 | char str[MAXLEN_GEOM]; |
… | |
… | |
273 | if (n < MAXLEN_GEOM) |
278 | if (n < MAXLEN_GEOM) |
274 | { |
279 | { |
275 | char *ops; |
280 | char *ops; |
276 | new_flags |= geometrySet; |
281 | new_flags |= geometrySet; |
277 | |
282 | |
278 | strncpy (str, geom, n); |
283 | memcpy (str, geom, n); |
279 | str[n] = '\0'; |
284 | str[n] = '\0'; |
280 | if (str[0] == ':') |
285 | if (str[0] == ':') |
281 | ops = &str[0]; |
286 | ops = &str[0]; |
282 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
287 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
283 | ops = &str[0]; |
288 | ops = &str[0]; |
… | |
… | |
366 | if (ops) |
371 | if (ops) |
367 | { |
372 | { |
368 | while (*ops) |
373 | while (*ops) |
369 | { |
374 | { |
370 | while (*ops == ':' || isspace(*ops)) ++ops; |
375 | while (*ops == ':' || isspace(*ops)) ++ops; |
|
|
376 | |
371 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
377 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) |
372 | if (CHECK_GEOM_OPS("tile")) |
378 | if (CHECK_GEOM_OPS ("tile")) |
373 | { |
379 | { |
374 | w = h = noScale; |
380 | w = h = noScale; |
375 | geom_flags |= WidthValue|HeightValue; |
381 | geom_flags |= WidthValue|HeightValue; |
376 | } |
382 | } |
377 | else if (CHECK_GEOM_OPS("propscale")) |
383 | else if (CHECK_GEOM_OPS ("propscale")) |
378 | { |
384 | { |
379 | if (w == 0 && h == 0) |
385 | if (w == 0 && h == 0) |
380 | { |
386 | { |
381 | w = windowScale; |
387 | w = windowScale; |
382 | geom_flags |= WidthValue; |
388 | geom_flags |= WidthValue; |
383 | } |
389 | } |
384 | new_flags |= propScale; |
390 | new_flags |= propScale; |
385 | } |
391 | } |
386 | else if (CHECK_GEOM_OPS("hscale")) |
392 | else if (CHECK_GEOM_OPS ("hscale")) |
387 | { |
393 | { |
388 | if (w == 0) |
|
|
389 | w = windowScale; |
394 | if (w == 0) w = windowScale; |
|
|
395 | |
390 | h = noScale; |
396 | h = noScale; |
391 | geom_flags |= WidthValue|HeightValue; |
397 | geom_flags |= WidthValue|HeightValue; |
392 | } |
398 | } |
393 | else if (CHECK_GEOM_OPS("vscale")) |
399 | else if (CHECK_GEOM_OPS ("vscale")) |
394 | { |
400 | { |
395 | if (h == 0) |
|
|
396 | h = windowScale; |
401 | if (h == 0) h = windowScale; |
|
|
402 | |
397 | w = noScale; |
403 | w = noScale; |
398 | geom_flags |= WidthValue|HeightValue; |
404 | geom_flags |= WidthValue|HeightValue; |
399 | } |
405 | } |
400 | else if (CHECK_GEOM_OPS("scale")) |
406 | else if (CHECK_GEOM_OPS ("scale")) |
401 | { |
407 | { |
402 | if (h == 0) |
|
|
403 | h = windowScale; |
408 | if (h == 0) h = windowScale; |
404 | if (w == 0) |
|
|
405 | w = windowScale; |
409 | if (w == 0) w = windowScale; |
|
|
410 | |
406 | geom_flags |= WidthValue|HeightValue; |
411 | geom_flags |= WidthValue|HeightValue; |
407 | } |
412 | } |
408 | else if (CHECK_GEOM_OPS("auto")) |
413 | else if (CHECK_GEOM_OPS ("auto")) |
409 | { |
414 | { |
410 | w = h = windowScale; |
415 | w = h = windowScale; |
411 | x = y = centerAlign; |
416 | x = y = centerAlign; |
412 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
417 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
413 | } |
418 | } |
414 | else if (CHECK_GEOM_OPS("root")) |
419 | else if (CHECK_GEOM_OPS ("root")) |
415 | { |
420 | { |
416 | w = h = noScale; |
421 | w = h = noScale; |
417 | x = y = rootAlign; |
422 | x = y = rootAlign; |
418 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
423 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
419 | } |
424 | } |
420 | # undef CHECK_GEOM_OPS |
425 | # undef CHECK_GEOM_OPS |
|
|
426 | |
421 | while (*ops != ':' && *ops != '\0') ++ops; |
427 | while (*ops != ':' && *ops != '\0') ++ops; |
422 | } /* done parsing ops */ |
428 | } /* done parsing ops */ |
423 | } |
429 | } |
424 | |
430 | |
425 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) |
431 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; |
426 | ++changed; |
|
|
427 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) |
432 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; |
428 | ++changed; |
|
|
429 | if (check_set_align_value (geom_flags, XValue, h_align, x)) |
433 | if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; |
430 | ++changed; |
|
|
431 | if (check_set_align_value (geom_flags, YValue, v_align, y)) |
434 | if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; |
432 | ++changed; |
|
|
433 | } |
435 | } |
434 | |
436 | |
435 | if (new_flags != flags) |
437 | if (new_flags != flags) |
436 | { |
438 | { |
437 | flags = new_flags; |
439 | flags = new_flags; |
438 | changed++; |
440 | changed++; |
439 | } |
441 | } |
|
|
442 | |
440 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
443 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
441 | // flags, h_scale, v_scale, h_align, v_align); |
444 | // flags, h_scale, v_scale, h_align, v_align); |
442 | return (changed > 0); |
445 | return (changed > 0); |
443 | } |
446 | } |
444 | |
447 | |
445 | # ifdef HAVE_AFTERIMAGE |
448 | # ifdef HAVE_AFTERIMAGE |
446 | bool |
449 | bool |
447 | bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) |
450 | bgPixmap_t::render_image (unsigned long background_flags) |
448 | { |
451 | { |
449 | if (target == NULL) |
452 | if (target == NULL) |
450 | return false; |
453 | return false; |
451 | |
454 | |
|
|
455 | target->init_asv (); |
|
|
456 | |
|
|
457 | ASImage *background = NULL; |
|
|
458 | ARGB32 background_tint = TINT_LEAVE_SAME; |
|
|
459 | |
|
|
460 | # ifdef ENABLE_TRANSPARENCY |
|
|
461 | if (background_flags) |
|
|
462 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
463 | |
|
|
464 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
465 | { |
|
|
466 | ShadingInfo as_shade; |
|
|
467 | as_shade.shading = (shade == 0) ? 100 : shade; |
|
|
468 | |
|
|
469 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
470 | if (flags & tintSet) |
|
|
471 | tint.get (c); |
|
|
472 | as_shade.tintColor.red = c.r; |
|
|
473 | as_shade.tintColor.green = c.g; |
|
|
474 | as_shade.tintColor.blue = c.b; |
|
|
475 | |
|
|
476 | background_tint = shading2tint32 (&as_shade); |
|
|
477 | } |
|
|
478 | |
|
|
479 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
|
|
480 | { |
|
|
481 | ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
482 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
|
|
483 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
484 | if (tmp) |
|
|
485 | { |
|
|
486 | destroy_asimage (&background); |
|
|
487 | background = tmp; |
|
|
488 | } |
|
|
489 | } |
|
|
490 | # endif |
|
|
491 | |
|
|
492 | ASImage *result = 0; |
|
|
493 | |
452 | int target_width = (int)target->szHint.width; |
494 | int target_width = target->szHint.width; |
453 | int target_height = (int)target->szHint.height; |
495 | int target_height = target->szHint.height; |
454 | int new_pmap_width = target_width, new_pmap_height = target_height; |
496 | int new_pmap_width = target_width; |
455 | ASImage *result = NULL; |
497 | int new_pmap_height = target_height; |
456 | |
498 | |
457 | int x = 0; |
499 | int x = 0; |
458 | int y = 0; |
500 | int y = 0; |
459 | int w = h_scale * target_width / 100; |
501 | int w = h_scale * target_width / 100; |
460 | int h = v_scale * target_height / 100; |
502 | int h = v_scale * target_height / 100; |
… | |
… | |
463 | |
505 | |
464 | if (original_asim) |
506 | if (original_asim) |
465 | { |
507 | { |
466 | if (h_align == rootAlign || v_align == rootAlign) |
508 | if (h_align == rootAlign || v_align == rootAlign) |
467 | { |
509 | { |
468 | target->get_window_origin(x, y); |
510 | target->get_window_origin (x, y); |
469 | x = -x; |
511 | x = -x; |
470 | y = -y; |
512 | y = -y; |
471 | } |
513 | } |
|
|
514 | |
472 | if (h_align != rootAlign) |
515 | if (h_align != rootAlign) |
473 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
516 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
517 | |
474 | if (v_align != rootAlign) |
518 | if (v_align != rootAlign) |
475 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
519 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
476 | } |
520 | } |
477 | |
521 | |
478 | if (original_asim == NULL |
522 | if (!original_asim |
479 | || x >= target_width |
523 | || x >= target_width |
480 | || y >= target_height |
524 | || y >= target_height |
481 | || (w > 0 && x + w <= 0) |
525 | || (w > 0 && x + w <= 0) |
482 | || (h > 0 && y + h <= 0)) |
526 | || (h > 0 && y + h <= 0)) |
483 | { |
527 | { |
484 | if (background) |
528 | if (background) |
485 | { |
529 | { |
486 | new_pmap_width = background->width; |
530 | new_pmap_width = background->width; |
487 | new_pmap_height = background->height; |
531 | new_pmap_height = background->height; |
488 | result = background; |
532 | result = background; |
|
|
533 | |
489 | if (background_tint != TINT_LEAVE_SAME) |
534 | if (background_tint != TINT_LEAVE_SAME) |
490 | { |
535 | { |
491 | ASImage* tmp = tile_asimage (target->asv, background, 0, 0, |
536 | ASImage *tmp = tile_asimage (target->asv, background, 0, 0, |
492 | target_width, target_height, background_tint, |
537 | target_width, target_height, background_tint, |
493 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
538 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
494 | if (tmp) |
539 | if (tmp) |
495 | result = tmp; |
540 | result = tmp; |
496 | } |
541 | } |
… | |
… | |
499 | new_pmap_width = new_pmap_height = 0; |
544 | new_pmap_width = new_pmap_height = 0; |
500 | } |
545 | } |
501 | else |
546 | else |
502 | { |
547 | { |
503 | result = original_asim; |
548 | result = original_asim; |
|
|
549 | |
504 | if ((w > 0 && w != original_asim->width) |
550 | if ((w > 0 && w != original_asim->width) |
505 | || (h > 0 && h != original_asim->height)) |
551 | || (h > 0 && h != original_asim->height)) |
506 | { |
552 | { |
507 | result = scale_asimage (target->asv, original_asim, |
553 | result = scale_asimage (target->asv, original_asim, |
508 | w > 0 ? w : original_asim->width, |
554 | w > 0 ? w : original_asim->width, |
509 | h > 0 ? h : original_asim->height, |
555 | h > 0 ? h : original_asim->height, |
510 | background ? ASA_ASImage : ASA_XImage, |
556 | background ? ASA_ASImage : ASA_XImage, |
511 | 100, ASIMAGE_QUALITY_DEFAULT); |
557 | 100, ASIMAGE_QUALITY_DEFAULT); |
512 | } |
558 | } |
|
|
559 | |
513 | if (background == NULL) |
560 | if (background == NULL) |
514 | { |
561 | { |
515 | /* if tiling - pixmap has to be sized exactly as the image, |
562 | /* if tiling - pixmap has to be sized exactly as the image, |
516 | but there is no need to make it bigger then the window! */ |
563 | but there is no need to make it bigger than the window! */ |
517 | if (h_scale == 0) |
564 | if (h_scale == 0) |
518 | new_pmap_width = min (result->width, target_width); |
565 | new_pmap_width = min (result->width, target_width); |
519 | if (v_scale == 0) |
566 | if (v_scale == 0) |
520 | new_pmap_height = min (result->height, target_height); |
567 | new_pmap_height = min (result->height, target_height); |
521 | /* we also need to tile our image in one or both directions */ |
568 | /* we also need to tile our image in one or both directions */ |
522 | if (h_scale == 0 || v_scale == 0) |
569 | if (h_scale == 0 || v_scale == 0) |
523 | { |
570 | { |
524 | ASImage *tmp = tile_asimage (target->asv, result, |
571 | ASImage *tmp = tile_asimage (target->asv, result, |
525 | (h_scale > 0) ? 0 : (int)result->width - x, |
572 | (h_scale > 0) ? 0 : (int)result->width - x, |
526 | (v_scale > 0) ? 0 : (int)result->height - y, |
573 | (v_scale > 0) ? 0 : (int)result->height - y, |
527 | new_pmap_width, |
574 | new_pmap_width, |
528 | new_pmap_height, |
575 | new_pmap_height, |
529 | TINT_LEAVE_SAME, ASA_XImage, |
576 | TINT_LEAVE_SAME, ASA_XImage, |
530 | 100, ASIMAGE_QUALITY_DEFAULT); |
577 | 100, ASIMAGE_QUALITY_DEFAULT); |
531 | if (tmp) |
578 | if (tmp) |
532 | { |
579 | { |
533 | if (result != original_asim) |
580 | if (result != original_asim) |
534 | destroy_asimage (&result); |
581 | destroy_asimage (&result); |
|
|
582 | |
535 | result = tmp; |
583 | result = tmp; |
536 | } |
584 | } |
537 | } |
585 | } |
538 | } |
586 | } |
539 | else |
587 | else |
540 | { |
588 | { |
541 | /* if blending background and image - pixmap has to be sized same as target window */ |
589 | /* if blending background and image - pixmap has to be sized same as target window */ |
542 | ASImageLayer *layers = create_image_layers (2); |
590 | ASImageLayer *layers = create_image_layers (2); |
543 | ASImage *merged_im = NULL; |
|
|
544 | |
591 | |
545 | layers[0].im = background; |
592 | layers[0].im = background; |
546 | layers[0].clip_width = target_width; |
593 | layers[0].clip_width = target_width; |
547 | layers[0].clip_height = target_height; |
594 | layers[0].clip_height = target_height; |
548 | layers[0].tint = background_tint; |
595 | layers[0].tint = background_tint; |
549 | layers[1].im = result; |
596 | layers[1].im = result; |
|
|
597 | |
550 | if (w <= 0) |
598 | if (w <= 0) |
551 | { |
599 | { |
552 | /* tile horizontally */ |
600 | /* tile horizontally */ |
553 | while (x > 0) x -= (int)result->width; |
601 | while (x > 0) x -= (int)result->width; |
554 | layers[1].dst_x = x; |
602 | layers[1].dst_x = x; |
… | |
… | |
558 | { |
606 | { |
559 | /* clip horizontally */ |
607 | /* clip horizontally */ |
560 | layers[1].dst_x = x; |
608 | layers[1].dst_x = x; |
561 | layers[1].clip_width = result->width; |
609 | layers[1].clip_width = result->width; |
562 | } |
610 | } |
|
|
611 | |
563 | if (h <= 0) |
612 | if (h <= 0) |
564 | { |
613 | { |
565 | while (y > 0) y -= (int)result->height; |
614 | while (y > 0) y -= (int)result->height; |
566 | layers[1].dst_y = y; |
615 | layers[1].dst_y = y; |
567 | layers[1].clip_height = result->height + target_height; |
616 | layers[1].clip_height = result->height + target_height; |
… | |
… | |
569 | else |
618 | else |
570 | { |
619 | { |
571 | layers[1].dst_y = y; |
620 | layers[1].dst_y = y; |
572 | layers[1].clip_height = result->height; |
621 | layers[1].clip_height = result->height; |
573 | } |
622 | } |
|
|
623 | |
574 | if (target->rs[Rs_blendtype]) |
624 | if (target->rs[Rs_blendtype]) |
575 | { |
625 | { |
576 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
626 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
577 | if (layers[1].merge_scanlines == NULL) |
627 | if (layers[1].merge_scanlines == NULL) |
578 | layers[1].merge_scanlines = alphablend_scanlines; |
628 | layers[1].merge_scanlines = alphablend_scanlines; |
579 | } |
629 | } |
|
|
630 | |
580 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
631 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
581 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
632 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
633 | |
582 | if (tmp) |
634 | if (tmp) |
583 | { |
635 | { |
584 | if (result != original_asim) |
636 | if (result != original_asim) |
585 | destroy_asimage (&result); |
637 | destroy_asimage (&result); |
|
|
638 | |
586 | result = tmp; |
639 | result = tmp; |
587 | } |
640 | } |
|
|
641 | |
588 | free (layers); |
642 | free (layers); |
589 | } |
643 | } |
590 | } |
644 | } |
591 | TIMING_TEST_PRINT_RESULT (asim); |
645 | TIMING_TEST_PRINT_RESULT (asim); |
592 | |
646 | |
593 | if (pixmap) |
647 | bool ret = false; |
594 | { |
|
|
595 | if (result == NULL |
|
|
596 | || pmap_width != new_pmap_width |
|
|
597 | || pmap_height != new_pmap_height |
|
|
598 | || pmap_depth != target->depth) |
|
|
599 | { |
|
|
600 | XFreePixmap (target->dpy, pixmap); |
|
|
601 | pixmap = None; |
|
|
602 | } |
|
|
603 | } |
|
|
604 | |
648 | |
605 | if (result) |
649 | if (result) |
606 | { |
650 | { |
607 | XGCValues gcv; |
651 | XGCValues gcv; |
608 | GC gc; |
652 | GC gc; |
|
|
653 | |
|
|
654 | if (pixmap) |
|
|
655 | { |
|
|
656 | if (pmap_width != new_pmap_width |
|
|
657 | || pmap_height != new_pmap_height |
|
|
658 | || pmap_depth != target->depth) |
|
|
659 | { |
|
|
660 | XFreePixmap (target->dpy, pixmap); |
|
|
661 | pixmap = None; |
|
|
662 | } |
|
|
663 | } |
609 | |
664 | |
610 | /* create Pixmap */ |
665 | /* create Pixmap */ |
611 | if (pixmap == None) |
666 | if (pixmap == None) |
612 | { |
667 | { |
613 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
668 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
614 | pmap_width = new_pmap_width; |
669 | pmap_width = new_pmap_width; |
615 | pmap_height = new_pmap_height; |
670 | pmap_height = new_pmap_height; |
616 | pmap_depth = target->depth; |
671 | pmap_depth = target->depth; |
617 | } |
672 | } |
618 | /* fill with background color ( if result's not completely overlapping it)*/ |
673 | /* fill with background color (if result's not completely overlapping it) */ |
619 | gcv.foreground = target->pix_colors[Color_bg]; |
674 | gcv.foreground = target->pix_colors[Color_bg]; |
620 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
675 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
621 | |
676 | |
622 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
677 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
623 | int dst_width = result->width, dst_height = result->height; |
678 | int dst_width = result->width, dst_height = result->height; |
624 | if (background == NULL) |
679 | if (background == NULL) |
625 | { |
680 | { |
626 | if (h_scale > 0) |
|
|
627 | src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); |
681 | if (h_scale > 0) src_x = make_clip_rectangle (x, result->width , new_pmap_width , dst_x, dst_width ); |
628 | if (v_scale > 0) |
|
|
629 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
682 | if (v_scale > 0) src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
630 | |
683 | |
631 | if (dst_x > 0 || dst_y > 0 |
684 | if (dst_x > 0 || dst_y > 0 |
632 | || dst_x + dst_width < new_pmap_width |
685 | || dst_x + dst_width < new_pmap_width |
633 | || dst_y + dst_height < new_pmap_height) |
686 | || dst_y + dst_height < new_pmap_height) |
634 | { |
|
|
635 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
687 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
636 | } |
|
|
637 | } |
688 | } |
638 | |
689 | |
639 | /* put result on pixmap */ |
690 | /* put result on pixmap */ |
640 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
691 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
641 | asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
692 | asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
… | |
… | |
643 | if (result != background && result != original_asim) |
694 | if (result != background && result != original_asim) |
644 | destroy_asimage (&result); |
695 | destroy_asimage (&result); |
645 | |
696 | |
646 | XFreeGC (target->dpy, gc); |
697 | XFreeGC (target->dpy, gc); |
647 | TIMING_TEST_PRINT_RESULT (asim); |
698 | TIMING_TEST_PRINT_RESULT (asim); |
648 | } |
|
|
649 | |
699 | |
|
|
700 | ret = true; |
|
|
701 | } |
|
|
702 | |
|
|
703 | if (background) |
|
|
704 | destroy_asimage (&background); |
|
|
705 | |
650 | return true; |
706 | return ret; |
651 | } |
707 | } |
652 | # endif /* HAVE_AFTERIMAGE */ |
708 | # endif /* HAVE_AFTERIMAGE */ |
653 | |
709 | |
654 | bool |
710 | bool |
655 | bgPixmap_t::set_file (const char *file) |
711 | bgPixmap_t::set_file (const char *file) |
656 | { |
712 | { |
657 | char *f; |
|
|
658 | |
|
|
659 | assert (file != NULL); |
713 | assert (file); |
660 | |
714 | |
661 | if (*file != '\0') |
715 | if (*file) |
662 | { |
716 | { |
|
|
717 | if (const char *p = strchr (file, ';')) |
|
|
718 | { |
|
|
719 | size_t len = p - file; |
|
|
720 | char *f = rxvt_temp_buf<char> (len + 1); |
|
|
721 | memcpy (f, file, len); |
|
|
722 | f[len] = '\0'; |
|
|
723 | file = f; |
|
|
724 | } |
|
|
725 | |
663 | # ifdef HAVE_AFTERIMAGE |
726 | # ifdef HAVE_AFTERIMAGE |
664 | if (target->asimman == NULL) |
727 | if (!target->asimman) |
665 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
728 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
666 | if ((f = strchr (file, ';')) == NULL) |
|
|
667 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
729 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
668 | else |
730 | if (original_asim) |
669 | { |
731 | have_image = true; |
670 | size_t len = f - file; |
732 | return have_image; |
671 | f = (char *)malloc (len + 1); |
|
|
672 | strncpy (f, file, len); |
|
|
673 | f[len] = '\0'; |
|
|
674 | original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); |
|
|
675 | free (f); |
|
|
676 | } |
|
|
677 | return (original_asim != NULL); |
|
|
678 | # endif |
733 | # endif |
679 | } |
734 | } |
|
|
735 | |
680 | return false; |
736 | return false; |
681 | } |
737 | } |
682 | |
738 | |
683 | # endif /* BG_IMAGE_FROM_FILE */ |
739 | # endif /* BG_IMAGE_FROM_FILE */ |
684 | |
740 | |
… | |
… | |
689 | if (!(flags & isTransparent)) |
745 | if (!(flags & isTransparent)) |
690 | { |
746 | { |
691 | flags |= isTransparent; |
747 | flags |= isTransparent; |
692 | return true; |
748 | return true; |
693 | } |
749 | } |
|
|
750 | |
694 | return false; |
751 | return false; |
695 | } |
752 | } |
696 | |
753 | |
697 | bool |
754 | bool |
698 | bgPixmap_t::set_blur_radius (const char *geom) |
755 | bgPixmap_t::set_blur_radius (const char *geom) |
… | |
… | |
700 | int changed = 0; |
757 | int changed = 0; |
701 | unsigned int hr, vr; |
758 | unsigned int hr, vr; |
702 | int junk; |
759 | int junk; |
703 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
760 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
704 | |
761 | |
705 | if (!(geom_flags&WidthValue)) |
762 | if (!(geom_flags & WidthValue)) |
706 | hr = 1; |
763 | hr = 1; |
707 | if (!(geom_flags&HeightValue)) |
764 | if (!(geom_flags & HeightValue)) |
708 | vr = hr; |
765 | vr = hr; |
709 | |
766 | |
710 | if (h_blurRadius != hr) |
767 | if (h_blurRadius != hr) |
711 | { |
768 | { |
712 | ++changed; |
769 | ++changed; |
… | |
… | |
722 | if (v_blurRadius == 0 && h_blurRadius == 0) |
779 | if (v_blurRadius == 0 && h_blurRadius == 0) |
723 | flags &= ~blurNeeded; |
780 | flags &= ~blurNeeded; |
724 | else |
781 | else |
725 | flags |= blurNeeded; |
782 | flags |= blurNeeded; |
726 | |
783 | |
727 | return (changed>0); |
784 | return (changed > 0); |
728 | } |
785 | } |
729 | |
786 | |
730 | static inline unsigned long |
787 | static inline unsigned long |
731 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
788 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
732 | { |
789 | { |
… | |
… | |
749 | flags |= bgPixmap_t::tintNeeded; |
806 | flags |= bgPixmap_t::tintNeeded; |
750 | else if (tint) |
807 | else if (tint) |
751 | { |
808 | { |
752 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
809 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
753 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
810 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
754 | { |
811 | { |
755 | flags |= bgPixmap_t::tintNeeded; |
812 | flags |= bgPixmap_t::tintNeeded; |
756 | } |
813 | } |
757 | } |
814 | } |
758 | |
815 | |
759 | if (flags & bgPixmap_t::tintNeeded) |
816 | if (flags & bgPixmap_t::tintNeeded) |
760 | { |
817 | { |
761 | if (flags & bgPixmap_t::tintWholesome) |
818 | if (flags & bgPixmap_t::tintWholesome) |
… | |
… | |
779 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
836 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
780 | tint = new_tint; |
837 | tint = new_tint; |
781 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
838 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
782 | return true; |
839 | return true; |
783 | } |
840 | } |
|
|
841 | |
784 | return false; |
842 | return false; |
785 | } |
843 | } |
786 | |
844 | |
787 | bool |
845 | bool |
788 | bgPixmap_t::unset_tint () |
846 | bgPixmap_t::unset_tint () |
789 | { |
847 | { |
790 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
848 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
791 | |
849 | |
792 | if (new_flags != (flags & tintFlags)) |
850 | if (new_flags != (flags & tintFlags)) |
793 | { |
851 | { |
794 | flags = (flags&~tintFlags)|new_flags; |
852 | flags = (flags & ~tintFlags) | new_flags; |
795 | return true; |
853 | return true; |
796 | } |
854 | } |
|
|
855 | |
797 | return false; |
856 | return false; |
798 | } |
857 | } |
799 | |
858 | |
800 | bool |
859 | bool |
801 | bgPixmap_t::set_shade (const char *shade_str) |
860 | bgPixmap_t::set_shade (const char *shade_str) |
802 | { |
861 | { |
803 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
862 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
804 | |
863 | |
805 | if (new_shade < 0 && new_shade > -100) |
864 | if (new_shade < 0 && new_shade > -100) |
806 | new_shade = 200 - (100 + new_shade); |
865 | new_shade = 200 - (100 + new_shade); |
807 | else if (new_shade == 100) |
866 | else if (new_shade == 100) |
808 | new_shade = 0; |
867 | new_shade = 0; |
809 | |
868 | |
810 | if (new_shade != shade) |
869 | if (new_shade != shade) |
811 | { |
870 | { |
812 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
871 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
813 | shade = new_shade; |
872 | shade = new_shade; |
814 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
873 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
815 | return true; |
874 | return true; |
816 | } |
875 | } |
|
|
876 | |
817 | return false; |
877 | return false; |
818 | } |
878 | } |
819 | |
879 | |
820 | /* make_transparency_pixmap() |
880 | /* make_transparency_pixmap() |
821 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
881 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
… | |
… | |
828 | unsigned long result = 0; |
888 | unsigned long result = 0; |
829 | |
889 | |
830 | if (target == NULL) |
890 | if (target == NULL) |
831 | return 0; |
891 | return 0; |
832 | |
892 | |
833 | /* root dimentions may change from call to call - but Display structure should |
893 | /* root dimensions may change from call to call - but Display structure should |
834 | * be always up-to-date, so let's use it : |
894 | * be always up-to-date, so let's use it : |
835 | */ |
895 | */ |
836 | Window root = target->display->root; |
896 | Window root = target->display->root; |
837 | int screen = target->display->screen; |
897 | int screen = target->display->screen; |
838 | Display *dpy = target->dpy; |
898 | Display *dpy = target->dpy; |
… | |
… | |
883 | |
943 | |
884 | attr.background_pixmap = ParentRelative; |
944 | attr.background_pixmap = ParentRelative; |
885 | attr.backing_store = Always; |
945 | attr.backing_store = Always; |
886 | attr.event_mask = ExposureMask; |
946 | attr.event_mask = ExposureMask; |
887 | attr.override_redirect = True; |
947 | attr.override_redirect = True; |
888 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
948 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
889 | CopyFromParent, CopyFromParent, CopyFromParent, |
949 | CopyFromParent, CopyFromParent, CopyFromParent, |
890 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
950 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
891 | &attr); |
951 | &attr); |
892 | |
952 | |
893 | if (src != None) |
953 | if (src != None) |
… | |
… | |
897 | XGrabServer (dpy); |
957 | XGrabServer (dpy); |
898 | XMapRaised (dpy, src); |
958 | XMapRaised (dpy, src); |
899 | XSync (dpy, False); |
959 | XSync (dpy, False); |
900 | |
960 | |
901 | /* XSync should get window where it's properly exposed, |
961 | /* XSync should get window where it's properly exposed, |
902 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
962 | * but to be on the safe side - let's check for the actual event to arrive : */ |
903 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
963 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
904 | ++ev_count; |
964 | ++ev_count; |
905 | |
965 | |
906 | if (ev_count > 0); |
966 | if (ev_count > 0); |
907 | { |
967 | { |
… | |
… | |
911 | { |
971 | { |
912 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
972 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
913 | success = true; |
973 | success = true; |
914 | } |
974 | } |
915 | } |
975 | } |
|
|
976 | |
916 | XDestroyWindow (dpy, src); |
977 | XDestroyWindow (dpy, src); |
917 | XUngrabServer (dpy); |
978 | XUngrabServer (dpy); |
918 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
979 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
919 | } |
980 | } |
920 | |
981 | |
921 | if (!success) |
982 | if (!success) |
922 | { |
983 | { |
923 | XFreePixmap (dpy, tiled_root_pmap); |
984 | XFreePixmap (dpy, tiled_root_pmap); |
924 | tiled_root_pmap = None; |
985 | tiled_root_pmap = None; |
925 | } |
986 | } |
926 | else |
987 | else |
927 | result |= transpPmapTiled; |
988 | result |= transpPmapTiled; |
928 | } |
989 | } |
929 | else |
990 | else |
930 | { |
991 | { |
931 | /* strightforward pixmap copy */ |
992 | /* straightforward pixmap copy */ |
932 | gcv.tile = root_pixmap; |
993 | gcv.tile = root_pixmap; |
933 | gcv.fill_style = FillTiled; |
994 | gcv.fill_style = FillTiled; |
934 | |
995 | |
935 | while (sx < 0) sx += (int)root_width; |
996 | while (sx < 0) sx += (int)root_width; |
936 | while (sy < 0) sy += (int)root_height; |
997 | while (sy < 0) sy += (int)root_height; |
… | |
… | |
1040 | mask_c.blue = 0xffff - c.b; |
1101 | mask_c.blue = 0xffff - c.b; |
1041 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1102 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1042 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
1103 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
1043 | result |= transpPmapTinted; |
1104 | result |= transpPmapTinted; |
1044 | } |
1105 | } |
|
|
1106 | |
1045 | XRenderFreePicture (dpy, mask_pic); |
1107 | XRenderFreePicture (dpy, mask_pic); |
1046 | XRenderFreePicture (dpy, overlay_pic); |
1108 | XRenderFreePicture (dpy, overlay_pic); |
1047 | XRenderFreePicture (dpy, back_pic); |
1109 | XRenderFreePicture (dpy, back_pic); |
1048 | # if DO_TIMING_TEST |
1110 | # if DO_TIMING_TEST |
1049 | XSync (dpy, False); |
1111 | XSync (dpy, False); |
1050 | # endif |
1112 | # endif |
1051 | # endif |
1113 | # endif |
1052 | } |
1114 | } |
1053 | } |
1115 | } |
1054 | } /* server side rendering completed */ |
1116 | } /* server side rendering completed */ |
1055 | |
1117 | |
1056 | if (pixmap) |
1118 | if (pixmap) |
1057 | XFreePixmap (dpy, pixmap); |
1119 | XFreePixmap (dpy, pixmap); |
1058 | |
1120 | |
… | |
… | |
1071 | } |
1133 | } |
1072 | |
1134 | |
1073 | bool |
1135 | bool |
1074 | bgPixmap_t::set_root_pixmap () |
1136 | bgPixmap_t::set_root_pixmap () |
1075 | { |
1137 | { |
1076 | Pixmap new_root_pixmap = None; |
|
|
1077 | |
|
|
1078 | new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1138 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1079 | if (new_root_pixmap == None) |
1139 | if (new_root_pixmap == None) |
1080 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1140 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1081 | |
1141 | |
1082 | if (new_root_pixmap != root_pixmap) |
1142 | if (new_root_pixmap != root_pixmap) |
1083 | { |
1143 | { |
1084 | root_pixmap = new_root_pixmap; |
1144 | root_pixmap = new_root_pixmap; |
1085 | return true; |
1145 | return true; |
1086 | } |
1146 | } |
|
|
1147 | |
1087 | return false; |
1148 | return false; |
1088 | } |
1149 | } |
1089 | # endif /* ENABLE_TRANSPARENCY */ |
1150 | # endif /* ENABLE_TRANSPARENCY */ |
1090 | |
1151 | |
1091 | # ifndef HAVE_AFTERIMAGE |
1152 | # ifndef HAVE_AFTERIMAGE |
1092 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1153 | static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); |
1093 | # endif |
1154 | # endif |
1094 | |
|
|
1095 | |
1155 | |
1096 | bool |
1156 | bool |
1097 | bgPixmap_t::render () |
1157 | bgPixmap_t::render () |
1098 | { |
1158 | { |
1099 | unsigned long background_flags = 0; |
1159 | unsigned long background_flags = 0; |
… | |
… | |
1101 | if (target == NULL) |
1161 | if (target == NULL) |
1102 | return false; |
1162 | return false; |
1103 | |
1163 | |
1104 | TIMING_TEST_START (tp); |
1164 | TIMING_TEST_START (tp); |
1105 | |
1165 | |
1106 | invalidate(); |
1166 | invalidate (); |
1107 | # ifdef ENABLE_TRANSPARENCY |
1167 | # ifdef ENABLE_TRANSPARENCY |
1108 | if (flags & isTransparent) |
1168 | if (flags & isTransparent) |
1109 | { |
1169 | { |
1110 | /* we need to re-generate transparency pixmap in that case ! */ |
1170 | /* we need to re-generate transparency pixmap in that case ! */ |
1111 | background_flags = make_transparency_pixmap (); |
1171 | background_flags = make_transparency_pixmap (); |
1112 | if (background_flags == 0) |
1172 | if (background_flags == 0) |
1113 | return false; |
1173 | return false; |
1114 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1174 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1115 | && pmap_depth == target->depth) |
1175 | && pmap_depth == target->depth) |
1116 | flags = flags & ~isInvalid; |
1176 | flags = flags & ~isInvalid; |
1117 | } |
1177 | } |
1118 | # endif |
1178 | # endif |
1119 | |
1179 | |
|
|
1180 | # ifdef BG_IMAGE_FROM_FILE |
|
|
1181 | if (have_image |
|
|
1182 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
|
|
1183 | { |
|
|
1184 | if (render_image (background_flags)) |
|
|
1185 | flags = flags & ~isInvalid; |
|
|
1186 | } |
|
|
1187 | # endif |
|
|
1188 | |
1120 | XImage *result = NULL; |
1189 | XImage *result = NULL; |
1121 | # ifdef HAVE_AFTERIMAGE |
|
|
1122 | if (original_asim |
|
|
1123 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
|
|
1124 | { |
|
|
1125 | ASImage *background = NULL; |
|
|
1126 | ARGB32 as_tint = TINT_LEAVE_SAME; |
|
|
1127 | if (background_flags) |
|
|
1128 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
1129 | |
1190 | |
1130 | # ifdef ENABLE_TRANSPARENCY |
1191 | if (background_flags && (flags & isInvalid)) |
1131 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
1132 | { |
|
|
1133 | ShadingInfo as_shade; |
|
|
1134 | as_shade.shading = (shade == 0) ? 100 : shade; |
|
|
1135 | |
|
|
1136 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1137 | if (flags & tintSet) |
|
|
1138 | tint.get (c); |
|
|
1139 | as_shade.tintColor.red = c.r; |
|
|
1140 | as_shade.tintColor.green = c.g; |
|
|
1141 | as_shade.tintColor.blue = c.b; |
|
|
1142 | |
|
|
1143 | as_tint = shading2tint32 (&as_shade); |
|
|
1144 | } |
|
|
1145 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
|
|
1146 | { |
|
|
1147 | ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
1148 | (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, |
|
|
1149 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1150 | if (tmp) |
|
|
1151 | { |
|
|
1152 | destroy_asimage (&background); |
|
|
1153 | background = tmp; |
|
|
1154 | } |
|
|
1155 | } |
|
|
1156 | # endif |
|
|
1157 | |
|
|
1158 | if (render_asim (background, as_tint)) |
|
|
1159 | flags = flags & ~isInvalid; |
|
|
1160 | if (background) |
|
|
1161 | destroy_asimage (&background); |
|
|
1162 | } |
|
|
1163 | else if (background_flags && pmap_depth != target->depth) |
|
|
1164 | { |
1192 | { |
1165 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1193 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1166 | } |
|
|
1167 | |
1194 | |
|
|
1195 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
1168 | # elif !XFT /* our own client-side tinting */ |
1196 | /* our own client-side tinting */ |
1169 | |
|
|
1170 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side. |
1197 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
1171 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1198 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1172 | |
|
|
1173 | if (background_flags && (flags & isInvalid)) |
|
|
1174 | { |
|
|
1175 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
1176 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1199 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1177 | { |
1200 | { |
1178 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1201 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1179 | if (flags & tintSet) |
1202 | if (flags & tintSet) |
1180 | tint.get (c); |
1203 | tint.get (c); |
1181 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1204 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1182 | } |
1205 | } |
|
|
1206 | # endif |
1183 | } |
1207 | } |
1184 | # endif /* HAVE_AFTERIMAGE */ |
|
|
1185 | |
1208 | |
1186 | if (result != NULL) |
1209 | if (result) |
1187 | { |
1210 | { |
1188 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1211 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
|
|
1212 | |
1189 | if (gc) |
1213 | if (gc) |
1190 | { |
1214 | { |
1191 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1215 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1192 | { |
1216 | { |
1193 | XFreePixmap (target->dpy, pixmap); |
1217 | XFreePixmap (target->dpy, pixmap); |
1194 | pixmap = None; |
1218 | pixmap = None; |
1195 | } |
1219 | } |
|
|
1220 | |
1196 | if (pixmap == None) |
1221 | if (pixmap == None) |
1197 | { |
1222 | { |
1198 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1223 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1199 | pmap_width = result->width; |
1224 | pmap_width = result->width; |
1200 | pmap_height = result->height; |
1225 | pmap_height = result->height; |
1201 | pmap_depth = target->depth; |
1226 | pmap_depth = target->depth; |
1202 | } |
1227 | } |
|
|
1228 | |
1203 | if (pmap_depth != result->depth) |
1229 | if (pmap_depth != result->depth) |
1204 | { |
1230 | { |
1205 | /* Bad Match error will ensue ! stupid X !!!! */ |
1231 | /* Bad Match error will ensue ! stupid X !!!! */ |
1206 | if (result->depth == 24 && pmap_depth == 32) |
1232 | if (result->depth == 24 && pmap_depth == 32) |
1207 | result->depth = 32; |
1233 | result->depth = 32; |
… | |
… | |
1210 | else |
1236 | else |
1211 | { |
1237 | { |
1212 | /* TODO: implement image recoding */ |
1238 | /* TODO: implement image recoding */ |
1213 | } |
1239 | } |
1214 | } |
1240 | } |
|
|
1241 | |
1215 | if (pmap_depth == result->depth) |
1242 | if (pmap_depth == result->depth) |
1216 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1243 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
1244 | |
1217 | XFreeGC (target->dpy, gc); |
1245 | XFreeGC (target->dpy, gc); |
1218 | flags = flags & ~isInvalid; |
1246 | flags = flags & ~isInvalid; |
1219 | } |
1247 | } |
|
|
1248 | |
1220 | XDestroyImage (result); |
1249 | XDestroyImage (result); |
1221 | } |
1250 | } |
1222 | |
1251 | |
1223 | if (flags & isInvalid) |
1252 | if (flags & isInvalid) |
1224 | { |
1253 | { |
1225 | if (pixmap != None) |
1254 | if (pixmap != None) |
… | |
… | |
1228 | pixmap = None; |
1257 | pixmap = None; |
1229 | } |
1258 | } |
1230 | } |
1259 | } |
1231 | |
1260 | |
1232 | apply (); |
1261 | apply (); |
|
|
1262 | |
|
|
1263 | XSync (target->dpy, False); |
|
|
1264 | valid_since = ev::now (); |
1233 | |
1265 | |
1234 | TIMING_TEST_PRINT_RESULT (tp); |
1266 | TIMING_TEST_PRINT_RESULT (tp); |
1235 | |
1267 | |
1236 | return true; |
1268 | return true; |
1237 | } |
1269 | } |
… | |
… | |
1246 | # ifdef ENABLE_TRANSPARENCY |
1278 | # ifdef ENABLE_TRANSPARENCY |
1247 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1279 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1248 | # endif |
1280 | # endif |
1249 | return true; |
1281 | return true; |
1250 | } |
1282 | } |
|
|
1283 | |
1251 | return false; |
1284 | return false; |
1252 | } |
1285 | } |
1253 | |
1286 | |
1254 | void |
1287 | void |
1255 | bgPixmap_t::apply() |
1288 | bgPixmap_t::apply () |
1256 | { |
1289 | { |
1257 | if (target) |
1290 | if (target) |
1258 | { |
1291 | { |
1259 | flags &= ~isVtOrigin; |
1292 | flags &= ~isVtOrigin; |
|
|
1293 | |
1260 | if (pixmap != None) |
1294 | if (pixmap != None) |
1261 | { |
1295 | { |
1262 | /* set target's background to pixmap */ |
1296 | /* set target's background to pixmap */ |
1263 | # ifdef ENABLE_TRANSPARENCY |
1297 | # ifdef ENABLE_TRANSPARENCY |
1264 | if (flags & isTransparent) |
1298 | if (flags & isTransparent) |
1265 | { |
1299 | { |
1266 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1300 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1267 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1301 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1268 | # if HAVE_SCROLLBARS |
1302 | |
1269 | if (target->scrollBar.win) |
1303 | if (target->scrollBar.win) |
1270 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1304 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1271 | # endif |
|
|
1272 | } |
1305 | } |
1273 | else |
1306 | else |
1274 | # endif |
1307 | # endif |
1275 | { |
1308 | { |
1276 | flags |= isVtOrigin; |
1309 | flags |= isVtOrigin; |
1277 | /* force old pixmap dereference in case it was transparent before :*/ |
1310 | /* force old pixmap dereference in case it was transparent before :*/ |
1278 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1311 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1279 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1312 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1280 | /* do we also need to set scrollbar's background here ? */ |
1313 | /* do we also need to set scrollbar's background here ? */ |
1281 | # if HAVE_SCROLLBARS |
1314 | |
1282 | if (target->scrollBar.win) |
1315 | if (target->scrollBar.win) |
1283 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1316 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1284 | # endif |
|
|
1285 | } |
1317 | } |
1286 | } |
1318 | } |
1287 | else |
1319 | else |
1288 | { |
1320 | { |
1289 | /* set target background to a pixel */ |
1321 | /* set target background to a pixel */ |
1290 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1322 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1291 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1323 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1292 | /* do we also need to set scrollbar's background here ? */ |
1324 | /* do we also need to set scrollbar's background here ? */ |
1293 | # if HAVE_SCROLLBARS |
|
|
1294 | if (target->scrollBar.win) |
1325 | if (target->scrollBar.win) |
1295 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1326 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1296 | # endif |
|
|
1297 | } |
1327 | } |
|
|
1328 | |
1298 | /* don't want Expose on the parent or vt. It is better to use |
1329 | /* don't want Expose on the parent or vt. It is better to use |
1299 | scr_touch or we get a great deal of flicker otherwise: */ |
1330 | scr_touch or we get a great deal of flicker otherwise: */ |
1300 | XClearWindow (target->dpy, target->parent[0]); |
1331 | XClearWindow (target->dpy, target->parent[0]); |
1301 | |
1332 | |
1302 | # if HAVE_SCROLLBARS |
1333 | if (target->scrollBar.state && target->scrollBar.win) |
1303 | if (target->scrollBar.win) |
|
|
1304 | { |
1334 | { |
1305 | target->scrollBar.setIdle (); |
1335 | target->scrollBar.state = STATE_IDLE; |
1306 | target->scrollbar_show (0); |
1336 | target->scrollBar.show (0); |
1307 | } |
1337 | } |
1308 | # endif |
|
|
1309 | |
1338 | |
1310 | target->want_refresh = 1; |
1339 | target->want_refresh = 1; |
1311 | flags |= hasChanged; |
1340 | flags |= hasChanged; |
1312 | } |
1341 | } |
1313 | } |
1342 | } |
… | |
… | |
1318 | /* taken from aterm-0.4.2 */ |
1347 | /* taken from aterm-0.4.2 */ |
1319 | |
1348 | |
1320 | typedef uint32_t RUINT32T; |
1349 | typedef uint32_t RUINT32T; |
1321 | |
1350 | |
1322 | static void |
1351 | static void |
1323 | ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) |
1352 | ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) |
1324 | { |
1353 | { |
1325 | int sh_r, sh_g, sh_b; |
1354 | int sh_r, sh_g, sh_b; |
1326 | RUINT32T mask_r, mask_g, mask_b; |
1355 | RUINT32T mask_r, mask_g, mask_b; |
1327 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1356 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1328 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1357 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |