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.240 by sf-exg, Mon Jun 11 13:23:01 2012 UTC vs.
Revision 1.258 by root, Thu May 22 18:54:32 2014 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>
8 * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it> 8 * Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it>
9 * 9 *
10 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or 12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version. 13 * (at your option) any later version.
14 * 14 *
15 * This program is distributed in the hope that it will be useful, 15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 (root_img)
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 (root_img)
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)
255 252
256 return changed; 253 return changed;
257} 254}
258 255
259void 256void
260rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) 257rxvt_term::render_image (rxvt_image &image)
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 parent_width = szHint.width; 261 int parent_width = szHint.width;
265 int parent_height = szHint.height; 262 int parent_height = szHint.height;
266 int h_scale = min (image.h_scale, 32767 * 100 / parent_width); 263 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
267 int v_scale = min (image.v_scale, 32767 * 100 / parent_height); 264 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
268 265
266 int w;
267 int h;
268 int x;
269 int y;
270
269 w = h_scale * parent_width / 100; 271 w = h_scale * parent_width / 100;
270 h = v_scale * parent_height / 100; 272 h = v_scale * parent_height / 100;
271 273
272 if (image.flags & IM_KEEP_ASPECT) 274 if (image.flags & IM_KEEP_ASPECT)
273 { 275 {
288 else 290 else
289 { 291 {
290 x = make_align_position (image.h_align, parent_width, w); 292 x = make_align_position (image.h_align, parent_width, w);
291 y = make_align_position (image.v_align, parent_height, h); 293 y = make_align_position (image.v_align, parent_height, h);
292 } 294 }
293}
294
295bool
296rxvt_term::render_image (rxvt_image &image)
297{
298 int parent_width = szHint.width;
299 int parent_height = szHint.height;
300
301 int x = 0;
302 int y = 0;
303 int w = 0;
304 int h = 0;
305
306 get_image_geometry (image, w, h, x, y);
307 295
308 if (!(image.flags & IM_ROOT_ALIGN) 296 if (!(image.flags & IM_ROOT_ALIGN)
309 && (x >= parent_width 297 && (x >= parent_width
310 || y >= parent_height 298 || y >= parent_height
311 || x + w <= 0 299 || x + w <= 0
312 || y + h <= 0)) 300 || y + h <= 0))
313 return false; 301 return;
314 302
315 rxvt_img *img = image.img->scale (w, h); 303 rxvt_img *img = image.img->scale (w, h);
316 304
317 if (image.flags & IM_TILE) 305 if (image.flags & IM_TILE)
318 img->repeat_mode (RepeatNormal); 306 img->repeat_mode (RepeatNormal);
319 else 307 else
320 img->repeat_mode (RepeatNone); 308 img->repeat_mode (RepeatNone);
321 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img); 309 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
322 310
323 if (bg_flags & BG_IS_VALID) 311 if (bg_img)
324 { 312 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 313
329 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 314 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
330 img->convert_format (format, pix_colors [Color_bg])->replace (img); 315 img->convert_format (format, pix_colors [Color_bg])->replace (img);
331 316
332 delete bg_img; 317 delete bg_img;
333 bg_img = img; 318 bg_img = img;
334
335 return true;
336} 319}
337 320
338rxvt_image::rxvt_image () 321rxvt_image::rxvt_image ()
339{ 322{
340 alpha = 0xffff; 323 alpha = 0xffff;
345 v_align = defaultAlign; 328 v_align = defaultAlign;
346 329
347 img = 0; 330 img = 0;
348} 331}
349 332
350bool 333void
351rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 334rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
352{ 335{
353 if (!file || !*file) 336 if (!file || !*file)
354 return false; 337 return;
355 338
356 const char *p = strchr (file, ';'); 339 const char *p = strchr (file, ';');
357 340
358 if (p) 341 if (p)
359 { 342 {
362 memcpy (f, file, len); 345 memcpy (f, file, len);
363 f[len] = '\0'; 346 f[len] = '\0';
364 file = f; 347 file = f;
365 } 348 }
366 349
367 bool ret = set_file (s, file); 350 set_file (s, file);
368 alpha = 0x8000; 351 alpha = 0x8000;
369 if (ret)
370 set_geometry (p ? p + 1 : ""); 352 set_geometry (p ? p + 1 : "");
371 return ret;
372} 353}
373 354
374bool 355void
375rxvt_image::set_file (rxvt_screen *s, const char *file) 356rxvt_image::set_file (rxvt_screen *s, const char *file)
376{ 357{
358 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
377 delete img; 359 delete img;
378 img = rxvt_img::new_from_file (s, file); 360 img = img2;
379 return img != 0;
380} 361}
381 362
382# endif /* BG_IMAGE_FROM_FILE */ 363# endif /* BG_IMAGE_FROM_FILE */
383 364
384bool 365bool
442 } 423 }
443 424
444 return false; 425 return false;
445} 426}
446 427
447# if ENABLE_TRANSPARENCY 428# if BG_IMAGE_FROM_ROOT
448/* 429/*
449 * 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
450 * 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
451 * our window. 432 * our window.
452 */ 433 */
453bool 434void
454rxvt_term::render_root_image () 435rxvt_term::render_root_image ()
455{ 436{
456 /* 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
457 * be always up-to-date, so let's use it : 438 * be always up-to-date, so let's use it :
458 */ 439 */
464 int sx, sy; 445 int sx, sy;
465 446
466 sx = parent_x; 447 sx = parent_x;
467 sy = parent_y; 448 sy = parent_y;
468 449
469 if (!root_img)
470 return false;
471
472 /* 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 : */
473 if (sx + parent_width <= 0 || sy + parent_height <= 0 451 if (sx + parent_width <= 0 || sy + parent_height <= 0
474 || sx >= root_width || sy >= root_height) 452 || sx >= root_width || sy >= root_height)
475 return 0; 453 return;
476 454
477 while (sx < 0) sx += root_img->w; 455 while (sx < 0) sx += root_img->w;
478 while (sy < 0) sy += root_img->h; 456 while (sy < 0) sy += root_img->h;
479 457
480 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);
481 459
482 if (root_effects.need_blur ()) 460 if (root_effects.need_blur ())
483 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); 461 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
484 462
485 if (root_effects.need_tint ()) 463 if (root_effects.need_tint ())
486 tint_image (img, root_effects.tint, root_effects.tint_set, root_effects.shade); 464 {
465 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
466
467 if (root_effects.tint_set)
468 root_effects.tint.get (c);
469 rxvt_img::nv factor = root_effects.shade / 100. - 1.;
470 img->shade (factor, c)->replace (img);
471 }
487 472
488 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 473 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
489 img->convert_format (format, pix_colors [Color_bg])->replace (img); 474 img->convert_format (format, pix_colors [Color_bg])->replace (img);
490 475
491 delete bg_img; 476 delete bg_img;
492 bg_img = img; 477 bg_img = img;
493
494 return true;
495} 478}
496 479# endif /* BG_IMAGE_FROM_ROOT */
497void
498rxvt_term::bg_set_root_pixmap ()
499{
500 delete root_img;
501 root_img = rxvt_img::new_from_root (this);
502}
503# endif /* ENABLE_TRANSPARENCY */
504 480
505void 481void
506rxvt_term::bg_render () 482rxvt_term::bg_render ()
507{ 483{
508 if (bg_flags & BG_INHIBIT_RENDER) 484 if (bg_flags & BG_INHIBIT_RENDER)
509 return; 485 return;
510 486
511 bg_invalidate (); 487 delete bg_img;
512# if ENABLE_TRANSPARENCY 488 bg_img = 0;
513 if (bg_flags & BG_IS_TRANSPARENT) 489 bg_flags = 0;
490
491 if (!mapped)
492 return;
493
494# if BG_IMAGE_FROM_ROOT
495 if (root_img)
514 { 496 {
515 /* we need to re-generate transparency pixmap in that case ! */
516 if (render_root_image ()) 497 render_root_image ();
517 bg_flags |= BG_IS_VALID; 498 bg_flags |= BG_IS_TRANSPARENT;
518 } 499 }
519# endif 500# endif
520 501
521# if BG_IMAGE_FROM_FILE 502# if BG_IMAGE_FROM_FILE
522 if (fimage.img) 503 if (fimage.img)
523 {
524 if (render_image (fimage)) 504 render_image (fimage);
525 bg_flags |= BG_IS_VALID;
526 }
527# endif 505# endif
528
529 if (!(bg_flags & BG_IS_VALID))
530 {
531 delete bg_img;
532 bg_img = 0;
533 }
534 506
535 scr_recolour (false); 507 scr_recolour (false);
536 bg_flags |= BG_NEEDS_REFRESH; 508 bg_flags |= BG_NEEDS_REFRESH;
537 509
538 bg_valid_since = ev::now (); 510 bg_valid_since = ev::now ();
539} 511}
540 512
541void 513void
542rxvt_term::bg_init () 514rxvt_term::bg_init ()
543{ 515{
516#if BG_IMAGE_FROM_ROOT
517 if (option (Opt_transparent))
518 {
519 if (rs [Rs_blurradius])
520 root_effects.set_blur (rs [Rs_blurradius]);
521
522 if (ISSET_PIXCOLOR (Color_tint))
523 root_effects.set_tint (pix_colors_focused [Color_tint]);
524
525 if (rs [Rs_shade])
526 root_effects.set_shade (rs [Rs_shade]);
527
528 rxvt_img::new_from_root (this)->replace (root_img);
529 XSelectInput (dpy, display->root, PropertyChangeMask);
530 rootwin_ev.start (display, display->root);
531 }
532#endif
533
544#if BG_IMAGE_FROM_FILE 534#if BG_IMAGE_FROM_FILE
545 if (rs[Rs_backgroundPixmap]) 535 if (rs[Rs_backgroundPixmap])
546 { 536 {
547 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 537 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
548 && !bg_window_position_sensitive ()) 538 if (!bg_window_position_sensitive ())
549 update_background (); 539 update_background ();
550 } 540 }
551#endif 541#endif
552} 542}
553 543
554void
555rxvt_term::tint_image (rxvt_img *img, rxvt_color &tint, bool tint_set, int shade)
556{
557 rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC);
558
559 if (tint_set)
560 tint.get (c);
561
562 if (shade > 100)
563 {
564 c.r = c.r * (200 - shade) / 100;
565 c.g = c.g * (200 - shade) / 100;
566 c.b = c.b * (200 - shade) / 100;
567 }
568 else
569 {
570 c.r = c.r * shade / 100;
571 c.g = c.g * shade / 100;
572 c.b = c.b * shade / 100;
573 }
574
575 img->contrast (c.r, c.g, c.b, c.a);
576
577 if (shade > 100)
578 {
579 c.a = 0xffff;
580 c.r =
581 c.g =
582 c.b = 0xffff * (shade - 100) / 100;
583 img->brightness (c.r, c.g, c.b, c.a);
584 }
585}
586
587#endif /* HAVE_BG_PIXMAP */ 544#endif /* HAVE_BG_PIXMAP */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines