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.6 2004/01/31 02:15:02 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 */ |
|
|
53 | int |
52 | int |
54 | rxvt_scale_pixmap(pR_ const char *geom) |
53 | rxvt_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->h->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 = 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 */ |
|
|
147 | void |
145 | void |
148 | rxvt_resize_pixmap(pR) |
146 | rxvt_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->h->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->h->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->h->bgPixmap.pixmap != None) { /* we have a specified pixmap */ |
167 | if (bgPixmap.pixmap != None) { /* we have a specified pixmap */ |
170 | unsigned int w = R->h->bgPixmap.w, h = R->h->bgPixmap.h, |
168 | unsigned int w = bgPixmap.w, h = bgPixmap.h, |
171 | x = R->h->bgPixmap.x, y = R->h->bgPixmap.y; |
169 | x = bgPixmap.x, y = bgPixmap.y; |
172 | unsigned int xpmh = R->h->xpmAttr.height, |
170 | unsigned int xpmh = xpmAttr.height, |
173 | xpmw = R->h->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->h->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->h->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->h->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 */ |
248 | /* INTPROTO */ |
251 | void |
249 | static void |
252 | rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) |
250 | rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) |
253 | { |
251 | { |
254 | unsigned int cwh, cxy; |
252 | unsigned int cwh, cxy; |
255 | float cincr, cp; |
253 | float cincr, cp; |
256 | |
254 | |
… | |
… | |
282 | |
280 | |
283 | cxy = (widthheight - cwh); |
281 | cxy = (widthheight - cwh); |
284 | if (pos <= 0) |
282 | if (pos <= 0) |
285 | cxy = 0; |
283 | cxy = 0; |
286 | else if (pos < cxy) |
284 | else if (pos < cxy) |
287 | cxy = pos; |
285 | cxy = (int) pos; |
288 | cwh += cxy; |
286 | cwh += cxy; |
289 | } else { /* expand */ |
287 | } else { /* expand */ |
290 | if (cxy > 0) { /* position */ |
288 | if (cxy > 0) { /* position */ |
291 | float pos; |
289 | float pos; |
292 | |
290 | |
… | |
… | |
306 | *xy = cxy; |
304 | *xy = cxy; |
307 | *incr = cincr; |
305 | *incr = cincr; |
308 | *p = cp; |
306 | *p = cp; |
309 | } |
307 | } |
310 | |
308 | |
311 | /* EXTPROTO */ |
|
|
312 | Pixmap |
309 | Pixmap |
313 | rxvt_set_bgPixmap(pR_ const char *file) |
310 | rxvt_term::set_bgPixmap (const char *file) |
314 | { |
311 | { |
315 | char *f; |
312 | char *f; |
316 | |
313 | |
317 | assert(file != NULL); |
314 | assert(file != NULL); |
318 | |
315 | |
319 | if (R->h->bgPixmap.pixmap != None) { |
316 | if (bgPixmap.pixmap != None) { |
320 | XFreePixmap(R->Xdisplay, R->h->bgPixmap.pixmap); |
317 | XFreePixmap(Xdisplay, bgPixmap.pixmap); |
321 | R->h->bgPixmap.pixmap = None; |
318 | bgPixmap.pixmap = None; |
322 | } |
319 | } |
323 | XSetWindowBackground(R->Xdisplay, R->TermWin.vt, R->PixColors[Color_bg]); |
320 | XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]); |
324 | |
321 | |
325 | if (*file != '\0') { |
322 | if (*file != '\0') { |
326 | /* XWindowAttributes attr; */ |
323 | /* XWindowAttributes attr; */ |
327 | |
324 | |
328 | /* |
325 | /* |
329 | * we already have the required attributes |
326 | * we already have the required attributes |
330 | */ |
327 | */ |
331 | /* XGetWindowAttributes(R->Xdisplay, R->TermWin.vt, &attr); */ |
328 | /* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */ |
332 | |
329 | |
333 | R->h->xpmAttr.closeness = 30000; |
330 | xpmAttr.closeness = 30000; |
334 | R->h->xpmAttr.colormap = XCMAP; |
331 | xpmAttr.colormap = XCMAP; |
335 | R->h->xpmAttr.visual = XVISUAL; |
332 | xpmAttr.visual = XVISUAL; |
336 | R->h->xpmAttr.depth = XDEPTH; |
333 | xpmAttr.depth = XDEPTH; |
337 | R->h->xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | |
334 | xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | |
338 | XpmDepth | XpmSize | XpmReturnPixels); |
335 | XpmDepth | XpmSize | XpmReturnPixels); |
339 | |
336 | |
340 | /* search environment variables here too */ |
337 | /* search environment variables here too */ |
341 | f = (char *)rxvt_File_find(file, ".xpm", R->h->rs[Rs_path]); |
338 | f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]); |
342 | if (f == NULL |
339 | if (f == NULL |
343 | || XpmReadFileToPixmap(R->Xdisplay, Xroot, f, |
340 | || XpmReadFileToPixmap(Xdisplay, Xroot, f, |
344 | &R->h->bgPixmap.pixmap, NULL, |
341 | &bgPixmap.pixmap, NULL, |
345 | &R->h->xpmAttr)) { |
342 | &xpmAttr)) { |
346 | char *p; |
343 | char *p; |
347 | |
344 | |
348 | /* semi-colon delimited */ |
345 | /* semi-colon delimited */ |
349 | if ((p = STRCHR(file, ';')) == NULL) |
346 | if ((p = STRCHR(file, ';')) == NULL) |
350 | p = STRCHR(file, '\0'); |
347 | p = STRCHR(file, '\0'); |
… | |
… | |
352 | rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), |
349 | rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), |
353 | file); |
350 | file); |
354 | } |
351 | } |
355 | free(f); |
352 | free(f); |
356 | } |
353 | } |
357 | rxvt_resize_pixmap(aR); |
354 | resize_pixmap (); |
358 | return R->h->bgPixmap.pixmap; |
355 | return bgPixmap.pixmap; |
359 | } |
356 | } |
360 | |
357 | |
361 | #endif /* XPM_BACKGROUND */ |
358 | #endif /* XPM_BACKGROUND */ |