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

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 {
354 double factor = image.alpha * 1. / 0xffff; 325 double factor = image.alpha * 1. / 0xffff;
355 bg_img->blend (img, factor)->replace (img); 326 bg_img->blend (img, factor)->replace (img);
374 v_align = defaultAlign; 345 v_align = defaultAlign;
375 346
376 img = 0; 347 img = 0;
377} 348}
378 349
379bool 350void
380rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 351rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
381{ 352{
382 if (!file || !*file) 353 if (!file || !*file)
383 return false; 354 return;
384 355
385 const char *p = strchr (file, ';'); 356 const char *p = strchr (file, ';');
386 357
387 if (p) 358 if (p)
388 { 359 {
391 memcpy (f, file, len); 362 memcpy (f, file, len);
392 f[len] = '\0'; 363 f[len] = '\0';
393 file = f; 364 file = f;
394 } 365 }
395 366
396 bool ret = set_file (s, file); 367 set_file (s, file);
397 alpha = 0x8000; 368 alpha = 0x8000;
398 if (ret)
399 set_geometry (p ? p + 1 : ""); 369 set_geometry (p ? p + 1 : "");
400 return ret;
401} 370}
402 371
403bool 372void
404rxvt_image::set_file (rxvt_screen *s, const char *file) 373rxvt_image::set_file (rxvt_screen *s, const char *file)
405{ 374{
375 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
406 delete img; 376 delete img;
407 img = rxvt_img::new_from_file (s, file); 377 img = img2;
408 return img != 0;
409} 378}
410 379
411# endif /* BG_IMAGE_FROM_FILE */ 380# endif /* BG_IMAGE_FROM_FILE */
412 381
413bool 382bool
486 * be always up-to-date, so let's use it : 455 * be always up-to-date, so let's use it :
487 */ 456 */
488 int screen = display->screen; 457 int screen = display->screen;
489 int root_width = DisplayWidth (dpy, screen); 458 int root_width = DisplayWidth (dpy, screen);
490 int root_height = DisplayHeight (dpy, screen); 459 int root_height = DisplayHeight (dpy, screen);
491 int window_width = szHint.width; 460 int parent_width = szHint.width;
492 int window_height = szHint.height; 461 int parent_height = szHint.height;
493 int sx, sy; 462 int sx, sy;
494 463
495 sx = target_x; 464 sx = parent_x;
496 sy = target_y; 465 sy = parent_y;
497 466
498 if (!root_img) 467 if (!root_img)
499 return false; 468 return false;
500 469
501 /* 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 : */
502 if (sx + window_width <= 0 || sy + window_height <= 0 471 if (sx + parent_width <= 0 || sy + parent_height <= 0
503 || sx >= root_width || sy >= root_height) 472 || sx >= root_width || sy >= root_height)
504 return 0; 473 return 0;
505 474
506 while (sx < 0) sx += root_img->w; 475 while (sx < 0) sx += root_img->w;
507 while (sy < 0) sy += root_img->h; 476 while (sy < 0) sy += root_img->h;
508 477
509 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);
510 479
511 if (root_effects.need_blur ()) 480 if (root_effects.need_blur ())
512 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);
513 482
514 if (root_effects.need_tint ()) 483 if (root_effects.need_tint ())
568} 537}
569 538
570void 539void
571rxvt_term::bg_init () 540rxvt_term::bg_init ()
572{ 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
573#if BG_IMAGE_FROM_FILE 562#if BG_IMAGE_FROM_FILE
574 if (rs[Rs_backgroundPixmap]) 563 if (rs[Rs_backgroundPixmap])
575 { 564 {
576 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 565 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
577 && !bg_window_position_sensitive ()) 566 if (!bg_window_position_sensitive ())
578 update_background (); 567 update_background ();
579 } 568 }
580#endif 569#endif
581} 570}
582 571

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines