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 ();
168 if (TermWin.pixmap != None)
169 XFreePixmap (disp, TermWin.pixmap);
171 if (bgPixmap.pixmap == None)
172 { /* So be it: I'm not using pixmaps */
173 TermWin.pixmap = None;
175 if (!(options & Opt_transparent) || !am_transparent)
176 XSetWindowBackground (disp, TermWin.vt,
177 pix_colors[Color_bg]);
182 gcvalue.foreground = pix_colors[Color_bg];
183 gc = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue);
185 if (bgPixmap.pixmap != None)
186 { /* we have a specified pixmap */
187 unsigned int w = bgPixmap.w, h = bgPixmap.h,
188 x = bgPixmap.x, y = bgPixmap.y;
189 unsigned int xpmh = xpmAttr.height,
190 xpmw = xpmAttr.width;
193 * don't zoom pixmap too much nor expand really small pixmaps
195 if (w > 1000 || h > 1000)
197 else if (width > (10 * xpmw)
198 || height > (10 * xpmh))
203 /* basic X tiling - let the X server do it */
204 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
206 (unsigned int)display->depth);
207 XCopyArea (disp, bgPixmap.pixmap, TermWin.pixmap, gc,
208 0, 0, xpmw, xpmh, 0, 0);
215 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
217 (unsigned int)display->depth);
221 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
223 tmp = XCreatePixmap (disp, TermWin.vt,
224 width, xpmh, (unsigned int)display->depth);
225 XFillRectangle (disp, tmp, gc, 0, 0, width,
228 for ( /*nil */ ; x < w; x++, p += incr)
232 /* copy one column from the original pixmap to the tmp pixmap */
233 XCopyArea (disp, bgPixmap.pixmap, tmp, gc,
234 (int)p, 0, 1, xpmh, (int)x, 0);
240 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
243 XFillRectangle (disp, TermWin.pixmap, gc, 0, 0, width, y);
246 XFillRectangle (disp, TermWin.pixmap, gc, 0, (int)h, width, height - h + 1);
248 for ( /*nil */ ; y < h; y++, p += incr)
253 /* copy one row from the tmp pixmap to the main pixmap */
254 XCopyArea (disp, tmp, TermWin.pixmap, gc,
255 0, (int)p, width, 1, 0, (int)y);
258 XFreePixmap (disp, tmp);
262 XSetWindowBackgroundPixmap (disp, TermWin.vt, TermWin.pixmap);
268 * Calculate tiling sizes and increments
269 * At start, p == 0, incr == xpmwidthheight
273 rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
275 unsigned int cwh, cxy;
279 cincr = (float)xpmwidthheight;
283 { /* display one image, no horizontal/vertical scaling */
284 cincr = (float)widthheight;
285 if (xpmwidthheight <= widthheight)
287 cwh = xpmwidthheight;
288 cxy = (cxy * (widthheight - cwh)) / 100; /* beware! order */
298 { /* fit WH images across/down screen */
305 cincr *= 100.0 / cwh;
310 cwh = (cwh * widthheight) / 100;
311 pos = (float)cxy / 100 * widthheight - (cwh / 2);
313 cxy = (widthheight - cwh);
326 pos = (float)cxy / 100 * xpmwidthheight - (cincr / 2);
327 cp = xpmwidthheight - cincr;
337 cincr /= widthheight;
345 rxvt_term::set_bgPixmap (const char *file)
349 assert (file != NULL);
351 if (bgPixmap.pixmap != None)
353 XFreePixmap (display->display, bgPixmap.pixmap);
354 bgPixmap.pixmap = None;
357 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]);
361 /* XWindowAttributes attr; */
364 * we already have the required attributes
366 /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */
368 xpmAttr.closeness = 30000;
369 xpmAttr.colormap = display->cmap;
370 xpmAttr.visual = display->visual;
371 xpmAttr.depth = display->depth;
372 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
373 XpmDepth | XpmSize | XpmReturnPixels);
375 /* search environment variables here too */
376 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
378 || XpmReadFileToPixmap (display->display, display->root, f,
379 &bgPixmap.pixmap, NULL,
384 /* semi-colon delimited */
385 if ((p = strchr (file, ';')) == NULL)
386 p = strchr (file, '\0');
388 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
395 return bgPixmap.pixmap;
398 #endif /* XPM_BACKGROUND */