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.27 by root, Wed Jan 4 04:42:45 2006 UTC vs.
Revision 1.29 by root, Wed Jan 25 21:03:04 2006 UTC

50 * @ `?' 50 * @ `?'
51 */ 51 */
52int 52int
53rxvt_term::scale_pixmap (const char *geom) 53rxvt_term::scale_pixmap (const char *geom)
54{ 54{
55 int flags, changed = 0; 55 int flags, changed = 0;
56 int x = 0, y = 0; 56 int x = 0, y = 0;
57 unsigned int w = 0, h = 0; 57 unsigned int w = 0, h = 0;
58 unsigned int n; 58 unsigned int n;
59 char *p, *str; 59 char *p;
60 bgPixmap_t *bgpixmap = & (bgPixmap); 60 bgPixmap_t *bgpixmap = & (bgPixmap);
61 61
62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 62#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]")
63 63
64 if (geom == NULL) 64 if (geom == NULL)
65 return 0; 65 return 0;
66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 66
67 char str[MAXLEN_GEOM];
68
67 if (!strcmp (geom, "?")) 69 if (!strcmp (geom, "?"))
68 { 70 {
69 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 71 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
70 min (bgpixmap->w, 9999), min (bgpixmap->h, 9999), 72 min (bgpixmap->w, 32767), min (bgpixmap->h, 32767),
71 min (bgpixmap->x, 9999), min (bgpixmap->y, 9999)); 73 min (bgpixmap->x, 32767), min (bgpixmap->y, 32767));
72 process_xterm_seq (XTerm_title, str, CHAR_ST); 74 process_xterm_seq (XTerm_title, str, CHAR_ST);
73 free (str);
74 return 0; 75 return 0;
75 } 76 }
76 77
77 if ((p = strchr (geom, ';')) == NULL) 78 if ((p = strchr (geom, ';')) == NULL)
78 p = strchr (geom, '\0'); 79 p = strchr (geom, '\0');
80
79 n = (p - geom); 81 n = (p - geom);
80 if (n <= MAXLEN_GEOM) 82 if (n <= MAXLEN_GEOM)
81 { 83 {
82 strncpy (str, geom, n); 84 strncpy (str, geom, n);
83 str[n] = '\0'; 85 str[n] = '\0';
84 86
85 flags = XParseGeometry (str, &x, &y, &w, &h); 87 flags = XParseGeometry (str, &x, &y, &w, &h);
88
86 if (!flags) 89 if (!flags)
87 { 90 {
88 flags |= WidthValue; 91 flags |= WidthValue;
89 w = 0; 92 w = 0;
90 } /* default is tile */ 93 } /* default is tile */
94
91 if (flags & WidthValue) 95 if (flags & WidthValue)
92 { 96 {
93 if (! (flags & XValue)) 97 if (!(flags & XValue))
94 x = 50; 98 x = 50;
99
95 if (! (flags & HeightValue)) 100 if (!(flags & HeightValue))
96 h = w; 101 h = w;
102
97 if (w && !h) 103 if (w && !h)
98 { 104 {
99 w = (bgpixmap->w * w) / 100; 105 w = (bgpixmap->w * w) / 100;
100 h = bgpixmap->h; 106 h = bgpixmap->h;
101 } 107 }
102 else if (h && !w) 108 else if (h && !w)
103 { 109 {
104 w = bgpixmap->w; 110 w = bgpixmap->w;
105 h = (bgpixmap->h * h) / 100; 111 h = (bgpixmap->h * h) / 100;
106 } 112 }
107 if (w > 1000) 113
108 w = 1000; 114 min_it (w, 32767);
109 if (h > 1000) 115 min_it (h, 32767);
110 h = 1000; 116
111 if (bgpixmap->w != (short)w) 117 if (bgpixmap->w != (short)w)
112 { 118 {
113 bgpixmap->w = (short)w; 119 bgpixmap->w = (short)w;
114 changed++; 120 changed++;
115 } 121 }
122
116 if (bgpixmap->h != (short)h) 123 if (bgpixmap->h != (short)h)
117 { 124 {
118 bgpixmap->h = (short)h; 125 bgpixmap->h = (short)h;
119 changed++; 126 changed++;
120 } 127 }
121 } 128 }
129
122 if (! (flags & YValue)) 130 if (!(flags & YValue))
123 { 131 {
124 if (flags & XNegative) 132 if (flags & XNegative)
125 flags |= YNegative; 133 flags |= YNegative;
134
126 y = x; 135 y = x;
127 } 136 }
128 137
129 if (! (flags & WidthValue) && geom[0] != '=') 138 if (!(flags & WidthValue) && geom[0] != '=')
130 { 139 {
131 x += bgpixmap->x; 140 x += bgpixmap->x;
132 y += bgpixmap->y; 141 y += bgpixmap->y;
133 } 142 }
134 else 143
135 { 144 if (xpmAttr.width && xpmAttr.height)
136 if (flags & XNegative)
137 x += 100;
138 if (flags & YNegative)
139 y += 100;
140 } 145 {
141 min_it (x, 100); 146 x = MOD(x, xpmAttr.width);
142 min_it (y, 100); 147 y = MOD(y, xpmAttr.height);
143 max_it (x, 0); 148 }
144 max_it (y, 0); 149
145 if (bgpixmap->x != x) 150 if (bgpixmap->x != x)
146 { 151 {
147 bgpixmap->x = x; 152 bgpixmap->x = x;
148 changed++; 153 changed++;
149 } 154 }
155
150 if (bgpixmap->y != y) 156 if (bgpixmap->y != y)
151 { 157 {
152 bgpixmap->y = y; 158 bgpixmap->y = y;
153 changed++; 159 changed++;
154 } 160 }
155 } 161 }
156 free (str); 162
157 return changed; 163 return changed;
158} 164}
159 165
160void 166void
161rxvt_term::resize_pixmap () 167rxvt_term::resize_pixmap ()
162{ 168{
163 XGCValues gcvalue; 169 XGCValues gcvalue;
164 GC gc; 170 GC gc;
165 dDisp;
166 171
167 if (pixmap != None) 172 if (pixmap != None)
168 XFreePixmap (disp, pixmap); 173 XFreePixmap (xdisp, pixmap);
169 174
170 if (bgPixmap.pixmap == None) 175 if (bgPixmap.pixmap == None)
171 { /* So be it: I'm not using pixmaps */ 176 { /* So be it: I'm not using pixmaps */
172 pixmap = None; 177 pixmap = None;
173 178
174 if (!OPTION (Opt_transparent) || !am_transparent) 179 if (!OPTION (Opt_transparent) || !am_transparent)
175 XSetWindowBackground (disp, vt, pix_colors[Color_bg]); 180 XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]);
176 181
177 return; 182 return;
178 } 183 }
179 184
180 gcvalue.foreground = pix_colors[Color_bg]; 185 gcvalue.foreground = pix_colors[Color_bg];
181 gc = XCreateGC (disp, vt, GCForeground, &gcvalue); 186 gc = XCreateGC (xdisp, vt, GCForeground, &gcvalue);
182 187
183 if (bgPixmap.pixmap != None) 188 if (bgPixmap.pixmap != None)
184 { /* we have a specified pixmap */ 189 { /* we have a specified pixmap */
185 unsigned int w = bgPixmap.w, h = bgPixmap.h, 190 unsigned int w = bgPixmap.w, h = bgPixmap.h,
186 x = bgPixmap.x, y = bgPixmap.y; 191 x = bgPixmap.x, y = bgPixmap.y;
187 unsigned int xpmh = xpmAttr.height, 192 unsigned int xpmh = xpmAttr.height,
188 xpmw = xpmAttr.width; 193 xpmw = xpmAttr.width;
189 194
190 /* 195 /*
191 * don't zoom pixmap too much nor expand really small pixmaps 196 * don't zoom pixmap too much nor expand really small pixmaps
192 */ 197 */
193 if (w > 1000 || h > 1000) 198 if (w > 32767 || h > 32767)
194 w = 1; 199 w = 1;
195 else if (width > (10 * xpmw) 200 else if (width > (10 * xpmw)
196 || height > (10 * xpmh)) 201 || height > (10 * xpmh))
197 w = 0; /* tile */ 202 w = 0; /* tile */
198 203
199 if (w == 0) 204 if (!w)
200 { 205 {
201 /* basic X tiling - let the X server do it */ 206 /* basic X tiling - let the X server do it */
202 pixmap = XCreatePixmap (disp, vt, xpmw, xpmh, 207 pixmap = XCreatePixmap (xdisp, vt, xpmw, xpmh, depth);
203 (unsigned int)display->depth); 208
204 XCopyArea (disp, bgPixmap.pixmap, pixmap, gc, 209 XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0);
205 0, 0, xpmw, xpmh, 0, 0); 210 XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y);
211 XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0);
212 XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y);
206 } 213 }
207 else 214 else
208 { 215 {
209 float incr, p; 216 float incr, p;
210 Pixmap tmp; 217 Pixmap tmp;
211 218
212 pixmap = XCreatePixmap (disp, vt, width, height, 219 pixmap = XCreatePixmap (xdisp, vt, width, height, depth);
213 (unsigned int)display->depth);
214 /* 220 /*
215 * horizontal scaling 221 * horizontal scaling
216 */ 222 */
217 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw); 223 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
218 224
219 tmp = XCreatePixmap (disp, vt, width, xpmh, (unsigned int)display->depth); 225 tmp = XCreatePixmap (xdisp, vt, width, xpmh, depth);
220 XFillRectangle (disp, tmp, gc, 0, 0, width, xpmh); 226 XFillRectangle (xdisp, tmp, gc, 0, 0, width, xpmh);
221 227
222 for ( /*nil */ ; x < w; x++, p += incr) 228 for ( /*nil */ ; x < w; x++, p += incr)
223 { 229 {
224 if (p >= xpmw) 230 if (p >= xpmw)
225 p = 0; 231 p = 0;
232
226 /* copy one column from the original pixmap to the tmp pixmap */ 233 /* copy one column from the original pixmap to the tmp pixmap */
227 XCopyArea (disp, bgPixmap.pixmap, tmp, gc, 234 XCopyArea (xdisp, bgPixmap.pixmap, tmp, gc, (int)p, 0, 1, xpmh, (int)x, 0);
228 (int)p, 0, 1, xpmh, (int)x, 0);
229 } 235 }
230 236
231 /* 237 /*
232 * vertical scaling 238 * vertical scaling
233 */ 239 */
234 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh); 240 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
235 241
236 if (y > 0) 242 if (y > 0)
237 XFillRectangle (disp, pixmap, gc, 0, 0, width, y); 243 XFillRectangle (xdisp, pixmap, gc, 0, 0, width, y);
238 244
239 if (h < height) 245 if (h < height)
240 XFillRectangle (disp, pixmap, gc, 0, (int)h, width, height - h + 1); 246 XFillRectangle (xdisp, pixmap, gc, 0, (int)h, width, height - h + 1);
241 247
242 for ( /*nil */ ; y < h; y++, p += incr) 248 for ( /*nil */ ; y < h; y++, p += incr)
243 { 249 {
244 if (p >= xpmh) 250 if (p >= xpmh)
245 p = 0; 251 p = 0;
246 252
247 /* copy one row from the tmp pixmap to the main pixmap */ 253 /* copy one row from the tmp pixmap to the main pixmap */
248 XCopyArea (disp, tmp, pixmap, gc, 254 XCopyArea (xdisp, tmp, pixmap, gc, 0, (int)p, width, 1, 0, (int)y);
249 0, (int)p, width, 1, 0, (int)y);
250 } 255 }
251 256
252 XFreePixmap (disp, tmp); 257 XFreePixmap (xdisp, tmp);
253 } 258 }
254 } 259 }
255 260
256 XSetWindowBackgroundPixmap (disp, vt, pixmap); 261 XSetWindowBackgroundPixmap (xdisp, vt, pixmap);
262
263 if (pixmap != None)
264 {
265 XFreePixmap (xdisp, pixmap);
266 pixmap = None;
267 }
268
257 XFreeGC (disp, gc); 269 XFreeGC (xdisp, gc);
258 am_transparent = 0; 270 am_transparent = 0;
259} 271}
260 272
261/* 273/*
262 * Calculate tiling sizes and increments 274 * Calculate tiling sizes and increments
357 * we already have the required attributes 369 * we already have the required attributes
358 */ 370 */
359 /* XGetWindowAttributes (display->display, vt, &attr); */ 371 /* XGetWindowAttributes (display->display, vt, &attr); */
360 372
361 xpmAttr.closeness = 30000; 373 xpmAttr.closeness = 30000;
362 xpmAttr.colormap = display->cmap; 374 xpmAttr.colormap = cmap;
363 xpmAttr.visual = display->visual; 375 xpmAttr.visual = visual;
364 xpmAttr.depth = display->depth; 376 xpmAttr.depth = depth;
365 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | 377 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual
366 XpmDepth | XpmSize | XpmReturnPixels); 378 | XpmDepth | XpmSize | XpmReturnPixels);
367 379
368 /* search environment variables here too */ 380 /* search environment variables here too */
369 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); 381 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
370 if (f == NULL 382 if (f == NULL
371 || XpmReadFileToPixmap (display->display, display->root, f, 383 || XpmReadFileToPixmap (display->display, display->root, f,
372 &bgPixmap.pixmap, NULL, 384 &bgPixmap.pixmap, NULL,
373 &xpmAttr)) 385 &xpmAttr))
374 { 386 {
375 char *p; 387 char *p;
376 388
377 /* semi-colon delimited */ 389 /* semi-colon delimited */
378 if ((p = strchr (file, ';')) == NULL) 390 if ((p = strchr (file, ';')) == NULL)

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines