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) 1997 Carsten Haitzler <raster@zip.com.au> |
|
|
7 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
|
|
8 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
|
|
9 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <pcg@goof.com> |
10 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
11 | * |
8 | * |
12 | * 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 |
13 | * 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 |
14 | * the Free Software Foundation; either version 2 of the License, or |
11 | * the Free Software Foundation; either version 2 of the License, or |
… | |
… | |
28 | #include "rxvt.h" /* NECESSARY */ |
25 | #include "rxvt.h" /* NECESSARY */ |
29 | |
26 | |
30 | #define DO_TIMING_TEST 0 |
27 | #define DO_TIMING_TEST 0 |
31 | |
28 | |
32 | #if DO_TIMING_TEST |
29 | #if DO_TIMING_TEST |
|
|
30 | # include <sys/time.h> |
33 | #define TIMING_TEST_START(id) \ |
31 | #define TIMING_TEST_START(id) \ |
34 | struct timeval timing_test_##id##_stv;\ |
32 | struct timeval timing_test_##id##_stv; \ |
35 | gettimeofday (&timing_test_##id##_stv, NULL); |
33 | gettimeofday (&timing_test_##id##_stv, NULL); |
36 | |
34 | |
37 | #define TIMING_TEST_PRINT_RESULT(id) \ |
35 | #define TIMING_TEST_PRINT_RESULT(id) \ |
38 | 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; \ |
39 | 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__, \ |
40 | 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) |
41 | |
43 | |
42 | #else |
44 | #else |
43 | #define TIMING_TEST_START(id) do{}while (0) |
45 | #define TIMING_TEST_START(id) do {} while (0) |
44 | #define TIMING_TEST_PRINT_RESULT(id) do{}while (0) |
46 | #define TIMING_TEST_PRINT_RESULT(id) do {} while (0) |
45 | #endif |
47 | #endif |
46 | |
48 | |
47 | /* |
49 | /* |
48 | * Pixmap geometry string interpretation : |
50 | * Pixmap geometry string interpretation : |
49 | * Each geometry string contains zero or one scale/position |
51 | * Each geometry string contains zero or one scale/position |
50 | * 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 |
51 | * colon-delimited pixmap operations. |
53 | * colon-delimited pixmap operations. |
52 | * The following table shows the valid geometry strings and their |
54 | * The following table shows the valid geometry strings and their |
53 | * affects on the background image : |
55 | * effects on the background image : |
54 | * |
56 | * |
55 | * 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%. |
56 | * W and H are percentages of the terminal window size. |
58 | * W and H are percentages of the terminal window size. |
57 | * X and Y are also percentages; e.g., +50+50 centers |
59 | * X and Y are also percentages; e.g., +50+50 centers |
58 | * the image in the window. |
60 | * the image in the window. |
59 | * WxH+X Assumes Y == X |
61 | * WxH+X Assumes Y == X |
60 | * WxH Assumes Y == X == 50 (centers the image) |
62 | * WxH Assumes Y == X == 50 (centers the image) |
61 | * W+X+Y Assumes H == W |
63 | * W+X+Y Assumes H == W |
62 | * W+X Assumes H == W and Y == X |
64 | * W+X Assumes H == W and Y == X |
63 | * W Assumes H == W and Y == X == 50 |
65 | * W Assumes H == W and Y == X == 50 |
64 | * |
66 | * |
65 | * Adjusting position only : |
67 | * Adjusting position only : |
66 | * =+X+Y Set position to X% by Y% (absolute). |
68 | * =+X+Y Set position to X% by Y% (absolute). |
67 | * =+X Set position to X% by X%. |
69 | * =+X Set position to X% by X%. |
68 | * +X+Y Adjust position horizontally X% and vertically Y% |
70 | * +X+Y Adjust position horizontally X% and vertically Y% |
69 | * from current position (relative). |
71 | * from current position (relative). |
70 | * +X Adjust position horizontally X% and vertically X% |
72 | * +X Adjust position horizontally X% and vertically X% |
71 | * from current position. |
73 | * from current position. |
72 | * |
74 | * |
73 | * Adjusting scale only : |
75 | * Adjusting scale only : |
74 | * Wx0 Multiply horizontal scaling factor by W% |
76 | * Wx0 Multiply horizontal scaling factor by W% |
75 | * 0xH Multiply vertical scaling factor by H% |
77 | * 0xH Multiply vertical scaling factor by H% |
76 | * 0x0 No scaling (show image at normal size). |
78 | * 0x0 No scaling (show image at normal size). |
77 | * |
79 | * |
78 | * Pixmap Operations : (should be prepended by a colon) |
80 | * Pixmap Operations : (should be prepended by a colon) |
79 | * tile Tile image. Scaling/position modifiers above will affect |
81 | * tile Tile image. Scaling/position modifiers above will affect |
80 | * the tile size and origin. |
82 | * the tile size and origin. |
81 | * propscale When scaling, scale proportionally. That is, maintain the |
83 | * propscale When scaling, scale proportionally. That is, maintain the |
82 | * proper aspect ratio for the image. Any portion of the |
84 | * proper aspect ratio for the image. Any portion of the |
83 | * background not covered by the image is filled with the |
85 | * background not covered by the image is filled with the |
84 | * current background color. |
86 | * current background color. |
85 | * hscale Scale horizontally, tile vertically ? |
87 | * hscale Scale horizontally, tile vertically ? |
86 | * vscale Tile horizontally, scale vertically ? |
88 | * vscale Tile horizontally, scale vertically ? |
87 | * scale Scale both up and down |
89 | * scale Scale both up and down |
88 | * auto Same as 100x100+50+50 |
90 | * auto Same as 100x100+50+50 |
89 | */ |
91 | */ |
90 | |
92 | |
91 | #ifdef HAVE_BG_PIXMAP |
93 | #ifdef HAVE_BG_PIXMAP |
92 | bgPixmap_t::bgPixmap_t() |
94 | bgPixmap_t::bgPixmap_t () |
93 | { |
95 | { |
|
|
96 | // this is basically redundant as bgPixmap_t is only used in |
|
|
97 | // zero_initialised-derived structs |
94 | #ifdef HAVE_AFTERIMAGE |
98 | #ifdef HAVE_AFTERIMAGE |
95 | original_asim = NULL; |
99 | original_asim = NULL; |
96 | #endif |
100 | #endif |
|
|
101 | #ifdef HAVE_PIXBUF |
|
|
102 | pixbuf = NULL; |
|
|
103 | #endif |
97 | #ifdef BG_IMAGE_FROM_FILE |
104 | #ifdef BG_IMAGE_FROM_FILE |
|
|
105 | have_image = false; |
98 | h_scale = v_scale = 0; |
106 | h_scale = v_scale = 0; |
99 | h_align = v_align = 0; |
107 | h_align = v_align = 0; |
100 | #endif |
108 | #endif |
101 | flags = 0; |
109 | flags = 0; |
102 | pixmap = None; |
110 | pixmap = None; |
|
|
111 | valid_since = invalid_since = 0; |
|
|
112 | target = 0; |
103 | } |
113 | } |
104 | |
114 | |
|
|
115 | void |
|
|
116 | bgPixmap_t::destroy () |
|
|
117 | { |
|
|
118 | #ifdef HAVE_AFTERIMAGE |
|
|
119 | if (original_asim) |
|
|
120 | safe_asimage_destroy (original_asim); |
|
|
121 | #endif |
|
|
122 | |
|
|
123 | #ifdef HAVE_PIXBUF |
|
|
124 | if (pixbuf) |
|
|
125 | g_object_unref (pixbuf); |
|
|
126 | #endif |
|
|
127 | |
|
|
128 | if (pixmap && target) |
|
|
129 | XFreePixmap (target->dpy, pixmap); |
|
|
130 | } |
105 | |
131 | |
106 | bool |
132 | bool |
107 | bgPixmap_t::window_size_sensitive () |
133 | bgPixmap_t::window_size_sensitive () |
108 | { |
134 | { |
109 | # ifdef BG_IMAGE_FROM_FILE |
|
|
110 | # ifdef HAVE_AFTERIMAGE |
|
|
111 | if (original_asim != NULL) |
|
|
112 | # endif |
|
|
113 | { |
|
|
114 | if (h_scale != 0 || v_scale != 0 |
|
|
115 | || h_align != 0 || v_align != 0) |
|
|
116 | return true; |
|
|
117 | } |
|
|
118 | # endif |
|
|
119 | # ifdef ENABLE_TRANSPARENCY |
135 | # ifdef ENABLE_TRANSPARENCY |
120 | if (flags & isTransparent) |
136 | if (flags & isTransparent) |
121 | return true; |
137 | return true; |
122 | # endif |
138 | # endif |
|
|
139 | |
|
|
140 | # ifdef BG_IMAGE_FROM_FILE |
|
|
141 | if (have_image) |
|
|
142 | { |
|
|
143 | if (flags & sizeSensitive) |
|
|
144 | return true; |
|
|
145 | } |
|
|
146 | # endif |
|
|
147 | |
123 | return false; |
148 | return false; |
124 | } |
149 | } |
125 | |
150 | |
|
|
151 | bool |
|
|
152 | bgPixmap_t::window_position_sensitive () |
|
|
153 | { |
|
|
154 | # ifdef ENABLE_TRANSPARENCY |
|
|
155 | if (flags & isTransparent) |
|
|
156 | return true; |
|
|
157 | # endif |
|
|
158 | |
|
|
159 | # ifdef BG_IMAGE_FROM_FILE |
|
|
160 | if (have_image) |
|
|
161 | { |
|
|
162 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
163 | return true; |
|
|
164 | } |
|
|
165 | # endif |
|
|
166 | |
|
|
167 | return false; |
|
|
168 | }; |
|
|
169 | |
126 | bool bgPixmap_t::need_client_side_rendering () |
170 | bool bgPixmap_t::need_client_side_rendering () |
127 | { |
171 | { |
128 | # ifdef HAVE_AFTERIMAGE |
172 | # ifdef HAVE_AFTERIMAGE |
129 | if (original_asim != NULL) |
173 | if (original_asim) |
130 | return true; |
174 | return true; |
131 | # endif |
175 | # endif |
132 | # ifdef ENABLE_TRANSPARENCY |
176 | # ifdef ENABLE_TRANSPARENCY |
133 | if (flags & isTransparent) |
177 | if (flags & isTransparent) |
134 | { |
178 | { |
135 | # ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways |
179 | # ifdef HAVE_AFTERIMAGE // can't blur without libAI anyways |
136 | if ((flags & blurNeeded) && !(flags & blurServerSide)) |
180 | if ((flags & blurNeeded) && !(flags & blurServerSide)) |
137 | return true; |
181 | return true; |
138 | # endif |
182 | # endif |
139 | if ((flags & tintNeeded) && !(flags & tintServerSide)) |
183 | if ((flags & tintNeeded) && !(flags & tintServerSide)) |
140 | return true; |
184 | return true; |
141 | } |
185 | } |
142 | # endif |
186 | # endif |
… | |
… | |
163 | static inline bool |
207 | static inline bool |
164 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
208 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
165 | { |
209 | { |
166 | if (geom_flags & flag) |
210 | if (geom_flags & flag) |
167 | { |
211 | { |
|
|
212 | if (new_value != bgPixmap_t::rootAlign) |
|
|
213 | { |
168 | if (new_value < -100) |
214 | if (new_value < -100) |
169 | new_value = -100; |
215 | new_value = -100; |
170 | else if (new_value > 200) |
216 | else if (new_value > 200) |
171 | new_value = 200; |
217 | new_value = 200; |
|
|
218 | } |
172 | if (new_value != align) |
219 | if (new_value != align) |
173 | { |
220 | { |
174 | align = new_value; |
221 | align = new_value; |
175 | return true; |
222 | return true; |
176 | } |
223 | } |
… | |
… | |
180 | |
227 | |
181 | static inline int |
228 | static inline int |
182 | make_align_position (int align, int window_size, int image_size) |
229 | make_align_position (int align, int window_size, int image_size) |
183 | { |
230 | { |
184 | int diff = window_size - image_size; |
231 | int diff = window_size - image_size; |
185 | int smaller = MIN (image_size,window_size); |
232 | int smaller = min (image_size, window_size); |
186 | |
233 | |
187 | if (align >= 0 && align <= 50) |
234 | if (align >= 0 && align <= 50) |
188 | return diff * align / 100; |
235 | return diff * align / 100; |
189 | else if (align > 50 && align <= 100) |
236 | else if (align > 50 && align <= 100) |
190 | return window_size - image_size - diff * (100 - align) / 100; |
237 | return window_size - image_size - diff * (100 - align) / 100; |
… | |
… | |
199 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
246 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
200 | { |
247 | { |
201 | int src_pos = 0; |
248 | int src_pos = 0; |
202 | dst_pos = 0; |
249 | dst_pos = 0; |
203 | dst_size = size; |
250 | dst_size = size; |
204 | if (pos < 0 && size > target_size) |
251 | if (pos < 0) |
205 | { |
252 | { |
206 | src_pos = -pos; |
253 | src_pos = -pos; |
207 | dst_size += pos; |
254 | dst_size += pos; |
208 | } |
255 | } |
209 | else if (pos > 0) |
256 | else if (pos > 0) |
… | |
… | |
220 | int geom_flags = 0, changed = 0; |
267 | int geom_flags = 0, changed = 0; |
221 | int x = 0, y = 0; |
268 | int x = 0, y = 0; |
222 | unsigned int w = 0, h = 0; |
269 | unsigned int w = 0, h = 0; |
223 | unsigned int n; |
270 | unsigned int n; |
224 | unsigned long new_flags = (flags & (~geometryFlags)); |
271 | unsigned long new_flags = (flags & (~geometryFlags)); |
225 | char *p; |
272 | const char *p; |
226 | # define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
273 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
227 | |
274 | |
228 | if (geom == NULL) |
275 | if (geom == NULL) |
229 | return false; |
276 | return false; |
230 | |
277 | |
231 | char str[MAXLEN_GEOM]; |
278 | char str[MAXLEN_GEOM]; |
… | |
… | |
238 | if (n < MAXLEN_GEOM) |
285 | if (n < MAXLEN_GEOM) |
239 | { |
286 | { |
240 | char *ops; |
287 | char *ops; |
241 | new_flags |= geometrySet; |
288 | new_flags |= geometrySet; |
242 | |
289 | |
243 | strncpy (str, geom, n); |
290 | memcpy (str, geom, n); |
244 | str[n] = '\0'; |
291 | str[n] = '\0'; |
245 | if (str[0] == ':') |
292 | if (str[0] == ':') |
246 | ops = &str[0]; |
293 | ops = &str[0]; |
247 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
294 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
248 | ops = &str[0]; |
295 | ops = &str[0]; |
… | |
… | |
268 | y = x; |
315 | y = x; |
269 | geom_flags |= YValue; |
316 | geom_flags |= YValue; |
270 | } |
317 | } |
271 | |
318 | |
272 | if (flags & geometrySet) |
319 | if (flags & geometrySet) |
|
|
320 | { |
273 | {/* new geometry is an adjustment to the old one ! */ |
321 | /* new geometry is an adjustment to the old one ! */ |
274 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
322 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
275 | { |
323 | { |
276 | if (w == 0 && h != 0) |
324 | if (w == 0 && h != 0) |
277 | { |
325 | { |
278 | w = h_scale; |
326 | w = h_scale; |
… | |
… | |
294 | } |
342 | } |
295 | } |
343 | } |
296 | else /* setting up geometry from scratch */ |
344 | else /* setting up geometry from scratch */ |
297 | { |
345 | { |
298 | if (!(geom_flags & XValue)) |
346 | if (!(geom_flags & XValue)) |
|
|
347 | { |
299 | {/* use default geometry - centered */ |
348 | /* use default geometry - centered */ |
300 | x = y = defaultAlign; |
349 | x = y = defaultAlign; |
301 | } |
350 | } |
302 | else if (!(geom_flags & YValue)) |
351 | else if (!(geom_flags & YValue)) |
303 | y = x; |
352 | y = x; |
304 | |
353 | |
305 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
354 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
|
|
355 | { |
306 | {/* use default geometry - scaled */ |
356 | /* use default geometry - scaled */ |
307 | w = h = defaultScale; |
357 | w = h = defaultScale; |
308 | } |
358 | } |
309 | else if (geom_flags & WidthValue) |
359 | else if (geom_flags & WidthValue) |
310 | { |
360 | { |
311 | if (!(geom_flags & HeightValue)) |
361 | if (!(geom_flags & HeightValue)) |
… | |
… | |
314 | else |
364 | else |
315 | w = h; |
365 | w = h; |
316 | } |
366 | } |
317 | } /* done parsing geometry string */ |
367 | } /* done parsing geometry string */ |
318 | else if (!(flags & geometrySet)) |
368 | else if (!(flags & geometrySet)) |
|
|
369 | { |
319 | { /* default geometry - scaled and centered */ |
370 | /* default geometry - scaled and centered */ |
320 | x = y = defaultAlign; |
371 | x = y = defaultAlign; |
321 | w = h = defaultScale; |
372 | w = h = defaultScale; |
322 | } |
373 | } |
323 | |
374 | |
324 | if (!(flags & geometrySet)) |
375 | if (!(flags & geometrySet)) |
325 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
376 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
326 | |
377 | |
327 | if (ops) |
378 | if (ops) |
328 | { |
379 | { |
329 | while (*ops) |
380 | while (*ops) |
330 | { |
381 | { |
331 | while (*ops == ':' || isspace(*ops)) ++ops; |
382 | while (*ops == ':' || isspace(*ops)) ++ops; |
|
|
383 | |
332 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
384 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) |
333 | if (CHECK_GEOM_OPS("tile")) |
385 | if (CHECK_GEOM_OPS ("tile")) |
334 | { |
386 | { |
335 | w = h = 0; |
387 | w = h = noScale; |
336 | geom_flags |= WidthValue|HeightValue; |
388 | geom_flags |= WidthValue|HeightValue; |
337 | } |
389 | } |
338 | else if (CHECK_GEOM_OPS("propscale")) |
390 | else if (CHECK_GEOM_OPS ("propscale")) |
339 | { |
391 | { |
340 | if (w == 0 && h == 0) |
|
|
341 | { |
|
|
342 | w = 100; |
|
|
343 | geom_flags |= WidthValue; |
|
|
344 | } |
|
|
345 | new_flags |= propScale; |
392 | new_flags |= propScale; |
346 | } |
393 | } |
347 | else if (CHECK_GEOM_OPS("hscale")) |
394 | else if (CHECK_GEOM_OPS ("hscale")) |
348 | { |
395 | { |
349 | if (w == 0) |
396 | if (w == 0) w = windowScale; |
350 | w = 100; |
397 | |
351 | h = 0; |
398 | h = noScale; |
352 | geom_flags |= WidthValue|HeightValue; |
399 | geom_flags |= WidthValue|HeightValue; |
353 | } |
400 | } |
354 | else if (CHECK_GEOM_OPS("vscale")) |
401 | else if (CHECK_GEOM_OPS ("vscale")) |
355 | { |
402 | { |
356 | if (h == 0) |
403 | if (h == 0) h = windowScale; |
357 | h = 100; |
404 | |
358 | w = 0; |
405 | w = noScale; |
359 | geom_flags |= WidthValue|HeightValue; |
406 | geom_flags |= WidthValue|HeightValue; |
360 | } |
407 | } |
361 | else if (CHECK_GEOM_OPS("scale")) |
408 | else if (CHECK_GEOM_OPS ("scale")) |
362 | { |
409 | { |
363 | if (h == 0) |
410 | if (h == 0) h = windowScale; |
364 | h = 100; |
|
|
365 | if (w == 0) |
411 | if (w == 0) w = windowScale; |
366 | w = 100; |
412 | |
367 | geom_flags |= WidthValue|HeightValue; |
413 | geom_flags |= WidthValue|HeightValue; |
368 | } |
414 | } |
369 | else if (CHECK_GEOM_OPS("auto")) |
415 | else if (CHECK_GEOM_OPS ("auto")) |
370 | { |
416 | { |
|
|
417 | w = h = windowScale; |
|
|
418 | x = y = centerAlign; |
|
|
419 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
420 | } |
|
|
421 | else if (CHECK_GEOM_OPS ("root")) |
|
|
422 | { |
371 | w = h = 100; |
423 | w = h = noScale; |
372 | x = y = 50; |
424 | x = y = rootAlign; |
373 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
425 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
374 | } |
426 | } |
375 | # undef CHECK_GEOM_OPS |
427 | # undef CHECK_GEOM_OPS |
|
|
428 | |
376 | while (*ops != ':' && *ops != '\0') ++ops; |
429 | while (*ops != ':' && *ops != '\0') ++ops; |
377 | } /* done parsing ops */ |
430 | } /* done parsing ops */ |
378 | } |
431 | } |
379 | |
432 | |
380 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) |
433 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; |
381 | ++changed; |
|
|
382 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) |
434 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; |
383 | ++changed; |
|
|
384 | if (check_set_align_value (geom_flags, XValue, h_align, x)) |
435 | if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; |
385 | ++changed; |
|
|
386 | if (check_set_align_value (geom_flags, YValue, v_align, y)) |
436 | if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; |
387 | ++changed; |
|
|
388 | } |
437 | } |
389 | |
438 | |
390 | if (new_flags != flags) |
439 | if (new_flags != flags) |
391 | { |
440 | { |
392 | flags = new_flags; |
441 | flags = new_flags; |
393 | changed++; |
442 | changed++; |
394 | } |
443 | } |
|
|
444 | |
395 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
445 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
396 | // flags, h_scale, v_scale, h_align, v_align); |
446 | // flags, h_scale, v_scale, h_align, v_align); |
397 | return (changed > 0); |
447 | return (changed > 0); |
|
|
448 | } |
|
|
449 | |
|
|
450 | void |
|
|
451 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
|
|
452 | { |
|
|
453 | int target_width = target->szHint.width; |
|
|
454 | int target_height = target->szHint.height; |
|
|
455 | |
|
|
456 | if (flags & propScale) |
|
|
457 | { |
|
|
458 | float scale = (float)target_width / image_width; |
|
|
459 | min_it (scale, (float)target_height / image_height); |
|
|
460 | w = image_width * scale + 0.5; |
|
|
461 | h = image_height * scale + 0.5; |
|
|
462 | } |
|
|
463 | else |
|
|
464 | { |
|
|
465 | w = h_scale * target_width / 100; |
|
|
466 | h = v_scale * target_height / 100; |
|
|
467 | } |
|
|
468 | |
|
|
469 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
470 | { |
|
|
471 | target->get_window_origin (x, y); |
|
|
472 | x = -x; |
|
|
473 | y = -y; |
|
|
474 | } |
|
|
475 | |
|
|
476 | if (h_align != rootAlign) |
|
|
477 | x = make_align_position (h_align, target_width, w > 0 ? w : image_width); |
|
|
478 | |
|
|
479 | if (v_align != rootAlign) |
|
|
480 | y = make_align_position (v_align, target_height, h > 0 ? h : image_height); |
|
|
481 | |
|
|
482 | flags &= ~sizeSensitive; |
|
|
483 | if (h_scale != 0 || v_scale != 0 |
|
|
484 | || h_align != 0 || v_align != 0 |
|
|
485 | || image_width > target_width || image_height > target_height) |
|
|
486 | flags |= sizeSensitive; |
398 | } |
487 | } |
399 | |
488 | |
400 | # ifdef HAVE_AFTERIMAGE |
489 | # ifdef HAVE_AFTERIMAGE |
401 | bool |
490 | bool |
402 | bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) |
491 | bgPixmap_t::render_image (unsigned long background_flags) |
403 | { |
492 | { |
404 | if (target == NULL) |
493 | if (target == NULL) |
405 | return false; |
494 | return false; |
406 | |
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 == 0) ? 100 : 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 & transpPmapBlured) && (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 | |
407 | int target_width = (int)target->szHint.width; |
535 | int target_width = target->szHint.width; |
408 | int target_height = (int)target->szHint.height; |
536 | int target_height = target->szHint.height; |
409 | int new_pmap_width = target_width, new_pmap_height = target_height; |
537 | int new_pmap_width = target_width; |
410 | ASImage *result = NULL; |
538 | int new_pmap_height = target_height; |
411 | |
539 | |
412 | int x = 0; |
540 | int x = 0; |
413 | int y = 0; |
541 | int y = 0; |
414 | int w = h_scale * target_width / 100; |
542 | int w = 0; |
415 | int h = v_scale * target_height / 100; |
543 | int h = 0; |
416 | |
544 | |
417 | TIMING_TEST_START (asim); |
545 | TIMING_TEST_START (asim); |
418 | |
546 | |
419 | if (original_asim) |
547 | if (original_asim) |
420 | { |
548 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
421 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
422 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
|
|
423 | } |
|
|
424 | |
549 | |
425 | if (original_asim == NULL |
550 | if (!original_asim |
426 | || x >= target_width |
551 | || x >= target_width |
427 | || y >= target_height |
552 | || y >= target_height |
428 | || (w > 0 && x + w <= 0) |
553 | || (w > 0 && x + w <= 0) |
429 | || (h > 0 && y + h <= 0)) |
554 | || (h > 0 && y + h <= 0)) |
430 | { |
555 | { |
431 | if (background) |
556 | if (background) |
432 | { |
557 | { |
433 | new_pmap_width = background->width; |
558 | new_pmap_width = background->width; |
434 | new_pmap_height = background->height; |
559 | new_pmap_height = background->height; |
435 | result = background; |
560 | result = background; |
|
|
561 | |
436 | if (background_tint != TINT_LEAVE_SAME) |
562 | if (background_tint != TINT_LEAVE_SAME) |
437 | { |
563 | { |
438 | ASImage* tmp = tile_asimage (target->asv, background, 0, 0, |
564 | ASImage *tmp = tile_asimage (target->asv, background, 0, 0, |
439 | target_width, target_height, background_tint, |
565 | target_width, target_height, background_tint, |
440 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
566 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
441 | if (tmp) |
567 | if (tmp) |
442 | result = tmp; |
568 | result = tmp; |
443 | } |
569 | } |
… | |
… | |
446 | new_pmap_width = new_pmap_height = 0; |
572 | new_pmap_width = new_pmap_height = 0; |
447 | } |
573 | } |
448 | else |
574 | else |
449 | { |
575 | { |
450 | result = original_asim; |
576 | result = original_asim; |
|
|
577 | |
451 | if ((w > 0 && w != original_asim->width) |
578 | if ((w > 0 && w != original_asim->width) |
452 | || (h > 0 && h != original_asim->height)) |
579 | || (h > 0 && h != original_asim->height)) |
453 | { |
580 | { |
454 | result = scale_asimage (target->asv, original_asim, |
581 | result = scale_asimage (target->asv, original_asim, |
455 | w > 0 ? w : original_asim->width, |
582 | w > 0 ? w : original_asim->width, |
456 | h > 0 ? h : original_asim->height, |
583 | h > 0 ? h : original_asim->height, |
457 | background ? ASA_ASImage : ASA_XImage, |
584 | background ? ASA_ASImage : ASA_XImage, |
458 | 100, ASIMAGE_QUALITY_DEFAULT); |
585 | 100, ASIMAGE_QUALITY_DEFAULT); |
459 | } |
586 | } |
|
|
587 | |
460 | if (background == NULL) |
588 | if (background == NULL) |
461 | {/* if tiling - pixmap has to be sized exactly as the image */ |
589 | { |
462 | if (h_scale == 0) |
|
|
463 | new_pmap_width = result->width; |
|
|
464 | if (v_scale == 0) |
|
|
465 | new_pmap_height = result->height; |
|
|
466 | /* we also need to tile our image in one or both directions */ |
|
|
467 | if (h_scale == 0 || v_scale == 0) |
590 | if (h_scale == 0 || v_scale == 0) |
468 | { |
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 */ |
469 | ASImage *tmp = tile_asimage (target->asv, result, |
598 | ASImage *tmp = tile_asimage (target->asv, result, |
470 | (h_scale > 0) ? 0 : (int)result->width - x, |
599 | (int)result->width - x, |
471 | (v_scale > 0) ? 0 : (int)result->height - y, |
600 | (int)result->height - y, |
|
|
601 | new_pmap_width, |
472 | result->width, result->height, |
602 | new_pmap_height, |
473 | TINT_LEAVE_SAME, ASA_XImage, |
603 | TINT_LEAVE_SAME, ASA_XImage, |
474 | 100, ASIMAGE_QUALITY_DEFAULT); |
604 | 100, ASIMAGE_QUALITY_DEFAULT); |
475 | if (tmp) |
605 | if (tmp) |
476 | { |
606 | { |
477 | if (result != original_asim) |
607 | if (result != original_asim) |
478 | destroy_asimage (&result); |
608 | destroy_asimage (&result); |
|
|
609 | |
479 | result = tmp; |
610 | result = tmp; |
480 | } |
611 | } |
481 | } |
612 | } |
482 | } |
613 | } |
483 | else |
614 | else |
|
|
615 | { |
484 | {/* 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 */ |
485 | ASImageLayer *layers = create_image_layers (2); |
617 | ASImageLayer *layers = create_image_layers (2); |
486 | ASImage *merged_im = NULL; |
|
|
487 | |
618 | |
488 | layers[0].im = background; |
619 | layers[0].im = background; |
489 | layers[0].clip_width = target_width; |
620 | layers[0].clip_width = target_width; |
490 | layers[0].clip_height = target_height; |
621 | layers[0].clip_height = target_height; |
491 | layers[0].tint = background_tint; |
622 | layers[0].tint = background_tint; |
492 | layers[1].im = result; |
623 | layers[1].im = result; |
|
|
624 | |
493 | if (w <= 0) |
625 | if (w <= 0) |
|
|
626 | { |
494 | {/* tile horizontally */ |
627 | /* tile horizontally */ |
495 | while (x > 0) x -= (int)result->width; |
628 | while (x > 0) x -= (int)result->width; |
496 | layers[1].dst_x = x; |
629 | layers[1].dst_x = x; |
497 | layers[1].clip_width = result->width+target_width; |
630 | layers[1].clip_width = result->width+target_width; |
498 | } |
631 | } |
499 | else |
632 | else |
|
|
633 | { |
500 | {/* clip horizontally */ |
634 | /* clip horizontally */ |
501 | layers[1].dst_x = x; |
635 | layers[1].dst_x = x; |
502 | layers[1].clip_width = result->width; |
636 | layers[1].clip_width = result->width; |
503 | } |
637 | } |
|
|
638 | |
504 | if (h <= 0) |
639 | if (h <= 0) |
505 | { |
640 | { |
506 | while (y > 0) y -= (int)result->height; |
641 | while (y > 0) y -= (int)result->height; |
507 | layers[1].dst_y = y; |
642 | layers[1].dst_y = y; |
508 | layers[1].clip_height = result->height + target_height; |
643 | layers[1].clip_height = result->height + target_height; |
… | |
… | |
510 | else |
645 | else |
511 | { |
646 | { |
512 | layers[1].dst_y = y; |
647 | layers[1].dst_y = y; |
513 | layers[1].clip_height = result->height; |
648 | layers[1].clip_height = result->height; |
514 | } |
649 | } |
|
|
650 | |
515 | if (target->rs[Rs_blendtype]) |
651 | if (target->rs[Rs_blendtype]) |
516 | { |
652 | { |
517 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
653 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
518 | if (layers[1].merge_scanlines == NULL) |
654 | if (layers[1].merge_scanlines == NULL) |
519 | layers[1].merge_scanlines = alphablend_scanlines; |
655 | layers[1].merge_scanlines = alphablend_scanlines; |
520 | } |
656 | } |
|
|
657 | |
521 | 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, |
522 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
659 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
660 | |
523 | if (tmp) |
661 | if (tmp) |
524 | { |
662 | { |
525 | if (result != original_asim) |
663 | if (result != original_asim) |
526 | destroy_asimage (&result); |
664 | destroy_asimage (&result); |
|
|
665 | |
527 | result = tmp; |
666 | result = tmp; |
528 | } |
667 | } |
|
|
668 | |
529 | free (layers); |
669 | free (layers); |
530 | } |
670 | } |
531 | } |
671 | } |
532 | TIMING_TEST_PRINT_RESULT (asim); |
672 | TIMING_TEST_PRINT_RESULT (asim); |
533 | |
673 | |
534 | if (pixmap) |
674 | bool ret = false; |
535 | { |
|
|
536 | if (result == NULL |
|
|
537 | || pmap_width != new_pmap_width |
|
|
538 | || pmap_height != new_pmap_height |
|
|
539 | || pmap_depth != target->depth) |
|
|
540 | { |
|
|
541 | XFreePixmap (target->dpy, pixmap); |
|
|
542 | pixmap = None; |
|
|
543 | } |
|
|
544 | } |
|
|
545 | |
675 | |
546 | if (result) |
676 | if (result) |
547 | { |
677 | { |
548 | XGCValues gcv; |
678 | XGCValues gcv; |
549 | 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 | } |
550 | |
691 | |
551 | /* create Pixmap */ |
692 | /* create Pixmap */ |
552 | if (pixmap == None) |
693 | if (pixmap == None) |
553 | { |
694 | { |
554 | 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); |
555 | pmap_width = new_pmap_width; |
696 | pmap_width = new_pmap_width; |
556 | pmap_height = new_pmap_height; |
697 | pmap_height = new_pmap_height; |
557 | pmap_depth = target->depth; |
698 | pmap_depth = target->depth; |
558 | } |
699 | } |
559 | /* fill with background color ( if result's not completely overlapping it)*/ |
700 | /* fill with background color (if result's not completely overlapping it) */ |
560 | gcv.foreground = target->pix_colors[Color_bg]; |
701 | gcv.foreground = target->pix_colors[Color_bg]; |
561 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
702 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
562 | |
703 | |
563 | 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; |
564 | int dst_width = result->width, dst_height = result->height; |
705 | int dst_width = result->width, dst_height = result->height; |
565 | if (background == NULL) |
706 | if (background == NULL) |
566 | { |
707 | { |
567 | if (h_scale > 0) |
708 | if (!(h_scale == 0 || v_scale == 0)) |
|
|
709 | { |
568 | 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 ); |
569 | if (v_scale > 0) |
|
|
570 | 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 | } |
571 | |
713 | |
572 | if (dst_x > 0 || dst_y > 0 |
714 | if (dst_x > 0 || dst_y > 0 |
573 | || dst_x + dst_width < new_pmap_width |
715 | || dst_x + dst_width < new_pmap_width |
574 | || dst_y + dst_height < new_pmap_height) |
716 | || dst_y + dst_height < new_pmap_height) |
575 | { |
|
|
576 | 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); |
577 | } |
|
|
578 | } |
718 | } |
579 | |
719 | |
580 | /* put result on pixmap */ |
720 | /* put result on pixmap */ |
581 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
721 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
582 | 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); |
583 | |
723 | |
584 | if (result != background && result != original_asim) |
724 | if (result != background && result != original_asim) |
585 | destroy_asimage (&result); |
725 | destroy_asimage (&result); |
586 | |
726 | |
587 | XFreeGC (target->dpy, gc); |
727 | XFreeGC (target->dpy, gc); |
588 | TIMING_TEST_PRINT_RESULT (asim); |
728 | TIMING_TEST_PRINT_RESULT (asim); |
589 | } |
|
|
590 | |
729 | |
|
|
730 | ret = true; |
|
|
731 | } |
|
|
732 | |
|
|
733 | if (background) |
|
|
734 | destroy_asimage (&background); |
|
|
735 | |
591 | return true; |
736 | return ret; |
592 | } |
737 | } |
593 | # 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 | // TODO: add alpha blending |
|
|
751 | if (background_flags) |
|
|
752 | return false; |
|
|
753 | |
|
|
754 | GdkPixbuf *result; |
|
|
755 | |
|
|
756 | int image_width = gdk_pixbuf_get_width (pixbuf); |
|
|
757 | int image_height = gdk_pixbuf_get_height (pixbuf); |
|
|
758 | |
|
|
759 | int target_width = target->szHint.width; |
|
|
760 | int target_height = target->szHint.height; |
|
|
761 | int new_pmap_width = target_width; |
|
|
762 | int new_pmap_height = target_height; |
|
|
763 | |
|
|
764 | int x = 0; |
|
|
765 | int y = 0; |
|
|
766 | int w = 0; |
|
|
767 | int h = 0; |
|
|
768 | |
|
|
769 | get_image_geometry (image_width, image_height, w, h, x, y); |
|
|
770 | |
|
|
771 | if (x >= target_width |
|
|
772 | || y >= target_height |
|
|
773 | || (w > 0 && x + w <= 0) |
|
|
774 | || (h > 0 && y + h <= 0)) |
|
|
775 | return false; |
|
|
776 | |
|
|
777 | result = pixbuf; |
|
|
778 | |
|
|
779 | if ((w > 0 && w != image_width) |
|
|
780 | || (h > 0 && h != image_height)) |
|
|
781 | { |
|
|
782 | result = gdk_pixbuf_scale_simple (pixbuf, |
|
|
783 | w > 0 ? w : image_width, |
|
|
784 | h > 0 ? h : image_height, |
|
|
785 | GDK_INTERP_BILINEAR); |
|
|
786 | } |
|
|
787 | |
|
|
788 | bool ret = false; |
|
|
789 | |
|
|
790 | if (result) |
|
|
791 | { |
|
|
792 | XGCValues gcv; |
|
|
793 | GC gc; |
|
|
794 | |
|
|
795 | image_width = gdk_pixbuf_get_width (result); |
|
|
796 | image_height = gdk_pixbuf_get_height (result); |
|
|
797 | |
|
|
798 | if (h_scale == 0 || v_scale == 0) |
|
|
799 | { |
|
|
800 | new_pmap_width = min (image_width, target_width); |
|
|
801 | new_pmap_height = min (image_height, target_height); |
|
|
802 | } |
|
|
803 | |
|
|
804 | if (pixmap) |
|
|
805 | { |
|
|
806 | if (pmap_width != new_pmap_width |
|
|
807 | || pmap_height != new_pmap_height |
|
|
808 | || pmap_depth != target->depth) |
|
|
809 | { |
|
|
810 | XFreePixmap (target->dpy, pixmap); |
|
|
811 | pixmap = None; |
|
|
812 | } |
|
|
813 | } |
|
|
814 | |
|
|
815 | if (pixmap == None) |
|
|
816 | { |
|
|
817 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
|
|
818 | pmap_width = new_pmap_width; |
|
|
819 | pmap_height = new_pmap_height; |
|
|
820 | pmap_depth = target->depth; |
|
|
821 | } |
|
|
822 | |
|
|
823 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
824 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
825 | |
|
|
826 | if (h_scale == 0 || v_scale == 0) |
|
|
827 | { |
|
|
828 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
|
|
829 | gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, |
|
|
830 | 0, 0, |
|
|
831 | 0, 0, |
|
|
832 | image_width, image_height, |
|
|
833 | XLIB_RGB_DITHER_NONE, |
|
|
834 | 0, 0); |
|
|
835 | |
|
|
836 | gcv.tile = tile; |
|
|
837 | gcv.fill_style = FillTiled; |
|
|
838 | gcv.ts_x_origin = x; |
|
|
839 | gcv.ts_y_origin = y; |
|
|
840 | XChangeGC (target->dpy, gc, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
|
|
841 | |
|
|
842 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
843 | XFreePixmap (target->dpy, tile); |
|
|
844 | } |
|
|
845 | else |
|
|
846 | { |
|
|
847 | int src_x, src_y, dst_x, dst_y; |
|
|
848 | int dst_width, dst_height; |
|
|
849 | |
|
|
850 | src_x = make_clip_rectangle (x, image_width , new_pmap_width , dst_x, dst_width ); |
|
|
851 | src_y = make_clip_rectangle (y, image_height, new_pmap_height, dst_y, dst_height); |
|
|
852 | |
|
|
853 | if (dst_x > 0 || dst_y > 0 |
|
|
854 | || dst_x + dst_width < new_pmap_width |
|
|
855 | || dst_y + dst_height < new_pmap_height) |
|
|
856 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
857 | |
|
|
858 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
|
|
859 | gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, |
|
|
860 | src_x, src_y, |
|
|
861 | dst_x, dst_y, |
|
|
862 | dst_width, dst_height, |
|
|
863 | XLIB_RGB_DITHER_NONE, |
|
|
864 | 0, 0); |
|
|
865 | } |
|
|
866 | |
|
|
867 | if (result != pixbuf) |
|
|
868 | g_object_unref (result); |
|
|
869 | |
|
|
870 | XFreeGC (target->dpy, gc); |
|
|
871 | |
|
|
872 | ret = true; |
|
|
873 | } |
|
|
874 | |
|
|
875 | return ret; |
|
|
876 | } |
|
|
877 | # endif /* HAVE_PIXBUF */ |
594 | |
878 | |
595 | bool |
879 | bool |
596 | bgPixmap_t::set_file (const char *file) |
880 | bgPixmap_t::set_file (const char *file) |
597 | { |
881 | { |
598 | char *f; |
|
|
599 | |
|
|
600 | assert (file != NULL); |
882 | assert (file); |
601 | |
883 | |
602 | if (*file != '\0') |
884 | if (*file) |
603 | { |
885 | { |
|
|
886 | if (const char *p = strchr (file, ';')) |
|
|
887 | { |
|
|
888 | size_t len = p - file; |
|
|
889 | char *f = rxvt_temp_buf<char> (len + 1); |
|
|
890 | memcpy (f, file, len); |
|
|
891 | f[len] = '\0'; |
|
|
892 | file = f; |
|
|
893 | } |
|
|
894 | |
604 | # ifdef HAVE_AFTERIMAGE |
895 | # ifdef HAVE_AFTERIMAGE |
605 | if (target->asimman == NULL) |
896 | if (!target->asimman) |
606 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
897 | target->asimman = create_generic_imageman (target->rs[Rs_path]); |
607 | if ((f = strchr (file, ';')) == NULL) |
|
|
608 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
898 | original_asim = get_asimage (target->asimman, file, 0xFFFFFFFF, 100); |
609 | else |
899 | if (original_asim) |
610 | { |
900 | have_image = true; |
611 | size_t len = f - file; |
901 | return have_image; |
612 | f = (char *)malloc (len + 1); |
|
|
613 | strncpy (f, file, len); |
|
|
614 | f[len] = '\0'; |
|
|
615 | original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); |
|
|
616 | free (f); |
|
|
617 | } |
|
|
618 | return (original_asim != NULL); |
|
|
619 | # endif |
902 | # endif |
|
|
903 | |
|
|
904 | # ifdef HAVE_PIXBUF |
|
|
905 | pixbuf = gdk_pixbuf_new_from_file (file, NULL); |
|
|
906 | if (pixbuf) |
|
|
907 | have_image = true; |
|
|
908 | return have_image; |
|
|
909 | # endif |
620 | } |
910 | } |
|
|
911 | |
621 | return false; |
912 | return false; |
622 | } |
913 | } |
623 | |
914 | |
624 | # endif /* BG_IMAGE_FROM_FILE */ |
915 | # endif /* BG_IMAGE_FROM_FILE */ |
625 | |
916 | |
626 | # ifdef ENABLE_TRANSPARENCY |
917 | # ifdef ENABLE_TRANSPARENCY |
627 | bool |
918 | bool |
628 | bgPixmap_t::set_transparent () |
919 | bgPixmap_t::set_transparent () |
629 | { |
920 | { |
630 | if (!(flags & isTransparent)) |
921 | if (!(flags & isTransparent)) |
631 | { |
922 | { |
632 | flags |= isTransparent; |
923 | flags |= isTransparent; |
633 | return true; |
924 | return true; |
634 | } |
925 | } |
|
|
926 | |
635 | return false; |
927 | return false; |
636 | } |
928 | } |
637 | |
929 | |
638 | bool |
930 | bool |
639 | bgPixmap_t::set_blur_radius (const char *geom) |
931 | bgPixmap_t::set_blur_radius (const char *geom) |
… | |
… | |
641 | int changed = 0; |
933 | int changed = 0; |
642 | unsigned int hr, vr; |
934 | unsigned int hr, vr; |
643 | int junk; |
935 | int junk; |
644 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
936 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
645 | |
937 | |
646 | if (!(geom_flags&WidthValue)) |
938 | if (!(geom_flags & WidthValue)) |
647 | hr = 1; |
939 | hr = 1; |
648 | if (!(geom_flags&HeightValue)) |
940 | if (!(geom_flags & HeightValue)) |
649 | vr = hr; |
941 | vr = hr; |
650 | |
942 | |
651 | if (h_blurRadius != hr) |
943 | if (h_blurRadius != hr) |
652 | { |
944 | { |
653 | ++changed; |
945 | ++changed; |
… | |
… | |
657 | if (v_blurRadius != vr) |
949 | if (v_blurRadius != vr) |
658 | { |
950 | { |
659 | ++changed; |
951 | ++changed; |
660 | v_blurRadius = vr; |
952 | v_blurRadius = vr; |
661 | } |
953 | } |
662 | |
954 | |
663 | if (v_blurRadius == 0 && h_blurRadius == 0) |
955 | if (v_blurRadius == 0 && h_blurRadius == 0) |
664 | flags &= ~blurNeeded; |
956 | flags &= ~blurNeeded; |
665 | else |
957 | else |
666 | flags |= blurNeeded; |
958 | flags |= blurNeeded; |
667 | |
959 | |
668 | return (changed>0); |
960 | return (changed > 0); |
669 | } |
961 | } |
670 | |
962 | |
671 | static inline unsigned long |
963 | static inline unsigned long |
672 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
964 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
673 | { |
965 | { |
… | |
… | |
690 | flags |= bgPixmap_t::tintNeeded; |
982 | flags |= bgPixmap_t::tintNeeded; |
691 | else if (tint) |
983 | else if (tint) |
692 | { |
984 | { |
693 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
985 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
694 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
986 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
695 | { |
987 | { |
696 | flags |= bgPixmap_t::tintNeeded; |
988 | flags |= bgPixmap_t::tintNeeded; |
697 | } |
989 | } |
698 | } |
|
|
699 | |
990 | } |
|
|
991 | |
700 | if (flags & bgPixmap_t::tintNeeded) |
992 | if (flags & bgPixmap_t::tintNeeded) |
701 | { |
993 | { |
702 | if (flags & bgPixmap_t::tintWholesome) |
994 | if (flags & bgPixmap_t::tintWholesome) |
703 | flags |= bgPixmap_t::tintServerSide; |
995 | flags |= bgPixmap_t::tintServerSide; |
704 | else |
996 | else |
… | |
… | |
720 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
1012 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
721 | tint = new_tint; |
1013 | tint = new_tint; |
722 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
1014 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
723 | return true; |
1015 | return true; |
724 | } |
1016 | } |
|
|
1017 | |
725 | return false; |
1018 | return false; |
726 | } |
1019 | } |
727 | |
1020 | |
728 | bool |
1021 | bool |
729 | bgPixmap_t::unset_tint () |
1022 | bgPixmap_t::unset_tint () |
730 | { |
1023 | { |
731 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
1024 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
732 | |
1025 | |
733 | if (new_flags != (flags & tintFlags)) |
1026 | if (new_flags != (flags & tintFlags)) |
734 | { |
1027 | { |
735 | flags = (flags&~tintFlags)|new_flags; |
1028 | flags = (flags & ~tintFlags) | new_flags; |
736 | return true; |
1029 | return true; |
737 | } |
1030 | } |
|
|
1031 | |
738 | return false; |
1032 | return false; |
739 | } |
1033 | } |
740 | |
1034 | |
741 | bool |
1035 | bool |
742 | bgPixmap_t::set_shade (const char *shade_str) |
1036 | bgPixmap_t::set_shade (const char *shade_str) |
743 | { |
1037 | { |
744 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
1038 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
745 | |
1039 | |
|
|
1040 | if (new_shade < 0 && new_shade > -100) |
|
|
1041 | new_shade = 200 - (100 + new_shade); |
746 | if (new_shade == 100) |
1042 | else if (new_shade == 100) |
747 | new_shade = 0; |
1043 | new_shade = 0; |
748 | |
1044 | |
749 | if (new_shade != shade) |
1045 | if (new_shade != shade) |
750 | { |
1046 | { |
751 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
1047 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
752 | shade = new_shade; |
1048 | shade = new_shade; |
753 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
1049 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
754 | return true; |
1050 | return true; |
755 | } |
1051 | } |
|
|
1052 | |
756 | return false; |
1053 | return false; |
757 | } |
1054 | } |
758 | |
1055 | |
759 | /* make_transparency_pixmap() |
1056 | /* make_transparency_pixmap() |
760 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
1057 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
761 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
1058 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
762 | * our window. |
1059 | * our window. |
763 | */ |
1060 | */ |
764 | unsigned long |
1061 | unsigned long |
765 | bgPixmap_t::make_transparency_pixmap () |
1062 | bgPixmap_t::make_transparency_pixmap () |
766 | { |
1063 | { |
767 | unsigned long result = 0; |
1064 | unsigned long result = 0; |
768 | |
1065 | |
769 | if (target == NULL) |
1066 | if (target == NULL) |
770 | return 0; |
1067 | return 0; |
771 | |
1068 | |
772 | /* root dimentions may change from call to call - but Display structure should |
1069 | /* root dimensions may change from call to call - but Display structure should |
773 | * be always up-to-date, so let's use it : |
1070 | * be always up-to-date, so let's use it : |
774 | */ |
1071 | */ |
775 | Window root = target->display->root; |
1072 | Window root = target->display->root; |
776 | int screen = target->display->screen; |
1073 | int screen = target->display->screen; |
777 | Display *dpy = target->dpy; |
1074 | Display *dpy = target->dpy; |
… | |
… | |
790 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1087 | if (sx + window_width <= 0 || sy + window_height <= 0 |
791 | || sx >= root_width || sy >= root_height) |
1088 | || sx >= root_width || sy >= root_height) |
792 | return 0; |
1089 | return 0; |
793 | |
1090 | |
794 | if (root_pixmap != None) |
1091 | if (root_pixmap != None) |
|
|
1092 | { |
795 | {/* we want to validate the pixmap and get it's size at the same time : */ |
1093 | /* we want to validate the pixmap and get it's size at the same time : */ |
796 | int junk; |
1094 | int junk; |
797 | unsigned int ujunk; |
1095 | unsigned int ujunk; |
798 | /* root pixmap may be bad - allow a error */ |
1096 | /* root pixmap may be bad - allow a error */ |
799 | target->allowedxerror = -1; |
1097 | target->allowedxerror = -1; |
800 | |
1098 | |
… | |
… | |
809 | |
1107 | |
810 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1108 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
811 | return 0; |
1109 | return 0; |
812 | |
1110 | |
813 | if (root_pixmap == None) |
1111 | if (root_pixmap == None) |
|
|
1112 | { |
814 | { /* use tricks to obtain the root background image :*/ |
1113 | /* use tricks to obtain the root background image :*/ |
815 | /* we want to create Overrideredirect window overlapping out window |
1114 | /* we want to create Overrideredirect window overlapping out window |
816 | with background type of Parent Relative and then grab it */ |
1115 | with background type of Parent Relative and then grab it */ |
817 | XSetWindowAttributes attr; |
1116 | XSetWindowAttributes attr; |
818 | Window src; |
1117 | Window src; |
819 | bool success = false; |
1118 | bool success = false; |
820 | |
1119 | |
821 | attr.background_pixmap = ParentRelative; |
1120 | attr.background_pixmap = ParentRelative; |
822 | attr.backing_store = Always; |
1121 | attr.backing_store = Always; |
823 | attr.event_mask = ExposureMask; |
1122 | attr.event_mask = ExposureMask; |
824 | attr.override_redirect = True; |
1123 | attr.override_redirect = True; |
825 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
1124 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
826 | CopyFromParent, CopyFromParent, CopyFromParent, |
1125 | CopyFromParent, CopyFromParent, CopyFromParent, |
827 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
1126 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
828 | &attr); |
1127 | &attr); |
829 | |
1128 | |
830 | if (src != None) |
1129 | if (src != None) |
… | |
… | |
834 | XGrabServer (dpy); |
1133 | XGrabServer (dpy); |
835 | XMapRaised (dpy, src); |
1134 | XMapRaised (dpy, src); |
836 | XSync (dpy, False); |
1135 | XSync (dpy, False); |
837 | |
1136 | |
838 | /* XSync should get window where it's properly exposed, |
1137 | /* XSync should get window where it's properly exposed, |
839 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
1138 | * but to be on the safe side - let's check for the actual event to arrive : */ |
840 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
1139 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
841 | ++ev_count; |
1140 | ++ev_count; |
842 | |
1141 | |
843 | if (ev_count > 0); |
1142 | if (ev_count > 0); |
|
|
1143 | { |
844 | { /* hooray! - we can grab the image! */ |
1144 | /* hooray! - we can grab the image! */ |
845 | gc = XCreateGC (dpy, root, 0, NULL); |
1145 | gc = XCreateGC (dpy, root, 0, NULL); |
846 | if (gc) |
1146 | if (gc) |
847 | { |
1147 | { |
848 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
1148 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
849 | success = true; |
1149 | success = true; |
850 | } |
1150 | } |
851 | } |
1151 | } |
|
|
1152 | |
852 | XDestroyWindow (dpy, src); |
1153 | XDestroyWindow (dpy, src); |
853 | XUngrabServer (dpy); |
1154 | XUngrabServer (dpy); |
854 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
1155 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
855 | } |
1156 | } |
856 | |
1157 | |
857 | if (!success) |
1158 | if (!success) |
858 | { |
1159 | { |
859 | XFreePixmap (dpy, tiled_root_pmap); |
1160 | XFreePixmap (dpy, tiled_root_pmap); |
860 | tiled_root_pmap = None; |
1161 | tiled_root_pmap = None; |
861 | } |
1162 | } |
862 | else |
1163 | else |
863 | result |= transpPmapTiled; |
1164 | result |= transpPmapTiled; |
864 | } |
1165 | } |
865 | else |
1166 | else |
|
|
1167 | { |
866 | {/* strightforward pixmap copy */ |
1168 | /* straightforward pixmap copy */ |
867 | gcv.tile = root_pixmap; |
1169 | gcv.tile = root_pixmap; |
868 | gcv.fill_style = FillTiled; |
1170 | gcv.fill_style = FillTiled; |
869 | |
1171 | |
870 | while (sx < 0) sx += (int)root_width; |
1172 | while (sx < 0) sx += (int)root_width; |
871 | while (sy < 0) sy += (int)root_height; |
1173 | while (sy < 0) sy += (int)root_height; |
… | |
… | |
882 | } |
1184 | } |
883 | TIMING_TEST_PRINT_RESULT (tp); |
1185 | TIMING_TEST_PRINT_RESULT (tp); |
884 | |
1186 | |
885 | if (tiled_root_pmap != None) |
1187 | if (tiled_root_pmap != None) |
886 | { |
1188 | { |
887 | if (!need_client_side_rendering ()) |
1189 | if (!need_client_side_rendering ()) |
888 | { |
1190 | { |
889 | if ((flags & tintNeeded)) |
1191 | if ((flags & tintNeeded)) |
890 | { |
1192 | { |
891 | if (flags & tintWholesome) |
1193 | if (flags & tintWholesome) |
892 | { |
1194 | { |
893 | /* In this case we can tint image server-side getting significant |
1195 | /* In this case we can tint image server-side getting significant |
894 | * performance improvements, as we eliminate XImage transfer |
1196 | * performance improvements, as we eliminate XImage transfer |
… | |
… | |
919 | { |
1221 | { |
920 | c.r = (c.r * shade) / 100; |
1222 | c.r = (c.r * shade) / 100; |
921 | c.g = (c.g * shade) / 100; |
1223 | c.g = (c.g * shade) / 100; |
922 | c.b = (c.b * shade) / 100; |
1224 | c.b = (c.b * shade) / 100; |
923 | } |
1225 | } |
924 | else if( shade > 100 && shade < 200) |
1226 | else if (shade > 100 && shade < 200) |
925 | { |
1227 | { |
926 | c.r = (c.r * (200 - shade)) / 100; |
1228 | c.r = (c.r * (200 - shade)) / 100; |
927 | c.g = (c.g * (200 - shade)) / 100; |
1229 | c.g = (c.g * (200 - shade)) / 100; |
928 | c.b = (c.b * (200 - shade)) / 100; |
1230 | c.b = (c.b * (200 - shade)) / 100; |
929 | } |
1231 | } |
… | |
… | |
935 | pf.direct.greenMask = 0xff; |
1237 | pf.direct.greenMask = 0xff; |
936 | pf.direct.blueMask = 0xff; |
1238 | pf.direct.blueMask = 0xff; |
937 | pf.direct.alphaMask = 0xff; |
1239 | pf.direct.alphaMask = 0xff; |
938 | |
1240 | |
939 | XRenderPictFormat *solid_format = XRenderFindFormat (dpy, |
1241 | XRenderPictFormat *solid_format = XRenderFindFormat (dpy, |
940 | (PictFormatType| |
1242 | (PictFormatType| |
941 | PictFormatDepth| |
1243 | PictFormatDepth| |
942 | PictFormatRedMask| |
1244 | PictFormatRedMask| |
943 | PictFormatGreenMask| |
1245 | PictFormatGreenMask| |
944 | PictFormatBlueMask| |
1246 | PictFormatBlueMask| |
945 | PictFormatAlphaMask), |
1247 | PictFormatAlphaMask), |
946 | &pf, |
1248 | &pf, |
947 | 0); |
1249 | 0); |
948 | XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); |
1250 | XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); |
949 | XRenderPictureAttributes pa ; |
1251 | XRenderPictureAttributes pa ; |
950 | |
1252 | |
951 | back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); |
1253 | back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); |
952 | |
1254 | |
… | |
… | |
954 | |
1256 | |
955 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
1257 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
956 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1258 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
957 | XFreePixmap (dpy, overlay_pmap); |
1259 | XFreePixmap (dpy, overlay_pmap); |
958 | |
1260 | |
959 | pa.component_alpha = True; |
1261 | pa.component_alpha = True; |
960 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
1262 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
961 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
1263 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
962 | XFreePixmap (dpy, mask_pmap); |
1264 | XFreePixmap (dpy, mask_pmap); |
963 | |
1265 | |
964 | if (mask_pic && overlay_pic && back_pic) |
1266 | if (mask_pic && overlay_pic && back_pic) |
… | |
… | |
975 | mask_c.blue = 0xffff - c.b; |
1277 | mask_c.blue = 0xffff - c.b; |
976 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1278 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
977 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
1279 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
978 | result |= transpPmapTinted; |
1280 | result |= transpPmapTinted; |
979 | } |
1281 | } |
|
|
1282 | |
980 | XRenderFreePicture (dpy, mask_pic); |
1283 | XRenderFreePicture (dpy, mask_pic); |
981 | XRenderFreePicture (dpy, overlay_pic); |
1284 | XRenderFreePicture (dpy, overlay_pic); |
982 | XRenderFreePicture (dpy, back_pic); |
1285 | XRenderFreePicture (dpy, back_pic); |
983 | # if DO_TIMING_TEST |
1286 | # if DO_TIMING_TEST |
984 | XSync (dpy, False); |
1287 | XSync (dpy, False); |
985 | # endif |
1288 | # endif |
986 | # endif |
1289 | # endif |
987 | } |
1290 | } |
988 | } |
1291 | } |
989 | } /* server side rendering completed */ |
1292 | } /* server side rendering completed */ |
990 | |
1293 | |
991 | if (pixmap) |
1294 | if (pixmap) |
992 | XFreePixmap (dpy, pixmap); |
1295 | XFreePixmap (dpy, pixmap); |
993 | |
1296 | |
994 | pixmap = tiled_root_pmap; |
1297 | pixmap = tiled_root_pmap; |
995 | pmap_width = window_width; |
1298 | pmap_width = window_width; |
996 | pmap_height = window_height; |
1299 | pmap_height = window_height; |
997 | pmap_depth = root_depth; |
1300 | pmap_depth = root_depth; |
998 | } |
1301 | } |
999 | |
1302 | |
1000 | if (gc) |
1303 | if (gc) |
1001 | XFreeGC (dpy, gc); |
1304 | XFreeGC (dpy, gc); |
1002 | |
1305 | |
1003 | TIMING_TEST_PRINT_RESULT (tp); |
1306 | TIMING_TEST_PRINT_RESULT (tp); |
1004 | |
1307 | |
1005 | return result; |
1308 | return result; |
1006 | } |
1309 | } |
1007 | |
1310 | |
1008 | bool |
1311 | bool |
1009 | bgPixmap_t::set_root_pixmap () |
1312 | bgPixmap_t::set_root_pixmap () |
1010 | { |
1313 | { |
1011 | Pixmap new_root_pixmap = None; |
|
|
1012 | |
|
|
1013 | new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1314 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1014 | if (new_root_pixmap == None) |
1315 | if (new_root_pixmap == None) |
1015 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1316 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1016 | |
1317 | |
1017 | if (new_root_pixmap != root_pixmap) |
1318 | if (new_root_pixmap != root_pixmap) |
1018 | { |
1319 | { |
1019 | root_pixmap = new_root_pixmap; |
1320 | root_pixmap = new_root_pixmap; |
1020 | return true; |
1321 | return true; |
1021 | } |
1322 | } |
|
|
1323 | |
1022 | return false; |
1324 | return false; |
1023 | } |
1325 | } |
1024 | # endif /* ENABLE_TRANSPARENCY */ |
1326 | # endif /* ENABLE_TRANSPARENCY */ |
1025 | |
1327 | |
1026 | # ifndef HAVE_AFTERIMAGE |
1328 | # ifndef HAVE_AFTERIMAGE |
1027 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1329 | static void ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm); |
1028 | # endif |
1330 | # endif |
1029 | |
|
|
1030 | |
1331 | |
1031 | bool |
1332 | bool |
1032 | bgPixmap_t::render () |
1333 | bgPixmap_t::render () |
1033 | { |
1334 | { |
1034 | unsigned long background_flags = 0; |
1335 | unsigned long background_flags = 0; |
… | |
… | |
1036 | if (target == NULL) |
1337 | if (target == NULL) |
1037 | return false; |
1338 | return false; |
1038 | |
1339 | |
1039 | TIMING_TEST_START (tp); |
1340 | TIMING_TEST_START (tp); |
1040 | |
1341 | |
1041 | invalidate(); |
1342 | invalidate (); |
1042 | # ifdef ENABLE_TRANSPARENCY |
1343 | # ifdef ENABLE_TRANSPARENCY |
1043 | if (flags & isTransparent) |
1344 | if (flags & isTransparent) |
1044 | { |
1345 | { |
1045 | /* we need to re-generate transparency pixmap in that case ! */ |
1346 | /* we need to re-generate transparency pixmap in that case ! */ |
1046 | background_flags = make_transparency_pixmap (); |
1347 | background_flags = make_transparency_pixmap (); |
1047 | if (background_flags == 0) |
1348 | if (background_flags == 0) |
1048 | return false; |
1349 | return false; |
1049 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1350 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
1050 | && pmap_depth == target->depth) |
1351 | && pmap_depth == target->depth) |
1051 | flags = flags & ~isInvalid; |
1352 | flags = flags & ~isInvalid; |
1052 | } |
1353 | } |
1053 | # endif |
1354 | # endif |
1054 | |
1355 | |
|
|
1356 | # ifdef BG_IMAGE_FROM_FILE |
|
|
1357 | if (have_image |
|
|
1358 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
|
|
1359 | { |
|
|
1360 | if (render_image (background_flags)) |
|
|
1361 | flags = flags & ~isInvalid; |
|
|
1362 | } |
|
|
1363 | # endif |
|
|
1364 | |
1055 | XImage *result = NULL; |
1365 | XImage *result = NULL; |
1056 | # ifdef HAVE_AFTERIMAGE |
1366 | |
1057 | if (original_asim |
1367 | if (background_flags && (flags & isInvalid)) |
1058 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1368 | { |
|
|
1369 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1059 | { |
1370 | } |
1060 | ASImage *background = NULL; |
|
|
1061 | ARGB32 as_tint = TINT_LEAVE_SAME; |
|
|
1062 | if (background_flags) |
|
|
1063 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
1064 | |
1371 | |
1065 | # ifdef ENABLE_TRANSPARENCY |
1372 | if (result) |
|
|
1373 | { |
|
|
1374 | # if !defined(HAVE_AFTERIMAGE) && !XFT |
|
|
1375 | /* our own client-side tinting */ |
|
|
1376 | /* ATTENTION: We ASSUME that XFT will let us do all the tinting necessary server-side. |
|
|
1377 | This may need to be changed in need_client_side_rendering() logic is altered !!! */ |
1066 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1378 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1067 | { |
|
|
1068 | ShadingInfo as_shade; |
|
|
1069 | as_shade.shading = (shade == 0) ? 100 : shade; |
|
|
1070 | |
|
|
1071 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1072 | if (flags & tintSet) |
|
|
1073 | tint.get (c); |
|
|
1074 | as_shade.tintColor.red = c.r; |
|
|
1075 | as_shade.tintColor.green = c.g; |
|
|
1076 | as_shade.tintColor.blue = c.b; |
|
|
1077 | |
|
|
1078 | as_tint = shading2tint32 (&as_shade); |
|
|
1079 | } |
|
|
1080 | if (!(background_flags & transpPmapBlured) && (flags & blurNeeded) && background != NULL) |
|
|
1081 | { |
|
|
1082 | ASImage* tmp = blur_asimage_gauss (target->asv, background, h_blurRadius, v_blurRadius, 0xFFFFFFFF, |
|
|
1083 | (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, |
|
|
1084 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1085 | if (tmp) |
|
|
1086 | { |
|
|
1087 | destroy_asimage (&background); |
|
|
1088 | background = tmp; |
|
|
1089 | } |
|
|
1090 | } |
|
|
1091 | # endif |
|
|
1092 | |
|
|
1093 | if (render_asim (background, as_tint)) |
|
|
1094 | flags = flags & ~isInvalid; |
|
|
1095 | if (background) |
|
|
1096 | destroy_asimage (&background); |
|
|
1097 | } |
|
|
1098 | else if (background_flags && pmap_depth != target->depth) |
|
|
1099 | { |
|
|
1100 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
1101 | } |
|
|
1102 | |
|
|
1103 | # elif !XFT /* our own client-side tinting */ |
|
|
1104 | |
|
|
1105 | /* ATTENTION: We ASSUME that XFT will let us do all the tinint neccessary server-side. |
|
|
1106 | This may need to be changed in need_client_seide_rendering() logic is altered !!! */ |
|
|
1107 | |
|
|
1108 | if (background_flags && (flags & isInvalid)) |
|
|
1109 | { |
|
|
1110 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
1111 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
1112 | { |
1379 | { |
1113 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1380 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1114 | if (flags & tintSet) |
1381 | if (flags & tintSet) |
1115 | tint.get (c); |
1382 | tint.get (c); |
1116 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1383 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1117 | } |
1384 | } |
1118 | } |
1385 | # endif |
1119 | # endif /* HAVE_AFTERIMAGE */ |
|
|
1120 | |
1386 | |
1121 | if (result != NULL) |
|
|
1122 | { |
|
|
1123 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1387 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
|
|
1388 | |
1124 | if (gc) |
1389 | if (gc) |
1125 | { |
1390 | { |
1126 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1391 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1127 | { |
1392 | { |
1128 | XFreePixmap (target->dpy, pixmap); |
1393 | XFreePixmap (target->dpy, pixmap); |
1129 | pixmap = None; |
1394 | pixmap = None; |
1130 | } |
1395 | } |
|
|
1396 | |
1131 | if (pixmap == None) |
1397 | if (pixmap == None) |
1132 | { |
1398 | { |
1133 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1399 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1134 | pmap_width = result->width; |
1400 | pmap_width = result->width; |
1135 | pmap_height = result->height; |
1401 | pmap_height = result->height; |
1136 | pmap_depth = target->depth; |
1402 | pmap_depth = target->depth; |
1137 | } |
1403 | } |
|
|
1404 | |
1138 | if (pmap_depth != result->depth) |
1405 | if (pmap_depth != result->depth) |
|
|
1406 | { |
1139 | { /* Bad Match error will ensue ! stupid X !!!! */ |
1407 | /* Bad Match error will ensue ! stupid X !!!! */ |
1140 | if( result->depth == 24 && pmap_depth == 32) |
1408 | if (result->depth == 24 && pmap_depth == 32) |
1141 | result->depth = 32; |
1409 | result->depth = 32; |
1142 | else if( result->depth == 32 && pmap_depth == 24) |
1410 | else if (result->depth == 32 && pmap_depth == 24) |
1143 | result->depth = 24; |
1411 | result->depth = 24; |
1144 | else |
1412 | else |
1145 | { |
1413 | { |
1146 | /* TODO: implement image recoding */ |
1414 | /* TODO: implement image recoding */ |
1147 | } |
1415 | } |
1148 | } |
1416 | } |
|
|
1417 | |
1149 | if (pmap_depth == result->depth) |
1418 | if (pmap_depth == result->depth) |
1150 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1419 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
1420 | |
1151 | XFreeGC (target->dpy, gc); |
1421 | XFreeGC (target->dpy, gc); |
1152 | flags = flags & ~isInvalid; |
1422 | flags = flags & ~isInvalid; |
1153 | } |
1423 | } |
|
|
1424 | |
1154 | XDestroyImage (result); |
1425 | XDestroyImage (result); |
1155 | } |
1426 | } |
1156 | |
1427 | |
1157 | if (flags & isInvalid) |
1428 | if (flags & isInvalid) |
1158 | { |
1429 | { |
1159 | if (pixmap != None) |
1430 | if (pixmap != None) |
… | |
… | |
1163 | } |
1434 | } |
1164 | } |
1435 | } |
1165 | |
1436 | |
1166 | apply (); |
1437 | apply (); |
1167 | |
1438 | |
|
|
1439 | XSync (target->dpy, False); |
|
|
1440 | valid_since = ev::now (); |
|
|
1441 | |
1168 | TIMING_TEST_PRINT_RESULT (tp); |
1442 | TIMING_TEST_PRINT_RESULT (tp); |
1169 | |
1443 | |
1170 | return true; |
1444 | return true; |
1171 | } |
1445 | } |
1172 | |
1446 | |
1173 | bool |
1447 | bool |
1174 | bgPixmap_t::set_target (rxvt_term *new_target) |
1448 | bgPixmap_t::set_target (rxvt_term *new_target) |
1175 | { |
1449 | { |
1176 | if (new_target) |
1450 | if (new_target) |
1177 | if (target != new_target) |
1451 | if (target != new_target) |
1178 | { |
1452 | { |
… | |
… | |
1180 | # ifdef ENABLE_TRANSPARENCY |
1454 | # ifdef ENABLE_TRANSPARENCY |
1181 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1455 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
1182 | # endif |
1456 | # endif |
1183 | return true; |
1457 | return true; |
1184 | } |
1458 | } |
|
|
1459 | |
1185 | return false; |
1460 | return false; |
1186 | } |
1461 | } |
1187 | |
1462 | |
1188 | void |
1463 | void |
1189 | bgPixmap_t::apply() |
1464 | bgPixmap_t::apply () |
1190 | { |
1465 | { |
1191 | if (target) |
1466 | if (target) |
1192 | { |
1467 | { |
1193 | flags &= ~isVtOrigin; |
1468 | flags &= ~isVtOrigin; |
|
|
1469 | |
1194 | if (pixmap != None) |
1470 | if (pixmap != None) |
|
|
1471 | { |
1195 | { /* set target's background to pixmap */ |
1472 | /* set target's background to pixmap */ |
1196 | # ifdef ENABLE_TRANSPARENCY |
1473 | # ifdef ENABLE_TRANSPARENCY |
1197 | if (flags & isTransparent) |
1474 | if (flags & isTransparent) |
1198 | { |
1475 | { |
1199 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1476 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1200 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1477 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1201 | # if HAVE_SCROLLBARS |
1478 | |
1202 | if (target->scrollBar.win) |
1479 | if (target->scrollBar.win) |
1203 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1480 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
1204 | # endif |
|
|
1205 | } |
1481 | } |
1206 | else |
1482 | else |
1207 | # endif |
1483 | # endif |
1208 | { |
1484 | { |
1209 | flags |= isVtOrigin; |
1485 | flags |= isVtOrigin; |
1210 | /* force old pixmap dereference in case it was transparent before :*/ |
1486 | /* force old pixmap dereference in case it was transparent before :*/ |
1211 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1487 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1212 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1488 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
1213 | /* do we also need to set scrollbar's background here ? */ |
1489 | /* do we also need to set scrollbar's background here ? */ |
1214 | # if HAVE_SCROLLBARS |
1490 | |
1215 | if (target->scrollBar.win) |
1491 | if (target->scrollBar.win) |
1216 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1492 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1217 | # endif |
|
|
1218 | } |
1493 | } |
1219 | } |
1494 | } |
1220 | else |
1495 | else |
|
|
1496 | { |
1221 | { /* set target background to a pixel */ |
1497 | /* set target background to a pixel */ |
1222 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1498 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1223 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1499 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1224 | /* do we also need to set scrollbar's background here ? */ |
1500 | /* do we also need to set scrollbar's background here ? */ |
1225 | # if HAVE_SCROLLBARS |
|
|
1226 | if (target->scrollBar.win) |
1501 | if (target->scrollBar.win) |
1227 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1502 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1228 | # endif |
|
|
1229 | } |
1503 | } |
|
|
1504 | |
1230 | /* don't want Expose on the parent or vt. It is better to use |
1505 | /* don't want Expose on the parent or vt. It is better to use |
1231 | scr_touch or we get a great deal of flicker otherwise: */ |
1506 | scr_touch or we get a great deal of flicker otherwise: */ |
1232 | XClearWindow (target->dpy, target->parent[0]); |
1507 | XClearWindow (target->dpy, target->parent[0]); |
1233 | |
1508 | |
1234 | # if HAVE_SCROLLBARS |
1509 | if (target->scrollBar.state && target->scrollBar.win) |
1235 | if (target->scrollBar.win) |
|
|
1236 | { |
1510 | { |
1237 | target->scrollBar.setIdle (); |
1511 | target->scrollBar.state = STATE_IDLE; |
1238 | target->scrollbar_show (0); |
1512 | target->scrollBar.show (0); |
1239 | } |
1513 | } |
1240 | # endif |
|
|
1241 | |
1514 | |
1242 | target->want_refresh = 1; |
1515 | target->want_refresh = 1; |
1243 | flags |= hasChanged; |
1516 | flags |= hasChanged; |
1244 | } |
1517 | } |
1245 | } |
1518 | } |
1246 | |
1519 | |
1247 | #endif /* HAVE_BG_PIXMAP */ |
1520 | #endif /* HAVE_BG_PIXMAP */ |
1248 | |
1521 | |
1249 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1522 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1250 | /* taken from aterm-0.4.2 */ |
1523 | /* taken from aterm-0.4.2 */ |
1251 | |
1524 | |
1252 | typedef uint32_t RUINT32T; |
1525 | typedef uint32_t RUINT32T; |
1253 | |
1526 | |
1254 | static void |
1527 | static void |
1255 | ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm) |
1528 | ShadeXImage(rxvt_term *term, XImage *srcImage, int shade, int rm, int gm, int bm) |
1256 | { |
1529 | { |
1257 | int sh_r, sh_g, sh_b; |
1530 | int sh_r, sh_g, sh_b; |
1258 | RUINT32T mask_r, mask_g, mask_b; |
1531 | RUINT32T mask_r, mask_g, mask_b; |
1259 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1532 | RUINT32T *lookup, *lookup_r, *lookup_g, *lookup_b; |
1260 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1533 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |