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.255 by sf-exg, Mon Dec 31 12:05:34 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 (root_img)
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 (root_img)
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)
268 flags &= ~IM_IS_SIZE_SENSITIVE; 251 flags &= ~IM_IS_SIZE_SENSITIVE;
269 252
270 return changed; 253 return changed;
271} 254}
272 255
273void 256bool
274rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) 257rxvt_term::render_image (rxvt_image &image)
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
266 int w;
267 int h;
268 int x;
269 int y;
270
283 w = h_scale * target_width / 100; 271 w = h_scale * parent_width / 100;
284 h = v_scale * target_height / 100; 272 h = v_scale * parent_height / 100;
285 273
286 if (image.flags & IM_KEEP_ASPECT) 274 if (image.flags & IM_KEEP_ASPECT)
287 { 275 {
288 float scale = (float)w / image_width; 276 float scale = (float)w / image_width;
289 min_it (scale, (float)h / image_height); 277 min_it (scale, (float)h / image_height);
294 if (!w) w = image_width; 282 if (!w) w = image_width;
295 if (!h) h = image_height; 283 if (!h) h = image_height;
296 284
297 if (image.flags & IM_ROOT_ALIGN) 285 if (image.flags & IM_ROOT_ALIGN)
298 { 286 {
299 x = -target_x; 287 x = -parent_x;
300 y = -target_y; 288 y = -parent_y;
301 } 289 }
302 else 290 else
303 { 291 {
304 x = make_align_position (image.h_align, target_width, w); 292 x = make_align_position (image.h_align, parent_width, w);
305 y = make_align_position (image.v_align, target_height, h); 293 y = make_align_position (image.v_align, parent_height, h);
306 } 294 }
307}
308
309bool
310rxvt_term::render_image (rxvt_image &image)
311{
312 int target_width = szHint.width;
313 int target_height = szHint.height;
314
315 int x = 0;
316 int y = 0;
317 int w = 0;
318 int h = 0;
319
320 get_image_geometry (image, w, h, x, y);
321 295
322 if (!(image.flags & IM_ROOT_ALIGN) 296 if (!(image.flags & IM_ROOT_ALIGN)
323 && (x >= target_width 297 && (x >= parent_width
324 || y >= target_height 298 || y >= parent_height
325 || x + w <= 0 299 || x + w <= 0
326 || y + h <= 0)) 300 || y + h <= 0))
327 return false; 301 return false;
328 302
329 rxvt_img *img = image.img->scale (w, h); 303 rxvt_img *img = image.img->scale (w, h);
330 304
331 if (image.flags & IM_TILE) 305 if (image.flags & IM_TILE)
332 img->repeat_mode (RepeatNormal); 306 img->repeat_mode (RepeatNormal);
333 else 307 else
334 img->repeat_mode (RepeatNone); 308 img->repeat_mode (RepeatNone);
335 img->sub_rect (-x, -y, target_width, target_height)->replace (img); 309 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
336 310
337 if (bg_flags & BG_IS_VALID) 311 if (bg_img)
338 { 312 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 313
343 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 314 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
344 img->convert_format (format, pix_colors [Color_bg])->replace (img); 315 img->convert_format (format, pix_colors [Color_bg])->replace (img);
345 316
346 delete bg_img; 317 delete bg_img;
359 v_align = defaultAlign; 330 v_align = defaultAlign;
360 331
361 img = 0; 332 img = 0;
362} 333}
363 334
364bool 335void
365rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 336rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
366{ 337{
367 if (!file || !*file) 338 if (!file || !*file)
368 return false; 339 return;
369 340
370 const char *p = strchr (file, ';'); 341 const char *p = strchr (file, ';');
371 342
372 if (p) 343 if (p)
373 { 344 {
376 memcpy (f, file, len); 347 memcpy (f, file, len);
377 f[len] = '\0'; 348 f[len] = '\0';
378 file = f; 349 file = f;
379 } 350 }
380 351
381 bool ret = set_file (s, file); 352 set_file (s, file);
382 alpha = 0x8000; 353 alpha = 0x8000;
383 if (ret)
384 set_geometry (p ? p + 1 : ""); 354 set_geometry (p ? p + 1 : "");
385 return ret;
386} 355}
387 356
388bool 357void
389rxvt_image::set_file (rxvt_screen *s, const char *file) 358rxvt_image::set_file (rxvt_screen *s, const char *file)
390{ 359{
360 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
391 delete img; 361 delete img;
392 img = rxvt_img::new_from_file (s, file); 362 img = img2;
393 return img != 0;
394} 363}
395 364
396# endif /* BG_IMAGE_FROM_FILE */ 365# endif /* BG_IMAGE_FROM_FILE */
397 366
398bool 367bool
456 } 425 }
457 426
458 return false; 427 return false;
459} 428}
460 429
461# if ENABLE_TRANSPARENCY 430# if BG_IMAGE_FROM_ROOT
462/* 431/*
463 * Builds a pixmap of the same size as the terminal window that contains 432 * 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 433 * the tiled portion of the root pixmap that is supposed to be covered by
465 * our window. 434 * our window.
466 */ 435 */
471 * be always up-to-date, so let's use it : 440 * be always up-to-date, so let's use it :
472 */ 441 */
473 int screen = display->screen; 442 int screen = display->screen;
474 int root_width = DisplayWidth (dpy, screen); 443 int root_width = DisplayWidth (dpy, screen);
475 int root_height = DisplayHeight (dpy, screen); 444 int root_height = DisplayHeight (dpy, screen);
476 int window_width = szHint.width; 445 int parent_width = szHint.width;
477 int window_height = szHint.height; 446 int parent_height = szHint.height;
478 int sx, sy; 447 int sx, sy;
479 448
480 sx = target_x; 449 sx = parent_x;
481 sy = target_y; 450 sy = parent_y;
482
483 if (!root_img)
484 return false;
485 451
486 /* check if we are outside of the visible part of the virtual screen : */ 452 /* check if we are outside of the visible part of the virtual screen : */
487 if (sx + window_width <= 0 || sy + window_height <= 0 453 if (sx + parent_width <= 0 || sy + parent_height <= 0
488 || sx >= root_width || sy >= root_height) 454 || sx >= root_width || sy >= root_height)
489 return 0; 455 return 0;
490 456
491 while (sx < 0) sx += root_img->w; 457 while (sx < 0) sx += root_img->w;
492 while (sy < 0) sy += root_img->h; 458 while (sy < 0) sy += root_img->h;
493 459
494 rxvt_img *img = root_img->sub_rect (sx, sy, window_width, window_height); 460 rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height);
495 461
496 if (root_effects.need_blur ()) 462 if (root_effects.need_blur ())
497 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); 463 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
498 464
499 if (root_effects.need_tint ()) 465 if (root_effects.need_tint ())
505 delete bg_img; 471 delete bg_img;
506 bg_img = img; 472 bg_img = img;
507 473
508 return true; 474 return true;
509} 475}
510 476# endif /* BG_IMAGE_FROM_ROOT */
511void
512rxvt_term::bg_set_root_pixmap ()
513{
514 delete root_img;
515 root_img = rxvt_img::new_from_root (this);
516}
517# endif /* ENABLE_TRANSPARENCY */
518 477
519void 478void
520rxvt_term::bg_render () 479rxvt_term::bg_render ()
521{ 480{
522 if (bg_flags & BG_INHIBIT_RENDER) 481 if (bg_flags & BG_INHIBIT_RENDER)
523 return; 482 return;
524 483
525 bg_invalidate (); 484 delete bg_img;
526# if ENABLE_TRANSPARENCY 485 bg_img = 0;
527 if (bg_flags & BG_IS_TRANSPARENT) 486 bg_flags = 0;
528 { 487
529 /* we need to re-generate transparency pixmap in that case ! */ 488 if (!mapped)
489 return;
490
491# if BG_IMAGE_FROM_ROOT
492 if (root_img)
530 if (render_root_image ()) 493 if (render_root_image ())
531 bg_flags |= BG_IS_VALID; 494 bg_flags |= BG_IS_TRANSPARENT;
532 }
533# endif 495# endif
534 496
535# if BG_IMAGE_FROM_FILE 497# if BG_IMAGE_FROM_FILE
536 if (fimage.img) 498 if (fimage.img)
537 {
538 if (render_image (fimage)) 499 render_image (fimage);
539 bg_flags |= BG_IS_VALID;
540 }
541# endif 500# endif
542
543 if (!(bg_flags & BG_IS_VALID))
544 {
545 delete bg_img;
546 bg_img = 0;
547 }
548 501
549 scr_recolour (false); 502 scr_recolour (false);
550 bg_flags |= BG_NEEDS_REFRESH; 503 bg_flags |= BG_NEEDS_REFRESH;
551 504
552 bg_valid_since = ev::now (); 505 bg_valid_since = ev::now ();
553} 506}
554 507
555void 508void
556rxvt_term::bg_init () 509rxvt_term::bg_init ()
557{ 510{
511#if BG_IMAGE_FROM_ROOT
512 if (option (Opt_transparent))
513 {
514 if (rs [Rs_blurradius])
515 root_effects.set_blur (rs [Rs_blurradius]);
516
517 if (ISSET_PIXCOLOR (Color_tint))
518 root_effects.set_tint (pix_colors_focused [Color_tint]);
519
520 if (rs [Rs_shade])
521 root_effects.set_shade (rs [Rs_shade]);
522
523 rxvt_img::new_from_root (this)->replace (root_img);
524 XSelectInput (dpy, display->root, PropertyChangeMask);
525 rootwin_ev.start (display, display->root);
526 }
527#endif
528
558#if BG_IMAGE_FROM_FILE 529#if BG_IMAGE_FROM_FILE
559 if (rs[Rs_backgroundPixmap]) 530 if (rs[Rs_backgroundPixmap])
560 { 531 {
561 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 532 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
562 && !bg_window_position_sensitive ()) 533 if (!bg_window_position_sensitive ())
563 update_background (); 534 update_background ();
564 } 535 }
565#endif 536#endif
566} 537}
567 538

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines