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.8 by pcg, Mon Feb 9 07:11:49 2004 UTC vs.
Revision 1.20 by root, Wed Jan 26 07:08:15 2005 UTC

1/*--------------------------------*-C-*---------------------------------* 1/*--------------------------------*-C-*---------------------------------*
2 * File: xpm.c 2 * File: xpm.C
3 *----------------------------------------------------------------------* 3 *----------------------------------------------------------------------*
4 * $Id: xpm.C,v 1.8 2004/02/09 07:11:49 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>
55 int flags, changed = 0; 54 int flags, changed = 0;
56 int x = 0, y = 0; 55 int x = 0, y = 0;
57 unsigned int w = 0, h = 0; 56 unsigned int w = 0, h = 0;
58 unsigned int n; 57 unsigned int n;
59 char *p, *str; 58 char *p, *str;
60 bgPixmap_t *bgpixmap = &(bgPixmap); 59 bgPixmap_t *bgpixmap = & (bgPixmap);
61 60
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 {
88 flags |= WidthValue; 87 flags |= WidthValue;
89 w = 0; 88 w = 0;
90 } /* default is tile */ 89 } /* default is tile */
91 if (flags & WidthValue) 90 if (flags & WidthValue)
92 { 91 {
93 if (!(flags & XValue)) 92 if (! (flags & XValue))
94 x = 50; 93 x = 50;
95 if (!(flags & HeightValue)) 94 if (! (flags & HeightValue))
96 h = w; 95 h = w;
97 if (w && !h) 96 if (w && !h)
98 { 97 {
99 w = (bgpixmap->w * w) / 100; 98 w = (bgpixmap->w * w) / 100;
100 h = bgpixmap->h; 99 h = bgpixmap->h;
117 { 116 {
118 bgpixmap->h = (short)h; 117 bgpixmap->h = (short)h;
119 changed++; 118 changed++;
120 } 119 }
121 } 120 }
122 if (!(flags & YValue)) 121 if (! (flags & YValue))
123 { 122 {
124 if (flags & XNegative) 123 if (flags & XNegative)
125 flags |= YNegative; 124 flags |= YNegative;
126 y = x; 125 y = x;
127 } 126 }
128 127
129 if (!(flags & WidthValue) && geom[0] != '=') 128 if (! (flags & WidthValue) && geom[0] != '=')
130 { 129 {
131 x += bgpixmap->x; 130 x += bgpixmap->x;
132 y += bgpixmap->y; 131 y += bgpixmap->y;
133 } 132 }
134 else 133 else
136 if (flags & XNegative) 135 if (flags & XNegative)
137 x += 100; 136 x += 100;
138 if (flags & YNegative) 137 if (flags & YNegative)
139 y += 100; 138 y += 100;
140 } 139 }
141 MIN_IT(x, 100); 140 MIN_IT (x, 100);
142 MIN_IT(y, 100); 141 MIN_IT (y, 100);
143 MAX_IT(x, 0); 142 MAX_IT (x, 0);
144 MAX_IT(y, 0); 143 MAX_IT (y, 0);
145 if (bgpixmap->x != x) 144 if (bgpixmap->x != x)
146 { 145 {
147 bgpixmap->x = x; 146 bgpixmap->x = x;
148 changed++; 147 changed++;
149 } 148 }
151 { 150 {
152 bgpixmap->y = y; 151 bgpixmap->y = y;
153 changed++; 152 changed++;
154 } 153 }
155 } 154 }
156 free(str); 155 free (str);
157 return changed; 156 return changed;
158} 157}
159 158
160void 159void
161rxvt_term::resize_pixmap () 160rxvt_term::resize_pixmap ()
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 ();
167 166
168 if (TermWin.pixmap != None) 167 if (TermWin.pixmap != None)
169 XFreePixmap(display->display, TermWin.pixmap); 168 XFreePixmap (display->display, TermWin.pixmap);
170 169
171 if (bgPixmap.pixmap == None) 170 if (bgPixmap.pixmap == None)
172 { /* So be it: I'm not using pixmaps */ 171 { /* So be it: I'm not using pixmaps */
173 TermWin.pixmap = None; 172 TermWin.pixmap = None;
173
174 if (!(Options & Opt_transparent) || am_transparent == 0) 174 if (!(options & Opt_transparent) || !am_transparent)
175 XSetWindowBackground(display->display, TermWin.vt, 175 XSetWindowBackground (display->display, TermWin.vt,
176 PixColors[Color_bg]); 176 pix_colors[Color_bg]);
177
177 return; 178 return;
178 } 179 }
179 180
180 gcvalue.foreground = PixColors[Color_bg]; 181 gcvalue.foreground = pix_colors[Color_bg];
181 gc = XCreateGC(display->display, TermWin.vt, GCForeground, &gcvalue); 182 gc = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue);
182 183
183 if (bgPixmap.pixmap != None) 184 if (bgPixmap.pixmap != None)
184 { /* we have a specified pixmap */ 185 { /* we have a specified pixmap */
185 unsigned int w = bgPixmap.w, h = bgPixmap.h, 186 unsigned int w = bgPixmap.w, h = bgPixmap.h,
186 x = bgPixmap.x, y = bgPixmap.y; 187 x = bgPixmap.x, y = bgPixmap.y;
187 unsigned int xpmh = xpmAttr.height, 188 unsigned int xpmh = xpmAttr.height,
188 xpmw = xpmAttr.width; 189 xpmw = xpmAttr.width;
189 190
190 /* 191 /*
191 * don't zoom pixmap too much nor expand really small pixmaps 192 * don't zoom pixmap too much nor expand really small pixmaps
192 */ 193 */
193 if (w > 1000 || h > 1000) 194 if (w > 1000 || h > 1000)
197 w = 0; /* tile */ 198 w = 0; /* tile */
198 199
199 if (w == 0) 200 if (w == 0)
200 { 201 {
201 /* basic X tiling - let the X server do it */ 202 /* basic X tiling - let the X server do it */
202 TermWin.pixmap = XCreatePixmap(display->display, TermWin.vt, 203 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
203 xpmw, xpmh, 204 xpmw, xpmh,
204 (unsigned int)XDEPTH); 205 (unsigned int)display->depth);
205 XCopyArea(display->display, bgPixmap.pixmap, TermWin.pixmap, gc, 206 XCopyArea (display->display, bgPixmap.pixmap, TermWin.pixmap, gc,
206 0, 0, xpmw, xpmh, 0, 0); 207 0, 0, xpmw, xpmh, 0, 0);
207 } 208 }
208 else 209 else
209 { 210 {
210 float incr, p; 211 float incr, p;
211 Pixmap tmp; 212 Pixmap tmp;
212 213
213 TermWin.pixmap = XCreatePixmap(display->display, TermWin.vt, 214 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt,
214 width, height, 215 width, height,
215 (unsigned int)XDEPTH); 216 (unsigned int)display->depth);
216 /* 217 /*
217 * horizontal scaling 218 * horizontal scaling
218 */ 219 */
219 rxvt_pixmap_incr(&w, &x, &incr, &p, width, xpmw); 220 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
220 221
221 tmp = XCreatePixmap(display->display, TermWin.vt, 222 tmp = XCreatePixmap (display->display, TermWin.vt,
222 width, xpmh, (unsigned int)XDEPTH); 223 width, xpmh, (unsigned int)display->depth);
223 XFillRectangle(display->display, tmp, gc, 0, 0, width, 224 XFillRectangle (display->display, tmp, gc, 0, 0, width,
224 xpmh); 225 xpmh);
225 226
226 for ( /*nil */ ; x < w; x++, p += incr) 227 for ( /*nil */ ; x < w; x++, p += incr)
227 { 228 {
228 if (p >= xpmw) 229 if (p >= xpmw)
229 p = 0; 230 p = 0;
230 /* copy one column from the original pixmap to the tmp pixmap */ 231 /* copy one column from the original pixmap to the tmp pixmap */
231 XCopyArea(display->display, bgPixmap.pixmap, tmp, gc, 232 XCopyArea (display->display, bgPixmap.pixmap, tmp, gc,
232 (int)p, 0, 1, xpmh, (int)x, 0); 233 (int)p, 0, 1, xpmh, (int)x, 0);
233 } 234 }
234 235
235 /* 236 /*
236 * vertical scaling 237 * vertical scaling
237 */ 238 */
238 rxvt_pixmap_incr(&h, &y, &incr, &p, height, xpmh); 239 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
239 240
240 if (y > 0) 241 if (y > 0)
241 XFillRectangle(display->display, TermWin.pixmap, gc, 0, 0, width, 242 XFillRectangle (display->display, TermWin.pixmap, gc, 0, 0, width, y);
242 y); 243
243 if (h < height) 244 if (h < height)
244 XFillRectangle(display->display, TermWin.pixmap, gc, 0, (int)h, 245 XFillRectangle (display->display, TermWin.pixmap, gc, 0, (int)h, width, height - h + 1);
245 width, height - h + 1); 246
246 for ( /*nil */ ; y < h; y++, p += incr) 247 for ( /*nil */ ; y < h; y++, p += incr)
247 { 248 {
248 if (p >= xpmh) 249 if (p >= xpmh)
249 p = 0; 250 p = 0;
251
250 /* copy one row from the tmp pixmap to the main pixmap */ 252 /* copy one row from the tmp pixmap to the main pixmap */
251 XCopyArea(display->display, tmp, TermWin.pixmap, gc, 253 XCopyArea (display->display, tmp, TermWin.pixmap, gc,
252 0, (int)p, width, 1, 0, (int)y); 254 0, (int)p, width, 1, 0, (int)y);
253 } 255 }
256
254 XFreePixmap(display->display, tmp); 257 XFreePixmap (display->display, tmp);
255 } 258 }
256 } 259 }
260
257 XSetWindowBackgroundPixmap(display->display, TermWin.vt, TermWin.pixmap); 261 XSetWindowBackgroundPixmap (display->display, TermWin.vt, TermWin.pixmap);
258 XFreeGC(display->display, gc); 262 XFreeGC (display->display, gc);
259 am_transparent = 0; 263 am_transparent = 0;
260
261 XClearWindow(display->display, TermWin.vt);
262
263 XSync(display->display, False);
264} 264}
265 265
266/* 266/*
267 * Calculate tiling sizes and increments 267 * Calculate tiling sizes and increments
268 * At start, p == 0, incr == xpmwidthheight 268 * At start, p == 0, incr == xpmwidthheight
269 */ 269 */
270/* INTPROTO */ 270/* INTPROTO */
271static void 271static void
272rxvt_pixmap_incr(unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) 272rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
273{ 273{
274 unsigned int cwh, cxy; 274 unsigned int cwh, cxy;
275 float cincr, cp; 275 float cincr, cp;
276 276
277 cp = 0; 277 cp = 0;
343Pixmap 343Pixmap
344rxvt_term::set_bgPixmap (const char *file) 344rxvt_term::set_bgPixmap (const char *file)
345{ 345{
346 char *f; 346 char *f;
347 347
348 assert(file != NULL); 348 assert (file != NULL);
349 349
350 if (bgPixmap.pixmap != None) 350 if (bgPixmap.pixmap != None)
351 { 351 {
352 XFreePixmap(display->display, bgPixmap.pixmap); 352 XFreePixmap (display->display, bgPixmap.pixmap);
353 bgPixmap.pixmap = None; 353 bgPixmap.pixmap = None;
354 } 354 }
355
355 XSetWindowBackground(display->display, TermWin.vt, PixColors[Color_bg]); 356 XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]);
356 357
357 if (*file != '\0') 358 if (*file != '\0')
358 { 359 {
359 /* XWindowAttributes attr; */ 360 /* XWindowAttributes attr; */
360 361
361 /* 362 /*
362 * we already have the required attributes 363 * we already have the required attributes
363 */ 364 */
364 /* XGetWindowAttributes(display->display, TermWin.vt, &attr); */ 365 /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */
365 366
366 xpmAttr.closeness = 30000; 367 xpmAttr.closeness = 30000;
367 xpmAttr.colormap = XCMAP; 368 xpmAttr.colormap = display->cmap;
368 xpmAttr.visual = XVISUAL; 369 xpmAttr.visual = display->visual;
369 xpmAttr.depth = XDEPTH; 370 xpmAttr.depth = display->depth;
370 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | 371 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
371 XpmDepth | XpmSize | XpmReturnPixels); 372 XpmDepth | XpmSize | XpmReturnPixels);
372 373
373 /* search environment variables here too */ 374 /* search environment variables here too */
374 f = (char *)rxvt_File_find(file, ".xpm", rs[Rs_path]); 375 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
375 if (f == NULL 376 if (f == NULL
376 || XpmReadFileToPixmap(display->display, display->root, f, 377 || XpmReadFileToPixmap (display->display, display->root, f,
377 &bgPixmap.pixmap, NULL, 378 &bgPixmap.pixmap, NULL,
378 &xpmAttr)) 379 &xpmAttr))
379 { 380 {
380 char *p; 381 char *p;
381 382
382 /* semi-colon delimited */ 383 /* semi-colon delimited */
383 if ((p = STRCHR(file, ';')) == NULL) 384 if ((p = strchr (file, ';')) == NULL)
384 p = STRCHR(file, '\0'); 385 p = strchr (file, '\0');
385 386
386 rxvt_print_error("couldn't load XPM file \"%.*s\"", (p - file), 387 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
387 file);
388 } 388 }
389
389 free(f); 390 free (f);
390 } 391 }
392
391 resize_pixmap (); 393 resize_pixmap ();
392 return bgPixmap.pixmap; 394 return bgPixmap.pixmap;
393} 395}
394 396
395#endif /* XPM_BACKGROUND */ 397#endif /* XPM_BACKGROUND */

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines