ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.239 by sf-exg, Sun Jun 10 16:00:25 2012 UTC vs.
Revision 1.250 by sf-exg, Sun Dec 30 12:06:33 2012 UTC

1/*----------------------------------------------------------------------* 1/*----------------------------------------------------------------------*
2 * File: background.C - former xpm.C 2 * File: background.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) 2005-2008 Marc Lehmann <schmorp@schmorp.de> 6 * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de>
7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> 7 * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net>
28#ifdef HAVE_BG_PIXMAP 28#ifdef HAVE_BG_PIXMAP
29 29
30void 30void
31rxvt_term::bg_destroy () 31rxvt_term::bg_destroy ()
32{ 32{
33# if ENABLE_TRANSPARENCY 33# if BG_IMAGE_FROM_ROOT
34 delete root_img; 34 delete root_img;
35 root_img = 0; 35 root_img = 0;
36# endif 36# endif
37 37
38# if BG_IMAGE_FROM_FILE 38# if BG_IMAGE_FROM_FILE
39 fimage.destroy (); 39 fimage.destroy ();
40# endif 40# endif
41
42 delete bg_img;
43 bg_img = 0;
44} 41}
45 42
46bool 43bool
47rxvt_term::bg_window_size_sensitive () 44rxvt_term::bg_window_size_sensitive ()
48{ 45{
49# if ENABLE_TRANSPARENCY 46# if BG_IMAGE_FROM_ROOT
50 if (bg_flags & BG_IS_TRANSPARENT) 47 if (option (Opt_transparent))
51 return true; 48 return true;
52# endif 49# endif
53 50
54# if BG_IMAGE_FROM_FILE 51# if BG_IMAGE_FROM_FILE
55 if (fimage.img) 52 if (fimage.img)
65} 62}
66 63
67bool 64bool
68rxvt_term::bg_window_position_sensitive () 65rxvt_term::bg_window_position_sensitive ()
69{ 66{
70# if ENABLE_TRANSPARENCY 67# if BG_IMAGE_FROM_ROOT
71 if (bg_flags & BG_IS_TRANSPARENT) 68 if (option (Opt_transparent))
72 return true; 69 return true;
73# endif 70# endif
74 71
75# if BG_IMAGE_FROM_FILE 72# if BG_IMAGE_FROM_FILE
76 if (fimage.img) 73 if (fimage.img)
259void 256void
260rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) 257rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y)
261{ 258{
262 int image_width = image.img->w; 259 int image_width = image.img->w;
263 int image_height = image.img->h; 260 int image_height = image.img->h;
264 int target_width = szHint.width; 261 int parent_width = szHint.width;
265 int target_height = szHint.height; 262 int parent_height = szHint.height;
266 int h_scale = min (image.h_scale, 32767 * 100 / target_width); 263 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
267 int v_scale = min (image.v_scale, 32767 * 100 / target_height); 264 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
268 265
269 w = h_scale * target_width / 100; 266 w = h_scale * parent_width / 100;
270 h = v_scale * target_height / 100; 267 h = v_scale * parent_height / 100;
271 268
272 if (image.flags & IM_KEEP_ASPECT) 269 if (image.flags & IM_KEEP_ASPECT)
273 { 270 {
274 float scale = (float)w / image_width; 271 float scale = (float)w / image_width;
275 min_it (scale, (float)h / image_height); 272 min_it (scale, (float)h / image_height);
285 x = -parent_x; 282 x = -parent_x;
286 y = -parent_y; 283 y = -parent_y;
287 } 284 }
288 else 285 else
289 { 286 {
290 x = make_align_position (image.h_align, target_width, w); 287 x = make_align_position (image.h_align, parent_width, w);
291 y = make_align_position (image.v_align, target_height, h); 288 y = make_align_position (image.v_align, parent_height, h);
292 } 289 }
293} 290}
294 291
295bool 292bool
296rxvt_term::render_image (rxvt_image &image) 293rxvt_term::render_image (rxvt_image &image)
297{ 294{
298 int target_width = szHint.width; 295 int parent_width = szHint.width;
299 int target_height = szHint.height; 296 int parent_height = szHint.height;
300 297
301 int x = 0; 298 int x = 0;
302 int y = 0; 299 int y = 0;
303 int w = 0; 300 int w = 0;
304 int h = 0; 301 int h = 0;
305 302
306 get_image_geometry (image, w, h, x, y); 303 get_image_geometry (image, w, h, x, y);
307 304
308 if (!(image.flags & IM_ROOT_ALIGN) 305 if (!(image.flags & IM_ROOT_ALIGN)
309 && (x >= target_width 306 && (x >= parent_width
310 || y >= target_height 307 || y >= parent_height
311 || x + w <= 0 308 || x + w <= 0
312 || y + h <= 0)) 309 || y + h <= 0))
313 return false; 310 return false;
314 311
315 rxvt_img *img = image.img->scale (w, h); 312 rxvt_img *img = image.img->scale (w, h);
316 313
317 if (image.flags & IM_TILE) 314 if (image.flags & IM_TILE)
318 img->repeat_mode (RepeatNormal); 315 img->repeat_mode (RepeatNormal);
319 else 316 else
320 img->repeat_mode (RepeatNone); 317 img->repeat_mode (RepeatNone);
321 img->sub_rect (-x, -y, target_width, target_height)->replace (img); 318 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
322 319
323 if (bg_flags & BG_IS_VALID) 320 if (bg_img)
324 { 321 img->draw (bg_img, PictOpOver, image.alpha * 1. / 0xffff);
325 double factor = image.alpha * 1. / 0xffff;
326 bg_img->blend (img, factor)->replace (img);
327 }
328 322
329 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 323 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
330 img->convert_format (format, pix_colors [Color_bg])->replace (img); 324 img->convert_format (format, pix_colors [Color_bg])->replace (img);
331 325
332 delete bg_img; 326 delete bg_img;
345 v_align = defaultAlign; 339 v_align = defaultAlign;
346 340
347 img = 0; 341 img = 0;
348} 342}
349 343
350bool 344void
351rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 345rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
352{ 346{
353 if (!file || !*file) 347 if (!file || !*file)
354 return false; 348 return;
355 349
356 const char *p = strchr (file, ';'); 350 const char *p = strchr (file, ';');
357 351
358 if (p) 352 if (p)
359 { 353 {
362 memcpy (f, file, len); 356 memcpy (f, file, len);
363 f[len] = '\0'; 357 f[len] = '\0';
364 file = f; 358 file = f;
365 } 359 }
366 360
367 bool ret = set_file (s, file); 361 set_file (s, file);
368 alpha = 0x8000; 362 alpha = 0x8000;
369 if (ret)
370 set_geometry (p ? p + 1 : ""); 363 set_geometry (p ? p + 1 : "");
371 return ret;
372} 364}
373 365
374bool 366void
375rxvt_image::set_file (rxvt_screen *s, const char *file) 367rxvt_image::set_file (rxvt_screen *s, const char *file)
376{ 368{
369 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
377 delete img; 370 delete img;
378 img = rxvt_img::new_from_file (s, file); 371 img = img2;
379 return img != 0;
380} 372}
381 373
382# endif /* BG_IMAGE_FROM_FILE */ 374# endif /* BG_IMAGE_FROM_FILE */
383 375
384bool 376bool
442 } 434 }
443 435
444 return false; 436 return false;
445} 437}
446 438
447# if ENABLE_TRANSPARENCY 439# if BG_IMAGE_FROM_ROOT
448/* 440/*
449 * Builds a pixmap of the same size as the terminal window that contains 441 * Builds a pixmap of the same size as the terminal window that contains
450 * the tiled portion of the root pixmap that is supposed to be covered by 442 * the tiled portion of the root pixmap that is supposed to be covered by
451 * our window. 443 * our window.
452 */ 444 */
457 * be always up-to-date, so let's use it : 449 * be always up-to-date, so let's use it :
458 */ 450 */
459 int screen = display->screen; 451 int screen = display->screen;
460 int root_width = DisplayWidth (dpy, screen); 452 int root_width = DisplayWidth (dpy, screen);
461 int root_height = DisplayHeight (dpy, screen); 453 int root_height = DisplayHeight (dpy, screen);
462 int window_width = szHint.width; 454 int parent_width = szHint.width;
463 int window_height = szHint.height; 455 int parent_height = szHint.height;
464 int sx, sy; 456 int sx, sy;
465 457
466 sx = parent_x; 458 sx = parent_x;
467 sy = parent_y; 459 sy = parent_y;
468 460
469 if (!root_img) 461 if (!root_img)
470 return false; 462 return false;
471 463
472 /* check if we are outside of the visible part of the virtual screen : */ 464 /* check if we are outside of the visible part of the virtual screen : */
473 if (sx + window_width <= 0 || sy + window_height <= 0 465 if (sx + parent_width <= 0 || sy + parent_height <= 0
474 || sx >= root_width || sy >= root_height) 466 || sx >= root_width || sy >= root_height)
475 return 0; 467 return 0;
476 468
477 while (sx < 0) sx += root_img->w; 469 while (sx < 0) sx += root_img->w;
478 while (sy < 0) sy += root_img->h; 470 while (sy < 0) sy += root_img->h;
479 471
480 rxvt_img *img = root_img->sub_rect (sx, sy, window_width, window_height); 472 rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height);
481 473
482 if (root_effects.need_blur ()) 474 if (root_effects.need_blur ())
483 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); 475 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
484 476
485 if (root_effects.need_tint ()) 477 if (root_effects.need_tint ())
498rxvt_term::bg_set_root_pixmap () 490rxvt_term::bg_set_root_pixmap ()
499{ 491{
500 delete root_img; 492 delete root_img;
501 root_img = rxvt_img::new_from_root (this); 493 root_img = rxvt_img::new_from_root (this);
502} 494}
503# endif /* ENABLE_TRANSPARENCY */ 495# endif /* BG_IMAGE_FROM_ROOT */
504 496
505void 497void
506rxvt_term::bg_render () 498rxvt_term::bg_render ()
507{ 499{
508 if (bg_flags & BG_INHIBIT_RENDER) 500 if (bg_flags & BG_INHIBIT_RENDER)
509 return; 501 return;
510 502
511 bg_invalidate (); 503 delete bg_img;
512# if ENABLE_TRANSPARENCY 504 bg_img = 0;
513 if (bg_flags & BG_IS_TRANSPARENT) 505 bg_flags &= BG_INHIBIT_RENDER;
506
507# if BG_IMAGE_FROM_ROOT
508 if (option (Opt_transparent))
514 { 509 {
515 /* we need to re-generate transparency pixmap in that case ! */ 510 /* we need to re-generate transparency pixmap in that case ! */
516 if (render_root_image ()) 511 if (render_root_image ())
517 bg_flags |= BG_IS_VALID; 512 bg_flags |= BG_IS_VALID | BG_IS_TRANSPARENT;
518 } 513 }
519# endif 514# endif
520 515
521# if BG_IMAGE_FROM_FILE 516# if BG_IMAGE_FROM_FILE
522 if (fimage.img) 517 if (fimage.img)
524 if (render_image (fimage)) 519 if (render_image (fimage))
525 bg_flags |= BG_IS_VALID; 520 bg_flags |= BG_IS_VALID;
526 } 521 }
527# endif 522# endif
528 523
529 if (!(bg_flags & BG_IS_VALID))
530 {
531 delete bg_img;
532 bg_img = 0;
533 }
534
535 scr_recolour (false); 524 scr_recolour (false);
536 bg_flags |= BG_NEEDS_REFRESH; 525 bg_flags |= BG_NEEDS_REFRESH;
537 526
538 bg_valid_since = ev::now (); 527 bg_valid_since = ev::now ();
539} 528}
540 529
541void 530void
542rxvt_term::bg_init () 531rxvt_term::bg_init ()
543{ 532{
533#if BG_IMAGE_FROM_ROOT
534 if (option (Opt_transparent))
535 {
536 if (rs [Rs_blurradius])
537 root_effects.set_blur (rs [Rs_blurradius]);
538
539 if (ISSET_PIXCOLOR (Color_tint))
540 root_effects.set_tint (pix_colors_focused [Color_tint]);
541
542 if (rs [Rs_shade])
543 root_effects.set_shade (rs [Rs_shade]);
544
545 bg_set_root_pixmap ();
546 XSelectInput (dpy, display->root, PropertyChangeMask);
547 rootwin_ev.start (display, display->root);
548 }
549#endif
550
544#if BG_IMAGE_FROM_FILE 551#if BG_IMAGE_FROM_FILE
545 if (rs[Rs_backgroundPixmap]) 552 if (rs[Rs_backgroundPixmap])
546 { 553 {
547 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 554 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
548 && !bg_window_position_sensitive ()) 555 if (!bg_window_position_sensitive ())
549 update_background (); 556 update_background ();
550 } 557 }
551#endif 558#endif
552} 559}
553 560

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines