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.242 by sf-exg, Mon Jun 11 14:56:33 2012 UTC

42 delete bg_img; 42 delete bg_img;
43 bg_img = 0; 43 bg_img = 0;
44} 44}
45 45
46bool 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}
59
60bool
61rxvt_term::bg_window_size_sensitive () 47rxvt_term::bg_window_size_sensitive ()
62{ 48{
63# if ENABLE_TRANSPARENCY 49# if ENABLE_TRANSPARENCY
64 if (bg_flags & BG_IS_TRANSPARENT) 50 if (bg_flags & BG_IS_TRANSPARENT)
65 return true; 51 return true;
105 return lerp (0, window_size - image_size, align); 91 return lerp (0, window_size - image_size, align);
106 else if (align > 100) 92 else if (align > 100)
107 return lerp (window_size - image_size, window_size, align - 100); 93 return lerp (window_size - image_size, window_size, align - 100);
108 else 94 else
109 return lerp (-image_size, 0, align + 100); 95 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} 96}
128 97
129static void 98static void
130parse_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)
131{ 100{
290void 259void
291rxvt_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)
292{ 261{
293 int image_width = image.img->w; 262 int image_width = image.img->w;
294 int image_height = image.img->h; 263 int image_height = image.img->h;
295 int target_width = szHint.width; 264 int parent_width = szHint.width;
296 int target_height = szHint.height; 265 int parent_height = szHint.height;
297 int h_scale = min (image.h_scale, 32767 * 100 / target_width); 266 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
298 int v_scale = min (image.v_scale, 32767 * 100 / target_height); 267 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
299 268
300 w = h_scale * target_width / 100; 269 w = h_scale * parent_width / 100;
301 h = v_scale * target_height / 100; 270 h = v_scale * parent_height / 100;
302 271
303 if (image.flags & IM_KEEP_ASPECT) 272 if (image.flags & IM_KEEP_ASPECT)
304 { 273 {
305 float scale = (float)w / image_width; 274 float scale = (float)w / image_width;
306 min_it (scale, (float)h / image_height); 275 min_it (scale, (float)h / image_height);
311 if (!w) w = image_width; 280 if (!w) w = image_width;
312 if (!h) h = image_height; 281 if (!h) h = image_height;
313 282
314 if (image.flags & IM_ROOT_ALIGN) 283 if (image.flags & IM_ROOT_ALIGN)
315 { 284 {
316 x = -target_x; 285 x = -parent_x;
317 y = -target_y; 286 y = -parent_y;
318 } 287 }
319 else 288 else
320 { 289 {
321 x = make_align_position (image.h_align, target_width, w); 290 x = make_align_position (image.h_align, parent_width, w);
322 y = make_align_position (image.v_align, target_height, h); 291 y = make_align_position (image.v_align, parent_height, h);
323 } 292 }
324} 293}
325 294
326bool 295bool
327rxvt_term::render_image (rxvt_image &image) 296rxvt_term::render_image (rxvt_image &image)
328{ 297{
329 int target_width = szHint.width; 298 int parent_width = szHint.width;
330 int target_height = szHint.height; 299 int parent_height = szHint.height;
331 300
332 int x = 0; 301 int x = 0;
333 int y = 0; 302 int y = 0;
334 int w = 0; 303 int w = 0;
335 int h = 0; 304 int h = 0;
336 305
337 get_image_geometry (image, w, h, x, y); 306 get_image_geometry (image, w, h, x, y);
338 307
339 if (!(image.flags & IM_ROOT_ALIGN) 308 if (!(image.flags & IM_ROOT_ALIGN)
340 && (x >= target_width 309 && (x >= parent_width
341 || y >= target_height 310 || y >= parent_height
342 || x + w <= 0 311 || x + w <= 0
343 || y + h <= 0)) 312 || y + h <= 0))
344 return false; 313 return false;
345 314
346 rxvt_img *img = image.img->scale (w, h); 315 rxvt_img *img = image.img->scale (w, h);
347 316
348 if (image.flags & IM_TILE) 317 if (image.flags & IM_TILE)
349 img->repeat_mode (RepeatNormal); 318 img->repeat_mode (RepeatNormal);
350 else 319 else
351 img->repeat_mode (RepeatNone); 320 img->repeat_mode (RepeatNone);
352 img->sub_rect (-x, -y, target_width, target_height)->replace (img); 321 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
353 322
354 if (bg_flags & BG_IS_VALID) 323 if (bg_flags & BG_IS_VALID)
355 { 324 {
356 double factor = image.alpha * 1. / 0xffff; 325 double factor = image.alpha * 1. / 0xffff;
357 bg_img->blend (img, factor)->replace (img); 326 bg_img->blend (img, factor)->replace (img);
376 v_align = defaultAlign; 345 v_align = defaultAlign;
377 346
378 img = 0; 347 img = 0;
379} 348}
380 349
381bool 350void
382rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 351rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
383{ 352{
384 if (!file || !*file) 353 if (!file || !*file)
385 return false; 354 return;
386 355
387 const char *p = strchr (file, ';'); 356 const char *p = strchr (file, ';');
388 357
389 if (p) 358 if (p)
390 { 359 {
393 memcpy (f, file, len); 362 memcpy (f, file, len);
394 f[len] = '\0'; 363 f[len] = '\0';
395 file = f; 364 file = f;
396 } 365 }
397 366
398 bool ret = set_file (s, file); 367 set_file (s, file);
399 alpha = 0x8000; 368 alpha = 0x8000;
400 if (ret)
401 set_geometry (p ? p + 1 : ""); 369 set_geometry (p ? p + 1 : "");
402 return ret;
403} 370}
404 371
405bool 372void
406rxvt_image::set_file (rxvt_screen *s, const char *file) 373rxvt_image::set_file (rxvt_screen *s, const char *file)
407{ 374{
375 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
408 delete img; 376 delete img;
409 img = rxvt_img::new_from_file (s, file); 377 img = img2;
410 return img != 0;
411} 378}
412 379
413# endif /* BG_IMAGE_FROM_FILE */ 380# endif /* BG_IMAGE_FROM_FILE */
414 381
415bool 382bool
488 * be always up-to-date, so let's use it : 455 * be always up-to-date, so let's use it :
489 */ 456 */
490 int screen = display->screen; 457 int screen = display->screen;
491 int root_width = DisplayWidth (dpy, screen); 458 int root_width = DisplayWidth (dpy, screen);
492 int root_height = DisplayHeight (dpy, screen); 459 int root_height = DisplayHeight (dpy, screen);
493 int window_width = szHint.width; 460 int parent_width = szHint.width;
494 int window_height = szHint.height; 461 int parent_height = szHint.height;
495 int sx, sy; 462 int sx, sy;
496 463
497 sx = target_x; 464 sx = parent_x;
498 sy = target_y; 465 sy = parent_y;
499 466
500 if (!root_img) 467 if (!root_img)
501 return false; 468 return false;
502 469
503 /* check if we are outside of the visible part of the virtual screen : */ 470 /* check if we are outside of the visible part of the virtual screen : */
504 if (sx + window_width <= 0 || sy + window_height <= 0 471 if (sx + parent_width <= 0 || sy + parent_height <= 0
505 || sx >= root_width || sy >= root_height) 472 || sx >= root_width || sy >= root_height)
506 return 0; 473 return 0;
507 474
508 while (sx < 0) sx += root_img->w; 475 while (sx < 0) sx += root_img->w;
509 while (sy < 0) sy += root_img->h; 476 while (sy < 0) sy += root_img->h;
510 477
511 rxvt_img *img = root_img->sub_rect (sx, sy, window_width, window_height); 478 rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height);
512 479
513 if (root_effects.need_blur ()) 480 if (root_effects.need_blur ())
514 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); 481 img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img);
515 482
516 if (root_effects.need_tint ()) 483 if (root_effects.need_tint ())
570} 537}
571 538
572void 539void
573rxvt_term::bg_init () 540rxvt_term::bg_init ()
574{ 541{
542#if ENABLE_TRANSPARENCY
543 if (option (Opt_transparent))
544 {
545 bg_set_transparent ();
546
547 if (rs [Rs_blurradius])
548 root_effects.set_blur (rs [Rs_blurradius]);
549
550 if (ISSET_PIXCOLOR (Color_tint))
551 root_effects.set_tint (pix_colors_focused [Color_tint]);
552
553 if (rs [Rs_shade])
554 root_effects.set_shade (rs [Rs_shade]);
555
556 bg_set_root_pixmap ();
557 XSelectInput (dpy, display->root, PropertyChangeMask);
558 rootwin_ev.start (display, display->root);
559 }
560#endif
561
575#if BG_IMAGE_FROM_FILE 562#if BG_IMAGE_FROM_FILE
576 if (rs[Rs_backgroundPixmap]) 563 if (rs[Rs_backgroundPixmap])
577 { 564 {
578 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 565 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
579 && !bg_window_position_sensitive ()) 566 if (!bg_window_position_sensitive ())
580 update_background (); 567 update_background ();
581 } 568 }
582#endif 569#endif
583} 570}
584 571

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines