1 /*--------------------------------*-C-*---------------------------------*
3 *----------------------------------------------------------------------*
5 * All portions of code are copyright by their respective author/s.
6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *---------------------------------------------------------------------*/
25 #include "../config.h" /* NECESSARY */
26 #include "rxvt.h" /* NECESSARY */
27 #include "xpm.intpro" /* PROTOS for internal routines */
32 * These GEOM strings indicate absolute size/position:
35 * @ `WxH' -> Y = X = 50
37 * @ `W+X' -> H = W, Y = X
38 * @ `W' -> H = W, X = Y = 50
39 * @ `0xH' -> H *= H/100, X = Y = 50 (W unchanged)
40 * @ `Wx0' -> W *= W/100, X = Y = 50 (H unchanged)
41 * @ `=+X+Y' -> (H, W unchanged)
42 * @ `=+X' -> Y = X (H, W unchanged)
44 * These GEOM strings adjust position relative to current position:
48 * And this GEOM string is for querying current scale/position:
52 rxvt_term::scale_pixmap (const char *geom)
54 int flags, changed = 0;
56 unsigned int w = 0, h = 0;
59 bgPixmap_t *bgpixmap = & (bgPixmap);
61 #define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]")
65 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1);
66 if (!strcmp (geom, "?"))
68 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
69 min (bgpixmap->w, 9999), min (bgpixmap->h, 9999),
70 min (bgpixmap->x, 9999), min (bgpixmap->y, 9999));
71 process_xterm_seq (XTerm_title, str, CHAR_ST);
76 if ((p = strchr (geom, ';')) == NULL)
77 p = strchr (geom, '\0');
81 strncpy (str, geom, n);
84 flags = XParseGeometry (str, &x, &y, &w, &h);
89 } /* default is tile */
90 if (flags & WidthValue)
92 if (! (flags & XValue))
94 if (! (flags & HeightValue))
98 w = (bgpixmap->w * w) / 100;
104 h = (bgpixmap->h * h) / 100;
110 if (bgpixmap->w != (short)w)
112 bgpixmap->w = (short)w;
115 if (bgpixmap->h != (short)h)
117 bgpixmap->h = (short)h;
121 if (! (flags & YValue))
123 if (flags & XNegative)
128 if (! (flags & WidthValue) && geom[0] != '=')
135 if (flags & XNegative)
137 if (flags & YNegative)
144 if (bgpixmap->x != x)
149 if (bgpixmap->y != y)
160 rxvt_term::resize_pixmap ()
164 unsigned int width = TermWin_TotalWidth ();
165 unsigned int height = TermWin_TotalHeight ();
167 if (TermWin.pixmap != None)
168 XFreePixmap (display->display, TermWin.pixmap);
170 if (bgPixmap.pixmap == None)
171 { /* So be it: I'm not using pixmaps */
172 TermWin.pixmap = None;
174 if (!(options & Opt_transparent) || !am_transparent)
175 XSetWindowBackground (display->display, TermWin.vt,
176 pix_colors[Color_bg]);
181 gcvalue.foreground = pix_colors[Color_bg];
182 gc = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue);
184 if (bgPixmap.pixmap != None)
185 { /* we have a specified pixmap */
186 unsigned int w = bgPixmap.w, h = bgPixmap.h,
187 x = bgPixmap.x, y = bgPixmap.y;
188 unsigned int xpmh = xpmAttr.height,
189 xpmw = xpmAttr.width;
192 * don't zoom pixmap too much nor expand really small pixmaps
194 if (w > 1000 || h > 1000)
196 else if (width > (10 * xpmw)
197 || height > (10 * xpmh))
202 /* basic X tiling - let the X server do it */
203 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
205 (unsigned int)display->depth);
206 XCopyArea (display->display, bgPixmap.pixmap, TermWin.pixmap, gc,
207 0, 0, xpmw, xpmh, 0, 0);
214 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
216 (unsigned int)display->depth);
220 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
222 tmp = XCreatePixmap (display->display, TermWin.vt,
223 width, xpmh, (unsigned int)display->depth);
224 XFillRectangle (display->display, tmp, gc, 0, 0, width,
227 for ( /*nil */ ; x < w; x++, p += incr)
231 /* copy one column from the original pixmap to the tmp pixmap */
232 XCopyArea (display->display, bgPixmap.pixmap, tmp, gc,
233 (int)p, 0, 1, xpmh, (int)x, 0);
239 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
242 XFillRectangle (display->display, TermWin.pixmap, gc, 0, 0, width, y);
245 XFillRectangle (display->display, TermWin.pixmap, gc, 0, (int)h, width, height - h + 1);
247 for ( /*nil */ ; y < h; y++, p += incr)
252 /* copy one row from the tmp pixmap to the main pixmap */
253 XCopyArea (display->display, tmp, TermWin.pixmap, gc,
254 0, (int)p, width, 1, 0, (int)y);
257 XFreePixmap (display->display, tmp);
261 XSetWindowBackgroundPixmap (display->display, TermWin.vt, TermWin.pixmap);
262 XFreeGC (display->display, gc);
267 * Calculate tiling sizes and increments
268 * At start, p == 0, incr == xpmwidthheight
272 rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
274 unsigned int cwh, cxy;
278 cincr = (float)xpmwidthheight;
282 { /* display one image, no horizontal/vertical scaling */
283 cincr = (float)widthheight;
284 if (xpmwidthheight <= widthheight)
286 cwh = xpmwidthheight;
287 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
297 { /* fit WH images across/down screen */
304 cincr *= 100.0 / cwh;
309 cwh = (cwh * widthheight) / 100;
310 pos = (float)cxy / 100 * widthheight - (cwh / 2);
312 cxy = (widthheight - cwh);
325 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2);
326 cp = xpmwidthheight - cincr;
336 cincr /= widthheight;
344 rxvt_term::set_bgPixmap (const char *file)
348 assert (file != NULL);
350 if (bgPixmap.pixmap != None)
352 XFreePixmap (display->display, bgPixmap.pixmap);
353 bgPixmap.pixmap = None;
356 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]);
360 /* XWindowAttributes attr; */
363 * we already have the required attributes
365 /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */
367 xpmAttr.closeness = 30000;
368 xpmAttr.colormap = display->cmap;
369 xpmAttr.visual = display->visual;
370 xpmAttr.depth = display->depth;
371 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
372 XpmDepth | XpmSize | XpmReturnPixels);
374 /* search environment variables here too */
375 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
377 || XpmReadFileToPixmap (display->display, display->root, f,
378 &bgPixmap.pixmap, NULL,
383 /* semi-colon delimited */
384 if ((p = strchr (file, ';')) == NULL)
385 p = strchr (file, '\0');
387 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
394 return bgPixmap.pixmap;
397 #endif /* XPM_BACKGROUND */