… | |
… | |
72 | |
72 | |
73 | #ifdef HAVE_BG_PIXMAP |
73 | #ifdef HAVE_BG_PIXMAP |
74 | bool |
74 | bool |
75 | bgPixmap_t::window_size_sensitive () |
75 | bgPixmap_t::window_size_sensitive () |
76 | { |
76 | { |
77 | #ifdef XPM_BACKGROUND |
77 | # ifdef XPM_BACKGROUND |
78 | #ifdef HAVE_AFTERIMAGE |
78 | # ifdef HAVE_AFTERIMAGE |
79 | if (original_asim != NULL) |
79 | if (original_asim != NULL) |
80 | #endif |
80 | # endif |
81 | { |
81 | { |
82 | if (h_scale != 0 || v_scale != 0) |
82 | if (h_scale != 0 || v_scale != 0) |
83 | return true; |
83 | return true; |
84 | } |
84 | } |
85 | #endif |
85 | # endif |
86 | #ifdef ENABLE_TRANSPARENCY |
86 | # ifdef ENABLE_TRANSPARENCY |
87 | if (flags & bgPmap_Transparent) |
87 | if (flags & bgPmap_Transparent) |
88 | return true; |
88 | return true; |
89 | #endif |
89 | # endif |
90 | return false; |
90 | return false; |
91 | } |
91 | } |
92 | |
92 | |
93 | #ifdef XPM_BACKGROUND |
93 | # ifdef XPM_BACKGROUND |
94 | static inline bool |
94 | static inline bool |
95 | check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) |
95 | check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) |
96 | { |
96 | { |
97 | if (geom_flags & flag) |
97 | if (geom_flags & flag) |
98 | { |
98 | { |
… | |
… | |
121 | align = new_value; |
121 | align = new_value; |
122 | return true; |
122 | return true; |
123 | } |
123 | } |
124 | } |
124 | } |
125 | return false; |
125 | return false; |
|
|
126 | } |
|
|
127 | |
|
|
128 | static inline int |
|
|
129 | make_align_position (int align, int window_size, int image_size) |
|
|
130 | { |
|
|
131 | int diff = window_size - image_size; |
|
|
132 | int smaller = MIN (image_size,window_size); |
|
|
133 | |
|
|
134 | if (align >= 0 && align <= 50) |
|
|
135 | return diff * align / 100; |
|
|
136 | else if (align > 50 && align <= 100) |
|
|
137 | return window_size - image_size - diff * (100 - align) / 100; |
|
|
138 | else if (align > 100 && align <= 200 ) |
|
|
139 | return ((align - 100) * smaller / 100) + window_size - smaller; |
|
|
140 | else if (align > -100 && align < 0) |
|
|
141 | return ((align + 100) * smaller / 100) - image_size; |
|
|
142 | return 0; |
|
|
143 | } |
|
|
144 | |
|
|
145 | static inline int |
|
|
146 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
|
|
147 | { |
|
|
148 | int src_pos = 0; |
|
|
149 | dst_pos = 0; |
|
|
150 | dst_size = size; |
|
|
151 | if (pos < 0 && size > target_size) |
|
|
152 | { |
|
|
153 | src_pos = -pos; |
|
|
154 | dst_size += pos; |
|
|
155 | } |
|
|
156 | else if (pos > 0) |
|
|
157 | dst_pos = pos; |
|
|
158 | |
|
|
159 | if (dst_pos + dst_size > target_size) |
|
|
160 | dst_size = target_size - dst_pos; |
|
|
161 | return src_pos; |
126 | } |
162 | } |
127 | |
163 | |
128 | bool |
164 | bool |
129 | bgPixmap_t::handle_geometry (const char *geom) |
165 | bgPixmap_t::handle_geometry (const char *geom) |
130 | { |
166 | { |
… | |
… | |
132 | int x = 0, y = 0; |
168 | int x = 0, y = 0; |
133 | unsigned int w = 0, h = 0; |
169 | unsigned int w = 0, h = 0; |
134 | unsigned int n; |
170 | unsigned int n; |
135 | unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); |
171 | unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); |
136 | char *p; |
172 | char *p; |
137 | #define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
173 | # define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
138 | |
174 | |
139 | if (geom == NULL) |
175 | if (geom == NULL) |
140 | return false; |
176 | return false; |
141 | |
177 | |
142 | char str[MAXLEN_GEOM]; |
178 | char str[MAXLEN_GEOM]; |
143 | |
179 | |
144 | if (!strcmp (geom, "?")) |
180 | if (!strcmp (geom, "?")) |
145 | { |
181 | { |
146 | #if 0 /* TODO: */ |
182 | if (target) |
|
|
183 | { |
147 | sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ |
184 | sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ |
148 | min (h_scale, 32767), min (v_scale, 32767), |
185 | min (h_scale, 32767), min (v_scale, 32767), |
149 | min (h_align, 32767), min (v_align, 32767)); |
186 | min (h_align, 32767), min (v_align, 32767)); |
150 | process_xterm_seq (XTerm_title, str, CHAR_ST); |
187 | target->process_xterm_seq (XTerm_title, str, CHAR_ST); |
151 | #endif |
188 | } |
152 | return false; |
189 | return false; |
153 | } |
190 | } |
154 | while (isspace(*geom)) ++geom; |
191 | while (isspace(*geom)) ++geom; |
155 | if ((p = strchr (geom, ';')) == NULL) |
192 | if ((p = strchr (geom, ';')) == NULL) |
156 | p = strchr (geom, '\0'); |
193 | p = strchr (geom, '\0'); |
… | |
… | |
228 | w = h = bgPmap_defaultScale; |
265 | w = h = bgPmap_defaultScale; |
229 | } |
266 | } |
230 | else if (geom_flags & WidthValue) |
267 | else if (geom_flags & WidthValue) |
231 | { |
268 | { |
232 | if (!(geom_flags & HeightValue)) |
269 | if (!(geom_flags & HeightValue)) |
233 | h = w; |
270 | h = w; |
234 | } |
271 | } |
235 | else |
272 | else |
236 | w = h; |
273 | w = h; |
237 | } |
274 | } |
238 | } /* done parsing geometry string */ |
275 | } /* done parsing geometry string */ |
239 | else if (!(flags & bgPmap_geometrySet)) |
276 | else if (!(flags & bgPmap_geometrySet)) |
240 | { /* default geometry - scaled and centered */ |
277 | { /* default geometry - scaled and centered */ |
241 | x = y = bgPmap_defaultAlign; |
278 | x = y = bgPmap_defaultAlign; |
242 | w = h = bgPmap_defaultScale; |
279 | w = h = bgPmap_defaultScale; |
243 | } |
280 | } |
244 | |
281 | |
245 | if (!(flags & bgPmap_geometrySet)) |
282 | if (!(flags & bgPmap_geometrySet)) |
246 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
283 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
247 | |
284 | |
248 | if (ops) |
285 | if (ops) |
249 | { |
286 | { |
250 | while (*ops) |
287 | while (*ops) |
251 | { |
288 | { |
252 | while (*ops == ':' || isspace(*ops)) ++ops; |
289 | while (*ops == ':' || isspace(*ops)) ++ops; |
253 | #define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
290 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
254 | if (CHECK_GEOM_OPS("tile")) |
291 | if (CHECK_GEOM_OPS("tile")) |
255 | { |
292 | { |
256 | w = h = 0; |
293 | w = h = 0; |
257 | geom_flags |= WidthValue|HeightValue; |
294 | geom_flags |= WidthValue|HeightValue; |
258 | } |
295 | } |
… | |
… | |
291 | { |
328 | { |
292 | w = h = 100; |
329 | w = h = 100; |
293 | x = y = 50; |
330 | x = y = 50; |
294 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
331 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
295 | } |
332 | } |
296 | #undef CHECK_GEOM_OPS |
333 | # undef CHECK_GEOM_OPS |
297 | while (*ops != ':' && *ops != '\0') ++ops; |
334 | while (*ops != ':' && *ops != '\0') ++ops; |
298 | } /* done parsing ops */ |
335 | } /* done parsing ops */ |
299 | } |
336 | } |
300 | |
337 | |
301 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) |
338 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) |
… | |
… | |
316 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
353 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
317 | // flags, h_scale, v_scale, h_align, v_align); |
354 | // flags, h_scale, v_scale, h_align, v_align); |
318 | return (changed > 0); |
355 | return (changed > 0); |
319 | } |
356 | } |
320 | |
357 | |
|
|
358 | # ifdef HAVE_AFTERIMAGE |
|
|
359 | bool |
|
|
360 | bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) |
|
|
361 | { |
|
|
362 | if (target == NULL) |
|
|
363 | return false; |
|
|
364 | |
|
|
365 | int target_width = (int)target->szHint.width; |
|
|
366 | int target_height = (int)target->szHint.height; |
|
|
367 | int new_pmap_width = target_width, new_pmap_height = target_height; |
|
|
368 | ASImage *result = NULL; |
|
|
369 | |
|
|
370 | int x = 0; |
|
|
371 | int y = 0; |
|
|
372 | int w = h_scale * target_width / 100; |
|
|
373 | int h = v_scale * target_height / 100; |
|
|
374 | |
|
|
375 | if (original_asim) |
|
|
376 | { |
|
|
377 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
378 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
|
|
379 | } |
|
|
380 | |
|
|
381 | if (original_asim == NULL |
|
|
382 | || x >= target_width |
|
|
383 | || y >= target_height |
|
|
384 | || (w > 0 && x + w <= 0) |
|
|
385 | || (h > 0 && y + h <= 0)) |
|
|
386 | { |
|
|
387 | if (background) |
|
|
388 | { |
|
|
389 | new_pmap_width = background->width; |
|
|
390 | new_pmap_height = background->height; |
|
|
391 | result = background; |
|
|
392 | if (background_tint != TINT_LEAVE_SAME) |
|
|
393 | { |
|
|
394 | ASImage* tmp = tile_asimage (target->asv, background, 0, 0, |
|
|
395 | target_width, target_height, background_tint, |
|
|
396 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
397 | if (tmp) |
|
|
398 | result = tmp; |
|
|
399 | } |
|
|
400 | } |
|
|
401 | else |
|
|
402 | new_pmap_width = new_pmap_height = 0; |
|
|
403 | } |
|
|
404 | else |
|
|
405 | { |
|
|
406 | result = original_asim; |
|
|
407 | if ((w > 0 && w != original_asim->width) |
|
|
408 | || (h > 0 && h != original_asim->height)) |
|
|
409 | { |
|
|
410 | result = scale_asimage (target->asv, original_asim, |
|
|
411 | w > 0 ? w : original_asim->width, |
|
|
412 | h > 0 ? h : original_asim->height, |
|
|
413 | background ? ASA_ASImage : ASA_XImage, |
|
|
414 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
415 | } |
|
|
416 | if (background == NULL) |
|
|
417 | {/* if tiling - pixmap has to be sized exactly as the image */ |
|
|
418 | if (h_scale == 0) |
|
|
419 | new_pmap_width = result->width; |
|
|
420 | if (v_scale == 0) |
|
|
421 | new_pmap_height = result->height; |
|
|
422 | /* we also need to tile our image in one or both directions */ |
|
|
423 | if (h_scale == 0 || v_scale == 0) |
|
|
424 | { |
|
|
425 | ASImage *tmp = tile_asimage (target->asv, result, |
|
|
426 | (h_scale > 0) ? 0 : (int)result->width - x, |
|
|
427 | (v_scale > 0) ? 0 : (int)result->height - y, |
|
|
428 | result->width, result->height, |
|
|
429 | TINT_LEAVE_SAME, ASA_XImage, |
|
|
430 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
431 | if (tmp) |
|
|
432 | { |
|
|
433 | if (result != original_asim) |
|
|
434 | destroy_asimage (&result); |
|
|
435 | result = tmp; |
|
|
436 | } |
|
|
437 | } |
|
|
438 | } |
|
|
439 | else |
|
|
440 | {/* if blending background and image - pixmap has to be sized same as target window */ |
|
|
441 | ASImageLayer *layers = create_image_layers (2); |
|
|
442 | ASImage *merged_im = NULL; |
|
|
443 | |
|
|
444 | layers[0].im = background; |
|
|
445 | layers[0].clip_width = target_width; |
|
|
446 | layers[0].clip_height = target_height; |
|
|
447 | layers[0].tint = background_tint; |
|
|
448 | layers[1].im = result; |
|
|
449 | if (w <= 0) |
|
|
450 | {/* tile horizontally */ |
|
|
451 | while (x > 0) x -= (int)result->width; |
|
|
452 | layers[1].dst_x = x; |
|
|
453 | layers[1].clip_width = result->width+target_width; |
|
|
454 | } |
|
|
455 | else |
|
|
456 | {/* clip horizontally */ |
|
|
457 | layers[1].dst_x = x; |
|
|
458 | layers[1].clip_width = result->width; |
|
|
459 | } |
|
|
460 | if (h <= 0) |
|
|
461 | { |
|
|
462 | while (y > 0) y -= (int)result->height; |
|
|
463 | layers[1].dst_y = y; |
|
|
464 | layers[1].clip_height = result->height + target_height; |
|
|
465 | } |
|
|
466 | else |
|
|
467 | { |
|
|
468 | layers[1].dst_y = y; |
|
|
469 | layers[1].clip_height = result->height; |
|
|
470 | } |
|
|
471 | if (target->rs[Rs_blendtype]) |
|
|
472 | { |
|
|
473 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
|
|
474 | if (layers[1].merge_scanlines == NULL) |
|
|
475 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
476 | } |
|
|
477 | ASImage *tmp = merge_layers (target->asv, layers, 2, target_width, target_height, |
|
|
478 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
479 | if (tmp) |
|
|
480 | { |
|
|
481 | if (result != original_asim) |
|
|
482 | destroy_asimage (&result); |
|
|
483 | result = tmp; |
|
|
484 | } |
|
|
485 | free (layers); |
|
|
486 | } |
|
|
487 | } |
|
|
488 | |
|
|
489 | if (pixmap) |
|
|
490 | { |
|
|
491 | if (result == NULL |
|
|
492 | || pmap_width != new_pmap_width |
|
|
493 | || pmap_height != new_pmap_height |
|
|
494 | || pmap_depth != target->depth) |
|
|
495 | { |
|
|
496 | XFreePixmap (target->dpy, pixmap); |
|
|
497 | pixmap = None; |
|
|
498 | } |
|
|
499 | } |
|
|
500 | |
|
|
501 | if (result) |
|
|
502 | { |
|
|
503 | XGCValues gcv; |
|
|
504 | GC gc; |
|
|
505 | |
|
|
506 | /* create Pixmap */ |
|
|
507 | if (pixmap == None) |
|
|
508 | { |
|
|
509 | pixmap = XCreatePixmap (target->dpy, target->vt, new_pmap_width, new_pmap_height, target->depth); |
|
|
510 | pmap_width = new_pmap_width; |
|
|
511 | pmap_height = new_pmap_height; |
|
|
512 | pmap_depth = target->depth; |
|
|
513 | } |
|
|
514 | /* fill with background color ( if result's not completely overlapping it)*/ |
|
|
515 | gcv.foreground = target->pix_colors[Color_bg]; |
|
|
516 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
|
|
517 | |
|
|
518 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
|
|
519 | int dst_width = result->width, dst_height = result->height; |
|
|
520 | if (background == NULL) |
|
|
521 | { |
|
|
522 | if (h_scale > 0) |
|
|
523 | src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); |
|
|
524 | if (v_scale > 0) |
|
|
525 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
|
|
526 | |
|
|
527 | if (dst_x > 0 || dst_y > 0 |
|
|
528 | || dst_x + dst_width < new_pmap_width |
|
|
529 | || dst_y + dst_height < new_pmap_height) |
|
|
530 | { |
|
|
531 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
|
|
532 | } |
|
|
533 | } |
|
|
534 | |
|
|
535 | /* put result on pixmap */ |
|
|
536 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
|
|
537 | asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
|
|
538 | |
|
|
539 | if (result != background && result != original_asim) |
|
|
540 | destroy_asimage (&result); |
|
|
541 | |
|
|
542 | XFreeGC (target->dpy, gc); |
|
|
543 | if (background) |
|
|
544 | flags |= bgPmap_Transparent; |
|
|
545 | else |
|
|
546 | flags &= ~bgPmap_Transparent; |
|
|
547 | } |
|
|
548 | |
|
|
549 | return true; |
|
|
550 | } |
|
|
551 | # endif /* HAVE_AFTERIMAGE */ |
|
|
552 | |
321 | void |
553 | void |
322 | rxvt_term::resize_pixmap () |
554 | rxvt_term::resize_pixmap () |
323 | { |
555 | { |
324 | XGCValues gcvalue; |
556 | |
325 | GC gc; |
|
|
326 | unsigned int w = bgPixmap.h_scale*szHint.width/100; |
|
|
327 | unsigned int h = bgPixmap.v_scale*szHint.height/100; |
|
|
328 | int x = bgPixmap.h_align*szHint.width/100; |
|
|
329 | int y = bgPixmap.v_align*szHint.height/100; |
|
|
330 | #ifdef HAVE_AFTERIMAGE |
|
|
331 | ASImage *im = bgPixmap.original_asim; |
|
|
332 | #else |
|
|
333 | void *im = NULL; |
|
|
334 | #endif |
|
|
335 | /* preliminary cleanup - this needs to be integrated with check_our_parents() code */ |
|
|
336 | if (bgPixmap.pixmap != None) |
|
|
337 | { |
|
|
338 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
339 | bgPixmap.pixmap = None ; |
|
|
340 | } |
|
|
341 | #ifdef ENABLE_TRANSPARENCY |
557 | # ifdef ENABLE_TRANSPARENCY |
342 | if (option(Opt_transparent) && am_transparent) |
558 | if (option(Opt_transparent) && am_transparent) |
343 | { |
559 | { |
344 | /* we need to re-generate transparency pixmap in that case ! */ |
560 | /* we need to re-generate transparency pixmap in that case ! */ |
345 | check_our_parents (); |
561 | check_our_parents (); |
346 | return; |
562 | return; |
347 | } |
563 | } |
348 | #endif |
564 | # endif |
349 | |
|
|
350 | if (im == NULL) |
|
|
351 | { /* So be it: I'm not using pixmaps */ |
|
|
352 | XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
|
|
353 | return; |
|
|
354 | } |
|
|
355 | |
|
|
356 | gcvalue.foreground = pix_colors[Color_bg]; |
|
|
357 | gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); |
|
|
358 | |
|
|
359 | /* don't zoom pixmap too much nor expand really small pixmaps */ |
|
|
360 | if (w > 16000) |
|
|
361 | w = 1; |
|
|
362 | if (h > 16000) |
|
|
363 | h = 1; |
|
|
364 | |
|
|
365 | #ifdef HAVE_AFTERIMAGE |
565 | # ifdef HAVE_AFTERIMAGE |
366 | if (w == 0) |
566 | bgPixmap.render_asim(NULL, TINT_LEAVE_SAME); |
367 | w = im->width; |
567 | bgPixmap.apply_background(); |
368 | if (h == 0) |
|
|
369 | h = im->height; |
|
|
370 | |
|
|
371 | if (w != im->width || h != im->height) |
|
|
372 | { |
|
|
373 | ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
374 | if (tmp != NULL) |
|
|
375 | im = tmp; |
|
|
376 | } |
|
|
377 | bgPixmap.pmap_width = MIN(w,szHint.width); |
|
|
378 | bgPixmap.pmap_height = MIN(h,szHint.height); |
|
|
379 | #if 0 /* TODO: fix that! */ |
|
|
380 | if (x != 0 || y != 0) |
|
|
381 | { |
|
|
382 | ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
383 | if (tmp != NULL) |
|
|
384 | { |
|
|
385 | if (im != bgPixmap.original_asim) |
|
|
386 | destroy_asimage (&im); |
|
|
387 | im = tmp; |
|
|
388 | } |
|
|
389 | } |
|
|
390 | #endif |
|
|
391 | bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth); |
|
|
392 | bgPixmap.pmap_depth = depth; |
|
|
393 | |
|
|
394 | asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True); |
|
|
395 | |
|
|
396 | if (im != bgPixmap.original_asim) |
|
|
397 | destroy_asimage (&im); |
|
|
398 | #endif |
568 | # endif |
399 | if( bgPixmap.pixmap ) |
|
|
400 | XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap); |
|
|
401 | |
|
|
402 | XFreeGC (dpy, gc); |
|
|
403 | } |
569 | } |
404 | |
570 | |
405 | void |
571 | void |
406 | rxvt_term::set_bgPixmap (const char *file) |
572 | rxvt_term::set_bgPixmap (const char *file) |
407 | { |
573 | { |
… | |
… | |
416 | } |
582 | } |
417 | |
583 | |
418 | XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
584 | XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
419 | if (*file != '\0') |
585 | if (*file != '\0') |
420 | { |
586 | { |
421 | #ifdef HAVE_AFTERIMAGE |
587 | # ifdef HAVE_AFTERIMAGE |
422 | if (asimman == NULL) |
588 | if (asimman == NULL) |
423 | asimman = create_generic_imageman(rs[Rs_path]); |
589 | asimman = create_generic_imageman(rs[Rs_path]); |
424 | if ((f = strchr (file, ';')) == NULL) |
590 | if ((f = strchr (file, ';')) == NULL) |
425 | bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); |
591 | bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); |
426 | else |
592 | else |
… | |
… | |
430 | strncpy (f, file, len); |
596 | strncpy (f, file, len); |
431 | f[len] = '\0'; |
597 | f[len] = '\0'; |
432 | bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); |
598 | bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); |
433 | free( f ); |
599 | free( f ); |
434 | } |
600 | } |
435 | #endif |
601 | # endif |
436 | } |
602 | } |
437 | |
603 | resize_pixmap (); /* TODO: temporary fix - should be done by the caller! */ |
438 | resize_pixmap (); |
|
|
439 | } |
604 | } |
440 | |
605 | |
441 | #endif /* XPM_BACKGROUND */ |
606 | # endif /* XPM_BACKGROUND */ |
|
|
607 | |
|
|
608 | # ifdef ENABLE_TRANSPARENCY |
|
|
609 | /* make_transparency_pixmap() |
|
|
610 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
|
|
611 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
|
|
612 | * our window. |
|
|
613 | */ |
|
|
614 | #if 0 |
|
|
615 | bool |
|
|
616 | bgPixmap_t::make_transparency_pixmap() |
|
|
617 | { |
|
|
618 | if (target == NULL) |
|
|
619 | return false; |
|
|
620 | |
|
|
621 | int sx, sy; |
|
|
622 | Window cr; |
|
|
623 | XTranslateCoordinates (target->dpy, target->parent[0], target->display->root, |
|
|
624 | 0, 0, &sx, &sy, &cr); |
|
|
625 | |
|
|
626 | /* check if we are outside of the visible part of the virtual screen : */ |
|
|
627 | if( sx + (int)szHint.width <= 0 || sy + (int)szHint.height <= 0 |
|
|
628 | || sx >= wrootattr.width || sy >= wrootattr.height ) |
|
|
629 | return false ; |
|
|
630 | |
|
|
631 | XWindowAttributes wattr, wrootattr; |
|
|
632 | |
|
|
633 | XGetWindowAttributes (dpy, display->root, &wrootattr); |
|
|
634 | |
|
|
635 | /* |
|
|
636 | * Make the frame window set by the window manager have |
|
|
637 | * the root background. Some window managers put multiple nested frame |
|
|
638 | * windows for each client, so we have to take care about that. |
|
|
639 | */ |
|
|
640 | i = (xa[XA_XROOTPMAP_ID] |
|
|
641 | && XGetWindowProperty (dpy, display->root, xa[XA_XROOTPMAP_ID], |
|
|
642 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
643 | &nitems, &bytes_after, &prop) == Success); |
|
|
644 | |
|
|
645 | if (!i || prop == NULL) |
|
|
646 | i = (xa[XA_ESETROOT_PMAP_ID] |
|
|
647 | && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], |
|
|
648 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
649 | &nitems, &bytes_after, &prop) == Success); |
|
|
650 | |
|
|
651 | if (!i || prop == NULL) |
|
|
652 | rootpixmap = None; |
|
|
653 | |
|
|
654 | } |
|
|
655 | #endif /* 0 */ |
|
|
656 | # endif /* ENABLE_TRANSPARENCY */ |
|
|
657 | |
|
|
658 | void |
|
|
659 | bgPixmap_t::apply_background() |
|
|
660 | { |
|
|
661 | if (target) |
|
|
662 | { |
|
|
663 | if (pixmap != None) |
|
|
664 | { /* set target's background to pixmap */ |
|
|
665 | # ifdef ENABLE_TRANSPARENCY |
|
|
666 | if (flags & bgPmap_Transparent) |
|
|
667 | { |
|
|
668 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
|
|
669 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
|
|
670 | if (target->scrollBar.win) |
|
|
671 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
|
|
672 | } |
|
|
673 | else |
|
|
674 | # endif |
|
|
675 | { |
|
|
676 | /* force old pixmap dereference in case it was transparent before :*/ |
|
|
677 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); |
|
|
678 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
679 | /* do we also need to set scrollbar's background here ? */ |
|
|
680 | } |
|
|
681 | } |
|
|
682 | else |
|
|
683 | { /* set target background to a pixel */ |
|
|
684 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_bg]); |
|
|
685 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
686 | /* do we also need to set scrollbar's background here ? */ |
|
|
687 | } |
|
|
688 | /* don't want Expose on the parent */ |
|
|
689 | XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); |
|
|
690 | /* do want Expose on the vt */ |
|
|
691 | XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); |
|
|
692 | } |
|
|
693 | } |
442 | #endif /* HAVE_BG_PIXMAP */ |
694 | #endif /* HAVE_BG_PIXMAP */ |
|
|
695 | |
|
|
696 | |
443 | |
697 | |
444 | #ifdef ENABLE_TRANSPARENCY |
698 | #ifdef ENABLE_TRANSPARENCY |
445 | #ifndef HAVE_AFTERIMAGE |
699 | #ifndef HAVE_AFTERIMAGE |
446 | /* taken from aterm-0.4.2 */ |
700 | /* taken from aterm-0.4.2 */ |
447 | |
701 | |
… | |
… | |
687 | } |
941 | } |
688 | |
942 | |
689 | void |
943 | void |
690 | rxvt_term::check_our_parents_cb (time_watcher &w) |
944 | rxvt_term::check_our_parents_cb (time_watcher &w) |
691 | { |
945 | { |
692 | int i, pchanged, aformat, rootdepth; |
946 | int i, aformat, rootdepth; |
693 | unsigned long nitems, bytes_after; |
947 | unsigned long nitems, bytes_after; |
694 | Atom atype; |
948 | Atom atype; |
695 | unsigned char *prop = NULL; |
949 | unsigned char *prop = NULL; |
696 | Window root, oldp, *list; |
950 | Window root, oldp, *list; |
697 | Pixmap rootpixmap = None; |
951 | Pixmap rootpixmap = None; |
698 | XWindowAttributes wattr, wrootattr; |
952 | XWindowAttributes wattr, wrootattr; |
699 | int sx, sy; |
953 | int sx, sy; |
700 | Window cr; |
954 | Window cr; |
701 | unsigned int rootpixmap_w = 0, rootpixmap_h = 0; |
955 | unsigned int rootpixmap_w = 0, rootpixmap_h = 0; |
702 | |
956 | |
703 | pchanged = 0; |
|
|
704 | |
|
|
705 | if (!option (Opt_transparent)) |
957 | if (!option (Opt_transparent)) |
706 | return /*pchanged*/; /* Don't try any more */ |
958 | return; /* Don't try any more */ |
707 | |
959 | |
708 | #if 0 |
960 | #if 0 |
709 | struct timeval stv; |
961 | struct timeval stv; |
710 | gettimeofday (&stv,NULL); |
962 | gettimeofday (&stv,NULL); |
711 | #define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ |
963 | #define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ |
… | |
… | |
723 | |
975 | |
724 | if (rootdepth != wattr.depth) |
976 | if (rootdepth != wattr.depth) |
725 | { |
977 | { |
726 | if (am_transparent) |
978 | if (am_transparent) |
727 | { |
979 | { |
728 | pchanged = 1; |
|
|
729 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
980 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
730 | am_transparent = am_pixmap_trans = 0; |
981 | am_transparent = am_pixmap_trans = 0; |
731 | } |
982 | } |
732 | |
983 | |
733 | return /*pchanged*/; /* Don't try any more */ |
984 | return; /* Don't try any more */ |
734 | } |
985 | } |
735 | |
986 | |
736 | /* Get all X ops out of the queue so that our information is up-to-date. */ |
987 | /* Get all X ops out of the queue so that our information is up-to-date. */ |
737 | XSync (dpy, False); |
988 | XSync (dpy, False); |
738 | |
989 | |
… | |
… | |
756 | i = (xa[XA_ESETROOT_PMAP_ID] |
1007 | i = (xa[XA_ESETROOT_PMAP_ID] |
757 | && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], |
1008 | && XGetWindowProperty (dpy, display->root, xa[XA_ESETROOT_PMAP_ID], |
758 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
1009 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
759 | &nitems, &bytes_after, &prop) == Success); |
1010 | &nitems, &bytes_after, &prop) == Success); |
760 | |
1011 | |
761 | /* TODO: the below logic needs to be cleaned up */ |
|
|
762 | if (!i || prop == NULL |
1012 | if (!i || prop == NULL) |
763 | || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL |
|
|
764 | #ifdef HAVE_AFTERIMAGE |
|
|
765 | && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL |
|
|
766 | #endif |
|
|
767 | ) |
|
|
768 | ) |
|
|
769 | rootpixmap = None; |
1013 | rootpixmap = None; |
770 | else |
1014 | else |
771 | { |
1015 | { |
772 | int junk; |
1016 | int junk; |
773 | unsigned int ujunk; |
1017 | unsigned int ujunk; |
… | |
… | |
877 | { |
1121 | { |
878 | destroy_asimage (&back_im); |
1122 | destroy_asimage (&back_im); |
879 | back_im = tmp; |
1123 | back_im = tmp; |
880 | } |
1124 | } |
881 | } |
1125 | } |
882 | |
1126 | /* TODO: temporary fix - redo the logic, so that same function can do both |
883 | if (bgPixmap.original_asim != NULL) |
1127 | transparency and non-transparency */ |
884 | { |
1128 | bgPixmap.render_asim (back_im, tint); |
885 | ASImageLayer *layers = create_image_layers (2); |
|
|
886 | ASImage *merged_im = NULL; |
|
|
887 | int fore_w, fore_h; |
|
|
888 | |
|
|
889 | layers[0].im = back_im; |
|
|
890 | layers[0].clip_width = szHint.width; |
|
|
891 | layers[0].clip_height = szHint.height; |
|
|
892 | layers[0].tint = tint; |
|
|
893 | layers[1].im = bgPixmap.original_asim; |
|
|
894 | |
|
|
895 | fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100; |
|
|
896 | fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100; |
|
|
897 | |
|
|
898 | if (fore_w != bgPixmap.original_asim->width |
|
|
899 | || fore_h != bgPixmap.original_asim->height) |
|
|
900 | { |
|
|
901 | layers[1].im = scale_asimage (asv, |
|
|
902 | bgPixmap.original_asim, |
|
|
903 | fore_w, fore_h, |
|
|
904 | ASA_ASImage, 100, |
|
|
905 | ASIMAGE_QUALITY_DEFAULT); |
|
|
906 | } |
|
|
907 | layers[1].clip_width = szHint.width; |
|
|
908 | layers[1].clip_height = szHint.height; |
|
|
909 | |
|
|
910 | if (rs[Rs_blendtype]) |
|
|
911 | { |
|
|
912 | layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); |
|
|
913 | if (layers[1].merge_scanlines == NULL) |
|
|
914 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
915 | } |
|
|
916 | PRINT_BACKGROUND_OP_TIME; |
|
|
917 | merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height, |
|
|
918 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
919 | if (layers[1].im != bgPixmap.original_asim) |
|
|
920 | destroy_asimage (&(layers[1].im)); |
|
|
921 | free (layers); |
|
|
922 | |
|
|
923 | if (merged_im != NULL) |
|
|
924 | { |
|
|
925 | destroy_asimage (&back_im); |
|
|
926 | back_im = merged_im; |
|
|
927 | } |
|
|
928 | PRINT_BACKGROUND_OP_TIME; |
|
|
929 | } |
|
|
930 | else if (tint != TINT_LEAVE_SAME) |
|
|
931 | { |
|
|
932 | ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
933 | if (tmp) |
|
|
934 | { |
|
|
935 | destroy_asimage (&back_im); |
|
|
936 | back_im = tmp; |
|
|
937 | } |
|
|
938 | PRINT_BACKGROUND_OP_TIME; |
|
|
939 | } |
|
|
940 | asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True); |
|
|
941 | destroy_asimage (&back_im); |
1129 | destroy_asimage (&back_im); |
|
|
1130 | |
942 | } /* back_im != NULL */ |
1131 | } /* back_im != NULL */ |
943 | else |
1132 | else |
944 | success = False; |
1133 | success = False; |
945 | } |
1134 | } |
946 | #else /* HAVE_AFTERIMAGE */ |
1135 | #else /* HAVE_AFTERIMAGE */ |
… | |
… | |
963 | #endif /* HAVE_AFTERIMAGE */ |
1152 | #endif /* HAVE_AFTERIMAGE */ |
964 | PRINT_BACKGROUND_OP_TIME; |
1153 | PRINT_BACKGROUND_OP_TIME; |
965 | |
1154 | |
966 | if (gc != NULL) |
1155 | if (gc != NULL) |
967 | XFreeGC (dpy, gc); |
1156 | XFreeGC (dpy, gc); |
968 | |
1157 | |
|
|
1158 | bgPixmap.apply_background(); |
969 | if (!success) |
1159 | if (!success) |
970 | { |
|
|
971 | if (am_transparent && am_pixmap_trans) |
|
|
972 | { |
|
|
973 | pchanged = 1; |
|
|
974 | if (bgPixmap.pixmap != None) |
|
|
975 | { |
|
|
976 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
977 | bgPixmap.pixmap = None; |
|
|
978 | } |
|
|
979 | } |
|
|
980 | |
|
|
981 | am_pixmap_trans = 0; |
1160 | am_pixmap_trans = 0; |
982 | } |
|
|
983 | else |
1161 | else |
984 | { |
1162 | { |
985 | XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap); |
|
|
986 | XClearWindow (dpy, parent[0]); |
|
|
987 | |
|
|
988 | if (!am_transparent || !am_pixmap_trans) |
|
|
989 | pchanged = 1; |
|
|
990 | |
|
|
991 | am_transparent = am_pixmap_trans = 1; |
1163 | am_transparent = am_pixmap_trans = 1; |
992 | } |
1164 | } |
993 | } /* rootpixmap != None */ |
1165 | } /* rootpixmap != None */ |
994 | |
1166 | |
995 | if (am_pixmap_trans) |
1167 | if (am_pixmap_trans) |
996 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
|
|
997 | else |
|
|
998 | { |
|
|
999 | unsigned int n; |
|
|
1000 | /* |
|
|
1001 | * InheritPixmap transparency |
|
|
1002 | */ |
|
|
1003 | for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
|
|
1004 | { |
|
|
1005 | oldp = parent[i]; |
|
|
1006 | XQueryTree (dpy, parent[i - 1], &root, &parent[i], &list, &n); |
|
|
1007 | XFree (list); |
|
|
1008 | |
|
|
1009 | if (parent[i] == display->root) |
|
|
1010 | { |
|
|
1011 | if (oldp != None) |
|
|
1012 | pchanged = 1; |
|
|
1013 | |
|
|
1014 | break; |
|
|
1015 | } |
|
|
1016 | |
|
|
1017 | if (oldp != parent[i]) |
|
|
1018 | pchanged = 1; |
|
|
1019 | } |
|
|
1020 | |
|
|
1021 | n = 0; |
|
|
1022 | |
|
|
1023 | if (pchanged) |
|
|
1024 | for (; n < (unsigned int)i; n++) |
|
|
1025 | { |
|
|
1026 | XGetWindowAttributes (dpy, parent[n], &wattr); |
|
|
1027 | |
|
|
1028 | if (wattr.depth != rootdepth || wattr.c_class == InputOnly) |
|
|
1029 | { |
|
|
1030 | n = (int) (sizeof (parent) / sizeof (Window)) + 1; |
|
|
1031 | break; |
|
|
1032 | } |
|
|
1033 | } |
|
|
1034 | |
|
|
1035 | if (n > (sizeof (parent) / sizeof (parent[0]))) |
|
|
1036 | { |
|
|
1037 | XSetWindowBackground (dpy, parent[0], pix_colors_focused[Color_border]); |
|
|
1038 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
|
|
1039 | am_transparent = 0; |
|
|
1040 | /* XXX: also turn off Opt_transparent? */ |
|
|
1041 | } |
|
|
1042 | else |
|
|
1043 | { |
|
|
1044 | for (n = 0; n < (unsigned int)i; n++) |
|
|
1045 | { |
|
|
1046 | XSetWindowBackgroundPixmap (dpy, parent[n], ParentRelative); |
|
|
1047 | XClearWindow (dpy, parent[n]); |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
|
|
1051 | am_transparent = 1; |
|
|
1052 | } |
|
|
1053 | |
|
|
1054 | for (; i < (int) (sizeof (parent) / sizeof (Window)); i++) |
|
|
1055 | parent[i] = None; |
|
|
1056 | } |
1168 | { |
1057 | |
|
|
1058 | if (scrollBar.win) |
1169 | if (scrollBar.win) |
1059 | { |
1170 | { |
1060 | XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); |
|
|
1061 | scrollBar.setIdle (); |
1171 | scrollBar.setIdle (); |
1062 | scrollbar_show (0); |
1172 | scrollbar_show (0); |
1063 | } |
1173 | } |
1064 | |
1174 | |
1065 | if (am_transparent) |
1175 | if (am_transparent) |
1066 | { |
1176 | { |
1067 | want_refresh = want_full_refresh = 1; |
1177 | want_refresh = want_full_refresh = 1; |
1068 | if (am_pixmap_trans) |
1178 | if (am_pixmap_trans) |
1069 | flush (); |
1179 | flush (); |
|
|
1180 | } |
1070 | } |
1181 | } |
1071 | |
|
|
1072 | // return pchanged; |
|
|
1073 | } |
1182 | } |
1074 | #endif |
1183 | #endif |