… | |
… | |
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 | |
|
|
30 | static 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 |
… | |
… | |
49 | * @ `?' |
50 | * @ `?' |
50 | */ |
51 | */ |
51 | int |
52 | int |
52 | rxvt_term::scale_pixmap (const char *geom) |
53 | rxvt_term::scale_pixmap (const char *geom) |
53 | { |
54 | { |
54 | int flags, changed = 0; |
55 | int flags, changed = 0; |
55 | int x = 0, y = 0; |
56 | int x = 0, y = 0; |
56 | unsigned int w = 0, h = 0; |
57 | unsigned int w = 0, h = 0; |
57 | unsigned int n; |
58 | unsigned int n; |
58 | char *p, *str; |
59 | char *p; |
59 | bgPixmap_t *bgpixmap = & (bgPixmap); |
60 | bgPixmap_t *bgpixmap = & (bgPixmap); |
60 | |
61 | |
61 | #define MAXLEN_GEOM sizeof("[1000x1000+1000+1000]") |
62 | #define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]") |
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 | |
|
|
67 | char str[MAXLEN_GEOM]; |
|
|
68 | |
66 | if (!strcmp (geom, "?")) |
69 | if (!strcmp (geom, "?")) |
67 | { |
70 | { |
68 | sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ |
71 | sprintf (str, "[%dx%d+%d+%d]", /* can't presume snprintf () ! */ |
69 | min (bgpixmap->w, 9999), min (bgpixmap->h, 9999), |
72 | min (bgpixmap->w, 32767), min (bgpixmap->h, 32767), |
70 | min (bgpixmap->x, 9999), min (bgpixmap->y, 9999)); |
73 | min (bgpixmap->x, 32767), min (bgpixmap->y, 32767)); |
71 | process_xterm_seq (XTerm_title, str, CHAR_ST); |
74 | process_xterm_seq (XTerm_title, str, CHAR_ST); |
72 | free (str); |
|
|
73 | return 0; |
75 | return 0; |
74 | } |
76 | } |
75 | |
77 | |
76 | if ((p = strchr (geom, ';')) == NULL) |
78 | if ((p = strchr (geom, ';')) == NULL) |
77 | p = strchr (geom, '\0'); |
79 | p = strchr (geom, '\0'); |
|
|
80 | |
78 | n = (p - geom); |
81 | n = (p - geom); |
79 | if (n <= MAXLEN_GEOM) |
82 | if (n <= MAXLEN_GEOM) |
80 | { |
83 | { |
81 | strncpy (str, geom, n); |
84 | strncpy (str, geom, n); |
82 | str[n] = '\0'; |
85 | str[n] = '\0'; |
83 | |
86 | |
84 | flags = XParseGeometry (str, &x, &y, &w, &h); |
87 | flags = XParseGeometry (str, &x, &y, &w, &h); |
|
|
88 | |
85 | if (!flags) |
89 | if (!flags) |
86 | { |
90 | { |
87 | flags |= WidthValue; |
91 | flags |= WidthValue; |
88 | w = 0; |
92 | w = 0; |
89 | } /* default is tile */ |
93 | } /* default is tile */ |
|
|
94 | |
90 | if (flags & WidthValue) |
95 | if (flags & WidthValue) |
91 | { |
96 | { |
92 | if (! (flags & XValue)) |
97 | if (!(flags & XValue)) |
93 | x = 50; |
98 | x = 50; |
|
|
99 | |
94 | if (! (flags & HeightValue)) |
100 | if (!(flags & HeightValue)) |
95 | h = w; |
101 | h = w; |
|
|
102 | |
96 | if (w && !h) |
103 | if (w && !h) |
97 | { |
104 | { |
98 | w = (bgpixmap->w * w) / 100; |
105 | w = (bgpixmap->w * w) / 100; |
99 | h = bgpixmap->h; |
106 | h = bgpixmap->h; |
100 | } |
107 | } |
101 | else if (h && !w) |
108 | else if (h && !w) |
102 | { |
109 | { |
103 | w = bgpixmap->w; |
110 | w = bgpixmap->w; |
104 | h = (bgpixmap->h * h) / 100; |
111 | h = (bgpixmap->h * h) / 100; |
105 | } |
112 | } |
106 | if (w > 1000) |
113 | |
107 | w = 1000; |
114 | min_it (w, 32767); |
108 | if (h > 1000) |
115 | min_it (h, 32767); |
109 | h = 1000; |
116 | |
110 | if (bgpixmap->w != (short)w) |
117 | if (bgpixmap->w != (short)w) |
111 | { |
118 | { |
112 | bgpixmap->w = (short)w; |
119 | bgpixmap->w = (short)w; |
113 | changed++; |
120 | changed++; |
114 | } |
121 | } |
|
|
122 | |
115 | if (bgpixmap->h != (short)h) |
123 | if (bgpixmap->h != (short)h) |
116 | { |
124 | { |
117 | bgpixmap->h = (short)h; |
125 | bgpixmap->h = (short)h; |
118 | changed++; |
126 | changed++; |
119 | } |
127 | } |
120 | } |
128 | } |
|
|
129 | |
121 | if (! (flags & YValue)) |
130 | if (!(flags & YValue)) |
122 | { |
131 | { |
123 | if (flags & XNegative) |
132 | if (flags & XNegative) |
124 | flags |= YNegative; |
133 | flags |= YNegative; |
|
|
134 | |
125 | y = x; |
135 | y = x; |
126 | } |
136 | } |
127 | |
137 | |
128 | if (! (flags & WidthValue) && geom[0] != '=') |
138 | if (!(flags & WidthValue) && geom[0] != '=') |
129 | { |
139 | { |
130 | x += bgpixmap->x; |
140 | x += bgpixmap->x; |
131 | y += bgpixmap->y; |
141 | y += bgpixmap->y; |
132 | } |
142 | } |
133 | else |
143 | |
134 | { |
144 | if (xpmAttr.width && xpmAttr.height) |
135 | if (flags & XNegative) |
|
|
136 | x += 100; |
|
|
137 | if (flags & YNegative) |
|
|
138 | y += 100; |
|
|
139 | } |
145 | { |
140 | MIN_IT (x, 100); |
146 | x = MOD(x, xpmAttr.width); |
141 | MIN_IT (y, 100); |
147 | y = MOD(y, xpmAttr.height); |
142 | MAX_IT (x, 0); |
148 | } |
143 | MAX_IT (y, 0); |
149 | |
144 | if (bgpixmap->x != x) |
150 | if (bgpixmap->x != x) |
145 | { |
151 | { |
146 | bgpixmap->x = x; |
152 | bgpixmap->x = x; |
147 | changed++; |
153 | changed++; |
148 | } |
154 | } |
|
|
155 | |
149 | if (bgpixmap->y != y) |
156 | if (bgpixmap->y != y) |
150 | { |
157 | { |
151 | bgpixmap->y = y; |
158 | bgpixmap->y = y; |
152 | changed++; |
159 | changed++; |
153 | } |
160 | } |
154 | } |
161 | } |
155 | free (str); |
162 | |
156 | return changed; |
163 | return changed; |
157 | } |
164 | } |
158 | |
165 | |
159 | void |
166 | void |
160 | rxvt_term::resize_pixmap () |
167 | rxvt_term::resize_pixmap () |
161 | { |
168 | { |
162 | XGCValues gcvalue; |
169 | XGCValues gcvalue; |
163 | GC gc; |
170 | GC gc; |
164 | unsigned int width = TermWin_TotalWidth (); |
|
|
165 | unsigned int height = TermWin_TotalHeight (); |
|
|
166 | |
171 | |
167 | if (TermWin.pixmap != None) |
172 | if (pixmap != None) |
168 | XFreePixmap (display->display, TermWin.pixmap); |
173 | XFreePixmap (xdisp, pixmap); |
169 | |
174 | |
170 | if (bgPixmap.pixmap == None) |
175 | if (bgPixmap.pixmap == None) |
171 | { /* So be it: I'm not using pixmaps */ |
176 | { /* So be it: I'm not using pixmaps */ |
172 | TermWin.pixmap = None; |
177 | pixmap = None; |
|
|
178 | |
173 | if (! (options & Opt_transparent) || am_transparent == 0) |
179 | if (!OPTION (Opt_transparent) || !am_transparent) |
174 | XSetWindowBackground (display->display, TermWin.vt, |
180 | XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]); |
175 | pix_colors[Color_bg]); |
181 | |
176 | return; |
182 | return; |
177 | } |
183 | } |
178 | |
184 | |
179 | gcvalue.foreground = pix_colors[Color_bg]; |
185 | gcvalue.foreground = pix_colors[Color_bg]; |
180 | gc = XCreateGC (display->display, TermWin.vt, GCForeground, &gcvalue); |
186 | gc = XCreateGC (xdisp, vt, GCForeground, &gcvalue); |
181 | |
187 | |
182 | if (bgPixmap.pixmap != None) |
188 | if (bgPixmap.pixmap != None) |
183 | { /* we have a specified pixmap */ |
189 | { /* we have a specified pixmap */ |
184 | unsigned int w = bgPixmap.w, h = bgPixmap.h, |
190 | unsigned int w = bgPixmap.w, h = bgPixmap.h, |
185 | x = bgPixmap.x, y = bgPixmap.y; |
191 | x = bgPixmap.x, y = bgPixmap.y; |
186 | unsigned int xpmh = xpmAttr.height, |
192 | unsigned int xpmh = xpmAttr.height, |
187 | xpmw = xpmAttr.width; |
193 | xpmw = xpmAttr.width; |
188 | |
194 | |
189 | /* |
195 | /* |
190 | * don't zoom pixmap too much nor expand really small pixmaps |
196 | * don't zoom pixmap too much nor expand really small pixmaps |
191 | */ |
197 | */ |
192 | if (w > 1000 || h > 1000) |
198 | if (w > 32767 || h > 32767) |
193 | w = 1; |
199 | w = 1; |
194 | else if (width > (10 * xpmw) |
200 | else if (width > (10 * xpmw) |
195 | || height > (10 * xpmh)) |
201 | || height > (10 * xpmh)) |
196 | w = 0; /* tile */ |
202 | w = 0; /* tile */ |
197 | |
203 | |
198 | if (w == 0) |
204 | if (!w) |
199 | { |
205 | { |
200 | /* basic X tiling - let the X server do it */ |
206 | /* basic X tiling - let the X server do it */ |
201 | TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, |
207 | pixmap = XCreatePixmap (xdisp, vt, xpmw, xpmh, depth); |
202 | xpmw, xpmh, |
208 | |
203 | (unsigned int)display->depth); |
209 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, y, xpmw - x, xpmh - y, 0, 0); |
204 | XCopyArea (display->display, bgPixmap.pixmap, TermWin.pixmap, gc, |
210 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, x, 0, xpmw - x, y, 0, xpmh - y); |
205 | 0, 0, xpmw, xpmh, 0, 0); |
211 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, y, x, xpmh - y, xpmw - x, 0); |
|
|
212 | XCopyArea (xdisp, bgPixmap.pixmap, pixmap, gc, 0, 0, x, y, xpmw - x, xpmh - y); |
206 | } |
213 | } |
207 | else |
214 | else |
208 | { |
215 | { |
209 | float incr, p; |
216 | float incr, p; |
210 | Pixmap tmp; |
217 | Pixmap tmp; |
211 | |
218 | |
212 | TermWin.pixmap = XCreatePixmap (display->display, TermWin.vt, |
219 | pixmap = XCreatePixmap (xdisp, vt, width, height, depth); |
213 | width, height, |
|
|
214 | (unsigned int)display->depth); |
|
|
215 | /* |
220 | /* |
216 | * horizontal scaling |
221 | * horizontal scaling |
217 | */ |
222 | */ |
218 | rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw); |
223 | rxvt_pixmap_incr (&w, &x, &incr, &p, width, xpmw); |
219 | |
224 | |
220 | tmp = XCreatePixmap (display->display, TermWin.vt, |
225 | tmp = XCreatePixmap (xdisp, vt, width, xpmh, depth); |
221 | width, xpmh, (unsigned int)display->depth); |
|
|
222 | XFillRectangle (display->display, tmp, gc, 0, 0, width, |
226 | XFillRectangle (xdisp, tmp, gc, 0, 0, width, xpmh); |
223 | xpmh); |
|
|
224 | |
227 | |
225 | for ( /*nil */ ; x < w; x++, p += incr) |
228 | for ( /*nil */ ; x < w; x++, p += incr) |
226 | { |
229 | { |
227 | if (p >= xpmw) |
230 | if (p >= xpmw) |
228 | p = 0; |
231 | p = 0; |
|
|
232 | |
229 | /* copy one column from the original pixmap to the tmp pixmap */ |
233 | /* copy one column from the original pixmap to the tmp pixmap */ |
230 | XCopyArea (display->display, bgPixmap.pixmap, tmp, gc, |
234 | XCopyArea (xdisp, bgPixmap.pixmap, tmp, gc, (int)p, 0, 1, xpmh, (int)x, 0); |
231 | (int)p, 0, 1, xpmh, (int)x, 0); |
|
|
232 | } |
235 | } |
233 | |
236 | |
234 | /* |
237 | /* |
235 | * vertical scaling |
238 | * vertical scaling |
236 | */ |
239 | */ |
237 | rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh); |
240 | rxvt_pixmap_incr (&h, &y, &incr, &p, height, xpmh); |
238 | |
241 | |
239 | if (y > 0) |
242 | if (y > 0) |
240 | XFillRectangle (display->display, TermWin.pixmap, gc, 0, 0, width, |
243 | XFillRectangle (xdisp, pixmap, gc, 0, 0, width, y); |
241 | y); |
244 | |
242 | if (h < height) |
245 | if (h < height) |
243 | XFillRectangle (display->display, TermWin.pixmap, gc, 0, (int)h, |
246 | XFillRectangle (xdisp, pixmap, gc, 0, (int)h, width, height - h + 1); |
244 | width, height - h + 1); |
247 | |
245 | for ( /*nil */ ; y < h; y++, p += incr) |
248 | for ( /*nil */ ; y < h; y++, p += incr) |
246 | { |
249 | { |
247 | if (p >= xpmh) |
250 | if (p >= xpmh) |
248 | p = 0; |
251 | p = 0; |
|
|
252 | |
249 | /* copy one row from the tmp pixmap to the main pixmap */ |
253 | /* copy one row from the tmp pixmap to the main pixmap */ |
250 | XCopyArea (display->display, tmp, TermWin.pixmap, gc, |
254 | XCopyArea (xdisp, tmp, pixmap, gc, 0, (int)p, width, 1, 0, (int)y); |
251 | 0, (int)p, width, 1, 0, (int)y); |
|
|
252 | } |
255 | } |
|
|
256 | |
253 | XFreePixmap (display->display, tmp); |
257 | XFreePixmap (xdisp, tmp); |
254 | } |
258 | } |
|
|
259 | } |
|
|
260 | |
|
|
261 | XSetWindowBackgroundPixmap (xdisp, vt, pixmap); |
|
|
262 | |
|
|
263 | if (pixmap != None) |
255 | } |
264 | { |
|
|
265 | XFreePixmap (xdisp, pixmap); |
|
|
266 | pixmap = None; |
|
|
267 | } |
256 | |
268 | |
257 | XSetWindowBackgroundPixmap (display->display, TermWin.vt, TermWin.pixmap); |
|
|
258 | XFreeGC (display->display, gc); |
269 | XFreeGC (xdisp, gc); |
259 | am_transparent = 0; |
270 | am_transparent = 0; |
260 | |
|
|
261 | XClearWindow (display->display, TermWin.vt); |
|
|
262 | |
|
|
263 | XSync (display->display, False); |
|
|
264 | } |
271 | } |
265 | |
272 | |
266 | /* |
273 | /* |
267 | * Calculate tiling sizes and increments |
274 | * Calculate tiling sizes and increments |
268 | * At start, p == 0, incr == xpmwidthheight |
275 | * At start, p == 0, incr == xpmwidthheight |
269 | */ |
276 | */ |
270 | /* INTPROTO */ |
|
|
271 | static void |
277 | static void |
272 | rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) |
278 | rxvt_pixmap_incr (unsigned int *wh, unsigned int *xy, float *incr, float *p, unsigned int widthheight, unsigned int xpmwidthheight) |
273 | { |
279 | { |
274 | unsigned int cwh, cxy; |
280 | unsigned int cwh, cxy; |
275 | float cincr, cp; |
281 | float cincr, cp; |
… | |
… | |
341 | } |
347 | } |
342 | |
348 | |
343 | Pixmap |
349 | Pixmap |
344 | rxvt_term::set_bgPixmap (const char *file) |
350 | rxvt_term::set_bgPixmap (const char *file) |
345 | { |
351 | { |
346 | char *f; |
352 | char *f; |
347 | |
353 | |
348 | assert (file != NULL); |
354 | assert (file != NULL); |
349 | |
355 | |
350 | if (bgPixmap.pixmap != None) |
356 | if (bgPixmap.pixmap != None) |
351 | { |
357 | { |
352 | XFreePixmap (display->display, bgPixmap.pixmap); |
358 | XFreePixmap (xdisp, bgPixmap.pixmap); |
353 | bgPixmap.pixmap = None; |
359 | bgPixmap.pixmap = None; |
354 | } |
360 | } |
|
|
361 | |
355 | XSetWindowBackground (display->display, TermWin.vt, pix_colors[Color_bg]); |
362 | XSetWindowBackground (xdisp, vt, pix_colors[Color_bg]); |
356 | |
363 | |
357 | if (*file != '\0') |
364 | if (*file != '\0') |
358 | { |
365 | { |
359 | /* XWindowAttributes attr; */ |
366 | /* XWindowAttributes attr; */ |
360 | |
367 | |
361 | /* |
368 | /* |
362 | * we already have the required attributes |
369 | * we already have the required attributes |
363 | */ |
370 | */ |
364 | /* XGetWindowAttributes (display->display, TermWin.vt, &attr); */ |
371 | /* XGetWindowAttributes (xdisp, vt, &attr); */ |
365 | |
372 | |
366 | xpmAttr.closeness = 30000; |
373 | xpmAttr.closeness = 30000; |
367 | xpmAttr.colormap = display->cmap; |
374 | xpmAttr.colormap = cmap; |
368 | xpmAttr.visual = display->visual; |
375 | xpmAttr.visual = visual; |
369 | xpmAttr.depth = display->depth; |
376 | xpmAttr.depth = depth; |
370 | xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual | |
377 | xpmAttr.valuemask = (XpmCloseness | XpmColormap | XpmVisual |
371 | XpmDepth | XpmSize | XpmReturnPixels); |
378 | | XpmDepth | XpmSize | XpmReturnPixels); |
372 | |
379 | |
373 | /* search environment variables here too */ |
380 | /* search environment variables here too */ |
374 | f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); |
381 | f = (char *)rxvt_File_find (file, ".xpm", rs[Rs_path]); |
375 | if (f == NULL |
382 | if (f == NULL |
376 | || XpmReadFileToPixmap (display->display, display->root, f, |
383 | || XpmReadFileToPixmap (xdisp, display->root, f, |
377 | &bgPixmap.pixmap, NULL, |
384 | &bgPixmap.pixmap, NULL, |
378 | &xpmAttr)) |
385 | &xpmAttr)) |
379 | { |
386 | { |
380 | char *p; |
387 | char *p; |
381 | |
388 | |
382 | /* semi-colon delimited */ |
389 | /* semi-colon delimited */ |
383 | if ((p = strchr (file, ';')) == NULL) |
390 | if ((p = strchr (file, ';')) == NULL) |
384 | p = strchr (file, '\0'); |
391 | p = strchr (file, '\0'); |
385 | |
392 | |
386 | rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.", (p - file), file); |
393 | rxvt_warn ("couldn't load XPM file \"%.*s\", ignoring.\n", (p - file), file); |
387 | } |
394 | } |
388 | |
395 | |
389 | free (f); |
396 | free (f); |
390 | } |
397 | } |
391 | |
398 | |