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) \ |
38 | do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ |
36 | do{ struct timeval tv;gettimeofday (&tv, NULL); tv.tv_sec -= (timing_test_##id##_stv).tv_sec;\ |
39 | fprintf (stderr, "%s: %s: %d: elapsed %ld usec\n", #id, __FILE__, __LINE__,\ |
37 | 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) |
38 | tv.tv_sec * 1000000 + tv.tv_usec - (timing_test_##id##_stv).tv_usec);}while (0) |
41 | |
39 | |
… | |
… | |
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 |
… | |
… | |
100 | #endif |
98 | #endif |
101 | flags = 0; |
99 | flags = 0; |
102 | pixmap = None; |
100 | pixmap = None; |
103 | } |
101 | } |
104 | |
102 | |
|
|
103 | void |
|
|
104 | bgPixmap_t::destroy () |
|
|
105 | { |
|
|
106 | #ifdef HAVE_AFTERIMAGE |
|
|
107 | if (original_asim) |
|
|
108 | safe_asimage_destroy (original_asim); |
|
|
109 | #endif |
|
|
110 | |
|
|
111 | if (pixmap && target) |
|
|
112 | XFreePixmap (target->dpy, pixmap); |
|
|
113 | } |
105 | |
114 | |
106 | bool |
115 | bool |
107 | bgPixmap_t::window_size_sensitive () |
116 | bgPixmap_t::window_size_sensitive () |
108 | { |
117 | { |
|
|
118 | # ifdef ENABLE_TRANSPARENCY |
|
|
119 | if (flags & isTransparent) |
|
|
120 | return true; |
|
|
121 | # endif |
|
|
122 | |
109 | # ifdef BG_IMAGE_FROM_FILE |
123 | # ifdef BG_IMAGE_FROM_FILE |
110 | # ifdef HAVE_AFTERIMAGE |
124 | # ifdef HAVE_AFTERIMAGE |
111 | if (original_asim != NULL) |
125 | if (original_asim != NULL) |
112 | # endif |
126 | # endif |
113 | { |
127 | { |
114 | if (h_scale != 0 || v_scale != 0 |
128 | if (h_scale != 0 || v_scale != 0 |
115 | || h_align != 0 || v_align != 0) |
129 | || h_align != 0 || v_align != 0) |
116 | return true; |
130 | return true; |
117 | } |
131 | } |
118 | # endif |
132 | # endif |
|
|
133 | |
|
|
134 | return false; |
|
|
135 | } |
|
|
136 | |
|
|
137 | bool |
|
|
138 | bgPixmap_t::window_position_sensitive () |
|
|
139 | { |
119 | # ifdef ENABLE_TRANSPARENCY |
140 | # ifdef ENABLE_TRANSPARENCY |
120 | if (flags & isTransparent) |
141 | if (flags & isTransparent) |
121 | return true; |
142 | return true; |
122 | # endif |
143 | # endif |
|
|
144 | |
|
|
145 | # ifdef BG_IMAGE_FROM_FILE |
|
|
146 | # ifdef HAVE_AFTERIMAGE |
|
|
147 | if (original_asim != NULL) |
|
|
148 | # endif |
|
|
149 | { |
|
|
150 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
151 | return true; |
|
|
152 | } |
|
|
153 | # endif |
|
|
154 | |
123 | return false; |
155 | return false; |
124 | } |
156 | }; |
125 | |
157 | |
126 | bool bgPixmap_t::need_client_side_rendering () |
158 | bool bgPixmap_t::need_client_side_rendering () |
127 | { |
159 | { |
128 | # ifdef HAVE_AFTERIMAGE |
160 | # ifdef HAVE_AFTERIMAGE |
129 | if (original_asim != NULL) |
161 | if (original_asim != NULL) |
… | |
… | |
163 | static inline bool |
195 | static inline bool |
164 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
196 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
165 | { |
197 | { |
166 | if (geom_flags & flag) |
198 | if (geom_flags & flag) |
167 | { |
199 | { |
|
|
200 | if (new_value != bgPixmap_t::rootAlign) |
|
|
201 | { |
168 | if (new_value < -100) |
202 | if (new_value < -100) |
169 | new_value = -100; |
203 | new_value = -100; |
170 | else if (new_value > 200) |
204 | else if (new_value > 200) |
171 | new_value = 200; |
205 | new_value = 200; |
|
|
206 | } |
172 | if (new_value != align) |
207 | if (new_value != align) |
173 | { |
208 | { |
174 | align = new_value; |
209 | align = new_value; |
175 | return true; |
210 | return true; |
176 | } |
211 | } |
… | |
… | |
268 | y = x; |
303 | y = x; |
269 | geom_flags |= YValue; |
304 | geom_flags |= YValue; |
270 | } |
305 | } |
271 | |
306 | |
272 | if (flags & geometrySet) |
307 | if (flags & geometrySet) |
|
|
308 | { |
273 | {/* new geometry is an adjustment to the old one ! */ |
309 | /* new geometry is an adjustment to the old one ! */ |
274 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
310 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
275 | { |
311 | { |
276 | if (w == 0 && h != 0) |
312 | if (w == 0 && h != 0) |
277 | { |
313 | { |
278 | w = h_scale; |
314 | w = h_scale; |
… | |
… | |
294 | } |
330 | } |
295 | } |
331 | } |
296 | else /* setting up geometry from scratch */ |
332 | else /* setting up geometry from scratch */ |
297 | { |
333 | { |
298 | if (!(geom_flags & XValue)) |
334 | if (!(geom_flags & XValue)) |
|
|
335 | { |
299 | {/* use default geometry - centered */ |
336 | /* use default geometry - centered */ |
300 | x = y = defaultAlign; |
337 | x = y = defaultAlign; |
301 | } |
338 | } |
302 | else if (!(geom_flags & YValue)) |
339 | else if (!(geom_flags & YValue)) |
303 | y = x; |
340 | y = x; |
304 | |
341 | |
305 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
342 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
|
|
343 | { |
306 | {/* use default geometry - scaled */ |
344 | /* use default geometry - scaled */ |
307 | w = h = defaultScale; |
345 | w = h = defaultScale; |
308 | } |
346 | } |
309 | else if (geom_flags & WidthValue) |
347 | else if (geom_flags & WidthValue) |
310 | { |
348 | { |
311 | if (!(geom_flags & HeightValue)) |
349 | if (!(geom_flags & HeightValue)) |
… | |
… | |
314 | else |
352 | else |
315 | w = h; |
353 | w = h; |
316 | } |
354 | } |
317 | } /* done parsing geometry string */ |
355 | } /* done parsing geometry string */ |
318 | else if (!(flags & geometrySet)) |
356 | else if (!(flags & geometrySet)) |
|
|
357 | { |
319 | { /* default geometry - scaled and centered */ |
358 | /* default geometry - scaled and centered */ |
320 | x = y = defaultAlign; |
359 | x = y = defaultAlign; |
321 | w = h = defaultScale; |
360 | w = h = defaultScale; |
322 | } |
361 | } |
323 | |
362 | |
324 | if (!(flags & geometrySet)) |
363 | if (!(flags & geometrySet)) |
325 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
364 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
326 | |
365 | |
327 | if (ops) |
366 | if (ops) |
328 | { |
367 | { |
… | |
… | |
330 | { |
369 | { |
331 | while (*ops == ':' || isspace(*ops)) ++ops; |
370 | while (*ops == ':' || isspace(*ops)) ++ops; |
332 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
371 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
333 | if (CHECK_GEOM_OPS("tile")) |
372 | if (CHECK_GEOM_OPS("tile")) |
334 | { |
373 | { |
335 | w = h = 0; |
374 | w = h = noScale; |
336 | geom_flags |= WidthValue|HeightValue; |
375 | geom_flags |= WidthValue|HeightValue; |
337 | } |
376 | } |
338 | else if (CHECK_GEOM_OPS("propscale")) |
377 | else if (CHECK_GEOM_OPS("propscale")) |
339 | { |
378 | { |
340 | if (w == 0 && h == 0) |
379 | if (w == 0 && h == 0) |
341 | { |
380 | { |
342 | w = 100; |
381 | w = windowScale; |
343 | geom_flags |= WidthValue; |
382 | geom_flags |= WidthValue; |
344 | } |
383 | } |
345 | new_flags |= propScale; |
384 | new_flags |= propScale; |
346 | } |
385 | } |
347 | else if (CHECK_GEOM_OPS("hscale")) |
386 | else if (CHECK_GEOM_OPS("hscale")) |
348 | { |
387 | { |
349 | if (w == 0) |
388 | if (w == 0) |
350 | w = 100; |
389 | w = windowScale; |
351 | h = 0; |
390 | h = noScale; |
352 | geom_flags |= WidthValue|HeightValue; |
391 | geom_flags |= WidthValue|HeightValue; |
353 | } |
392 | } |
354 | else if (CHECK_GEOM_OPS("vscale")) |
393 | else if (CHECK_GEOM_OPS("vscale")) |
355 | { |
394 | { |
356 | if (h == 0) |
395 | if (h == 0) |
357 | h = 100; |
396 | h = windowScale; |
358 | w = 0; |
397 | w = noScale; |
359 | geom_flags |= WidthValue|HeightValue; |
398 | geom_flags |= WidthValue|HeightValue; |
360 | } |
399 | } |
361 | else if (CHECK_GEOM_OPS("scale")) |
400 | else if (CHECK_GEOM_OPS("scale")) |
362 | { |
401 | { |
363 | if (h == 0) |
402 | if (h == 0) |
364 | h = 100; |
403 | h = windowScale; |
365 | if (w == 0) |
404 | if (w == 0) |
366 | w = 100; |
405 | w = windowScale; |
367 | geom_flags |= WidthValue|HeightValue; |
406 | geom_flags |= WidthValue|HeightValue; |
368 | } |
407 | } |
369 | else if (CHECK_GEOM_OPS("auto")) |
408 | else if (CHECK_GEOM_OPS("auto")) |
370 | { |
409 | { |
|
|
410 | w = h = windowScale; |
|
|
411 | x = y = centerAlign; |
|
|
412 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
413 | } |
|
|
414 | else if (CHECK_GEOM_OPS("root")) |
|
|
415 | { |
371 | w = h = 100; |
416 | w = h = noScale; |
372 | x = y = 50; |
417 | x = y = rootAlign; |
373 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
418 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
374 | } |
419 | } |
375 | # undef CHECK_GEOM_OPS |
420 | # undef CHECK_GEOM_OPS |
376 | while (*ops != ':' && *ops != '\0') ++ops; |
421 | while (*ops != ':' && *ops != '\0') ++ops; |
377 | } /* done parsing ops */ |
422 | } /* done parsing ops */ |
… | |
… | |
390 | if (new_flags != flags) |
435 | if (new_flags != flags) |
391 | { |
436 | { |
392 | flags = new_flags; |
437 | flags = new_flags; |
393 | changed++; |
438 | changed++; |
394 | } |
439 | } |
395 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
440 | //fprintf (stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
396 | // flags, h_scale, v_scale, h_align, v_align); |
441 | // flags, h_scale, v_scale, h_align, v_align); |
397 | return (changed > 0); |
442 | return (changed > 0); |
398 | } |
443 | } |
399 | |
444 | |
400 | # ifdef HAVE_AFTERIMAGE |
445 | # ifdef HAVE_AFTERIMAGE |
… | |
… | |
416 | |
461 | |
417 | TIMING_TEST_START (asim); |
462 | TIMING_TEST_START (asim); |
418 | |
463 | |
419 | if (original_asim) |
464 | if (original_asim) |
420 | { |
465 | { |
|
|
466 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
467 | { |
|
|
468 | target->get_window_origin(x, y); |
|
|
469 | x = -x; |
|
|
470 | y = -y; |
|
|
471 | } |
|
|
472 | if (h_align != rootAlign) |
421 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
473 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
474 | if (v_align != rootAlign) |
422 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
475 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
423 | } |
476 | } |
424 | |
477 | |
425 | if (original_asim == NULL |
478 | if (original_asim == NULL |
426 | || x >= target_width |
479 | || x >= target_width |
427 | || y >= target_height |
480 | || y >= target_height |
… | |
… | |
449 | { |
502 | { |
450 | result = original_asim; |
503 | result = original_asim; |
451 | if ((w > 0 && w != original_asim->width) |
504 | if ((w > 0 && w != original_asim->width) |
452 | || (h > 0 && h != original_asim->height)) |
505 | || (h > 0 && h != original_asim->height)) |
453 | { |
506 | { |
454 | result = scale_asimage (target->asv, original_asim, |
507 | result = scale_asimage (target->asv, original_asim, |
455 | w > 0 ? w : original_asim->width, |
508 | w > 0 ? w : original_asim->width, |
456 | h > 0 ? h : original_asim->height, |
509 | h > 0 ? h : original_asim->height, |
457 | background ? ASA_ASImage : ASA_XImage, |
510 | background ? ASA_ASImage : ASA_XImage, |
458 | 100, ASIMAGE_QUALITY_DEFAULT); |
511 | 100, ASIMAGE_QUALITY_DEFAULT); |
459 | } |
512 | } |
460 | if (background == NULL) |
513 | if (background == NULL) |
|
|
514 | { |
461 | {/* if tiling - pixmap has to be sized exactly as the image */ |
515 | /* if tiling - pixmap has to be sized exactly as the image, |
|
|
516 | but there is no need to make it bigger then the window! */ |
462 | if (h_scale == 0) |
517 | if (h_scale == 0) |
463 | new_pmap_width = result->width; |
518 | new_pmap_width = min (result->width, target_width); |
464 | if (v_scale == 0) |
519 | if (v_scale == 0) |
465 | new_pmap_height = result->height; |
520 | new_pmap_height = min (result->height, target_height); |
466 | /* we also need to tile our image in one or both directions */ |
521 | /* we also need to tile our image in one or both directions */ |
467 | if (h_scale == 0 || v_scale == 0) |
522 | if (h_scale == 0 || v_scale == 0) |
468 | { |
523 | { |
469 | ASImage *tmp = tile_asimage (target->asv, result, |
524 | ASImage *tmp = tile_asimage (target->asv, result, |
470 | (h_scale > 0) ? 0 : (int)result->width - x, |
525 | (h_scale > 0) ? 0 : (int)result->width - x, |
471 | (v_scale > 0) ? 0 : (int)result->height - y, |
526 | (v_scale > 0) ? 0 : (int)result->height - y, |
|
|
527 | new_pmap_width, |
472 | result->width, result->height, |
528 | new_pmap_height, |
473 | TINT_LEAVE_SAME, ASA_XImage, |
529 | TINT_LEAVE_SAME, ASA_XImage, |
474 | 100, ASIMAGE_QUALITY_DEFAULT); |
530 | 100, ASIMAGE_QUALITY_DEFAULT); |
475 | if (tmp) |
531 | if (tmp) |
476 | { |
532 | { |
477 | if (result != original_asim) |
533 | if (result != original_asim) |
… | |
… | |
479 | result = tmp; |
535 | result = tmp; |
480 | } |
536 | } |
481 | } |
537 | } |
482 | } |
538 | } |
483 | else |
539 | else |
|
|
540 | { |
484 | {/* if blending background and image - pixmap has to be sized same as target window */ |
541 | /* if blending background and image - pixmap has to be sized same as target window */ |
485 | ASImageLayer *layers = create_image_layers (2); |
542 | ASImageLayer *layers = create_image_layers (2); |
486 | ASImage *merged_im = NULL; |
543 | ASImage *merged_im = NULL; |
487 | |
544 | |
488 | layers[0].im = background; |
545 | layers[0].im = background; |
489 | layers[0].clip_width = target_width; |
546 | layers[0].clip_width = target_width; |
490 | layers[0].clip_height = target_height; |
547 | layers[0].clip_height = target_height; |
491 | layers[0].tint = background_tint; |
548 | layers[0].tint = background_tint; |
492 | layers[1].im = result; |
549 | layers[1].im = result; |
493 | if (w <= 0) |
550 | if (w <= 0) |
|
|
551 | { |
494 | {/* tile horizontally */ |
552 | /* tile horizontally */ |
495 | while (x > 0) x -= (int)result->width; |
553 | while (x > 0) x -= (int)result->width; |
496 | layers[1].dst_x = x; |
554 | layers[1].dst_x = x; |
497 | layers[1].clip_width = result->width+target_width; |
555 | layers[1].clip_width = result->width+target_width; |
498 | } |
556 | } |
499 | else |
557 | else |
|
|
558 | { |
500 | {/* clip horizontally */ |
559 | /* clip horizontally */ |
501 | layers[1].dst_x = x; |
560 | layers[1].dst_x = x; |
502 | layers[1].clip_width = result->width; |
561 | layers[1].clip_width = result->width; |
503 | } |
562 | } |
504 | if (h <= 0) |
563 | if (h <= 0) |
505 | { |
564 | { |
… | |
… | |
578 | } |
637 | } |
579 | |
638 | |
580 | /* put result on pixmap */ |
639 | /* put result on pixmap */ |
581 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
640 | 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); |
641 | asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
583 | |
642 | |
584 | if (result != background && result != original_asim) |
643 | if (result != background && result != original_asim) |
585 | destroy_asimage (&result); |
644 | destroy_asimage (&result); |
586 | |
645 | |
587 | XFreeGC (target->dpy, gc); |
646 | XFreeGC (target->dpy, gc); |
588 | TIMING_TEST_PRINT_RESULT (asim); |
647 | TIMING_TEST_PRINT_RESULT (asim); |
… | |
… | |
614 | f[len] = '\0'; |
673 | f[len] = '\0'; |
615 | original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); |
674 | original_asim = get_asimage (target->asimman, f, 0xFFFFFFFF, 100); |
616 | free (f); |
675 | free (f); |
617 | } |
676 | } |
618 | return (original_asim != NULL); |
677 | return (original_asim != NULL); |
619 | # endif |
678 | # endif |
620 | } |
679 | } |
621 | return false; |
680 | return false; |
622 | } |
681 | } |
623 | |
682 | |
624 | # endif /* BG_IMAGE_FROM_FILE */ |
683 | # endif /* BG_IMAGE_FROM_FILE */ |
625 | |
684 | |
626 | # ifdef ENABLE_TRANSPARENCY |
685 | # ifdef ENABLE_TRANSPARENCY |
627 | bool |
686 | bool |
628 | bgPixmap_t::set_transparent () |
687 | bgPixmap_t::set_transparent () |
629 | { |
688 | { |
630 | if (!(flags & isTransparent)) |
689 | if (!(flags & isTransparent)) |
631 | { |
690 | { |
632 | flags |= isTransparent; |
691 | flags |= isTransparent; |
… | |
… | |
657 | if (v_blurRadius != vr) |
716 | if (v_blurRadius != vr) |
658 | { |
717 | { |
659 | ++changed; |
718 | ++changed; |
660 | v_blurRadius = vr; |
719 | v_blurRadius = vr; |
661 | } |
720 | } |
662 | |
721 | |
663 | if (v_blurRadius == 0 && h_blurRadius == 0) |
722 | if (v_blurRadius == 0 && h_blurRadius == 0) |
664 | flags &= ~blurNeeded; |
723 | flags &= ~blurNeeded; |
665 | else |
724 | else |
666 | flags |= blurNeeded; |
725 | flags |= blurNeeded; |
667 | |
726 | |
… | |
… | |
694 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
753 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
695 | { |
754 | { |
696 | flags |= bgPixmap_t::tintNeeded; |
755 | flags |= bgPixmap_t::tintNeeded; |
697 | } |
756 | } |
698 | } |
757 | } |
699 | |
758 | |
700 | if (flags & bgPixmap_t::tintNeeded) |
759 | if (flags & bgPixmap_t::tintNeeded) |
701 | { |
760 | { |
702 | if (flags & bgPixmap_t::tintWholesome) |
761 | if (flags & bgPixmap_t::tintWholesome) |
703 | flags |= bgPixmap_t::tintServerSide; |
762 | flags |= bgPixmap_t::tintServerSide; |
704 | else |
763 | else |
… | |
… | |
741 | bool |
800 | bool |
742 | bgPixmap_t::set_shade (const char *shade_str) |
801 | bgPixmap_t::set_shade (const char *shade_str) |
743 | { |
802 | { |
744 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
803 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
745 | |
804 | |
|
|
805 | if (new_shade < 0 && new_shade > -100) |
|
|
806 | new_shade = 200 - (100 + new_shade); |
746 | if (new_shade == 100) |
807 | else if (new_shade == 100) |
747 | new_shade = 0; |
808 | new_shade = 0; |
748 | |
809 | |
749 | if (new_shade != shade) |
810 | if (new_shade != shade) |
750 | { |
811 | { |
751 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
812 | unsigned long new_flags = compute_tint_shade_flags ((flags & tintSet) ? &tint : NULL, new_shade); |
… | |
… | |
754 | return true; |
815 | return true; |
755 | } |
816 | } |
756 | return false; |
817 | return false; |
757 | } |
818 | } |
758 | |
819 | |
759 | /* make_transparency_pixmap() |
820 | /* make_transparency_pixmap() |
760 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
821 | * 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 |
822 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
762 | * our window. |
823 | * our window. |
763 | */ |
824 | */ |
764 | unsigned long |
825 | unsigned long |
765 | bgPixmap_t::make_transparency_pixmap () |
826 | bgPixmap_t::make_transparency_pixmap () |
766 | { |
827 | { |
… | |
… | |
790 | if (sx + window_width <= 0 || sy + window_height <= 0 |
851 | if (sx + window_width <= 0 || sy + window_height <= 0 |
791 | || sx >= root_width || sy >= root_height) |
852 | || sx >= root_width || sy >= root_height) |
792 | return 0; |
853 | return 0; |
793 | |
854 | |
794 | if (root_pixmap != None) |
855 | if (root_pixmap != None) |
|
|
856 | { |
795 | {/* we want to validate the pixmap and get it's size at the same time : */ |
857 | /* we want to validate the pixmap and get it's size at the same time : */ |
796 | int junk; |
858 | int junk; |
797 | unsigned int ujunk; |
859 | unsigned int ujunk; |
798 | /* root pixmap may be bad - allow a error */ |
860 | /* root pixmap may be bad - allow a error */ |
799 | target->allowedxerror = -1; |
861 | target->allowedxerror = -1; |
800 | |
862 | |
… | |
… | |
809 | |
871 | |
810 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
872 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
811 | return 0; |
873 | return 0; |
812 | |
874 | |
813 | if (root_pixmap == None) |
875 | if (root_pixmap == None) |
|
|
876 | { |
814 | { /* use tricks to obtain the root background image :*/ |
877 | /* use tricks to obtain the root background image :*/ |
815 | /* we want to create Overrideredirect window overlapping out window |
878 | /* we want to create Overrideredirect window overlapping out window |
816 | with background type of Parent Relative and then grab it */ |
879 | with background type of Parent Relative and then grab it */ |
817 | XSetWindowAttributes attr; |
880 | XSetWindowAttributes attr; |
818 | Window src; |
881 | Window src; |
819 | bool success = false; |
882 | bool success = false; |
… | |
… | |
839 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
902 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
840 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
903 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
841 | ++ev_count; |
904 | ++ev_count; |
842 | |
905 | |
843 | if (ev_count > 0); |
906 | if (ev_count > 0); |
|
|
907 | { |
844 | { /* hooray! - we can grab the image! */ |
908 | /* hooray! - we can grab the image! */ |
845 | gc = XCreateGC (dpy, root, 0, NULL); |
909 | gc = XCreateGC (dpy, root, 0, NULL); |
846 | if (gc) |
910 | if (gc) |
847 | { |
911 | { |
848 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
912 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
849 | success = true; |
913 | success = true; |
… | |
… | |
861 | } |
925 | } |
862 | else |
926 | else |
863 | result |= transpPmapTiled; |
927 | result |= transpPmapTiled; |
864 | } |
928 | } |
865 | else |
929 | else |
|
|
930 | { |
866 | {/* strightforward pixmap copy */ |
931 | /* strightforward pixmap copy */ |
867 | gcv.tile = root_pixmap; |
932 | gcv.tile = root_pixmap; |
868 | gcv.fill_style = FillTiled; |
933 | gcv.fill_style = FillTiled; |
869 | |
934 | |
870 | while (sx < 0) sx += (int)root_width; |
935 | while (sx < 0) sx += (int)root_width; |
871 | while (sy < 0) sy += (int)root_height; |
936 | while (sy < 0) sy += (int)root_height; |
… | |
… | |
882 | } |
947 | } |
883 | TIMING_TEST_PRINT_RESULT (tp); |
948 | TIMING_TEST_PRINT_RESULT (tp); |
884 | |
949 | |
885 | if (tiled_root_pmap != None) |
950 | if (tiled_root_pmap != None) |
886 | { |
951 | { |
887 | if (!need_client_side_rendering ()) |
952 | if (!need_client_side_rendering ()) |
888 | { |
953 | { |
889 | if ((flags & tintNeeded)) |
954 | if ((flags & tintNeeded)) |
890 | { |
955 | { |
891 | if (flags & tintWholesome) |
956 | if (flags & tintWholesome) |
892 | { |
957 | { |
893 | /* In this case we can tint image server-side getting significant |
958 | /* In this case we can tint image server-side getting significant |
894 | * performance improvements, as we eliminate XImage transfer |
959 | * performance improvements, as we eliminate XImage transfer |
… | |
… | |
919 | { |
984 | { |
920 | c.r = (c.r * shade) / 100; |
985 | c.r = (c.r * shade) / 100; |
921 | c.g = (c.g * shade) / 100; |
986 | c.g = (c.g * shade) / 100; |
922 | c.b = (c.b * shade) / 100; |
987 | c.b = (c.b * shade) / 100; |
923 | } |
988 | } |
924 | else if( shade > 100 && shade < 200) |
989 | else if (shade > 100 && shade < 200) |
925 | { |
990 | { |
926 | c.r = (c.r * (200 - shade)) / 100; |
991 | c.r = (c.r * (200 - shade)) / 100; |
927 | c.g = (c.g * (200 - shade)) / 100; |
992 | c.g = (c.g * (200 - shade)) / 100; |
928 | c.b = (c.b * (200 - shade)) / 100; |
993 | c.b = (c.b * (200 - shade)) / 100; |
929 | } |
994 | } |
… | |
… | |
954 | |
1019 | |
955 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
1020 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
956 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1021 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
957 | XFreePixmap (dpy, overlay_pmap); |
1022 | XFreePixmap (dpy, overlay_pmap); |
958 | |
1023 | |
959 | pa.component_alpha = True; |
1024 | pa.component_alpha = True; |
960 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
1025 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
961 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
1026 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
962 | XFreePixmap (dpy, mask_pmap); |
1027 | XFreePixmap (dpy, mask_pmap); |
963 | |
1028 | |
964 | if (mask_pic && overlay_pic && back_pic) |
1029 | if (mask_pic && overlay_pic && back_pic) |
… | |
… | |
980 | XRenderFreePicture (dpy, mask_pic); |
1045 | XRenderFreePicture (dpy, mask_pic); |
981 | XRenderFreePicture (dpy, overlay_pic); |
1046 | XRenderFreePicture (dpy, overlay_pic); |
982 | XRenderFreePicture (dpy, back_pic); |
1047 | XRenderFreePicture (dpy, back_pic); |
983 | # if DO_TIMING_TEST |
1048 | # if DO_TIMING_TEST |
984 | XSync (dpy, False); |
1049 | XSync (dpy, False); |
985 | # endif |
1050 | # endif |
986 | # endif |
1051 | # endif |
987 | } |
1052 | } |
988 | } |
1053 | } |
989 | } /* server side rendering completed */ |
1054 | } /* server side rendering completed */ |
990 | |
1055 | |
… | |
… | |
994 | pixmap = tiled_root_pmap; |
1059 | pixmap = tiled_root_pmap; |
995 | pmap_width = window_width; |
1060 | pmap_width = window_width; |
996 | pmap_height = window_height; |
1061 | pmap_height = window_height; |
997 | pmap_depth = root_depth; |
1062 | pmap_depth = root_depth; |
998 | } |
1063 | } |
999 | |
1064 | |
1000 | if (gc) |
1065 | if (gc) |
1001 | XFreeGC (dpy, gc); |
1066 | XFreeGC (dpy, gc); |
1002 | |
1067 | |
1003 | TIMING_TEST_PRINT_RESULT (tp); |
1068 | TIMING_TEST_PRINT_RESULT (tp); |
1004 | |
1069 | |
1005 | return result; |
1070 | return result; |
1006 | } |
1071 | } |
1007 | |
1072 | |
1008 | bool |
1073 | bool |
1009 | bgPixmap_t::set_root_pixmap () |
1074 | bgPixmap_t::set_root_pixmap () |
1010 | { |
1075 | { |
1011 | Pixmap new_root_pixmap = None; |
1076 | Pixmap new_root_pixmap = None; |
1012 | |
1077 | |
1013 | new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1078 | new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
1014 | if (new_root_pixmap == None) |
1079 | if (new_root_pixmap == None) |
1015 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1080 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
1016 | |
1081 | |
1017 | if (new_root_pixmap != root_pixmap) |
1082 | if (new_root_pixmap != root_pixmap) |
… | |
… | |
1134 | pmap_width = result->width; |
1199 | pmap_width = result->width; |
1135 | pmap_height = result->height; |
1200 | pmap_height = result->height; |
1136 | pmap_depth = target->depth; |
1201 | pmap_depth = target->depth; |
1137 | } |
1202 | } |
1138 | if (pmap_depth != result->depth) |
1203 | if (pmap_depth != result->depth) |
|
|
1204 | { |
1139 | { /* Bad Match error will ensue ! stupid X !!!! */ |
1205 | /* Bad Match error will ensue ! stupid X !!!! */ |
1140 | if( result->depth == 24 && pmap_depth == 32) |
1206 | if (result->depth == 24 && pmap_depth == 32) |
1141 | result->depth = 32; |
1207 | result->depth = 32; |
1142 | else if( result->depth == 32 && pmap_depth == 24) |
1208 | else if (result->depth == 32 && pmap_depth == 24) |
1143 | result->depth = 24; |
1209 | result->depth = 24; |
1144 | else |
1210 | else |
1145 | { |
1211 | { |
1146 | /* TODO: implement image recoding */ |
1212 | /* TODO: implement image recoding */ |
1147 | } |
1213 | } |
… | |
… | |
1165 | |
1231 | |
1166 | apply (); |
1232 | apply (); |
1167 | |
1233 | |
1168 | TIMING_TEST_PRINT_RESULT (tp); |
1234 | TIMING_TEST_PRINT_RESULT (tp); |
1169 | |
1235 | |
1170 | return true; |
1236 | return true; |
1171 | } |
1237 | } |
1172 | |
1238 | |
1173 | bool |
1239 | bool |
1174 | bgPixmap_t::set_target (rxvt_term *new_target) |
1240 | bgPixmap_t::set_target (rxvt_term *new_target) |
1175 | { |
1241 | { |
1176 | if (new_target) |
1242 | if (new_target) |
1177 | if (target != new_target) |
1243 | if (target != new_target) |
1178 | { |
1244 | { |
… | |
… | |
1190 | { |
1256 | { |
1191 | if (target) |
1257 | if (target) |
1192 | { |
1258 | { |
1193 | flags &= ~isVtOrigin; |
1259 | flags &= ~isVtOrigin; |
1194 | if (pixmap != None) |
1260 | if (pixmap != None) |
|
|
1261 | { |
1195 | { /* set target's background to pixmap */ |
1262 | /* set target's background to pixmap */ |
1196 | # ifdef ENABLE_TRANSPARENCY |
1263 | # ifdef ENABLE_TRANSPARENCY |
1197 | if (flags & isTransparent) |
1264 | if (flags & isTransparent) |
1198 | { |
1265 | { |
1199 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1266 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1200 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1267 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
… | |
… | |
1216 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1283 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1217 | # endif |
1284 | # endif |
1218 | } |
1285 | } |
1219 | } |
1286 | } |
1220 | else |
1287 | else |
|
|
1288 | { |
1221 | { /* set target background to a pixel */ |
1289 | /* set target background to a pixel */ |
1222 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1290 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1223 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1291 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1224 | /* do we also need to set scrollbar's background here ? */ |
1292 | /* do we also need to set scrollbar's background here ? */ |
1225 | # if HAVE_SCROLLBARS |
1293 | # if HAVE_SCROLLBARS |
1226 | if (target->scrollBar.win) |
1294 | if (target->scrollBar.win) |
1227 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1295 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1228 | # endif |
1296 | # endif |
1229 | } |
1297 | } |
1230 | /* don't want Expose on the parent or vt. It is better to use |
1298 | /* 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: */ |
1299 | scr_touch or we get a great deal of flicker otherwise: */ |
1232 | XClearWindow (target->dpy, target->parent[0]); |
1300 | XClearWindow (target->dpy, target->parent[0]); |
1233 | |
1301 | |
1234 | # if HAVE_SCROLLBARS |
1302 | # if HAVE_SCROLLBARS |
1235 | if (target->scrollBar.win) |
1303 | if (target->scrollBar.win) |
… | |
… | |
1242 | target->want_refresh = 1; |
1310 | target->want_refresh = 1; |
1243 | flags |= hasChanged; |
1311 | flags |= hasChanged; |
1244 | } |
1312 | } |
1245 | } |
1313 | } |
1246 | |
1314 | |
1247 | #endif /* HAVE_BG_PIXMAP */ |
1315 | #endif /* HAVE_BG_PIXMAP */ |
1248 | |
1316 | |
1249 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1317 | #if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) && !XFT |
1250 | /* taken from aterm-0.4.2 */ |
1318 | /* taken from aterm-0.4.2 */ |
1251 | |
1319 | |
1252 | typedef uint32_t RUINT32T; |
1320 | typedef uint32_t RUINT32T; |