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 |
… | |
… | |
19 | * You should have received a copy of the GNU General Public License |
19 | * You should have received a copy of the GNU General Public License |
20 | * along with this program; if not, write to the Free Software |
20 | * along with this program; if not, write to the Free Software |
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
22 | *---------------------------------------------------------------------*/ |
22 | *---------------------------------------------------------------------*/ |
23 | |
23 | |
|
|
24 | #include <cmath> |
24 | #include "../config.h" /* NECESSARY */ |
25 | #include "../config.h" /* NECESSARY */ |
25 | #include "rxvt.h" /* NECESSARY */ |
26 | #include "rxvt.h" /* NECESSARY */ |
26 | |
27 | |
27 | #define DO_TIMING_TEST 0 |
28 | #define DO_TIMING_TEST 0 |
28 | |
29 | |
29 | #if DO_TIMING_TEST |
30 | #if DO_TIMING_TEST |
30 | # include <sys/time.h> |
31 | # include <sys/time.h> |
31 | #define TIMING_TEST_START(id) \ |
32 | #define TIMING_TEST_START(id) \ |
32 | struct timeval timing_test_##id##_stv;\ |
33 | struct timeval timing_test_##id##_stv; \ |
33 | gettimeofday (&timing_test_##id##_stv, NULL); |
34 | gettimeofday (&timing_test_##id##_stv, NULL); |
34 | |
35 | |
35 | #define TIMING_TEST_PRINT_RESULT(id) \ |
36 | #define TIMING_TEST_PRINT_RESULT(id) \ |
36 | do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ |
37 | do { \ |
|
|
38 | struct timeval tv; \ |
|
|
39 | gettimeofday (&tv, NULL); \ |
|
|
40 | tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \ |
37 | fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ |
41 | 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) |
42 | tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \ |
|
|
43 | } while (0) |
39 | |
44 | |
40 | #else |
45 | #else |
41 | #define TIMING_TEST_START(id) do{}while (0) |
46 | #define TIMING_TEST_START(id) do {} while (0) |
42 | #define TIMING_TEST_PRINT_RESULT(id) do{}while (0) |
47 | #define TIMING_TEST_PRINT_RESULT(id) do {} while (0) |
43 | #endif |
48 | #endif |
44 | |
49 | |
45 | /* |
50 | /* |
46 | * Pixmap geometry string interpretation : |
51 | * Pixmap geometry string interpretation : |
47 | * Each geometry string contains zero or one scale/position |
52 | * Each geometry string contains zero or one scale/position |
48 | * adjustment and may optionally be followed by a colon and one or more |
53 | * adjustment and may optionally be followed by a colon and one or more |
49 | * colon-delimited pixmap operations. |
54 | * colon-delimited pixmap operations. |
50 | * The following table shows the valid geometry strings and their |
55 | * The following table shows the valid geometry strings and their |
51 | * affects on the background image : |
56 | * effects on the background image : |
52 | * |
57 | * |
53 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
58 | * 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. |
59 | * W and H are percentages of the terminal window size. |
55 | * X and Y are also percentages; e.g., +50+50 centers |
60 | * X and Y are also percentages; e.g., +50+50 centers |
56 | * the image in the window. |
61 | * the image in the window. |
57 | * WxH+X Assumes Y == X |
62 | * WxH+X Assumes Y == X |
58 | * WxH Assumes Y == X == 50 (centers the image) |
63 | * WxH Assumes Y == X == 50 (centers the image) |
59 | * W+X+Y Assumes H == W |
64 | * W+X+Y Assumes H == W |
60 | * W+X Assumes H == W and Y == X |
65 | * W+X Assumes H == W and Y == X |
61 | * W Assumes H == W and Y == X == 50 |
66 | * W Assumes H == W and Y == X == 50 |
62 | * |
67 | * |
63 | * Adjusting position only : |
68 | * Adjusting position only : |
64 | * =+X+Y Set position to X% by Y% (absolute). |
69 | * =+X+Y Set position to X% by Y% (absolute). |
65 | * =+X Set position to X% by X%. |
70 | * =+X Set position to X% by X%. |
66 | * +X+Y Adjust position horizontally X% and vertically Y% |
71 | * +X+Y Adjust position horizontally X% and vertically Y% |
67 | * from current position (relative). |
72 | * from current position (relative). |
68 | * +X Adjust position horizontally X% and vertically X% |
73 | * +X Adjust position horizontally X% and vertically X% |
69 | * from current position. |
74 | * from current position. |
70 | * |
75 | * |
71 | * Adjusting scale only : |
76 | * Adjusting scale only : |
72 | * Wx0 Multiply horizontal scaling factor by W% |
77 | * Wx0 Multiply horizontal scaling factor by W% |
73 | * 0xH Multiply vertical scaling factor by H% |
78 | * 0xH Multiply vertical scaling factor by H% |
74 | * 0x0 No scaling (show image at normal size). |
79 | * 0x0 No scaling (show image at normal size). |
75 | * |
80 | * |
76 | * Pixmap Operations : (should be prepended by a colon) |
81 | * Pixmap Operations : (should be prepended by a colon) |
77 | * tile Tile image. Scaling/position modifiers above will affect |
82 | * tile Tile image. Scaling/position modifiers above will affect |
78 | * the tile size and origin. |
83 | * the tile size and origin. |
79 | * propscale When scaling, scale proportionally. That is, maintain the |
84 | * propscale When scaling, scale proportionally. That is, maintain the |
80 | * proper aspect ratio for the image. Any portion of the |
85 | * proper aspect ratio for the image. Any portion of the |
81 | * background not covered by the image is filled with the |
86 | * background not covered by the image is filled with the |
82 | * current background color. |
87 | * current background color. |
83 | * hscale Scale horizontally, tile vertically ? |
88 | * hscale Scale horizontally, tile vertically ? |
84 | * vscale Tile horizontally, scale vertically ? |
89 | * vscale Tile horizontally, scale vertically ? |
… | |
… | |
87 | */ |
92 | */ |
88 | |
93 | |
89 | #ifdef HAVE_BG_PIXMAP |
94 | #ifdef HAVE_BG_PIXMAP |
90 | bgPixmap_t::bgPixmap_t () |
95 | bgPixmap_t::bgPixmap_t () |
91 | { |
96 | { |
|
|
97 | // this is basically redundant as bgPixmap_t is only used in |
|
|
98 | // zero_initialised-derived structs |
92 | #ifdef HAVE_AFTERIMAGE |
99 | #ifdef HAVE_AFTERIMAGE |
93 | original_asim = NULL; |
100 | original_asim = NULL; |
94 | #endif |
101 | #endif |
|
|
102 | #ifdef HAVE_PIXBUF |
|
|
103 | pixbuf = NULL; |
|
|
104 | #endif |
95 | #ifdef BG_IMAGE_FROM_FILE |
105 | #ifdef BG_IMAGE_FROM_FILE |
|
|
106 | have_image = false; |
96 | h_scale = v_scale = 0; |
107 | h_scale = v_scale = 0; |
97 | h_align = v_align = 0; |
108 | h_align = v_align = 0; |
98 | #endif |
109 | #endif |
|
|
110 | #ifdef ENABLE_TRANSPARENCY |
|
|
111 | shade = 100; |
|
|
112 | #endif |
99 | flags = 0; |
113 | flags = 0; |
100 | pixmap = None; |
114 | pixmap = None; |
|
|
115 | valid_since = invalid_since = 0; |
|
|
116 | target = 0; |
101 | } |
117 | } |
102 | |
118 | |
103 | void |
119 | void |
104 | bgPixmap_t::destroy () |
120 | bgPixmap_t::destroy () |
105 | { |
121 | { |
106 | #ifdef HAVE_AFTERIMAGE |
122 | #ifdef HAVE_AFTERIMAGE |
107 | if (original_asim) |
123 | if (original_asim) |
108 | safe_asimage_destroy (original_asim); |
124 | safe_asimage_destroy (original_asim); |
109 | #endif |
125 | #endif |
110 | |
126 | |
|
|
127 | #ifdef HAVE_PIXBUF |
|
|
128 | if (pixbuf) |
|
|
129 | g_object_unref (pixbuf); |
|
|
130 | #endif |
|
|
131 | |
111 | if (pixmap && target) |
132 | if (pixmap && target) |
112 | XFreePixmap (target->dpy, pixmap); |
133 | XFreePixmap (target->dpy, pixmap); |
113 | } |
134 | } |
114 | |
135 | |
115 | bool |
136 | bool |
… | |
… | |
119 | if (flags & isTransparent) |
140 | if (flags & isTransparent) |
120 | return true; |
141 | return true; |
121 | # endif |
142 | # endif |
122 | |
143 | |
123 | # ifdef BG_IMAGE_FROM_FILE |
144 | # ifdef BG_IMAGE_FROM_FILE |
124 | # ifdef HAVE_AFTERIMAGE |
145 | if (have_image) |
125 | if (original_asim != NULL) |
|
|
126 | # endif |
|
|
127 | { |
146 | { |
128 | if (h_scale != 0 || v_scale != 0 |
147 | if (flags & sizeSensitive) |
129 | || h_align != 0 || v_align != 0) |
|
|
130 | return true; |
148 | return true; |
131 | } |
149 | } |
132 | # endif |
150 | # endif |
133 | |
151 | |
134 | return false; |
152 | return false; |
135 | } |
153 | } |
136 | |
154 | |
137 | bool |
155 | bool |
138 | bgPixmap_t::window_position_sensitive () |
156 | bgPixmap_t::window_position_sensitive () |
139 | { |
157 | { |
140 | # ifdef ENABLE_TRANSPARENCY |
158 | # ifdef ENABLE_TRANSPARENCY |
141 | if (flags & isTransparent) |
159 | if (flags & isTransparent) |
142 | return true; |
160 | return true; |
143 | # endif |
161 | # endif |
144 | |
162 | |
145 | # ifdef BG_IMAGE_FROM_FILE |
163 | # ifdef BG_IMAGE_FROM_FILE |
146 | # ifdef HAVE_AFTERIMAGE |
164 | if (have_image) |
147 | if (original_asim != NULL) |
|
|
148 | # endif |
|
|
149 | { |
165 | { |
150 | if (h_align == rootAlign || v_align == rootAlign) |
166 | if (flags & rootAlign) |
151 | return true; |
167 | return true; |
152 | } |
168 | } |
153 | # endif |
169 | # endif |
154 | |
170 | |
155 | return false; |
171 | return false; |
156 | }; |
172 | }; |
157 | |
173 | |
158 | bool bgPixmap_t::need_client_side_rendering () |
174 | bool bgPixmap_t::need_client_side_rendering () |
159 | { |
175 | { |
160 | # ifdef HAVE_AFTERIMAGE |
176 | # ifdef HAVE_AFTERIMAGE |
161 | if (original_asim != NULL) |
177 | if (original_asim) |
162 | return true; |
178 | return true; |
163 | # endif |
179 | # endif |
164 | # ifdef ENABLE_TRANSPARENCY |
180 | # ifdef ENABLE_TRANSPARENCY |
165 | if (flags & isTransparent) |
181 | if (flags & isTransparent) |
166 | { |
182 | { |
167 | # ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways |
183 | # ifdef HAVE_AFTERIMAGE |
168 | if ((flags & blurNeeded) && !(flags & blurServerSide)) |
184 | if ((flags & blurNeeded) && !(flags & blurServerSide)) |
169 | return true; |
185 | return true; |
170 | # endif |
186 | # endif |
171 | if ((flags & tintNeeded) && !(flags & tintServerSide)) |
187 | if ((flags & tintNeeded) && !(flags & tintServerSide)) |
172 | return true; |
188 | return true; |
… | |
… | |
195 | static inline bool |
211 | static inline bool |
196 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
212 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
197 | { |
213 | { |
198 | if (geom_flags & flag) |
214 | if (geom_flags & flag) |
199 | { |
215 | { |
200 | if (new_value != bgPixmap_t::rootAlign) |
|
|
201 | { |
|
|
202 | if (new_value < -100) |
216 | if (new_value < -100) |
203 | new_value = -100; |
217 | new_value = -100; |
204 | else if (new_value > 200) |
218 | else if (new_value > 200) |
205 | new_value = 200; |
219 | new_value = 200; |
206 | } |
|
|
207 | if (new_value != align) |
220 | if (new_value != align) |
208 | { |
221 | { |
209 | align = new_value; |
222 | align = new_value; |
210 | return true; |
223 | return true; |
211 | } |
224 | } |
… | |
… | |
215 | |
228 | |
216 | static inline int |
229 | static inline int |
217 | make_align_position (int align, int window_size, int image_size) |
230 | make_align_position (int align, int window_size, int image_size) |
218 | { |
231 | { |
219 | int diff = window_size - image_size; |
232 | int diff = window_size - image_size; |
220 | int smaller = MIN (image_size,window_size); |
233 | int smaller = min (image_size, window_size); |
221 | |
234 | |
222 | if (align >= 0 && align <= 50) |
235 | if (align >= 0 && align <= 100) |
223 | return diff * align / 100; |
236 | return diff * align / 100; |
224 | else if (align > 50 && align <= 100) |
|
|
225 | return window_size - image_size - diff * (100 - align) / 100; |
|
|
226 | else if (align > 100 && align <= 200 ) |
237 | else if (align > 100 && align <= 200 ) |
227 | return ((align - 100) * smaller / 100) + window_size - smaller; |
238 | return ((align - 100) * smaller / 100) + window_size - smaller; |
228 | else if (align > -100 && align < 0) |
239 | else if (align >= -100 && align < 0) |
229 | return ((align + 100) * smaller / 100) - image_size; |
240 | return ((align + 100) * smaller / 100) - image_size; |
230 | return 0; |
241 | return 0; |
231 | } |
242 | } |
232 | |
243 | |
233 | static inline int |
244 | static inline int |
234 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
245 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
235 | { |
246 | { |
236 | int src_pos = 0; |
247 | int src_pos = 0; |
237 | dst_pos = 0; |
248 | dst_pos = pos; |
238 | dst_size = size; |
249 | dst_size = size; |
239 | if (pos < 0 && size > target_size) |
250 | if (pos < 0) |
240 | { |
251 | { |
241 | src_pos = -pos; |
252 | src_pos = -pos; |
|
|
253 | dst_pos = 0; |
242 | dst_size += pos; |
254 | dst_size += pos; |
243 | } |
255 | } |
244 | else if (pos > 0) |
|
|
245 | dst_pos = pos; |
|
|
246 | |
256 | |
247 | if (dst_pos + dst_size > target_size) |
257 | if (dst_pos + dst_size > target_size) |
248 | dst_size = target_size - dst_pos; |
258 | dst_size = target_size - dst_pos; |
249 | return src_pos; |
259 | return src_pos; |
250 | } |
260 | } |
… | |
… | |
255 | int geom_flags = 0, changed = 0; |
265 | int geom_flags = 0, changed = 0; |
256 | int x = 0, y = 0; |
266 | int x = 0, y = 0; |
257 | unsigned int w = 0, h = 0; |
267 | unsigned int w = 0, h = 0; |
258 | unsigned int n; |
268 | unsigned int n; |
259 | unsigned long new_flags = (flags & (~geometryFlags)); |
269 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | char *p; |
270 | const char *p; |
261 | # define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
271 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
262 | |
272 | |
263 | if (geom == NULL) |
273 | if (geom == NULL) |
264 | return false; |
274 | return false; |
265 | |
275 | |
266 | char str[MAXLEN_GEOM]; |
276 | char str[MAXLEN_GEOM]; |
… | |
… | |
273 | if (n < MAXLEN_GEOM) |
283 | if (n < MAXLEN_GEOM) |
274 | { |
284 | { |
275 | char *ops; |
285 | char *ops; |
276 | new_flags |= geometrySet; |
286 | new_flags |= geometrySet; |
277 | |
287 | |
278 | strncpy (str, geom, n); |
288 | memcpy (str, geom, n); |
279 | str[n] = '\0'; |
289 | str[n] = '\0'; |
280 | if (str[0] == ':') |
290 | if (str[0] == ':') |
281 | ops = &str[0]; |
291 | ops = &str[0]; |
282 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
292 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
283 | ops = &str[0]; |
293 | ops = &str[0]; |
… | |
… | |
366 | if (ops) |
376 | if (ops) |
367 | { |
377 | { |
368 | while (*ops) |
378 | while (*ops) |
369 | { |
379 | { |
370 | while (*ops == ':' || isspace(*ops)) ++ops; |
380 | while (*ops == ':' || isspace(*ops)) ++ops; |
|
|
381 | |
371 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
382 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) |
372 | if (CHECK_GEOM_OPS("tile")) |
383 | if (CHECK_GEOM_OPS ("tile")) |
373 | { |
384 | { |
374 | w = h = noScale; |
385 | w = h = noScale; |
375 | geom_flags |= WidthValue|HeightValue; |
386 | geom_flags |= WidthValue|HeightValue; |
376 | } |
387 | } |
377 | else if (CHECK_GEOM_OPS("propscale")) |
388 | else if (CHECK_GEOM_OPS ("propscale")) |
378 | { |
389 | { |
379 | if (w == 0 && h == 0) |
|
|
380 | { |
|
|
381 | w = windowScale; |
|
|
382 | geom_flags |= WidthValue; |
|
|
383 | } |
|
|
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 | { |
|
|
421 | new_flags |= rootAlign; |
416 | w = h = noScale; |
422 | w = h = noScale; |
417 | x = y = rootAlign; |
|
|
418 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
423 | geom_flags |= WidthValue|HeightValue; |
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); |
|
|
446 | } |
|
|
447 | |
|
|
448 | void |
|
|
449 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
|
|
450 | { |
|
|
451 | int target_width = target->szHint.width; |
|
|
452 | int target_height = target->szHint.height; |
|
|
453 | |
|
|
454 | if (flags & propScale) |
|
|
455 | { |
|
|
456 | float scale = (float)target_width / image_width; |
|
|
457 | min_it (scale, (float)target_height / image_height); |
|
|
458 | w = image_width * scale + 0.5; |
|
|
459 | h = image_height * scale + 0.5; |
|
|
460 | } |
|
|
461 | else |
|
|
462 | { |
|
|
463 | w = h_scale * target_width / 100; |
|
|
464 | h = v_scale * target_height / 100; |
|
|
465 | } |
|
|
466 | |
|
|
467 | if (!w) w = image_width; |
|
|
468 | if (!h) h = image_height; |
|
|
469 | |
|
|
470 | if (flags & rootAlign) |
|
|
471 | { |
|
|
472 | target->get_window_origin (x, y); |
|
|
473 | x = -x; |
|
|
474 | y = -y; |
|
|
475 | } |
|
|
476 | else |
|
|
477 | { |
|
|
478 | x = make_align_position (h_align, target_width, w); |
|
|
479 | y = make_align_position (v_align, target_height, h); |
|
|
480 | } |
|
|
481 | |
|
|
482 | flags &= ~sizeSensitive; |
|
|
483 | if (h_scale != 0 || v_scale != 0 |
|
|
484 | || h_align != 0 || v_align != 0 |
|
|
485 | || w > target_width || h > target_height) |
|
|
486 | flags |= sizeSensitive; |
443 | } |
487 | } |
444 | |
488 | |
445 | # ifdef HAVE_AFTERIMAGE |
489 | # ifdef HAVE_AFTERIMAGE |
446 | bool |
490 | bool |
447 | bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) |
491 | bgPixmap_t::render_image (unsigned long background_flags) |
448 | { |
492 | { |
449 | if (target == NULL) |
493 | if (target == NULL) |
450 | return false; |
494 | return false; |
451 | |
495 | |
|
|
496 | target->init_asv (); |
|
|
497 | |
|
|
498 | ASImage *background = NULL; |
|
|
499 | ARGB32 background_tint = TINT_LEAVE_SAME; |
|
|
500 | |
|
|
501 | # ifdef ENABLE_TRANSPARENCY |
|
|
502 | if (background_flags) |
|
|
503 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
504 | |
|
|
505 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
506 | { |
|
|
507 | ShadingInfo as_shade; |
|
|
508 | as_shade.shading = shade; |
|
|
509 | |
|
|
510 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
511 | if (flags & tintSet) |
|
|
512 | tint.get (c); |
|
|
513 | as_shade.tintColor.red = c.r; |
|
|
514 | as_shade.tintColor.green = c.g; |
|
|
515 | as_shade.tintColor.blue = c.b; |
|
|
516 | |
|
|
517 | background_tint = shading2tint32 (&as_shade); |
|
|
518 | } |
|
|
519 | |
|
|
520 | if (!(background_flags & transpPmapBlurred) && (flags & blurNeeded) && background != NULL) |
|
|
521 | { |
|
|
522 | ASImage *tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
523 | (original_asim == NULL || tint == TINT_LEAVE_SAME) ? ASA_XImage : ASA_ASImage, |
|
|
524 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
525 | if (tmp) |
|
|
526 | { |
|
|
527 | destroy_asimage (&background); |
|
|
528 | background = tmp; |
|
|
529 | } |
|
|
530 | } |
|
|
531 | # endif |
|
|
532 | |
|
|
533 | ASImage *result = 0; |
|
|
534 | |
452 | int target_width = (int)target->szHint.width; |
535 | int target_width = target->szHint.width; |
453 | int target_height = (int)target->szHint.height; |
536 | int target_height = target->szHint.height; |
454 | int new_pmap_width = target_width, new_pmap_height = target_height; |
537 | int new_pmap_width = target_width; |
455 | ASImage *result = NULL; |
538 | int new_pmap_height = target_height; |
456 | |
539 | |
457 | int x = 0; |
540 | int x = 0; |
458 | int y = 0; |
541 | int y = 0; |
459 | int w = h_scale * target_width / 100; |
542 | int w = 0; |
460 | int h = v_scale * target_height / 100; |
543 | int h = 0; |
461 | |
544 | |
462 | TIMING_TEST_START (asim); |
545 | TIMING_TEST_START (asim); |
463 | |
546 | |
464 | if (original_asim) |
547 | if (original_asim) |
465 | { |
548 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
466 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
467 | { |
|
|
468 | target->get_window_origin(x, y); |
|
|
469 | x = -x; |
|
|
470 | y = -y; |
|
|
471 | } |
|
|
472 | if (h_align != rootAlign) |
|
|
473 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
474 | if (v_align != rootAlign) |
|
|
475 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
|
|
476 | } |
|
|
477 | |
549 | |
478 | if (original_asim == NULL |
550 | if (!original_asim |
|
|
551 | || (!(flags & rootAlign) |
479 | || x >= target_width |
552 | && (x >= target_width |
480 | || y >= target_height |
553 | || y >= target_height |
481 | || (w > 0 && x + w <= 0) |
554 | || (x + w <= 0) |
482 | || (h > 0 && y + h <= 0)) |
555 | || (y + h <= 0)))) |
483 | { |
556 | { |
484 | if (background) |
557 | if (background) |
485 | { |
558 | { |
486 | new_pmap_width = background->width; |
559 | new_pmap_width = background->width; |
487 | new_pmap_height = background->height; |
560 | new_pmap_height = background->height; |
488 | result = background; |
561 | result = background; |
|
|
562 | |
489 | if (background_tint != TINT_LEAVE_SAME) |
563 | if (background_tint != TINT_LEAVE_SAME) |
490 | { |
564 | { |
491 | ASImage* tmp = tile_asimage (target->asv, background, 0, 0, |
565 | ASImage *tmp = tile_asimage (target->asv, background, 0, 0, |
492 | target_width, target_height, background_tint, |
566 | target_width, target_height, background_tint, |
493 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
567 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
494 | if (tmp) |
568 | if (tmp) |
495 | result = tmp; |
569 | result = tmp; |
496 | } |
570 | } |
… | |
… | |
499 | new_pmap_width = new_pmap_height = 0; |
573 | new_pmap_width = new_pmap_height = 0; |
500 | } |
574 | } |
501 | else |
575 | else |
502 | { |
576 | { |
503 | result = original_asim; |
577 | result = original_asim; |
|
|
578 | |
504 | if ((w > 0 && w != original_asim->width) |
579 | if ((w != original_asim->width) |
505 | || (h > 0 && h != original_asim->height)) |
580 | || (h != original_asim->height)) |
506 | { |
581 | { |
507 | result = scale_asimage (target->asv, original_asim, |
582 | result = scale_asimage (target->asv, original_asim, |
508 | w > 0 ? w : original_asim->width, |
583 | w, h, |
509 | h > 0 ? h : original_asim->height, |
|
|
510 | background ? ASA_ASImage : ASA_XImage, |
584 | background ? ASA_ASImage : ASA_XImage, |
511 | 100, ASIMAGE_QUALITY_DEFAULT); |
585 | 100, ASIMAGE_QUALITY_DEFAULT); |
512 | } |
586 | } |
|
|
587 | |
513 | if (background == NULL) |
588 | if (background == NULL) |
514 | { |
589 | { |
515 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
516 | but there is no need to make it bigger then the window! */ |
|
|
517 | if (h_scale == 0) |
|
|
518 | new_pmap_width = min (result->width, target_width); |
|
|
519 | if (v_scale == 0) |
|
|
520 | new_pmap_height = min (result->height, target_height); |
|
|
521 | /* we also need to tile our image in one or both directions */ |
|
|
522 | if (h_scale == 0 || v_scale == 0) |
590 | if (h_scale == 0 || v_scale == 0) |
523 | { |
591 | { |
|
|
592 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
593 | but there is no need to make it bigger than the window! */ |
|
|
594 | new_pmap_width = min (result->width, target_width); |
|
|
595 | new_pmap_height = min (result->height, target_height); |
|
|
596 | |
|
|
597 | /* we also need to tile our image in both directions */ |
524 | ASImage *tmp = tile_asimage (target->asv, result, |
598 | ASImage *tmp = tile_asimage (target->asv, result, |
525 | (h_scale > 0) ? 0 : (int)result->width - x, |
599 | (int)result->width - x, |
526 | (v_scale > 0) ? 0 : (int)result->height - y, |
600 | (int)result->height - y, |
527 | new_pmap_width, |
601 | new_pmap_width, |
528 | new_pmap_height, |
602 | new_pmap_height, |
529 | TINT_LEAVE_SAME, ASA_XImage, |
603 | TINT_LEAVE_SAME, ASA_XImage, |
530 | 100, ASIMAGE_QUALITY_DEFAULT); |
604 | 100, ASIMAGE_QUALITY_DEFAULT); |
531 | if (tmp) |
605 | if (tmp) |
532 | { |
606 | { |
533 | if (result != original_asim) |
607 | if (result != original_asim) |
534 | destroy_asimage (&result); |
608 | destroy_asimage (&result); |
|
|
609 | |
535 | result = tmp; |
610 | result = tmp; |
536 | } |
611 | } |
537 | } |
612 | } |
538 | } |
613 | } |
539 | else |
614 | else |
540 | { |
615 | { |
541 | /* if blending background and image - pixmap has to be sized same as target window */ |
616 | /* if blending background and image - pixmap has to be sized same as target window */ |
542 | ASImageLayer *layers = create_image_layers (2); |
617 | ASImageLayer *layers = create_image_layers (2); |
543 | ASImage *merged_im = NULL; |
|
|
544 | |
618 | |
545 | layers[0].im = background; |
619 | layers[0].im = background; |
546 | layers[0].clip_width = target_width; |
620 | layers[0].clip_width = target_width; |
547 | layers[0].clip_height = target_height; |
621 | layers[0].clip_height = target_height; |
548 | layers[0].tint = background_tint; |
622 | layers[0].tint = background_tint; |
549 | layers[1].im = result; |
623 | layers[1].im = result; |
550 | if (w <= 0) |
624 | |
|
|
625 | if (h_scale == 0 || v_scale == 0) |
551 | { |
626 | { |
552 | /* tile horizontally */ |
627 | /* tile horizontally */ |
553 | while (x > 0) x -= (int)result->width; |
628 | while (x > 0) x -= (int)result->width; |
554 | layers[1].dst_x = x; |
629 | layers[1].dst_x = x; |
555 | layers[1].clip_width = result->width+target_width; |
630 | layers[1].clip_width = result->width+target_width; |
… | |
… | |
558 | { |
633 | { |
559 | /* clip horizontally */ |
634 | /* clip horizontally */ |
560 | layers[1].dst_x = x; |
635 | layers[1].dst_x = x; |
561 | layers[1].clip_width = result->width; |
636 | layers[1].clip_width = result->width; |
562 | } |
637 | } |
563 | if (h <= 0) |
638 | |
|
|
639 | if (h_scale == 0 || v_scale == 0) |
564 | { |
640 | { |
565 | while (y > 0) y -= (int)result->height; |
641 | while (y > 0) y -= (int)result->height; |
566 | layers[1].dst_y = y; |
642 | layers[1].dst_y = y; |
567 | layers[1].clip_height = result->height + target_height; |
643 | layers[1].clip_height = result->height + target_height; |
568 | } |
644 | } |
569 | else |
645 | else |
570 | { |
646 | { |
571 | layers[1].dst_y = y; |
647 | layers[1].dst_y = y; |
572 | layers[1].clip_height = result->height; |
648 | layers[1].clip_height = result->height; |
573 | } |
649 | } |
|
|
650 | |
574 | if (target->rs[Rs_blendtype]) |
651 | if (target->rs[Rs_blendtype]) |
575 | { |
652 | { |
576 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
653 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
577 | if (layers[1].merge_scanlines == NULL) |
654 | if (layers[1].merge_scanlines == NULL) |
578 | layers[1].merge_scanlines = alphablend_scanlines; |
655 | layers[1].merge_scanlines = alphablend_scanlines; |
579 | } |
656 | } |
|
|
657 | |
580 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
658 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
581 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
659 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
660 | |
582 | if (tmp) |
661 | if (tmp) |
583 | { |
662 | { |
584 | if (result != original_asim) |
663 | if (result != original_asim) |
585 | destroy_asimage (&result); |
664 | destroy_asimage (&result); |
|
|
665 | |
586 | result = tmp; |
666 | result = tmp; |
587 | } |
667 | } |
|
|
668 | |
588 | free (layers); |
669 | free (layers); |
589 | } |
670 | } |
590 | } |
671 | } |
591 | TIMING_TEST_PRINT_RESULT (asim); |
672 | TIMING_TEST_PRINT_RESULT (asim); |
592 | |
673 | |
593 | if (pixmap) |
674 | 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 | |
675 | |
605 | if (result) |
676 | if (result) |
606 | { |
677 | { |
607 | XGCValues gcv; |
678 | XGCValues gcv; |
608 | GC gc; |
679 | GC gc; |
|
|
680 | |
|
|
681 | if (pixmap) |
|
|
682 | { |
|
|
683 | if (pmap_width != new_pmap_width |
|
|
684 | || pmap_height != new_pmap_height |
|
|
685 | || pmap_depth != target->depth) |
|
|
686 | { |
|
|
687 | XFreePixmap (target->dpy, pixmap); |
|
|
688 | pixmap = None; |
|
|
689 | } |
|
|
690 | } |
609 | |
691 | |
610 | /* create Pixmap */ |
692 | /* create Pixmap */ |
611 | if (pixmap == None) |
693 | if (pixmap == None) |
612 | { |
694 | { |
613 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
695 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
614 | pmap_width = new_pmap_width; |
696 | pmap_width = new_pmap_width; |
615 | pmap_height = new_pmap_height; |
697 | pmap_height = new_pmap_height; |
616 | pmap_depth = target->depth; |
698 | pmap_depth = target->depth; |
617 | } |
699 | } |
618 | /* fill with background color ( if result's not completely overlapping it)*/ |
700 | /* fill with background color (if result's not completely overlapping it) */ |
619 | gcv.foreground = target->pix_colors[Color_bg]; |
701 | gcv.foreground = target->pix_colors[Color_bg]; |
620 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
702 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
621 | |
703 | |
622 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
704 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
623 | int dst_width = result->width, dst_height = result->height; |
705 | int dst_width = result->width, dst_height = result->height; |
624 | if (background == NULL) |
706 | if (background == NULL) |
625 | { |
707 | { |
626 | if (h_scale > 0) |
708 | if (!(h_scale == 0 || v_scale == 0)) |
|
|
709 | { |
627 | src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); |
710 | 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); |
711 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
|
|
712 | } |
630 | |
713 | |
631 | if (dst_x > 0 || dst_y > 0 |
714 | if (dst_x > 0 || dst_y > 0 |
632 | || dst_x + dst_width < new_pmap_width |
715 | || dst_x + dst_width < new_pmap_width |
633 | || dst_y + dst_height < new_pmap_height) |
716 | || dst_y + dst_height < new_pmap_height) |
634 | { |
|
|
635 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
717 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
636 | } |
|
|
637 | } |
718 | } |
638 | |
719 | |
639 | /* put result on pixmap */ |
720 | /* put result on pixmap */ |
640 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
721 | 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); |
722 | 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) |
724 | if (result != background && result != original_asim) |
644 | destroy_asimage (&result); |
725 | destroy_asimage (&result); |
645 | |
726 | |
646 | XFreeGC (target->dpy, gc); |
727 | XFreeGC (target->dpy, gc); |
647 | TIMING_TEST_PRINT_RESULT (asim); |
728 | TIMING_TEST_PRINT_RESULT (asim); |
648 | } |
|
|
649 | |
729 | |
|
|
730 | ret = true; |
|
|
731 | } |
|
|
732 | |
|
|
733 | if (background) |
|
|
734 | destroy_asimage (&background); |
|
|
735 | |
650 | return true; |
736 | return ret; |
651 | } |
737 | } |
652 | # endif /* HAVE_AFTERIMAGE */ |
738 | # endif /* HAVE_AFTERIMAGE */ |
|
|
739 | |
|
|
740 | # ifdef HAVE_PIXBUF |
|
|
741 | bool |
|
|
742 | bgPixmap_t::render_image (unsigned long background_flags) |
|
|
743 | { |
|
|
744 | if (target == NULL) |
|
|
745 | return false; |
|
|
746 | |
|
|
747 | if (!pixbuf) |
|
|
748 | return false; |
|
|
749 | |
|
|
750 | #if !XFT |
|
|
751 | if (background_flags) |
|
|
752 | return false; |
|
|
753 | #endif |
|
|
754 | |
|
|
755 | GdkPixbuf *result; |
|
|
756 | |
|
|
757 | int image_width = gdk_pixbuf_get_width (pixbuf); |
|
|
758 | int image_height = gdk_pixbuf_get_height (pixbuf); |
|
|
759 | |
|
|
760 | int target_width = target->szHint.width; |
|
|
761 | int target_height = target->szHint.height; |
|
|
762 | int new_pmap_width = target_width; |
|
|
763 | int new_pmap_height = target_height; |
|
|
764 | |
|
|
765 | int x = 0; |
|
|
766 | int y = 0; |
|
|
767 | int w = 0; |
|
|
768 | int h = 0; |
|
|
769 | |
|
|
770 | get_image_geometry (image_width, image_height, w, h, x, y); |
|
|
771 | |
|
|
772 | if (!(flags & rootAlign) |
|
|
773 | && (x >= target_width |
|
|
774 | || y >= target_height |
|
|
775 | || (x + w <= 0) |
|
|
776 | || (y + h <= 0))) |
|
|
777 | return false; |
|
|
778 | |
|
|
779 | result = pixbuf; |
|
|
780 | |
|
|
781 | if ((w != image_width) |
|
|
782 | || (h != image_height)) |
|
|
783 | { |
|
|
784 | result = gdk_pixbuf_scale_simple (pixbuf, |
|
|
785 | w, h, |
|
|
786 | GDK_INTERP_BILINEAR); |
|
|
787 | } |
|
|
788 | |
|
|
789 | bool ret = false; |
|
|
790 | |
|
|
791 | if (result) |
|
|
792 | { |
|
|
793 | XGCValues gcv; |
|
|
794 | GC gc; |
|
|
795 | Pixmap root_pmap; |
|
|
796 | |
|
|
797 | image_width = gdk_pixbuf_get_width (result); |
|
|
798 | image_height = gdk_pixbuf_get_height (result); |
|
|
799 | |
|
|
800 | if (background_flags) |
|
|
801 | { |
|
|
802 | root_pmap = pixmap; |
|
|
803 | pixmap = None; |
|
|
804 | } |
|
|
805 | else |
|
|
806 | { |
|
|
807 | if (h_scale == 0 || v_scale == 0) |
|
|
808 | { |
|
|
809 | new_pmap_width = min (image_width, target_width); |
|
|
810 | new_pmap_height = min (image_height, target_height); |
|
|
811 | } |
|
|
812 | } |
|
|
813 | |
|
|
814 | if (pixmap) |
|
|
815 | { |
|
|
816 | if (pmap_width != new_pmap_width |
|
|
817 | || pmap_height != new_pmap_height |
|
|
818 | || pmap_depth != target->depth) |
|
|
819 | { |
|
|
820 | XFreePixmap (target->dpy, pixmap); |
|
|
821 | pixmap = None; |
|
|
822 | } |
|
|
823 | } |
|
|
824 | |
|
|
825 | if (pixmap == None) |
|
|
826 | { |
|
|
827 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
|
|
828 | pmap_width = new_pmap_width; |
|
|
829 | pmap_height = new_pmap_height; |
|
|
830 | pmap_depth = target->depth; |
|
|
831 | } |
|
|
832 | |
|
|
833 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
834 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
835 | |
|
|
836 | if (h_scale == 0 || v_scale == 0) |
|
|
837 | { |
|
|
838 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
|
|
839 | gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, |
|
|
840 | 0, 0, |
|
|
841 | 0, 0, |
|
|
842 | image_width, image_height, |
|
|
843 | XLIB_RGB_DITHER_NONE, |
|
|
844 | 0, 0); |
|
|
845 | |
|
|
846 | gcv.tile = tile; |
|
|
847 | gcv.fill_style = FillTiled; |
|
|
848 | gcv.ts_x_origin = x; |
|
|
849 | gcv.ts_y_origin = y; |
|
|
850 | XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
|
|
851 | |
|
|
852 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
853 | XFreePixmap (target->dpy, tile); |
|
|
854 | } |
|
|
855 | else |
|
|
856 | { |
|
|
857 | int src_x, src_y, dst_x, dst_y; |
|
|
858 | int dst_width, dst_height; |
|
|
859 | |
|
|
860 | src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width ); |
|
|
861 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
|
|
862 | |
|
|
863 | if (dst_x > 0 || dst_y > 0 |
|
|
864 | || dst_x + dst_width < new_pmap_width |
|
|
865 | || dst_y + dst_height < new_pmap_height) |
|
|
866 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
867 | |
|
|
868 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
|
|
869 | gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, |
|
|
870 | src_x, src_y, |
|
|
871 | dst_x, dst_y, |
|
|
872 | dst_width, dst_height, |
|
|
873 | XLIB_RGB_DITHER_NONE, |
|
|
874 | 0, 0); |
|
|
875 | } |
|
|
876 | |
|
|
877 | #if XFT |
|
|
878 | if (background_flags) |
|
|
879 | { |
|
|
880 | Display *dpy = target->dpy; |
|
|
881 | XRenderPictureAttributes pa; |
|
|
882 | |
|
|
883 | XRenderPictFormat *src_format = XRenderFindVisualFormat (dpy, DefaultVisual (dpy, target->display->screen)); |
|
|
884 | Picture src = XRenderCreatePicture (dpy, root_pmap, src_format, 0, &pa); |
|
|
885 | |
|
|
886 | XRenderPictFormat *dst_format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
887 | Picture dst = XRenderCreatePicture (dpy, pixmap, dst_format, 0, &pa); |
|
|
888 | |
|
|
889 | pa.repeat = True; |
|
|
890 | Pixmap mask_pmap = XCreatePixmap (dpy, target->vt, 1, 1, 8); |
|
|
891 | XRenderPictFormat *mask_format = XRenderFindStandardFormat (dpy, PictStandardA8); |
|
|
892 | Picture mask = XRenderCreatePicture (dpy, mask_pmap, mask_format, CPRepeat, &pa); |
|
|
893 | XFreePixmap (dpy, mask_pmap); |
|
|
894 | |
|
|
895 | if (src && dst && mask) |
|
|
896 | { |
|
|
897 | XRenderColor mask_c; |
|
|
898 | |
|
|
899 | mask_c.alpha = 0x8000; |
|
|
900 | mask_c.red = 0; |
|
|
901 | mask_c.green = 0; |
|
|
902 | mask_c.blue = 0; |
|
|
903 | XRenderFillRectangle (dpy, PictOpSrc, mask, &mask_c, 0, 0, 1, 1); |
|
|
904 | XRenderComposite (dpy, PictOpOver, src, mask, dst, 0, 0, 0, 0, 0, 0, target_width, target_height); |
|
|
905 | } |
|
|
906 | |
|
|
907 | XRenderFreePicture (dpy, src); |
|
|
908 | XRenderFreePicture (dpy, dst); |
|
|
909 | XRenderFreePicture (dpy, mask); |
|
|
910 | |
|
|
911 | XFreePixmap (dpy, root_pmap); |
|
|
912 | } |
|
|
913 | #endif |
|
|
914 | |
|
|
915 | if (result != pixbuf) |
|
|
916 | g_object_unref (result); |
|
|
917 | |
|
|
918 | XFreeGC (target->dpy, gc); |
|
|
919 | |
|
|
920 | ret = true; |
|
|
921 | } |
|
|
922 | |
|
|
923 | return ret; |
|
|
924 | } |
|
|
925 | # endif /* HAVE_PIXBUF */ |
653 | |
926 | |
654 | bool |
927 | bool |
655 | bgPixmap_t::set_file (const char *file) |
928 | bgPixmap_t::set_file (const char *file) |
656 | { |
929 | { |
657 | char *f; |
|
|
658 | |
|
|
659 | assert (file != NULL); |
930 | assert (file); |
660 | |
931 | |
661 | if (*file != '\0') |
932 | if (*file) |
662 | { |
933 | { |
|
|
934 | if (const char *p = strchr (file, ';')) |
|
|
935 | { |
|
|
936 | size_t len = p - file; |
|
|
937 | char *f = rxvt_temp_buf<char> (len + 1); |
|
|
938 | memcpy (f, file, len); |
|
|
939 | f[len] = '\0'; |
|
|
940 | file = f; |
|
|
941 | } |
|
|
942 | |
663 | # ifdef HAVE_AFTERIMAGE |
943 | # ifdef HAVE_AFTERIMAGE |
664 | if (target->asimman == NULL) |
944 | if (!target->asimman) |
665 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
945 | 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); |
946 | ASImage *image = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
668 | else |
947 | if (image) |
669 | { |
|
|
670 | size_t len = f - file; |
|
|
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 | } |
948 | { |
677 | return (original_asim != NULL); |
949 | if (original_asim) |
|
|
950 | safe_asimage_destroy (original_asim); |
|
|
951 | original_asim = image; |
|
|
952 | have_image = true; |
|
|
953 | return true; |
|
|
954 | } |
678 | # endif |
955 | # endif |
|
|
956 | |
|
|
957 | # ifdef HAVE_PIXBUF |
|
|
958 | GdkPixbuf *image = gdk_pixbuf_new_from_file (file, NULL); |
|
|
959 | if (image) |
|
|
960 | { |
|
|
961 | if (pixbuf) |
|
|
962 | g_object_unref (pixbuf); |
|
|
963 | pixbuf = image; |
|
|
964 | have_image = true; |
|
|
965 | return true; |
|
|
966 | } |
|
|
967 | # endif |
679 | } |
968 | } |
|
|
969 | |
680 | return false; |
970 | return false; |
681 | } |
971 | } |
682 | |
972 | |
683 | # endif /* BG_IMAGE_FROM_FILE */ |
973 | # endif /* BG_IMAGE_FROM_FILE */ |
684 | |
974 | |
… | |
… | |
689 | if (!(flags & isTransparent)) |
979 | if (!(flags & isTransparent)) |
690 | { |
980 | { |
691 | flags |= isTransparent; |
981 | flags |= isTransparent; |
692 | return true; |
982 | return true; |
693 | } |
983 | } |
|
|
984 | |
694 | return false; |
985 | return false; |
695 | } |
986 | } |
696 | |
987 | |
697 | bool |
988 | bool |
698 | bgPixmap_t::set_blur_radius (const char *geom) |
989 | bgPixmap_t::set_blur_radius (const char *geom) |
… | |
… | |
700 | int changed = 0; |
991 | int changed = 0; |
701 | unsigned int hr, vr; |
992 | unsigned int hr, vr; |
702 | int junk; |
993 | int junk; |
703 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
994 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
704 | |
995 | |
705 | if (!(geom_flags&WidthValue)) |
996 | if (!(geom_flags & WidthValue)) |
706 | hr = 1; |
997 | hr = 1; |
707 | if (!(geom_flags&HeightValue)) |
998 | if (!(geom_flags & HeightValue)) |
708 | vr = hr; |
999 | vr = hr; |
|
|
1000 | |
|
|
1001 | min_it (hr, 128); |
|
|
1002 | min_it (vr, 128); |
709 | |
1003 | |
710 | if (h_blurRadius != hr) |
1004 | if (h_blurRadius != hr) |
711 | { |
1005 | { |
712 | ++changed; |
1006 | ++changed; |
713 | h_blurRadius = hr; |
1007 | h_blurRadius = hr; |
… | |
… | |
722 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1016 | if (v_blurRadius == 0 && h_blurRadius == 0) |
723 | flags &= ~blurNeeded; |
1017 | flags &= ~blurNeeded; |
724 | else |
1018 | else |
725 | flags |= blurNeeded; |
1019 | flags |= blurNeeded; |
726 | |
1020 | |
|
|
1021 | #if XFT |
|
|
1022 | XFilters *filters = XRenderQueryFilters (target->dpy, target->display->root); |
|
|
1023 | if (filters) |
|
|
1024 | { |
|
|
1025 | for (int i = 0; i < filters->nfilter; i++) |
|
|
1026 | if (!strcmp (filters->filter[i], FilterConvolution)) |
|
|
1027 | flags |= bgPixmap_t::blurServerSide; |
|
|
1028 | |
|
|
1029 | XFree (filters); |
|
|
1030 | } |
|
|
1031 | #endif |
|
|
1032 | |
727 | return (changed>0); |
1033 | return (changed > 0); |
728 | } |
1034 | } |
729 | |
1035 | |
730 | static inline unsigned long |
1036 | static inline unsigned long |
731 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1037 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
732 | { |
1038 | { |
733 | unsigned long flags = 0; |
1039 | unsigned long flags = 0; |
734 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1040 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
735 | bool has_shade = (shade > 0 && shade < 100) || (shade > 100 && shade < 200); |
1041 | bool has_shade = shade != 100; |
736 | |
1042 | |
737 | if (tint) |
1043 | if (tint) |
738 | { |
1044 | { |
739 | tint->get (c); |
1045 | tint->get (c); |
740 | # define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) |
1046 | # define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) |
… | |
… | |
749 | flags |= bgPixmap_t::tintNeeded; |
1055 | flags |= bgPixmap_t::tintNeeded; |
750 | else if (tint) |
1056 | else if (tint) |
751 | { |
1057 | { |
752 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
1058 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
753 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
1059 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
754 | { |
1060 | { |
755 | flags |= bgPixmap_t::tintNeeded; |
1061 | flags |= bgPixmap_t::tintNeeded; |
756 | } |
1062 | } |
757 | } |
1063 | } |
758 | |
1064 | |
759 | if (flags & bgPixmap_t::tintNeeded) |
1065 | if (flags & bgPixmap_t::tintNeeded) |
760 | { |
1066 | { |
761 | if (flags & bgPixmap_t::tintWholesome) |
1067 | if (flags & bgPixmap_t::tintWholesome) |
… | |
… | |
772 | } |
1078 | } |
773 | |
1079 | |
774 | bool |
1080 | bool |
775 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
1081 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
776 | { |
1082 | { |
777 | if (tint != new_tint) |
1083 | if (!(flags & tintSet) || tint != new_tint) |
778 | { |
1084 | { |
779 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
1085 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
780 | tint = new_tint; |
1086 | tint = new_tint; |
781 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
1087 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
782 | return true; |
1088 | return true; |
… | |
… | |
790 | { |
1096 | { |
791 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
1097 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
792 | |
1098 | |
793 | if (new_flags != (flags & tintFlags)) |
1099 | if (new_flags != (flags & tintFlags)) |
794 | { |
1100 | { |
795 | flags = (flags&~tintFlags)|new_flags; |
1101 | flags = (flags & ~tintFlags) | new_flags; |
796 | return true; |
1102 | return true; |
797 | } |
1103 | } |
798 | |
1104 | |
799 | return false; |
1105 | return false; |
800 | } |
1106 | } |
801 | |
1107 | |
802 | bool |
1108 | bool |
803 | bgPixmap_t::set_shade (const char *shade_str) |
1109 | bgPixmap_t::set_shade (const char *shade_str) |
804 | { |
1110 | { |
805 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
1111 | int new_shade = (shade_str) ? atoi (shade_str) : 100; |
806 | |
1112 | |
807 | if (new_shade < 0 && new_shade > -100) |
1113 | clamp_it (new_shade, -100, 200); |
|
|
1114 | if (new_shade < 0) |
808 | new_shade = 200 - (100 + new_shade); |
1115 | new_shade = 200 - (100 + new_shade); |
809 | else if (new_shade == 100) |
|
|
810 | new_shade = 0; |
|
|
811 | |
1116 | |
812 | if (new_shade != shade) |
1117 | if (new_shade != shade) |
813 | { |
1118 | { |
814 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
1119 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
815 | shade = new_shade; |
1120 | shade = new_shade; |
816 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
1121 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
817 | return true; |
1122 | return true; |
818 | } |
1123 | } |
819 | |
1124 | |
820 | return false; |
1125 | return false; |
|
|
1126 | } |
|
|
1127 | |
|
|
1128 | static void |
|
|
1129 | get_gaussian_kernel (int radius, int width, double *kernel, XFixed *params) |
|
|
1130 | { |
|
|
1131 | double sigma = radius / 2.0; |
|
|
1132 | double scale = sqrt (2.0 * M_PI) * sigma; |
|
|
1133 | double sum = 0.0; |
|
|
1134 | |
|
|
1135 | for (int i = 0; i < width; i++) |
|
|
1136 | { |
|
|
1137 | double x = i - width / 2; |
|
|
1138 | kernel[i] = exp (-(x * x) / (2.0 * sigma * sigma)) / scale; |
|
|
1139 | sum += kernel[i]; |
|
|
1140 | } |
|
|
1141 | |
|
|
1142 | params[0] = XDoubleToFixed (width); |
|
|
1143 | params[1] = XDoubleToFixed (1); |
|
|
1144 | |
|
|
1145 | for (int i = 0; i < width; i++) |
|
|
1146 | params[i+2] = XDoubleToFixed (kernel[i] / sum); |
|
|
1147 | } |
|
|
1148 | |
|
|
1149 | bool |
|
|
1150 | bgPixmap_t::blur_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
|
|
1151 | { |
|
|
1152 | bool ret = false; |
|
|
1153 | #if XFT |
|
|
1154 | int size = max (h_blurRadius, v_blurRadius) * 2 + 1; |
|
|
1155 | double *kernel = (double *)malloc (size * sizeof (double)); |
|
|
1156 | XFixed *params = (XFixed *)malloc ((size + 2) * sizeof (XFixed)); |
|
|
1157 | |
|
|
1158 | Display *dpy = target->dpy; |
|
|
1159 | XRenderPictureAttributes pa; |
|
|
1160 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, target->visual); |
|
|
1161 | |
|
|
1162 | Picture src = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
|
|
1163 | Picture dst = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
|
|
1164 | |
|
|
1165 | if (kernel && params && src && dst) |
|
|
1166 | { |
|
|
1167 | if (h_blurRadius) |
|
|
1168 | { |
|
|
1169 | size = h_blurRadius * 2 + 1; |
|
|
1170 | get_gaussian_kernel (h_blurRadius, size, kernel, params); |
|
|
1171 | |
|
|
1172 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
|
|
1173 | XRenderComposite (dpy, |
|
|
1174 | PictOpSrc, |
|
|
1175 | src, |
|
|
1176 | None, |
|
|
1177 | dst, |
|
|
1178 | 0, 0, |
|
|
1179 | 0, 0, |
|
|
1180 | 0, 0, |
|
|
1181 | width, height); |
|
|
1182 | } |
|
|
1183 | |
|
|
1184 | if (v_blurRadius) |
|
|
1185 | { |
|
|
1186 | size = v_blurRadius * 2 + 1; |
|
|
1187 | get_gaussian_kernel (v_blurRadius, size, kernel, params); |
|
|
1188 | swap (params[0], params[1]); |
|
|
1189 | |
|
|
1190 | XRenderSetPictureFilter (dpy, src, FilterConvolution, params, size+2); |
|
|
1191 | XRenderComposite (dpy, |
|
|
1192 | PictOpSrc, |
|
|
1193 | src, |
|
|
1194 | None, |
|
|
1195 | dst, |
|
|
1196 | 0, 0, |
|
|
1197 | 0, 0, |
|
|
1198 | 0, 0, |
|
|
1199 | width, height); |
|
|
1200 | } |
|
|
1201 | |
|
|
1202 | ret = true; |
|
|
1203 | } |
|
|
1204 | |
|
|
1205 | free (kernel); |
|
|
1206 | free (params); |
|
|
1207 | XRenderFreePicture (dpy, src); |
|
|
1208 | XRenderFreePicture (dpy, dst); |
|
|
1209 | #endif |
|
|
1210 | return ret; |
|
|
1211 | } |
|
|
1212 | |
|
|
1213 | bool |
|
|
1214 | bgPixmap_t::tint_pixmap (Pixmap pixmap, Visual *visual, int width, int height) |
|
|
1215 | { |
|
|
1216 | Display *dpy = target->dpy; |
|
|
1217 | bool ret = false; |
|
|
1218 | |
|
|
1219 | if (flags & tintWholesome) |
|
|
1220 | { |
|
|
1221 | XGCValues gcv; |
|
|
1222 | GC gc; |
|
|
1223 | |
|
|
1224 | /* In this case we can tint image server-side getting significant |
|
|
1225 | * performance improvements, as we eliminate XImage transfer |
|
|
1226 | */ |
|
|
1227 | gcv.foreground = Pixel (tint); |
|
|
1228 | gcv.function = GXand; |
|
|
1229 | gcv.fill_style = FillSolid; |
|
|
1230 | gc = XCreateGC (dpy, pixmap, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
1231 | if (gc) |
|
|
1232 | { |
|
|
1233 | XFillRectangle (dpy, pixmap, gc, 0, 0, width, height); |
|
|
1234 | ret = true; |
|
|
1235 | XFreeGC (dpy, gc); |
|
|
1236 | } |
|
|
1237 | } |
|
|
1238 | else |
|
|
1239 | { |
|
|
1240 | # if XFT |
|
|
1241 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1242 | |
|
|
1243 | if (flags & tintSet) |
|
|
1244 | tint.get (c); |
|
|
1245 | |
|
|
1246 | if (shade <= 100) |
|
|
1247 | { |
|
|
1248 | c.r = (c.r * shade) / 100; |
|
|
1249 | c.g = (c.g * shade) / 100; |
|
|
1250 | c.b = (c.b * shade) / 100; |
|
|
1251 | } |
|
|
1252 | else |
|
|
1253 | { |
|
|
1254 | c.r = ((0xffff - c.r) * (200 - shade)) / 100; |
|
|
1255 | c.g = ((0xffff - c.g) * (200 - shade)) / 100; |
|
|
1256 | c.b = ((0xffff - c.b) * (200 - shade)) / 100; |
|
|
1257 | } |
|
|
1258 | |
|
|
1259 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
|
|
1260 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
|
|
1261 | XRenderPictureAttributes pa; |
|
|
1262 | |
|
|
1263 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, format, 0, &pa); |
|
|
1264 | |
|
|
1265 | pa.repeat = True; |
|
|
1266 | |
|
|
1267 | Pixmap overlay_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
|
|
1268 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
|
|
1269 | XFreePixmap (dpy, overlay_pmap); |
|
|
1270 | |
|
|
1271 | pa.component_alpha = True; |
|
|
1272 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
|
|
1273 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
|
|
1274 | XFreePixmap (dpy, mask_pmap); |
|
|
1275 | |
|
|
1276 | if (mask_pic && overlay_pic && back_pic) |
|
|
1277 | { |
|
|
1278 | XRenderColor mask_c; |
|
|
1279 | |
|
|
1280 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
|
|
1281 | mask_c.alpha = 0xffff; |
|
|
1282 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1283 | |
|
|
1284 | mask_c.alpha = 0; |
|
|
1285 | mask_c.red = 0xffff - c.r; |
|
|
1286 | mask_c.green = 0xffff - c.g; |
|
|
1287 | mask_c.blue = 0xffff - c.b; |
|
|
1288 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1289 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1290 | ret = true; |
|
|
1291 | } |
|
|
1292 | |
|
|
1293 | XRenderFreePicture (dpy, mask_pic); |
|
|
1294 | XRenderFreePicture (dpy, overlay_pic); |
|
|
1295 | XRenderFreePicture (dpy, back_pic); |
|
|
1296 | # if DO_TIMING_TEST |
|
|
1297 | XSync (dpy, False); |
|
|
1298 | # endif |
|
|
1299 | # endif |
|
|
1300 | } |
|
|
1301 | |
|
|
1302 | return ret; |
821 | } |
1303 | } |
822 | |
1304 | |
823 | /* make_transparency_pixmap() |
1305 | /* make_transparency_pixmap() |
824 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
1306 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
825 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
1307 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
… | |
… | |
831 | unsigned long result = 0; |
1313 | unsigned long result = 0; |
832 | |
1314 | |
833 | if (target == NULL) |
1315 | if (target == NULL) |
834 | return 0; |
1316 | return 0; |
835 | |
1317 | |
836 | /* root dimentions may change from call to call - but Display structure should |
1318 | /* root dimensions may change from call to call - but Display structure should |
837 | * be always up-to-date, so let's use it : |
1319 | * be always up-to-date, so let's use it : |
838 | */ |
1320 | */ |
839 | Window root = target->display->root; |
1321 | Window root = target->display->root; |
840 | int screen = target->display->screen; |
1322 | int screen = target->display->screen; |
841 | Display *dpy = target->dpy; |
1323 | Display *dpy = target->dpy; |
… | |
… | |
844 | unsigned int root_pmap_width, root_pmap_height; |
1326 | unsigned int root_pmap_width, root_pmap_height; |
845 | int window_width = target->szHint.width; |
1327 | int window_width = target->szHint.width; |
846 | int window_height = target->szHint.height; |
1328 | int window_height = target->szHint.height; |
847 | int sx, sy; |
1329 | int sx, sy; |
848 | XGCValues gcv; |
1330 | XGCValues gcv; |
|
|
1331 | GC gc; |
849 | |
1332 | |
850 | TIMING_TEST_START (tp); |
1333 | TIMING_TEST_START (tp); |
851 | target->get_window_origin (sx, sy); |
1334 | target->get_window_origin (sx, sy); |
852 | |
1335 | |
853 | /* check if we are outside of the visible part of the virtual screen : */ |
1336 | /* check if we are outside of the visible part of the virtual screen : */ |
… | |
… | |
855 | || sx >= root_width || sy >= root_height) |
1338 | || sx >= root_width || sy >= root_height) |
856 | return 0; |
1339 | return 0; |
857 | |
1340 | |
858 | if (root_pixmap != None) |
1341 | if (root_pixmap != None) |
859 | { |
1342 | { |
860 | /* we want to validate the pixmap and get it's size at the same time : */ |
1343 | /* we want to validate the pixmap and get its size at the same time : */ |
861 | int junk; |
1344 | int junk; |
862 | unsigned int ujunk; |
1345 | unsigned int ujunk; |
863 | /* root pixmap may be bad - allow a error */ |
1346 | /* root pixmap may be bad - allow a error */ |
864 | target->allowedxerror = -1; |
1347 | target->allowedxerror = -1; |
865 | |
1348 | |
… | |
… | |
867 | root_pixmap = None; |
1350 | root_pixmap = None; |
868 | |
1351 | |
869 | target->allowedxerror = 0; |
1352 | target->allowedxerror = 0; |
870 | } |
1353 | } |
871 | |
1354 | |
|
|
1355 | if (root_pixmap == None) |
|
|
1356 | return 0; |
|
|
1357 | |
872 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
1358 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
873 | GC gc = NULL; |
|
|
874 | |
1359 | |
875 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1360 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
876 | return 0; |
1361 | return 0; |
877 | |
1362 | |
878 | if (root_pixmap == None) |
|
|
879 | { |
|
|
880 | /* use tricks to obtain the root background image :*/ |
|
|
881 | /* we want to create Overrideredirect window overlapping out window |
|
|
882 | with background type of Parent Relative and then grab it */ |
|
|
883 | XSetWindowAttributes attr; |
|
|
884 | Window src; |
|
|
885 | bool success = false; |
|
|
886 | |
|
|
887 | attr.background_pixmap = ParentRelative; |
|
|
888 | attr.backing_store = Always; |
|
|
889 | attr.event_mask = ExposureMask; |
|
|
890 | attr.override_redirect = True; |
|
|
891 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
|
|
892 | CopyFromParent, CopyFromParent, CopyFromParent, |
|
|
893 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
|
|
894 | &attr); |
|
|
895 | |
|
|
896 | if (src != None) |
|
|
897 | { |
|
|
898 | XEvent event; |
|
|
899 | int ev_count = 0; |
|
|
900 | XGrabServer (dpy); |
|
|
901 | XMapRaised (dpy, src); |
|
|
902 | XSync (dpy, False); |
|
|
903 | |
|
|
904 | /* XSync should get window where it's properly exposed, |
|
|
905 | * but to be on the safe side - let's check for the actual event to arrive : */ |
|
|
906 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
|
|
907 | ++ev_count; |
|
|
908 | |
|
|
909 | if (ev_count > 0); |
|
|
910 | { |
|
|
911 | /* hooray! - we can grab the image! */ |
|
|
912 | gc = XCreateGC (dpy, root, 0, NULL); |
|
|
913 | if (gc) |
|
|
914 | { |
|
|
915 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
|
|
916 | success = true; |
|
|
917 | } |
|
|
918 | } |
|
|
919 | |
|
|
920 | XDestroyWindow (dpy, src); |
|
|
921 | XUngrabServer (dpy); |
|
|
922 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
|
|
923 | } |
|
|
924 | |
|
|
925 | if (!success) |
|
|
926 | { |
|
|
927 | XFreePixmap (dpy, tiled_root_pmap); |
|
|
928 | tiled_root_pmap = None; |
|
|
929 | } |
|
|
930 | else |
|
|
931 | result |= transpPmapTiled; |
|
|
932 | } |
|
|
933 | else |
|
|
934 | { |
|
|
935 | /* strightforward pixmap copy */ |
1363 | /* straightforward pixmap copy */ |
936 | gcv.tile = root_pixmap; |
1364 | gcv.tile = root_pixmap; |
937 | gcv.fill_style = FillTiled; |
1365 | gcv.fill_style = FillTiled; |
938 | |
1366 | |
939 | while (sx < 0) sx += (int)root_width; |
1367 | while (sx < 0) sx += (int)root_width; |
940 | while (sy < 0) sy += (int)root_height; |
1368 | while (sy < 0) sy += (int)root_height; |
941 | |
1369 | |
942 | gcv.ts_x_origin = -sx; |
1370 | gcv.ts_x_origin = -sx; |
943 | gcv.ts_y_origin = -sy; |
1371 | gcv.ts_y_origin = -sy; |
944 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1372 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
945 | |
1373 | |
946 | if (gc) |
1374 | if (gc) |
947 | { |
1375 | { |
948 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1376 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
949 | result |= transpPmapTiled; |
1377 | result |= transpPmapTiled; |
950 | } |
1378 | XFreeGC (dpy, gc); |
951 | } |
1379 | } |
952 | TIMING_TEST_PRINT_RESULT (tp); |
1380 | TIMING_TEST_PRINT_RESULT (tp); |
953 | |
1381 | |
954 | if (tiled_root_pmap != None) |
1382 | if (tiled_root_pmap != None) |
955 | { |
1383 | { |
956 | if (!need_client_side_rendering ()) |
1384 | if (!need_client_side_rendering ()) |
957 | { |
1385 | { |
|
|
1386 | if ((flags & blurNeeded)) |
|
|
1387 | { |
|
|
1388 | if (blur_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
|
|
1389 | result |= transpPmapBlurred; |
|
|
1390 | } |
958 | if ((flags & tintNeeded)) |
1391 | if ((flags & tintNeeded)) |
959 | { |
1392 | { |
960 | if (flags & tintWholesome) |
1393 | if (tint_pixmap (tiled_root_pmap, DefaultVisual (dpy, target->display->screen), window_width, window_height)) |
961 | { |
|
|
962 | /* In this case we can tint image server-side getting significant |
|
|
963 | * performance improvements, as we eliminate XImage transfer |
|
|
964 | */ |
|
|
965 | gcv.foreground = Pixel (tint); |
|
|
966 | gcv.function = GXand; |
|
|
967 | gcv.fill_style = FillSolid; |
|
|
968 | if (gc) |
|
|
969 | XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
970 | else |
|
|
971 | gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
972 | if (gc) |
|
|
973 | { |
|
|
974 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
|
|
975 | result |= transpPmapTinted; |
1394 | result |= transpPmapTinted; |
976 | } |
|
|
977 | } |
|
|
978 | else |
|
|
979 | { |
|
|
980 | # if XFT |
|
|
981 | Picture back_pic = 0; |
|
|
982 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
983 | |
|
|
984 | if (flags & tintSet) |
|
|
985 | tint.get (c); |
|
|
986 | |
|
|
987 | if (shade > 0 && shade < 100) |
|
|
988 | { |
|
|
989 | c.r = (c.r * shade) / 100; |
|
|
990 | c.g = (c.g * shade) / 100; |
|
|
991 | c.b = (c.b * shade) / 100; |
|
|
992 | } |
|
|
993 | else if (shade > 100 && shade < 200) |
|
|
994 | { |
|
|
995 | c.r = (c.r * (200 - shade)) / 100; |
|
|
996 | c.g = (c.g * (200 - shade)) / 100; |
|
|
997 | c.b = (c.b * (200 - shade)) / 100; |
|
|
998 | } |
|
|
999 | |
|
|
1000 | XRenderPictFormat pf; |
|
|
1001 | pf.type = PictTypeDirect; |
|
|
1002 | pf.depth = 32; |
|
|
1003 | pf.direct.redMask = 0xff; |
|
|
1004 | pf.direct.greenMask = 0xff; |
|
|
1005 | pf.direct.blueMask = 0xff; |
|
|
1006 | pf.direct.alphaMask = 0xff; |
|
|
1007 | |
|
|
1008 | XRenderPictFormat *solid_format = XRenderFindFormat (dpy, |
|
|
1009 | (PictFormatType| |
|
|
1010 | PictFormatDepth| |
|
|
1011 | PictFormatRedMask| |
|
|
1012 | PictFormatGreenMask| |
|
|
1013 | PictFormatBlueMask| |
|
|
1014 | PictFormatAlphaMask), |
|
|
1015 | &pf, |
|
|
1016 | 0); |
|
|
1017 | XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); |
|
|
1018 | XRenderPictureAttributes pa ; |
|
|
1019 | |
|
|
1020 | back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); |
|
|
1021 | |
|
|
1022 | pa.repeat = True; |
|
|
1023 | |
|
|
1024 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
|
|
1025 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
|
|
1026 | XFreePixmap (dpy, overlay_pmap); |
|
|
1027 | |
|
|
1028 | pa.component_alpha = True; |
|
|
1029 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
|
|
1030 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
|
|
1031 | XFreePixmap (dpy, mask_pmap); |
|
|
1032 | |
|
|
1033 | if (mask_pic && overlay_pic && back_pic) |
|
|
1034 | { |
|
|
1035 | XRenderColor mask_c; |
|
|
1036 | |
|
|
1037 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
|
|
1038 | mask_c.alpha = 0xffff; |
|
|
1039 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1040 | |
|
|
1041 | mask_c.alpha = 0; |
|
|
1042 | mask_c.red = 0xffff - c.r; |
|
|
1043 | mask_c.green = 0xffff - c.g; |
|
|
1044 | mask_c.blue = 0xffff - c.b; |
|
|
1045 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1046 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
|
|
1047 | result |= transpPmapTinted; |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | XRenderFreePicture (dpy, mask_pic); |
|
|
1051 | XRenderFreePicture (dpy, overlay_pic); |
|
|
1052 | XRenderFreePicture (dpy, back_pic); |
|
|
1053 | # if DO_TIMING_TEST |
|
|
1054 | XSync (dpy, False); |
|
|
1055 | # endif |
|
|
1056 | # endif |
|
|
1057 | } |
|
|
1058 | } |
1395 | } |
1059 | } /* server side rendering completed */ |
1396 | } /* server side rendering completed */ |
1060 | |
1397 | |
1061 | if (pixmap) |
1398 | if (pixmap) |
1062 | XFreePixmap (dpy, pixmap); |
1399 | XFreePixmap (dpy, pixmap); |
1063 | |
1400 | |
… | |
… | |
1065 | pmap_width = window_width; |
1402 | pmap_width = window_width; |
1066 | pmap_height = window_height; |
1403 | pmap_height = window_height; |
1067 | pmap_depth = root_depth; |
1404 | pmap_depth = root_depth; |
1068 | } |
1405 | } |
1069 | |
1406 | |
1070 | if (gc) |
|
|
1071 | XFreeGC (dpy, gc); |
|
|
1072 | |
|
|
1073 | TIMING_TEST_PRINT_RESULT (tp); |
1407 | TIMING_TEST_PRINT_RESULT (tp); |
1074 | |
1408 | |
1075 | return result; |
1409 | return result; |
1076 | } |
1410 | } |
1077 | |
1411 | |
… | |
… | |
1091 | return false; |
1425 | return false; |
1092 | } |
1426 | } |
1093 | # endif /* ENABLE_TRANSPARENCY */ |
1427 | # endif /* ENABLE_TRANSPARENCY */ |
1094 | |
1428 | |
1095 | # ifndef HAVE_AFTERIMAGE |
1429 | # ifndef HAVE_AFTERIMAGE |
1096 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1430 | static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); |
1097 | # endif |
1431 | # endif |
1098 | |
1432 | |
1099 | bool |
1433 | bool |
1100 | bgPixmap_t::render () |
1434 | bgPixmap_t::render () |
1101 | { |
1435 | { |
… | |
… | |
1104 | if (target == NULL) |
1438 | if (target == NULL) |
1105 | return false; |
1439 | return false; |
1106 | |
1440 | |
1107 | TIMING_TEST_START (tp); |
1441 | TIMING_TEST_START (tp); |
1108 | |
1442 | |
1109 | invalidate(); |
1443 | invalidate (); |
1110 | # ifdef ENABLE_TRANSPARENCY |
1444 | # ifdef ENABLE_TRANSPARENCY |
1111 | if (flags & isTransparent) |
1445 | if (flags & isTransparent) |
1112 | { |
1446 | { |
1113 | /* we need to re-generate transparency pixmap in that case ! */ |
1447 | /* we need to re-generate transparency pixmap in that case ! */ |
1114 | background_flags = make_transparency_pixmap (); |
1448 | background_flags = make_transparency_pixmap (); |
1115 | if (background_flags == 0) |
1449 | if (background_flags == 0) |
1116 | return false; |
1450 | return false; |
1117 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1451 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1118 | && pmap_depth == target->depth) |
1452 | && pmap_depth == target->depth) |
1119 | flags = flags & ~isInvalid; |
1453 | flags = flags & ~isInvalid; |
1120 | } |
1454 | } |
1121 | # endif |
1455 | # endif |
1122 | |
1456 | |
|
|
1457 | # ifdef BG_IMAGE_FROM_FILE |
|
|
1458 | if (have_image |
|
|
1459 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
|
|
1460 | { |
|
|
1461 | if (render_image (background_flags)) |
|
|
1462 | flags = flags & ~isInvalid; |
|
|
1463 | } |
|
|
1464 | # endif |
|
|
1465 | |
1123 | XImage *result = NULL; |
1466 | XImage *result = NULL; |
1124 | # ifdef HAVE_AFTERIMAGE |
1467 | |
1125 | if (original_asim |
1468 | if (background_flags && (flags & isInvalid)) |
1126 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1469 | { |
|
|
1470 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1127 | { |
1471 | } |
1128 | ASImage *background = NULL; |
|
|
1129 | ARGB32 as_tint = TINT_LEAVE_SAME; |
|
|
1130 | if (background_flags) |
|
|
1131 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
1132 | |
1472 | |
1133 | # ifdef ENABLE_TRANSPARENCY |
1473 | if (result) |
|
|
1474 | { |
|
|
1475 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
|
|
1476 | /* our own client-side tinting */ |
|
|
1477 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
|
|
1478 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1134 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1479 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1135 | { |
|
|
1136 | ShadingInfo as_shade; |
|
|
1137 | as_shade.shading = (shade == 0) ? 100 : shade; |
|
|
1138 | |
|
|
1139 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1140 | if (flags & tintSet) |
|
|
1141 | tint.get (c); |
|
|
1142 | as_shade.tintColor.red = c.r; |
|
|
1143 | as_shade.tintColor.green = c.g; |
|
|
1144 | as_shade.tintColor.blue = c.b; |
|
|
1145 | |
|
|
1146 | as_tint = shading2tint32 (&as_shade); |
|
|
1147 | } |
|
|
1148 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
|
|
1149 | { |
|
|
1150 | ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
1151 | (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, |
|
|
1152 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1153 | if (tmp) |
|
|
1154 | { |
|
|
1155 | destroy_asimage (&background); |
|
|
1156 | background = tmp; |
|
|
1157 | } |
|
|
1158 | } |
|
|
1159 | # endif |
|
|
1160 | |
|
|
1161 | if (render_asim (background, as_tint)) |
|
|
1162 | flags = flags & ~isInvalid; |
|
|
1163 | if (background) |
|
|
1164 | destroy_asimage (&background); |
|
|
1165 | } |
|
|
1166 | else if (background_flags && pmap_depth != target->depth) |
|
|
1167 | { |
|
|
1168 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
1169 | } |
|
|
1170 | |
|
|
1171 | # elif !XFT /* our own client-side tinting */ |
|
|
1172 | |
|
|
1173 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting neccessary server-side. |
|
|
1174 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
|
|
1175 | |
|
|
1176 | if (background_flags && (flags & isInvalid)) |
|
|
1177 | { |
|
|
1178 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
1179 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
1180 | { |
1480 | { |
1181 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1481 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1182 | if (flags & tintSet) |
1482 | if (flags & tintSet) |
1183 | tint.get (c); |
1483 | tint.get (c); |
1184 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1484 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1185 | } |
1485 | } |
1186 | } |
1486 | # endif |
1187 | # endif /* HAVE_AFTERIMAGE */ |
|
|
1188 | |
1487 | |
1189 | if (result) |
|
|
1190 | { |
|
|
1191 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1488 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1192 | |
1489 | |
1193 | if (gc) |
1490 | if (gc) |
1194 | { |
1491 | { |
1195 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1492 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
… | |
… | |
1224 | |
1521 | |
1225 | XFreeGC (target->dpy, gc); |
1522 | XFreeGC (target->dpy, gc); |
1226 | flags = flags & ~isInvalid; |
1523 | flags = flags & ~isInvalid; |
1227 | } |
1524 | } |
1228 | |
1525 | |
1229 | XDestroyImage (result); |
1526 | XDestroyImage (result); |
1230 | } |
1527 | } |
1231 | |
1528 | |
1232 | if (flags & isInvalid) |
1529 | if (flags & isInvalid) |
1233 | { |
1530 | { |
1234 | if (pixmap != None) |
1531 | if (pixmap != None) |
… | |
… | |
1237 | pixmap = None; |
1534 | pixmap = None; |
1238 | } |
1535 | } |
1239 | } |
1536 | } |
1240 | |
1537 | |
1241 | apply (); |
1538 | apply (); |
|
|
1539 | |
|
|
1540 | XSync (target->dpy, False); |
|
|
1541 | valid_since = ev::now (); |
1242 | |
1542 | |
1243 | TIMING_TEST_PRINT_RESULT (tp); |
1543 | TIMING_TEST_PRINT_RESULT (tp); |
1244 | |
1544 | |
1245 | return true; |
1545 | return true; |
1246 | } |
1546 | } |
… | |
… | |
1255 | # ifdef ENABLE_TRANSPARENCY |
1555 | # ifdef ENABLE_TRANSPARENCY |
1256 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1556 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1257 | # endif |
1557 | # endif |
1258 | return true; |
1558 | return true; |
1259 | } |
1559 | } |
|
|
1560 | |
1260 | return false; |
1561 | return false; |
1261 | } |
1562 | } |
1262 | |
1563 | |
1263 | void |
1564 | void |
1264 | bgPixmap_t::apply () |
1565 | bgPixmap_t::apply () |
1265 | { |
1566 | { |
1266 | if (target) |
1567 | if (target) |
1267 | { |
1568 | { |
1268 | flags &= ~isVtOrigin; |
1569 | flags &= ~isVtOrigin; |
|
|
1570 | |
1269 | if (pixmap != None) |
1571 | if (pixmap != None) |
1270 | { |
1572 | { |
1271 | /* set target's background to pixmap */ |
1573 | /* set target's background to pixmap */ |
1272 | # ifdef ENABLE_TRANSPARENCY |
1574 | # ifdef ENABLE_TRANSPARENCY |
1273 | if (flags & isTransparent) |
1575 | if (flags & isTransparent) |
1274 | { |
1576 | { |
1275 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1577 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1276 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1578 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1277 | # if HAVE_SCROLLBARS |
1579 | |
1278 | if (target->scrollBar.win) |
1580 | if (target->scrollBar.win) |
1279 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1581 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1280 | # endif |
|
|
1281 | } |
1582 | } |
1282 | else |
1583 | else |
1283 | # endif |
1584 | # endif |
1284 | { |
1585 | { |
1285 | flags |= isVtOrigin; |
1586 | flags |= isVtOrigin; |
1286 | /* force old pixmap dereference in case it was transparent before :*/ |
1587 | /* force old pixmap dereference in case it was transparent before :*/ |
1287 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1588 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1288 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1589 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1289 | /* do we also need to set scrollbar's background here ? */ |
1590 | /* do we also need to set scrollbar's background here ? */ |
1290 | # if HAVE_SCROLLBARS |
1591 | |
1291 | if (target->scrollBar.win) |
1592 | if (target->scrollBar.win) |
1292 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1593 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1293 | # endif |
|
|
1294 | } |
1594 | } |
1295 | } |
1595 | } |
1296 | else |
1596 | else |
1297 | { |
1597 | { |
1298 | /* set target background to a pixel */ |
1598 | /* set target background to a pixel */ |
1299 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1599 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1300 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1600 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1301 | /* do we also need to set scrollbar's background here ? */ |
1601 | /* do we also need to set scrollbar's background here ? */ |
1302 | # if HAVE_SCROLLBARS |
|
|
1303 | if (target->scrollBar.win) |
1602 | if (target->scrollBar.win) |
1304 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1603 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1305 | # endif |
|
|
1306 | } |
1604 | } |
|
|
1605 | |
1307 | /* don't want Expose on the parent or vt. It is better to use |
1606 | /* don't want Expose on the parent or vt. It is better to use |
1308 | scr_touch or we get a great deal of flicker otherwise: */ |
1607 | scr_touch or we get a great deal of flicker otherwise: */ |
1309 | XClearWindow (target->dpy, target->parent[0]); |
1608 | XClearWindow (target->dpy, target->parent[0]); |
1310 | |
1609 | |
1311 | # if HAVE_SCROLLBARS |
1610 | if (target->scrollBar.state && target->scrollBar.win) |
1312 | if (target->scrollBar.win) |
|
|
1313 | { |
1611 | { |
1314 | target->scrollBar.setIdle (); |
1612 | target->scrollBar.state = STATE_IDLE; |
1315 | target->scrollbar_show (0); |
1613 | target->scrollBar.show (0); |
1316 | } |
1614 | } |
1317 | # endif |
|
|
1318 | |
1615 | |
1319 | target->want_refresh = 1; |
1616 | target->want_refresh = 1; |
1320 | flags |= hasChanged; |
1617 | flags |= hasChanged; |
1321 | } |
1618 | } |
1322 | } |
1619 | } |
… | |
… | |
1327 | /* taken from aterm-0.4.2 */ |
1624 | /* taken from aterm-0.4.2 */ |
1328 | |
1625 | |
1329 | typedef uint32_t RUINT32T; |
1626 | typedef uint32_t RUINT32T; |
1330 | |
1627 | |
1331 | static void |
1628 | static void |
1332 | ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) |
1629 | ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) |
1333 | { |
1630 | { |
1334 | int sh_r, sh_g, sh_b; |
1631 | int sh_r, sh_g, sh_b; |
1335 | RUINT32T mask_r, mask_g, mask_b; |
1632 | RUINT32T mask_r, mask_g, mask_b; |
1336 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1633 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1337 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1634 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
… | |
… | |
1339 | int i; |
1636 | int i; |
1340 | |
1637 | |
1341 | Visual *visual = term->visual; |
1638 | Visual *visual = term->visual; |
1342 | |
1639 | |
1343 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
1640 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
1344 | |
|
|
1345 | if (shade == 0) |
|
|
1346 | shade = 100; |
|
|
1347 | |
1641 | |
1348 | /* for convenience */ |
1642 | /* for convenience */ |
1349 | mask_r = visual->red_mask; |
1643 | mask_r = visual->red_mask; |
1350 | mask_g = visual->green_mask; |
1644 | mask_g = visual->green_mask; |
1351 | mask_b = visual->blue_mask; |
1645 | mask_b = visual->blue_mask; |
… | |
… | |
1407 | default: |
1701 | default: |
1408 | return; /* we do not support this color depth */ |
1702 | return; /* we do not support this color depth */ |
1409 | } |
1703 | } |
1410 | |
1704 | |
1411 | /* prepare limits for color transformation (each channel is handled separately) */ |
1705 | /* prepare limits for color transformation (each channel is handled separately) */ |
1412 | if (shade < 0) { |
1706 | if (shade > 100) { |
1413 | shade = -shade; |
1707 | shade = 200 - shade; |
1414 | if (shade < 0) shade = 0; |
|
|
1415 | if (shade > 100) shade = 100; |
|
|
1416 | |
1708 | |
1417 | lower_lim_r = 65535-rm; |
1709 | lower_lim_r = 65535-rm; |
1418 | lower_lim_g = 65535-gm; |
1710 | lower_lim_g = 65535-gm; |
1419 | lower_lim_b = 65535-bm; |
1711 | lower_lim_b = 65535-bm; |
1420 | |
1712 | |
… | |
… | |
1422 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
1714 | lower_lim_g = 65535-(unsigned int)(((RUINT32T)lower_lim_g)*((RUINT32T)shade)/100); |
1423 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
1715 | lower_lim_b = 65535-(unsigned int)(((RUINT32T)lower_lim_b)*((RUINT32T)shade)/100); |
1424 | |
1716 | |
1425 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1717 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
1426 | } else { |
1718 | } else { |
1427 | if (shade < 0) shade = 0; |
|
|
1428 | if (shade > 100) shade = 100; |
|
|
1429 | |
1719 | |
1430 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1720 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1431 | |
1721 | |
1432 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1722 | upper_lim_r = (unsigned int)((((RUINT32T)rm)*((RUINT32T)shade))/100); |
1433 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |
1723 | upper_lim_g = (unsigned int)((((RUINT32T)gm)*((RUINT32T)shade))/100); |