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.4 by pcg, Thu Dec 18 02:07:12 2003 UTC vs.
Revision 1.5 by pcg, Sat Jan 31 00:20:21 2004 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: xpm.c 2 * File: xpm.c
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: xpm.C,v 1.4 2003/12/18 02:07:12 pcg Exp $ 4 * $Id: xpm.C,v 1.5 2004/01/31 00:20:21 pcg Exp $
5 * 5 *
6 * All portions of code are copyright by their respective author/s. 6 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au> 7 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
8 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 8 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
9 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 9 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
47 * @ `+X' -> Y = X 47 * @ `+X' -> Y = X
48 * 48 *
49 * And this GEOM string is for querying current scale/position: 49 * And this GEOM string is for querying current scale/position:
50 * @ `?' 50 * @ `?'
51 */ 51 */
52/* EXTPROTO */
53int 52int
54rxvt_scale_pixmap(pR_ const char *geom) 53rxvt_term::scale_pixmap (const char *geom)
55{ 54{
56 int flags, changed = 0; 55 int flags, changed = 0;
57 int x = 0, y = 0; 56 int x = 0, y = 0;
58 unsigned int w = 0, h = 0; 57 unsigned int w = 0, h = 0;
59 unsigned int n; 58 unsigned int n;
60 char *p, *str; 59 char *p, *str;
61 bgPixmap_t *bgpixmap = &(R->bgPixmap); 60 bgPixmap_t *bgpixmap = &(bgPixmap);
62 61
63#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]")
64 63
65 if (geom == NULL) 64 if (geom == NULL)
66 return 0; 65 return 0;
67 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1);
68 if (!STRCMP(geom, "?")) { 67 if (!STRCMP(geom, "?")) {
69 sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */ 68 sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */
70 min(bgpixmap->w, 9999), min(bgpixmap->h, 9999), 69 min(bgpixmap->w, 9999), min(bgpixmap->h, 9999),
71 min(bgpixmap->x, 9999), min(bgpixmap->y, 9999)); 70 min(bgpixmap->x, 9999), min(bgpixmap->y, 9999));
72 rxvt_xterm_seq(aR_ XTerm_title, str, CHAR_ST); 71 xterm_seq (XTerm_title, str, CHAR_ST);
73 free(str); 72 free(str);
74 return 0; 73 return 0;
75 } 74 }
76 75
77 if ((p = STRCHR(geom, ';')) == NULL) 76 if ((p = STRCHR(geom, ';')) == NULL)
141 } 140 }
142 free(str); 141 free(str);
143 return changed; 142 return changed;
144} 143}
145 144
146/* EXTPROTO */
147void 145void
148rxvt_resize_pixmap(pR) 146rxvt_term::resize_pixmap ()
149{ 147{
150 XGCValues gcvalue; 148 XGCValues gcvalue;
151 GC gc; 149 GC gc;
152 unsigned int width = TermWin_TotalWidth(); 150 unsigned int width = TermWin_TotalWidth();
153 unsigned int height = TermWin_TotalHeight(); 151 unsigned int height = TermWin_TotalHeight();
154 152
155 if (R->TermWin.pixmap != None) 153 if (TermWin.pixmap != None)
156 XFreePixmap(R->Xdisplay, R->TermWin.pixmap); 154 XFreePixmap(Xdisplay, TermWin.pixmap);
157 155
158 if (R->bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */ 156 if (bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */
159 R->TermWin.pixmap = None; 157 TermWin.pixmap = None;
160 if (!(R->Options & Opt_transparent) || R->am_transparent == 0) 158 if (!(Options & Opt_transparent) || am_transparent == 0)
161 XSetWindowBackground(R->Xdisplay, R->TermWin.vt, 159 XSetWindowBackground(Xdisplay, TermWin.vt,
162 R->PixColors[Color_bg]); 160 PixColors[Color_bg]);
163 return; 161 return;
164 } 162 }
165 163
166 gcvalue.foreground = R->PixColors[Color_bg]; 164 gcvalue.foreground = PixColors[Color_bg];
167 gc = XCreateGC(R->Xdisplay, R->TermWin.vt, GCForeground, &gcvalue); 165 gc = XCreateGC(Xdisplay, TermWin.vt, GCForeground, &gcvalue);
168 166
169 if (R->bgPixmap.pixmap != None) { /* we have a specified pixmap */ 167 if (bgPixmap.pixmap != None) { /* we have a specified pixmap */
170 unsigned int w = R->bgPixmap.w, h = R->bgPixmap.h, 168 unsigned int w = bgPixmap.w, h = bgPixmap.h,
171 x = R->bgPixmap.x, y = R->bgPixmap.y; 169 x = bgPixmap.x, y = bgPixmap.y;
172 unsigned int xpmh = R->xpmAttr.height, 170 unsigned int xpmh = xpmAttr.height,
173 xpmw = R->xpmAttr.width; 171 xpmw = xpmAttr.width;
174 172
175 /* 173 /*
176 * don't zoom pixmap too much nor expand really small pixmaps 174 * don't zoom pixmap too much nor expand really small pixmaps
177 */ 175 */
178 if (w > 1000 || h > 1000) 176 if (w > 1000 || h > 1000)
181 || height > (10 * xpmh)) 179 || height > (10 * xpmh))
182 w = 0; /* tile */ 180 w = 0; /* tile */
183 181
184 if (w == 0) { 182 if (w == 0) {
185 /* basic X tiling - let the X server do it */ 183 /* basic X tiling - let the X server do it */
186 R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 184 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt,
187 xpmw, xpmh, 185 xpmw, xpmh,
188 (unsigned int)XDEPTH); 186 (unsigned int)XDEPTH);
189 XCopyArea(R->Xdisplay, R->bgPixmap.pixmap, R->TermWin.pixmap, gc, 187 XCopyArea(Xdisplay, bgPixmap.pixmap, TermWin.pixmap, gc,
190 0, 0, xpmw, xpmh, 0, 0); 188 0, 0, xpmw, xpmh, 0, 0);
191 } else { 189 } else {
192 float incr, p; 190 float incr, p;
193 Pixmap tmp; 191 Pixmap tmp;
194 192
195 R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 193 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt,
196 width, height, 194 width, height,
197 (unsigned int)XDEPTH); 195 (unsigned int)XDEPTH);
198 /* 196 /*
199 * horizontal scaling 197 * horizontal scaling
200 */ 198 */
201 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); 199 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw);
202 200
203 tmp = XCreatePixmap(R->Xdisplay, R->TermWin.vt, 201 tmp = XCreatePixmap(Xdisplay, TermWin.vt,
204 width, xpmh, (unsigned int)XDEPTH); 202 width, xpmh, (unsigned int)XDEPTH);
205 XFillRectangle(R->Xdisplay, tmp, gc, 0, 0, width, 203 XFillRectangle(Xdisplay, tmp, gc, 0, 0, width,
206 xpmh); 204 xpmh);
207 205
208 for ( /*nil */ ; x < w; x++, p += incr) { 206 for ( /*nil */ ; x < w; x++, p += incr) {
209 if (p >= xpmw) 207 if (p >= xpmw)
210 p = 0; 208 p = 0;
211 /* copy one column from the original pixmap to the tmp pixmap */ 209 /* copy one column from the original pixmap to the tmp pixmap */
212 XCopyArea(R->Xdisplay, R->bgPixmap.pixmap, tmp, gc, 210 XCopyArea(Xdisplay, bgPixmap.pixmap, tmp, gc,
213 (int)p, 0, 1, xpmh, (int)x, 0); 211 (int)p, 0, 1, xpmh, (int)x, 0);
214 } 212 }
215 213
216 /* 214 /*
217 * vertical scaling 215 * vertical scaling
218 */ 216 */
219 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); 217 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh);
220 218
221 if (y > 0) 219 if (y > 0)
222 XFillRectangle(R->Xdisplay, R->TermWin.pixmap, gc, 0, 0, width, 220 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, 0, width,
223 y); 221 y);
224 if (h < height) 222 if (h < height)
225 XFillRectangle(R->Xdisplay, R->TermWin.pixmap, gc, 0, (int)h, 223 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, (int)h,
226 width, height - h + 1); 224 width, height - h + 1);
227 for ( /*nil */ ; y < h; y++, p += incr) { 225 for ( /*nil */ ; y < h; y++, p += incr) {
228 if (p >= xpmh) 226 if (p >= xpmh)
229 p = 0; 227 p = 0;
230 /* copy one row from the tmp pixmap to the main pixmap */ 228 /* copy one row from the tmp pixmap to the main pixmap */
231 XCopyArea(R->Xdisplay, tmp, R->TermWin.pixmap, gc, 229 XCopyArea(Xdisplay, tmp, TermWin.pixmap, gc,
232 0, (int)p, width, 1, 0, (int)y); 230 0, (int)p, width, 1, 0, (int)y);
233 } 231 }
234 XFreePixmap(R->Xdisplay, tmp); 232 XFreePixmap(Xdisplay, tmp);
235 } 233 }
236 } 234 }
237 XSetWindowBackgroundPixmap(R->Xdisplay, R->TermWin.vt, R->TermWin.pixmap); 235 XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt, TermWin.pixmap);
238 XFreeGC(R->Xdisplay, gc); 236 XFreeGC(Xdisplay, gc);
239 R->am_transparent = 0; 237 am_transparent = 0;
240 238
241 XClearWindow(R->Xdisplay, R->TermWin.vt); 239 XClearWindow(Xdisplay, TermWin.vt);
242 240
243 XSync(R->Xdisplay, False); 241 XSync(Xdisplay, False);
244} 242}
245 243
246/* 244/*
247 * Calculate tiling sizes and increments 245 * Calculate tiling sizes and increments
248 * At start, p == 0, incr == xpmwidthheight 246 * At start, p == 0, incr == xpmwidthheight
249 */ 247 */
250/* INTPROTO */
251void 248void
252rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) 249rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
253{ 250{
254 unsigned int cwh, cxy; 251 unsigned int cwh, cxy;
255 float cincr, cp; 252 float cincr, cp;
306 *xy = cxy; 303 *xy = cxy;
307 *incr = cincr; 304 *incr = cincr;
308 *p = cp; 305 *p = cp;
309} 306}
310 307
311/* EXTPROTO */
312Pixmap 308Pixmap
313rxvt_set_bgPixmap(pR_ const char *file) 309rxvt_term::set_bgPixmap (const char *file)
314{ 310{
315 char *f; 311 char *f;
316 312
317 assert(file != NULL); 313 assert(file != NULL);
318 314
319 if (R->bgPixmap.pixmap != None) { 315 if (bgPixmap.pixmap != None) {
320 XFreePixmap(R->Xdisplay, R->bgPixmap.pixmap); 316 XFreePixmap(Xdisplay, bgPixmap.pixmap);
321 R->bgPixmap.pixmap = None; 317 bgPixmap.pixmap = None;
322 } 318 }
323 XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]); 319 XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]);
324 320
325 if (*file != '\0') { 321 if (*file != '\0') {
326/* XWindowAttributes attr; */ 322/* XWindowAttributes attr; */
327 323
328 /* 324 /*
329 * we already have the required attributes 325 * we already have the required attributes
330 */ 326 */
331/* XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &attr); */ 327/* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */
332 328
333 R->xpmAttr.closeness = 30000; 329 xpmAttr.closeness = 30000;
334 R->xpmAttr.colormap = XCMAP; 330 xpmAttr.colormap = XCMAP;
335 R->xpmAttr.visual = XVISUAL; 331 xpmAttr.visual = XVISUAL;
336 R->xpmAttr.depth = XDEPTH; 332 xpmAttr.depth = XDEPTH;
337 R->xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | 333 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
338 XpmDepth | XpmSize | XpmReturnPixels); 334 XpmDepth | XpmSize | XpmReturnPixels);
339 335
340 /* search environment variables here too */ 336 /* search environment variables here too */
341 f = (char *)rxvt_File_find(file, ".xpm", R->rs[Rs_path]); 337 f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]);
342 if (f == NULL 338 if (f == NULL
343 || XpmReadFileToPixmap(R->Xdisplay, Xroot, f, 339 || XpmReadFileToPixmap(Xdisplay, Xroot, f,
344 &R->bgPixmap.pixmap, NULL, 340 &bgPixmap.pixmap, NULL,
345 &R->xpmAttr)) { 341 &xpmAttr)) {
346 char *p; 342 char *p;
347 343
348 /* semi-colon delimited */ 344 /* semi-colon delimited */
349 if ((p = STRCHR(file, ';')) == NULL) 345 if ((p = STRCHR(file, ';')) == NULL)
350 p = STRCHR(file, '\0'); 346 p = STRCHR(file, '\0');
352 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), 348 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file),
353 file); 349 file);
354 } 350 }
355 free(f); 351 free(f);
356 } 352 }
357 rxvt_resize_pixmap(aR); 353 resize_pixmap ();
358 return R->bgPixmap.pixmap; 354 return bgPixmap.pixmap;
359} 355}
360 356
361#endif /* XPM_BACKGROUND */ 357#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines