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.237 by root, Sun Jun 10 15:01:14 2012 UTC vs.
Revision 1.254 by sf-exg, Sun Dec 30 20:28:31 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)
105 return lerp (0, window_size - image_size, align); 88 return lerp (0, window_size - image_size, align);
106 else if (align > 100) 89 else if (align > 100)
107 return lerp (window_size - image_size, window_size, align - 100); 90 return lerp (window_size - image_size, window_size, align - 100);
108 else 91 else
109 return lerp (-image_size, 0, align + 100); 92 return lerp (-image_size, 0, align + 100);
110}
111
112static inline int
113make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
114{
115 int src_pos = 0;
116 dst_pos = pos;
117 dst_size = size;
118 if (pos < 0)
119 {
120 src_pos = -pos;
121 dst_pos = 0;
122 dst_size += pos;
123 }
124
125 min_it (dst_size, target_size - dst_pos);
126 return src_pos;
127} 93}
128 94
129static void 95static void
130parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) 96parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags)
131{ 97{
290void 256void
291rxvt_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)
292{ 258{
293 int image_width = image.img->w; 259 int image_width = image.img->w;
294 int image_height = image.img->h; 260 int image_height = image.img->h;
295 int target_width = szHint.width; 261 int parent_width = szHint.width;
296 int target_height = szHint.height; 262 int parent_height = szHint.height;
297 int h_scale = min (image.h_scale, 32767 * 100 / target_width); 263 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
298 int v_scale = min (image.v_scale, 32767 * 100 / target_height); 264 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
299 265
300 w = h_scale * target_width / 100; 266 w = h_scale * parent_width / 100;
301 h = v_scale * target_height / 100; 267 h = v_scale * parent_height / 100;
302 268
303 if (image.flags & IM_KEEP_ASPECT) 269 if (image.flags & IM_KEEP_ASPECT)
304 { 270 {
305 float scale = (float)w / image_width; 271 float scale = (float)w / image_width;
306 min_it (scale, (float)h / image_height); 272 min_it (scale, (float)h / image_height);
311 if (!w) w = image_width; 277 if (!w) w = image_width;
312 if (!h) h = image_height; 278 if (!h) h = image_height;
313 279
314 if (image.flags & IM_ROOT_ALIGN) 280 if (image.flags & IM_ROOT_ALIGN)
315 { 281 {
316 x = -target_x; 282 x = -parent_x;
317 y = -target_y; 283 y = -parent_y;
318 } 284 }
319 else 285 else
320 { 286 {
321 x = make_align_position (image.h_align, target_width, w); 287 x = make_align_position (image.h_align, parent_width, w);
322 y = make_align_position (image.v_align, target_height, h); 288 y = make_align_position (image.v_align, parent_height, h);
323 } 289 }
324} 290}
325 291
326bool 292bool
327rxvt_term::render_image (rxvt_image &image) 293rxvt_term::render_image (rxvt_image &image)
328{ 294{
329 int target_width = szHint.width; 295 int parent_width = szHint.width;
330 int target_height = szHint.height; 296 int parent_height = szHint.height;
331 297
332 int x = 0; 298 int x = 0;
333 int y = 0; 299 int y = 0;
334 int w = 0; 300 int w = 0;
335 int h = 0; 301 int h = 0;
336 302
337 get_image_geometry (image, w, h, x, y); 303 get_image_geometry (image, w, h, x, y);
338 304
339 if (!(image.flags & IM_ROOT_ALIGN) 305 if (!(image.flags & IM_ROOT_ALIGN)
340 && (x >= target_width 306 && (x >= parent_width
341 || y >= target_height 307 || y >= parent_height
342 || x + w <= 0 308 || x + w <= 0
343 || y + h <= 0)) 309 || y + h <= 0))
344 return false; 310 return false;
345 311
346 rxvt_img *img = image.img->scale (w, h); 312 rxvt_img *img = image.img->scale (w, h);
347 313
348 if (image.flags & IM_TILE) 314 if (image.flags & IM_TILE)
349 img->repeat_mode (RepeatNormal); 315 img->repeat_mode (RepeatNormal);
350 else 316 else
351 img->repeat_mode (RepeatNone); 317 img->repeat_mode (RepeatNone);
352 img->sub_rect (-x, -y, target_width, target_height)->replace (img); 318 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
353 319
354 if (bg_flags & BG_IS_VALID) 320 if (bg_img)
355 { 321 img->draw (bg_img, PictOpOver, image.alpha * 1. / 0xffff);
356 double factor = image.alpha * 1. / 0xffff;
357 bg_img->blend (img, factor)->replace (img);
358 }
359 322
360 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 323 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
361 img->convert_format (format, pix_colors [Color_bg])->replace (img); 324 img->convert_format (format, pix_colors [Color_bg])->replace (img);
362 325
363 delete bg_img; 326 delete bg_img;
376 v_align = defaultAlign; 339 v_align = defaultAlign;
377 340
378 img = 0; 341 img = 0;
379} 342}
380 343
381bool 344void
382rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 345rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
383{ 346{
384 if (!file || !*file) 347 if (!file || !*file)
385 return false; 348 return;
386 349
387 const char *p = strchr (file, ';'); 350 const char *p = strchr (file, ';');
388 351
389 if (p) 352 if (p)
390 { 353 {
393 memcpy (f, file, len); 356 memcpy (f, file, len);
394 f[len] = '\0'; 357 f[len] = '\0';
395 file = f; 358 file = f;
396 } 359 }
397 360
398 bool ret = set_file (s, file); 361 set_file (s, file);
399 alpha = 0x8000; 362 alpha = 0x8000;
400 if (ret)
401 set_geometry (p ? p + 1 : ""); 363 set_geometry (p ? p + 1 : "");
402 return ret;
403} 364}
404 365
405bool 366void
406rxvt_image::set_file (rxvt_screen *s, const char *file) 367rxvt_image::set_file (rxvt_screen *s, const char *file)
407{ 368{
369 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
408 delete img; 370 delete img;
409 img = rxvt_img::new_from_file (s, file); 371 img = img2;
410 return img != 0;
411} 372}
412 373
413# endif /* BG_IMAGE_FROM_FILE */ 374# endif /* BG_IMAGE_FROM_FILE */
414 375
415bool 376bool
473 } 434 }
474 435
475 return false; 436 return false;
476} 437}
477 438
478# if ENABLE_TRANSPARENCY 439# if BG_IMAGE_FROM_ROOT
479/* 440/*
480 * 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
481 * 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
482 * our window. 443 * our window.
483 */ 444 */
488 * be always up-to-date, so let's use it : 449 * be always up-to-date, so let's use it :
489 */ 450 */
490 int screen = display->screen; 451 int screen = display->screen;
491 int root_width = DisplayWidth (dpy, screen); 452 int root_width = DisplayWidth (dpy, screen);
492 int root_height = DisplayHeight (dpy, screen); 453 int root_height = DisplayHeight (dpy, screen);
493 int window_width = szHint.width; 454 int parent_width = szHint.width;
494 int window_height = szHint.height; 455 int parent_height = szHint.height;
495 int sx, sy; 456 int sx, sy;
496 457
497 sx = target_x; 458 sx = parent_x;
498 sy = target_y; 459 sy = parent_y;
499
500 if (!root_img)
501 return false;
502 460
503 /* check if we are outside of the visible part of the virtual screen : */ 461 /* check if we are outside of the visible part of the virtual screen : */
504 if (sx + window_width <= 0 || sy + window_height <= 0 462 if (sx + parent_width <= 0 || sy + parent_height <= 0
505 || sx >= root_width || sy >= root_height) 463 || sx >= root_width || sy >= root_height)
506 return 0; 464 return 0;
507 465
508 while (sx < 0) sx += root_img->w; 466 while (sx < 0) sx += root_img->w;
509 while (sy < 0) sy += root_img->h; 467 while (sy < 0) sy += root_img->h;
510 468
511 rxvt_img *img = root_img->sub_rect (sx, sy, window_width, window_height); 469 rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height);
512 470
513 if (root_effects.need_blur ()) 471 if (root_effects.need_blur ())
514 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); 472 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
515 473
516 if (root_effects.need_tint ()) 474 if (root_effects.need_tint ())
529rxvt_term::bg_set_root_pixmap () 487rxvt_term::bg_set_root_pixmap ()
530{ 488{
531 delete root_img; 489 delete root_img;
532 root_img = rxvt_img::new_from_root (this); 490 root_img = rxvt_img::new_from_root (this);
533} 491}
534# endif /* ENABLE_TRANSPARENCY */ 492# endif /* BG_IMAGE_FROM_ROOT */
535 493
536void 494void
537rxvt_term::bg_render () 495rxvt_term::bg_render ()
538{ 496{
539 if (bg_flags & BG_INHIBIT_RENDER) 497 if (bg_flags & BG_INHIBIT_RENDER)
540 return; 498 return;
541 499
542 bg_invalidate (); 500 delete bg_img;
543# if ENABLE_TRANSPARENCY 501 bg_img = 0;
544 if (bg_flags & BG_IS_TRANSPARENT) 502 bg_flags = 0;
545 { 503
546 /* we need to re-generate transparency pixmap in that case ! */ 504 if (!mapped)
505 return;
506
507# if BG_IMAGE_FROM_ROOT
508 if (root_img)
547 if (render_root_image ()) 509 if (render_root_image ())
548 bg_flags |= BG_IS_VALID; 510 bg_flags |= BG_IS_TRANSPARENT;
549 }
550# endif 511# endif
551 512
552# if BG_IMAGE_FROM_FILE 513# if BG_IMAGE_FROM_FILE
553 if (fimage.img) 514 if (fimage.img)
554 {
555 if (render_image (fimage)) 515 render_image (fimage);
556 bg_flags |= BG_IS_VALID;
557 }
558# endif 516# endif
559
560 if (!(bg_flags & BG_IS_VALID))
561 {
562 delete bg_img;
563 bg_img = 0;
564 }
565 517
566 scr_recolour (false); 518 scr_recolour (false);
567 bg_flags |= BG_NEEDS_REFRESH; 519 bg_flags |= BG_NEEDS_REFRESH;
568 520
569 bg_valid_since = ev::now (); 521 bg_valid_since = ev::now ();
570} 522}
571 523
572void 524void
573rxvt_term::bg_init () 525rxvt_term::bg_init ()
574{ 526{
527#if BG_IMAGE_FROM_ROOT
528 if (option (Opt_transparent))
529 {
530 if (rs [Rs_blurradius])
531 root_effects.set_blur (rs [Rs_blurradius]);
532
533 if (ISSET_PIXCOLOR (Color_tint))
534 root_effects.set_tint (pix_colors_focused [Color_tint]);
535
536 if (rs [Rs_shade])
537 root_effects.set_shade (rs [Rs_shade]);
538
539 bg_set_root_pixmap ();
540 XSelectInput (dpy, display->root, PropertyChangeMask);
541 rootwin_ev.start (display, display->root);
542 }
543#endif
544
575#if BG_IMAGE_FROM_FILE 545#if BG_IMAGE_FROM_FILE
576 if (rs[Rs_backgroundPixmap]) 546 if (rs[Rs_backgroundPixmap])
577 { 547 {
578 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 548 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
579 && !bg_window_position_sensitive ()) 549 if (!bg_window_position_sensitive ())
580 update_background (); 550 update_background ();
581 } 551 }
582#endif 552#endif
583} 553}
584 554

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines