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.239 by sf-exg, Sun Jun 10 16:00:25 2012 UTC vs.
Revision 1.243 by sf-exg, Sun Jun 17 17:06:47 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>
259void 259void
260rxvt_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)
261{ 261{
262 int image_width = image.img->w; 262 int image_width = image.img->w;
263 int image_height = image.img->h; 263 int image_height = image.img->h;
264 int target_width = szHint.width; 264 int parent_width = szHint.width;
265 int target_height = szHint.height; 265 int parent_height = szHint.height;
266 int h_scale = min (image.h_scale, 32767 * 100 / target_width); 266 int h_scale = min (image.h_scale, 32767 * 100 / parent_width);
267 int v_scale = min (image.v_scale, 32767 * 100 / target_height); 267 int v_scale = min (image.v_scale, 32767 * 100 / parent_height);
268 268
269 w = h_scale * target_width / 100; 269 w = h_scale * parent_width / 100;
270 h = v_scale * target_height / 100; 270 h = v_scale * parent_height / 100;
271 271
272 if (image.flags & IM_KEEP_ASPECT) 272 if (image.flags & IM_KEEP_ASPECT)
273 { 273 {
274 float scale = (float)w / image_width; 274 float scale = (float)w / image_width;
275 min_it (scale, (float)h / image_height); 275 min_it (scale, (float)h / image_height);
285 x = -parent_x; 285 x = -parent_x;
286 y = -parent_y; 286 y = -parent_y;
287 } 287 }
288 else 288 else
289 { 289 {
290 x = make_align_position (image.h_align, target_width, w); 290 x = make_align_position (image.h_align, parent_width, w);
291 y = make_align_position (image.v_align, target_height, h); 291 y = make_align_position (image.v_align, parent_height, h);
292 } 292 }
293} 293}
294 294
295bool 295bool
296rxvt_term::render_image (rxvt_image &image) 296rxvt_term::render_image (rxvt_image &image)
297{ 297{
298 int target_width = szHint.width; 298 int parent_width = szHint.width;
299 int target_height = szHint.height; 299 int parent_height = szHint.height;
300 300
301 int x = 0; 301 int x = 0;
302 int y = 0; 302 int y = 0;
303 int w = 0; 303 int w = 0;
304 int h = 0; 304 int h = 0;
305 305
306 get_image_geometry (image, w, h, x, y); 306 get_image_geometry (image, w, h, x, y);
307 307
308 if (!(image.flags & IM_ROOT_ALIGN) 308 if (!(image.flags & IM_ROOT_ALIGN)
309 && (x >= target_width 309 && (x >= parent_width
310 || y >= target_height 310 || y >= parent_height
311 || x + w <= 0 311 || x + w <= 0
312 || y + h <= 0)) 312 || y + h <= 0))
313 return false; 313 return false;
314 314
315 rxvt_img *img = image.img->scale (w, h); 315 rxvt_img *img = image.img->scale (w, h);
316 316
317 if (image.flags & IM_TILE) 317 if (image.flags & IM_TILE)
318 img->repeat_mode (RepeatNormal); 318 img->repeat_mode (RepeatNormal);
319 else 319 else
320 img->repeat_mode (RepeatNone); 320 img->repeat_mode (RepeatNone);
321 img->sub_rect (-x, -y, target_width, target_height)->replace (img); 321 img->sub_rect (-x, -y, parent_width, parent_height)->replace (img);
322 322
323 if (bg_flags & BG_IS_VALID) 323 if (bg_flags & BG_IS_VALID)
324 { 324 {
325 double factor = image.alpha * 1. / 0xffff; 325 double factor = image.alpha * 1. / 0xffff;
326 bg_img->blend (img, factor)->replace (img); 326 bg_img->blend (img, factor)->replace (img);
345 v_align = defaultAlign; 345 v_align = defaultAlign;
346 346
347 img = 0; 347 img = 0;
348} 348}
349 349
350bool 350void
351rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) 351rxvt_image::set_file_geometry (rxvt_screen *s, const char *file)
352{ 352{
353 if (!file || !*file) 353 if (!file || !*file)
354 return false; 354 return;
355 355
356 const char *p = strchr (file, ';'); 356 const char *p = strchr (file, ';');
357 357
358 if (p) 358 if (p)
359 { 359 {
362 memcpy (f, file, len); 362 memcpy (f, file, len);
363 f[len] = '\0'; 363 f[len] = '\0';
364 file = f; 364 file = f;
365 } 365 }
366 366
367 bool ret = set_file (s, file); 367 set_file (s, file);
368 alpha = 0x8000; 368 alpha = 0x8000;
369 if (ret)
370 set_geometry (p ? p + 1 : ""); 369 set_geometry (p ? p + 1 : "");
371 return ret;
372} 370}
373 371
374bool 372void
375rxvt_image::set_file (rxvt_screen *s, const char *file) 373rxvt_image::set_file (rxvt_screen *s, const char *file)
376{ 374{
375 rxvt_img *img2 = rxvt_img::new_from_file (s, file);
377 delete img; 376 delete img;
378 img = rxvt_img::new_from_file (s, file); 377 img = img2;
379 return img != 0;
380} 378}
381 379
382# endif /* BG_IMAGE_FROM_FILE */ 380# endif /* BG_IMAGE_FROM_FILE */
383 381
384bool 382bool
457 * be always up-to-date, so let's use it : 455 * be always up-to-date, so let's use it :
458 */ 456 */
459 int screen = display->screen; 457 int screen = display->screen;
460 int root_width = DisplayWidth (dpy, screen); 458 int root_width = DisplayWidth (dpy, screen);
461 int root_height = DisplayHeight (dpy, screen); 459 int root_height = DisplayHeight (dpy, screen);
462 int window_width = szHint.width; 460 int parent_width = szHint.width;
463 int window_height = szHint.height; 461 int parent_height = szHint.height;
464 int sx, sy; 462 int sx, sy;
465 463
466 sx = parent_x; 464 sx = parent_x;
467 sy = parent_y; 465 sy = parent_y;
468 466
469 if (!root_img) 467 if (!root_img)
470 return false; 468 return false;
471 469
472 /* 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 : */
473 if (sx + window_width <= 0 || sy + window_height <= 0 471 if (sx + parent_width <= 0 || sy + parent_height <= 0
474 || sx >= root_width || sy >= root_height) 472 || sx >= root_width || sy >= root_height)
475 return 0; 473 return 0;
476 474
477 while (sx < 0) sx += root_img->w; 475 while (sx < 0) sx += root_img->w;
478 while (sy < 0) sy += root_img->h; 476 while (sy < 0) sy += root_img->h;
479 477
480 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);
481 479
482 if (root_effects.need_blur ()) 480 if (root_effects.need_blur ())
483 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);
484 482
485 if (root_effects.need_tint ()) 483 if (root_effects.need_tint ())
539} 537}
540 538
541void 539void
542rxvt_term::bg_init () 540rxvt_term::bg_init ()
543{ 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
544#if BG_IMAGE_FROM_FILE 562#if BG_IMAGE_FROM_FILE
545 if (rs[Rs_backgroundPixmap]) 563 if (rs[Rs_backgroundPixmap])
546 { 564 {
547 if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) 565 fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]);
548 && !bg_window_position_sensitive ()) 566 if (!bg_window_position_sensitive ())
549 update_background (); 567 update_background ();
550 } 568 }
551#endif 569#endif
552} 570}
553 571

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines