… | |
… | |
72 | |
72 | |
73 | #ifdef HAVE_BG_PIXMAP |
73 | #ifdef HAVE_BG_PIXMAP |
74 | bool |
74 | bool |
75 | bgPixmap_t::window_size_sensitive () |
75 | bgPixmap_t::window_size_sensitive () |
76 | { |
76 | { |
77 | #ifdef XPM_BACKGROUND |
77 | # ifdef XPM_BACKGROUND |
78 | #ifdef HAVE_AFTERIMAGE |
78 | # ifdef HAVE_AFTERIMAGE |
79 | if (original_asim != NULL) |
79 | if (original_asim != NULL) |
80 | #endif |
80 | # endif |
81 | { |
81 | { |
82 | if (h_scale != 0 || v_scale != 0) |
82 | if (h_scale != 0 || v_scale != 0) |
83 | return true; |
83 | return true; |
84 | } |
84 | } |
85 | #endif |
85 | # endif |
86 | #ifdef ENABLE_TRANSPARENCY |
86 | # ifdef ENABLE_TRANSPARENCY |
87 | if (flags & bgPmap_Transparent) |
87 | if (flags & isTransparent) |
88 | return true; |
88 | return true; |
89 | #endif |
89 | # endif |
90 | return false; |
90 | return false; |
91 | } |
91 | } |
92 | |
92 | |
93 | #ifdef XPM_BACKGROUND |
93 | # ifdef XPM_BACKGROUND |
94 | static inline bool |
94 | static inline bool |
95 | check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) |
95 | check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value) |
96 | { |
96 | { |
97 | if (geom_flags & flag) |
97 | if (geom_flags & flag) |
98 | { |
98 | { |
… | |
… | |
132 | int smaller = MIN (image_size,window_size); |
132 | int smaller = MIN (image_size,window_size); |
133 | |
133 | |
134 | if (align >= 0 && align <= 50) |
134 | if (align >= 0 && align <= 50) |
135 | return diff * align / 100; |
135 | return diff * align / 100; |
136 | else if (align > 50 && align <= 100) |
136 | else if (align > 50 && align <= 100) |
137 | return window_size - image_size + diff * align / 100; |
137 | return window_size - image_size - diff * (100 - align) / 100; |
138 | else if (align > 100 && align <= 200 ) |
138 | else if (align > 100 && align <= 200 ) |
139 | return ((align - 100) * smaller / 100) + window_size - smaller; |
139 | return ((align - 100) * smaller / 100) + window_size - smaller; |
140 | else if (align > -100 && align < 0) |
140 | else if (align > -100 && align < 0) |
141 | return ((align + 100) * smaller / 100) - image_size; |
141 | return ((align + 100) * smaller / 100) - image_size; |
142 | return 0; |
142 | return 0; |
143 | } |
143 | } |
144 | |
144 | |
145 | static inline void |
145 | static inline int |
146 | make_clip_rectangle (int pos, int size, int target_size, int &clip_pos, int &clip_size) |
146 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
147 | { |
147 | { |
148 | if (size <= 0) |
148 | int src_pos = 0; |
149 | { /* special case - tiling */ |
149 | dst_pos = 0; |
|
|
150 | dst_size = size; |
|
|
151 | if (pos < 0 && size > target_size) |
|
|
152 | { |
150 | clip_pos = pos; |
153 | src_pos = -pos; |
151 | clip_size = target_size; |
154 | dst_size += pos; |
152 | } |
155 | } |
153 | else if (pos < 0) |
156 | else if (pos > 0) |
154 | { |
|
|
155 | clip_pos = 0; |
|
|
156 | clip_size = MIN (target_size, size + pos); |
|
|
157 | } |
|
|
158 | else |
|
|
159 | { |
|
|
160 | clip_pos = pos; |
157 | dst_pos = pos; |
161 | clip_size = size; |
158 | |
162 | if (pos < target_size && (int)clip_size > target_size - pos) |
159 | if (dst_pos + dst_size > target_size) |
163 | clip_pos = target_size - pos; |
160 | dst_size = target_size - dst_pos; |
164 | } |
161 | return src_pos; |
165 | } |
162 | } |
166 | |
163 | |
167 | bool |
164 | bool |
168 | bgPixmap_t::handle_geometry (const char *geom) |
165 | bgPixmap_t::set_geometry (const char *geom) |
169 | { |
166 | { |
170 | int geom_flags = 0, changed = 0; |
167 | int geom_flags = 0, changed = 0; |
171 | int x = 0, y = 0; |
168 | int x = 0, y = 0; |
172 | unsigned int w = 0, h = 0; |
169 | unsigned int w = 0, h = 0; |
173 | unsigned int n; |
170 | unsigned int n; |
174 | unsigned long new_flags = (flags&(~bgPmap_geometryFlags)); |
171 | unsigned long new_flags = (flags & (~geometryFlags)); |
175 | char *p; |
172 | char *p; |
176 | #define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
173 | # define MAXLEN_GEOM 256 /* could be longer then regular geometry string */ |
177 | |
174 | |
178 | if (geom == NULL) |
175 | if (geom == NULL) |
179 | return false; |
176 | return false; |
180 | |
177 | |
181 | char str[MAXLEN_GEOM]; |
178 | char str[MAXLEN_GEOM]; |
182 | |
179 | |
183 | if (!strcmp (geom, "?")) |
|
|
184 | { |
|
|
185 | #if 0 /* TODO: */ |
|
|
186 | sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ |
|
|
187 | min (h_scale, 32767), min (v_scale, 32767), |
|
|
188 | min (h_align, 32767), min (v_align, 32767)); |
|
|
189 | process_xterm_seq (XTerm_title, str, CHAR_ST); |
|
|
190 | #endif |
|
|
191 | return false; |
|
|
192 | } |
|
|
193 | while (isspace(*geom)) ++geom; |
180 | while (isspace(*geom)) ++geom; |
194 | if ((p = strchr (geom, ';')) == NULL) |
181 | if ((p = strchr (geom, ';')) == NULL) |
195 | p = strchr (geom, '\0'); |
182 | p = strchr (geom, '\0'); |
196 | |
183 | |
197 | n = (p - geom); |
184 | n = (p - geom); |
198 | if (n < MAXLEN_GEOM) |
185 | if (n < MAXLEN_GEOM) |
199 | { |
186 | { |
200 | char *ops; |
187 | char *ops; |
201 | new_flags |= bgPmap_geometrySet; |
188 | new_flags |= geometrySet; |
202 | |
189 | |
203 | strncpy (str, geom, n); |
190 | strncpy (str, geom, n); |
204 | str[n] = '\0'; |
191 | str[n] = '\0'; |
205 | if (str[0] == ':') |
192 | if (str[0] == ':') |
206 | ops = &str[0]; |
193 | ops = &str[0]; |
… | |
… | |
227 | { |
214 | { |
228 | y = x; |
215 | y = x; |
229 | geom_flags |= YValue; |
216 | geom_flags |= YValue; |
230 | } |
217 | } |
231 | |
218 | |
232 | if (flags & bgPmap_geometrySet) |
219 | if (flags & geometrySet) |
233 | {/* new geometry is an adjustment to the old one ! */ |
220 | {/* new geometry is an adjustment to the old one ! */ |
234 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
221 | if ((geom_flags & WidthValue) && (geom_flags & HeightValue)) |
235 | { |
222 | { |
236 | if (w == 0 && h != 0) |
223 | if (w == 0 && h != 0) |
237 | { |
224 | { |
… | |
… | |
255 | } |
242 | } |
256 | else /* setting up geometry from scratch */ |
243 | else /* setting up geometry from scratch */ |
257 | { |
244 | { |
258 | if (!(geom_flags & XValue)) |
245 | if (!(geom_flags & XValue)) |
259 | {/* use default geometry - centered */ |
246 | {/* use default geometry - centered */ |
260 | x = y = bgPmap_defaultAlign; |
247 | x = y = defaultAlign; |
261 | } |
248 | } |
262 | else if (!(geom_flags & YValue)) |
249 | else if (!(geom_flags & YValue)) |
263 | y = x; |
250 | y = x; |
264 | |
251 | |
265 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
252 | if ((geom_flags & (WidthValue|HeightValue)) == 0) |
266 | {/* use default geometry - scaled */ |
253 | {/* use default geometry - scaled */ |
267 | w = h = bgPmap_defaultScale; |
254 | w = h = defaultScale; |
268 | } |
255 | } |
269 | else if (geom_flags & WidthValue) |
256 | else if (geom_flags & WidthValue) |
270 | { |
257 | { |
271 | if (!(geom_flags & HeightValue)) |
258 | if (!(geom_flags & HeightValue)) |
272 | h = w; |
259 | h = w; |
273 | } |
260 | } |
274 | else |
261 | else |
275 | w = h; |
262 | w = h; |
276 | } |
263 | } |
277 | } /* done parsing geometry string */ |
264 | } /* done parsing geometry string */ |
278 | else if (!(flags & bgPmap_geometrySet)) |
265 | else if (!(flags & geometrySet)) |
279 | { /* default geometry - scaled and centered */ |
266 | { /* default geometry - scaled and centered */ |
280 | x = y = bgPmap_defaultAlign; |
267 | x = y = defaultAlign; |
281 | w = h = bgPmap_defaultScale; |
268 | w = h = defaultScale; |
282 | } |
269 | } |
283 | |
270 | |
284 | if (!(flags & bgPmap_geometrySet)) |
271 | if (!(flags & geometrySet)) |
285 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
272 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
286 | |
273 | |
287 | if (ops) |
274 | if (ops) |
288 | { |
275 | { |
289 | while (*ops) |
276 | while (*ops) |
290 | { |
277 | { |
291 | while (*ops == ':' || isspace(*ops)) ++ops; |
278 | while (*ops == ':' || isspace(*ops)) ++ops; |
292 | #define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
279 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
293 | if (CHECK_GEOM_OPS("tile")) |
280 | if (CHECK_GEOM_OPS("tile")) |
294 | { |
281 | { |
295 | w = h = 0; |
282 | w = h = 0; |
296 | geom_flags |= WidthValue|HeightValue; |
283 | geom_flags |= WidthValue|HeightValue; |
297 | } |
284 | } |
… | |
… | |
300 | if (w == 0 && h == 0) |
287 | if (w == 0 && h == 0) |
301 | { |
288 | { |
302 | w = 100; |
289 | w = 100; |
303 | geom_flags |= WidthValue; |
290 | geom_flags |= WidthValue; |
304 | } |
291 | } |
305 | new_flags |= bgPmap_propScale; |
292 | new_flags |= propScale; |
306 | } |
293 | } |
307 | else if (CHECK_GEOM_OPS("hscale")) |
294 | else if (CHECK_GEOM_OPS("hscale")) |
308 | { |
295 | { |
309 | if (w == 0) |
296 | if (w == 0) |
310 | w = 100; |
297 | w = 100; |
… | |
… | |
330 | { |
317 | { |
331 | w = h = 100; |
318 | w = h = 100; |
332 | x = y = 50; |
319 | x = y = 50; |
333 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
320 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
334 | } |
321 | } |
335 | #undef CHECK_GEOM_OPS |
322 | # undef CHECK_GEOM_OPS |
336 | while (*ops != ':' && *ops != '\0') ++ops; |
323 | while (*ops != ':' && *ops != '\0') ++ops; |
337 | } /* done parsing ops */ |
324 | } /* done parsing ops */ |
338 | } |
325 | } |
339 | |
326 | |
340 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) |
327 | if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) |
… | |
… | |
355 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
342 | //fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n", |
356 | // flags, h_scale, v_scale, h_align, v_align); |
343 | // flags, h_scale, v_scale, h_align, v_align); |
357 | return (changed > 0); |
344 | return (changed > 0); |
358 | } |
345 | } |
359 | |
346 | |
360 | #ifdef HAVE_AFTERIMAGE |
347 | # ifdef HAVE_AFTERIMAGE |
361 | bool |
348 | bool |
362 | bgPixmap_t::render_asim (rxvt_term *target, ASImage *background, ARGB32 background_tint) |
349 | bgPixmap_t::render_asim (ASImage *background, ARGB32 background_tint) |
363 | { |
350 | { |
364 | if (target == NULL) |
351 | if (target == NULL) |
365 | return false; |
352 | return false; |
366 | |
353 | |
367 | int target_width = (int)target->szHint.width; |
354 | int target_width = (int)target->szHint.width; |
… | |
… | |
378 | { |
365 | { |
379 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
366 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
380 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
367 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
381 | } |
368 | } |
382 | |
369 | |
383 | int dst_x, dst_y; |
370 | if (original_asim == NULL |
384 | int clip_width, clip_height; |
371 | || x >= target_width |
385 | |
372 | || y >= target_height |
386 | make_clip_rectangle (x, w, target_width, dst_x, clip_width); |
373 | || (w > 0 && x + w <= 0) |
387 | make_clip_rectangle (y, h, target_height, dst_y, clip_height); |
374 | || (h > 0 && y + h <= 0)) |
388 | |
|
|
389 | /* TODO : actuall scaling code :) */ |
|
|
390 | if (dst_x >= target_width || dst_y >= target_height |
|
|
391 | || clip_width <= 0 || clip_height <= 0 || original_asim == NULL) |
|
|
392 | { |
375 | { |
393 | result = background; |
|
|
394 | dst_x = dst_y = 0; |
|
|
395 | if (background) |
376 | if (background) |
396 | { |
377 | { |
397 | new_pmap_width = clip_width = background->width; |
378 | new_pmap_width = background->width; |
398 | new_pmap_height = clip_height = background->height; |
379 | new_pmap_height = background->height; |
|
|
380 | result = background; |
|
|
381 | if (background_tint != TINT_LEAVE_SAME) |
|
|
382 | { |
|
|
383 | ASImage* tmp = tile_asimage (target->asv, background, 0, 0, |
|
|
384 | target_width, target_height, background_tint, |
|
|
385 | ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
386 | if (tmp) |
|
|
387 | result = tmp; |
|
|
388 | } |
399 | } |
389 | } |
400 | else |
390 | else |
401 | new_pmap_width = new_pmap_height = 0; |
391 | new_pmap_width = new_pmap_height = 0; |
402 | } |
392 | } |
403 | else |
393 | else |
404 | { |
394 | { |
405 | result = original_asim; |
395 | result = original_asim; |
406 | if ((w > 0 && w != original_asim->width) |
396 | if ((w > 0 && w != original_asim->width) |
… | |
… | |
416 | {/* if tiling - pixmap has to be sized exactly as the image */ |
406 | {/* if tiling - pixmap has to be sized exactly as the image */ |
417 | if (h_scale == 0) |
407 | if (h_scale == 0) |
418 | new_pmap_width = result->width; |
408 | new_pmap_width = result->width; |
419 | if (v_scale == 0) |
409 | if (v_scale == 0) |
420 | new_pmap_height = result->height; |
410 | new_pmap_height = result->height; |
|
|
411 | /* we also need to tile our image in one or both directions */ |
|
|
412 | if (h_scale == 0 || v_scale == 0) |
|
|
413 | { |
|
|
414 | ASImage *tmp = tile_asimage (target->asv, result, |
|
|
415 | (h_scale > 0) ? 0 : (int)result->width - x, |
|
|
416 | (v_scale > 0) ? 0 : (int)result->height - y, |
|
|
417 | result->width, result->height, |
|
|
418 | TINT_LEAVE_SAME, ASA_XImage, |
|
|
419 | 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
420 | if (tmp) |
|
|
421 | { |
|
|
422 | if (result != original_asim) |
|
|
423 | destroy_asimage (&result); |
|
|
424 | result = tmp; |
|
|
425 | } |
|
|
426 | } |
421 | } |
427 | } |
422 | else |
428 | else |
423 | {/* if blending background and image - pixmap has to be sized same as target window */ |
429 | {/* if blending background and image - pixmap has to be sized same as target window */ |
424 | ASImageLayer *layers = create_image_layers (2); |
430 | ASImageLayer *layers = create_image_layers (2); |
425 | ASImage *merged_im = NULL; |
431 | ASImage *merged_im = NULL; |
… | |
… | |
429 | layers[0].clip_height = target_height; |
435 | layers[0].clip_height = target_height; |
430 | layers[0].tint = background_tint; |
436 | layers[0].tint = background_tint; |
431 | layers[1].im = result; |
437 | layers[1].im = result; |
432 | if (w <= 0) |
438 | if (w <= 0) |
433 | {/* tile horizontally */ |
439 | {/* tile horizontally */ |
434 | layers[1].dst_x = dst_x - (int)result->width; |
440 | while (x > 0) x -= (int)result->width; |
|
|
441 | layers[1].dst_x = x; |
435 | layers[1].clip_width = result->width; |
442 | layers[1].clip_width = result->width+target_width; |
436 | } |
443 | } |
437 | else |
444 | else |
438 | {/* clip horizontally */ |
445 | {/* clip horizontally */ |
439 | layers[1].dst_x = dst_x; |
446 | layers[1].dst_x = x; |
440 | layers[1].clip_width = clip_width; |
447 | layers[1].clip_width = result->width; |
441 | } |
448 | } |
442 | if (h <= 0) |
449 | if (h <= 0) |
443 | { |
450 | { |
444 | layers[1].dst_y = dst_y - (int)result->height; |
451 | while (y > 0) y -= (int)result->height; |
|
|
452 | layers[1].dst_y = y; |
|
|
453 | layers[1].clip_height = result->height + target_height; |
|
|
454 | } |
|
|
455 | else |
|
|
456 | { |
|
|
457 | layers[1].dst_y = y; |
445 | layers[1].clip_height = result->height; |
458 | layers[1].clip_height = result->height; |
446 | } |
|
|
447 | else |
|
|
448 | { |
|
|
449 | layers[1].dst_y = dst_y; |
|
|
450 | layers[1].clip_height = clip_height; |
|
|
451 | } |
459 | } |
452 | if (target->rs[Rs_blendtype]) |
460 | if (target->rs[Rs_blendtype]) |
453 | { |
461 | { |
454 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
462 | layers[1].merge_scanlines = blend_scanlines_name2func (target->rs[Rs_blendtype]); |
455 | if (layers[1].merge_scanlines == NULL) |
463 | if (layers[1].merge_scanlines == NULL) |
… | |
… | |
460 | if (tmp) |
468 | if (tmp) |
461 | { |
469 | { |
462 | if (result != original_asim) |
470 | if (result != original_asim) |
463 | destroy_asimage (&result); |
471 | destroy_asimage (&result); |
464 | result = tmp; |
472 | result = tmp; |
465 | dst_x = dst_y = 0; |
|
|
466 | clip_width = target_width; |
|
|
467 | clip_height = target_height; |
|
|
468 | } |
473 | } |
469 | free (layers); |
474 | free (layers); |
470 | } |
475 | } |
471 | } |
476 | } |
472 | |
477 | |
… | |
… | |
497 | } |
502 | } |
498 | /* fill with background color ( if result's not completely overlapping it)*/ |
503 | /* fill with background color ( if result's not completely overlapping it)*/ |
499 | gcv.foreground = target->pix_colors[Color_bg]; |
504 | gcv.foreground = target->pix_colors[Color_bg]; |
500 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
505 | gc = XCreateGC (target->dpy, target->vt, GCForeground, &gcv); |
501 | |
506 | |
|
|
507 | int src_x = 0, src_y = 0, dst_x = 0, dst_y = 0; |
|
|
508 | int dst_width = result->width, dst_height = result->height; |
|
|
509 | if (background == NULL) |
|
|
510 | { |
|
|
511 | if (h_scale > 0) |
|
|
512 | src_x = make_clip_rectangle (x, result->width, new_pmap_width, dst_x, dst_width); |
|
|
513 | if (v_scale > 0) |
|
|
514 | src_y = make_clip_rectangle (y, result->height, new_pmap_height, dst_y, dst_height); |
|
|
515 | |
502 | if (dst_x > 0 || dst_y > 0 |
516 | if (dst_x > 0 || dst_y > 0 |
503 | || dst_x + clip_width < new_pmap_width |
517 | || dst_x + dst_width < new_pmap_width |
504 | || dst_y + clip_height < new_pmap_height) |
518 | || dst_y + dst_height < new_pmap_height) |
505 | { |
519 | { |
506 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
520 | XFillRectangle (target->dpy, pixmap, gc, 0, 0, new_pmap_width, new_pmap_height); |
507 | } |
521 | } |
|
|
522 | } |
|
|
523 | |
508 | /* put result on pixmap */ |
524 | /* put result on pixmap */ |
|
|
525 | if (dst_x < new_pmap_width && dst_y < new_pmap_height) |
509 | asimage2drawable (target->asv, pixmap, result, gc, 0, 0, dst_x, dst_y, clip_width, clip_height, True); |
526 | asimage2drawable (target->asv, pixmap, result, gc, src_x, src_y, dst_x, dst_y, dst_width, dst_height, True); |
510 | |
527 | |
511 | /* set target's background to pixmap */ |
528 | if (result != background && result != original_asim) |
512 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
529 | destroy_asimage (&result); |
513 | |
530 | |
514 | XFreeGC (target->dpy, gc); |
531 | XFreeGC (target->dpy, gc); |
515 | } |
532 | } |
516 | else |
|
|
517 | { |
|
|
518 | /* set target background to a pixel */ |
|
|
519 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
520 | } |
|
|
521 | |
533 | |
522 | return true; |
534 | return true; |
523 | } |
535 | } |
524 | #endif |
536 | # endif /* HAVE_AFTERIMAGE */ |
525 | |
537 | |
526 | void |
538 | bool |
527 | rxvt_term::resize_pixmap () |
539 | bgPixmap_t::set_file (const char *file) |
528 | { |
|
|
529 | XGCValues gcvalue; |
|
|
530 | GC gc; |
|
|
531 | unsigned int w = bgPixmap.h_scale*szHint.width/100; |
|
|
532 | unsigned int h = bgPixmap.v_scale*szHint.height/100; |
|
|
533 | int x = bgPixmap.h_align*szHint.width/100; |
|
|
534 | int y = bgPixmap.v_align*szHint.height/100; |
|
|
535 | #ifdef HAVE_AFTERIMAGE |
|
|
536 | ASImage *im = bgPixmap.original_asim; |
|
|
537 | #else |
|
|
538 | void *im = NULL; |
|
|
539 | #endif |
|
|
540 | /* preliminary cleanup - this needs to be integrated with check_our_parents() code */ |
|
|
541 | if (bgPixmap.pixmap != None) |
|
|
542 | { |
|
|
543 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
544 | bgPixmap.pixmap = None ; |
|
|
545 | } |
|
|
546 | #ifdef ENABLE_TRANSPARENCY |
|
|
547 | if (option(Opt_transparent) && am_transparent) |
|
|
548 | { |
|
|
549 | /* we need to re-generate transparency pixmap in that case ! */ |
|
|
550 | check_our_parents (); |
|
|
551 | return; |
|
|
552 | } |
|
|
553 | #endif |
|
|
554 | |
|
|
555 | if (im == NULL) |
|
|
556 | { /* So be it: I'm not using pixmaps */ |
|
|
557 | XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
|
|
558 | return; |
|
|
559 | } |
|
|
560 | |
|
|
561 | gcvalue.foreground = pix_colors[Color_bg]; |
|
|
562 | gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); |
|
|
563 | |
|
|
564 | /* don't zoom pixmap too much nor expand really small pixmaps */ |
|
|
565 | if (w > 16000) |
|
|
566 | w = 1; |
|
|
567 | if (h > 16000) |
|
|
568 | h = 1; |
|
|
569 | |
|
|
570 | #ifdef HAVE_AFTERIMAGE |
|
|
571 | if (w == 0) |
|
|
572 | w = im->width; |
|
|
573 | if (h == 0) |
|
|
574 | h = im->height; |
|
|
575 | |
|
|
576 | if (w != im->width || h != im->height) |
|
|
577 | { |
|
|
578 | ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
579 | if (tmp != NULL) |
|
|
580 | im = tmp; |
|
|
581 | } |
|
|
582 | bgPixmap.pmap_width = MIN(w,szHint.width); |
|
|
583 | bgPixmap.pmap_height = MIN(h,szHint.height); |
|
|
584 | #if 0 /* TODO: fix that! */ |
|
|
585 | if (x != 0 || y != 0) |
|
|
586 | { |
|
|
587 | ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
588 | if (tmp != NULL) |
|
|
589 | { |
|
|
590 | if (im != bgPixmap.original_asim) |
|
|
591 | destroy_asimage (&im); |
|
|
592 | im = tmp; |
|
|
593 | } |
|
|
594 | } |
|
|
595 | #endif |
|
|
596 | bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth); |
|
|
597 | bgPixmap.pmap_depth = depth; |
|
|
598 | |
|
|
599 | asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True); |
|
|
600 | |
|
|
601 | if (im != bgPixmap.original_asim) |
|
|
602 | destroy_asimage (&im); |
|
|
603 | #endif |
|
|
604 | if( bgPixmap.pixmap ) |
|
|
605 | XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap); |
|
|
606 | |
|
|
607 | XFreeGC (dpy, gc); |
|
|
608 | } |
|
|
609 | |
|
|
610 | void |
|
|
611 | rxvt_term::set_bgPixmap (const char *file) |
|
|
612 | { |
540 | { |
613 | char *f; |
541 | char *f; |
614 | |
542 | |
615 | assert (file != NULL); |
543 | assert (file != NULL); |
616 | |
544 | |
617 | if (bgPixmap.pixmap != None) |
|
|
618 | { |
|
|
619 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
620 | bgPixmap.pixmap = None; |
|
|
621 | } |
|
|
622 | |
|
|
623 | XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); |
|
|
624 | if (*file != '\0') |
545 | if (*file != '\0') |
625 | { |
546 | { |
626 | #ifdef HAVE_AFTERIMAGE |
547 | # ifdef HAVE_AFTERIMAGE |
627 | if (asimman == NULL) |
548 | if (target->asimman == NULL) |
628 | asimman = create_generic_imageman(rs[Rs_path]); |
549 | target->asimman = create_generic_imageman(target->rs[Rs_path]); |
629 | if ((f = strchr (file, ';')) == NULL) |
550 | if ((f = strchr (file, ';')) == NULL) |
630 | bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); |
551 | original_asim = get_asimage( target->asimman, file, 0xFFFFFFFF, 100 ); |
631 | else |
552 | else |
632 | { |
553 | { |
633 | size_t len = f - file; |
554 | size_t len = f - file; |
634 | f = (char *)malloc (len + 1); |
555 | f = (char *)malloc (len + 1); |
635 | strncpy (f, file, len); |
556 | strncpy (f, file, len); |
636 | f[len] = '\0'; |
557 | f[len] = '\0'; |
637 | bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); |
558 | original_asim = get_asimage( target->asimman, f, 0xFFFFFFFF, 100 ); |
638 | free( f ); |
559 | free( f ); |
639 | } |
560 | } |
|
|
561 | return (original_asim != NULL); |
640 | #endif |
562 | # endif |
641 | } |
563 | } |
642 | |
564 | return false; |
643 | resize_pixmap (); |
|
|
644 | } |
565 | } |
645 | |
566 | |
646 | #endif /* XPM_BACKGROUND */ |
567 | # endif /* XPM_BACKGROUND */ |
|
|
568 | |
|
|
569 | # ifdef ENABLE_TRANSPARENCY |
|
|
570 | bool |
|
|
571 | bgPixmap_t::set_transparent () |
|
|
572 | { |
|
|
573 | if (!(flags & isTransparent)) |
|
|
574 | { |
|
|
575 | flags |= isTransparent; |
|
|
576 | return true; |
|
|
577 | } |
|
|
578 | } |
|
|
579 | |
|
|
580 | bool |
|
|
581 | bgPixmap_t::set_blur_radius (const char *geom) |
|
|
582 | { |
|
|
583 | int changed = 0; |
|
|
584 | unsigned int hr, vr; |
|
|
585 | int junk; |
|
|
586 | int geom_flags = XParseGeometry (geom, &junk, &junk, &hr, &vr); |
|
|
587 | if (!(geom_flags&WidthValue)) |
|
|
588 | hr = 1; |
|
|
589 | if (!(geom_flags&HeightValue)) |
|
|
590 | vr = hr; |
|
|
591 | |
|
|
592 | if (h_blurRadius != hr) |
|
|
593 | { |
|
|
594 | ++changed; |
|
|
595 | h_blurRadius = hr; |
|
|
596 | } |
|
|
597 | if (v_blurRadius != vr) |
|
|
598 | { |
|
|
599 | ++changed; |
|
|
600 | v_blurRadius = vr; |
|
|
601 | } |
|
|
602 | return (changed>0); |
|
|
603 | } |
|
|
604 | |
|
|
605 | static inline unsigned long |
|
|
606 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
|
|
607 | { |
|
|
608 | unsigned long flags = 0; |
|
|
609 | |
|
|
610 | if (shade > 0 && shade <100) |
|
|
611 | flags |= bgPixmap_t::tintNeeded; |
|
|
612 | else if (tint) |
|
|
613 | { |
|
|
614 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
615 | tint->get (c); |
|
|
616 | |
|
|
617 | flags |= bgPixmap_t::tintNeeded; |
|
|
618 | if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700) |
|
|
619 | && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700)) |
|
|
620 | { |
|
|
621 | flags |= bgPixmap_t::tintNeeded; |
|
|
622 | #define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) |
|
|
623 | if (IS_COMPONENT_WHOLESOME (c.r) |
|
|
624 | && IS_COMPONENT_WHOLESOME (c.g) |
|
|
625 | && IS_COMPONENT_WHOLESOME (c.b)) |
|
|
626 | flags |= bgPixmap_t::tintServerSide; |
|
|
627 | #undef IS_COMPONENT_WHOLESOME |
|
|
628 | } |
|
|
629 | } |
|
|
630 | return flags; |
|
|
631 | } |
|
|
632 | |
|
|
633 | bool |
|
|
634 | bgPixmap_t::set_tint (rxvt_color &new_tint) |
|
|
635 | { |
|
|
636 | if (tint != new_tint) |
|
|
637 | { |
|
|
638 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
|
|
639 | tint = new_tint; |
|
|
640 | flags = (flags & ~tintFlags) | new_flags | tintSet; |
|
|
641 | return true; |
|
|
642 | } |
|
|
643 | return false; |
|
|
644 | } |
|
|
645 | |
|
|
646 | bool |
|
|
647 | bgPixmap_t::unset_tint () |
|
|
648 | { |
|
|
649 | unsigned long new_flags = compute_tint_shade_flags (NULL, shade); |
|
|
650 | |
|
|
651 | if (new_flags != (flags & tintFlags)) |
|
|
652 | { |
|
|
653 | flags = (flags&~tintFlags)|new_flags; |
|
|
654 | return true; |
|
|
655 | } |
|
|
656 | return false; |
|
|
657 | } |
|
|
658 | |
|
|
659 | bool |
|
|
660 | bgPixmap_t::set_shade (const char *shade_str) |
|
|
661 | { |
|
|
662 | int new_shade = (shade_str) ? atoi (shade_str) : 0; |
|
|
663 | |
|
|
664 | if (new_shade == 100) |
|
|
665 | new_shade = 0; |
|
|
666 | |
|
|
667 | if (new_shade != shade) |
|
|
668 | { |
|
|
669 | unsigned long new_flags = compute_tint_shade_flags (&tint, new_shade); |
|
|
670 | shade = new_shade; |
|
|
671 | flags = (flags & ~tintFlags) | new_flags; |
|
|
672 | return true; |
|
|
673 | } |
|
|
674 | return false; |
|
|
675 | } |
|
|
676 | |
|
|
677 | |
|
|
678 | /* make_transparency_pixmap() |
|
|
679 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
|
|
680 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
|
|
681 | * our window. |
|
|
682 | */ |
|
|
683 | unsigned long |
|
|
684 | bgPixmap_t::make_transparency_pixmap () |
|
|
685 | { |
|
|
686 | unsigned long result = 0; |
|
|
687 | |
|
|
688 | if (target == NULL) |
|
|
689 | return 0; |
|
|
690 | |
|
|
691 | /* root dimentions may change from call to call - but Display structure should |
|
|
692 | * be always up-to-date, so let's use it : |
|
|
693 | */ |
|
|
694 | Window root = target->display->root; |
|
|
695 | int screen = target->display->screen; |
|
|
696 | Display *dpy = target->dpy; |
|
|
697 | int root_width = DisplayWidth (dpy, screen); |
|
|
698 | int root_height = DisplayHeight (dpy, screen); |
|
|
699 | unsigned int root_pmap_width, root_pmap_height; |
|
|
700 | int window_width = target->szHint.width; |
|
|
701 | int window_height = target->szHint.height; |
|
|
702 | int sx, sy; |
|
|
703 | XGCValues gcv; |
|
|
704 | |
|
|
705 | target->get_window_origin (sx, sy); |
|
|
706 | |
|
|
707 | /* check if we are outside of the visible part of the virtual screen : */ |
|
|
708 | if (sx + window_width <= 0 || sy + window_height <= 0 |
|
|
709 | || sx >= root_width || sy >= root_height) |
|
|
710 | return 0; |
|
|
711 | |
|
|
712 | if (root_pixmap != None) |
|
|
713 | {/* we want to validate the pixmap and get it's size at the same time : */ |
|
|
714 | int junk; |
|
|
715 | unsigned int ujunk; |
|
|
716 | /* root pixmap may be bad - allow a error */ |
|
|
717 | target->allowedxerror = -1; |
|
|
718 | if (!XGetGeometry (dpy, root_pixmap, &root, &junk, &junk, &root_pmap_width, &root_pmap_height, &ujunk, &ujunk)) |
|
|
719 | root_pixmap = None; |
|
|
720 | target->allowedxerror = 0; |
|
|
721 | } |
|
|
722 | |
|
|
723 | Pixmap tiled_root_pmap = XCreatePixmap (dpy, root, window_width, window_height, root_depth); |
|
|
724 | GC gc = NULL; |
|
|
725 | |
|
|
726 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
|
|
727 | return 0; |
|
|
728 | |
|
|
729 | if (root_pixmap == None) |
|
|
730 | { /* use tricks to obtain the root background image :*/ |
|
|
731 | /* we want to create Overrideredirect window overlapping out window |
|
|
732 | with background type of Parent Relative and then grab it */ |
|
|
733 | XSetWindowAttributes attr; |
|
|
734 | Window src; |
|
|
735 | bool success = false; |
|
|
736 | |
|
|
737 | attr.background_pixmap = ParentRelative; |
|
|
738 | attr.backing_store = Always; |
|
|
739 | attr.event_mask = ExposureMask; |
|
|
740 | attr.override_redirect = True; |
|
|
741 | src = XCreateWindow (dpy, root, sx, sy, window_width, window_height, 0, |
|
|
742 | CopyFromParent, CopyFromParent, CopyFromParent, |
|
|
743 | CWBackPixmap|CWBackingStore|CWOverrideRedirect|CWEventMask, |
|
|
744 | &attr); |
|
|
745 | |
|
|
746 | if (src != None) |
|
|
747 | { |
|
|
748 | XEvent event; |
|
|
749 | int ev_count = 0; |
|
|
750 | XGrabServer (dpy); |
|
|
751 | XMapRaised (dpy, src); |
|
|
752 | XSync (dpy, False); |
|
|
753 | /* XSync should get window where it's properly exposed, |
|
|
754 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
|
|
755 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
|
|
756 | ++ev_count; |
|
|
757 | if (ev_count > 0); |
|
|
758 | { /* hooray! - we can grab the image! */ |
|
|
759 | gc = XCreateGC (dpy, root, 0, NULL); |
|
|
760 | if (gc) |
|
|
761 | { |
|
|
762 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
|
|
763 | success = true; |
|
|
764 | } |
|
|
765 | } |
|
|
766 | XDestroyWindow (dpy, src); |
|
|
767 | XUngrabServer (dpy); |
|
|
768 | //fprintf (stderr, "%s:%d: ev_count = %d\n", __FUNCTION__, __LINE__, ev_count); |
|
|
769 | } |
|
|
770 | if (!success) |
|
|
771 | { |
|
|
772 | XFreePixmap (dpy, tiled_root_pmap); |
|
|
773 | tiled_root_pmap = None; |
|
|
774 | } |
|
|
775 | else |
|
|
776 | result |= transpPmapTiled; |
|
|
777 | } |
|
|
778 | else |
|
|
779 | {/* strightforward pixmap copy */ |
|
|
780 | gcv.tile = root_pixmap; |
|
|
781 | gcv.fill_style = FillTiled; |
|
|
782 | while (sx < 0) sx += (int)window_width; |
|
|
783 | while (sy < 0) sy += (int)window_height; |
|
|
784 | gcv.ts_x_origin = -sx; |
|
|
785 | gcv.ts_y_origin = -sy; |
|
|
786 | gc = XCreateGC (dpy, root, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); |
|
|
787 | if (gc) |
|
|
788 | { |
|
|
789 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
|
|
790 | result |= transpPmapTiled; |
|
|
791 | } |
|
|
792 | } |
|
|
793 | |
|
|
794 | if (tiled_root_pmap != None) |
|
|
795 | { |
|
|
796 | if (flags & tintNeeded) |
|
|
797 | { |
|
|
798 | if ((flags & tintServerSide) |
|
|
799 | && h_blurRadius <= 1 && v_blurRadius <= 1 |
|
|
800 | # ifdef HAVE_AFTERIMAGE |
|
|
801 | && original_asim == NULL |
|
|
802 | # endif |
|
|
803 | ) |
|
|
804 | { /* In this case we can tint image server-side getting significant |
|
|
805 | * performance improvements, as we eliminate XImage transfer |
|
|
806 | */ |
|
|
807 | gcv.foreground = Pixel (tint); |
|
|
808 | gcv.function = GXand; |
|
|
809 | gcv.fill_style = FillSolid; |
|
|
810 | if (gc) |
|
|
811 | XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
812 | else |
|
|
813 | gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
814 | if (gc) |
|
|
815 | { |
|
|
816 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
|
|
817 | result |= transpPmapTinted; |
|
|
818 | } |
|
|
819 | } |
|
|
820 | } |
|
|
821 | if (pixmap) |
|
|
822 | XFreePixmap (dpy, pixmap); |
|
|
823 | pixmap = tiled_root_pmap; |
|
|
824 | pmap_width = window_width; |
|
|
825 | pmap_height = window_height; |
|
|
826 | pmap_depth = root_depth; |
|
|
827 | } |
|
|
828 | |
|
|
829 | if (gc) |
|
|
830 | XFreeGC (dpy, gc); |
|
|
831 | |
|
|
832 | return result; |
|
|
833 | } |
|
|
834 | |
|
|
835 | bool |
|
|
836 | bgPixmap_t::set_root_pixmap () |
|
|
837 | { |
|
|
838 | Pixmap new_root_pixmap = None; |
|
|
839 | |
|
|
840 | new_root_pixmap = target->get_pixmap_property (XA_XROOTPMAP_ID); |
|
|
841 | if (new_root_pixmap == None) |
|
|
842 | new_root_pixmap = target->get_pixmap_property (XA_ESETROOT_PMAP_ID); |
|
|
843 | |
|
|
844 | if (new_root_pixmap != root_pixmap) |
|
|
845 | { |
|
|
846 | root_pixmap = new_root_pixmap; |
|
|
847 | return true; |
|
|
848 | } |
|
|
849 | return false; |
|
|
850 | } |
|
|
851 | # endif /* ENABLE_TRANSPARENCY */ |
|
|
852 | |
|
|
853 | # ifndef HAVE_AFTERIMAGE |
|
|
854 | static void ShadeXImage(rxvt_term *term, XImage* srcImage, int shade, int rm, int gm, int bm); |
|
|
855 | #endif |
|
|
856 | |
|
|
857 | |
|
|
858 | bool |
|
|
859 | bgPixmap_t::render () |
|
|
860 | { |
|
|
861 | unsigned long background_flags = 0; |
|
|
862 | |
|
|
863 | if (target == NULL) |
|
|
864 | return false; |
|
|
865 | |
|
|
866 | invalidate(); |
|
|
867 | # ifdef ENABLE_TRANSPARENCY |
|
|
868 | if (flags & isTransparent) |
|
|
869 | { |
|
|
870 | /* we need to re-generate transparency pixmap in that case ! */ |
|
|
871 | background_flags = make_transparency_pixmap (); |
|
|
872 | if (background_flags == 0) |
|
|
873 | return false; |
|
|
874 | else if ((background_flags & transpTransformations) == (flags & transpTransformations) |
|
|
875 | && pmap_depth == target->depth) |
|
|
876 | flags = flags & ~isInvalid; |
|
|
877 | } |
|
|
878 | # endif |
|
|
879 | |
|
|
880 | XImage *result = NULL; |
|
|
881 | # ifdef HAVE_AFTERIMAGE |
|
|
882 | if (original_asim |
|
|
883 | || (background_flags & transpTransformations) != (flags & transpTransformations)) |
|
|
884 | { |
|
|
885 | ASImage *background = NULL; |
|
|
886 | ARGB32 as_tint = TINT_LEAVE_SAME; |
|
|
887 | if (background_flags) |
|
|
888 | background = pixmap2ximage (target->asv, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, 100); |
|
|
889 | |
|
|
890 | if (!(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
891 | { |
|
|
892 | ShadingInfo as_shade; |
|
|
893 | as_shade.shading = (shade == 0) ? 100 : shade; |
|
|
894 | |
|
|
895 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
896 | if (flags & tintSet) |
|
|
897 | tint.get (c); |
|
|
898 | as_shade.tintColor.red = c.r; |
|
|
899 | as_shade.tintColor.green = c.g; |
|
|
900 | as_shade.tintColor.blue = c.b; |
|
|
901 | |
|
|
902 | as_tint = shading2tint32 (&as_shade); |
|
|
903 | } |
|
|
904 | if (render_asim (background, as_tint)) |
|
|
905 | flags = flags & ~isInvalid; |
|
|
906 | if (background) |
|
|
907 | destroy_asimage (&background); |
|
|
908 | } |
|
|
909 | else if (background_flags && pmap_depth != target->depth) |
|
|
910 | { |
|
|
911 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
912 | } |
|
|
913 | # else /* our own client-side tinting */ |
|
|
914 | if (background_flags && (flags & isInvalid)) |
|
|
915 | { |
|
|
916 | result = XGetImage (target->dpy, pixmap, 0, 0, pmap_width, pmap_height, AllPlanes, ZPixmap); |
|
|
917 | if (result != NULL && !(background_flags & transpPmapTinted) && (flags & tintNeeded)) |
|
|
918 | { |
|
|
919 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
920 | if (flags & tintSet) |
|
|
921 | tint.get (c); |
|
|
922 | ShadeXImage (target, result, shade, c.r, c.g, c.b); |
|
|
923 | } |
|
|
924 | } |
|
|
925 | # endif |
|
|
926 | if (result != NULL) |
|
|
927 | { |
|
|
928 | GC gc = XCreateGC (target->dpy, target->vt, 0UL, NULL); |
|
|
929 | if (gc) |
|
|
930 | { |
|
|
931 | if (pmap_depth != target->depth && pixmap != None) |
|
|
932 | { |
|
|
933 | XFreePixmap (target->dpy, pixmap); |
|
|
934 | pixmap = None; |
|
|
935 | } |
|
|
936 | if (pixmap == None) |
|
|
937 | { |
|
|
938 | pixmap = XCreatePixmap (target->dpy, target->vt, result->width, result->height, target->depth); |
|
|
939 | pmap_width = result->width; |
|
|
940 | pmap_height = result->height; |
|
|
941 | pmap_depth = target->depth; |
|
|
942 | } |
|
|
943 | XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); |
|
|
944 | XFreeGC (target->dpy, gc); |
|
|
945 | flags = flags & ~isInvalid; |
|
|
946 | } |
|
|
947 | XDestroyImage (result); |
|
|
948 | } |
|
|
949 | |
|
|
950 | if (flags & isInvalid) |
|
|
951 | { |
|
|
952 | if (pixmap != None) |
|
|
953 | { |
|
|
954 | XFreePixmap (target->dpy, pixmap); |
|
|
955 | pixmap = None; |
|
|
956 | } |
|
|
957 | // TODO : we need to get rid of that garbadge : |
|
|
958 | target->am_transparent = target->am_pixmap_trans = 0; |
|
|
959 | } |
|
|
960 | else |
|
|
961 | target->am_transparent = target->am_pixmap_trans = 1; |
|
|
962 | |
|
|
963 | apply (); |
|
|
964 | |
|
|
965 | return true; |
|
|
966 | } |
|
|
967 | |
|
|
968 | bool |
|
|
969 | bgPixmap_t::set_target (rxvt_term *new_target) |
|
|
970 | { |
|
|
971 | if (new_target) |
|
|
972 | if (target != new_target) |
|
|
973 | { |
|
|
974 | target = new_target; |
|
|
975 | # ifdef ENABLE_TRANSPARENCY |
|
|
976 | root_depth = DefaultDepthOfScreen (ScreenOfDisplay (target->dpy, target->display->screen)); |
|
|
977 | # endif |
|
|
978 | return true; |
|
|
979 | } |
|
|
980 | return false; |
|
|
981 | } |
|
|
982 | |
|
|
983 | void |
|
|
984 | bgPixmap_t::apply() |
|
|
985 | { |
|
|
986 | if (target) |
|
|
987 | { |
|
|
988 | if (pixmap != None) |
|
|
989 | { /* set target's background to pixmap */ |
|
|
990 | # ifdef ENABLE_TRANSPARENCY |
|
|
991 | if (flags & isTransparent) |
|
|
992 | { |
|
|
993 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
|
|
994 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
|
|
995 | # if HAVE_SCROLLBARS |
|
|
996 | if (target->scrollBar.win) |
|
|
997 | XSetWindowBackgroundPixmap (target->dpy, target->scrollBar.win, ParentRelative); |
|
|
998 | # endif |
|
|
999 | } |
|
|
1000 | else |
|
|
1001 | # endif |
|
|
1002 | { |
|
|
1003 | /* force old pixmap dereference in case it was transparent before :*/ |
|
|
1004 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1005 | XSetWindowBackgroundPixmap (target->dpy, target->vt, pixmap); |
|
|
1006 | /* do we also need to set scrollbar's background here ? */ |
|
|
1007 | # if HAVE_SCROLLBARS |
|
|
1008 | if (target->scrollBar.win) |
|
|
1009 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1010 | # endif |
|
|
1011 | } |
|
|
1012 | } |
|
|
1013 | else |
|
|
1014 | { /* set target background to a pixel */ |
|
|
1015 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
|
|
1016 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
|
|
1017 | /* do we also need to set scrollbar's background here ? */ |
|
|
1018 | # if HAVE_SCROLLBARS |
|
|
1019 | if (target->scrollBar.win) |
|
|
1020 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
|
|
1021 | # endif |
|
|
1022 | } |
|
|
1023 | /* don't want Expose on the parent */ |
|
|
1024 | XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, False); |
|
|
1025 | /* do want Expose on the vt */ |
|
|
1026 | XClearArea (target->dpy, target->parent[0], 0, 0, 0, 0, True); |
|
|
1027 | #if HAVE_SCROLLBARS |
|
|
1028 | if (target->scrollBar.win) |
|
|
1029 | { |
|
|
1030 | target->scrollBar.setIdle (); |
|
|
1031 | target->scrollbar_show (0); |
|
|
1032 | } |
|
|
1033 | #endif |
|
|
1034 | /* Is that really neccessary? we did a XClearArea to generate Expose events alreday ! */ |
|
|
1035 | target->want_refresh = target->want_full_refresh = 1; |
|
|
1036 | /* TODO: why do we need a flush here ??? It causes segfault on resize ! */ |
|
|
1037 | // target->flush (); |
|
|
1038 | } |
|
|
1039 | } |
647 | #endif /* HAVE_BG_PIXMAP */ |
1040 | #endif /* HAVE_BG_PIXMAP */ |
|
|
1041 | |
|
|
1042 | |
|
|
1043 | void |
|
|
1044 | rxvt_term::get_window_origin (int &x, int &y) |
|
|
1045 | { |
|
|
1046 | Window cr; |
|
|
1047 | XTranslateCoordinates (dpy, parent[0], display->root, 0, 0, &x, &y, &cr); |
|
|
1048 | } |
|
|
1049 | |
|
|
1050 | Pixmap |
|
|
1051 | rxvt_term::get_pixmap_property (int prop_id) |
|
|
1052 | { |
|
|
1053 | if (prop_id > 0 && prop_id < NUM_XA) |
|
|
1054 | if (xa[prop_id]) |
|
|
1055 | { |
|
|
1056 | int aformat, rootdepth; |
|
|
1057 | unsigned long nitems, bytes_after; |
|
|
1058 | Atom atype; |
|
|
1059 | unsigned char *prop = NULL; |
|
|
1060 | int result = XGetWindowProperty (dpy, display->root, xa[prop_id], |
|
|
1061 | 0L, 1L, False, XA_PIXMAP, &atype, &aformat, |
|
|
1062 | &nitems, &bytes_after, &prop); |
|
|
1063 | if (result == Success && prop && atype == XA_PIXMAP) |
|
|
1064 | { |
|
|
1065 | return *(Pixmap *)prop; |
|
|
1066 | } |
|
|
1067 | } |
|
|
1068 | return None; |
|
|
1069 | } |
|
|
1070 | |
648 | |
1071 | |
649 | #ifdef ENABLE_TRANSPARENCY |
1072 | #ifdef ENABLE_TRANSPARENCY |
650 | #ifndef HAVE_AFTERIMAGE |
1073 | #ifndef HAVE_AFTERIMAGE |
651 | /* taken from aterm-0.4.2 */ |
1074 | /* taken from aterm-0.4.2 */ |
652 | |
1075 | |
… | |
… | |
662 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
1085 | unsigned int upper_lim_r, upper_lim_g, upper_lim_b; |
663 | int i; |
1086 | int i; |
664 | |
1087 | |
665 | Visual *visual = term->visual; |
1088 | Visual *visual = term->visual; |
666 | |
1089 | |
667 | if( visual->c_class != TrueColor || srcImage->format != ZPixmap ) return ; |
1090 | if (visual->c_class != TrueColor || srcImage->format != ZPixmap) return ; |
668 | |
1091 | |
|
|
1092 | if (shade == 0) |
|
|
1093 | shade = 100; |
|
|
1094 | |
669 | /* for convenience */ |
1095 | /* for convenience */ |
670 | mask_r = visual->red_mask; |
1096 | mask_r = visual->red_mask; |
671 | mask_g = visual->green_mask; |
1097 | mask_g = visual->green_mask; |
672 | mask_b = visual->blue_mask; |
1098 | mask_b = visual->blue_mask; |
673 | |
1099 | |
… | |
… | |
892 | } |
1318 | } |
893 | |
1319 | |
894 | void |
1320 | void |
895 | rxvt_term::check_our_parents_cb (time_watcher &w) |
1321 | rxvt_term::check_our_parents_cb (time_watcher &w) |
896 | { |
1322 | { |
|
|
1323 | #if 0 /* replaced by a bgPixmap_t::render() - leve here temporarily for reference */ |
|
|
1324 | |
897 | int i, pchanged, aformat, rootdepth; |
1325 | int i, aformat, rootdepth; |
898 | unsigned long nitems, bytes_after; |
1326 | unsigned long nitems, bytes_after; |
899 | Atom atype; |
1327 | Atom atype; |
900 | unsigned char *prop = NULL; |
1328 | unsigned char *prop = NULL; |
901 | Window root, oldp, *list; |
1329 | Window root, oldp, *list; |
902 | Pixmap rootpixmap = None; |
1330 | Pixmap rootpixmap = None; |
903 | XWindowAttributes wattr, wrootattr; |
1331 | XWindowAttributes wattr, wrootattr; |
904 | int sx, sy; |
1332 | int sx, sy; |
905 | Window cr; |
1333 | Window cr; |
906 | unsigned int rootpixmap_w = 0, rootpixmap_h = 0; |
1334 | unsigned int rootpixmap_w = 0, rootpixmap_h = 0; |
907 | |
1335 | |
908 | pchanged = 0; |
|
|
909 | |
|
|
910 | if (!option (Opt_transparent)) |
1336 | if (!option (Opt_transparent)) |
911 | return /*pchanged*/; /* Don't try any more */ |
1337 | return; /* Don't try any more */ |
912 | |
|
|
913 | #if 0 |
1338 | #if 0 |
914 | struct timeval stv; |
1339 | struct timeval stv; |
915 | gettimeofday (&stv,NULL); |
1340 | gettimeofday (&stv,NULL); |
916 | #define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ |
1341 | #define PRINT_BACKGROUND_OP_TIME do{ struct timeval tv;gettimeofday (&tv,NULL); tv.tv_sec-= stv.tv_sec;\ |
917 | fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\ |
1342 | fprintf (stderr,"%d: elapsed %ld usec\n",__LINE__,\ |
… | |
… | |
928 | |
1353 | |
929 | if (rootdepth != wattr.depth) |
1354 | if (rootdepth != wattr.depth) |
930 | { |
1355 | { |
931 | if (am_transparent) |
1356 | if (am_transparent) |
932 | { |
1357 | { |
933 | pchanged = 1; |
|
|
934 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
1358 | XSetWindowBackground (dpy, vt, pix_colors_focused[Color_bg]); |
935 | am_transparent = am_pixmap_trans = 0; |
1359 | am_transparent = am_pixmap_trans = 0; |
936 | } |
1360 | } |
937 | |
1361 | |
938 | return /*pchanged*/; /* Don't try any more */ |
1362 | return; /* Don't try any more */ |
939 | } |
1363 | } |
940 | |
1364 | |
941 | /* Get all X ops out of the queue so that our information is up-to-date. */ |
1365 | /* Get all X ops out of the queue so that our information is up-to-date. */ |
942 | XSync (dpy, False); |
1366 | XSync (dpy, False); |
943 | |
1367 | |
… | |
… | |
1001 | whole_tint = (IS_COMPONENT_WHOLESOME(c.r) |
1425 | whole_tint = (IS_COMPONENT_WHOLESOME(c.r) |
1002 | && IS_COMPONENT_WHOLESOME(c.g) |
1426 | && IS_COMPONENT_WHOLESOME(c.g) |
1003 | && IS_COMPONENT_WHOLESOME(c.b)); |
1427 | && IS_COMPONENT_WHOLESOME(c.b)); |
1004 | no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); |
1428 | no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); |
1005 | #undef IS_COMPONENT_WHOLESOME |
1429 | #undef IS_COMPONENT_WHOLESOME |
1006 | /* theer are no performance advantages to reusing same pixmap */ |
|
|
1007 | if (bgPixmap.pixmap != None) |
|
|
1008 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
1009 | bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth); |
|
|
1010 | bgPixmap.pmap_width = szHint.width; |
|
|
1011 | bgPixmap.pmap_height = szHint.height; |
|
|
1012 | bgPixmap.pmap_depth = rootdepth; |
|
|
1013 | |
1430 | |
1014 | #if 0 /* TODO : identify cases where this will be detrimental to performance : */ |
1431 | bgPixmap.make_transparency_pixmap(); |
1015 | /* we want to tile root pixmap into our own pixmap in this cases : |
|
|
1016 | * 1) rootpixmap does not cover our window entirely |
|
|
1017 | * 2) whole_tint - we can use server-side tinting or tinting disabled |
|
|
1018 | */ |
|
|
1019 | if ( whole_tint || no_tint || pmap_w < sx + szHint.width || pmap_h < sy + szHint.height) |
|
|
1020 | { |
|
|
1021 | } |
|
|
1022 | #endif |
|
|
1023 | gcvalue.tile = rootpixmap; |
|
|
1024 | gcvalue.fill_style = FillTiled; |
|
|
1025 | gcvalue.ts_x_origin = -sx; |
|
|
1026 | gcvalue.ts_y_origin = -sy; |
|
|
1027 | gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue); |
|
|
1028 | XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height); |
|
|
1029 | |
1432 | |
1030 | if (whole_tint && !no_tint) |
1433 | if (whole_tint && !no_tint) |
1031 | { |
1434 | { |
1032 | /* In this case we can tint image server-side getting significant |
|
|
1033 | * performance improvements, as we eliminate XImage transfer |
|
|
1034 | */ |
|
|
1035 | gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]); |
|
|
1036 | gcvalue.function = GXand; |
|
|
1037 | gcvalue.fill_style = FillSolid; |
|
|
1038 | XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue); |
|
|
1039 | XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height); |
|
|
1040 | } |
1435 | } |
1041 | success = True; |
1436 | success = True; |
1042 | #ifdef HAVE_AFTERIMAGE |
1437 | #ifdef HAVE_AFTERIMAGE |
1043 | if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) |
1438 | if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) |
1044 | { |
1439 | { |
… | |
… | |
1075 | { |
1470 | { |
1076 | destroy_asimage (&back_im); |
1471 | destroy_asimage (&back_im); |
1077 | back_im = tmp; |
1472 | back_im = tmp; |
1078 | } |
1473 | } |
1079 | } |
1474 | } |
1080 | |
1475 | /* TODO: temporary fix - redo the logic, so that same function can do both |
1081 | if (bgPixmap.original_asim != NULL) |
1476 | transparency and non-transparency */ |
1082 | { |
1477 | bgPixmap.render_asim (back_im, tint); |
1083 | ASImageLayer *layers = create_image_layers (2); |
|
|
1084 | ASImage *merged_im = NULL; |
|
|
1085 | int fore_w, fore_h; |
|
|
1086 | |
|
|
1087 | layers[0].im = back_im; |
|
|
1088 | layers[0].clip_width = szHint.width; |
|
|
1089 | layers[0].clip_height = szHint.height; |
|
|
1090 | layers[0].tint = tint; |
|
|
1091 | layers[1].im = bgPixmap.original_asim; |
|
|
1092 | |
|
|
1093 | fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100; |
|
|
1094 | fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100; |
|
|
1095 | |
|
|
1096 | if (fore_w != bgPixmap.original_asim->width |
|
|
1097 | || fore_h != bgPixmap.original_asim->height) |
|
|
1098 | { |
|
|
1099 | layers[1].im = scale_asimage (asv, |
|
|
1100 | bgPixmap.original_asim, |
|
|
1101 | fore_w, fore_h, |
|
|
1102 | ASA_ASImage, 100, |
|
|
1103 | ASIMAGE_QUALITY_DEFAULT); |
|
|
1104 | } |
|
|
1105 | layers[1].clip_width = szHint.width; |
|
|
1106 | layers[1].clip_height = szHint.height; |
|
|
1107 | |
|
|
1108 | if (rs[Rs_blendtype]) |
|
|
1109 | { |
|
|
1110 | layers[1].merge_scanlines = blend_scanlines_name2func (rs[Rs_blendtype]); |
|
|
1111 | if (layers[1].merge_scanlines == NULL) |
|
|
1112 | layers[1].merge_scanlines = alphablend_scanlines; |
|
|
1113 | } |
|
|
1114 | PRINT_BACKGROUND_OP_TIME; |
|
|
1115 | merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height, |
|
|
1116 | ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); |
|
|
1117 | if (layers[1].im != bgPixmap.original_asim) |
|
|
1118 | destroy_asimage (&(layers[1].im)); |
|
|
1119 | free (layers); |
|
|
1120 | |
|
|
1121 | if (merged_im != NULL) |
|
|
1122 | { |
|
|
1123 | destroy_asimage (&back_im); |
|
|
1124 | back_im = merged_im; |
|
|
1125 | } |
|
|
1126 | PRINT_BACKGROUND_OP_TIME; |
|
|
1127 | } |
|
|
1128 | else if (tint != TINT_LEAVE_SAME) |
|
|
1129 | { |
|
|
1130 | ASImage* tmp = tile_asimage (asv, back_im, 0, 0, szHint.width, szHint.height, tint, ASA_XImage, 100, ASIMAGE_QUALITY_DEFAULT); |
|
|
1131 | if (tmp) |
|
|
1132 | { |
|
|
1133 | destroy_asimage (&back_im); |
|
|
1134 | back_im = tmp; |
|
|
1135 | } |
|
|
1136 | PRINT_BACKGROUND_OP_TIME; |
|
|
1137 | } |
|
|
1138 | asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True); |
|
|
1139 | destroy_asimage (&back_im); |
1478 | destroy_asimage (&back_im); |
|
|
1479 | |
1140 | } /* back_im != NULL */ |
1480 | } /* back_im != NULL */ |
1141 | else |
1481 | else |
1142 | success = False; |
1482 | success = False; |
1143 | } |
1483 | } |
1144 | #else /* HAVE_AFTERIMAGE */ |
1484 | #else /* HAVE_AFTERIMAGE */ |
… | |
… | |
1161 | #endif /* HAVE_AFTERIMAGE */ |
1501 | #endif /* HAVE_AFTERIMAGE */ |
1162 | PRINT_BACKGROUND_OP_TIME; |
1502 | PRINT_BACKGROUND_OP_TIME; |
1163 | |
1503 | |
1164 | if (gc != NULL) |
1504 | if (gc != NULL) |
1165 | XFreeGC (dpy, gc); |
1505 | XFreeGC (dpy, gc); |
1166 | |
1506 | |
|
|
1507 | bgPixmap.apply(); |
1167 | if (!success) |
1508 | if (!success) |
1168 | { |
|
|
1169 | if (am_transparent && am_pixmap_trans) |
|
|
1170 | { |
|
|
1171 | pchanged = 1; |
|
|
1172 | if (bgPixmap.pixmap != None) |
|
|
1173 | { |
|
|
1174 | XFreePixmap (dpy, bgPixmap.pixmap); |
|
|
1175 | bgPixmap.pixmap = None; |
|
|
1176 | } |
|
|
1177 | } |
|
|
1178 | |
|
|
1179 | am_pixmap_trans = 0; |
1509 | am_pixmap_trans = 0; |
1180 | } |
|
|
1181 | else |
1510 | else |
1182 | { |
1511 | { |
1183 | XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap); |
|
|
1184 | XClearWindow (dpy, parent[0]); |
|
|
1185 | |
|
|
1186 | if (!am_transparent || !am_pixmap_trans) |
|
|
1187 | pchanged = 1; |
|
|
1188 | |
|
|
1189 | am_transparent = am_pixmap_trans = 1; |
1512 | am_transparent = am_pixmap_trans = 1; |
1190 | } |
1513 | } |
1191 | } /* rootpixmap != None */ |
1514 | } /* rootpixmap != None */ |
1192 | |
1515 | |
1193 | if (am_pixmap_trans) |
1516 | if (am_pixmap_trans) |
1194 | XSetWindowBackgroundPixmap (dpy, vt, ParentRelative); |
1517 | { |
1195 | else |
|
|
1196 | return; |
|
|
1197 | |
|
|
1198 | if (scrollBar.win) |
1518 | if (scrollBar.win) |
1199 | { |
1519 | { |
1200 | XSetWindowBackgroundPixmap (dpy, scrollBar.win, ParentRelative); |
|
|
1201 | scrollBar.setIdle (); |
1520 | scrollBar.setIdle (); |
1202 | scrollbar_show (0); |
1521 | scrollbar_show (0); |
1203 | } |
1522 | } |
1204 | |
1523 | |
1205 | if (am_transparent) |
1524 | if (am_transparent) |
1206 | { |
1525 | { |
1207 | want_refresh = want_full_refresh = 1; |
1526 | want_refresh = want_full_refresh = 1; |
1208 | if (am_pixmap_trans) |
1527 | if (am_pixmap_trans) |
1209 | flush (); |
1528 | flush (); |
|
|
1529 | } |
1210 | } |
1530 | } |
1211 | |
1531 | #endif |
1212 | // return pchanged; |
|
|
1213 | } |
1532 | } |
1214 | #endif |
1533 | #endif |