1 | /*--------------------------------*-C-*---------------------------------* |
1 | /*--------------------------------*-C-*---------------------------------* |
2 | * File: xpm.c |
2 | * File: xpm.c |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * $Id: xpm.C,v 1.7 2004/02/01 01:34:41 pcg Exp $ |
4 | * $Id: xpm.C,v 1.8 2004/02/09 07:11:49 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> |
… | |
… | |
164 | GC gc; |
164 | GC gc; |
165 | unsigned int width = TermWin_TotalWidth(); |
165 | unsigned int width = TermWin_TotalWidth(); |
166 | unsigned int height = TermWin_TotalHeight(); |
166 | unsigned int height = TermWin_TotalHeight(); |
167 | |
167 | |
168 | if (TermWin.pixmap != None) |
168 | if (TermWin.pixmap != None) |
169 | XFreePixmap(Xdisplay, TermWin.pixmap); |
169 | XFreePixmap(display->display, TermWin.pixmap); |
170 | |
170 | |
171 | if (bgPixmap.pixmap == None) |
171 | if (bgPixmap.pixmap == None) |
172 | { /* So be it: I'm not using pixmaps */ |
172 | { /* So be it: I'm not using pixmaps */ |
173 | TermWin.pixmap = None; |
173 | TermWin.pixmap = None; |
174 | if (!(Options & Opt_transparent) || am_transparent == 0) |
174 | if (!(Options & Opt_transparent) || am_transparent == 0) |
175 | XSetWindowBackground(Xdisplay, TermWin.vt, |
175 | XSetWindowBackground(display->display, TermWin.vt, |
176 | PixColors[Color_bg]); |
176 | PixColors[Color_bg]); |
177 | return; |
177 | return; |
178 | } |
178 | } |
179 | |
179 | |
180 | gcvalue.foreground = PixColors[Color_bg]; |
180 | gcvalue.foreground = PixColors[Color_bg]; |
181 | gc = XCreateGC(Xdisplay, TermWin.vt, GCForeground, &gcvalue); |
181 | gc = XCreateGC(display->display, TermWin.vt, GCForeground, &gcvalue); |
182 | |
182 | |
183 | if (bgPixmap.pixmap != None) |
183 | if (bgPixmap.pixmap != None) |
184 | { /* we have a specified pixmap */ |
184 | { /* we have a specified pixmap */ |
185 | unsigned int w = bgPixmap.w, h = bgPixmap.h, |
185 | unsigned int w = bgPixmap.w, h = bgPixmap.h, |
186 | x = bgPixmap.x, y = bgPixmap.y; |
186 | x = bgPixmap.x, y = bgPixmap.y; |
… | |
… | |
197 | w = 0; /* tile */ |
197 | w = 0; /* tile */ |
198 | |
198 | |
199 | if (w == 0) |
199 | if (w == 0) |
200 | { |
200 | { |
201 | /* basic X tiling - let the X server do it */ |
201 | /* basic X tiling - let the X server do it */ |
202 | TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, |
202 | TermWin.pixmap = XCreatePixmap(display->display, TermWin.vt, |
203 | xpmw, xpmh, |
203 | xpmw, xpmh, |
204 | (unsigned int)XDEPTH); |
204 | (unsigned int)XDEPTH); |
205 | XCopyArea(Xdisplay, bgPixmap.pixmap, TermWin.pixmap, gc, |
205 | XCopyArea(display->display, bgPixmap.pixmap, TermWin.pixmap, gc, |
206 | 0, 0, xpmw, xpmh, 0, 0); |
206 | 0, 0, xpmw, xpmh, 0, 0); |
207 | } |
207 | } |
208 | else |
208 | else |
209 | { |
209 | { |
210 | float incr, p; |
210 | float incr, p; |
211 | Pixmap tmp; |
211 | Pixmap tmp; |
212 | |
212 | |
213 | TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, |
213 | TermWin.pixmap = XCreatePixmap(display->display, TermWin.vt, |
214 | width, height, |
214 | width, height, |
215 | (unsigned int)XDEPTH); |
215 | (unsigned int)XDEPTH); |
216 | /* |
216 | /* |
217 | * horizontal scaling |
217 | * horizontal scaling |
218 | */ |
218 | */ |
219 | rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); |
219 | rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); |
220 | |
220 | |
221 | tmp = XCreatePixmap(Xdisplay, TermWin.vt, |
221 | tmp = XCreatePixmap(display->display, TermWin.vt, |
222 | width, xpmh, (unsigned int)XDEPTH); |
222 | width, xpmh, (unsigned int)XDEPTH); |
223 | XFillRectangle(Xdisplay, tmp, gc, 0, 0, width, |
223 | XFillRectangle(display->display, tmp, gc, 0, 0, width, |
224 | xpmh); |
224 | xpmh); |
225 | |
225 | |
226 | for ( /*nil */ ; x < w; x++, p += incr) |
226 | for ( /*nil */ ; x < w; x++, p += incr) |
227 | { |
227 | { |
228 | if (p >= xpmw) |
228 | if (p >= xpmw) |
229 | p = 0; |
229 | p = 0; |
230 | /* copy one column from the original pixmap to the tmp pixmap */ |
230 | /* copy one column from the original pixmap to the tmp pixmap */ |
231 | XCopyArea(Xdisplay, bgPixmap.pixmap, tmp, gc, |
231 | XCopyArea(display->display, bgPixmap.pixmap, tmp, gc, |
232 | (int)p, 0, 1, xpmh, (int)x, 0); |
232 | (int)p, 0, 1, xpmh, (int)x, 0); |
233 | } |
233 | } |
234 | |
234 | |
235 | /* |
235 | /* |
236 | * vertical scaling |
236 | * vertical scaling |
237 | */ |
237 | */ |
238 | rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); |
238 | rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); |
239 | |
239 | |
240 | if (y > 0) |
240 | if (y > 0) |
241 | XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, 0, width, |
241 | XFillRectangle(display->display, TermWin.pixmap, gc, 0, 0, width, |
242 | y); |
242 | y); |
243 | if (h < height) |
243 | if (h < height) |
244 | XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, (int)h, |
244 | XFillRectangle(display->display, TermWin.pixmap, gc, 0, (int)h, |
245 | width, height - h + 1); |
245 | width, height - h + 1); |
246 | for ( /*nil */ ; y < h; y++, p += incr) |
246 | for ( /*nil */ ; y < h; y++, p += incr) |
247 | { |
247 | { |
248 | if (p >= xpmh) |
248 | if (p >= xpmh) |
249 | p = 0; |
249 | p = 0; |
250 | /* copy one row from the tmp pixmap to the main pixmap */ |
250 | /* copy one row from the tmp pixmap to the main pixmap */ |
251 | XCopyArea(Xdisplay, tmp, TermWin.pixmap, gc, |
251 | XCopyArea(display->display, tmp, TermWin.pixmap, gc, |
252 | 0, (int)p, width, 1, 0, (int)y); |
252 | 0, (int)p, width, 1, 0, (int)y); |
253 | } |
253 | } |
254 | XFreePixmap(Xdisplay, tmp); |
254 | XFreePixmap(display->display, tmp); |
255 | } |
255 | } |
256 | } |
256 | } |
257 | XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt, TermWin.pixmap); |
257 | XSetWindowBackgroundPixmap(display->display, TermWin.vt, TermWin.pixmap); |
258 | XFreeGC(Xdisplay, gc); |
258 | XFreeGC(display->display, gc); |
259 | am_transparent = 0; |
259 | am_transparent = 0; |
260 | |
260 | |
261 | XClearWindow(Xdisplay, TermWin.vt); |
261 | XClearWindow(display->display, TermWin.vt); |
262 | |
262 | |
263 | XSync(Xdisplay, False); |
263 | XSync(display->display, False); |
264 | } |
264 | } |
265 | |
265 | |
266 | /* |
266 | /* |
267 | * Calculate tiling sizes and increments |
267 | * Calculate tiling sizes and increments |
268 | * At start, p == 0, incr == xpmwidthheight |
268 | * At start, p == 0, incr == xpmwidthheight |
… | |
… | |
347 | |
347 | |
348 | assert(file != NULL); |
348 | assert(file != NULL); |
349 | |
349 | |
350 | if (bgPixmap.pixmap != None) |
350 | if (bgPixmap.pixmap != None) |
351 | { |
351 | { |
352 | XFreePixmap(Xdisplay, bgPixmap.pixmap); |
352 | XFreePixmap(display->display, bgPixmap.pixmap); |
353 | bgPixmap.pixmap = None; |
353 | bgPixmap.pixmap = None; |
354 | } |
354 | } |
355 | XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]); |
355 | XSetWindowBackground(display->display, TermWin.vt, PixColors[Color_bg]); |
356 | |
356 | |
357 | if (*file != '\0') |
357 | if (*file != '\0') |
358 | { |
358 | { |
359 | /* XWindowAttributes attr; */ |
359 | /* XWindowAttributes attr; */ |
360 | |
360 | |
361 | /* |
361 | /* |
362 | * we already have the required attributes |
362 | * we already have the required attributes |
363 | */ |
363 | */ |
364 | /* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */ |
364 | /* XGetWindowAttributes(display->display, TermWin.vt, &attr); */ |
365 | |
365 | |
366 | xpmAttr.closeness = 30000; |
366 | xpmAttr.closeness = 30000; |
367 | xpmAttr.colormap = XCMAP; |
367 | xpmAttr.colormap = XCMAP; |
368 | xpmAttr.visual = XVISUAL; |
368 | xpmAttr.visual = XVISUAL; |
369 | xpmAttr.depth = XDEPTH; |
369 | xpmAttr.depth = XDEPTH; |
… | |
… | |
371 | XpmDepth | XpmSize | XpmReturnPixels); |
371 | XpmDepth | XpmSize | XpmReturnPixels); |
372 | |
372 | |
373 | /* search environment variables here too */ |
373 | /* search environment variables here too */ |
374 | f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]); |
374 | f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]); |
375 | if (f == NULL |
375 | if (f == NULL |
376 | || XpmReadFileToPixmap(Xdisplay, Xroot, f, |
376 | || XpmReadFileToPixmap(display->display, display->root, f, |
377 | &bgPixmap.pixmap, NULL, |
377 | &bgPixmap.pixmap, NULL, |
378 | &xpmAttr)) |
378 | &xpmAttr)) |
379 | { |
379 | { |
380 | char *p; |
380 | char *p; |
381 | |
381 | |