… | |
… | |
28 | |
28 | |
29 | #if XRENDER |
29 | #if XRENDER |
30 | # include <X11/extensions/Xrender.h> |
30 | # include <X11/extensions/Xrender.h> |
31 | #endif |
31 | #endif |
32 | |
32 | |
33 | #define DO_TIMING_TEST 0 |
33 | #ifndef FilterConvolution |
34 | |
34 | #define FilterConvolution "convolution" |
35 | #if DO_TIMING_TEST |
|
|
36 | # include <sys/time.h> |
|
|
37 | #define TIMING_TEST_START(id) \ |
|
|
38 | struct timeval timing_test_##id##_stv; \ |
|
|
39 | gettimeofday (&timing_test_##id##_stv, NULL); |
|
|
40 | |
|
|
41 | #define TIMING_TEST_PRINT_RESULT(id) \ |
|
|
42 | do { \ |
|
|
43 | struct timeval tv; \ |
|
|
44 | gettimeofday (&tv, NULL); \ |
|
|
45 | tv.tv_sec -= (timing_test_##id##_stv).tv_sec; \ |
|
|
46 | fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__, \ |
|
|
47 | tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec); \ |
|
|
48 | } while (0) |
|
|
49 | |
|
|
50 | #else |
|
|
51 | #define TIMING_TEST_START(id) do {} while (0) |
|
|
52 | #define TIMING_TEST_PRINT_RESULT(id) do {} while (0) |
|
|
53 | #endif |
35 | #endif |
54 | |
36 | |
55 | /* |
37 | /* |
56 | * Pixmap geometry string interpretation : |
38 | * Pixmap geometry string interpretation : |
57 | * Each geometry string contains zero or one scale/position |
39 | * Each geometry string contains zero or one scale/position |
… | |
… | |
62 | * |
44 | * |
63 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
45 | * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. |
64 | * W and H are percentages of the terminal window size. |
46 | * W and H are percentages of the terminal window size. |
65 | * X and Y are also percentages; e.g., +50+50 centers |
47 | * X and Y are also percentages; e.g., +50+50 centers |
66 | * the image in the window. |
48 | * the image in the window. |
67 | * WxH+X Assumes Y == X |
|
|
68 | * WxH Assumes Y == X == 50 (centers the image) |
|
|
69 | * W+X+Y Assumes H == W |
|
|
70 | * W+X Assumes H == W and Y == X |
|
|
71 | * W Assumes H == W and Y == X == 50 |
|
|
72 | * |
|
|
73 | * Adjusting position only : |
|
|
74 | * =+X+Y Set position to X% by Y% (absolute). |
|
|
75 | * =+X Set position to X% by X%. |
|
|
76 | * +X+Y Adjust position horizontally X% and vertically Y% |
|
|
77 | * from current position (relative). |
|
|
78 | * +X Adjust position horizontally X% and vertically X% |
|
|
79 | * from current position. |
|
|
80 | * |
|
|
81 | * Adjusting scale only : |
|
|
82 | * Wx0 Multiply horizontal scaling factor by W% |
|
|
83 | * 0xH Multiply vertical scaling factor by H% |
|
|
84 | * 0x0 No scaling (show image at normal size). |
|
|
85 | * |
49 | * |
86 | * Pixmap Operations : (should be prepended by a colon) |
50 | * Pixmap Operations : (should be prepended by a colon) |
87 | * tile Tile image. Scaling/position modifiers above will affect |
51 | * tile Tile image. Scaling/position modifiers above will affect |
88 | * the tile size and origin. |
52 | * the tile size and origin. |
89 | * propscale When scaling, scale proportionally. That is, maintain the |
53 | * propscale When scaling, scale proportionally. That is, maintain the |
… | |
… | |
115 | #ifdef ENABLE_TRANSPARENCY |
79 | #ifdef ENABLE_TRANSPARENCY |
116 | shade = 100; |
80 | shade = 100; |
117 | #endif |
81 | #endif |
118 | flags = 0; |
82 | flags = 0; |
119 | pixmap = None; |
83 | pixmap = None; |
120 | valid_since = invalid_since = 0; |
84 | valid_since = 0; |
121 | target = 0; |
85 | target = 0; |
|
|
86 | target_x = target_y = 0; |
122 | } |
87 | } |
123 | |
88 | |
124 | void |
89 | void |
125 | bgPixmap_t::destroy () |
90 | bgPixmap_t::destroy () |
126 | { |
91 | { |
… | |
… | |
137 | if (pixmap && target) |
102 | if (pixmap && target) |
138 | XFreePixmap (target->dpy, pixmap); |
103 | XFreePixmap (target->dpy, pixmap); |
139 | } |
104 | } |
140 | |
105 | |
141 | bool |
106 | bool |
|
|
107 | bgPixmap_t::set_position (int x, int y) |
|
|
108 | { |
|
|
109 | |
|
|
110 | if (target_x != x |
|
|
111 | || target_y != y) |
|
|
112 | { |
|
|
113 | target_x = x; |
|
|
114 | target_y = y; |
|
|
115 | return true; |
|
|
116 | } |
|
|
117 | return false; |
|
|
118 | } |
|
|
119 | |
|
|
120 | bool |
142 | bgPixmap_t::window_size_sensitive () |
121 | bgPixmap_t::window_size_sensitive () |
143 | { |
122 | { |
144 | # ifdef ENABLE_TRANSPARENCY |
123 | # ifdef ENABLE_TRANSPARENCY |
145 | if (flags & isTransparent) |
124 | if (flags & isTransparent) |
146 | return true; |
125 | return true; |
… | |
… | |
171 | if (flags & rootAlign) |
150 | if (flags & rootAlign) |
172 | return true; |
151 | return true; |
173 | } |
152 | } |
174 | # endif |
153 | # endif |
175 | |
154 | |
176 | return false; |
|
|
177 | }; |
|
|
178 | |
|
|
179 | bool bgPixmap_t::need_client_side_rendering () |
|
|
180 | { |
|
|
181 | # ifdef HAVE_AFTERIMAGE |
|
|
182 | if (original_asim) |
|
|
183 | return true; |
|
|
184 | # endif |
|
|
185 | return false; |
155 | return false; |
186 | } |
156 | } |
187 | |
157 | |
188 | # ifdef BG_IMAGE_FROM_FILE |
158 | # ifdef BG_IMAGE_FROM_FILE |
189 | static inline bool |
159 | static inline bool |
… | |
… | |
252 | dst_size = target_size - dst_pos; |
222 | dst_size = target_size - dst_pos; |
253 | return src_pos; |
223 | return src_pos; |
254 | } |
224 | } |
255 | |
225 | |
256 | bool |
226 | bool |
257 | bgPixmap_t::set_geometry (const char *geom) |
227 | bgPixmap_t::set_geometry (const char *geom, bool update) |
258 | { |
228 | { |
|
|
229 | bool changed = false; |
259 | int geom_flags = 0, changed = 0; |
230 | int geom_flags = 0; |
260 | int x = 0, y = 0; |
231 | int x = 0, y = 0; |
261 | unsigned int w = 0, h = 0; |
232 | unsigned int w = 0, h = 0; |
262 | unsigned int n; |
233 | unsigned int n; |
263 | unsigned long new_flags = (flags & (~geometryFlags)); |
234 | unsigned long new_flags = (flags & (~geometryFlags)); |
264 | const char *p; |
235 | const char *ops; |
265 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
|
|
266 | |
236 | |
267 | if (geom == NULL) |
237 | if (geom == NULL) |
268 | return false; |
238 | return false; |
269 | |
239 | |
270 | char str[MAXLEN_GEOM]; |
240 | char str[256]; |
271 | |
241 | |
272 | while (isspace(*geom)) ++geom; |
|
|
273 | if ((p = strchr (geom, ';')) == NULL) |
|
|
274 | p = strchr (geom, '\0'); |
242 | ops = strchr (geom, ':'); |
275 | |
243 | if (ops == NULL) |
|
|
244 | n = strlen (geom); |
|
|
245 | else |
276 | n = (p - geom); |
246 | n = ops - geom; |
277 | if (n < MAXLEN_GEOM) |
|
|
278 | { |
|
|
279 | char *ops; |
|
|
280 | new_flags |= geometrySet; |
|
|
281 | |
247 | |
|
|
248 | if (n >= sizeof (str)) |
|
|
249 | return false; |
|
|
250 | |
282 | memcpy (str, geom, n); |
251 | memcpy (str, geom, n); |
283 | str[n] = '\0'; |
252 | str[n] = '\0'; |
284 | if (str[0] == ':') |
253 | rxvt_strtrim (str); |
285 | ops = &str[0]; |
|
|
286 | else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0])) |
|
|
287 | ops = &str[0]; |
|
|
288 | else |
|
|
289 | { |
|
|
290 | char *tmp; |
|
|
291 | ops = strchr (str, ':'); |
|
|
292 | if (ops != NULL) |
|
|
293 | { |
|
|
294 | for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp); |
|
|
295 | *(++tmp) = '\0'; |
|
|
296 | if (ops == tmp) ++ops; |
|
|
297 | } |
|
|
298 | } |
|
|
299 | |
254 | |
300 | if (ops > str || ops == NULL) |
255 | if (str[0]) |
301 | { |
256 | { |
302 | /* we have geometry string - let's handle it prior to applying ops */ |
257 | /* we have geometry string - let's handle it prior to applying ops */ |
303 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
258 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
304 | |
|
|
305 | if ((geom_flags & XValue) && !(geom_flags & YValue)) |
|
|
306 | { |
|
|
307 | y = x; |
|
|
308 | geom_flags |= YValue; |
|
|
309 | } |
|
|
310 | |
|
|
311 | if (flags & geometrySet) |
|
|
312 | { |
|
|
313 | /* new geometry is an adjustment to the old one ! */ |
|
|
314 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
|
|
315 | { |
|
|
316 | if (w == 0 && h != 0) |
|
|
317 | { |
|
|
318 | w = h_scale; |
|
|
319 | h = (v_scale * h) / 100; |
|
|
320 | } |
|
|
321 | else if (h == 0 && w != 0) |
|
|
322 | { |
|
|
323 | w = (h_scale * w) / 100; |
|
|
324 | h = v_scale; |
|
|
325 | } |
|
|
326 | } |
|
|
327 | if (geom_flags & XValue) |
|
|
328 | { |
|
|
329 | if (str[0] != '=') |
|
|
330 | { |
|
|
331 | y += v_align; |
|
|
332 | x += h_align; |
|
|
333 | } |
|
|
334 | } |
|
|
335 | } |
|
|
336 | else /* setting up geometry from scratch */ |
|
|
337 | { |
|
|
338 | if (!(geom_flags & XValue)) |
|
|
339 | { |
|
|
340 | /* use default geometry - centered */ |
|
|
341 | x = y = defaultAlign; |
|
|
342 | } |
|
|
343 | else if (!(geom_flags & YValue)) |
|
|
344 | y = x; |
|
|
345 | |
|
|
346 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
|
|
347 | { |
|
|
348 | /* use default geometry - scaled */ |
|
|
349 | w = h = defaultScale; |
|
|
350 | } |
|
|
351 | else if (geom_flags & WidthValue) |
|
|
352 | { |
|
|
353 | if (!(geom_flags & HeightValue)) |
|
|
354 | h = w; |
|
|
355 | } |
|
|
356 | else |
|
|
357 | w = h; |
|
|
358 | } |
|
|
359 | } /* done parsing geometry string */ |
259 | } /* done parsing geometry string */ |
360 | else if (!(flags & geometrySet)) |
260 | |
361 | { |
261 | if (!update) |
362 | /* default geometry - scaled and centered */ |
262 | { |
|
|
263 | if (!(geom_flags & XValue)) |
363 | x = y = defaultAlign; |
264 | x = y = defaultAlign; |
|
|
265 | else if (!(geom_flags & YValue)) |
|
|
266 | y = x; |
|
|
267 | |
|
|
268 | if (!(geom_flags & (WidthValue|HeightValue))) |
364 | w = h = defaultScale; |
269 | w = h = defaultScale; |
365 | } |
270 | else if (!(geom_flags & HeightValue)) |
|
|
271 | h = w; |
|
|
272 | else if (!(geom_flags & WidthValue)) |
|
|
273 | w = h; |
366 | |
274 | |
367 | if (!(flags & geometrySet)) |
|
|
368 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
275 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
276 | } |
369 | |
277 | |
370 | if (ops) |
278 | if (ops) |
371 | { |
279 | { |
372 | while (*ops) |
280 | char **arr = rxvt_strsplit (':', ops + 1); |
|
|
281 | |
|
|
282 | for (int i = 0; arr[i]; i++) |
373 | { |
283 | { |
374 | while (*ops == ':' || isspace(*ops)) ++ops; |
284 | if (!strcasecmp (arr[i], "tile")) |
375 | |
|
|
376 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) |
|
|
377 | if (CHECK_GEOM_OPS ("tile")) |
|
|
378 | { |
285 | { |
379 | w = h = noScale; |
286 | w = h = noScale; |
380 | geom_flags |= WidthValue|HeightValue; |
287 | geom_flags |= WidthValue|HeightValue; |
381 | } |
288 | } |
382 | else if (CHECK_GEOM_OPS ("propscale")) |
289 | else if (!strcasecmp (arr[i], "propscale")) |
383 | { |
290 | { |
384 | new_flags |= propScale; |
291 | new_flags |= propScale; |
385 | } |
292 | } |
386 | else if (CHECK_GEOM_OPS ("hscale")) |
293 | else if (!strcasecmp (arr[i], "hscale")) |
387 | { |
294 | { |
388 | if (w == 0) w = windowScale; |
295 | if (w == 0) w = windowScale; |
389 | |
296 | |
390 | h = noScale; |
297 | h = noScale; |
391 | geom_flags |= WidthValue|HeightValue; |
298 | geom_flags |= WidthValue|HeightValue; |
392 | } |
299 | } |
393 | else if (CHECK_GEOM_OPS ("vscale")) |
300 | else if (!strcasecmp (arr[i], "vscale")) |
394 | { |
301 | { |
395 | if (h == 0) h = windowScale; |
302 | if (h == 0) h = windowScale; |
396 | |
303 | |
397 | w = noScale; |
304 | w = noScale; |
398 | geom_flags |= WidthValue|HeightValue; |
305 | geom_flags |= WidthValue|HeightValue; |
399 | } |
306 | } |
400 | else if (CHECK_GEOM_OPS ("scale")) |
307 | else if (!strcasecmp (arr[i], "scale")) |
401 | { |
308 | { |
402 | if (h == 0) h = windowScale; |
309 | if (h == 0) h = windowScale; |
403 | if (w == 0) w = windowScale; |
310 | if (w == 0) w = windowScale; |
404 | |
311 | |
405 | geom_flags |= WidthValue|HeightValue; |
312 | geom_flags |= WidthValue|HeightValue; |
406 | } |
313 | } |
407 | else if (CHECK_GEOM_OPS ("auto")) |
314 | else if (!strcasecmp (arr[i], "auto")) |
408 | { |
315 | { |
409 | w = h = windowScale; |
316 | w = h = windowScale; |
410 | x = y = centerAlign; |
317 | x = y = centerAlign; |
411 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
318 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
412 | } |
319 | } |
413 | else if (CHECK_GEOM_OPS ("root")) |
320 | else if (!strcasecmp (arr[i], "root")) |
414 | { |
321 | { |
415 | new_flags |= rootAlign; |
322 | new_flags |= rootAlign; |
416 | w = h = noScale; |
323 | w = h = noScale; |
417 | geom_flags |= WidthValue|HeightValue; |
324 | geom_flags |= WidthValue|HeightValue; |
418 | } |
325 | } |
419 | # undef CHECK_GEOM_OPS |
|
|
420 | |
|
|
421 | while (*ops != ':' && *ops != '\0') ++ops; |
|
|
422 | } /* done parsing ops */ |
326 | } /* done parsing ops */ |
423 | } |
|
|
424 | |
327 | |
|
|
328 | rxvt_free_strsplit (arr); |
|
|
329 | } |
|
|
330 | |
425 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) ++changed; |
331 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; |
426 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) ++changed; |
332 | if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; |
427 | if (check_set_align_value (geom_flags, XValue, h_align, x)) ++changed; |
333 | if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; |
428 | if (check_set_align_value (geom_flags, YValue, v_align, y)) ++changed; |
334 | if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; |
429 | } |
|
|
430 | |
335 | |
431 | if (new_flags != flags) |
336 | if (new_flags != flags) |
432 | { |
337 | { |
433 | flags = new_flags; |
338 | flags = new_flags; |
434 | changed++; |
339 | changed = true; |
435 | } |
340 | } |
436 | |
341 | |
437 | return (changed > 0); |
342 | return changed; |
438 | } |
343 | } |
439 | |
344 | |
440 | void |
345 | void |
441 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
346 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
442 | { |
347 | { |
… | |
… | |
459 | if (!w) w = image_width; |
364 | if (!w) w = image_width; |
460 | if (!h) h = image_height; |
365 | if (!h) h = image_height; |
461 | |
366 | |
462 | if (flags & rootAlign) |
367 | if (flags & rootAlign) |
463 | { |
368 | { |
464 | target->get_window_origin (x, y); |
|
|
465 | x = -x; |
369 | x = -target_x; |
466 | y = -y; |
370 | y = -target_y; |
467 | } |
371 | } |
468 | else |
372 | else |
469 | { |
373 | { |
470 | x = make_align_position (h_align, target_width, w); |
374 | x = make_align_position (h_align, target_width, w); |
471 | y = make_align_position (v_align, target_height, h); |
375 | y = make_align_position (v_align, target_height, h); |
… | |
… | |
665 | if (result) |
569 | if (result) |
666 | { |
570 | { |
667 | XGCValues gcv; |
571 | XGCValues gcv; |
668 | GC gc; |
572 | GC gc; |
669 | |
573 | |
670 | if (pixmap) |
|
|
671 | { |
|
|
672 | if (pmap_width != new_pmap_width |
|
|
673 | || pmap_height != new_pmap_height |
|
|
674 | || pmap_depth != target->depth) |
|
|
675 | { |
|
|
676 | XFreePixmap (target->dpy, pixmap); |
|
|
677 | pixmap = None; |
|
|
678 | } |
|
|
679 | } |
|
|
680 | |
|
|
681 | /* create Pixmap */ |
574 | /* create Pixmap */ |
682 | if (pixmap == None) |
575 | if (pixmap == None |
|
|
576 | || pmap_width != new_pmap_width |
|
|
577 | || pmap_height != new_pmap_height) |
683 | { |
578 | { |
|
|
579 | if (pixmap) |
|
|
580 | XFreePixmap (target->dpy, pixmap); |
684 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
581 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
685 | pmap_width = new_pmap_width; |
582 | pmap_width = new_pmap_width; |
686 | pmap_height = new_pmap_height; |
583 | pmap_height = new_pmap_height; |
687 | pmap_depth = target->depth; |
|
|
688 | } |
584 | } |
689 | /* fill with background color (if result's not completely overlapping it) */ |
585 | /* fill with background color (if result's not completely overlapping it) */ |
690 | gcv.foreground = target->pix_colors[Color_bg]; |
586 | gcv.foreground = target->pix_colors[Color_bg]; |
691 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
587 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
692 | |
588 | |
… | |
… | |
724 | return ret; |
620 | return ret; |
725 | } |
621 | } |
726 | # endif /* HAVE_AFTERIMAGE */ |
622 | # endif /* HAVE_AFTERIMAGE */ |
727 | |
623 | |
728 | # ifdef HAVE_PIXBUF |
624 | # ifdef HAVE_PIXBUF |
|
|
625 | bool |
|
|
626 | bgPixmap_t::pixbuf_to_pixmap (GdkPixbuf *pixbuf, Pixmap pixmap, GC gc, |
|
|
627 | int src_x, int src_y, int dst_x, int dst_y, |
|
|
628 | unsigned int width, unsigned int height) |
|
|
629 | { |
|
|
630 | XImage *ximage; |
|
|
631 | char *data, *line; |
|
|
632 | int bytes_per_pixel; |
|
|
633 | int width_r, width_g, width_b; |
|
|
634 | int sh_r, sh_g, sh_b; |
|
|
635 | int rowstride; |
|
|
636 | int channels; |
|
|
637 | unsigned char *row; |
|
|
638 | Visual *visual = target->visual; |
|
|
639 | int depth = target->depth; |
|
|
640 | |
|
|
641 | if (visual->c_class != TrueColor) |
|
|
642 | return false; |
|
|
643 | |
|
|
644 | if (depth == 24 || depth == 32) |
|
|
645 | bytes_per_pixel = 4; |
|
|
646 | else if (depth == 15 || depth == 16) |
|
|
647 | bytes_per_pixel = 2; |
|
|
648 | else |
|
|
649 | return false; |
|
|
650 | |
|
|
651 | width_r = rxvt_popcount (visual->red_mask); |
|
|
652 | width_g = rxvt_popcount (visual->green_mask); |
|
|
653 | width_b = rxvt_popcount (visual->blue_mask); |
|
|
654 | |
|
|
655 | if (width_r > 8 || width_g > 8 || width_b > 8) |
|
|
656 | return false; |
|
|
657 | |
|
|
658 | sh_r = rxvt_ctz (visual->red_mask); |
|
|
659 | sh_g = rxvt_ctz (visual->green_mask); |
|
|
660 | sh_b = rxvt_ctz (visual->blue_mask); |
|
|
661 | |
|
|
662 | if (width > INT_MAX / height / bytes_per_pixel) |
|
|
663 | return false; |
|
|
664 | |
|
|
665 | data = (char *)malloc (width * height * bytes_per_pixel); |
|
|
666 | if (!data) |
|
|
667 | return false; |
|
|
668 | |
|
|
669 | ximage = XCreateImage (target->dpy, visual, depth, ZPixmap, 0, data, |
|
|
670 | width, height, bytes_per_pixel * 8, 0); |
|
|
671 | if (!ximage) |
|
|
672 | { |
|
|
673 | free (data); |
|
|
674 | return false; |
|
|
675 | } |
|
|
676 | |
|
|
677 | ximage->byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
|
|
678 | |
|
|
679 | rowstride = gdk_pixbuf_get_rowstride (pixbuf); |
|
|
680 | channels = gdk_pixbuf_get_n_channels (pixbuf); |
|
|
681 | row = gdk_pixbuf_get_pixels (pixbuf) + src_y * rowstride + src_x * channels; |
|
|
682 | line = data; |
|
|
683 | |
|
|
684 | for (int y = 0; y < height; y++) |
|
|
685 | { |
|
|
686 | for (int x = 0; x < width; x++) |
|
|
687 | { |
|
|
688 | unsigned char *pixel = row + x * channels; |
|
|
689 | uint32_t value; |
|
|
690 | |
|
|
691 | value = ((pixel[0] >> (8 - width_r)) << sh_r) |
|
|
692 | | ((pixel[1] >> (8 - width_g)) << sh_g) |
|
|
693 | | ((pixel[2] >> (8 - width_b)) << sh_b); |
|
|
694 | |
|
|
695 | if (bytes_per_pixel == 4) |
|
|
696 | ((uint32_t *)line)[x] = value; |
|
|
697 | else |
|
|
698 | ((uint16_t *)line)[x] = value; |
|
|
699 | } |
|
|
700 | |
|
|
701 | row += rowstride; |
|
|
702 | line += ximage->bytes_per_line; |
|
|
703 | } |
|
|
704 | |
|
|
705 | XPutImage (target->dpy, pixmap, gc, ximage, 0, 0, dst_x, dst_y, width, height); |
|
|
706 | XDestroyImage (ximage); |
|
|
707 | return true; |
|
|
708 | } |
|
|
709 | |
729 | bool |
710 | bool |
730 | bgPixmap_t::render_image (unsigned long background_flags) |
711 | bgPixmap_t::render_image (unsigned long background_flags) |
731 | { |
712 | { |
732 | if (target == NULL) |
713 | if (target == NULL) |
733 | return false; |
714 | return false; |
… | |
… | |
796 | new_pmap_width = min (image_width, target_width); |
777 | new_pmap_width = min (image_width, target_width); |
797 | new_pmap_height = min (image_height, target_height); |
778 | new_pmap_height = min (image_height, target_height); |
798 | } |
779 | } |
799 | } |
780 | } |
800 | |
781 | |
801 | if (pixmap) |
|
|
802 | { |
|
|
803 | if (pmap_width != new_pmap_width |
|
|
804 | || pmap_height != new_pmap_height |
|
|
805 | || pmap_depth != target->depth) |
|
|
806 | { |
|
|
807 | XFreePixmap (target->dpy, pixmap); |
|
|
808 | pixmap = None; |
|
|
809 | } |
|
|
810 | } |
|
|
811 | |
|
|
812 | if (pixmap == None) |
782 | if (pixmap == None |
|
|
783 | || pmap_width != new_pmap_width |
|
|
784 | || pmap_height != new_pmap_height) |
813 | { |
785 | { |
|
|
786 | if (pixmap) |
|
|
787 | XFreePixmap (target->dpy, pixmap); |
814 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
788 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
815 | pmap_width = new_pmap_width; |
789 | pmap_width = new_pmap_width; |
816 | pmap_height = new_pmap_height; |
790 | pmap_height = new_pmap_height; |
817 | pmap_depth = target->depth; |
|
|
818 | } |
791 | } |
819 | |
792 | |
820 | gcv.foreground = target->pix_colors[Color_bg]; |
793 | gcv.foreground = target->pix_colors[Color_bg]; |
821 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
794 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
822 | |
795 | |
823 | if (h_scale == 0 || v_scale == 0) |
796 | if (h_scale == 0 || v_scale == 0) |
824 | { |
797 | { |
825 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
798 | Pixmap tile = XCreatePixmap (target->dpy, target->vt, image_width, image_height, target->depth); |
826 | gdk_pixbuf_xlib_render_to_drawable (result, tile, gc, |
799 | pixbuf_to_pixmap (result, tile, gc, |
827 | 0, 0, |
800 | 0, 0, |
828 | 0, 0, |
801 | 0, 0, |
829 | image_width, image_height, |
802 | image_width, image_height); |
830 | XLIB_RGB_DITHER_NONE, |
|
|
831 | 0, 0); |
|
|
832 | |
803 | |
833 | gcv.tile = tile; |
804 | gcv.tile = tile; |
834 | gcv.fill_style = FillTiled; |
805 | gcv.fill_style = FillTiled; |
835 | gcv.ts_x_origin = x; |
806 | gcv.ts_x_origin = x; |
836 | gcv.ts_y_origin = y; |
807 | gcv.ts_y_origin = y; |
… | |
… | |
851 | || dst_x + dst_width < new_pmap_width |
822 | || dst_x + dst_width < new_pmap_width |
852 | || dst_y + dst_height < new_pmap_height) |
823 | || dst_y + dst_height < new_pmap_height) |
853 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
824 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
854 | |
825 | |
855 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
826 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
856 | gdk_pixbuf_xlib_render_to_drawable (result, pixmap, gc, |
827 | pixbuf_to_pixmap (result, pixmap, gc, |
857 | src_x, src_y, |
828 | src_x, src_y, |
858 | dst_x, dst_y, |
829 | dst_x, dst_y, |
859 | dst_width, dst_height, |
830 | dst_width, dst_height); |
860 | XLIB_RGB_DITHER_NONE, |
|
|
861 | 0, 0); |
|
|
862 | } |
831 | } |
863 | |
832 | |
864 | #if XRENDER |
833 | #if XRENDER |
865 | if (background_flags) |
834 | if (background_flags) |
866 | { |
835 | { |
… | |
… | |
933 | if (image) |
902 | if (image) |
934 | { |
903 | { |
935 | if (original_asim) |
904 | if (original_asim) |
936 | safe_asimage_destroy (original_asim); |
905 | safe_asimage_destroy (original_asim); |
937 | original_asim = image; |
906 | original_asim = image; |
|
|
907 | flags |= CLIENT_RENDER; |
938 | have_image = true; |
908 | have_image = true; |
939 | return true; |
909 | return true; |
940 | } |
910 | } |
941 | # endif |
911 | # endif |
942 | |
912 | |
… | |
… | |
971 | } |
941 | } |
972 | |
942 | |
973 | bool |
943 | bool |
974 | bgPixmap_t::set_blur_radius (const char *geom) |
944 | bgPixmap_t::set_blur_radius (const char *geom) |
975 | { |
945 | { |
976 | int changed = 0; |
946 | bool changed = false; |
977 | unsigned int hr, vr; |
947 | unsigned int hr, vr; |
978 | int junk; |
948 | int junk; |
979 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
949 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
980 | |
950 | |
981 | if (!(geom_flags & WidthValue)) |
951 | if (!(geom_flags & WidthValue)) |
… | |
… | |
986 | min_it (hr, 128); |
956 | min_it (hr, 128); |
987 | min_it (vr, 128); |
957 | min_it (vr, 128); |
988 | |
958 | |
989 | if (h_blurRadius != hr) |
959 | if (h_blurRadius != hr) |
990 | { |
960 | { |
991 | ++changed; |
961 | changed = true; |
992 | h_blurRadius = hr; |
962 | h_blurRadius = hr; |
993 | } |
963 | } |
994 | |
964 | |
995 | if (v_blurRadius != vr) |
965 | if (v_blurRadius != vr) |
996 | { |
966 | { |
997 | ++changed; |
967 | changed = true; |
998 | v_blurRadius = vr; |
968 | v_blurRadius = vr; |
999 | } |
969 | } |
1000 | |
970 | |
1001 | if (v_blurRadius == 0 && h_blurRadius == 0) |
971 | if (v_blurRadius == 0 && h_blurRadius == 0) |
1002 | flags &= ~blurNeeded; |
972 | flags &= ~blurNeeded; |
1003 | else |
973 | else |
1004 | flags |= blurNeeded; |
974 | flags |= blurNeeded; |
1005 | |
975 | |
1006 | return (changed > 0); |
976 | return changed; |
1007 | } |
977 | } |
1008 | |
978 | |
1009 | static inline unsigned long |
979 | static inline unsigned long |
1010 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
980 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
1011 | { |
981 | { |
… | |
… | |
1014 | bool has_shade = shade != 100; |
984 | bool has_shade = shade != 100; |
1015 | |
985 | |
1016 | if (tint) |
986 | if (tint) |
1017 | { |
987 | { |
1018 | tint->get (c); |
988 | tint->get (c); |
1019 | # define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) |
989 | if (!has_shade |
1020 | if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) |
990 | && (c.r <= 0x00ff || c.r >= 0xff00) |
1021 | && IS_COMPONENT_WHOLESOME (c.g) |
991 | && (c.g <= 0x00ff || c.g >= 0xff00) |
1022 | && IS_COMPONENT_WHOLESOME (c.b)) |
992 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
1023 | flags |= bgPixmap_t::tintWholesome; |
993 | flags |= bgPixmap_t::tintWholesome; |
1024 | # undef IS_COMPONENT_WHOLESOME |
|
|
1025 | } |
994 | } |
1026 | |
995 | |
1027 | if (has_shade) |
996 | if (has_shade || tint) |
1028 | flags |= bgPixmap_t::tintNeeded; |
997 | flags |= bgPixmap_t::tintNeeded; |
1029 | else if (tint) |
|
|
1030 | { |
|
|
1031 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
|
|
1032 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
|
|
1033 | { |
|
|
1034 | flags |= bgPixmap_t::tintNeeded; |
|
|
1035 | } |
|
|
1036 | } |
|
|
1037 | |
998 | |
1038 | return flags; |
999 | return flags; |
1039 | } |
1000 | } |
1040 | |
1001 | |
1041 | bool |
1002 | bool |
… | |
… | |
1044 | if (!(flags & tintSet) || tint != new_tint) |
1005 | if (!(flags & tintSet) || tint != new_tint) |
1045 | { |
1006 | { |
1046 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
1007 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
1047 | tint = new_tint; |
1008 | tint = new_tint; |
1048 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
1009 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
1049 | return true; |
|
|
1050 | } |
|
|
1051 | |
|
|
1052 | return false; |
|
|
1053 | } |
|
|
1054 | |
|
|
1055 | bool |
|
|
1056 | bgPixmap_t::unset_tint () |
|
|
1057 | { |
|
|
1058 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
|
|
1059 | |
|
|
1060 | if (new_flags != (flags & tintFlags)) |
|
|
1061 | { |
|
|
1062 | flags = (flags & ~tintFlags) | new_flags; |
|
|
1063 | return true; |
1010 | return true; |
1064 | } |
1011 | } |
1065 | |
1012 | |
1066 | return false; |
1013 | return false; |
1067 | } |
1014 | } |
… | |
… | |
1212 | c.g = (c.g * shade) / 100; |
1159 | c.g = (c.g * shade) / 100; |
1213 | c.b = (c.b * shade) / 100; |
1160 | c.b = (c.b * shade) / 100; |
1214 | } |
1161 | } |
1215 | else |
1162 | else |
1216 | { |
1163 | { |
1217 | c.r = ((0xffff - c.r) * (200 - shade)) / 100; |
1164 | c.r = (c.r * (200 - shade)) / 100; |
1218 | c.g = ((0xffff - c.g) * (200 - shade)) / 100; |
1165 | c.g = (c.g * (200 - shade)) / 100; |
1219 | c.b = ((0xffff - c.b) * (200 - shade)) / 100; |
1166 | c.b = (c.b * (200 - shade)) / 100; |
1220 | } |
1167 | } |
1221 | |
1168 | |
1222 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1169 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1223 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1170 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1224 | XRenderPictureAttributes pa; |
1171 | XRenderPictureAttributes pa; |
… | |
… | |
1238 | |
1185 | |
1239 | if (mask_pic && overlay_pic && back_pic) |
1186 | if (mask_pic && overlay_pic && back_pic) |
1240 | { |
1187 | { |
1241 | XRenderColor mask_c; |
1188 | XRenderColor mask_c; |
1242 | |
1189 | |
1243 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
1190 | mask_c.red = mask_c.green = mask_c.blue = 0; |
1244 | mask_c.alpha = 0xffff; |
1191 | mask_c.alpha = 0xffff; |
1245 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1192 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1246 | |
1193 | |
1247 | mask_c.alpha = 0; |
1194 | mask_c.alpha = 0; |
1248 | mask_c.red = 0xffff - c.r; |
1195 | mask_c.red = 0xffff - c.r; |
1249 | mask_c.green = 0xffff - c.g; |
1196 | mask_c.green = 0xffff - c.g; |
1250 | mask_c.blue = 0xffff - c.b; |
1197 | mask_c.blue = 0xffff - c.b; |
1251 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1198 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1252 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1199 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1200 | |
|
|
1201 | if (shade > 100) |
|
|
1202 | { |
|
|
1203 | mask_c.red = mask_c.green = mask_c.blue = 0xffff * (shade - 100) / 100; |
|
|
1204 | mask_c.alpha = 0; |
|
|
1205 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1206 | |
|
|
1207 | XRenderComposite (dpy, PictOpOver, overlay_pic, None, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
|
|
1208 | } |
|
|
1209 | |
1253 | ret = true; |
1210 | ret = true; |
1254 | } |
1211 | } |
1255 | |
1212 | |
1256 | XRenderFreePicture (dpy, mask_pic); |
1213 | XRenderFreePicture (dpy, mask_pic); |
1257 | XRenderFreePicture (dpy, overlay_pic); |
1214 | XRenderFreePicture (dpy, overlay_pic); |
… | |
… | |
1288 | int window_height = target->szHint.height; |
1245 | int window_height = target->szHint.height; |
1289 | int sx, sy; |
1246 | int sx, sy; |
1290 | XGCValues gcv; |
1247 | XGCValues gcv; |
1291 | GC gc; |
1248 | GC gc; |
1292 | |
1249 | |
1293 | target->get_window_origin (sx, sy); |
1250 | sx = target_x; |
|
|
1251 | sy = target_y; |
1294 | |
1252 | |
1295 | /* check if we are outside of the visible part of the virtual screen : */ |
1253 | /* check if we are outside of the visible part of the virtual screen : */ |
1296 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1254 | if (sx + window_width <= 0 || sy + window_height <= 0 |
1297 | || sx >= root_width || sy >= root_height) |
1255 | || sx >= root_width || sy >= root_height) |
1298 | return 0; |
1256 | return 0; |
… | |
… | |
1345 | } |
1303 | } |
1346 | |
1304 | |
1347 | if (root_pixmap == None) |
1305 | if (root_pixmap == None) |
1348 | return 0; |
1306 | return 0; |
1349 | |
1307 | |
|
|
1308 | if (pixmap == None |
|
|
1309 | || pmap_width != window_width |
|
|
1310 | || pmap_height != window_height) |
|
|
1311 | { |
|
|
1312 | if (pixmap) |
|
|
1313 | XFreePixmap (target->dpy, pixmap); |
1350 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, target->vt, window_width, window_height, target->depth); |
1314 | pixmap = XCreatePixmap (target->dpy, target->vt, window_width, window_height, target->depth); |
|
|
1315 | pmap_width = window_width; |
|
|
1316 | pmap_height = window_height; |
|
|
1317 | } |
1351 | |
1318 | |
1352 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
1319 | if (pixmap == None) |
1353 | return 0; |
1320 | return 0; |
1354 | |
1321 | |
1355 | /* straightforward pixmap copy */ |
1322 | /* straightforward pixmap copy */ |
|
|
1323 | while (sx < 0) sx += (int)root_width; |
|
|
1324 | while (sy < 0) sy += (int)root_height; |
|
|
1325 | |
1356 | gcv.tile = recoded_root_pmap; |
1326 | gcv.tile = recoded_root_pmap; |
1357 | gcv.fill_style = FillTiled; |
1327 | gcv.fill_style = FillTiled; |
1358 | |
|
|
1359 | while (sx < 0) sx += (int)root_width; |
|
|
1360 | while (sy < 0) sy += (int)root_height; |
|
|
1361 | |
|
|
1362 | gcv.ts_x_origin = -sx; |
1328 | gcv.ts_x_origin = -sx; |
1363 | gcv.ts_y_origin = -sy; |
1329 | gcv.ts_y_origin = -sy; |
1364 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1330 | gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
1365 | |
1331 | |
1366 | if (gc) |
1332 | if (gc) |
1367 | { |
1333 | { |
1368 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
1334 | XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height); |
1369 | result |= transpPmapTiled; |
1335 | result |= transpPmapTiled; |
1370 | XFreeGC (dpy, gc); |
1336 | XFreeGC (dpy, gc); |
1371 | } |
|
|
1372 | |
1337 | |
1373 | if (tiled_root_pmap != None) |
1338 | if (!(flags & CLIENT_RENDER)) |
1374 | { |
|
|
1375 | if (!need_client_side_rendering ()) |
|
|
1376 | { |
1339 | { |
1377 | if ((flags & blurNeeded) |
1340 | if ((flags & blurNeeded) |
1378 | && (flags & HAS_RENDER_CONV)) |
1341 | && (flags & HAS_RENDER_CONV)) |
1379 | { |
1342 | { |
1380 | if (blur_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1343 | if (blur_pixmap (pixmap, target->visual, window_width, window_height)) |
1381 | result |= transpPmapBlurred; |
1344 | result |= transpPmapBlurred; |
1382 | } |
1345 | } |
1383 | if ((flags & tintNeeded) |
1346 | if ((flags & tintNeeded) |
1384 | && (flags & (tintWholesome | HAS_RENDER))) |
1347 | && (flags & (tintWholesome | HAS_RENDER))) |
1385 | { |
1348 | { |
1386 | if (tint_pixmap (tiled_root_pmap, target->visual, window_width, window_height)) |
1349 | if (tint_pixmap (pixmap, target->visual, window_width, window_height)) |
1387 | result |= transpPmapTinted; |
1350 | result |= transpPmapTinted; |
1388 | } |
1351 | } |
1389 | } /* server side rendering completed */ |
1352 | } /* server side rendering completed */ |
1390 | |
|
|
1391 | if (pixmap) |
|
|
1392 | XFreePixmap (dpy, pixmap); |
|
|
1393 | |
|
|
1394 | pixmap = tiled_root_pmap; |
|
|
1395 | pmap_width = window_width; |
|
|
1396 | pmap_height = window_height; |
|
|
1397 | pmap_depth = target->depth; |
|
|
1398 | } |
1353 | } |
1399 | |
1354 | |
1400 | if (recoded_root_pmap != root_pixmap) |
1355 | if (recoded_root_pmap != root_pixmap) |
1401 | XFreePixmap (dpy, recoded_root_pmap); |
1356 | XFreePixmap (dpy, recoded_root_pmap); |
1402 | |
1357 | |
… | |
… | |
1404 | } |
1359 | } |
1405 | |
1360 | |
1406 | void |
1361 | void |
1407 | bgPixmap_t::set_root_pixmap () |
1362 | bgPixmap_t::set_root_pixmap () |
1408 | { |
1363 | { |
1409 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1364 | Pixmap new_root_pixmap = target->get_pixmap_property (target->xa[XA_XROOTPMAP_ID]); |
1410 | if (new_root_pixmap == None) |
1365 | if (new_root_pixmap == None) |
1411 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1366 | new_root_pixmap = target->get_pixmap_property (target->xa[XA_ESETROOT_PMAP_ID]); |
1412 | |
1367 | |
1413 | root_pixmap = new_root_pixmap; |
1368 | root_pixmap = new_root_pixmap; |
1414 | } |
1369 | } |
1415 | # endif /* ENABLE_TRANSPARENCY */ |
1370 | # endif /* ENABLE_TRANSPARENCY */ |
1416 | |
1371 | |
1417 | # ifndef HAVE_AFTERIMAGE |
1372 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1418 | static void ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm); |
1373 | static void shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c); |
1419 | # endif |
1374 | # endif |
1420 | |
1375 | |
1421 | bool |
1376 | bool |
1422 | bgPixmap_t::render () |
1377 | bgPixmap_t::render () |
1423 | { |
1378 | { |
… | |
… | |
1433 | /* we need to re-generate transparency pixmap in that case ! */ |
1388 | /* we need to re-generate transparency pixmap in that case ! */ |
1434 | background_flags = make_transparency_pixmap (); |
1389 | background_flags = make_transparency_pixmap (); |
1435 | if (background_flags == 0) |
1390 | if (background_flags == 0) |
1436 | return false; |
1391 | return false; |
1437 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1392 | else if ((background_flags & transpTransformations) == (flags & transpTransformations)) |
1438 | flags = flags & ~isInvalid; |
1393 | flags &= ~isInvalid; |
1439 | } |
1394 | } |
1440 | # endif |
1395 | # endif |
1441 | |
1396 | |
1442 | # ifdef BG_IMAGE_FROM_FILE |
1397 | # ifdef BG_IMAGE_FROM_FILE |
1443 | if (have_image |
1398 | if (have_image |
1444 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1399 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
1445 | { |
1400 | { |
1446 | if (render_image (background_flags)) |
1401 | if (render_image (background_flags)) |
1447 | flags = flags & ~isInvalid; |
1402 | flags &= ~isInvalid; |
1448 | } |
1403 | } |
1449 | # endif |
1404 | # endif |
1450 | |
1405 | |
|
|
1406 | # if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1451 | XImage *result = NULL; |
1407 | XImage *result = NULL; |
1452 | |
1408 | |
1453 | if (background_flags && (flags & isInvalid)) |
1409 | if (background_flags && (flags & isInvalid)) |
1454 | { |
1410 | { |
1455 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1411 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
1456 | } |
1412 | } |
1457 | |
1413 | |
1458 | if (result) |
1414 | if (result) |
1459 | { |
1415 | { |
1460 | # if !defined(HAVE_AFTERIMAGE) && !XRENDER |
|
|
1461 | /* our own client-side tinting */ |
1416 | /* our own client-side tinting */ |
1462 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1417 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
1463 | { |
1418 | { |
1464 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1419 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1465 | if (flags & tintSet) |
1420 | if (flags & tintSet) |
1466 | tint.get (c); |
1421 | tint.get (c); |
1467 | ShadeXImage (DefaultVisual (target->dpy, target->display->screen), result, shade, c.r, c.g, c.b); |
1422 | shade_ximage (DefaultVisual (target->dpy, target->display->screen), result, shade, c); |
1468 | } |
1423 | } |
1469 | # endif |
|
|
1470 | |
1424 | |
1471 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1425 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1472 | |
1426 | |
1473 | if (gc) |
1427 | if (gc) |
1474 | { |
1428 | { |
1475 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1429 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1476 | |
1430 | |
1477 | XFreeGC (target->dpy, gc); |
1431 | XFreeGC (target->dpy, gc); |
1478 | flags = flags & ~isInvalid; |
1432 | flags &= ~isInvalid; |
1479 | } |
1433 | } |
1480 | |
1434 | |
1481 | XDestroyImage (result); |
1435 | XDestroyImage (result); |
1482 | } |
1436 | } |
|
|
1437 | # endif |
1483 | |
1438 | |
1484 | if (flags & isInvalid) |
1439 | if (flags & isInvalid) |
1485 | { |
1440 | { |
1486 | if (pixmap != None) |
1441 | if (pixmap != None) |
1487 | { |
1442 | { |
1488 | XFreePixmap (target->dpy, pixmap); |
1443 | XFreePixmap (target->dpy, pixmap); |
1489 | pixmap = None; |
1444 | pixmap = None; |
1490 | } |
1445 | } |
1491 | } |
1446 | } |
1492 | |
1447 | |
1493 | apply (); |
1448 | target->scr_recolour (false); |
|
|
1449 | flags |= hasChanged; |
1494 | |
1450 | |
1495 | valid_since = ev::now (); |
1451 | valid_since = ev::now (); |
1496 | |
1452 | |
1497 | return true; |
1453 | return true; |
1498 | } |
1454 | } |
… | |
… | |
1517 | XFree (filters); |
1473 | XFree (filters); |
1518 | } |
1474 | } |
1519 | #endif |
1475 | #endif |
1520 | } |
1476 | } |
1521 | |
1477 | |
1522 | void |
|
|
1523 | bgPixmap_t::apply () |
|
|
1524 | { |
|
|
1525 | if (target == NULL) |
|
|
1526 | return; |
|
|
1527 | |
|
|
1528 | if (pixmap != None) |
|
|
1529 | { |
|
|
1530 | /* set target's background to pixmap */ |
|
|
1531 | # ifdef ENABLE_TRANSPARENCY |
|
|
1532 | if (flags & isTransparent) |
|
|
1533 | { |
|
|
1534 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
|
|
1535 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
|
|
1536 | |
|
|
1537 | if (target->scrollBar.win) |
|
|
1538 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
|
|
1539 | } |
|
|
1540 | else |
|
|
1541 | # endif |
|
|
1542 | { |
|
|
1543 | /* force old pixmap dereference in case it was transparent before :*/ |
|
|
1544 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1545 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1546 | /* do we also need to set scrollbar's background here ? */ |
|
|
1547 | |
|
|
1548 | if (target->scrollBar.win) |
|
|
1549 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1550 | } |
|
|
1551 | } |
|
|
1552 | else |
|
|
1553 | { |
|
|
1554 | /* set target background to a pixel */ |
|
|
1555 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1556 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
1557 | /* do we also need to set scrollbar's background here ? */ |
|
|
1558 | if (target->scrollBar.win) |
|
|
1559 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1560 | } |
|
|
1561 | |
|
|
1562 | /* don't want Expose on the parent or vt. It is better to use |
|
|
1563 | scr_touch or we get a great deal of flicker otherwise: */ |
|
|
1564 | XClearWindow (target->dpy, target->parent[0]); |
|
|
1565 | |
|
|
1566 | if (target->scrollBar.state && target->scrollBar.win) |
|
|
1567 | { |
|
|
1568 | target->scrollBar.state = STATE_IDLE; |
|
|
1569 | target->scrollBar.show (0); |
|
|
1570 | } |
|
|
1571 | |
|
|
1572 | target->want_refresh = 1; |
|
|
1573 | flags |= hasChanged; |
|
|
1574 | } |
|
|
1575 | |
|
|
1576 | #endif /* HAVE_BG_PIXMAP */ |
1478 | #endif /* HAVE_BG_PIXMAP */ |
1577 | |
1479 | |
1578 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XRENDER |
1480 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) |
1579 | /* taken from aterm-0.4.2 */ |
1481 | /* taken from aterm-0.4.2 */ |
1580 | |
1482 | |
1581 | static void |
1483 | static void |
1582 | ShadeXImage(Visual *visual, XImage *srcImage, int shade, int rm, int gm, int bm) |
1484 | shade_ximage (Visual *visual, XImage *ximage, int shade, const rgba &c) |
1583 | { |
1485 | { |
1584 | int sh_r, sh_g, sh_b; |
1486 | int sh_r, sh_g, sh_b; |
1585 | uint32_t mask_r, mask_g, mask_b; |
1487 | uint32_t mask_r, mask_g, mask_b; |
1586 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1488 | uint32_t *lookup, *lookup_r, *lookup_g, *lookup_b; |
1587 | unsigned int lower_lim_r, lower_lim_g, lower_lim_b; |
1489 | rgba low; |
1588 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1490 | rgba high; |
1589 | int i; |
1491 | int i; |
1590 | int host_byte_order = byteorder.big_endian () ? MSBFirst : LSBFirst; |
1492 | int host_byte_order = byteorder::big_endian () ? MSBFirst : LSBFirst; |
1591 | |
1493 | |
1592 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return; |
1494 | if (visual->c_class != TrueColor || ximage->format != ZPixmap) return; |
1593 | |
1495 | |
1594 | /* for convenience */ |
1496 | /* for convenience */ |
1595 | mask_r = visual->red_mask; |
1497 | mask_r = visual->red_mask; |
1596 | mask_g = visual->green_mask; |
1498 | mask_g = visual->green_mask; |
1597 | mask_b = visual->blue_mask; |
1499 | mask_b = visual->blue_mask; |
1598 | |
1500 | |
1599 | /* boring lookup table pre-initialization */ |
1501 | /* boring lookup table pre-initialization */ |
1600 | switch (srcImage->depth) |
1502 | switch (ximage->depth) |
1601 | { |
1503 | { |
1602 | case 15: |
1504 | case 15: |
1603 | if ((mask_r != 0x7c00) || |
1505 | if ((mask_r != 0x7c00) || |
1604 | (mask_g != 0x03e0) || |
1506 | (mask_g != 0x03e0) || |
1605 | (mask_b != 0x001f)) |
1507 | (mask_b != 0x001f)) |
… | |
… | |
1658 | /* prepare limits for color transformation (each channel is handled separately) */ |
1560 | /* prepare limits for color transformation (each channel is handled separately) */ |
1659 | if (shade > 100) |
1561 | if (shade > 100) |
1660 | { |
1562 | { |
1661 | shade = 200 - shade; |
1563 | shade = 200 - shade; |
1662 | |
1564 | |
1663 | lower_lim_r = 65535-rm; |
1565 | high.r = c.r * shade / 100; |
1664 | lower_lim_g = 65535-gm; |
1566 | high.g = c.g * shade / 100; |
1665 | lower_lim_b = 65535-bm; |
1567 | high.b = c.b * shade / 100; |
1666 | |
1568 | |
1667 | lower_lim_r = 65535-(unsigned int)(((uint32_t)lower_lim_r)*((uint32_t)shade)/100); |
1569 | low.r = 65535 * (100 - shade) / 100; |
1668 | lower_lim_g = 65535-(unsigned int)(((uint32_t)lower_lim_g)*((uint32_t)shade)/100); |
1570 | low.g = 65535 * (100 - shade) / 100; |
1669 | lower_lim_b = 65535-(unsigned int)(((uint32_t)lower_lim_b)*((uint32_t)shade)/100); |
1571 | low.b = 65535 * (100 - shade) / 100; |
1670 | |
|
|
1671 | upper_lim_r = upper_lim_g = upper_lim_b = 65535; |
|
|
1672 | } |
1572 | } |
1673 | else |
1573 | else |
1674 | { |
1574 | { |
|
|
1575 | high.r = c.r * shade / 100; |
|
|
1576 | high.g = c.g * shade / 100; |
|
|
1577 | high.b = c.b * shade / 100; |
1675 | |
1578 | |
1676 | lower_lim_r = lower_lim_g = lower_lim_b = 0; |
1579 | low.r = low.g = low.b = 0; |
1677 | |
|
|
1678 | upper_lim_r = (unsigned int)((((uint32_t)rm)*((uint32_t)shade))/100); |
|
|
1679 | upper_lim_g = (unsigned int)((((uint32_t)gm)*((uint32_t)shade))/100); |
|
|
1680 | upper_lim_b = (unsigned int)((((uint32_t)bm)*((uint32_t)shade))/100); |
|
|
1681 | } |
1580 | } |
1682 | |
1581 | |
1683 | /* fill our lookup tables */ |
1582 | /* fill our lookup tables */ |
1684 | for (i = 0; i <= mask_r>>sh_r; i++) |
1583 | for (i = 0; i <= mask_r>>sh_r; i++) |
1685 | { |
1584 | { |
1686 | uint32_t tmp; |
1585 | uint32_t tmp; |
1687 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_r-lower_lim_r)); |
1586 | tmp = i * high.r; |
1688 | tmp += ((uint32_t)(mask_r>>sh_r))*((uint32_t)lower_lim_r); |
1587 | tmp += (mask_r>>sh_r) * low.r; |
1689 | lookup_r[i] = (tmp/65535)<<sh_r; |
1588 | lookup_r[i] = (tmp/65535)<<sh_r; |
1690 | } |
1589 | } |
1691 | for (i = 0; i <= mask_g>>sh_g; i++) |
1590 | for (i = 0; i <= mask_g>>sh_g; i++) |
1692 | { |
1591 | { |
1693 | uint32_t tmp; |
1592 | uint32_t tmp; |
1694 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_g-lower_lim_g)); |
1593 | tmp = i * high.g; |
1695 | tmp += ((uint32_t)(mask_g>>sh_g))*((uint32_t)lower_lim_g); |
1594 | tmp += (mask_g>>sh_g) * low.g; |
1696 | lookup_g[i] = (tmp/65535)<<sh_g; |
1595 | lookup_g[i] = (tmp/65535)<<sh_g; |
1697 | } |
1596 | } |
1698 | for (i = 0; i <= mask_b>>sh_b; i++) |
1597 | for (i = 0; i <= mask_b>>sh_b; i++) |
1699 | { |
1598 | { |
1700 | uint32_t tmp; |
1599 | uint32_t tmp; |
1701 | tmp = ((uint32_t)i)*((uint32_t)(upper_lim_b-lower_lim_b)); |
1600 | tmp = i * high.b; |
1702 | tmp += ((uint32_t)(mask_b>>sh_b))*((uint32_t)lower_lim_b); |
1601 | tmp += (mask_b>>sh_b) * low.b; |
1703 | lookup_b[i] = (tmp/65535)<<sh_b; |
1602 | lookup_b[i] = (tmp/65535)<<sh_b; |
1704 | } |
1603 | } |
1705 | |
1604 | |
1706 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1605 | /* apply table to input image (replacing colors by newly calculated ones) */ |
1707 | if (srcImage->bits_per_pixel == 32 |
1606 | if (ximage->bits_per_pixel == 32 |
1708 | && (srcImage->depth == 24 || srcImage->depth == 32) |
1607 | && (ximage->depth == 24 || ximage->depth == 32) |
1709 | && srcImage->byte_order == host_byte_order) |
1608 | && ximage->byte_order == host_byte_order) |
1710 | { |
1609 | { |
1711 | uint32_t *p1, *pf, *p, *pl; |
1610 | uint32_t *p1, *pf, *p, *pl; |
1712 | p1 = (uint32_t *) srcImage->data; |
1611 | p1 = (uint32_t *) ximage->data; |
1713 | pf = (uint32_t *) (srcImage->data + srcImage->height * srcImage->bytes_per_line); |
1612 | pf = (uint32_t *) (ximage->data + ximage->height * ximage->bytes_per_line); |
1714 | |
1613 | |
1715 | while (p1 < pf) |
1614 | while (p1 < pf) |
1716 | { |
1615 | { |
1717 | p = p1; |
1616 | p = p1; |
1718 | pl = p1 + srcImage->width; |
1617 | pl = p1 + ximage->width; |
1719 | for (; p < pl; p++) |
1618 | for (; p < pl; p++) |
1720 | { |
1619 | { |
1721 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1620 | *p = lookup_r[(*p & 0xff0000) >> 16] | |
1722 | lookup_g[(*p & 0x00ff00) >> 8] | |
1621 | lookup_g[(*p & 0x00ff00) >> 8] | |
1723 | lookup_b[(*p & 0x0000ff)] | |
1622 | lookup_b[(*p & 0x0000ff)] | |
1724 | (*p & 0xff000000); |
1623 | (*p & 0xff000000); |
1725 | } |
1624 | } |
1726 | p1 = (uint32_t *) ((char *) p1 + srcImage->bytes_per_line); |
1625 | p1 = (uint32_t *) ((char *) p1 + ximage->bytes_per_line); |
1727 | } |
1626 | } |
1728 | } |
1627 | } |
1729 | else |
1628 | else |
1730 | { |
1629 | { |
1731 | for (int y = 0; y < srcImage->height; y++) |
1630 | for (int y = 0; y < ximage->height; y++) |
1732 | for (int x = 0; x < srcImage->width; x++) |
1631 | for (int x = 0; x < ximage->width; x++) |
1733 | { |
1632 | { |
1734 | unsigned long pixel = XGetPixel (srcImage, x, y); |
1633 | unsigned long pixel = XGetPixel (ximage, x, y); |
1735 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
1634 | pixel = lookup_r[(pixel & mask_r) >> sh_r] | |
1736 | lookup_g[(pixel & mask_g) >> sh_g] | |
1635 | lookup_g[(pixel & mask_g) >> sh_g] | |
1737 | lookup_b[(pixel & mask_b) >> sh_b]; |
1636 | lookup_b[(pixel & mask_b) >> sh_b]; |
1738 | XPutPixel (srcImage, x, y, pixel); |
1637 | XPutPixel (ximage, x, y, pixel); |
1739 | } |
1638 | } |
1740 | } |
1639 | } |
1741 | |
1640 | |
1742 | free (lookup); |
1641 | free (lookup); |
1743 | } |
1642 | } |