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.236 by sf-exg, Sun Jun 10 13:07:56 2012 UTC vs.
Revision 1.244 by root, Sun Jun 17 21:58:18 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>
30void 30void
31rxvt_term::bg_destroy () 31rxvt_term::bg_destroy ()
32{ 32{
33# if ENABLE_TRANSPARENCY 33# if ENABLE_TRANSPARENCY
34 delete root_img; 34 delete root_img;
35 root_img = 0;
35# endif 36# endif
36 37
37# if BG_IMAGE_FROM_FILE 38# if BG_IMAGE_FROM_FILE
38 fimage.destroy (); 39 fimage.destroy ();
39# endif 40# endif
40 41
41 delete bg_img; 42 delete bg_img;
42} 43 bg_img = 0;
43
44bool
45rxvt_term::bg_set_position (int x, int y)
46{
47
48 if (target_x != x
49 || target_y != y)
50 {
51 target_x = x;
52 target_y = y;
53 return true;
54 }
55 return false;
56} 44}
57 45
58bool 46bool
59rxvt_term::bg_window_size_sensitive () 47rxvt_term::bg_window_size_sensitive ()
60{ 48{
103 return lerp (0, window_size - image_size, align); 91 return lerp (0, window_size - image_size, align);
104 else if (align > 100) 92 else if (align > 100)
105 return lerp (window_size - image_size, window_size, align - 100); 93 return lerp (window_size - image_size, window_size, align - 100);
106 else 94 else
107 return lerp (-image_size, 0, align + 100); 95 return lerp (-image_size, 0, align + 100);
108}
109
110static inline int
111make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size)
112{
113 int src_pos = 0;
114 dst_pos = pos;
115 dst_size = size;
116 if (pos < 0)
117 {
118 src_pos = -pos;
119 dst_pos = 0;
120 dst_size += pos;
121 }
122
123 min_it (dst_size, target_size - dst_pos);
124 return src_pos;
125} 96}
126 97
127static void 98static void
128parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) 99parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags)
129{ 100{
288void 259void
289rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) 260rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y)
290{ 261{
291 int image_width = image.img->w; 262 int image_width = image.img->w;
292 int image_height = image.img->h; 263 int image_height = image.img->h;
293 int target_width = szHint.width; 264 int parent_width = szHint.width;
294 int target_height = szHint.height; 265 int parent_height = szHint.height;
295 int h_scale = min (image.h_scale, 32767 * 100 / target_width); 266 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
296 int v_scale = min (image.v_scale, 32767 * 100 / target_height); 267 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
297 268
298 w = h_scale * target_width / 100; 269 w = h_scale * parent_width / 100;
299 h = v_scale * target_height / 100; 270 h = v_scale * parent_height / 100;
300 271
301 if (image.flags & IM_KEEP_ASPECT) 272 if (image.flags & IM_KEEP_ASPECT)
302 { 273 {
303 float scale = (float)w / image_width; 274 float scale = (float)w / image_width;
304 min_it (scale, (float)h / image_height); 275 min_it (scale, (float)h / image_height);
309 if (!w) w = image_width; 280 if (!w) w = image_width;
310 if (!h) h = image_height; 281 if (!h) h = image_height;
311 282
312 if (image.flags & IM_ROOT_ALIGN) 283 if (image.flags & IM_ROOT_ALIGN)
313 { 284 {
314 x = -target_x; 285 x = -parent_x;
315 y = -target_y; 286 y = -parent_y;
316 } 287 }
317 else 288 else
318 { 289 {
319 x = make_align_position (image.h_align, target_width, w); 290 x = make_align_position (image.h_align, parent_width, w);
320 y = make_align_position (image.v_align, target_height, h); 291 y = make_align_position (image.v_align, parent_height, h);
321 } 292 }
322} 293}
323 294
324bool 295bool
325rxvt_term::render_image (rxvt_image &image) 296rxvt_term::render_image (rxvt_image &image)
326{ 297{
327 int target_width = szHint.width; 298 int parent_width = szHint.width;
328 int target_height = szHint.height; 299 int parent_height = szHint.height;
329 300
330 int x = 0; 301 int x = 0;
331 int y = 0; 302 int y = 0;
332 int w = 0; 303 int w = 0;
333 int h = 0; 304 int h = 0;
334 305
335 get_image_geometry (image, w, h, x, y); 306 get_image_geometry (image, w, h, x, y);
336 307
337 if (!(image.flags & IM_ROOT_ALIGN) 308 if (!(image.flags & IM_ROOT_ALIGN)
338 && (x >= target_width 309 && (x >= parent_width
339 || y >= target_height 310 || y >= parent_height
340 || x + w <= 0 311 || x + w <= 0
341 || y + h <= 0)) 312 || y + h <= 0))
342 return false; 313 return false;
343 314
344 rxvt_img *img = image.img->scale (w, h); 315 rxvt_img *img = image.img->scale (w, h);
345 316
346 if (image.flags & IM_TILE) 317 if (image.flags & IM_TILE)
347 img->repeat_mode (RepeatNormal); 318 img->repeat_mode (RepeatNormal);
348 else 319 else
349 img->repeat_mode (RepeatNone); 320 img->repeat_mode (RepeatNone);
350 img->sub_rect (-x, -y, target_width, target_height)->replace (img); 321 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
351 322
352 if (bg_flags & BG_IS_VALID) 323 if (bg_flags & BG_IS_VALID)
353 { 324 bg_img->draw (img, PictOpOver, image.alpha * 1. / 0xffff);
354 double factor = image.alpha * 1. / 0xffff;
355 bg_img->blend (img, factor)->replace (img);
356 }
357 325
358 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); 326 XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual);
359 img->convert_format (format, pix_colors [Color_bg])->replace (img); 327 img->convert_format (format, pix_colors [Color_bg])->replace (img);
360 328
361 delete bg_img; 329 delete bg_img;
374 v_align = defaultAlign; 342 v_align = defaultAlign;
375 343
376 img = 0; 344 img = 0;
377} 345}
378 346
379bool 347void
380rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 348rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
381{ 349{
382 if (!file || !*file) 350 if (!file || !*file)
383 return false; 351 return;
384 352
385 const char *p = strchr (file, ';'); 353 const char *p = strchr (file, ';');
386 354
387 if (p) 355 if (p)
388 { 356 {
391 memcpy (f, file, len); 359 memcpy (f, file, len);
392 f[len] = '\0'; 360 f[len] = '\0';
393 file = f; 361 file = f;
394 } 362 }
395 363
396 bool ret = set_file (s, file); 364 set_file (s, file);
397 alpha = 0x8000; 365 alpha = 0x8000;
398 if (ret)
399 set_geometry (p ? p + 1 : ""); 366 set_geometry (p ? p + 1 : "");
400 return ret;
401} 367}
402 368
403bool 369void
404rxvt_image::set_file (rxvt_screen *s, const char *file) 370rxvt_image::set_file (rxvt_screen *s, const char *file)
405{ 371{
372 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
406 delete img; 373 delete img;
407 img = rxvt_img::new_from_file (s, file); 374 img = img2;
408 return img != 0;
409} 375}
410 376
411# endif /* BG_IMAGE_FROM_FILE */ 377# endif /* BG_IMAGE_FROM_FILE */
412 378
413bool 379bool
486 * be always up-to-date, so let's use it : 452 * be always up-to-date, so let's use it :
487 */ 453 */
488 int screen = display->screen; 454 int screen = display->screen;
489 int root_width = DisplayWidth (dpy, screen); 455 int root_width = DisplayWidth (dpy, screen);
490 int root_height = DisplayHeight (dpy, screen); 456 int root_height = DisplayHeight (dpy, screen);
491 int window_width = szHint.width; 457 int parent_width = szHint.width;
492 int window_height = szHint.height; 458 int parent_height = szHint.height;
493 int sx, sy; 459 int sx, sy;
494 460
495 sx = target_x; 461 sx = parent_x;
496 sy = target_y; 462 sy = parent_y;
497 463
498 if (!root_img) 464 if (!root_img)
499 return false; 465 return false;
500 466
501 /* check if we are outside of the visible part of the virtual screen : */ 467 /* check if we are outside of the visible part of the virtual screen : */
502 if (sx + window_width <= 0 || sy + window_height <= 0 468 if (sx + parent_width <= 0 || sy + parent_height <= 0
503 || sx >= root_width || sy >= root_height) 469 || sx >= root_width || sy >= root_height)
504 return 0; 470 return 0;
505 471
506 while (sx < 0) sx += root_img->w; 472 while (sx < 0) sx += root_img->w;
507 while (sy < 0) sy += root_img->h; 473 while (sy < 0) sy += root_img->h;
508 474
509 rxvt_img *img = root_img->sub_rect (sx, sy, window_width, window_height); 475 rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height);
510 476
511 if (root_effects.need_blur ()) 477 if (root_effects.need_blur ())
512 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); 478 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
513 479
514 if (root_effects.need_tint ()) 480 if (root_effects.need_tint ())
568} 534}
569 535
570void 536void
571rxvt_term::bg_init () 537rxvt_term::bg_init ()
572{ 538{
539#if ENABLE_TRANSPARENCY
540 if (option (Opt_transparent))
541 {
542 bg_set_transparent ();
543
544 if (rs [Rs_blurradius])
545 root_effects.set_blur (rs [Rs_blurradius]);
546
547 if (ISSET_PIXCOLOR (Color_tint))
548 root_effects.set_tint (pix_colors_focused [Color_tint]);
549
550 if (rs [Rs_shade])
551 root_effects.set_shade (rs [Rs_shade]);
552
553 bg_set_root_pixmap ();
554 XSelectInput (dpy, display->root, PropertyChangeMask);
555 rootwin_ev.start (display, display->root);
556 }
557#endif
558
573#if BG_IMAGE_FROM_FILE 559#if BG_IMAGE_FROM_FILE
574 if (rs[Rs_backgroundPixmap]) 560 if (rs[Rs_backgroundPixmap])
575 { 561 {
576 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 562 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
577 && !bg_window_position_sensitive ()) 563 if (!bg_window_position_sensitive ())
578 update_background (); 564 update_background ();
579 } 565 }
580#endif 566#endif
581} 567}
582 568

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines