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.55 by sasha, Fri Aug 3 05:33:04 2007 UTC vs.
Revision 1.56 by sasha, Fri Aug 3 22:40:10 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+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{
77 return (flags&(bgPmap_Scale|bgPmap_Transparent));
78}
79
29#ifdef XPM_BACKGROUND 80#ifdef XPM_BACKGROUND
30 81bool
31/* 82bgPixmap_t::handle_geometry (const char *geom)
32 * These GEOM strings indicate absolute size/position:
33 * @ `WxH+X+Y'
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{ 83{
54 int flags, changed = 0; 84 int geom_flags, changed = 0;
55 int x = 0, y = 0; 85 int x = 0, y = 0;
56 unsigned int w = 0, h = 0; 86 unsigned int w = 0, h = 0;
57 unsigned int n; 87 unsigned int n;
88 unsigned long new_flags = (flags&(~bgPmap_geometryFlags)) ;
58 char *p; 89 char *p;
59 bgPixmap_t *bgpixmap = &bgPixmap;
60
61#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]") 90#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
62 91
63 if (geom == NULL) 92 if (geom == NULL)
64 return 0; 93 return false;
65 94
66 char str[MAXLEN_GEOM]; 95 char str[MAXLEN_GEOM];
67 96
68 if (!strcmp (geom, "?")) 97 if (!strcmp (geom, "?"))
69 { 98 {
99#if 0 /* TODO: */
70 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 100 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
71 min (bgpixmap->w, 32767), min (bgpixmap->h, 32767), 101 min (h_scale, 32767), min (v_scale, 32767),
72 min (bgpixmap->x, 32767), min (bgpixmap->y, 32767)); 102 min (h_align, 32767), min (v_align, 32767));
73 process_xterm_seq (XTerm_title, str, CHAR_ST); 103 process_xterm_seq (XTerm_title, str, CHAR_ST);
104#endif
74 return 0; 105 return false;
75 } 106 }
76 107
77 if ((p = strchr (geom, ';')) == NULL) 108 if ((p = strchr (geom, ';')) == NULL)
78 p = strchr (geom, '\0'); 109 p = strchr (geom, '\0');
79 110
80 n = (p - geom); 111 n = (p - geom);
81 if (n < MAXLEN_GEOM) 112 if (n < MAXLEN_GEOM)
82 { 113 {
114 new_flags |= bgPmap_geometrySet;
115
83 strncpy (str, geom, n); 116 strncpy (str, geom, n);
84 str[n] = '\0'; 117 str[n] = '\0';
85 118
86 if (strcmp(str, "auto") == 0) 119 if (strcmp(str, "auto") == 0)
87 { 120 {
88 if (!bgpixmap->auto_resize) 121 w = h = 100;
89 changed++;
90 bgpixmap->auto_resize = True ;
91 w = szHint.width ;
92 h = szHint.height ;
93 flags = WidthValue|HeightValue ; 122 geom_flags = WidthValue|HeightValue ;
94 } 123 }
95 else 124 else
96 { 125 {
97 bgpixmap->auto_resize = False ;
98 flags = XParseGeometry (str, &x, &y, &w, &h); 126 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
99 } 127 }
100/* code below is garbage and needs to be rewritten */ 128/* code below is garbage and needs to be rewritten */
101 if (!flags) 129 if (!geom_flags)
102 { 130 {
103 flags |= WidthValue; 131 geom_flags |= WidthValue;
104 w = 0; 132 w = 0;
105 } /* default is tile */ 133 } /* default is tile */
106 134
107 if (flags & WidthValue) 135 if (geom_flags & WidthValue)
108 { 136 {
109 if (!(flags & XValue)) 137 if (!(geom_flags & XValue))
110 x = 50; 138 x = 50;
111 139
112 if (!(flags & HeightValue)) 140 if (!(geom_flags & HeightValue))
113 h = w; 141 h = w;
114 142
115 if (w && !h) 143 if (w && !h)
116 { 144 {
117 w = (bgpixmap->w * w) / 100; 145 w = (h_scale * w) / 100;
118 h = bgpixmap->h; 146 h = v_scale;
119 } 147 }
120 else if (h && !w) 148 else if (h && !w)
121 { 149 {
122 w = bgpixmap->w; 150 w = h_scale;
123 h = (bgpixmap->h * h) / 100; 151 h = (v_scale * h) / 100;
124 } 152 }
125 153
126 min_it (w, 32767); 154 min_it (w, 32767);
127 min_it (h, 32767); 155 min_it (h, 32767);
128 156
129 if (bgpixmap->w != (short)w) 157 if (h_scale != w)
130 { 158 {
131 bgpixmap->w = (short)w; 159 h_scale = w;
132 changed++; 160 changed++;
133 } 161 }
134 162
135 if (bgpixmap->h != (short)h) 163 if (v_scale != h)
136 { 164 {
137 bgpixmap->h = (short)h; 165 v_scale = h;
138 changed++; 166 changed++;
139 } 167 }
140 } 168 }
141
142 if (!(flags & YValue)) 169 if (!(geom_flags & YValue))
143 { 170 {
144 if (flags & XNegative) 171 if (geom_flags & XNegative)
145 flags |= YNegative; 172 geom_flags |= YNegative;
146 173
147 y = x; 174 y = x;
148 } 175 }
149 176
150 if (!(flags & WidthValue) && geom[0] != '=') 177 if (!(geom_flags & WidthValue) && geom[0] != '=')
151 {
152 x += bgpixmap->x;
153 y += bgpixmap->y;
154 } 178 {
155 179 x += h_align;
156 if (bgpixmap->x != x) 180 y += v_align;
157 { 181 }
158 bgpixmap->x = x; 182
183 if (h_align != x)
184 {
185 h_align = x;
159 changed++; 186 changed++;
160 } 187 }
161 188
162 if (bgpixmap->y != y) 189 if (v_align != y)
163 { 190 {
164 bgpixmap->y = y; 191 v_align = y;
165 changed++; 192 changed++;
166 } 193 }
194
195 if (h_scale != 0)
196 new_flags |= bgPmap_hScale;
197 if (v_scale != 0)
198 new_flags |= bgPmap_vScale;
199 }
200
201 if (new_flags != flags)
167 } 202 {
168 203 flags = new_flags;
204 changed++;
205 }
169 return changed; 206 return (changed > 0);
170} 207}
171 208
172void 209void
173rxvt_term::resize_pixmap () 210rxvt_term::resize_pixmap ()
174{ 211{
175 XGCValues gcvalue; 212 XGCValues gcvalue;
176 GC gc; 213 GC gc;
177 unsigned int w = bgPixmap.w, h = bgPixmap.h; 214 unsigned int w = bgPixmap.h_scale*szHint.width/100;
178 unsigned int x = bgPixmap.x, y = bgPixmap.y; 215 unsigned int h = bgPixmap.v_scale*szHint.height/100;
216 int x = bgPixmap.h_align*szHint.width/100;
217 int y = bgPixmap.v_align*szHint.height/100;
218#ifdef HAVE_AFTERIMAGE
179 ASImage *im = bgPixmap.original_asim; 219 ASImage *im = bgPixmap.original_asim;
180 220#else
221 void *im = NULL;
222#endif
181/* preliminary cleanup - this needs to be integrated with check_our_parents() code */ 223/* preliminary cleanup - this needs to be integrated with check_our_parents() code */
182 if (bgPixmap.pixmap != None) 224 if (bgPixmap.pixmap != None)
183 { 225 {
184 XFreePixmap (dpy, bgPixmap.pixmap); 226 XFreePixmap (dpy, bgPixmap.pixmap);
185 bgPixmap.pixmap = None ; 227 bgPixmap.pixmap = None ;
191 check_our_parents (); 233 check_our_parents ();
192 return; 234 return;
193 } 235 }
194#endif 236#endif
195 237
196 if (bgPixmap.original_asim == NULL) 238 if (im == NULL)
197 { /* So be it: I'm not using pixmaps */ 239 { /* So be it: I'm not using pixmaps */
198 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 240 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
199 return; 241 return;
200 } 242 }
201 243
202 gcvalue.foreground = pix_colors[Color_bg]; 244 gcvalue.foreground = pix_colors[Color_bg];
203 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue); 245 gc = XCreateGC (dpy, vt, GCForeground, &gcvalue);
204 246
205 if (bgPixmap.auto_resize)
206 {
207 w = szHint.width;
208 h = szHint.height;
209 }
210 else
211 { /* don't zoom pixmap too much nor expand really small pixmaps */ 247 /* don't zoom pixmap too much nor expand really small pixmaps */
212 if (w > 16000) 248 if (w > 16000)
213 w = 1; 249 w = 1;
214 if (h > 16000) 250 if (h > 16000)
215 h = 1; 251 h = 1;
216 } 252
217 if (w == 0) w = im->width; 253#ifdef HAVE_AFTERIMAGE
218 else if (w < 10) w *= im->width; 254 if (w == 0)
219 if (h == 0) h = im->height; 255 w = im->width;
220 else if (w < 10) h *= im->height; 256 if (h == 0)
257 h = im->height;
221 258
222 if (w != im->width || h != im->height) 259 if (w != im->width || h != im->height)
223 { 260 {
224 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT); 261 ASImage *tmp = scale_asimage (asv, im, w, h, (x == 0 && y == 0)?ASA_XImage:ASA_ASImage, 0, ASIMAGE_QUALITY_DEFAULT);
225 if (tmp != NULL) 262 if (tmp != NULL)
226 im = tmp; 263 im = tmp;
227 } 264 }
265 bgPixmap.pmap_width = MIN(w,szHint.width);
266 bgPixmap.pmap_height = MIN(h,szHint.height);
267#if 0 /* TODO: fix that! */
228 if (x != 0 || y != 0) 268 if (x != 0 || y != 0)
229 { 269 {
230 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT); 270 ASImage *tmp = tile_asimage (asv, im, x, y, w, h, TINT_LEAVE_SAME, ASA_XImage, 0, ASIMAGE_QUALITY_DEFAULT);
231 if (tmp != NULL) 271 if (tmp != NULL)
232 { 272 {
233 if (im != bgPixmap.original_asim) 273 if (im != bgPixmap.original_asim)
234 destroy_asimage (&im); 274 destroy_asimage (&im);
235 im = tmp; 275 im = tmp;
236 } 276 }
237 } 277 }
238 bgPixmap.pixmap = XCreatePixmap (dpy, vt, w, h, depth); 278#endif
239 bgPixmap.pmap_width = w; 279 bgPixmap.pixmap = XCreatePixmap (dpy, vt, bgPixmap.pmap_width, bgPixmap.pmap_height, depth);
240 bgPixmap.pmap_height = h;
241 bgPixmap.pmap_depth = depth; 280 bgPixmap.pmap_depth = depth;
242 281
243 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, w, h, True); 282 asimage2drawable (asv, bgPixmap.pixmap, im, gc, 0, 0, 0, 0, bgPixmap.pmap_width, bgPixmap.pmap_height, True);
244 283
245 if (im != bgPixmap.original_asim) 284 if (im != bgPixmap.original_asim)
246 destroy_asimage (&im); 285 destroy_asimage (&im);
247 286#endif
287 if( bgPixmap.pixmap )
248 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap); 288 XSetWindowBackgroundPixmap (dpy, vt, bgPixmap.pixmap);
249 289
250 XFreeGC (dpy, gc); 290 XFreeGC (dpy, gc);
251} 291}
252 292
253void 293void
262 XFreePixmap (dpy, bgPixmap.pixmap); 302 XFreePixmap (dpy, bgPixmap.pixmap);
263 bgPixmap.pixmap = None; 303 bgPixmap.pixmap = None;
264 } 304 }
265 305
266 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]); 306 XSetWindowBackground (dpy, vt, pix_colors[Color_bg]);
267
268 if (*file != '\0') 307 if (*file != '\0')
269 { 308 {
309#ifdef HAVE_AFTERIMAGE
270 if (asimman == NULL) 310 if (asimman == NULL)
271 asimman = create_generic_imageman(rs[Rs_path]); 311 asimman = create_generic_imageman(rs[Rs_path]);
272 if ((f = strchr (file, ';')) == NULL) 312 if ((f = strchr (file, ';')) == NULL)
273 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 ); 313 bgPixmap.original_asim = get_asimage( asimman, file, 0xFFFFFFFF, 100 );
274 else 314 else
278 strncpy (f, file, len); 318 strncpy (f, file, len);
279 f[len] = '\0'; 319 f[len] = '\0';
280 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 ); 320 bgPixmap.original_asim = get_asimage( asimman, f, 0xFFFFFFFF, 100 );
281 free( f ); 321 free( f );
282 } 322 }
323#endif
283 } 324 }
284 325
285 resize_pixmap (); 326 resize_pixmap ();
286} 327}
287 328
288#endif /* XPM_BACKGROUND */ 329#endif /* XPM_BACKGROUND */
330#endif /* HAVE_BG_PIXMAP */
289 331
290#ifdef ENABLE_TRANSPARENCY 332#ifdef ENABLE_TRANSPARENCY
291#if TINTING && !defined(HAVE_AFTERIMAGE) 333#if TINTING && !defined(HAVE_AFTERIMAGE)
292/* taken from aterm-0.4.2 */ 334/* taken from aterm-0.4.2 */
293 335
741 layers[0].im = back_im; 783 layers[0].im = back_im;
742 layers[0].clip_width = szHint.width; 784 layers[0].clip_width = szHint.width;
743 layers[0].clip_height = szHint.height; 785 layers[0].clip_height = szHint.height;
744 layers[0].tint = tint; 786 layers[0].tint = tint;
745 layers[1].im = bgPixmap.original_asim; 787 layers[1].im = bgPixmap.original_asim;
746 if (bgPixmap.auto_resize) 788
747 {
748 fore_w = szHint.width;
749 fore_h = szHint.height;
750 }
751 else
752 {
753 fore_w = (bgPixmap.w == 0) ? bgPixmap.original_asim->width : bgPixmap.w; 789 fore_w = (bgPixmap.h_scale == 0) ? bgPixmap.original_asim->width : bgPixmap.h_scale*szHint.width/100;
754 fore_h = (bgPixmap.h == 0) ? bgPixmap.original_asim->height : bgPixmap.h; 790 fore_h = (bgPixmap.v_scale == 0) ? bgPixmap.original_asim->height : bgPixmap.v_scale*szHint.height/100;
755 } 791
756 if (fore_w != bgPixmap.original_asim->width 792 if (fore_w != bgPixmap.original_asim->width
757 || fore_h != bgPixmap.original_asim->height) 793 || fore_h != bgPixmap.original_asim->height)
758 { 794 {
759 layers[1].im = scale_asimage (asv, 795 layers[1].im = scale_asimage (asv,
760 bgPixmap.original_asim, 796 bgPixmap.original_asim,

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines