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> |
… | |
… | |
42 | delete bg_img; |
42 | delete bg_img; |
43 | bg_img = 0; |
43 | bg_img = 0; |
44 | } |
44 | } |
45 | |
45 | |
46 | bool |
46 | bool |
47 | rxvt_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 | |
|
|
60 | bool |
|
|
61 | rxvt_term::bg_window_size_sensitive () |
47 | rxvt_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 | |
|
|
112 | static inline int |
|
|
113 | make_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 | |
129 | static void |
98 | static void |
130 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
99 | parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
131 | { |
100 | { |
… | |
… | |
290 | void |
259 | void |
291 | rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
260 | rxvt_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 | |
326 | bool |
295 | bool |
327 | rxvt_term::render_image (rxvt_image &image) |
296 | rxvt_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 | bg_img->draw (img, PictOpOver, image.alpha * 1. / 0xffff); |
356 | double factor = image.alpha * 1. / 0xffff; |
|
|
357 | bg_img->blend (img, factor)->replace (img); |
|
|
358 | } |
|
|
359 | |
325 | |
360 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
326 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
361 | img->convert_format (format, pix_colors [Color_bg])->replace (img); |
327 | img->convert_format (format, pix_colors [Color_bg])->replace (img); |
362 | |
328 | |
363 | delete bg_img; |
329 | delete bg_img; |
… | |
… | |
376 | v_align = defaultAlign; |
342 | v_align = defaultAlign; |
377 | |
343 | |
378 | img = 0; |
344 | img = 0; |
379 | } |
345 | } |
380 | |
346 | |
381 | bool |
347 | void |
382 | rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) |
348 | rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) |
383 | { |
349 | { |
384 | if (!file || !*file) |
350 | if (!file || !*file) |
385 | return false; |
351 | return; |
386 | |
352 | |
387 | const char *p = strchr (file, ';'); |
353 | const char *p = strchr (file, ';'); |
388 | |
354 | |
389 | if (p) |
355 | if (p) |
390 | { |
356 | { |
… | |
… | |
393 | memcpy (f, file, len); |
359 | memcpy (f, file, len); |
394 | f[len] = '\0'; |
360 | f[len] = '\0'; |
395 | file = f; |
361 | file = f; |
396 | } |
362 | } |
397 | |
363 | |
398 | bool ret = set_file (s, file); |
364 | set_file (s, file); |
399 | alpha = 0x8000; |
365 | alpha = 0x8000; |
400 | if (ret) |
|
|
401 | set_geometry (p ? p + 1 : ""); |
366 | set_geometry (p ? p + 1 : ""); |
402 | return ret; |
|
|
403 | } |
367 | } |
404 | |
368 | |
405 | bool |
369 | void |
406 | rxvt_image::set_file (rxvt_screen *s, const char *file) |
370 | rxvt_image::set_file (rxvt_screen *s, const char *file) |
407 | { |
371 | { |
|
|
372 | rxvt_img *img2 = rxvt_img::new_from_file (s, file); |
408 | delete img; |
373 | delete img; |
409 | img = rxvt_img::new_from_file (s, file); |
374 | img = img2; |
410 | return img != 0; |
|
|
411 | } |
375 | } |
412 | |
376 | |
413 | # endif /* BG_IMAGE_FROM_FILE */ |
377 | # endif /* BG_IMAGE_FROM_FILE */ |
414 | |
378 | |
415 | bool |
379 | bool |
… | |
… | |
488 | * be always up-to-date, so let's use it : |
452 | * be always up-to-date, so let's use it : |
489 | */ |
453 | */ |
490 | int screen = display->screen; |
454 | int screen = display->screen; |
491 | int root_width = DisplayWidth (dpy, screen); |
455 | int root_width = DisplayWidth (dpy, screen); |
492 | int root_height = DisplayHeight (dpy, screen); |
456 | int root_height = DisplayHeight (dpy, screen); |
493 | int window_width = szHint.width; |
457 | int parent_width = szHint.width; |
494 | int window_height = szHint.height; |
458 | int parent_height = szHint.height; |
495 | int sx, sy; |
459 | int sx, sy; |
496 | |
460 | |
497 | sx = target_x; |
461 | sx = parent_x; |
498 | sy = target_y; |
462 | sy = parent_y; |
499 | |
463 | |
500 | if (!root_img) |
464 | if (!root_img) |
501 | return false; |
465 | return false; |
502 | |
466 | |
503 | /* 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 : */ |
504 | if (sx + window_width <= 0 || sy + window_height <= 0 |
468 | if (sx + parent_width <= 0 || sy + parent_height <= 0 |
505 | || sx >= root_width || sy >= root_height) |
469 | || sx >= root_width || sy >= root_height) |
506 | return 0; |
470 | return 0; |
507 | |
471 | |
508 | while (sx < 0) sx += root_img->w; |
472 | while (sx < 0) sx += root_img->w; |
509 | while (sy < 0) sy += root_img->h; |
473 | while (sy < 0) sy += root_img->h; |
510 | |
474 | |
511 | 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); |
512 | |
476 | |
513 | if (root_effects.need_blur ()) |
477 | if (root_effects.need_blur ()) |
514 | 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); |
515 | |
479 | |
516 | if (root_effects.need_tint ()) |
480 | if (root_effects.need_tint ()) |
… | |
… | |
570 | } |
534 | } |
571 | |
535 | |
572 | void |
536 | void |
573 | rxvt_term::bg_init () |
537 | rxvt_term::bg_init () |
574 | { |
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 | |
575 | #if BG_IMAGE_FROM_FILE |
559 | #if BG_IMAGE_FROM_FILE |
576 | if (rs[Rs_backgroundPixmap]) |
560 | if (rs[Rs_backgroundPixmap]) |
577 | { |
561 | { |
578 | if (fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]) |
562 | fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]); |
579 | && !bg_window_position_sensitive ()) |
563 | if (!bg_window_position_sensitive ()) |
580 | update_background (); |
564 | update_background (); |
581 | } |
565 | } |
582 | #endif |
566 | #endif |
583 | } |
567 | } |
584 | |
568 | |