1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: xpm.c |
2 | * File: xpm.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: xpm.C,v 1.2 2003/11/24 17:31:28 pcg Exp $ |
4 | * $Id: xpm.C,v 1.3 2003/11/25 11:52:42 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> |
… | |
… | |
56 | int flags, changed = 0; |
56 | int flags, changed = 0; |
57 | int x = 0, y = 0; |
57 | int x = 0, y = 0; |
58 | unsigned int w = 0, h = 0; |
58 | unsigned int w = 0, h = 0; |
59 | unsigned int n; |
59 | unsigned int n; |
60 | char *p, *str; |
60 | char *p, *str; |
61 | bgPixmap_t *bgpixmap = &(R->h->bgPixmap); |
61 | bgPixmap_t *bgpixmap = &(R->bgPixmap); |
62 | |
62 | |
63 | #define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") |
63 | #define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") |
64 | |
64 | |
65 | if (geom == NULL) |
65 | if (geom == NULL) |
66 | return 0; |
66 | return 0; |
… | |
… | |
153 | unsigned int height = TermWin_TotalHeight(); |
153 | unsigned int height = TermWin_TotalHeight(); |
154 | |
154 | |
155 | if (R->TermWin.pixmap != None) |
155 | if (R->TermWin.pixmap != None) |
156 | XFreePixmap(R->Xdisplay, R->TermWin.pixmap); |
156 | XFreePixmap(R->Xdisplay, R->TermWin.pixmap); |
157 | |
157 | |
158 | if (R->h->bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */ |
158 | if (R->bgPixmap.pixmap == None) { /* So be it: I'm not using pixmaps */ |
159 | R->TermWin.pixmap = None; |
159 | R->TermWin.pixmap = None; |
160 | if (!(R->Options & Opt_transparent) || R->h->am_transparent == 0) |
160 | if (!(R->Options & Opt_transparent) || R->am_transparent == 0) |
161 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
161 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, |
162 | R->PixColors[Color_bg]); |
162 | R->PixColors[Color_bg]); |
163 | return; |
163 | return; |
164 | } |
164 | } |
165 | |
165 | |
166 | gcvalue.foreground = R->PixColors[Color_bg]; |
166 | gcvalue.foreground = R->PixColors[Color_bg]; |
167 | gc = XCreateGC(R->Xdisplay, R->TermWin.vt, GCForeground, &gcvalue); |
167 | gc = XCreateGC(R->Xdisplay, R->TermWin.vt, GCForeground, &gcvalue); |
168 | |
168 | |
169 | if (R->h->bgPixmap.pixmap != None) { /* we have a specified pixmap */ |
169 | if (R->bgPixmap.pixmap != None) { /* we have a specified pixmap */ |
170 | unsigned int w = R->h->bgPixmap.w, h = R->h->bgPixmap.h, |
170 | unsigned int w = R->bgPixmap.w, h = R->bgPixmap.h, |
171 | x = R->h->bgPixmap.x, y = R->h->bgPixmap.y; |
171 | x = R->bgPixmap.x, y = R->bgPixmap.y; |
172 | unsigned int xpmh = R->h->xpmAttr.height, |
172 | unsigned int xpmh = R->xpmAttr.height, |
173 | xpmw = R->h->xpmAttr.width; |
173 | xpmw = R->xpmAttr.width; |
174 | |
174 | |
175 | /* |
175 | /* |
176 | * don't zoom pixmap too much nor expand really small pixmaps |
176 | * don't zoom pixmap too much nor expand really small pixmaps |
177 | */ |
177 | */ |
178 | if (w > 1000 || h > 1000) |
178 | if (w > 1000 || h > 1000) |
… | |
… | |
184 | if (w == 0) { |
184 | if (w == 0) { |
185 | /* basic X tiling - let the X server do it */ |
185 | /* basic X tiling - let the X server do it */ |
186 | R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, |
186 | R->TermWin.pixmap = XCreatePixmap(R->Xdisplay, R->TermWin.vt, |
187 | xpmw, xpmh, |
187 | xpmw, xpmh, |
188 | (unsigned int)XDEPTH); |
188 | (unsigned int)XDEPTH); |
189 | XCopyArea(R->Xdisplay, R->h->bgPixmap.pixmap, R->TermWin.pixmap, gc, |
189 | XCopyArea(R->Xdisplay, R->bgPixmap.pixmap, R->TermWin.pixmap, gc, |
190 | 0, 0, xpmw, xpmh, 0, 0); |
190 | 0, 0, xpmw, xpmh, 0, 0); |
191 | } else { |
191 | } else { |
192 | float incr, p; |
192 | float incr, p; |
193 | Pixmap tmp; |
193 | Pixmap tmp; |
194 | |
194 | |
… | |
… | |
207 | |
207 | |
208 | for ( /*nil */ ; x < w; x++, p += incr) { |
208 | for ( /*nil */ ; x < w; x++, p += incr) { |
209 | if (p >= xpmw) |
209 | if (p >= xpmw) |
210 | p = 0; |
210 | p = 0; |
211 | /* copy one column from the original pixmap to the tmp pixmap */ |
211 | /* copy one column from the original pixmap to the tmp pixmap */ |
212 | XCopyArea(R->Xdisplay, R->h->bgPixmap.pixmap, tmp, gc, |
212 | XCopyArea(R->Xdisplay, R->bgPixmap.pixmap, tmp, gc, |
213 | (int)p, 0, 1, xpmh, (int)x, 0); |
213 | (int)p, 0, 1, xpmh, (int)x, 0); |
214 | } |
214 | } |
215 | |
215 | |
216 | /* |
216 | /* |
217 | * vertical scaling |
217 | * vertical scaling |
… | |
… | |
234 | XFreePixmap(R->Xdisplay, tmp); |
234 | XFreePixmap(R->Xdisplay, tmp); |
235 | } |
235 | } |
236 | } |
236 | } |
237 | XSetWindowBackgroundPixmap(R->Xdisplay, R->TermWin.vt, R->TermWin.pixmap); |
237 | XSetWindowBackgroundPixmap(R->Xdisplay, R->TermWin.vt, R->TermWin.pixmap); |
238 | XFreeGC(R->Xdisplay, gc); |
238 | XFreeGC(R->Xdisplay, gc); |
239 | R->h->am_transparent = 0; |
239 | R->am_transparent = 0; |
240 | |
240 | |
241 | XClearWindow(R->Xdisplay, R->TermWin.vt); |
241 | XClearWindow(R->Xdisplay, R->TermWin.vt); |
242 | |
242 | |
243 | XSync(R->Xdisplay, False); |
243 | XSync(R->Xdisplay, False); |
244 | } |
244 | } |
… | |
… | |
314 | { |
314 | { |
315 | char *f; |
315 | char *f; |
316 | |
316 | |
317 | assert(file != NULL); |
317 | assert(file != NULL); |
318 | |
318 | |
319 | if (R->h->bgPixmap.pixmap != None) { |
319 | if (R->bgPixmap.pixmap != None) { |
320 | XFreePixmap(R->Xdisplay, R->h->bgPixmap.pixmap); |
320 | XFreePixmap(R->Xdisplay, R->bgPixmap.pixmap); |
321 | R->h->bgPixmap.pixmap = None; |
321 | R->bgPixmap.pixmap = None; |
322 | } |
322 | } |
323 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]); |
323 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]); |
324 | |
324 | |
325 | if (*file != '\0') { |
325 | if (*file != '\0') { |
326 | /* XWindowAttributes attr; */ |
326 | /* XWindowAttributes attr; */ |
… | |
… | |
328 | /* |
328 | /* |
329 | * we already have the required attributes |
329 | * we already have the required attributes |
330 | */ |
330 | */ |
331 | /* XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &attr); */ |
331 | /* XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &attr); */ |
332 | |
332 | |
333 | R->h->xpmAttr.closeness = 30000; |
333 | R->xpmAttr.closeness = 30000; |
334 | R->h->xpmAttr.colormap = XCMAP; |
334 | R->xpmAttr.colormap = XCMAP; |
335 | R->h->xpmAttr.visual = XVISUAL; |
335 | R->xpmAttr.visual = XVISUAL; |
336 | R->h->xpmAttr.depth = XDEPTH; |
336 | R->xpmAttr.depth = XDEPTH; |
337 | R->h->xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | |
337 | R->xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | |
338 | XpmDepth | XpmSize | XpmReturnPixels); |
338 | XpmDepth | XpmSize | XpmReturnPixels); |
339 | |
339 | |
340 | /* search environment variables here too */ |
340 | /* search environment variables here too */ |
341 | f = (char *)rxvt_File_find(file, ".xpm", R->h->rs[Rs_path]); |
341 | f = (char *)rxvt_File_find(file, ".xpm", R->rs[Rs_path]); |
342 | if (f == NULL |
342 | if (f == NULL |
343 | || XpmReadFileToPixmap(R->Xdisplay, Xroot, f, |
343 | || XpmReadFileToPixmap(R->Xdisplay, Xroot, f, |
344 | &R->h->bgPixmap.pixmap, NULL, |
344 | &R->bgPixmap.pixmap, NULL, |
345 | &R->h->xpmAttr)) { |
345 | &R->xpmAttr)) { |
346 | char *p; |
346 | char *p; |
347 | |
347 | |
348 | /* semi-colon delimited */ |
348 | /* semi-colon delimited */ |
349 | if ((p = STRCHR(file, ';')) == NULL) |
349 | if ((p = STRCHR(file, ';')) == NULL) |
350 | p = STRCHR(file, '\0'); |
350 | p = STRCHR(file, '\0'); |
… | |
… | |
353 | file); |
353 | file); |
354 | } |
354 | } |
355 | free(f); |
355 | free(f); |
356 | } |
356 | } |
357 | rxvt_resize_pixmap(aR); |
357 | rxvt_resize_pixmap(aR); |
358 | return R->h->bgPixmap.pixmap; |
358 | return R->bgPixmap.pixmap; |
359 | } |
359 | } |
360 | |
360 | |
361 | #endif /* XPM_BACKGROUND */ |
361 | #endif /* XPM_BACKGROUND */ |