1 |
sasha |
1.1 |
/*----------------------------------------------------------------------* |
2 |
sf-exg |
1.243 |
* File: background.C |
3 |
sasha |
1.1 |
*----------------------------------------------------------------------* |
4 |
|
|
* |
5 |
|
|
* All portions of code are copyright by their respective author/s. |
6 |
root |
1.147 |
* Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> |
7 |
sasha |
1.1 |
* Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
8 |
sf-exg |
1.209 |
* Copyright (c) 2010-2012 Emanuele Giaquinta <e.giaquinta@glauco.it> |
9 |
sasha |
1.1 |
* |
10 |
|
|
* This program is free software; you can redistribute it and/or modify |
11 |
|
|
* it under the terms of the GNU General Public License as published by |
12 |
|
|
* the Free Software Foundation; either version 2 of the License, or |
13 |
|
|
* (at your option) any later version. |
14 |
|
|
* |
15 |
|
|
* This program is distributed in the hope that it will be useful, |
16 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
17 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
18 |
|
|
* GNU General Public License for more details. |
19 |
|
|
* |
20 |
|
|
* You should have received a copy of the GNU General Public License |
21 |
|
|
* along with this program; if not, write to the Free Software |
22 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
23 |
|
|
*---------------------------------------------------------------------*/ |
24 |
|
|
|
25 |
|
|
#include "../config.h" /* NECESSARY */ |
26 |
|
|
#include "rxvt.h" /* NECESSARY */ |
27 |
|
|
|
28 |
|
|
#ifdef HAVE_BG_PIXMAP |
29 |
sf-exg |
1.188 |
|
30 |
root |
1.14 |
void |
31 |
sf-exg |
1.142 |
rxvt_term::bg_destroy () |
32 |
sasha |
1.11 |
{ |
33 |
sf-exg |
1.246 |
# if BG_IMAGE_FROM_ROOT |
34 |
sf-exg |
1.236 |
delete root_img; |
35 |
root |
1.237 |
root_img = 0; |
36 |
sf-exg |
1.236 |
# endif |
37 |
|
|
|
38 |
root |
1.232 |
# if BG_IMAGE_FROM_FILE |
39 |
sf-exg |
1.233 |
fimage.destroy (); |
40 |
sf-exg |
1.221 |
# endif |
41 |
|
|
|
42 |
sf-exg |
1.236 |
delete bg_img; |
43 |
root |
1.237 |
bg_img = 0; |
44 |
sasha |
1.11 |
} |
45 |
sasha |
1.2 |
|
46 |
sasha |
1.1 |
bool |
47 |
sf-exg |
1.142 |
rxvt_term::bg_window_size_sensitive () |
48 |
sasha |
1.1 |
{ |
49 |
sf-exg |
1.246 |
# if BG_IMAGE_FROM_ROOT |
50 |
sf-exg |
1.247 |
if (option (Opt_transparent)) |
51 |
sasha |
1.13 |
return true; |
52 |
|
|
# endif |
53 |
|
|
|
54 |
root |
1.232 |
# if BG_IMAGE_FROM_FILE |
55 |
sf-exg |
1.236 |
if (fimage.img) |
56 |
sasha |
1.1 |
{ |
57 |
sf-exg |
1.233 |
if ((fimage.flags & IM_IS_SIZE_SENSITIVE) |
58 |
sf-exg |
1.236 |
|| fimage.img->w > szHint.width |
59 |
|
|
|| fimage.img->h > szHint.height) |
60 |
sasha |
1.1 |
return true; |
61 |
|
|
} |
62 |
|
|
# endif |
63 |
sasha |
1.13 |
|
64 |
|
|
return false; |
65 |
|
|
} |
66 |
|
|
|
67 |
sf-exg |
1.37 |
bool |
68 |
sf-exg |
1.142 |
rxvt_term::bg_window_position_sensitive () |
69 |
sasha |
1.13 |
{ |
70 |
sf-exg |
1.246 |
# if BG_IMAGE_FROM_ROOT |
71 |
sf-exg |
1.247 |
if (option (Opt_transparent)) |
72 |
sasha |
1.1 |
return true; |
73 |
|
|
# endif |
74 |
sasha |
1.13 |
|
75 |
root |
1.232 |
# if BG_IMAGE_FROM_FILE |
76 |
sf-exg |
1.236 |
if (fimage.img) |
77 |
sasha |
1.13 |
{ |
78 |
sf-exg |
1.233 |
if (fimage.flags & IM_ROOT_ALIGN) |
79 |
sasha |
1.13 |
return true; |
80 |
|
|
} |
81 |
|
|
# endif |
82 |
|
|
|
83 |
sasha |
1.1 |
return false; |
84 |
sf-exg |
1.117 |
} |
85 |
sasha |
1.1 |
|
86 |
root |
1.232 |
# if BG_IMAGE_FROM_FILE |
87 |
sasha |
1.1 |
static inline int |
88 |
|
|
make_align_position (int align, int window_size, int image_size) |
89 |
|
|
{ |
90 |
sf-exg |
1.66 |
if (align >= 0 && align <= 100) |
91 |
sf-exg |
1.206 |
return lerp (0, window_size - image_size, align); |
92 |
sf-exg |
1.205 |
else if (align > 100) |
93 |
sf-exg |
1.206 |
return lerp (window_size - image_size, window_size, align - 100); |
94 |
sf-exg |
1.205 |
else |
95 |
sf-exg |
1.206 |
return lerp (-image_size, 0, align + 100); |
96 |
sasha |
1.1 |
} |
97 |
|
|
|
98 |
sf-exg |
1.219 |
static void |
99 |
|
|
parse_style (const char *style, int &x, int &y, unsigned int &w, unsigned int &h, uint8_t &flags) |
100 |
|
|
{ |
101 |
|
|
if (!strcasecmp (style, "tiled")) |
102 |
|
|
{ |
103 |
|
|
flags = IM_TILE; |
104 |
|
|
w = h = noScale; |
105 |
|
|
x = y = 0; |
106 |
|
|
} |
107 |
|
|
else if (!strcasecmp (style, "aspect-stretched")) |
108 |
|
|
{ |
109 |
|
|
flags = IM_KEEP_ASPECT; |
110 |
|
|
w = h = windowScale; |
111 |
|
|
x = y = centerAlign; |
112 |
|
|
} |
113 |
|
|
else if (!strcasecmp (style, "stretched")) |
114 |
|
|
{ |
115 |
|
|
flags = 0; |
116 |
|
|
w = h = windowScale; |
117 |
|
|
x = y = centerAlign; |
118 |
|
|
} |
119 |
|
|
else if (!strcasecmp (style, "centered")) |
120 |
|
|
{ |
121 |
|
|
flags = 0; |
122 |
|
|
w = h = noScale; |
123 |
|
|
x = y = centerAlign; |
124 |
|
|
} |
125 |
|
|
else if (!strcasecmp (style, "root-tiled")) |
126 |
|
|
{ |
127 |
|
|
flags = IM_TILE|IM_ROOT_ALIGN; |
128 |
|
|
w = h = noScale; |
129 |
|
|
x = y = 0; |
130 |
|
|
} |
131 |
|
|
} |
132 |
|
|
|
133 |
sasha |
1.1 |
bool |
134 |
sf-exg |
1.214 |
rxvt_image::set_geometry (const char *geom, bool update) |
135 |
sasha |
1.1 |
{ |
136 |
sf-exg |
1.110 |
bool changed = false; |
137 |
|
|
int geom_flags = 0; |
138 |
sf-exg |
1.198 |
int x = h_align; |
139 |
|
|
int y = v_align; |
140 |
|
|
unsigned int w = h_scale; |
141 |
|
|
unsigned int h = v_scale; |
142 |
sf-exg |
1.219 |
uint8_t new_flags = 0; |
143 |
sasha |
1.1 |
|
144 |
|
|
if (geom == NULL) |
145 |
|
|
return false; |
146 |
|
|
|
147 |
sf-exg |
1.163 |
if (geom[0]) |
148 |
sf-exg |
1.122 |
{ |
149 |
sf-exg |
1.163 |
char **arr = rxvt_strsplit (':', geom); |
150 |
sf-exg |
1.131 |
|
151 |
sf-exg |
1.173 |
for (int i = 0; arr[i]; i++) |
152 |
sasha |
1.1 |
{ |
153 |
sf-exg |
1.219 |
if (!strncasecmp (arr[i], "style=", 6)) |
154 |
sf-exg |
1.160 |
{ |
155 |
sf-exg |
1.219 |
parse_style (arr[i] + 6, x, y, w, h, new_flags); |
156 |
sf-exg |
1.160 |
geom_flags = WidthValue|HeightValue|XValue|YValue; |
157 |
|
|
} |
158 |
|
|
else if (!strcasecmp (arr[i], "op=tile")) |
159 |
sf-exg |
1.214 |
new_flags |= IM_TILE; |
160 |
sf-exg |
1.176 |
else if (!strcasecmp (arr[i], "op=keep-aspect")) |
161 |
sf-exg |
1.214 |
new_flags |= IM_KEEP_ASPECT; |
162 |
sf-exg |
1.176 |
else if (!strcasecmp (arr[i], "op=root-align")) |
163 |
sf-exg |
1.214 |
new_flags |= IM_ROOT_ALIGN; |
164 |
sf-exg |
1.160 |
|
165 |
|
|
// deprecated |
166 |
|
|
else if (!strcasecmp (arr[i], "tile")) |
167 |
sf-exg |
1.122 |
{ |
168 |
sf-exg |
1.214 |
new_flags |= IM_TILE; |
169 |
sf-exg |
1.122 |
w = h = noScale; |
170 |
|
|
geom_flags |= WidthValue|HeightValue; |
171 |
|
|
} |
172 |
sf-exg |
1.133 |
else if (!strcasecmp (arr[i], "propscale")) |
173 |
sf-exg |
1.122 |
{ |
174 |
sf-exg |
1.214 |
new_flags |= IM_KEEP_ASPECT; |
175 |
sf-exg |
1.177 |
w = h = windowScale; |
176 |
|
|
geom_flags |= WidthValue|HeightValue; |
177 |
sf-exg |
1.122 |
} |
178 |
sf-exg |
1.161 |
else if (!strcasecmp (arr[i], "hscale")) |
179 |
|
|
{ |
180 |
sf-exg |
1.214 |
new_flags |= IM_TILE; |
181 |
sf-exg |
1.161 |
w = windowScale; |
182 |
|
|
h = noScale; |
183 |
|
|
geom_flags |= WidthValue|HeightValue; |
184 |
|
|
} |
185 |
|
|
else if (!strcasecmp (arr[i], "vscale")) |
186 |
|
|
{ |
187 |
sf-exg |
1.214 |
new_flags |= IM_TILE; |
188 |
sf-exg |
1.161 |
h = windowScale; |
189 |
|
|
w = noScale; |
190 |
|
|
geom_flags |= WidthValue|HeightValue; |
191 |
|
|
} |
192 |
sf-exg |
1.133 |
else if (!strcasecmp (arr[i], "scale")) |
193 |
sf-exg |
1.122 |
{ |
194 |
sf-exg |
1.161 |
w = h = windowScale; |
195 |
sf-exg |
1.122 |
geom_flags |= WidthValue|HeightValue; |
196 |
|
|
} |
197 |
sf-exg |
1.161 |
else if (!strcasecmp (arr[i], "auto")) |
198 |
|
|
{ |
199 |
|
|
w = h = windowScale; |
200 |
|
|
x = y = centerAlign; |
201 |
|
|
geom_flags |= WidthValue|HeightValue|XValue|YValue; |
202 |
|
|
} |
203 |
sf-exg |
1.133 |
else if (!strcasecmp (arr[i], "root")) |
204 |
sf-exg |
1.122 |
{ |
205 |
sf-exg |
1.214 |
new_flags |= IM_TILE|IM_ROOT_ALIGN; |
206 |
sf-exg |
1.122 |
w = h = noScale; |
207 |
|
|
geom_flags |= WidthValue|HeightValue; |
208 |
|
|
} |
209 |
sf-exg |
1.163 |
|
210 |
|
|
else |
211 |
|
|
geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); |
212 |
sf-exg |
1.131 |
} /* done parsing ops */ |
213 |
root |
1.26 |
|
214 |
sf-exg |
1.131 |
rxvt_free_strsplit (arr); |
215 |
sf-exg |
1.122 |
} |
216 |
sasha |
1.1 |
|
217 |
sf-exg |
1.214 |
new_flags |= flags & ~IM_GEOMETRY_FLAGS; |
218 |
sf-exg |
1.185 |
|
219 |
sf-exg |
1.163 |
if (!update) |
220 |
|
|
{ |
221 |
|
|
if (!(geom_flags & XValue)) |
222 |
|
|
x = y = defaultAlign; |
223 |
|
|
else if (!(geom_flags & YValue)) |
224 |
|
|
y = x; |
225 |
|
|
|
226 |
|
|
if (!(geom_flags & (WidthValue|HeightValue))) |
227 |
|
|
w = h = defaultScale; |
228 |
|
|
else if (!(geom_flags & HeightValue)) |
229 |
|
|
h = w; |
230 |
|
|
else if (!(geom_flags & WidthValue)) |
231 |
|
|
w = h; |
232 |
|
|
} |
233 |
|
|
|
234 |
sf-exg |
1.198 |
clamp_it (x, -100, 200); |
235 |
|
|
clamp_it (y, -100, 200); |
236 |
|
|
|
237 |
sf-exg |
1.214 |
if (flags != new_flags |
238 |
sf-exg |
1.198 |
|| h_scale != w |
239 |
|
|
|| v_scale != h |
240 |
|
|
|| h_align != x |
241 |
|
|
|| v_align != y) |
242 |
sasha |
1.1 |
{ |
243 |
sf-exg |
1.214 |
flags = new_flags; |
244 |
sf-exg |
1.198 |
h_scale = w; |
245 |
|
|
v_scale = h; |
246 |
|
|
h_align = x; |
247 |
|
|
v_align = y; |
248 |
sf-exg |
1.110 |
changed = true; |
249 |
sasha |
1.1 |
} |
250 |
root |
1.26 |
|
251 |
sf-exg |
1.225 |
if (is_size_sensitive ()) |
252 |
sf-exg |
1.214 |
flags |= IM_IS_SIZE_SENSITIVE; |
253 |
|
|
else |
254 |
|
|
flags &= ~IM_IS_SIZE_SENSITIVE; |
255 |
|
|
|
256 |
sf-exg |
1.110 |
return changed; |
257 |
sasha |
1.1 |
} |
258 |
|
|
|
259 |
sf-exg |
1.59 |
void |
260 |
sf-exg |
1.214 |
rxvt_term::get_image_geometry (rxvt_image &image, int &w, int &h, int &x, int &y) |
261 |
sf-exg |
1.59 |
{ |
262 |
sf-exg |
1.236 |
int image_width = image.img->w; |
263 |
|
|
int image_height = image.img->h; |
264 |
sf-exg |
1.240 |
int parent_width = szHint.width; |
265 |
|
|
int parent_height = szHint.height; |
266 |
|
|
int h_scale = min (image.h_scale, 32767 * 100 / parent_width); |
267 |
|
|
int v_scale = min (image.v_scale, 32767 * 100 / parent_height); |
268 |
sf-exg |
1.59 |
|
269 |
sf-exg |
1.240 |
w = h_scale * parent_width / 100; |
270 |
|
|
h = v_scale * parent_height / 100; |
271 |
sf-exg |
1.164 |
|
272 |
sf-exg |
1.214 |
if (image.flags & IM_KEEP_ASPECT) |
273 |
sf-exg |
1.62 |
{ |
274 |
sf-exg |
1.164 |
float scale = (float)w / image_width; |
275 |
|
|
min_it (scale, (float)h / image_height); |
276 |
sf-exg |
1.62 |
w = image_width * scale + 0.5; |
277 |
|
|
h = image_height * scale + 0.5; |
278 |
|
|
} |
279 |
sf-exg |
1.59 |
|
280 |
sf-exg |
1.68 |
if (!w) w = image_width; |
281 |
|
|
if (!h) h = image_height; |
282 |
|
|
|
283 |
sf-exg |
1.214 |
if (image.flags & IM_ROOT_ALIGN) |
284 |
sf-exg |
1.59 |
{ |
285 |
sf-exg |
1.239 |
x = -parent_x; |
286 |
|
|
y = -parent_y; |
287 |
sf-exg |
1.59 |
} |
288 |
sf-exg |
1.63 |
else |
289 |
|
|
{ |
290 |
sf-exg |
1.240 |
x = make_align_position (image.h_align, parent_width, w); |
291 |
|
|
y = make_align_position (image.v_align, parent_height, h); |
292 |
sf-exg |
1.63 |
} |
293 |
sf-exg |
1.59 |
} |
294 |
|
|
|
295 |
sf-exg |
1.127 |
bool |
296 |
sf-exg |
1.215 |
rxvt_term::render_image (rxvt_image &image) |
297 |
sf-exg |
1.55 |
{ |
298 |
sf-exg |
1.240 |
int parent_width = szHint.width; |
299 |
|
|
int parent_height = szHint.height; |
300 |
sf-exg |
1.55 |
|
301 |
|
|
int x = 0; |
302 |
|
|
int y = 0; |
303 |
sf-exg |
1.59 |
int w = 0; |
304 |
|
|
int h = 0; |
305 |
sf-exg |
1.55 |
|
306 |
sf-exg |
1.214 |
get_image_geometry (image, w, h, x, y); |
307 |
sf-exg |
1.55 |
|
308 |
sf-exg |
1.214 |
if (!(image.flags & IM_ROOT_ALIGN) |
309 |
sf-exg |
1.240 |
&& (x >= parent_width |
310 |
|
|
|| y >= parent_height |
311 |
sf-exg |
1.172 |
|| x + w <= 0 |
312 |
|
|
|| y + h <= 0)) |
313 |
sf-exg |
1.55 |
return false; |
314 |
|
|
|
315 |
sf-exg |
1.236 |
rxvt_img *img = image.img->scale (w, h); |
316 |
sf-exg |
1.55 |
|
317 |
sf-exg |
1.236 |
if (image.flags & IM_TILE) |
318 |
|
|
img->repeat_mode (RepeatNormal); |
319 |
sf-exg |
1.152 |
else |
320 |
sf-exg |
1.236 |
img->repeat_mode (RepeatNone); |
321 |
sf-exg |
1.240 |
img->sub_rect (-x, -y, parent_width, parent_height)->replace (img); |
322 |
sf-exg |
1.154 |
|
323 |
sf-exg |
1.236 |
if (bg_flags & BG_IS_VALID) |
324 |
sf-exg |
1.245 |
img->draw (bg_img, PictOpOver, image.alpha * 1. / 0xffff); |
325 |
sf-exg |
1.79 |
|
326 |
sf-exg |
1.236 |
XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
327 |
|
|
img->convert_format (format, pix_colors [Color_bg])->replace (img); |
328 |
sf-exg |
1.55 |
|
329 |
sf-exg |
1.236 |
delete bg_img; |
330 |
|
|
bg_img = img; |
331 |
sf-exg |
1.55 |
|
332 |
sf-exg |
1.236 |
return true; |
333 |
sf-exg |
1.55 |
} |
334 |
|
|
|
335 |
sf-exg |
1.220 |
rxvt_image::rxvt_image () |
336 |
|
|
{ |
337 |
sf-exg |
1.224 |
alpha = 0xffff; |
338 |
|
|
flags = 0; |
339 |
sf-exg |
1.220 |
h_scale = |
340 |
sf-exg |
1.224 |
v_scale = defaultScale; |
341 |
sf-exg |
1.220 |
h_align = |
342 |
sf-exg |
1.224 |
v_align = defaultAlign; |
343 |
sf-exg |
1.220 |
|
344 |
sf-exg |
1.236 |
img = 0; |
345 |
sf-exg |
1.220 |
} |
346 |
|
|
|
347 |
sf-exg |
1.241 |
void |
348 |
sf-exg |
1.236 |
rxvt_image::set_file_geometry (rxvt_screen *s, const char *file) |
349 |
sasha |
1.1 |
{ |
350 |
sf-exg |
1.107 |
if (!file || !*file) |
351 |
sf-exg |
1.241 |
return; |
352 |
sasha |
1.1 |
|
353 |
sf-exg |
1.167 |
const char *p = strchr (file, ';'); |
354 |
|
|
|
355 |
|
|
if (p) |
356 |
sasha |
1.1 |
{ |
357 |
sf-exg |
1.107 |
size_t len = p - file; |
358 |
|
|
char *f = rxvt_temp_buf<char> (len + 1); |
359 |
|
|
memcpy (f, file, len); |
360 |
|
|
f[len] = '\0'; |
361 |
|
|
file = f; |
362 |
|
|
} |
363 |
root |
1.25 |
|
364 |
sf-exg |
1.241 |
set_file (s, file); |
365 |
sf-exg |
1.220 |
alpha = 0x8000; |
366 |
sf-exg |
1.241 |
set_geometry (p ? p + 1 : ""); |
367 |
sf-exg |
1.220 |
} |
368 |
|
|
|
369 |
sf-exg |
1.241 |
void |
370 |
sf-exg |
1.236 |
rxvt_image::set_file (rxvt_screen *s, const char *file) |
371 |
sf-exg |
1.220 |
{ |
372 |
sf-exg |
1.241 |
rxvt_img *img2 = rxvt_img::new_from_file (s, file); |
373 |
sf-exg |
1.236 |
delete img; |
374 |
sf-exg |
1.241 |
img = img2; |
375 |
sasha |
1.1 |
} |
376 |
|
|
|
377 |
ayin |
1.12 |
# endif /* BG_IMAGE_FROM_FILE */ |
378 |
sasha |
1.1 |
|
379 |
ayin |
1.10 |
bool |
380 |
sf-exg |
1.226 |
image_effects::set_blur (const char *geom) |
381 |
sasha |
1.1 |
{ |
382 |
sf-exg |
1.110 |
bool changed = false; |
383 |
sasha |
1.1 |
unsigned int hr, vr; |
384 |
|
|
int junk; |
385 |
|
|
int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
386 |
|
|
|
387 |
sf-exg |
1.52 |
if (!(geom_flags & WidthValue)) |
388 |
sasha |
1.1 |
hr = 1; |
389 |
sf-exg |
1.52 |
if (!(geom_flags & HeightValue)) |
390 |
sasha |
1.1 |
vr = hr; |
391 |
|
|
|
392 |
sf-exg |
1.80 |
min_it (hr, 128); |
393 |
|
|
min_it (vr, 128); |
394 |
|
|
|
395 |
sasha |
1.1 |
if (h_blurRadius != hr) |
396 |
|
|
{ |
397 |
sf-exg |
1.110 |
changed = true; |
398 |
sasha |
1.1 |
h_blurRadius = hr; |
399 |
|
|
} |
400 |
|
|
|
401 |
|
|
if (v_blurRadius != vr) |
402 |
|
|
{ |
403 |
sf-exg |
1.110 |
changed = true; |
404 |
sasha |
1.1 |
v_blurRadius = vr; |
405 |
|
|
} |
406 |
ayin |
1.10 |
|
407 |
sf-exg |
1.110 |
return changed; |
408 |
sasha |
1.1 |
} |
409 |
|
|
|
410 |
|
|
bool |
411 |
sf-exg |
1.226 |
image_effects::set_tint (const rxvt_color &new_tint) |
412 |
sasha |
1.1 |
{ |
413 |
sf-exg |
1.226 |
if (!tint_set || tint != new_tint) |
414 |
sasha |
1.1 |
{ |
415 |
|
|
tint = new_tint; |
416 |
sf-exg |
1.226 |
tint_set = true; |
417 |
sf-exg |
1.203 |
|
418 |
sasha |
1.1 |
return true; |
419 |
|
|
} |
420 |
root |
1.20 |
|
421 |
sasha |
1.1 |
return false; |
422 |
|
|
} |
423 |
|
|
|
424 |
|
|
bool |
425 |
sf-exg |
1.226 |
image_effects::set_shade (const char *shade_str) |
426 |
sasha |
1.1 |
{ |
427 |
sf-exg |
1.186 |
int new_shade = atoi (shade_str); |
428 |
sasha |
1.1 |
|
429 |
sf-exg |
1.75 |
clamp_it (new_shade, -100, 200); |
430 |
|
|
if (new_shade < 0) |
431 |
root |
1.20 |
new_shade = 200 - (100 + new_shade); |
432 |
sasha |
1.1 |
|
433 |
|
|
if (new_shade != shade) |
434 |
|
|
{ |
435 |
|
|
shade = new_shade; |
436 |
|
|
return true; |
437 |
|
|
} |
438 |
root |
1.20 |
|
439 |
sasha |
1.1 |
return false; |
440 |
|
|
} |
441 |
|
|
|
442 |
sf-exg |
1.246 |
# if BG_IMAGE_FROM_ROOT |
443 |
sf-exg |
1.149 |
/* |
444 |
sf-exg |
1.100 |
* Builds a pixmap of the same size as the terminal window that contains |
445 |
|
|
* the tiled portion of the root pixmap that is supposed to be covered by |
446 |
sasha |
1.1 |
* our window. |
447 |
|
|
*/ |
448 |
sf-exg |
1.202 |
bool |
449 |
sf-exg |
1.228 |
rxvt_term::render_root_image () |
450 |
sasha |
1.1 |
{ |
451 |
sf-exg |
1.39 |
/* root dimensions may change from call to call - but Display structure should |
452 |
sasha |
1.1 |
* be always up-to-date, so let's use it : |
453 |
|
|
*/ |
454 |
sf-exg |
1.142 |
int screen = display->screen; |
455 |
sasha |
1.1 |
int root_width = DisplayWidth (dpy, screen); |
456 |
|
|
int root_height = DisplayHeight (dpy, screen); |
457 |
sf-exg |
1.240 |
int parent_width = szHint.width; |
458 |
|
|
int parent_height = szHint.height; |
459 |
sasha |
1.1 |
int sx, sy; |
460 |
|
|
|
461 |
sf-exg |
1.239 |
sx = parent_x; |
462 |
|
|
sy = parent_y; |
463 |
sasha |
1.1 |
|
464 |
sf-exg |
1.236 |
if (!root_img) |
465 |
|
|
return false; |
466 |
|
|
|
467 |
sasha |
1.1 |
/* check if we are outside of the visible part of the virtual screen : */ |
468 |
sf-exg |
1.240 |
if (sx + parent_width <= 0 || sy + parent_height <= 0 |
469 |
sasha |
1.1 |
|| sx >= root_width || sy >= root_height) |
470 |
|
|
return 0; |
471 |
|
|
|
472 |
sf-exg |
1.236 |
while (sx < 0) sx += root_img->w; |
473 |
|
|
while (sy < 0) sy += root_img->h; |
474 |
sf-exg |
1.103 |
|
475 |
sf-exg |
1.240 |
rxvt_img *img = root_img->sub_rect (sx, sy, parent_width, parent_height); |
476 |
sf-exg |
1.103 |
|
477 |
sf-exg |
1.236 |
if (root_effects.need_blur ()) |
478 |
|
|
img->blur (root_effects.h_blurRadius, root_effects.v_blurRadius)->replace (img); |
479 |
sf-exg |
1.103 |
|
480 |
sf-exg |
1.236 |
if (root_effects.need_tint ()) |
481 |
|
|
tint_image (img, root_effects.tint, root_effects.tint_set, root_effects.shade); |
482 |
sf-exg |
1.103 |
|
483 |
sf-exg |
1.236 |
XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
484 |
|
|
img->convert_format (format, pix_colors [Color_bg])->replace (img); |
485 |
sf-exg |
1.103 |
|
486 |
sf-exg |
1.236 |
delete bg_img; |
487 |
|
|
bg_img = img; |
488 |
sf-exg |
1.152 |
|
489 |
sf-exg |
1.236 |
return true; |
490 |
sasha |
1.1 |
} |
491 |
|
|
|
492 |
sf-exg |
1.98 |
void |
493 |
sf-exg |
1.142 |
rxvt_term::bg_set_root_pixmap () |
494 |
sasha |
1.1 |
{ |
495 |
sf-exg |
1.236 |
delete root_img; |
496 |
|
|
root_img = rxvt_img::new_from_root (this); |
497 |
sasha |
1.1 |
} |
498 |
sf-exg |
1.246 |
# endif /* BG_IMAGE_FROM_ROOT */ |
499 |
sasha |
1.1 |
|
500 |
sf-exg |
1.234 |
void |
501 |
sf-exg |
1.142 |
rxvt_term::bg_render () |
502 |
sasha |
1.1 |
{ |
503 |
sf-exg |
1.235 |
if (bg_flags & BG_INHIBIT_RENDER) |
504 |
|
|
return; |
505 |
|
|
|
506 |
sf-exg |
1.142 |
bg_invalidate (); |
507 |
sf-exg |
1.246 |
# if BG_IMAGE_FROM_ROOT |
508 |
sf-exg |
1.247 |
if (option (Opt_transparent)) |
509 |
sasha |
1.1 |
{ |
510 |
|
|
/* we need to re-generate transparency pixmap in that case ! */ |
511 |
sf-exg |
1.228 |
if (render_root_image ()) |
512 |
sf-exg |
1.247 |
bg_flags |= BG_IS_VALID | BG_IS_TRANSPARENT; |
513 |
sasha |
1.1 |
} |
514 |
|
|
# endif |
515 |
|
|
|
516 |
root |
1.232 |
# if BG_IMAGE_FROM_FILE |
517 |
sf-exg |
1.236 |
if (fimage.img) |
518 |
sasha |
1.1 |
{ |
519 |
sf-exg |
1.233 |
if (render_image (fimage)) |
520 |
sf-exg |
1.143 |
bg_flags |= BG_IS_VALID; |
521 |
sasha |
1.1 |
} |
522 |
sf-exg |
1.46 |
# endif |
523 |
sasha |
1.7 |
|
524 |
sf-exg |
1.143 |
if (!(bg_flags & BG_IS_VALID)) |
525 |
sasha |
1.1 |
{ |
526 |
sf-exg |
1.236 |
delete bg_img; |
527 |
|
|
bg_img = 0; |
528 |
sasha |
1.1 |
} |
529 |
|
|
|
530 |
sf-exg |
1.142 |
scr_recolour (false); |
531 |
sf-exg |
1.143 |
bg_flags |= BG_NEEDS_REFRESH; |
532 |
sasha |
1.1 |
|
533 |
sf-exg |
1.142 |
bg_valid_since = ev::now (); |
534 |
sasha |
1.1 |
} |
535 |
|
|
|
536 |
sf-exg |
1.106 |
void |
537 |
sf-exg |
1.142 |
rxvt_term::bg_init () |
538 |
sasha |
1.1 |
{ |
539 |
sf-exg |
1.246 |
#if BG_IMAGE_FROM_ROOT |
540 |
sf-exg |
1.242 |
if (option (Opt_transparent)) |
541 |
|
|
{ |
542 |
|
|
if (rs [Rs_blurradius]) |
543 |
|
|
root_effects.set_blur (rs [Rs_blurradius]); |
544 |
|
|
|
545 |
|
|
if (ISSET_PIXCOLOR (Color_tint)) |
546 |
|
|
root_effects.set_tint (pix_colors_focused [Color_tint]); |
547 |
|
|
|
548 |
|
|
if (rs [Rs_shade]) |
549 |
|
|
root_effects.set_shade (rs [Rs_shade]); |
550 |
|
|
|
551 |
|
|
bg_set_root_pixmap (); |
552 |
|
|
XSelectInput (dpy, display->root, PropertyChangeMask); |
553 |
|
|
rootwin_ev.start (display, display->root); |
554 |
|
|
} |
555 |
|
|
#endif |
556 |
|
|
|
557 |
root |
1.232 |
#if BG_IMAGE_FROM_FILE |
558 |
sf-exg |
1.220 |
if (rs[Rs_backgroundPixmap]) |
559 |
|
|
{ |
560 |
sf-exg |
1.241 |
fimage.set_file_geometry (this, rs[Rs_backgroundPixmap]); |
561 |
|
|
if (!bg_window_position_sensitive ()) |
562 |
sf-exg |
1.233 |
update_background (); |
563 |
sf-exg |
1.220 |
} |
564 |
|
|
#endif |
565 |
sasha |
1.1 |
} |
566 |
|
|
|
567 |
sf-exg |
1.183 |
void |
568 |
sf-exg |
1.236 |
rxvt_term::tint_image (rxvt_img *img, rxvt_color &tint, bool tint_set, int shade) |
569 |
sasha |
1.1 |
{ |
570 |
sf-exg |
1.194 |
rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
571 |
sf-exg |
1.183 |
|
572 |
sf-exg |
1.226 |
if (tint_set) |
573 |
sf-exg |
1.194 |
tint.get (c); |
574 |
sf-exg |
1.183 |
|
575 |
sf-exg |
1.87 |
if (shade > 100) |
576 |
|
|
{ |
577 |
sf-exg |
1.184 |
c.r = c.r * (200 - shade) / 100; |
578 |
|
|
c.g = c.g * (200 - shade) / 100; |
579 |
|
|
c.b = c.b * (200 - shade) / 100; |
580 |
sf-exg |
1.87 |
} |
581 |
|
|
else |
582 |
|
|
{ |
583 |
sf-exg |
1.184 |
c.r = c.r * shade / 100; |
584 |
|
|
c.g = c.g * shade / 100; |
585 |
|
|
c.b = c.b * shade / 100; |
586 |
sf-exg |
1.87 |
} |
587 |
sasha |
1.1 |
|
588 |
sf-exg |
1.236 |
img->contrast (c.r, c.g, c.b, c.a); |
589 |
sasha |
1.1 |
|
590 |
sf-exg |
1.236 |
if (shade > 100) |
591 |
sf-exg |
1.93 |
{ |
592 |
sf-exg |
1.236 |
c.a = 0xffff; |
593 |
|
|
c.r = |
594 |
|
|
c.g = |
595 |
|
|
c.b = 0xffff * (shade - 100) / 100; |
596 |
|
|
img->brightness (c.r, c.g, c.b, c.a); |
597 |
sasha |
1.1 |
} |
598 |
|
|
} |
599 |
sf-exg |
1.226 |
|
600 |
|
|
#endif /* HAVE_BG_PIXMAP */ |