ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/rxvt-unicode/src/background.C
(Generate patch)

Comparing rxvt-unicode/src/background.C (file contents):
Revision 1.160 by sf-exg, Thu Aug 11 08:37:17 2011 UTC vs.
Revision 1.164 by sf-exg, Sun Aug 14 22:01:25 2011 UTC

197{ 197{
198 bool changed = false; 198 bool changed = false;
199 int geom_flags = 0; 199 int geom_flags = 0;
200 int x = 0, y = 0; 200 int x = 0, y = 0;
201 unsigned int w = 0, h = 0; 201 unsigned int w = 0, h = 0;
202 unsigned int n;
203 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); 202 unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS));
204 const char *ops;
205 203
206 if (geom == NULL) 204 if (geom == NULL)
207 return false; 205 return false;
208 206
209 char str[256]; 207 if (geom[0])
210
211 ops = strchr (geom, ':');
212 if (ops == NULL)
213 n = strlen (geom);
214 else
215 n = ops - geom;
216
217 if (n >= sizeof (str))
218 return false;
219
220 memcpy (str, geom, n);
221 str[n] = '\0';
222 rxvt_strtrim (str);
223
224 if (str[0])
225 { 208 {
226 /* we have geometry string - let's handle it prior to applying ops */ 209 char **arr = rxvt_strsplit (':', geom);
210
211 for (int i = 0; arr[i]; i++)
212 {
213 if (!strcasecmp (arr[i], "style=tiled"))
214 {
215 new_flags = BG_TILE;
216 w = h = noScale;
217 x = y = 0;
218 geom_flags = WidthValue|HeightValue|XValue|YValue;
219 }
220 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
221 {
222 new_flags = BG_PROP_SCALE;
223 w = h = windowScale;
224 x = y = centerAlign;
225 geom_flags = WidthValue|HeightValue|XValue|YValue;
226 }
227 else if (!strcasecmp (arr[i], "style=stretched"))
228 {
229 new_flags = 0;
230 w = h = windowScale;
231 geom_flags = WidthValue|HeightValue;
232 }
233 else if (!strcasecmp (arr[i], "style=centered"))
234 {
235 new_flags = 0;
236 w = h = noScale;
237 x = y = centerAlign;
238 geom_flags = WidthValue|HeightValue|XValue|YValue;
239 }
240 else if (!strcasecmp (arr[i], "style=root-tiled"))
241 {
242 new_flags = BG_TILE|BG_ROOT_ALIGN;
243 w = h = noScale;
244 geom_flags = WidthValue|HeightValue;
245 }
246 else if (!strcasecmp (arr[i], "op=tile"))
247 new_flags |= BG_TILE;
248 else if (!strcasecmp (arr[i], "op=pscale"))
249 new_flags |= BG_PROP_SCALE;
250 else if (!strcasecmp (arr[i], "op=root"))
251 new_flags |= BG_ROOT_ALIGN;
252
253 // deprecated
254 else if (!strcasecmp (arr[i], "tile"))
255 {
256 new_flags |= BG_TILE;
257 w = h = noScale;
258 geom_flags |= WidthValue|HeightValue;
259 }
260 else if (!strcasecmp (arr[i], "propscale"))
261 {
262 new_flags |= BG_PROP_SCALE;
263 }
264 else if (!strcasecmp (arr[i], "hscale"))
265 {
266 new_flags |= BG_TILE;
267 w = windowScale;
268 h = noScale;
269 geom_flags |= WidthValue|HeightValue;
270 }
271 else if (!strcasecmp (arr[i], "vscale"))
272 {
273 new_flags |= BG_TILE;
274 h = windowScale;
275 w = noScale;
276 geom_flags |= WidthValue|HeightValue;
277 }
278 else if (!strcasecmp (arr[i], "scale"))
279 {
280 w = h = windowScale;
281 geom_flags |= WidthValue|HeightValue;
282 }
283 else if (!strcasecmp (arr[i], "auto"))
284 {
285 w = h = windowScale;
286 x = y = centerAlign;
287 geom_flags |= WidthValue|HeightValue|XValue|YValue;
288 }
289 else if (!strcasecmp (arr[i], "root"))
290 {
291 new_flags |= BG_TILE|BG_ROOT_ALIGN;
292 w = h = noScale;
293 geom_flags |= WidthValue|HeightValue;
294 }
295
296 else
227 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 297 geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h);
228 } /* done parsing geometry string */ 298 } /* done parsing ops */
299
300 rxvt_free_strsplit (arr);
301 }
229 302
230 if (!update) 303 if (!update)
231 { 304 {
232 if (!(geom_flags & XValue)) 305 if (!(geom_flags & XValue))
233 x = y = defaultAlign; 306 x = y = defaultAlign;
242 w = h; 315 w = h;
243 316
244 geom_flags |= WidthValue|HeightValue|XValue|YValue; 317 geom_flags |= WidthValue|HeightValue|XValue|YValue;
245 } 318 }
246 319
247 if (ops)
248 {
249 char **arr = rxvt_strsplit (':', ops + 1);
250
251 for (int i = 0; arr[i]; i++)
252 {
253 if (!strcasecmp (arr[i], "style=tiled"))
254 {
255 new_flags = BG_TILE;
256 w = h = noScale;
257 x = y = 0;
258 geom_flags = WidthValue|HeightValue|XValue|YValue;
259 }
260 else if (!strcasecmp (arr[i], "style=aspect-stretched"))
261 {
262 new_flags = BG_PROP_SCALE;
263 x = y = centerAlign;
264 geom_flags = XValue|YValue;
265 }
266 else if (!strcasecmp (arr[i], "style=stretched"))
267 {
268 new_flags = 0;
269 w = h = windowScale;
270 geom_flags = WidthValue|HeightValue;
271 }
272 else if (!strcasecmp (arr[i], "style=centered"))
273 {
274 new_flags = 0;
275 w = h = noScale;
276 x = y = centerAlign;
277 geom_flags = WidthValue|HeightValue|XValue|YValue;
278 }
279 else if (!strcasecmp (arr[i], "style=root-tiled"))
280 {
281 new_flags = BG_TILE|BG_ROOT_ALIGN;
282 w = h = noScale;
283 geom_flags = WidthValue|HeightValue;
284 }
285 else if (!strcasecmp (arr[i], "op=tile"))
286 new_flags |= BG_TILE;
287 else if (!strcasecmp (arr[i], "op=pscale"))
288 new_flags |= BG_PROP_SCALE;
289 else if (!strcasecmp (arr[i], "op=root"))
290 new_flags |= BG_ROOT_ALIGN;
291
292 // deprecated
293 else if (!strcasecmp (arr[i], "tile"))
294 {
295 new_flags |= BG_TILE;
296 w = h = noScale;
297 geom_flags |= WidthValue|HeightValue;
298 }
299 else if (!strcasecmp (arr[i], "propscale"))
300 {
301 new_flags |= BG_PROP_SCALE;
302 }
303 else if (!strcasecmp (arr[i], "scale"))
304 {
305 if (h == 0) h = windowScale;
306 if (w == 0) w = windowScale;
307
308 geom_flags |= WidthValue|HeightValue;
309 }
310 else if (!strcasecmp (arr[i], "root"))
311 {
312 new_flags |= BG_TILE|BG_ROOT_ALIGN;
313 w = h = noScale;
314 geom_flags |= WidthValue|HeightValue;
315 }
316 } /* done parsing ops */
317
318 rxvt_free_strsplit (arr);
319 }
320
321 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 320 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
322 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 321 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
323 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 322 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
324 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 323 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
325 324
336rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) 335rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y)
337{ 336{
338 int target_width = szHint.width; 337 int target_width = szHint.width;
339 int target_height = szHint.height; 338 int target_height = szHint.height;
340 339
340 w = h_scale * target_width / 100;
341 h = v_scale * target_height / 100;
342
341 if (bg_flags & BG_PROP_SCALE) 343 if (bg_flags & BG_PROP_SCALE)
342 { 344 {
343 float scale = (float)target_width / image_width; 345 float scale = (float)w / image_width;
344 min_it (scale, (float)target_height / image_height); 346 min_it (scale, (float)h / image_height);
345 w = image_width * scale + 0.5; 347 w = image_width * scale + 0.5;
346 h = image_height * scale + 0.5; 348 h = image_height * scale + 0.5;
347 } 349 }
348 else
349 {
350 w = h_scale * target_width / 100;
351 h = v_scale * target_height / 100;
352 }
353 350
354 if (!w) w = image_width; 351 if (!w) w = image_width;
355 if (!h) h = image_height; 352 if (!h) h = image_height;
356 353
357 if (bg_flags & BG_ROOT_ALIGN) 354 if (bg_flags & BG_ROOT_ALIGN)
365 y = make_align_position (v_align, target_height, h); 362 y = make_align_position (v_align, target_height, h);
366 } 363 }
367 364
368 bg_flags &= ~BG_IS_SIZE_SENSITIVE; 365 bg_flags &= ~BG_IS_SIZE_SENSITIVE;
369 if (!(bg_flags & BG_TILE) 366 if (!(bg_flags & BG_TILE)
370 || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale 367 || h_scale || v_scale
371 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) 368 || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align))
372 || w > target_width || h > target_height) 369 || w > target_width || h > target_height)
373 bg_flags |= BG_IS_SIZE_SENSITIVE; 370 bg_flags |= BG_IS_SIZE_SENSITIVE;
374} 371}
375 372

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines