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-2006 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 |
… | |
… | |
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) \ |
… | |
… | |
87 | * scale Scale both up and down |
85 | * scale Scale both up and down |
88 | * auto Same as 100x100+50+50 |
86 | * auto Same as 100x100+50+50 |
89 | */ |
87 | */ |
90 | |
88 | |
91 | #ifdef HAVE_BG_PIXMAP |
89 | #ifdef HAVE_BG_PIXMAP |
92 | bgPixmap_t::bgPixmap_t() |
90 | bgPixmap_t::bgPixmap_t () |
93 | { |
91 | { |
94 | #ifdef HAVE_AFTERIMAGE |
92 | #ifdef HAVE_AFTERIMAGE |
95 | original_asim = NULL; |
93 | original_asim = NULL; |
96 | #endif |
94 | #endif |
97 | #ifdef BG_IMAGE_FROM_FILE |
95 | #ifdef BG_IMAGE_FROM_FILE |
98 | h_scale = v_scale = 0; |
96 | h_scale = v_scale = 0; |
99 | h_align = v_align = 0; |
97 | h_align = v_align = 0; |
100 | #endif |
98 | #endif |
101 | flags = 0; |
99 | flags = 0; |
102 | pixmap = None; |
100 | pixmap = None; |
|
|
101 | valid_since = invalid_since = 0; |
103 | } |
102 | } |
104 | |
103 | |
105 | bgPixmap_t::~bgPixmap_t() |
104 | void |
|
|
105 | bgPixmap_t::destroy () |
106 | { |
106 | { |
107 | #ifdef HAVE_AFTERIMAGE |
107 | #ifdef HAVE_AFTERIMAGE |
108 | if (original_asim) |
108 | if (original_asim) |
109 | safe_asimage_destroy (original_asim); |
109 | safe_asimage_destroy (original_asim); |
110 | #endif |
110 | #endif |
|
|
111 | |
111 | if (pixmap && target) |
112 | if (pixmap && target) |
112 | XFreePixmap (target->dpy, pixmap); |
113 | XFreePixmap (target->dpy, pixmap); |
113 | } |
114 | } |
114 | |
115 | |
115 | bool |
116 | bool |
116 | bgPixmap_t::window_size_sensitive () |
117 | bgPixmap_t::window_size_sensitive () |
117 | { |
118 | { |
|
|
119 | # ifdef ENABLE_TRANSPARENCY |
|
|
120 | if (flags & isTransparent) |
|
|
121 | return true; |
|
|
122 | # endif |
|
|
123 | |
118 | # ifdef BG_IMAGE_FROM_FILE |
124 | # ifdef BG_IMAGE_FROM_FILE |
119 | # ifdef HAVE_AFTERIMAGE |
125 | # ifdef HAVE_AFTERIMAGE |
120 | if (original_asim != NULL) |
126 | if (original_asim != NULL) |
121 | # endif |
127 | # endif |
122 | { |
128 | { |
123 | if (h_scale != 0 || v_scale != 0 |
129 | if (h_scale != 0 || v_scale != 0 |
124 | || h_align != 0 || v_align != 0) |
130 | || h_align != 0 || v_align != 0) |
125 | return true; |
131 | return true; |
126 | } |
132 | } |
127 | # endif |
133 | # endif |
|
|
134 | |
|
|
135 | return false; |
|
|
136 | } |
|
|
137 | |
|
|
138 | bool |
|
|
139 | bgPixmap_t::window_position_sensitive () |
|
|
140 | { |
128 | # ifdef ENABLE_TRANSPARENCY |
141 | # ifdef ENABLE_TRANSPARENCY |
129 | if (flags & isTransparent) |
142 | if (flags & isTransparent) |
130 | return true; |
143 | return true; |
131 | # endif |
144 | # endif |
|
|
145 | |
|
|
146 | # ifdef BG_IMAGE_FROM_FILE |
|
|
147 | # ifdef HAVE_AFTERIMAGE |
|
|
148 | if (original_asim != NULL) |
|
|
149 | # endif |
|
|
150 | { |
|
|
151 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
152 | return true; |
|
|
153 | } |
|
|
154 | # endif |
|
|
155 | |
132 | return false; |
156 | return false; |
133 | } |
157 | }; |
134 | |
158 | |
135 | bool bgPixmap_t::need_client_side_rendering () |
159 | bool bgPixmap_t::need_client_side_rendering () |
136 | { |
160 | { |
137 | # ifdef HAVE_AFTERIMAGE |
161 | # ifdef HAVE_AFTERIMAGE |
138 | if (original_asim != NULL) |
162 | if (original_asim != NULL) |
… | |
… | |
172 | static inline bool |
196 | static inline bool |
173 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
197 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
174 | { |
198 | { |
175 | if (geom_flags & flag) |
199 | if (geom_flags & flag) |
176 | { |
200 | { |
|
|
201 | if (new_value != bgPixmap_t::rootAlign) |
|
|
202 | { |
177 | if (new_value < -100) |
203 | if (new_value < -100) |
178 | new_value = -100; |
204 | new_value = -100; |
179 | else if (new_value > 200) |
205 | else if (new_value > 200) |
180 | new_value = 200; |
206 | new_value = 200; |
|
|
207 | } |
181 | if (new_value != align) |
208 | if (new_value != align) |
182 | { |
209 | { |
183 | align = new_value; |
210 | align = new_value; |
184 | return true; |
211 | return true; |
185 | } |
212 | } |
… | |
… | |
230 | int x = 0, y = 0; |
257 | int x = 0, y = 0; |
231 | unsigned int w = 0, h = 0; |
258 | unsigned int w = 0, h = 0; |
232 | unsigned int n; |
259 | unsigned int n; |
233 | unsigned long new_flags = (flags & (~geometryFlags)); |
260 | unsigned long new_flags = (flags & (~geometryFlags)); |
234 | char *p; |
261 | char *p; |
235 | # define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
262 | # define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ |
236 | |
263 | |
237 | if (geom == NULL) |
264 | if (geom == NULL) |
238 | return false; |
265 | return false; |
239 | |
266 | |
240 | char str[MAXLEN_GEOM]; |
267 | char str[MAXLEN_GEOM]; |
… | |
… | |
277 | y = x; |
304 | y = x; |
278 | geom_flags |= YValue; |
305 | geom_flags |= YValue; |
279 | } |
306 | } |
280 | |
307 | |
281 | if (flags & geometrySet) |
308 | if (flags & geometrySet) |
|
|
309 | { |
282 | {/* new geometry is an adjustment to the old one ! */ |
310 | /* new geometry is an adjustment to the old one ! */ |
283 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
311 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
284 | { |
312 | { |
285 | if (w == 0 && h != 0) |
313 | if (w == 0 && h != 0) |
286 | { |
314 | { |
287 | w = h_scale; |
315 | w = h_scale; |
… | |
… | |
303 | } |
331 | } |
304 | } |
332 | } |
305 | else /* setting up geometry from scratch */ |
333 | else /* setting up geometry from scratch */ |
306 | { |
334 | { |
307 | if (!(geom_flags & XValue)) |
335 | if (!(geom_flags & XValue)) |
|
|
336 | { |
308 | {/* use default geometry - centered */ |
337 | /* use default geometry - centered */ |
309 | x = y = defaultAlign; |
338 | x = y = defaultAlign; |
310 | } |
339 | } |
311 | else if (!(geom_flags & YValue)) |
340 | else if (!(geom_flags & YValue)) |
312 | y = x; |
341 | y = x; |
313 | |
342 | |
314 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
343 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
|
|
344 | { |
315 | {/* use default geometry - scaled */ |
345 | /* use default geometry - scaled */ |
316 | w = h = defaultScale; |
346 | w = h = defaultScale; |
317 | } |
347 | } |
318 | else if (geom_flags & WidthValue) |
348 | else if (geom_flags & WidthValue) |
319 | { |
349 | { |
320 | if (!(geom_flags & HeightValue)) |
350 | if (!(geom_flags & HeightValue)) |
… | |
… | |
323 | else |
353 | else |
324 | w = h; |
354 | w = h; |
325 | } |
355 | } |
326 | } /* done parsing geometry string */ |
356 | } /* done parsing geometry string */ |
327 | else if (!(flags & geometrySet)) |
357 | else if (!(flags & geometrySet)) |
|
|
358 | { |
328 | { /* default geometry - scaled and centered */ |
359 | /* default geometry - scaled and centered */ |
329 | x = y = defaultAlign; |
360 | x = y = defaultAlign; |
330 | w = h = defaultScale; |
361 | w = h = defaultScale; |
331 | } |
362 | } |
332 | |
363 | |
333 | if (!(flags & geometrySet)) |
364 | if (!(flags & geometrySet)) |
… | |
… | |
339 | { |
370 | { |
340 | while (*ops == ':' || isspace(*ops)) ++ops; |
371 | while (*ops == ':' || isspace(*ops)) ++ops; |
341 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
372 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
342 | if (CHECK_GEOM_OPS("tile")) |
373 | if (CHECK_GEOM_OPS("tile")) |
343 | { |
374 | { |
344 | w = h = 0; |
375 | w = h = noScale; |
345 | geom_flags |= WidthValue|HeightValue; |
376 | geom_flags |= WidthValue|HeightValue; |
346 | } |
377 | } |
347 | else if (CHECK_GEOM_OPS("propscale")) |
378 | else if (CHECK_GEOM_OPS("propscale")) |
348 | { |
379 | { |
349 | if (w == 0 && h == 0) |
380 | if (w == 0 && h == 0) |
350 | { |
381 | { |
351 | w = 100; |
382 | w = windowScale; |
352 | geom_flags |= WidthValue; |
383 | geom_flags |= WidthValue; |
353 | } |
384 | } |
354 | new_flags |= propScale; |
385 | new_flags |= propScale; |
355 | } |
386 | } |
356 | else if (CHECK_GEOM_OPS("hscale")) |
387 | else if (CHECK_GEOM_OPS("hscale")) |
357 | { |
388 | { |
358 | if (w == 0) |
389 | if (w == 0) |
359 | w = 100; |
390 | w = windowScale; |
360 | h = 0; |
391 | h = noScale; |
361 | geom_flags |= WidthValue|HeightValue; |
392 | geom_flags |= WidthValue|HeightValue; |
362 | } |
393 | } |
363 | else if (CHECK_GEOM_OPS("vscale")) |
394 | else if (CHECK_GEOM_OPS("vscale")) |
364 | { |
395 | { |
365 | if (h == 0) |
396 | if (h == 0) |
366 | h = 100; |
397 | h = windowScale; |
367 | w = 0; |
398 | w = noScale; |
368 | geom_flags |= WidthValue|HeightValue; |
399 | geom_flags |= WidthValue|HeightValue; |
369 | } |
400 | } |
370 | else if (CHECK_GEOM_OPS("scale")) |
401 | else if (CHECK_GEOM_OPS("scale")) |
371 | { |
402 | { |
372 | if (h == 0) |
403 | if (h == 0) |
373 | h = 100; |
404 | h = windowScale; |
374 | if (w == 0) |
405 | if (w == 0) |
375 | w = 100; |
406 | w = windowScale; |
376 | geom_flags |= WidthValue|HeightValue; |
407 | geom_flags |= WidthValue|HeightValue; |
377 | } |
408 | } |
378 | else if (CHECK_GEOM_OPS("auto")) |
409 | else if (CHECK_GEOM_OPS("auto")) |
379 | { |
410 | { |
|
|
411 | w = h = windowScale; |
|
|
412 | x = y = centerAlign; |
|
|
413 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
414 | } |
|
|
415 | else if (CHECK_GEOM_OPS("root")) |
|
|
416 | { |
380 | w = h = 100; |
417 | w = h = noScale; |
381 | x = y = 50; |
418 | x = y = rootAlign; |
382 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
419 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
383 | } |
420 | } |
384 | # undef CHECK_GEOM_OPS |
421 | # undef CHECK_GEOM_OPS |
385 | while (*ops != ':' && *ops != '\0') ++ops; |
422 | while (*ops != ':' && *ops != '\0') ++ops; |
386 | } /* done parsing ops */ |
423 | } /* done parsing ops */ |
… | |
… | |
399 | if (new_flags != flags) |
436 | if (new_flags != flags) |
400 | { |
437 | { |
401 | flags = new_flags; |
438 | flags = new_flags; |
402 | changed++; |
439 | changed++; |
403 | } |
440 | } |
404 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
441 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
405 | // flags, h_scale, v_scale, h_align, v_align); |
442 | // flags, h_scale, v_scale, h_align, v_align); |
406 | return (changed > 0); |
443 | return (changed > 0); |
407 | } |
444 | } |
408 | |
445 | |
409 | # ifdef HAVE_AFTERIMAGE |
446 | # ifdef HAVE_AFTERIMAGE |
… | |
… | |
425 | |
462 | |
426 | TIMING_TEST_START (asim); |
463 | TIMING_TEST_START (asim); |
427 | |
464 | |
428 | if (original_asim) |
465 | if (original_asim) |
429 | { |
466 | { |
|
|
467 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
468 | { |
|
|
469 | target->get_window_origin(x, y); |
|
|
470 | x = -x; |
|
|
471 | y = -y; |
|
|
472 | } |
|
|
473 | if (h_align != rootAlign) |
430 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
474 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
475 | if (v_align != rootAlign) |
431 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
476 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
432 | } |
477 | } |
433 | |
478 | |
434 | if (original_asim == NULL |
479 | if (original_asim == NULL |
435 | || x >= target_width |
480 | || x >= target_width |
436 | || y >= target_height |
481 | || y >= target_height |
… | |
… | |
465 | h > 0 ? h : original_asim->height, |
510 | h > 0 ? h : original_asim->height, |
466 | background ? ASA_ASImage : ASA_XImage, |
511 | background ? ASA_ASImage : ASA_XImage, |
467 | 100, ASIMAGE_QUALITY_DEFAULT); |
512 | 100, ASIMAGE_QUALITY_DEFAULT); |
468 | } |
513 | } |
469 | if (background == NULL) |
514 | if (background == NULL) |
|
|
515 | { |
470 | {/* if tiling - pixmap has to be sized exactly as the image */ |
516 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
517 | but there is no need to make it bigger than the window! */ |
471 | if (h_scale == 0) |
518 | if (h_scale == 0) |
472 | new_pmap_width = result->width; |
519 | new_pmap_width = min (result->width, target_width); |
473 | if (v_scale == 0) |
520 | if (v_scale == 0) |
474 | new_pmap_height = result->height; |
521 | new_pmap_height = min (result->height, target_height); |
475 | /* we also need to tile our image in one or both directions */ |
522 | /* we also need to tile our image in one or both directions */ |
476 | if (h_scale == 0 || v_scale == 0) |
523 | if (h_scale == 0 || v_scale == 0) |
477 | { |
524 | { |
478 | ASImage *tmp = tile_asimage (target->asv, result, |
525 | ASImage *tmp = tile_asimage (target->asv, result, |
479 | (h_scale > 0) ? 0 : (int)result->width - x, |
526 | (h_scale > 0) ? 0 : (int)result->width - x, |
480 | (v_scale > 0) ? 0 : (int)result->height - y, |
527 | (v_scale > 0) ? 0 : (int)result->height - y, |
|
|
528 | new_pmap_width, |
481 | result->width, result->height, |
529 | new_pmap_height, |
482 | TINT_LEAVE_SAME, ASA_XImage, |
530 | TINT_LEAVE_SAME, ASA_XImage, |
483 | 100, ASIMAGE_QUALITY_DEFAULT); |
531 | 100, ASIMAGE_QUALITY_DEFAULT); |
484 | if (tmp) |
532 | if (tmp) |
485 | { |
533 | { |
486 | if (result != original_asim) |
534 | if (result != original_asim) |
… | |
… | |
488 | result = tmp; |
536 | result = tmp; |
489 | } |
537 | } |
490 | } |
538 | } |
491 | } |
539 | } |
492 | else |
540 | else |
|
|
541 | { |
493 | {/* if blending background and image - pixmap has to be sized same as target window */ |
542 | /* if blending background and image - pixmap has to be sized same as target window */ |
494 | ASImageLayer *layers = create_image_layers (2); |
543 | ASImageLayer *layers = create_image_layers (2); |
495 | ASImage *merged_im = NULL; |
544 | ASImage *merged_im = NULL; |
496 | |
545 | |
497 | layers[0].im = background; |
546 | layers[0].im = background; |
498 | layers[0].clip_width = target_width; |
547 | layers[0].clip_width = target_width; |
499 | layers[0].clip_height = target_height; |
548 | layers[0].clip_height = target_height; |
500 | layers[0].tint = background_tint; |
549 | layers[0].tint = background_tint; |
501 | layers[1].im = result; |
550 | layers[1].im = result; |
502 | if (w <= 0) |
551 | if (w <= 0) |
|
|
552 | { |
503 | {/* tile horizontally */ |
553 | /* tile horizontally */ |
504 | while (x > 0) x -= (int)result->width; |
554 | while (x > 0) x -= (int)result->width; |
505 | layers[1].dst_x = x; |
555 | layers[1].dst_x = x; |
506 | layers[1].clip_width = result->width+target_width; |
556 | layers[1].clip_width = result->width+target_width; |
507 | } |
557 | } |
508 | else |
558 | else |
|
|
559 | { |
509 | {/* clip horizontally */ |
560 | /* clip horizontally */ |
510 | layers[1].dst_x = x; |
561 | layers[1].dst_x = x; |
511 | layers[1].clip_width = result->width; |
562 | layers[1].clip_width = result->width; |
512 | } |
563 | } |
513 | if (h <= 0) |
564 | if (h <= 0) |
514 | { |
565 | { |
… | |
… | |
729 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
780 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
730 | tint = new_tint; |
781 | tint = new_tint; |
731 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
782 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
732 | return true; |
783 | return true; |
733 | } |
784 | } |
|
|
785 | |
734 | return false; |
786 | return false; |
735 | } |
787 | } |
736 | |
788 | |
737 | bool |
789 | bool |
738 | bgPixmap_t::unset_tint () |
790 | bgPixmap_t::unset_tint () |
… | |
… | |
742 | if (new_flags != (flags & tintFlags)) |
794 | if (new_flags != (flags & tintFlags)) |
743 | { |
795 | { |
744 | flags = (flags&~tintFlags)|new_flags; |
796 | flags = (flags&~tintFlags)|new_flags; |
745 | return true; |
797 | return true; |
746 | } |
798 | } |
|
|
799 | |
747 | return false; |
800 | return false; |
748 | } |
801 | } |
749 | |
802 | |
750 | bool |
803 | bool |
751 | bgPixmap_t::set_shade (const char *shade_str) |
804 | bgPixmap_t::set_shade (const char *shade_str) |
752 | { |
805 | { |
753 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
806 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
754 | |
807 | |
755 | if (new_shade < 0 && new_shade > -100) |
808 | if (new_shade < 0 && new_shade > -100) |
756 | new_shade = 200 - (100 + new_shade); |
809 | new_shade = 200 - (100 + new_shade); |
757 | else if (new_shade == 100) |
810 | else if (new_shade == 100) |
758 | new_shade = 0; |
811 | new_shade = 0; |
759 | |
812 | |
760 | if (new_shade != shade) |
813 | if (new_shade != shade) |
761 | { |
814 | { |
762 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
815 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
763 | shade = new_shade; |
816 | shade = new_shade; |
764 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
817 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
765 | return true; |
818 | return true; |
766 | } |
819 | } |
|
|
820 | |
767 | return false; |
821 | return false; |
768 | } |
822 | } |
769 | |
823 | |
770 | /* make_transparency_pixmap() |
824 | /* make_transparency_pixmap() |
771 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
825 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
… | |
… | |
801 | if (sx + window_width <= 0 || sy + window_height <= 0 |
855 | if (sx + window_width <= 0 || sy + window_height <= 0 |
802 | || sx >= root_width || sy >= root_height) |
856 | || sx >= root_width || sy >= root_height) |
803 | return 0; |
857 | return 0; |
804 | |
858 | |
805 | if (root_pixmap != None) |
859 | if (root_pixmap != None) |
|
|
860 | { |
806 | {/* we want to validate the pixmap and get it's size at the same time : */ |
861 | /* we want to validate the pixmap and get it's size at the same time : */ |
807 | int junk; |
862 | int junk; |
808 | unsigned int ujunk; |
863 | unsigned int ujunk; |
809 | /* root pixmap may be bad - allow a error */ |
864 | /* root pixmap may be bad - allow a error */ |
810 | target->allowedxerror = -1; |
865 | target->allowedxerror = -1; |
811 | |
866 | |
… | |
… | |
820 | |
875 | |
821 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
876 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
822 | return 0; |
877 | return 0; |
823 | |
878 | |
824 | if (root_pixmap == None) |
879 | if (root_pixmap == None) |
|
|
880 | { |
825 | { /* use tricks to obtain the root background image :*/ |
881 | /* use tricks to obtain the root background image :*/ |
826 | /* we want to create Overrideredirect window overlapping out window |
882 | /* we want to create Overrideredirect window overlapping out window |
827 | with background type of Parent Relative and then grab it */ |
883 | with background type of Parent Relative and then grab it */ |
828 | XSetWindowAttributes attr; |
884 | XSetWindowAttributes attr; |
829 | Window src; |
885 | Window src; |
830 | bool success = false; |
886 | bool success = false; |
… | |
… | |
845 | XGrabServer (dpy); |
901 | XGrabServer (dpy); |
846 | XMapRaised (dpy, src); |
902 | XMapRaised (dpy, src); |
847 | XSync (dpy, False); |
903 | XSync (dpy, False); |
848 | |
904 | |
849 | /* XSync should get window where it's properly exposed, |
905 | /* XSync should get window where it's properly exposed, |
850 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
906 | * but to be on the safe side - let's check for the actual event to arrive : */ |
851 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
907 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
852 | ++ev_count; |
908 | ++ev_count; |
853 | |
909 | |
854 | if (ev_count > 0); |
910 | if (ev_count > 0); |
|
|
911 | { |
855 | { /* hooray! - we can grab the image! */ |
912 | /* hooray! - we can grab the image! */ |
856 | gc = XCreateGC (dpy, root, 0, NULL); |
913 | gc = XCreateGC (dpy, root, 0, NULL); |
857 | if (gc) |
914 | if (gc) |
858 | { |
915 | { |
859 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
916 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
860 | success = true; |
917 | success = true; |
861 | } |
918 | } |
862 | } |
919 | } |
|
|
920 | |
863 | XDestroyWindow (dpy, src); |
921 | XDestroyWindow (dpy, src); |
864 | XUngrabServer (dpy); |
922 | XUngrabServer (dpy); |
865 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
923 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
866 | } |
924 | } |
867 | |
925 | |
… | |
… | |
872 | } |
930 | } |
873 | else |
931 | else |
874 | result |= transpPmapTiled; |
932 | result |= transpPmapTiled; |
875 | } |
933 | } |
876 | else |
934 | else |
|
|
935 | { |
877 | {/* strightforward pixmap copy */ |
936 | /* strightforward pixmap copy */ |
878 | gcv.tile = root_pixmap; |
937 | gcv.tile = root_pixmap; |
879 | gcv.fill_style = FillTiled; |
938 | gcv.fill_style = FillTiled; |
880 | |
939 | |
881 | while (sx < 0) sx += (int)root_width; |
940 | while (sx < 0) sx += (int)root_width; |
882 | while (sy < 0) sy += (int)root_height; |
941 | while (sy < 0) sy += (int)root_height; |
… | |
… | |
930 | { |
989 | { |
931 | c.r = (c.r * shade) / 100; |
990 | c.r = (c.r * shade) / 100; |
932 | c.g = (c.g * shade) / 100; |
991 | c.g = (c.g * shade) / 100; |
933 | c.b = (c.b * shade) / 100; |
992 | c.b = (c.b * shade) / 100; |
934 | } |
993 | } |
935 | else if( shade > 100 && shade < 200) |
994 | else if (shade > 100 && shade < 200) |
936 | { |
995 | { |
937 | c.r = (c.r * (200 - shade)) / 100; |
996 | c.r = (c.r * (200 - shade)) / 100; |
938 | c.g = (c.g * (200 - shade)) / 100; |
997 | c.g = (c.g * (200 - shade)) / 100; |
939 | c.b = (c.b * (200 - shade)) / 100; |
998 | c.b = (c.b * (200 - shade)) / 100; |
940 | } |
999 | } |
… | |
… | |
986 | mask_c.blue = 0xffff - c.b; |
1045 | mask_c.blue = 0xffff - c.b; |
987 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1046 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
988 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
1047 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
989 | result |= transpPmapTinted; |
1048 | result |= transpPmapTinted; |
990 | } |
1049 | } |
|
|
1050 | |
991 | XRenderFreePicture (dpy, mask_pic); |
1051 | XRenderFreePicture (dpy, mask_pic); |
992 | XRenderFreePicture (dpy, overlay_pic); |
1052 | XRenderFreePicture (dpy, overlay_pic); |
993 | XRenderFreePicture (dpy, back_pic); |
1053 | XRenderFreePicture (dpy, back_pic); |
994 | # if DO_TIMING_TEST |
1054 | # if DO_TIMING_TEST |
995 | XSync (dpy, False); |
1055 | XSync (dpy, False); |
… | |
… | |
1017 | } |
1077 | } |
1018 | |
1078 | |
1019 | bool |
1079 | bool |
1020 | bgPixmap_t::set_root_pixmap () |
1080 | bgPixmap_t::set_root_pixmap () |
1021 | { |
1081 | { |
1022 | Pixmap new_root_pixmap = None; |
|
|
1023 | |
|
|
1024 | new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1082 | Pixmap new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1025 | if (new_root_pixmap == None) |
1083 | if (new_root_pixmap == None) |
1026 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1084 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1027 | |
1085 | |
1028 | if (new_root_pixmap != root_pixmap) |
1086 | if (new_root_pixmap != root_pixmap) |
1029 | { |
1087 | { |
1030 | root_pixmap = new_root_pixmap; |
1088 | root_pixmap = new_root_pixmap; |
1031 | return true; |
1089 | return true; |
1032 | } |
1090 | } |
|
|
1091 | |
1033 | return false; |
1092 | return false; |
1034 | } |
1093 | } |
1035 | # endif /* ENABLE_TRANSPARENCY */ |
1094 | # endif /* ENABLE_TRANSPARENCY */ |
1036 | |
1095 | |
1037 | # ifndef HAVE_AFTERIMAGE |
1096 | # ifndef HAVE_AFTERIMAGE |
1038 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1097 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
1039 | # endif |
1098 | # endif |
1040 | |
|
|
1041 | |
1099 | |
1042 | bool |
1100 | bool |
1043 | bgPixmap_t::render () |
1101 | bgPixmap_t::render () |
1044 | { |
1102 | { |
1045 | unsigned long background_flags = 0; |
1103 | unsigned long background_flags = 0; |
… | |
… | |
1127 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1185 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
1128 | } |
1186 | } |
1129 | } |
1187 | } |
1130 | # endif /* HAVE_AFTERIMAGE */ |
1188 | # endif /* HAVE_AFTERIMAGE */ |
1131 | |
1189 | |
1132 | if (result != NULL) |
1190 | if (result) |
1133 | { |
1191 | { |
1134 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
1192 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
|
|
1193 | |
1135 | if (gc) |
1194 | if (gc) |
1136 | { |
1195 | { |
1137 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1196 | if (/*pmap_depth != target->depth &&*/ pixmap != None) |
1138 | { |
1197 | { |
1139 | XFreePixmap (target->dpy, pixmap); |
1198 | XFreePixmap (target->dpy, pixmap); |
1140 | pixmap = None; |
1199 | pixmap = None; |
1141 | } |
1200 | } |
|
|
1201 | |
1142 | if (pixmap == None) |
1202 | if (pixmap == None) |
1143 | { |
1203 | { |
1144 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1204 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
1145 | pmap_width = result->width; |
1205 | pmap_width = result->width; |
1146 | pmap_height = result->height; |
1206 | pmap_height = result->height; |
1147 | pmap_depth = target->depth; |
1207 | pmap_depth = target->depth; |
1148 | } |
1208 | } |
|
|
1209 | |
1149 | if (pmap_depth != result->depth) |
1210 | if (pmap_depth != result->depth) |
|
|
1211 | { |
1150 | { /* Bad Match error will ensue ! stupid X !!!! */ |
1212 | /* Bad Match error will ensue ! stupid X !!!! */ |
1151 | if( result->depth == 24 && pmap_depth == 32) |
1213 | if (result->depth == 24 && pmap_depth == 32) |
1152 | result->depth = 32; |
1214 | result->depth = 32; |
1153 | else if( result->depth == 32 && pmap_depth == 24) |
1215 | else if (result->depth == 32 && pmap_depth == 24) |
1154 | result->depth = 24; |
1216 | result->depth = 24; |
1155 | else |
1217 | else |
1156 | { |
1218 | { |
1157 | /* TODO: implement image recoding */ |
1219 | /* TODO: implement image recoding */ |
1158 | } |
1220 | } |
1159 | } |
1221 | } |
|
|
1222 | |
1160 | if (pmap_depth == result->depth) |
1223 | if (pmap_depth == result->depth) |
1161 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
1224 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
1225 | |
1162 | XFreeGC (target->dpy, gc); |
1226 | XFreeGC (target->dpy, gc); |
1163 | flags = flags & ~isInvalid; |
1227 | flags = flags & ~isInvalid; |
1164 | } |
1228 | } |
|
|
1229 | |
1165 | XDestroyImage (result); |
1230 | XDestroyImage (result); |
1166 | } |
1231 | } |
1167 | |
1232 | |
1168 | if (flags & isInvalid) |
1233 | if (flags & isInvalid) |
1169 | { |
1234 | { |
… | |
… | |
1173 | pixmap = None; |
1238 | pixmap = None; |
1174 | } |
1239 | } |
1175 | } |
1240 | } |
1176 | |
1241 | |
1177 | apply (); |
1242 | apply (); |
|
|
1243 | |
|
|
1244 | XSync (target->dpy, False); |
|
|
1245 | valid_since = ev::now (); |
1178 | |
1246 | |
1179 | TIMING_TEST_PRINT_RESULT (tp); |
1247 | TIMING_TEST_PRINT_RESULT (tp); |
1180 | |
1248 | |
1181 | return true; |
1249 | return true; |
1182 | } |
1250 | } |
… | |
… | |
1195 | } |
1263 | } |
1196 | return false; |
1264 | return false; |
1197 | } |
1265 | } |
1198 | |
1266 | |
1199 | void |
1267 | void |
1200 | bgPixmap_t::apply() |
1268 | bgPixmap_t::apply () |
1201 | { |
1269 | { |
1202 | if (target) |
1270 | if (target) |
1203 | { |
1271 | { |
1204 | flags &= ~isVtOrigin; |
1272 | flags &= ~isVtOrigin; |
1205 | if (pixmap != None) |
1273 | if (pixmap != None) |
|
|
1274 | { |
1206 | { /* set target's background to pixmap */ |
1275 | /* set target's background to pixmap */ |
1207 | # ifdef ENABLE_TRANSPARENCY |
1276 | # ifdef ENABLE_TRANSPARENCY |
1208 | if (flags & isTransparent) |
1277 | if (flags & isTransparent) |
1209 | { |
1278 | { |
1210 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1279 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1211 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1280 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
… | |
… | |
1227 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1296 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1228 | # endif |
1297 | # endif |
1229 | } |
1298 | } |
1230 | } |
1299 | } |
1231 | else |
1300 | else |
|
|
1301 | { |
1232 | { /* set target background to a pixel */ |
1302 | /* set target background to a pixel */ |
1233 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1303 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1234 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1304 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1235 | /* do we also need to set scrollbar's background here ? */ |
1305 | /* do we also need to set scrollbar's background here ? */ |
1236 | # if HAVE_SCROLLBARS |
1306 | # if HAVE_SCROLLBARS |
1237 | if (target->scrollBar.win) |
1307 | if (target->scrollBar.win) |