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.238 by sf-exg, Sun Jun 10 15:48:08 2012 UTC vs.
Revision 1.253 by sf-exg, Sun Dec 30 15:52:37 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}
45
46bool
47rxvt_term::bg_set_position (int x, int y)
48{
49
50 if (target_x != x
51 || target_y != y)
52 {
53 target_x = x;
54 target_y = y;
55 return true;
56 }
57 return false;
58} 41}
59 42
60bool 43bool
61rxvt_term::bg_window_size_sensitive () 44rxvt_term::bg_window_size_sensitive ()
62{ 45{
63# if ENABLE_TRANSPARENCY 46# if BG_IMAGE_FROM_ROOT
64 if (bg_flags & BG_IS_TRANSPARENT) 47 if (option (Opt_transparent))
65 return true; 48 return true;
66# endif 49# endif
67 50
68# if BG_IMAGE_FROM_FILE 51# if BG_IMAGE_FROM_FILE
69 if (fimage.img) 52 if (fimage.img)
79} 62}
80 63
81bool 64bool
82rxvt_term::bg_window_position_sensitive () 65rxvt_term::bg_window_position_sensitive ()
83{ 66{
84# if ENABLE_TRANSPARENCY 67# if BG_IMAGE_FROM_ROOT
85 if (bg_flags & BG_IS_TRANSPARENT) 68 if (option (Opt_transparent))
86 return true; 69 return true;
87# endif 70# endif
88 71
89# if BG_IMAGE_FROM_FILE 72# if BG_IMAGE_FROM_FILE
90 if (fimage.img) 73 if (fimage.img)
273void 256void
274rxvt_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)
275{ 258{
276 int image_width = image.img->w; 259 int image_width = image.img->w;
277 int image_height = image.img->h; 260 int image_height = image.img->h;
278 int target_width = szHint.width; 261 int parent_width = szHint.width;
279 int target_height = szHint.height; 262 int parent_height = szHint.height;
280 int h_scale = min (image.h_scale, 32767 * 100 / target_width); 263 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
281 int v_scale = min (image.v_scale, 32767 * 100 / target_height); 264 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
282 265
283 w = h_scale * target_width / 100; 266 w = h_scale * parent_width / 100;
284 h = v_scale * target_height / 100; 267 h = v_scale * parent_height / 100;
285 268
286 if (image.flags & IM_KEEP_ASPECT) 269 if (image.flags & IM_KEEP_ASPECT)
287 { 270 {
288 float scale = (float)w / image_width; 271 float scale = (float)w / image_width;
289 min_it (scale, (float)h / image_height); 272 min_it (scale, (float)h / image_height);
294 if (!w) w = image_width; 277 if (!w) w = image_width;
295 if (!h) h = image_height; 278 if (!h) h = image_height;
296 279
297 if (image.flags & IM_ROOT_ALIGN) 280 if (image.flags & IM_ROOT_ALIGN)
298 { 281 {
299 x = -target_x; 282 x = -parent_x;
300 y = -target_y; 283 y = -parent_y;
301 } 284 }
302 else 285 else
303 { 286 {
304 x = make_align_position (image.h_align, target_width, w); 287 x = make_align_position (image.h_align, parent_width, w);
305 y = make_align_position (image.v_align, target_height, h); 288 y = make_align_position (image.v_align, parent_height, h);
306 } 289 }
307} 290}
308 291
309bool 292bool
310rxvt_term::render_image (rxvt_image &image) 293rxvt_term::render_image (rxvt_image &image)
311{ 294{
312 int target_width = szHint.width; 295 int parent_width = szHint.width;
313 int target_height = szHint.height; 296 int parent_height = szHint.height;
314 297
315 int x = 0; 298 int x = 0;
316 int y = 0; 299 int y = 0;
317 int w = 0; 300 int w = 0;
318 int h = 0; 301 int h = 0;
319 302
320 get_image_geometry (image, w, h, x, y); 303 get_image_geometry (image, w, h, x, y);
321 304
322 if (!(image.flags & IM_ROOT_ALIGN) 305 if (!(image.flags & IM_ROOT_ALIGN)
323 && (x >= target_width 306 && (x >= parent_width
324 || y >= target_height 307 || y >= parent_height
325 || x + w <= 0 308 || x + w <= 0
326 || y + h <= 0)) 309 || y + h <= 0))
327 return false; 310 return false;
328 311
329 rxvt_img *img = image.img->scale (w, h); 312 rxvt_img *img = image.img->scale (w, h);
330 313
331 if (image.flags & IM_TILE) 314 if (image.flags & IM_TILE)
332 img->repeat_mode (RepeatNormal); 315 img->repeat_mode (RepeatNormal);
333 else 316 else
334 img->repeat_mode (RepeatNone); 317 img->repeat_mode (RepeatNone);
335 img->sub_rect (-x, -y, target_width, target_height)->replace (img); 318 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
336 319
337 if (bg_flags & BG_IS_VALID) 320 if (bg_img)
338 { 321 img->draw (bg_img, PictOpOver, image.alpha * 1. / 0xffff);
339 double factor = image.alpha * 1. / 0xffff;
340 bg_img->blend (img, factor)->replace (img);
341 }
342 322
343 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 323 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
344 img->convert_format (format, pix_colors [Color_bg])->replace (img); 324 img->convert_format (format, pix_colors [Color_bg])->replace (img);
345 325
346 delete bg_img; 326 delete bg_img;
359 v_align = defaultAlign; 339 v_align = defaultAlign;
360 340
361 img = 0; 341 img = 0;
362} 342}
363 343
364bool 344void
365rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 345rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
366{ 346{
367 if (!file || !*file) 347 if (!file || !*file)
368 return false; 348 return;
369 349
370 const char *p = strchr (file, ';'); 350 const char *p = strchr (file, ';');
371 351
372 if (p) 352 if (p)
373 { 353 {
376 memcpy (f, file, len); 356 memcpy (f, file, len);
377 f[len] = '\0'; 357 f[len] = '\0';
378 file = f; 358 file = f;
379 } 359 }
380 360
381 bool ret = set_file (s, file); 361 set_file (s, file);
382 alpha = 0x8000; 362 alpha = 0x8000;
383 if (ret)
384 set_geometry (p ? p + 1 : ""); 363 set_geometry (p ? p + 1 : "");
385 return ret;
386} 364}
387 365
388bool 366void
389rxvt_image::set_file (rxvt_screen *s, const char *file) 367rxvt_image::set_file (rxvt_screen *s, const char *file)
390{ 368{
369 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
391 delete img; 370 delete img;
392 img = rxvt_img::new_from_file (s, file); 371 img = img2;
393 return img != 0;
394} 372}
395 373
396# endif /* BG_IMAGE_FROM_FILE */ 374# endif /* BG_IMAGE_FROM_FILE */
397 375
398bool 376bool
456 } 434 }
457 435
458 return false; 436 return false;
459} 437}
460 438
461# if ENABLE_TRANSPARENCY 439# if BG_IMAGE_FROM_ROOT
462/* 440/*
463 * 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
464 * 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
465 * our window. 443 * our window.
466 */ 444 */
471 * be always up-to-date, so let's use it : 449 * be always up-to-date, so let's use it :
472 */ 450 */
473 int screen = display->screen; 451 int screen = display->screen;
474 int root_width = DisplayWidth (dpy, screen); 452 int root_width = DisplayWidth (dpy, screen);
475 int root_height = DisplayHeight (dpy, screen); 453 int root_height = DisplayHeight (dpy, screen);
476 int window_width = szHint.width; 454 int parent_width = szHint.width;
477 int window_height = szHint.height; 455 int parent_height = szHint.height;
478 int sx, sy; 456 int sx, sy;
479 457
480 sx = target_x; 458 sx = parent_x;
481 sy = target_y; 459 sy = parent_y;
482 460
483 if (!root_img) 461 if (!root_img)
484 return false; 462 return false;
485 463
486 /* 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 : */
487 if (sx + window_width <= 0 || sy + window_height <= 0 465 if (sx + parent_width <= 0 || sy + parent_height <= 0
488 || sx >= root_width || sy >= root_height) 466 || sx >= root_width || sy >= root_height)
489 return 0; 467 return 0;
490 468
491 while (sx < 0) sx += root_img->w; 469 while (sx < 0) sx += root_img->w;
492 while (sy < 0) sy += root_img->h; 470 while (sy < 0) sy += root_img->h;
493 471
494 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);
495 473
496 if (root_effects.need_blur ()) 474 if (root_effects.need_blur ())
497 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);
498 476
499 if (root_effects.need_tint ()) 477 if (root_effects.need_tint ())
512rxvt_term::bg_set_root_pixmap () 490rxvt_term::bg_set_root_pixmap ()
513{ 491{
514 delete root_img; 492 delete root_img;
515 root_img = rxvt_img::new_from_root (this); 493 root_img = rxvt_img::new_from_root (this);
516} 494}
517# endif /* ENABLE_TRANSPARENCY */ 495# endif /* BG_IMAGE_FROM_ROOT */
518 496
519void 497void
520rxvt_term::bg_render () 498rxvt_term::bg_render ()
521{ 499{
522 if (bg_flags & BG_INHIBIT_RENDER) 500 if (bg_flags & BG_INHIBIT_RENDER)
523 return; 501 return;
524 502
525 bg_invalidate (); 503 delete bg_img;
526# if ENABLE_TRANSPARENCY 504 bg_img = 0;
527 if (bg_flags & BG_IS_TRANSPARENT) 505 bg_flags = 0;
528 { 506
529 /* we need to re-generate transparency pixmap in that case ! */ 507 if (!mapped)
508 return;
509
510# if BG_IMAGE_FROM_ROOT
511 if (option (Opt_transparent))
530 if (render_root_image ()) 512 if (render_root_image ())
531 bg_flags |= BG_IS_VALID; 513 bg_flags |= BG_IS_TRANSPARENT;
532 }
533# endif 514# endif
534 515
535# if BG_IMAGE_FROM_FILE 516# if BG_IMAGE_FROM_FILE
536 if (fimage.img) 517 if (fimage.img)
537 {
538 if (render_image (fimage)) 518 render_image (fimage);
539 bg_flags |= BG_IS_VALID;
540 }
541# endif 519# endif
542
543 if (!(bg_flags & BG_IS_VALID))
544 {
545 delete bg_img;
546 bg_img = 0;
547 }
548 520
549 scr_recolour (false); 521 scr_recolour (false);
550 bg_flags |= BG_NEEDS_REFRESH; 522 bg_flags |= BG_NEEDS_REFRESH;
551 523
552 bg_valid_since = ev::now (); 524 bg_valid_since = ev::now ();
553} 525}
554 526
555void 527void
556rxvt_term::bg_init () 528rxvt_term::bg_init ()
557{ 529{
530#if BG_IMAGE_FROM_ROOT
531 if (option (Opt_transparent))
532 {
533 if (rs [Rs_blurradius])
534 root_effects.set_blur (rs [Rs_blurradius]);
535
536 if (ISSET_PIXCOLOR (Color_tint))
537 root_effects.set_tint (pix_colors_focused [Color_tint]);
538
539 if (rs [Rs_shade])
540 root_effects.set_shade (rs [Rs_shade]);
541
542 bg_set_root_pixmap ();
543 XSelectInput (dpy, display->root, PropertyChangeMask);
544 rootwin_ev.start (display, display->root);
545 }
546#endif
547
558#if BG_IMAGE_FROM_FILE 548#if BG_IMAGE_FROM_FILE
559 if (rs[Rs_backgroundPixmap]) 549 if (rs[Rs_backgroundPixmap])
560 { 550 {
561 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 551 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
562 && !bg_window_position_sensitive ()) 552 if (!bg_window_position_sensitive ())
563 update_background (); 553 update_background ();
564 } 554 }
565#endif 555#endif
566} 556}
567 557

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines