ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/xpm.C
(Generate patch)

Comparing rxvt-unicode/src/xpm.C (file contents):
Revision 1.7 by pcg, Sun Feb 1 01:34:41 2004 UTC vs.
Revision 1.24 by root, Sun Dec 18 00:59:42 2005 UTC

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 $
5 * 4 *
6 * All portions of code are copyright by their respective author/s. 5 * All portions of code are copyright by their respective author/s.
7 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au> 6 * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au>
8 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> 7 * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de>
9 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> 8 * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com>
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
25 24
26#include "../config.h" /* NECESSARY */ 25#include "../config.h" /* NECESSARY */
27#include "rxvt.h" /* NECESSARY */ 26#include "rxvt.h" /* NECESSARY */
28#include "xpm.intpro" /* PROTOS for internal routines */
29 27
30#ifdef XPM_BACKGROUND 28#ifdef XPM_BACKGROUND
29
30static void rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight);
31 31
32/* 32/*
33 * These GEOM strings indicate absolute size/position: 33 * These GEOM strings indicate absolute size/position:
34 * @ `WxH+X+Y' 34 * @ `WxH+X+Y'
35 * @ `WxH+X' -> Y = X 35 * @ `WxH+X' -> Y = X
55 int flags, changed = 0; 55 int flags, changed = 0;
56 int x = 0, y = 0; 56 int x = 0, y = 0;
57 unsigned int w = 0, h = 0; 57 unsigned int w = 0, h = 0;
58 unsigned int n; 58 unsigned int n;
59 char *p, *str; 59 char *p, *str;
60 bgPixmap_t *bgpixmap = &(bgPixmap); 60 bgPixmap_t *bgpixmap = & (bgPixmap);
61 61
62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]")
63 63
64 if (geom == NULL) 64 if (geom == NULL)
65 return 0; 65 return 0;
66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1);
67 if (!STRCMP(geom, "?")) 67 if (!strcmp (geom, "?"))
68 { 68 {
69 sprintf(str, "[%dx%d+%d+%d]", /* can't presume snprintf() ! */ 69 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
70 min(bgpixmap->w, 9999), min(bgpixmap->h, 9999), 70 min (bgpixmap->w, 9999), min (bgpixmap->h, 9999),
71 min(bgpixmap->x, 9999), min(bgpixmap->y, 9999)); 71 min (bgpixmap->x, 9999), min (bgpixmap->y, 9999));
72 xterm_seq (XTerm_title, str, CHAR_ST); 72 process_xterm_seq (XTerm_title, str, CHAR_ST);
73 free(str); 73 free (str);
74 return 0; 74 return 0;
75 } 75 }
76 76
77 if ((p = STRCHR(geom, ';')) == NULL) 77 if ((p = strchr (geom, ';')) == NULL)
78 p = STRCHR(geom, '\0'); 78 p = strchr (geom, '\0');
79 n = (p - geom); 79 n = (p - geom);
80 if (n <= MAXLEN_GEOM) 80 if (n <= MAXLEN_GEOM)
81 { 81 {
82 STRNCPY(str, geom, n); 82 strncpy (str, geom, n);
83 str[n] = '\0'; 83 str[n] = '\0';
84 84
85 flags = XParseGeometry(str, &x, &y, &w, &h); 85 flags = XParseGeometry (str, &x, &y, &w, &h);
86 if (!flags) 86 if (!flags)
87 { 87 {
88 flags |= WidthValue; 88 flags |= WidthValue;
89 w = 0; 89 w = 0;
90 } /* default is tile */ 90 } /* default is tile */
91 if (flags & WidthValue) 91 if (flags & WidthValue)
92 { 92 {
93 if (!(flags & XValue)) 93 if (! (flags & XValue))
94 x = 50; 94 x = 50;
95 if (!(flags & HeightValue)) 95 if (! (flags & HeightValue))
96 h = w; 96 h = w;
97 if (w && !h) 97 if (w && !h)
98 { 98 {
99 w = (bgpixmap->w * w) / 100; 99 w = (bgpixmap->w * w) / 100;
100 h = bgpixmap->h; 100 h = bgpixmap->h;
117 { 117 {
118 bgpixmap->h = (short)h; 118 bgpixmap->h = (short)h;
119 changed++; 119 changed++;
120 } 120 }
121 } 121 }
122 if (!(flags & YValue)) 122 if (! (flags & YValue))
123 { 123 {
124 if (flags & XNegative) 124 if (flags & XNegative)
125 flags |= YNegative; 125 flags |= YNegative;
126 y = x; 126 y = x;
127 } 127 }
128 128
129 if (!(flags & WidthValue) && geom[0] != '=') 129 if (! (flags & WidthValue) && geom[0] != '=')
130 { 130 {
131 x += bgpixmap->x; 131 x += bgpixmap->x;
132 y += bgpixmap->y; 132 y += bgpixmap->y;
133 } 133 }
134 else 134 else
136 if (flags & XNegative) 136 if (flags & XNegative)
137 x += 100; 137 x += 100;
138 if (flags & YNegative) 138 if (flags & YNegative)
139 y += 100; 139 y += 100;
140 } 140 }
141 MIN_IT(x, 100); 141 MIN_IT (x, 100);
142 MIN_IT(y, 100); 142 MIN_IT (y, 100);
143 MAX_IT(x, 0); 143 MAX_IT (x, 0);
144 MAX_IT(y, 0); 144 MAX_IT (y, 0);
145 if (bgpixmap->x != x) 145 if (bgpixmap->x != x)
146 { 146 {
147 bgpixmap->x = x; 147 bgpixmap->x = x;
148 changed++; 148 changed++;
149 } 149 }
151 { 151 {
152 bgpixmap->y = y; 152 bgpixmap->y = y;
153 changed++; 153 changed++;
154 } 154 }
155 } 155 }
156 free(str); 156 free (str);
157 return changed; 157 return changed;
158} 158}
159 159
160void 160void
161rxvt_term::resize_pixmap () 161rxvt_term::resize_pixmap ()
162{ 162{
163 XGCValues gcvalue; 163 XGCValues gcvalue;
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 dDisp;
167 168
168 if (TermWin.pixmap != None) 169 if (pixmap != None)
169 XFreePixmap(Xdisplay, TermWin.pixmap); 170 XFreePixmap (disp, pixmap);
170 171
171 if (bgPixmap.pixmap == None) 172 if (bgPixmap.pixmap == None)
172 { /* So be it: I'm not using pixmaps */ 173 { /* So be it: I'm not using pixmaps */
173 TermWin.pixmap = None; 174 pixmap = None;
175
174 if (!(Options & Opt_transparent) || am_transparent == 0) 176 if (!(options & Opt_transparent) || !am_transparent)
175 XSetWindowBackground(Xdisplay, TermWin.vt, 177 XSetWindowBackground (disp, vt,
176 PixColors[Color_bg]); 178 pix_colors[Color_bg]);
179
177 return; 180 return;
178 } 181 }
179 182
180 gcvalue.foreground = PixColors[Color_bg]; 183 gcvalue.foreground = pix_colors[Color_bg];
181 gc = XCreateGC(Xdisplay, TermWin.vt, GCForeground, &gcvalue); 184 gc = XCreateGC (disp, vt, GCForeground, &gcvalue);
182 185
183 if (bgPixmap.pixmap != None) 186 if (bgPixmap.pixmap != None)
184 { /* we have a specified pixmap */ 187 { /* we have a specified pixmap */
185 unsigned int w = bgPixmap.w, h = bgPixmap.h, 188 unsigned int w = bgPixmap.w, h = bgPixmap.h,
186 x = bgPixmap.x, y = bgPixmap.y; 189 x = bgPixmap.x, y = bgPixmap.y;
187 unsigned int xpmh = xpmAttr.height, 190 unsigned int xpmh = xpmAttr.height,
188 xpmw = xpmAttr.width; 191 xpmw = xpmAttr.width;
189 192
190 /* 193 /*
191 * don't zoom pixmap too much nor expand really small pixmaps 194 * don't zoom pixmap too much nor expand really small pixmaps
192 */ 195 */
193 if (w > 1000 || h > 1000) 196 if (w > 1000 || h > 1000)
197 w = 0; /* tile */ 200 w = 0; /* tile */
198 201
199 if (w == 0) 202 if (w == 0)
200 { 203 {
201 /* basic X tiling - let the X server do it */ 204 /* basic X tiling - let the X server do it */
202 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, 205 pixmap = XCreatePixmap (disp, vt,
203 xpmw, xpmh, 206 xpmw, xpmh,
204 (unsigned int)XDEPTH); 207 (unsigned int)display->depth);
205 XCopyArea(Xdisplay, bgPixmap.pixmap, TermWin.pixmap, gc, 208 XCopyArea (disp, bgPixmap.pixmap, pixmap, gc,
206 0, 0, xpmw, xpmh, 0, 0); 209 0, 0, xpmw, xpmh, 0, 0);
207 } 210 }
208 else 211 else
209 { 212 {
210 float incr, p; 213 float incr, p;
211 Pixmap tmp; 214 Pixmap tmp;
212 215
213 TermWin.pixmap = XCreatePixmap(Xdisplay, TermWin.vt, 216 pixmap = XCreatePixmap (disp, vt,
214 width, height, 217 width, height,
215 (unsigned int)XDEPTH); 218 (unsigned int)display->depth);
216 /* 219 /*
217 * horizontal scaling 220 * horizontal scaling
218 */ 221 */
219 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); 222 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
220 223
221 tmp = XCreatePixmap(Xdisplay, TermWin.vt, 224 tmp = XCreatePixmap (disp, vt,
222 width, xpmh, (unsigned int)XDEPTH); 225 width, xpmh, (unsigned int)display->depth);
223 XFillRectangle(Xdisplay, tmp, gc, 0, 0, width, 226 XFillRectangle (disp, tmp, gc, 0, 0, width,
224 xpmh); 227 xpmh);
225 228
226 for ( /*nil */ ; x < w; x++, p += incr) 229 for ( /*nil */ ; x < w; x++, p += incr)
227 { 230 {
228 if (p >= xpmw) 231 if (p >= xpmw)
229 p = 0; 232 p = 0;
230 /* copy one column from the original pixmap to the tmp pixmap */ 233 /* copy one column from the original pixmap to the tmp pixmap */
231 XCopyArea(Xdisplay, bgPixmap.pixmap, tmp, gc, 234 XCopyArea (disp, bgPixmap.pixmap, tmp, gc,
232 (int)p, 0, 1, xpmh, (int)x, 0); 235 (int)p, 0, 1, xpmh, (int)x, 0);
233 } 236 }
234 237
235 /* 238 /*
236 * vertical scaling 239 * vertical scaling
237 */ 240 */
238 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); 241 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
239 242
240 if (y > 0) 243 if (y > 0)
241 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, 0, width, 244 XFillRectangle (disp, pixmap, gc, 0, 0, width, y);
242 y); 245
243 if (h < height) 246 if (h < height)
244 XFillRectangle(Xdisplay, TermWin.pixmap, gc, 0, (int)h, 247 XFillRectangle (disp, pixmap, gc, 0, (int)h, width, height - h + 1);
245 width, height - h + 1); 248
246 for ( /*nil */ ; y < h; y++, p += incr) 249 for ( /*nil */ ; y < h; y++, p += incr)
247 { 250 {
248 if (p >= xpmh) 251 if (p >= xpmh)
249 p = 0; 252 p = 0;
253
250 /* copy one row from the tmp pixmap to the main pixmap */ 254 /* copy one row from the tmp pixmap to the main pixmap */
251 XCopyArea(Xdisplay, tmp, TermWin.pixmap, gc, 255 XCopyArea (disp, tmp, pixmap, gc,
252 0, (int)p, width, 1, 0, (int)y); 256 0, (int)p, width, 1, 0, (int)y);
253 } 257 }
258
254 XFreePixmap(Xdisplay, tmp); 259 XFreePixmap (disp, tmp);
255 } 260 }
256 } 261 }
262
257 XSetWindowBackgroundPixmap(Xdisplay, TermWin.vt, TermWin.pixmap); 263 XSetWindowBackgroundPixmap (disp, vt, pixmap);
258 XFreeGC(Xdisplay, gc); 264 XFreeGC (disp, gc);
259 am_transparent = 0; 265 am_transparent = 0;
260
261 XClearWindow(Xdisplay, TermWin.vt);
262
263 XSync(Xdisplay, False);
264} 266}
265 267
266/* 268/*
267 * Calculate tiling sizes and increments 269 * Calculate tiling sizes and increments
268 * At start, p == 0, incr == xpmwidthheight 270 * At start, p == 0, incr == xpmwidthheight
269 */ 271 */
270/* INTPROTO */
271static void 272static void
272rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) 273rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
273{ 274{
274 unsigned int cwh, cxy; 275 unsigned int cwh, cxy;
275 float cincr, cp; 276 float cincr, cp;
276 277
277 cp = 0; 278 cp = 0;
341} 342}
342 343
343Pixmap 344Pixmap
344rxvt_term::set_bgPixmap (const char *file) 345rxvt_term::set_bgPixmap (const char *file)
345{ 346{
346 char *f; 347 char *f;
347 348
348 assert(file != NULL); 349 assert (file != NULL);
349 350
350 if (bgPixmap.pixmap != None) 351 if (bgPixmap.pixmap != None)
351 { 352 {
352 XFreePixmap(Xdisplay, bgPixmap.pixmap); 353 XFreePixmap (display->display, bgPixmap.pixmap);
353 bgPixmap.pixmap = None; 354 bgPixmap.pixmap = None;
354 } 355 }
356
355 XSetWindowBackground(Xdisplay, TermWin.vt, PixColors[Color_bg]); 357 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]);
356 358
357 if (*file != '\0') 359 if (*file != '\0')
358 { 360 {
359 /* XWindowAttributes attr; */ 361 /* XWindowAttributes attr; */
360 362
361 /* 363 /*
362 * we already have the required attributes 364 * we already have the required attributes
363 */ 365 */
364 /* XGetWindowAttributes(Xdisplay, TermWin.vt, &attr); */ 366 /* XGetWindowAttributes (display->display, vt, &attr); */
365 367
366 xpmAttr.closeness = 30000; 368 xpmAttr.closeness = 30000;
367 xpmAttr.colormap = XCMAP; 369 xpmAttr.colormap = display->cmap;
368 xpmAttr.visual = XVISUAL; 370 xpmAttr.visual = display->visual;
369 xpmAttr.depth = XDEPTH; 371 xpmAttr.depth = display->depth;
370 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | 372 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
371 XpmDepth | XpmSize | XpmReturnPixels); 373 XpmDepth | XpmSize | XpmReturnPixels);
372 374
373 /* search environment variables here too */ 375 /* search environment variables here too */
374 f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]); 376 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
375 if (f == NULL 377 if (f == NULL
376 || XpmReadFileToPixmap(Xdisplay, Xroot, f, 378 || XpmReadFileToPixmap (display->display, display->root, f,
377 &bgPixmap.pixmap, NULL, 379 &bgPixmap.pixmap, NULL,
378 &xpmAttr)) 380 &xpmAttr))
379 { 381 {
380 char *p; 382 char *p;
381 383
382 /* semi-colon delimited */ 384 /* semi-colon delimited */
383 if ((p = STRCHR(file, ';')) == NULL) 385 if ((p = strchr (file, ';')) == NULL)
384 p = STRCHR(file, '\0'); 386 p = strchr (file, '\0');
385 387
386 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), 388 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
387 file);
388 } 389 }
390
389 free(f); 391 free (f);
390 } 392 }
393
391 resize_pixmap (); 394 resize_pixmap ();
392 return bgPixmap.pixmap; 395 return bgPixmap.pixmap;
393} 396}
394 397
395#endif /* XPM_BACKGROUND */ 398#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines