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.12 by pcg, Thu Apr 8 20:31:45 2004 UTC vs.
Revision 1.27 by root, Wed Jan 4 04:42:45 2006 UTC

22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *---------------------------------------------------------------------*/ 23 *---------------------------------------------------------------------*/
24 24
25#include "../config.h" /* NECESSARY */ 25#include "../config.h" /* NECESSARY */
26#include "rxvt.h" /* NECESSARY */ 26#include "rxvt.h" /* NECESSARY */
27#include "xpm.intpro" /* PROTOS for internal routines */
28 27
29#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);
30 31
31/* 32/*
32 * These GEOM strings indicate absolute size/position: 33 * These GEOM strings indicate absolute size/position:
33 * @ `WxH+X+Y' 34 * @ `WxH+X+Y'
34 * @ `WxH+X' -> Y = X 35 * @ `WxH+X' -> Y = X
61#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") 62#define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]")
62 63
63 if (geom == NULL) 64 if (geom == NULL)
64 return 0; 65 return 0;
65 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1); 66 str = (char *)rxvt_malloc (MAXLEN_GEOM + 1);
66 if (!STRCMP (geom, "?")) 67 if (!strcmp (geom, "?"))
67 { 68 {
68 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ 69 sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */
69 min (bgpixmap->w, 9999), min (bgpixmap->h, 9999), 70 min (bgpixmap->w, 9999), min (bgpixmap->h, 9999),
70 min (bgpixmap->x, 9999), min (bgpixmap->y, 9999)); 71 min (bgpixmap->x, 9999), min (bgpixmap->y, 9999));
71 process_xterm_seq (XTerm_title, str, CHAR_ST); 72 process_xterm_seq (XTerm_title, str, CHAR_ST);
72 free (str); 73 free (str);
73 return 0; 74 return 0;
74 } 75 }
75 76
76 if ((p = STRCHR (geom, ';')) == NULL) 77 if ((p = strchr (geom, ';')) == NULL)
77 p = STRCHR (geom, '\0'); 78 p = strchr (geom, '\0');
78 n = (p - geom); 79 n = (p - geom);
79 if (n <= MAXLEN_GEOM) 80 if (n <= MAXLEN_GEOM)
80 { 81 {
81 STRNCPY (str, geom, n); 82 strncpy (str, geom, n);
82 str[n] = '\0'; 83 str[n] = '\0';
83 84
84 flags = XParseGeometry (str, &x, &y, &w, &h); 85 flags = XParseGeometry (str, &x, &y, &w, &h);
85 if (!flags) 86 if (!flags)
86 { 87 {
135 if (flags & XNegative) 136 if (flags & XNegative)
136 x += 100; 137 x += 100;
137 if (flags & YNegative) 138 if (flags & YNegative)
138 y += 100; 139 y += 100;
139 } 140 }
140 MIN_IT (x, 100); 141 min_it (x, 100);
141 MIN_IT (y, 100); 142 min_it (y, 100);
142 MAX_IT (x, 0); 143 max_it (x, 0);
143 MAX_IT (y, 0); 144 max_it (y, 0);
144 if (bgpixmap->x != x) 145 if (bgpixmap->x != x)
145 { 146 {
146 bgpixmap->x = x; 147 bgpixmap->x = x;
147 changed++; 148 changed++;
148 } 149 }
157} 158}
158 159
159void 160void
160rxvt_term::resize_pixmap () 161rxvt_term::resize_pixmap ()
161{ 162{
162 XGCValues gcvalue; 163 XGCValues gcvalue;
163 GC gc; 164 GC gc;
164 unsigned int width = TermWin_TotalWidth (); 165 dDisp;
165 unsigned int height = TermWin_TotalHeight ();
166 166
167 if (TermWin.pixmap != None) 167 if (pixmap != None)
168 XFreePixmap (display->display, TermWin.pixmap); 168 XFreePixmap (disp, pixmap);
169 169
170 if (bgPixmap.pixmap == None) 170 if (bgPixmap.pixmap == None)
171 { /* So be it: I'm not using pixmaps */ 171 { /* So be it: I'm not using pixmaps */
172 TermWin.pixmap = None; 172 pixmap = None;
173
173 if (! (Options & Opt_transparent) || am_transparent == 0) 174 if (!OPTION (Opt_transparent) || !am_transparent)
174 XSetWindowBackground (display->display, TermWin.vt, 175 XSetWindowBackground (disp, vt, pix_colors[Color_bg]);
175 PixColors[Color_bg]); 176
176 return; 177 return;
177 } 178 }
178 179
179 gcvalue.foreground = PixColors[Color_bg]; 180 gcvalue.foreground = pix_colors[Color_bg];
180 gc = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue); 181 gc = XCreateGC (disp, vt, GCForeground, &gcvalue);
181 182
182 if (bgPixmap.pixmap != None) 183 if (bgPixmap.pixmap != None)
183 { /* we have a specified pixmap */ 184 { /* we have a specified pixmap */
184 unsigned int w = bgPixmap.w, h = bgPixmap.h, 185 unsigned int w = bgPixmap.w, h = bgPixmap.h,
185 x = bgPixmap.x, y = bgPixmap.y; 186 x = bgPixmap.x, y = bgPixmap.y;
186 unsigned int xpmh = xpmAttr.height, 187 unsigned int xpmh = xpmAttr.height,
187 xpmw = xpmAttr.width; 188 xpmw = xpmAttr.width;
188 189
189 /* 190 /*
190 * don't zoom pixmap too much nor expand really small pixmaps 191 * don't zoom pixmap too much nor expand really small pixmaps
191 */ 192 */
192 if (w > 1000 || h > 1000) 193 if (w > 1000 || h > 1000)
196 w = 0; /* tile */ 197 w = 0; /* tile */
197 198
198 if (w == 0) 199 if (w == 0)
199 { 200 {
200 /* basic X tiling - let the X server do it */ 201 /* basic X tiling - let the X server do it */
201 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 202 pixmap = XCreatePixmap (disp, vt, xpmw, xpmh,
202 xpmw, xpmh,
203 (unsigned int)XDEPTH); 203 (unsigned int)display->depth);
204 XCopyArea (display->display, bgPixmap.pixmap, TermWin.pixmap, gc, 204 XCopyArea (disp, bgPixmap.pixmap, pixmap, gc,
205 0, 0, xpmw, xpmh, 0, 0); 205 0, 0, xpmw, xpmh, 0, 0);
206 } 206 }
207 else 207 else
208 { 208 {
209 float incr, p; 209 float incr, p;
210 Pixmap tmp; 210 Pixmap tmp;
211 211
212 TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, 212 pixmap = XCreatePixmap (disp, vt, width, height,
213 width, height,
214 (unsigned int)XDEPTH); 213 (unsigned int)display->depth);
215 /* 214 /*
216 * horizontal scaling 215 * horizontal scaling
217 */ 216 */
218 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw); 217 rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw);
219 218
220 tmp = XCreatePixmap (display->display, TermWin.vt, 219 tmp = XCreatePixmap (disp, vt, width, xpmh, (unsigned int)display->depth);
221 width, xpmh, (unsigned int)XDEPTH);
222 XFillRectangle (display->display, tmp, gc, 0, 0, width, 220 XFillRectangle (disp, tmp, gc, 0, 0, width, xpmh);
223 xpmh);
224 221
225 for ( /*nil */ ; x < w; x++, p += incr) 222 for ( /*nil */ ; x < w; x++, p += incr)
226 { 223 {
227 if (p >= xpmw) 224 if (p >= xpmw)
228 p = 0; 225 p = 0;
229 /* copy one column from the original pixmap to the tmp pixmap */ 226 /* copy one column from the original pixmap to the tmp pixmap */
230 XCopyArea (display->display, bgPixmap.pixmap, tmp, gc, 227 XCopyArea (disp, bgPixmap.pixmap, tmp, gc,
231 (int)p, 0, 1, xpmh, (int)x, 0); 228 (int)p, 0, 1, xpmh, (int)x, 0);
232 } 229 }
233 230
234 /* 231 /*
235 * vertical scaling 232 * vertical scaling
236 */ 233 */
237 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh); 234 rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh);
238 235
239 if (y > 0) 236 if (y > 0)
240 XFillRectangle (display->display, TermWin.pixmap, gc, 0, 0, width, 237 XFillRectangle (disp, pixmap, gc, 0, 0, width, y);
241 y); 238
242 if (h < height) 239 if (h < height)
243 XFillRectangle (display->display, TermWin.pixmap, gc, 0, (int)h, 240 XFillRectangle (disp, pixmap, gc, 0, (int)h, width, height - h + 1);
244 width, height - h + 1); 241
245 for ( /*nil */ ; y < h; y++, p += incr) 242 for ( /*nil */ ; y < h; y++, p += incr)
246 { 243 {
247 if (p >= xpmh) 244 if (p >= xpmh)
248 p = 0; 245 p = 0;
246
249 /* copy one row from the tmp pixmap to the main pixmap */ 247 /* copy one row from the tmp pixmap to the main pixmap */
250 XCopyArea (display->display, tmp, TermWin.pixmap, gc, 248 XCopyArea (disp, tmp, pixmap, gc,
251 0, (int)p, width, 1, 0, (int)y); 249 0, (int)p, width, 1, 0, (int)y);
252 } 250 }
251
253 XFreePixmap (display->display, tmp); 252 XFreePixmap (disp, tmp);
254 } 253 }
255 } 254 }
255
256 XSetWindowBackgroundPixmap (display->display, TermWin.vt, TermWin.pixmap); 256 XSetWindowBackgroundPixmap (disp, vt, pixmap);
257 XFreeGC (display->display, gc); 257 XFreeGC (disp, gc);
258 am_transparent = 0; 258 am_transparent = 0;
259
260 XClearWindow (display->display, TermWin.vt);
261
262 XSync (display->display, False);
263} 259}
264 260
265/* 261/*
266 * Calculate tiling sizes and increments 262 * Calculate tiling sizes and increments
267 * At start, p == 0, incr == xpmwidthheight 263 * At start, p == 0, incr == xpmwidthheight
268 */ 264 */
269/* INTPROTO */
270static void 265static void
271rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) 266rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight)
272{ 267{
273 unsigned int cwh, cxy; 268 unsigned int cwh, cxy;
274 float cincr, cp; 269 float cincr, cp;
340} 335}
341 336
342Pixmap 337Pixmap
343rxvt_term::set_bgPixmap (const char *file) 338rxvt_term::set_bgPixmap (const char *file)
344{ 339{
345 char *f; 340 char *f;
346 341
347 assert (file != NULL); 342 assert (file != NULL);
348 343
349 if (bgPixmap.pixmap != None) 344 if (bgPixmap.pixmap != None)
350 { 345 {
351 XFreePixmap (display->display, bgPixmap.pixmap); 346 XFreePixmap (display->display, bgPixmap.pixmap);
352 bgPixmap.pixmap = None; 347 bgPixmap.pixmap = None;
353 } 348 }
349
354 XSetWindowBackground (display->display, TermWin.vt, PixColors[Color_bg]); 350 XSetWindowBackground (display->display, vt, pix_colors[Color_bg]);
355 351
356 if (*file != '\0') 352 if (*file != '\0')
357 { 353 {
358 /* XWindowAttributes attr; */ 354 /* XWindowAttributes attr; */
359 355
360 /* 356 /*
361 * we already have the required attributes 357 * we already have the required attributes
362 */ 358 */
363 /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */ 359 /* XGetWindowAttributes (display->display, vt, &attr); */
364 360
365 xpmAttr.closeness = 30000; 361 xpmAttr.closeness = 30000;
366 xpmAttr.colormap = XCMAP; 362 xpmAttr.colormap = display->cmap;
367 xpmAttr.visual = XVISUAL; 363 xpmAttr.visual = display->visual;
368 xpmAttr.depth = XDEPTH; 364 xpmAttr.depth = display->depth;
369 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | 365 xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
370 XpmDepth | XpmSize | XpmReturnPixels); 366 XpmDepth | XpmSize | XpmReturnPixels);
371 367
372 /* search environment variables here too */ 368 /* search environment variables here too */
373 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); 369 f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]);
377 &xpmAttr)) 373 &xpmAttr))
378 { 374 {
379 char *p; 375 char *p;
380 376
381 /* semi-colon delimited */ 377 /* semi-colon delimited */
382 if ((p = STRCHR (file, ';')) == NULL) 378 if ((p = strchr (file, ';')) == NULL)
383 p = STRCHR (file, '\0'); 379 p = strchr (file, '\0');
384 380
385 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.", (p - file), file); 381 rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file);
386 } 382 }
387 383
388 free (f); 384 free (f);
389 } 385 }
390 386

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines