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.10 by pcg, Wed Mar 17 03:47:14 2004 UTC vs.
Revision 1.21 by root, Fri Feb 4 11:41:23 2005 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: xpm.c 2 * File: xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: xpm.C,v 1.10 2004/03/17 03:47:14 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>
62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 61#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]")
63 62
64 if (geom == NULL) 63 if (geom == NULL)
65 return 0; 64 return 0;
66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 65 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1);
67 if (!STRCMP (geom, "?")) 66 if (!strcmp (geom, "?"))
68 { 67 {
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 xterm_seq (XTerm_title, str, CHAR_ST); 71 process_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)
78 p = STRCHR (geom, '\0'); 77 p = strchr (geom, '\0');
79 n = (p - geom); 78 n = (p - geom);
80 if (n <= MAXLEN_GEOM) 79 if (n <= MAXLEN_GEOM)
81 { 80 {
82 STRNCPY (str, geom, n); 81 strncpy (str, geom, n);
83 str[n] = '\0'; 82 str[n] = '\0';
84 83
85 flags = XParseGeometry (str, &x, &y, &w, &h); 84 flags = XParseGeometry (str, &x, &y, &w, &h);
86 if (!flags) 85 if (!flags)
87 { 86 {
162{ 161{
163 XGCValues gcvalue; 162 XGCValues gcvalue;
164 GC gc; 163 GC gc;
165 unsigned int width = TermWin_TotalWidth (); 164 unsigned int width = TermWin_TotalWidth ();
166 unsigned int height = TermWin_TotalHeight (); 165 unsigned int height = TermWin_TotalHeight ();
166 dDisp;
167 167
168 if (TermWin.pixmap != None) 168 if (TermWin.pixmap != None)
169 XFreePixmap (display->display, TermWin.pixmap); 169 XFreePixmap (disp, 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
174 if (! (Options & Opt_transparent) || am_transparent == 0) 175 if (!(options & Opt_transparent) || !am_transparent)
175 XSetWindowBackground (display->display, TermWin.vt, 176 XSetWindowBackground (disp, TermWin.vt,
176 PixColors[Color_bg]); 177 pix_colors[Color_bg]);
178
177 return; 179 return;
178 } 180 }
179 181
180 gcvalue.foreground = PixColors[Color_bg]; 182 gcvalue.foreground = pix_colors[Color_bg];
181 gc = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue); 183 gc = XCreateGC (disp, TermWin.vt, GCForeground, &gcvalue);
182 184
183 if (bgPixmap.pixmap != None) 185 if (bgPixmap.pixmap != None)
184 { /* we have a specified pixmap */ 186 { /* we have a specified pixmap */
185 unsigned int w = bgPixmap.w, h = bgPixmap.h, 187 unsigned int w = bgPixmap.w, h = bgPixmap.h,
186 x = bgPixmap.x, y = bgPixmap.y; 188 x = bgPixmap.x, y = bgPixmap.y;
187 unsigned int xpmh = xpmAttr.height, 189 unsigned int xpmh = xpmAttr.height,
188 xpmw = xpmAttr.width; 190 xpmw = xpmAttr.width;
189 191
190 /* 192 /*
191 * don't zoom pixmap too much nor expand really small pixmaps 193 * don't zoom pixmap too much nor expand really small pixmaps
192 */ 194 */
193 if (w > 1000 || h > 1000) 195 if (w > 1000 || h > 1000)
197 w = 0; /* tile */ 199 w = 0; /* tile */
198 200
199 if (w == 0) 201 if (w == 0)
200 { 202 {
201 /* basic X tiling - let the X server do it */ 203 /* basic X tiling - let the X server do it */
202 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 204 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
203 xpmw, xpmh, 205 xpmw, xpmh,
204 (unsigned int)XDEPTH); 206 (unsigned int)display->depth);
205 XCopyArea (display->display, bgPixmap.pixmap, TermWin.pixmap, gc, 207 XCopyArea (disp, bgPixmap.pixmap, TermWin.pixmap, gc,
206 0, 0, xpmw, xpmh, 0, 0); 208 0, 0, xpmw, xpmh, 0, 0);
207 } 209 }
208 else 210 else
209 { 211 {
210 float incr, p; 212 float incr, p;
211 Pixmap tmp; 213 Pixmap tmp;
212 214
213 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 215 TermWin.pixmap = XCreatePixmap (disp, TermWin.vt,
214 width, height, 216 width, height,
215 (unsigned int)XDEPTH); 217 (unsigned int)display->depth);
216 /* 218 /*
217 * horizontal scaling 219 * horizontal scaling
218 */ 220 */
219 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw); 221 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
220 222
221 tmp = XCreatePixmap (display->display, TermWin.vt, 223 tmp = XCreatePixmap (disp, TermWin.vt,
222 width, xpmh, (unsigned int)XDEPTH); 224 width, xpmh, (unsigned int)display->depth);
223 XFillRectangle (display->display, tmp, gc, 0, 0, width, 225 XFillRectangle (disp, tmp, gc, 0, 0, width,
224 xpmh); 226 xpmh);
225 227
226 for ( /*nil */ ; x < w; x++, p += incr) 228 for ( /*nil */ ; x < w; x++, p += incr)
227 { 229 {
228 if (p >= xpmw) 230 if (p >= xpmw)
229 p = 0; 231 p = 0;
230 /* copy one column from the original pixmap to the tmp pixmap */ 232 /* copy one column from the original pixmap to the tmp pixmap */
231 XCopyArea (display->display, bgPixmap.pixmap, tmp, gc, 233 XCopyArea (disp, bgPixmap.pixmap, tmp, gc,
232 (int)p, 0, 1, xpmh, (int)x, 0); 234 (int)p, 0, 1, xpmh, (int)x, 0);
233 } 235 }
234 236
235 /* 237 /*
236 * vertical scaling 238 * vertical scaling
237 */ 239 */
238 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh); 240 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
239 241
240 if (y > 0) 242 if (y > 0)
241 XFillRectangle (display->display, TermWin.pixmap, gc, 0, 0, width, 243 XFillRectangle (disp, TermWin.pixmap, gc, 0, 0, width, y);
242 y); 244
243 if (h < height) 245 if (h < height)
244 XFillRectangle (display->display, TermWin.pixmap, gc, 0, (int)h, 246 XFillRectangle (disp, TermWin.pixmap, gc, 0, (int)h, width, height - h + 1);
245 width, height - h + 1); 247
246 for ( /*nil */ ; y < h; y++, p += incr) 248 for ( /*nil */ ; y < h; y++, p += incr)
247 { 249 {
248 if (p >= xpmh) 250 if (p >= xpmh)
249 p = 0; 251 p = 0;
252
250 /* copy one row from the tmp pixmap to the main pixmap */ 253 /* copy one row from the tmp pixmap to the main pixmap */
251 XCopyArea (display->display, tmp, TermWin.pixmap, gc, 254 XCopyArea (disp, tmp, TermWin.pixmap, gc,
252 0, (int)p, width, 1, 0, (int)y); 255 0, (int)p, width, 1, 0, (int)y);
253 } 256 }
257
254 XFreePixmap (display->display, tmp); 258 XFreePixmap (disp, tmp);
255 } 259 }
256 } 260 }
261
257 XSetWindowBackgroundPixmap (display->display, TermWin.vt, TermWin.pixmap); 262 XSetWindowBackgroundPixmap (disp, TermWin.vt, TermWin.pixmap);
258 XFreeGC (display->display, gc); 263 XFreeGC (disp, gc);
259 am_transparent = 0; 264 am_transparent = 0;
260
261 XClearWindow (display->display, TermWin.vt);
262
263 XSync (display->display, False);
264} 265}
265 266
266/* 267/*
267 * Calculate tiling sizes and increments 268 * Calculate tiling sizes and increments
268 * At start, p == 0, incr == xpmwidthheight 269 * At start, p == 0, incr == xpmwidthheight
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 (display->display, bgPixmap.pixmap); 353 XFreePixmap (display->display, bgPixmap.pixmap);
353 bgPixmap.pixmap = None; 354 bgPixmap.pixmap = None;
354 } 355 }
356
355 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); 357 XSetWindowBackground (display->display, TermWin.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
362 * we already have the required attributes 364 * we already have the required attributes
363 */ 365 */
364 /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */ 366 /* XGetWindowAttributes (display->display, TermWin.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]);
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_warn ("couldn't load XPM file \"%.*s\", ignoring.", (p - file), file); 388 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
387 } 389 }
388 390
389 free (f); 391 free (f);
390 } 392 }
391 393

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines