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.57 by ayin, Fri Aug 3 23:32:14 2007 UTC vs.
Revision 1.58 by sasha, Sat Aug 4 07:05:31 2007 UTC

47 * Adjusting position only : 47 * Adjusting position only :
48 * =+X+Y Set position to X% by Y% (absolute). 48 * =+X+Y Set position to X% by Y% (absolute).
49 * =+X Set position to X% by X%. 49 * =+X Set position to X% by X%.
50 * +X+Y Adjust position horizontally X% and vertically Y% 50 * +X+Y Adjust position horizontally X% and vertically Y%
51 * from current position (relative). 51 * from current position (relative).
52 * +X+X Adjust position horizontally X% and vertically X% 52 * +X Adjust position horizontally X% and vertically X%
53 * from current position. 53 * from current position.
54 * 54 *
55 * Adjusting scale only : 55 * Adjusting scale only :
56 * Wx0 Multiply horizontal scaling factor by W% 56 * Wx0 Multiply horizontal scaling factor by W%
57 * 0xH Multiply vertical scaling factor by H% 57 * 0xH Multiply vertical scaling factor by H%
72 72
73#ifdef HAVE_BG_PIXMAP 73#ifdef HAVE_BG_PIXMAP
74bool 74bool
75bgPixmap_t::window_size_sensitive () 75bgPixmap_t::window_size_sensitive ()
76{ 76{
77 return (flags&(bgPmap_Scale|bgPmap_Transparent)); 77#ifdef XPM_BACKGROUND
78#ifdef HAVE_AFTERIMAGE
79 if (original_asim != NULL)
80#endif
81 {
82 if (h_scale != 0 || v_scale != 0)
83 return true;
84 }
85#endif
86#ifdef ENABLE_TRANSPARENCY
87 if (flags & bgPmap_Transparent)
88 return true;
89#endif
90 return false;
78} 91}
79 92
80#ifdef XPM_BACKGROUND 93#ifdef XPM_BACKGROUND
94static inline bool
95check_set_scale_value (int geom_flags, int flag, unsigned int &scale, unsigned int new_value)
96{
97 if (geom_flags & flag)
98 {
99 if (new_value > 1000)
100 new_value = 1000;
101 if (new_value != scale)
102 {
103 scale = new_value;
104 return true;
105 }
106 }
107 return false;
108}
109
110static inline bool
111check_set_align_value (int geom_flags, int flag, int &align, int new_value)
112{
113 if (geom_flags & flag)
114 {
115 if (new_value < -100)
116 new_value = -100;
117 else if (new_value > 200)
118 new_value = 200;
119 if (new_value != align)
120 {
121 align = new_value;
122 return true;
123 }
124 }
125 return false;
126}
127
81bool 128bool
82bgPixmap_t::handle_geometry (const char *geom) 129bgPixmap_t::handle_geometry (const char *geom)
83{ 130{
84 int geom_flags, changed = 0; 131 int geom_flags = 0, changed = 0;
85 int x = 0, y = 0; 132 int x = 0, y = 0;
86 unsigned int w = 0, h = 0; 133 unsigned int w = 0, h = 0;
87 unsigned int n; 134 unsigned int n;
88 unsigned long new_flags = (flags&(~bgPmap_geometryFlags)) ; 135 unsigned long new_flags = (flags&(~bgPmap_geometryFlags));
89 char *p; 136 char *p;
90#define MAXLEN_GEOM sizeof("[10000x10000+10000+10000]") 137#define MAXLEN_GEOM 256 /* could be longer then regular geometry string */
91 138
92 if (geom == NULL) 139 if (geom == NULL)
93 return false; 140 return false;
94 141
95 char str[MAXLEN_GEOM]; 142 char str[MAXLEN_GEOM];
102 min (h_align, 32767), min (v_align, 32767)); 149 min (h_align, 32767), min (v_align, 32767));
103 process_xterm_seq (XTerm_title, str, CHAR_ST); 150 process_xterm_seq (XTerm_title, str, CHAR_ST);
104#endif 151#endif
105 return false; 152 return false;
106 } 153 }
107 154 while (isspace(*geom)) ++geom;
108 if ((p = strchr (geom, ';')) == NULL) 155 if ((p = strchr (geom, ';')) == NULL)
109 p = strchr (geom, '\0'); 156 p = strchr (geom, '\0');
110 157
111 n = (p - geom); 158 n = (p - geom);
112 if (n < MAXLEN_GEOM) 159 if (n < MAXLEN_GEOM)
113 { 160 {
161 char *ops;
114 new_flags |= bgPmap_geometrySet; 162 new_flags |= bgPmap_geometrySet;
115 163
116 strncpy (str, geom, n); 164 strncpy (str, geom, n);
117 str[n] = '\0'; 165 str[n] = '\0';
118 166 if (str[0] == ':')
119 if (strcmp(str, "auto") == 0) 167 ops = &str[0];
120 { 168 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
121 w = h = 100; 169 ops = &str[0];
122 geom_flags = WidthValue|HeightValue ;
123 }
124 else 170 else
125 { 171 {
172 char *tmp;
173 ops = strchr (str, ':');
174 if (ops != NULL)
175 {
176 for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp);
177 *(++tmp) = '\0';
178 if (ops == tmp) ++ops;
179 }
180 }
181
182 if (ops > str || ops == NULL)
183 {
184 /* we have geometry string - let's handle it prior to applying ops */
126 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 185 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
127 }
128/* code below is garbage and needs to be rewritten */
129 if (!geom_flags)
130 {
131 geom_flags |= WidthValue;
132 w = 0;
133 } /* default is tile */
134 186
135 if (geom_flags & WidthValue) 187 if ((geom_flags & XValue) && !(geom_flags & YValue))
136 {
137 if (!(geom_flags & XValue))
138 x = 50;
139
140 if (!(geom_flags & HeightValue))
141 h = w;
142
143 if (w && !h)
144 { 188 {
145 w = (h_scale * w) / 100;
146 h = v_scale; 189 y = x;
190 geom_flags |= YValue;
147 } 191 }
148 else if (h && !w) 192
193 if (flags & bgPmap_geometrySet)
194 {/* new geometry is an adjustment to the old one ! */
195 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
196 {
197 if (w == 0 && h != 0)
198 {
199 w = h_scale;
200 h = (v_scale * h) / 100;
201 }
202 else if (h == 0 && w != 0)
203 {
204 w = (h_scale * w) / 100;
205 h = v_scale;
206 }
207 }
208 if (geom_flags & XValue)
209 {
210 if (str[0] != '=')
211 {
212 y += v_align;
213 x += h_align;
214 }
215 }
216 }
217 else /* setting up geometry from scratch */
149 { 218 {
219 if (!(geom_flags & XValue))
220 {/* use default geometry - centered */
221 x = y = bgPmap_defaultAlign;
222 }
223 else if (!(geom_flags & YValue))
224 y = x;
225
226 if ((geom_flags & (WidthValue|HeightValue)) == 0)
227 {/* use default geometry - scaled */
228 w = h = bgPmap_defaultScale;
229 }
230 else if (geom_flags & WidthValue)
231 {
232 if (!(geom_flags & HeightValue))
233 h = w;
234 }
235 else
150 w = h_scale; 236 w = h;
151 h = (v_scale * h) / 100;
152 } 237 }
238 } /* done parsing geometry string */
239 else if (!(flags & bgPmap_geometrySet))
240 { /* default geometry - scaled and centered */
241 x = y = bgPmap_defaultAlign;
242 w = h = bgPmap_defaultScale;
243 }
244
245 if (!(flags & bgPmap_geometrySet))
246 geom_flags |= WidthValue|HeightValue|XValue|YValue;
153 247
154 min_it (w, 32767); 248 if (ops)
155 min_it (h, 32767); 249 {
156 250 while (*ops)
157 if (h_scale != w)
158 { 251 {
159 h_scale = w; 252 while (*ops == ':' || isspace(*ops)) ++ops;
160 changed++; 253#define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0)
161 } 254 if (CHECK_GEOM_OPS("tile"))
162
163 if (v_scale != h)
164 { 255 {
165 v_scale = h; 256 w = h = 0;
166 changed++; 257 geom_flags |= WidthValue|HeightValue;
167 } 258 }
168 } 259 else if (CHECK_GEOM_OPS("propscale"))
169 if (!(geom_flags & YValue)) 260 {
261 if (w == 0 && h == 0)
262 {
263 w = 100;
264 geom_flags |= WidthValue;
265 }
266 new_flags |= bgPmap_propScale;
267 }
268 else if (CHECK_GEOM_OPS("hscale"))
269 {
270 if (w == 0)
271 w = 100;
272 h = 0;
273 geom_flags |= WidthValue|HeightValue;
274 }
275 else if (CHECK_GEOM_OPS("vscale"))
276 {
277 if (h == 0)
278 h = 100;
279 w = 0;
280 geom_flags |= WidthValue|HeightValue;
281 }
282 else if (CHECK_GEOM_OPS("scale"))
283 {
284 if (h == 0)
285 h = 100;
286 if (w == 0)
287 w = 100;
288 geom_flags |= WidthValue|HeightValue;
289 }
290 else if (CHECK_GEOM_OPS("auto"))
291 {
292 w = h = 100;
293 x = y = 50;
294 geom_flags |= WidthValue|HeightValue|XValue|YValue;
295 }
296#undef CHECK_GEOM_OPS
297 while (*ops != ':' && *ops != '\0') ++ops;
298 } /* done parsing ops */
170 { 299 }
171 if (geom_flags & XNegative)
172 geom_flags |= YNegative;
173 300
174 y = x; 301 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w))
175 }
176
177 if (!(geom_flags & WidthValue) && geom[0] != '=')
178 {
179 x += h_align;
180 y += v_align;
181 }
182
183 if (h_align != x)
184 {
185 h_align = x;
186 changed++; 302 ++changed;
187 } 303 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h))
188
189 if (v_align != y)
190 {
191 v_align = y;
192 changed++; 304 ++changed;
193 } 305 if (check_set_align_value (geom_flags, XValue, h_align, x))
194 306 ++changed;
195 if (h_scale != 0) 307 if (check_set_align_value (geom_flags, YValue, v_align, y))
196 new_flags |= bgPmap_hScale; 308 ++changed;
197 if (v_scale != 0)
198 new_flags |= bgPmap_vScale;
199 } 309 }
200 310
201 if (new_flags != flags) 311 if (new_flags != flags)
202 { 312 {
203 flags = new_flags; 313 flags = new_flags;
204 changed++; 314 changed++;
205 } 315 }
316//fprintf( stderr, "flags = %lX, scale = %ux%u, align=%+d%+d\n",
317// flags, h_scale, v_scale, h_align, v_align);
206 return (changed > 0); 318 return (changed > 0);
207} 319}
208 320
209void 321void
210rxvt_term::resize_pixmap () 322rxvt_term::resize_pixmap ()

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines