ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xpm.C
(Generate patch)

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.54 by ayin, Thu Aug 2 00:09:54 2007 UTC vs.
Revision 1.59 by sasha, Sun Aug 5 06:19:01 2007 UTC

24 *---------------------------------------------------------------------*/ 24 *---------------------------------------------------------------------*/
25 25
26#include "../config.h" /* NECESSARY */ 26#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 27#include "rxvt.h" /* NECESSARY */
28 28
29/*
30 * Pixmap geometry string interpretation :
31 * Each geometry string contains zero or one scale/position
32 * adjustment and may optionally be followed by a colon and one or more
33 * colon-delimited pixmap operations.
34 * The following table shows the valid geometry strings and their
35 * affects on the background image :
36 *
37 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
38 * W and H are percentages of the terminal window size.
39 * X and Y are also percentages; e.g., +50+50 centers
40 * the image in the window.
41 * WxH+X Assumes Y == X
42 * WxH Assumes Y == X == 50 (centers the image)
43 * W+X+Y Assumes H == W
44 * W+X Assumes H == W and Y == X
45 * W Assumes H == W and Y == X == 50
46 *
47 * Adjusting position only :
48 * =+X+Y Set position to X% by Y% (absolute).
49 * =+X Set position to X% by X%.
50 * +X+Y Adjust position horizontally X% and vertically Y%
51 * from current position (relative).
52 * +X Adjust position horizontally X% and vertically X%
53 * from current position.
54 *
55 * Adjusting scale only :
56 * Wx0 Multiply horizontal scaling factor by W%
57 * 0xH Multiply vertical scaling factor by H%
58 * 0x0 No scaling (show image at normal size).
59 *
60 * Pixmap Operations : (should be prepended by a colon)
61 * tile Tile image. Scaling/position modifiers above will affect
62 * the tile size and origin.
63 * propscale When scaling, scale proportionally. That is, maintain the
64 * proper aspect ratio for the image. Any portion of the
65 * background not covered by the image is filled with the
66 * current background color.
67 * hscale Scale horizontally, tile vertically ?
68 * vscale Tile horizontally, scale vertically ?
69 * scale Scale both up and down
70 * auto Same as 100x100+50+50
71 */
72
73#ifdef HAVE_BG_PIXMAP
74bool
75bgPixmap_t::window_size_sensitive ()
76{
29#ifdef XPM_BACKGROUND 77#ifdef XPM_BACKGROUND
78#ifdef HAVE_AFTERIMAGE
79 if (original_asim != NULL)
80#endif
81 {
82 if (h_scale != 0 || v_scale != 0)
83 return true;
84 }
85#endif
86#ifdef ENABLE_TRANSPARENCY
87 if (flags & bgPmap_Transparent)
88 return true;
89#endif
90 return false;
91}
30 92
31/* 93#ifdef XPM_BACKGROUND
32 * These GEOM strings indicate absolute size/position: 94static inline bool
33 * @ `WxH+X+Y' 95check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
34 * @ `WxH+X' -> Y = X
35 * @ `WxH' -> Y = X = 50
36 * @ `W+X+Y' -> H = W
37 * @ `W+X' -> H = W, Y = X
38 * @ `W' -> H = W, X = Y = 50
39 * @ `0xH' -> H *= H/100, X = Y = 50 (W unchanged)
40 * @ `Wx0' -> W *= W/100, X = Y = 50 (H unchanged)
41 * @ `=+X+Y' -> (H, W unchanged)
42 * @ `=+X' -> Y = X (H, W unchanged)
43 *
44 * These GEOM strings adjust position relative to current position:
45 * @ `+X+Y'
46 * @ `+X' -> Y = X
47 *
48 * And this GEOM string is for querying current scale/position:
49 * @ `?'
50 */
51int
52rxvt_term::scale_pixmap (const char *geom)
53{ 96{
97 if (geom_flags & flag)
98 {
99 if (new_value > 1000)
100 new_value = 1000;
101 if (new_value != scale)
102 {
103 scale = new_value;
104 return true;
105 }
106 }
107 return false;
108}
109
110static inline bool
111check_set_align_value (int geom_flags, int flag, int &align, int new_value)
112{
113 if (geom_flags & flag)
114 {
115 if (new_value < -100)
116 new_value = -100;
117 else if (new_value > 200)
118 new_value = 200;
119 if (new_value != align)
120 {
121 align = new_value;
122 return true;
123 }
124 }
125 return false;
126}
127
128static inline int
129make_align_position (int align, int window_size, int image_size)
130{
131 int diff = window_size - image_size;
132 int smaller = MIN (image_size,window_size);
133
134 if (align >= 0 && align <= 50)
135 return diff * align / 100;
136 else if (align > 50 && align <= 100)
137 return window_size - image_size + diff * align / 100;
138 else if (align > 100 && align <= 200 )
139 return ((align - 100) * smaller / 100) + window_size - smaller;
140 else if (align > -100 && align < 0)
141 return ((align + 100) * smaller / 100) - image_size;
142 return 0;
143}
144
145static inline void
146make_clip_rectangle (int pos, int size, int target_size, short &clip_pos, unsigned short &clip_size)
147{
148 if (pos < 0)
149 {
150 clip_pos = 0;
151 clip_size = MIN (target_size, size + pos);
152 }
153 else
154 {
155 clip_pos = pos;
156 clip_size = size;
157 if (pos < target_size && (int)clip_size > target_size - pos)
158 clip_pos = target_size - pos;
159 }
160}
161
162bool
163bgPixmap_t::handle_geometry (const char *geom)
164{
54 int flags, changed = 0; 165 int geom_flags = 0, changed = 0;
55 int x = 0, y = 0; 166 int x = 0, y = 0;
56 unsigned int w = 0, h = 0; 167 unsigned int w = 0, h = 0;
57 unsigned int n; 168 unsigned int n;
169 unsigned long new_flags = (flags&(~bgPmap_geometryFlags));
58 char *p; 170 char *p;
59 bgPixmap_t *bgpixmap = &bgPixmap; 171#define MAXLEN_GEOM 256 /* could be longer then regular geometry string */
60
61#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
62 172
63 if (geom == NULL) 173 if (geom == NULL)
64 return 0; 174 return false;
65 175
66 char str[MAXLEN_GEOM]; 176 char str[MAXLEN_GEOM];
67 177
68 if (!strcmp (geom, "?")) 178 if (!strcmp (geom, "?"))
69 { 179 {
180#if 0 /* TODO: */
70 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 181 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
71 min (bgpixmap->w, 32767), min (bgpixmap->h, 32767), 182 min (h_scale, 32767), min (v_scale, 32767),
72 min (bgpixmap->x, 32767), min (bgpixmap->y, 32767)); 183 min (h_align, 32767), min (v_align, 32767));
73 process_xterm_seq (XTerm_title, str, CHAR_ST); 184 process_xterm_seq (XTerm_title, str, CHAR_ST);
185#endif
74 return 0; 186 return false;
75 } 187 }
76 188 while (isspace(*geom)) ++geom;
77 if ((p = strchr (geom, ';')) == NULL) 189 if ((p = strchr (geom, ';')) == NULL)
78 p = strchr (geom, '\0'); 190 p = strchr (geom, '\0');
79 191
80 n = (p - geom); 192 n = (p - geom);
81 if (n < MAXLEN_GEOM) 193 if (n < MAXLEN_GEOM)
82 { 194 {
195 char *ops;
196 new_flags |= bgPmap_geometrySet;
197
83 strncpy (str, geom, n); 198 strncpy (str, geom, n);
84 str[n] = '\0'; 199 str[n] = '\0';
85 200 if (str[0] == ':')
86 if (strcmp(str, "auto") == 0) 201 ops = &str[0];
87 { 202 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
88 if (!bgpixmap->auto_resize) 203 ops = &str[0];
89 changed++;
90 bgpixmap->auto_resize = True ;
91 w = szHint.width ;
92 h = szHint.height ;
93 flags = WidthValue|HeightValue ;
94 }
95 else 204 else
96 { 205 {
97 bgpixmap->auto_resize = False ; 206 char *tmp;
98 flags = XParseGeometry (str, &x, &y, &w, &h); 207 ops = strchr (str, ':');
99 } 208 if (ops != NULL)
100
101 if (!flags)
102 {
103 flags |= WidthValue;
104 w = 0;
105 } /* default is tile */
106
107 if (flags & WidthValue)
108 {
109 if (!(flags & XValue))
110 x = 50;
111
112 if (!(flags & HeightValue))
113 h = w;
114
115 if (w && !h)
116 { 209 {
117 w = (bgpixmap->w * w) / 100; 210 for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp);
118 h = bgpixmap->h; 211 *(++tmp) = '\0';
212 if (ops == tmp) ++ops;
119 } 213 }
120 else if (h && !w) 214 }
215
216 if (ops > str || ops == NULL)
217 {
218 /* we have geometry string - let's handle it prior to applying ops */
219 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
220
221 if ((geom_flags & XValue) && !(geom_flags & YValue))
121 { 222 {
122 w = bgpixmap->w; 223 y = x;
123 h = (bgpixmap->h * h) / 100; 224 geom_flags |= YValue;
124 } 225 }
125 226
126 min_it (w, 32767); 227 if (flags & bgPmap_geometrySet)
127 min_it (h, 32767); 228 {/* new geometry is an adjustment to the old one ! */
128 229 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
129 if (bgpixmap->w != (short)w) 230 {
231 if (w == 0 && h != 0)
232 {
233 w = h_scale;
234 h = (v_scale * h) / 100;
235 }
236 else if (h == 0 && w != 0)
237 {
238 w = (h_scale * w) / 100;
239 h = v_scale;
240 }
241 }
242 if (geom_flags & XValue)
243 {
244 if (str[0] != '=')
245 {
246 y += v_align;
247 x += h_align;
248 }
249 }
250 }
251 else /* setting up geometry from scratch */
130 { 252 {
131 bgpixmap->w = (short)w; 253 if (!(geom_flags & XValue))
132 changed++; 254 {/* use default geometry - centered */
255 x = y = bgPmap_defaultAlign;
256 }
257 else if (!(geom_flags & YValue))
258 y = x;
259
260 if ((geom_flags & (WidthValue|HeightValue)) == 0)
261 {/* use default geometry - scaled */
262 w = h = bgPmap_defaultScale;
263 }
264 else if (geom_flags & WidthValue)
265 {
266 if (!(geom_flags & HeightValue))
267 h = w;
268 }
269 else
270 w = h;
133 } 271 }
272 } /* done parsing geometry string */
273 else if (!(flags & bgPmap_geometrySet))
274 { /* default geometry - scaled and centered */
275 x = y = bgPmap_defaultAlign;
276 w = h = bgPmap_defaultScale;
277 }
278
279 if (!(flags & bgPmap_geometrySet))
280 geom_flags |= WidthValue|HeightValue|XValue|YValue;
134 281
135 if (bgpixmap->h != (short)h) 282 if (ops)
283 {
284 while (*ops)
136 { 285 {
137 bgpixmap->h = (short)h; 286 while (*ops == ':' || isspace(*ops)) ++ops;
138 changed++; 287#define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
288 if (CHECK_GEOM_OPS("tile"))
289 {
290 w = h = 0;
291 geom_flags |= WidthValue|HeightValue;
139 } 292 }
140 } 293 else if (CHECK_GEOM_OPS("propscale"))
141 294 {
142 if (!(flags & YValue)) 295 if (w == 0 && h == 0)
296 {
297 w = 100;
298 geom_flags |= WidthValue;
299 }
300 new_flags |= bgPmap_propScale;
301 }
302 else if (CHECK_GEOM_OPS("hscale"))
303 {
304 if (w == 0)
305 w = 100;
306 h = 0;
307 geom_flags |= WidthValue|HeightValue;
308 }
309 else if (CHECK_GEOM_OPS("vscale"))
310 {
311 if (h == 0)
312 h = 100;
313 w = 0;
314 geom_flags |= WidthValue|HeightValue;
315 }
316 else if (CHECK_GEOM_OPS("scale"))
317 {
318 if (h == 0)
319 h = 100;
320 if (w == 0)
321 w = 100;
322 geom_flags |= WidthValue|HeightValue;
323 }
324 else if (CHECK_GEOM_OPS("auto"))
325 {
326 w = h = 100;
327 x = y = 50;
328 geom_flags |= WidthValue|HeightValue|XValue|YValue;
329 }
330#undef CHECK_GEOM_OPS
331 while (*ops != ':' && *ops != '\0') ++ops;
332 } /* done parsing ops */
143 { 333 }
144 if (flags & XNegative)
145 flags |= YNegative;
146 334
147 y = x; 335 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w))
148 } 336 ++changed;
337 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h))
338 ++changed;
339 if (check_set_align_value (geom_flags, XValue, h_align, x))
340 ++changed;
341 if (check_set_align_value (geom_flags, YValue, v_align, y))
342 ++changed;
343 }
149 344
150 if (!(flags & WidthValue) && geom[0] != '=') 345 if (new_flags != flags)
151 { 346 {
152 x += bgpixmap->x; 347 flags = new_flags;
153 y += bgpixmap->y;
154 }
155
156 if (xpmAttr.width && xpmAttr.height)
157 {
158 x = MOD(x, xpmAttr.width);
159 y = MOD(y, xpmAttr.height);
160 }
161
162 if (bgpixmap->x != x)
163 {
164 bgpixmap->x = x;
165 changed++; 348 changed++;
166 }
167
168 if (bgpixmap->y != y)
169 {
170 bgpixmap->y = y;
171 changed++;
172 }
173 } 349 }
174 350//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
351// flags, h_scale, v_scale, h_align, v_align);
175 return changed; 352 return (changed > 0);
176} 353}
354
355#ifdef HAVE_AFTERIMAGE
356ASImage *
357bgPixmap_t::resize_asim (rxvt_term *target, ASImage *background, XRectangle &dst_rect)
358{
359 if (original_asim == NULL || target == NULL)
360 return NULL;
361
362 int target_width = (int)target->szHint.width;
363 int target_height = (int)target->szHint.height;
364 int w = h_scale * target_width / 100;
365 int h = v_scale * target_height / 100;
366 int x = make_align_position (h_align, target_width, w);
367 int y = make_align_position (v_align, target_height, h);
368
369 make_clip_rectangle (x, w, target_width, dst_rect.x, dst_rect.width);
370 make_clip_rectangle (y, h, target_height, dst_rect.y, dst_rect.height);
371
372 /* TODO : actuall scaling code :) */
373
374}
375#endif
177 376
178void 377void
179rxvt_term::resize_pixmap () 378rxvt_term::resize_pixmap ()
180{ 379{
181 XGCValues gcvalue; 380 XGCValues gcvalue;
182 GC gc; 381 GC gc;
183 382 unsigned int w = bgPixmap.h_scale*szHint.width/100;
184 if (pixmap != None) 383 unsigned int h = bgPixmap.v_scale*szHint.height/100;
185 { 384 int x = bgPixmap.h_align*szHint.width/100;
186 XFreePixmap (dpy, pixmap); 385 int y = bgPixmap.v_align*szHint.height/100;
187 pixmap = None ; 386#ifdef HAVE_AFTERIMAGE
188 } 387 ASImage *im = bgPixmap.original_asim;
189 388#else
389 void *im = NULL;
390#endif
391/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
190 if (bgPixmap.pixmap == None) 392 if (bgPixmap.pixmap != None)
393 {
394 XFreePixmap (dpy, bgPixmap.pixmap);
395 bgPixmap.pixmap = None ;
396 }
397#ifdef ENABLE_TRANSPARENCY
398 if (option(Opt_transparent) && am_transparent)
399 {
400 /* we need to re-generate transparency pixmap in that case ! */
401 check_our_parents ();
402 return;
403 }
404#endif
405
406 if (im == NULL)
191 { /* So be it: I'm not using pixmaps */ 407 { /* So be it: I'm not using pixmaps */
192 pixmap = None;
193
194#ifdef ENABLE_TRANSPARENCY
195 if (!option (Opt_transparent) || !am_transparent)
196#endif
197 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 408 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
198
199 return; 409 return;
200 } 410 }
201 411
202 gcvalue.foreground = pix_colors[Color_bg]; 412 gcvalue.foreground = pix_colors[Color_bg];
203 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); 413 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
204 414
205 if (bgPixmap.pixmap != None)
206 { /* we have a specified pixmap */
207 unsigned int w = bgPixmap.w, h = bgPixmap.h,
208 x = bgPixmap.x, y = bgPixmap.y;
209 unsigned int xpmh = xpmAttr.height,
210 xpmw = xpmAttr.width;
211
212 if (bgPixmap.auto_resize)
213 {
214 w = szHint.width ;
215 h = szHint.height ;
216 }
217 /*
218 * don't zoom pixmap too much nor expand really small pixmaps 415 /* don't zoom pixmap too much nor expand really small pixmaps */
219 */ 416 if (w > 16000)
220 if (w > 32767 || h > 32767)
221 w = 1; 417 w = 1;
222 else if (width > (10 * xpmw) 418 if (h > 16000)
223 || height > (10 * xpmh)) 419 h = 1;
224 w = 0; /* tile */ 420
421#ifdef HAVE_AFTERIMAGE
422 if (w == 0)
423 w = im->width;
424 if (h == 0)
425 h = im->height;
225 426
226 if (!w) 427 if (w != im->width || h != im->height)
227 { 428 {
228 /* basic X tiling - let the X server do it */ 429 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
229 pixmap = XCreatePixmap (dpy, vt, xpmw, xpmh, depth); 430 if (tmp != NULL)
230 431 im = tmp;
231 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0); 432 }
232 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y); 433 bgPixmap.pmap_width = MIN(w,szHint.width);
233 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0); 434 bgPixmap.pmap_height = MIN(h,szHint.height);
234 XCopyArea (dpy, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y); 435#if 0 /* TODO: fix that! */
436 if (x != 0 || y != 0)
437 {
438 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
439 if (tmp != NULL)
235 } 440 {
236 else 441 if (im != bgPixmap.original_asim)
237#ifdef ENABLE_TRANSPARENCY 442 destroy_asimage (&im);
238 if (!option(Opt_transparent) || !am_transparent) 443 im = tmp;
239 /* will do that in check_our_parents otherwise */ 444 }
445 }
446#endif
447 bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth);
448 bgPixmap.pmap_depth = depth;
449
450 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True);
451
452 if (im != bgPixmap.original_asim)
453 destroy_asimage (&im);
240#endif 454#endif
241 { 455 if( bgPixmap.pixmap )
242 ASImage *scaled_im = scale_asimage (asv, original_asim, w, h, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
243 if (scaled_im)
244 {
245 pixmap = asimage2pixmap(asv, display->root, scaled_im, gc, True);
246 destroy_asimage (&scaled_im);
247 }
248 }
249 }
250
251 XSetWindowBackgroundPixmap (dpy, vt, pixmap); 456 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
252 457
253 XFreeGC (dpy, gc); 458 XFreeGC (dpy, gc);
254#ifdef ENABLE_TRANSPARENCY
255 am_transparent = 0;
256#endif
257} 459}
258 460
259Pixmap 461void
260rxvt_term::set_bgPixmap (const char *file) 462rxvt_term::set_bgPixmap (const char *file)
261{ 463{
262 char *f; 464 char *f;
263 465
264 assert (file != NULL); 466 assert (file != NULL);
268 XFreePixmap (dpy, bgPixmap.pixmap); 470 XFreePixmap (dpy, bgPixmap.pixmap);
269 bgPixmap.pixmap = None; 471 bgPixmap.pixmap = None;
270 } 472 }
271 473
272 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 474 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
273
274 if (*file != '\0') 475 if (*file != '\0')
275 { 476 {
276 /* XWindowAttributes attr; */ 477#ifdef HAVE_AFTERIMAGE
277
278 /*
279 * we already have the required attributes
280 */
281 /* XGetWindowAttributes (dpy, vt, &attr); */
282
283 if (asimman == NULL) 478 if (asimman == NULL)
284 asimman = create_generic_imageman(rs[Rs_path]); 479 asimman = create_generic_imageman(rs[Rs_path]);
285 if ((f = strchr (file, ';')) == NULL) 480 if ((f = strchr (file, ';')) == NULL)
286 original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 481 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
287 else 482 else
288 { 483 {
289 size_t len = f - file; 484 size_t len = f - file;
290 f = (char *)malloc (len + 1); 485 f = (char *)malloc (len + 1);
291 strncpy (f, file, len); 486 strncpy (f, file, len);
292 f[len] = '\0'; 487 f[len] = '\0';
293 original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); 488 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
294 free( f ); 489 free( f );
295 } 490 }
296 if (original_asim) 491#endif
297 {
298 bgPixmap.pixmap = asimage2pixmap (asv, display->root, original_asim, NULL, True);
299 xpmAttr.width = original_asim->width ;
300 xpmAttr.height = original_asim->height ;
301 }
302 } 492 }
303 493
304 resize_pixmap (); 494 resize_pixmap ();
305 return bgPixmap.pixmap;
306} 495}
307 496
308#endif /* XPM_BACKGROUND */ 497#endif /* XPM_BACKGROUND */
498#endif /* HAVE_BG_PIXMAP */
309 499
310#ifdef ENABLE_TRANSPARENCY 500#ifdef ENABLE_TRANSPARENCY
311#if TINTING && !defined(HAVE_AFTERIMAGE) 501#ifndef HAVE_AFTERIMAGE
312/* taken from aterm-0.4.2 */ 502/* taken from aterm-0.4.2 */
313 503
314typedef uint32_t RUINT32T; 504typedef uint32_t RUINT32T;
315 505
316static void 506static void
624 0L, 1L, False, XA_PIXMAP, &atype, &aformat, 814 0L, 1L, False, XA_PIXMAP, &atype, &aformat,
625 &nitems, &bytes_after, &prop) == Success); 815 &nitems, &bytes_after, &prop) == Success);
626 816
627 /* TODO: the below logic needs to be cleaned up */ 817 /* TODO: the below logic needs to be cleaned up */
628 if (!i || prop == NULL 818 if (!i || prop == NULL
629#if TINTING
630 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL 819 || (!ISSET_PIXCOLOR (Color_tint) && rs[Rs_shade] == NULL
631#ifdef HAVE_AFTERIMAGE 820#ifdef HAVE_AFTERIMAGE
632 && original_asim == NULL && rs[Rs_blurradius] == NULL 821 && bgPixmap.original_asim == NULL && rs[Rs_blurradius] == NULL
633#endif 822#endif
634 ) 823 )
635#endif
636 ) 824 )
637 rootpixmap = None; 825 rootpixmap = None;
638 else 826 else
639 { 827 {
640 int junk; 828 int junk;
660 Bool whole_tint = False, no_tint = True; 848 Bool whole_tint = False, no_tint = True;
661 849
662 while (sx < 0) sx += (int)wrootattr.width; 850 while (sx < 0) sx += (int)wrootattr.width;
663 while (sy < 0) sy += (int)wrootattr.height; 851 while (sy < 0) sy += (int)wrootattr.height;
664 852
665#if TINTING
666 if (rs[Rs_shade]) 853 if (rs[Rs_shade])
667 shade = atoi (rs[Rs_shade]); 854 shade = atoi (rs[Rs_shade]);
668 if (ISSET_PIXCOLOR (Color_tint)) 855 if (ISSET_PIXCOLOR (Color_tint))
669 pix_colors_focused [Color_tint].get (c); 856 pix_colors_focused [Color_tint].get (c);
670#define IS_COMPONENT_WHOLESOME(c) ((c) <=0x000700 || (c)>=0x00f700) 857#define IS_COMPONENT_WHOLESOME(c) ((c) <=0x000700 || (c)>=0x00f700)
672 whole_tint = (IS_COMPONENT_WHOLESOME(c.r) 859 whole_tint = (IS_COMPONENT_WHOLESOME(c.r)
673 && IS_COMPONENT_WHOLESOME(c.g) 860 && IS_COMPONENT_WHOLESOME(c.g)
674 && IS_COMPONENT_WHOLESOME(c.b)); 861 && IS_COMPONENT_WHOLESOME(c.b));
675 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700); 862 no_tint = (c.r >= 0x00f700 && c.g >= 0x00f700 && c.b >= 0x00f700);
676#undef IS_COMPONENT_WHOLESOME 863#undef IS_COMPONENT_WHOLESOME
677#endif /* TINTING */
678 /* theer are no performance advantages to reusing same pixmap */ 864 /* theer are no performance advantages to reusing same pixmap */
679 if (pixmap != None) 865 if (bgPixmap.pixmap != None)
680 XFreePixmap (dpy, pixmap); 866 XFreePixmap (dpy, bgPixmap.pixmap);
681 pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth); 867 bgPixmap.pixmap = XCreatePixmap (dpy, vt, szHint.width, szHint.height, rootdepth);
868 bgPixmap.pmap_width = szHint.width;
869 bgPixmap.pmap_height = szHint.height;
870 bgPixmap.pmap_depth = rootdepth;
682 871
683#if 0 /* TODO : identify cases where this will be detrimental to performance : */ 872#if 0 /* TODO : identify cases where this will be detrimental to performance : */
684 /* we want to tile root pixmap into our own pixmap in this cases : 873 /* we want to tile root pixmap into our own pixmap in this cases :
685 * 1) rootpixmap does not cover our window entirely 874 * 1) rootpixmap does not cover our window entirely
686 * 2) whole_tint - we can use server-side tinting or tinting disabled 875 * 2) whole_tint - we can use server-side tinting or tinting disabled
692 gcvalue.tile = rootpixmap; 881 gcvalue.tile = rootpixmap;
693 gcvalue.fill_style = FillTiled; 882 gcvalue.fill_style = FillTiled;
694 gcvalue.ts_x_origin = -sx; 883 gcvalue.ts_x_origin = -sx;
695 gcvalue.ts_y_origin = -sy; 884 gcvalue.ts_y_origin = -sy;
696 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue); 885 gc = XCreateGC (dpy, rootpixmap, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcvalue);
697 XFillRectangle (dpy, pixmap, gc, 0, 0, szHint.width, szHint.height); 886 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
698 887
699#if TINTING
700 if (whole_tint && !no_tint) 888 if (whole_tint && !no_tint)
701 { 889 {
702 /* In this case we can tint image server-side getting significant 890 /* In this case we can tint image server-side getting significant
703 * performance improvements, as we eliminate XImage transfer 891 * performance improvements, as we eliminate XImage transfer
704 */ 892 */
705 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]); 893 gcvalue.foreground = Pixel (pix_colors_focused [Color_tint]);
706 gcvalue.function = GXand; 894 gcvalue.function = GXand;
707 gcvalue.fill_style = FillSolid; 895 gcvalue.fill_style = FillSolid;
708 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue); 896 XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcvalue);
709 XFillRectangle (dpy, pixmap, gc, 0, 0, szHint.width, szHint.height); 897 XFillRectangle (dpy, bgPixmap.pixmap, gc, 0, 0, szHint.width, szHint.height);
710 } 898 }
711#endif
712 success = True; 899 success = True;
713#ifdef HAVE_AFTERIMAGE 900#ifdef HAVE_AFTERIMAGE
714 if (rs[Rs_blurradius] || original_asim != NULL || (!whole_tint && (!no_tint || shade !=100))) 901 if (rs[Rs_blurradius] || bgPixmap.original_asim != NULL || (!whole_tint && (!no_tint || shade !=100)))
715 { 902 {
716 ARGB32 tint = TINT_LEAVE_SAME; 903 ARGB32 tint = TINT_LEAVE_SAME;
717 ASImage *back_im = NULL; 904 ASImage *back_im = NULL;
718 905
719 back_im = pixmap2ximage (asv, pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, 100); 906 back_im = pixmap2ximage (asv, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, 100);
720 if (back_im != NULL) 907 if (back_im != NULL)
721 { 908 {
722 if (!whole_tint && (!no_tint || shade !=100)) 909 if (!whole_tint && (!no_tint || shade !=100))
723 { 910 {
724 ShadingInfo as_shade; 911 ShadingInfo as_shade;
738 if (!(flags&WidthValue)) 925 if (!(flags&WidthValue))
739 hr = 1; 926 hr = 1;
740 if (!(flags&HeightValue)) 927 if (!(flags&HeightValue))
741 vr = hr; 928 vr = hr;
742 tmp = blur_asimage_gauss (asv, back_im, hr, vr, 0xFFFFFFFF, 929 tmp = blur_asimage_gauss (asv, back_im, hr, vr, 0xFFFFFFFF,
743 (original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage, 930 (bgPixmap.original_asim == NULL || tint == TINT_LEAVE_SAME)?ASA_XImage:ASA_ASImage,
744 100, ASIMAGE_QUALITY_DEFAULT); 931 100, ASIMAGE_QUALITY_DEFAULT);
745 if (tmp) 932 if (tmp)
746 { 933 {
747 destroy_asimage (&back_im); 934 destroy_asimage (&back_im);
748 back_im = tmp; 935 back_im = tmp;
749 } 936 }
750 } 937 }
751 938
752 if (original_asim != NULL) 939 if (bgPixmap.original_asim != NULL)
753 { 940 {
754 ASImageLayer *layers = create_image_layers (2); 941 ASImageLayer *layers = create_image_layers (2);
755 ASImage *merged_im = NULL; 942 ASImage *merged_im = NULL;
756 int fore_w, fore_h; 943 int fore_w, fore_h;
757 944
758 layers[0].im = back_im; 945 layers[0].im = back_im;
759 layers[0].clip_width = szHint.width; 946 layers[0].clip_width = szHint.width;
760 layers[0].clip_height = szHint.height; 947 layers[0].clip_height = szHint.height;
761 layers[0].tint = tint; 948 layers[0].tint = tint;
762 layers[1].im = original_asim; 949 layers[1].im = bgPixmap.original_asim;
763 if (bgPixmap.auto_resize) 950
764 { 951 fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100;
765 fore_w = szHint.width; 952 fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100;
766 fore_h = szHint.height; 953
767 }
768 else
769 {
770 fore_w = bgPixmap.w;
771 fore_h = bgPixmap.h;
772 }
773 if (fore_w != original_asim->width 954 if (fore_w != bgPixmap.original_asim->width
774 || fore_h != original_asim->height) 955 || fore_h != bgPixmap.original_asim->height)
775 { 956 {
776 layers[1].im = scale_asimage (asv, 957 layers[1].im = scale_asimage (asv,
777 original_asim, 958 bgPixmap.original_asim,
778 fore_w, fore_h, 959 fore_w, fore_h,
779 ASA_ASImage, 100, 960 ASA_ASImage, 100,
780 ASIMAGE_QUALITY_DEFAULT); 961 ASIMAGE_QUALITY_DEFAULT);
781 } 962 }
782 layers[1].clip_width = szHint.width; 963 layers[1].clip_width = szHint.width;
789 layers[1].merge_scanlines = alphablend_scanlines; 970 layers[1].merge_scanlines = alphablend_scanlines;
790 } 971 }
791 PRINT_BACKGROUND_OP_TIME; 972 PRINT_BACKGROUND_OP_TIME;
792 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height, 973 merged_im = merge_layers (asv, layers, 2, szHint.width, szHint.height,
793 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 974 ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
794 if (layers[1].im != original_asim) 975 if (layers[1].im != bgPixmap.original_asim)
795 destroy_asimage (&(layers[1].im)); 976 destroy_asimage (&(layers[1].im));
796 free (layers); 977 free (layers);
797 978
798 if (merged_im != NULL) 979 if (merged_im != NULL)
799 { 980 {
810 destroy_asimage (&back_im); 991 destroy_asimage (&back_im);
811 back_im = tmp; 992 back_im = tmp;
812 } 993 }
813 PRINT_BACKGROUND_OP_TIME; 994 PRINT_BACKGROUND_OP_TIME;
814 } 995 }
815 asimage2drawable (asv, pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True); 996 asimage2drawable (asv, bgPixmap.pixmap, back_im, gc, 0, 0, 0, 0, szHint.width, szHint.height, True);
816 destroy_asimage (&back_im); 997 destroy_asimage (&back_im);
817 } /* back_im != NULL */ 998 } /* back_im != NULL */
818 else 999 else
819 success = False; 1000 success = False;
820 } 1001 }
821#else /* HAVE_AFTERIMAGE */ 1002#else /* HAVE_AFTERIMAGE */
822#if TINTING
823 if (!whole_tint && (!no_tint || shade !=100)) 1003 if (!whole_tint && (!no_tint || shade !=100))
824 { 1004 {
825 XImage *image = XGetImage (dpy, pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap); 1005 XImage *image = XGetImage (dpy, bgPixmap.pixmap, 0, 0, szHint.width, szHint.height, AllPlanes, ZPixmap);
826 success = False; 1006 success = False;
827 if (image != NULL) 1007 if (image != NULL)
828 { 1008 {
829 PRINT_BACKGROUND_OP_TIME; 1009 PRINT_BACKGROUND_OP_TIME;
830 if (gc == NULL) 1010 if (gc == NULL)
831 gc = XCreateGC (dpy, vt, 0UL, &gcvalue); 1011 gc = XCreateGC (dpy, vt, 0UL, &gcvalue);
832 if (ISSET_PIXCOLOR (Color_tint) || shade != 100) 1012 if (ISSET_PIXCOLOR (Color_tint) || shade != 100)
833 ShadeXImage (this, image, shade, c.r, c.g, c.b); 1013 ShadeXImage (this, image, shade, c.r, c.g, c.b);
834 XPutImage (dpy, pixmap, gc, image, 0, 0, 0, 0, image->width, image->height); 1014 XPutImage (dpy, bgPixmap.pixmap, gc, image, 0, 0, 0, 0, image->width, image->height);
835 XDestroyImage (image); 1015 XDestroyImage (image);
836 success = True; 1016 success = True;
837 } 1017 }
838 } 1018 }
839#endif
840#endif /* HAVE_AFTERIMAGE */ 1019#endif /* HAVE_AFTERIMAGE */
841 PRINT_BACKGROUND_OP_TIME; 1020 PRINT_BACKGROUND_OP_TIME;
842 1021
843 if (gc != NULL) 1022 if (gc != NULL)
844 XFreeGC (dpy, gc); 1023 XFreeGC (dpy, gc);
846 if (!success) 1025 if (!success)
847 { 1026 {
848 if (am_transparent && am_pixmap_trans) 1027 if (am_transparent && am_pixmap_trans)
849 { 1028 {
850 pchanged = 1; 1029 pchanged = 1;
851 if (pixmap != None) 1030 if (bgPixmap.pixmap != None)
852 { 1031 {
853 XFreePixmap (dpy, pixmap); 1032 XFreePixmap (dpy, bgPixmap.pixmap);
854 pixmap = None; 1033 bgPixmap.pixmap = None;
855 } 1034 }
856 } 1035 }
857 1036
858 am_pixmap_trans = 0; 1037 am_pixmap_trans = 0;
859 } 1038 }
860 else 1039 else
861 { 1040 {
862 XSetWindowBackgroundPixmap (dpy, parent[0], pixmap); 1041 XSetWindowBackgroundPixmap (dpy, parent[0], bgPixmap.pixmap);
863 XClearWindow (dpy, parent[0]); 1042 XClearWindow (dpy, parent[0]);
864 1043
865 if (!am_transparent || !am_pixmap_trans) 1044 if (!am_transparent || !am_pixmap_trans)
866 pchanged = 1; 1045 pchanged = 1;
867 1046

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines