… | |
… | |
42 | |
42 | |
43 | bool |
43 | bool |
44 | rxvt_term::bg_window_size_sensitive () |
44 | rxvt_term::bg_window_size_sensitive () |
45 | { |
45 | { |
46 | # if BG_IMAGE_FROM_ROOT |
46 | # if BG_IMAGE_FROM_ROOT |
47 | if (option (Opt_transparent)) |
47 | if (root_img) |
48 | return true; |
48 | return true; |
49 | # endif |
49 | # endif |
50 | |
50 | |
51 | # if BG_IMAGE_FROM_FILE |
51 | # if BG_IMAGE_FROM_FILE |
52 | if (fimage.img) |
52 | if (fimage.img) |
… | |
… | |
63 | |
63 | |
64 | bool |
64 | bool |
65 | rxvt_term::bg_window_position_sensitive () |
65 | rxvt_term::bg_window_position_sensitive () |
66 | { |
66 | { |
67 | # if BG_IMAGE_FROM_ROOT |
67 | # if BG_IMAGE_FROM_ROOT |
68 | if (option (Opt_transparent)) |
68 | if (root_img) |
69 | return true; |
69 | return true; |
70 | # endif |
70 | # endif |
71 | |
71 | |
72 | # if BG_IMAGE_FROM_FILE |
72 | # if BG_IMAGE_FROM_FILE |
73 | if (fimage.img) |
73 | if (fimage.img) |
… | |
… | |
252 | |
252 | |
253 | return changed; |
253 | return changed; |
254 | } |
254 | } |
255 | |
255 | |
256 | void |
256 | void |
257 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
257 | rxvt_term::render_image (rxvt_image &image) |
258 | { |
258 | { |
259 | int image_width = image.img->w; |
259 | int image_width = image.img->w; |
260 | int image_height = image.img->h; |
260 | int image_height = image.img->h; |
261 | int parent_width = szHint.width; |
261 | int parent_width = szHint.width; |
262 | int parent_height = szHint.height; |
262 | int parent_height = szHint.height; |
263 | int h_scale = min (image.h_scale, 32767 * 100 / parent_width); |
263 | int h_scale = min (image.h_scale, 32767 * 100 / parent_width); |
264 | int v_scale = min (image.v_scale, 32767 * 100 / parent_height); |
264 | int v_scale = min (image.v_scale, 32767 * 100 / parent_height); |
265 | |
265 | |
|
|
266 | int w; |
|
|
267 | int h; |
|
|
268 | int x; |
|
|
269 | int y; |
|
|
270 | |
266 | w = h_scale * parent_width / 100; |
271 | w = h_scale * parent_width / 100; |
267 | h = v_scale * parent_height / 100; |
272 | h = v_scale * parent_height / 100; |
268 | |
273 | |
269 | if (image.flags & IM_KEEP_ASPECT) |
274 | if (image.flags & IM_KEEP_ASPECT) |
270 | { |
275 | { |
… | |
… | |
285 | else |
290 | else |
286 | { |
291 | { |
287 | x = make_align_position (image.h_align, parent_width, w); |
292 | x = make_align_position (image.h_align, parent_width, w); |
288 | y = make_align_position (image.v_align, parent_height, h); |
293 | y = make_align_position (image.v_align, parent_height, h); |
289 | } |
294 | } |
290 | } |
|
|
291 | |
|
|
292 | bool |
|
|
293 | rxvt_term::render_image (rxvt_image &image) |
|
|
294 | { |
|
|
295 | int parent_width = szHint.width; |
|
|
296 | int parent_height = szHint.height; |
|
|
297 | |
|
|
298 | int x = 0; |
|
|
299 | int y = 0; |
|
|
300 | int w = 0; |
|
|
301 | int h = 0; |
|
|
302 | |
|
|
303 | get_image_geometry (image, w, h, x, y); |
|
|
304 | |
295 | |
305 | if (!(image.flags & IM_ROOT_ALIGN) |
296 | if (!(image.flags & IM_ROOT_ALIGN) |
306 | && (x >= parent_width |
297 | && (x >= parent_width |
307 | || y >= parent_height |
298 | || y >= parent_height |
308 | || x + w <= 0 |
299 | || x + w <= 0 |
309 | || y + h <= 0)) |
300 | || y + h <= 0)) |
310 | return false; |
301 | return; |
311 | |
302 | |
312 | rxvt_img *img = image.img->scale (w, h); |
303 | rxvt_img *img = image.img->scale (w, h); |
313 | |
304 | |
314 | if (image.flags & IM_TILE) |
305 | if (image.flags & IM_TILE) |
315 | img->repeat_mode (RepeatNormal); |
306 | img->repeat_mode (RepeatNormal); |
316 | else |
307 | else |
317 | img->repeat_mode (RepeatNone); |
308 | img->repeat_mode (RepeatNone); |
318 | img->sub_rect (-x, -y, parent_width, parent_height)->replace (img); |
309 | img->sub_rect (-x, -y, parent_width, parent_height)->replace (img); |
319 | |
310 | |
320 | if (bg_flags & BG_IS_VALID) |
311 | if (bg_img) |
321 | img->draw (bg_img, PictOpOver, image.alpha * 1. / 0xffff); |
312 | img->draw (bg_img, PictOpOver, image.alpha * 1. / 0xffff); |
322 | |
313 | |
323 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
314 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
324 | img->convert_format (format, pix_colors [Color_bg])->replace (img); |
315 | img->convert_format (format, pix_colors [Color_bg])->replace (img); |
325 | |
316 | |
326 | delete bg_img; |
317 | delete bg_img; |
327 | bg_img = img; |
318 | bg_img = img; |
328 | |
|
|
329 | return true; |
|
|
330 | } |
319 | } |
331 | |
320 | |
332 | rxvt_image::rxvt_image () |
321 | rxvt_image::rxvt_image () |
333 | { |
322 | { |
334 | alpha = 0xffff; |
323 | alpha = 0xffff; |
… | |
… | |
440 | /* |
429 | /* |
441 | * Builds a pixmap of the same size as the terminal window that contains |
430 | * Builds a pixmap of the same size as the terminal window that contains |
442 | * the tiled portion of the root pixmap that is supposed to be covered by |
431 | * the tiled portion of the root pixmap that is supposed to be covered by |
443 | * our window. |
432 | * our window. |
444 | */ |
433 | */ |
445 | bool |
434 | void |
446 | rxvt_term::render_root_image () |
435 | rxvt_term::render_root_image () |
447 | { |
436 | { |
448 | /* root dimensions may change from call to call - but Display structure should |
437 | /* root dimensions may change from call to call - but Display structure should |
449 | * be always up-to-date, so let's use it : |
438 | * be always up-to-date, so let's use it : |
450 | */ |
439 | */ |
… | |
… | |
456 | int sx, sy; |
445 | int sx, sy; |
457 | |
446 | |
458 | sx = parent_x; |
447 | sx = parent_x; |
459 | sy = parent_y; |
448 | sy = parent_y; |
460 | |
449 | |
461 | if (!root_img) |
|
|
462 | return false; |
|
|
463 | |
|
|
464 | /* check if we are outside of the visible part of the virtual screen : */ |
450 | /* check if we are outside of the visible part of the virtual screen : */ |
465 | if (sx + parent_width <= 0 || sy + parent_height <= 0 |
451 | if (sx + parent_width <= 0 || sy + parent_height <= 0 |
466 | || sx >= root_width || sy >= root_height) |
452 | || sx >= root_width || sy >= root_height) |
467 | return 0; |
453 | return; |
468 | |
454 | |
469 | while (sx < 0) sx += root_img->w; |
455 | while (sx < 0) sx += root_img->w; |
470 | while (sy < 0) sy += root_img->h; |
456 | while (sy < 0) sy += root_img->h; |
471 | |
457 | |
472 | rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height); |
458 | rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height); |
… | |
… | |
480 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
466 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
481 | img->convert_format (format, pix_colors [Color_bg])->replace (img); |
467 | img->convert_format (format, pix_colors [Color_bg])->replace (img); |
482 | |
468 | |
483 | delete bg_img; |
469 | delete bg_img; |
484 | bg_img = img; |
470 | bg_img = img; |
485 | |
|
|
486 | return true; |
|
|
487 | } |
|
|
488 | |
|
|
489 | void |
|
|
490 | rxvt_term::bg_set_root_pixmap () |
|
|
491 | { |
|
|
492 | delete root_img; |
|
|
493 | root_img = rxvt_img::new_from_root (this); |
|
|
494 | } |
471 | } |
495 | # endif /* BG_IMAGE_FROM_ROOT */ |
472 | # endif /* BG_IMAGE_FROM_ROOT */ |
496 | |
473 | |
497 | void |
474 | void |
498 | rxvt_term::bg_render () |
475 | rxvt_term::bg_render () |
499 | { |
476 | { |
500 | if (bg_flags & BG_INHIBIT_RENDER) |
477 | if (bg_flags & BG_INHIBIT_RENDER) |
501 | return; |
478 | return; |
502 | |
479 | |
503 | bg_invalidate (); |
480 | delete bg_img; |
|
|
481 | bg_img = 0; |
|
|
482 | bg_flags = 0; |
|
|
483 | |
|
|
484 | if (!mapped) |
|
|
485 | return; |
|
|
486 | |
504 | # if BG_IMAGE_FROM_ROOT |
487 | # if BG_IMAGE_FROM_ROOT |
505 | if (option (Opt_transparent)) |
488 | if (root_img) |
506 | { |
489 | { |
507 | /* we need to re-generate transparency pixmap in that case ! */ |
|
|
508 | if (render_root_image ()) |
490 | render_root_image (); |
509 | bg_flags |= BG_IS_VALID | BG_IS_TRANSPARENT; |
491 | bg_flags |= BG_IS_TRANSPARENT; |
510 | } |
492 | } |
511 | # endif |
493 | # endif |
512 | |
494 | |
513 | # if BG_IMAGE_FROM_FILE |
495 | # if BG_IMAGE_FROM_FILE |
514 | if (fimage.img) |
496 | if (fimage.img) |
515 | { |
|
|
516 | if (render_image (fimage)) |
497 | render_image (fimage); |
517 | bg_flags |= BG_IS_VALID; |
|
|
518 | } |
|
|
519 | # endif |
498 | # endif |
520 | |
|
|
521 | if (!(bg_flags & BG_IS_VALID)) |
|
|
522 | { |
|
|
523 | delete bg_img; |
|
|
524 | bg_img = 0; |
|
|
525 | } |
|
|
526 | |
499 | |
527 | scr_recolour (false); |
500 | scr_recolour (false); |
528 | bg_flags |= BG_NEEDS_REFRESH; |
501 | bg_flags |= BG_NEEDS_REFRESH; |
529 | |
502 | |
530 | bg_valid_since = ev::now (); |
503 | bg_valid_since = ev::now (); |
… | |
… | |
543 | root_effects.set_tint (pix_colors_focused [Color_tint]); |
516 | root_effects.set_tint (pix_colors_focused [Color_tint]); |
544 | |
517 | |
545 | if (rs [Rs_shade]) |
518 | if (rs [Rs_shade]) |
546 | root_effects.set_shade (rs [Rs_shade]); |
519 | root_effects.set_shade (rs [Rs_shade]); |
547 | |
520 | |
548 | bg_set_root_pixmap (); |
521 | rxvt_img::new_from_root (this)->replace (root_img); |
549 | XSelectInput (dpy, display->root, PropertyChangeMask); |
522 | XSelectInput (dpy, display->root, PropertyChangeMask); |
550 | rootwin_ev.start (display, display->root); |
523 | rootwin_ev.start (display, display->root); |
551 | } |
524 | } |
552 | #endif |
525 | #endif |
553 | |
526 | |