… | |
… | |
46 | * W and H are percentages of the terminal window size. |
46 | * W and H are percentages of the terminal window size. |
47 | * X and Y are also percentages; e.g., +50+50 centers |
47 | * X and Y are also percentages; e.g., +50+50 centers |
48 | * the image in the window. |
48 | * the image in the window. |
49 | * |
49 | * |
50 | * Pixmap Operations : (should be prepended by a colon) |
50 | * Pixmap Operations : (should be prepended by a colon) |
51 | * tile Tile image. Scaling/position modifiers above will affect |
|
|
52 | * the tile size and origin. |
|
|
53 | * propscale When scaling, scale proportionally. That is, maintain the |
|
|
54 | * proper aspect ratio for the image. Any portion of the |
|
|
55 | * background not covered by the image is filled with the |
|
|
56 | * current background color. |
|
|
57 | * scale Scale both up and down |
|
|
58 | */ |
51 | */ |
59 | |
52 | |
60 | #ifdef HAVE_BG_PIXMAP |
53 | #ifdef HAVE_BG_PIXMAP |
61 | void |
54 | void |
62 | rxvt_term::bg_destroy () |
55 | rxvt_term::bg_destroy () |
… | |
… | |
204 | { |
197 | { |
205 | bool changed = false; |
198 | bool changed = false; |
206 | int geom_flags = 0; |
199 | int geom_flags = 0; |
207 | int x = 0, y = 0; |
200 | int x = 0, y = 0; |
208 | unsigned int w = 0, h = 0; |
201 | unsigned int w = 0, h = 0; |
209 | unsigned int n; |
|
|
210 | unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); |
202 | unsigned long new_flags = (bg_flags & (~BG_GEOMETRY_FLAGS)); |
211 | const char *ops; |
|
|
212 | |
203 | |
213 | if (geom == NULL) |
204 | if (geom == NULL) |
214 | return false; |
205 | return false; |
215 | |
206 | |
216 | char str[256]; |
207 | if (geom[0]) |
217 | |
|
|
218 | ops = strchr (geom, ':'); |
|
|
219 | if (ops == NULL) |
|
|
220 | n = strlen (geom); |
|
|
221 | else |
|
|
222 | n = ops - geom; |
|
|
223 | |
|
|
224 | if (n >= sizeof (str)) |
|
|
225 | return false; |
|
|
226 | |
|
|
227 | memcpy (str, geom, n); |
|
|
228 | str[n] = '\0'; |
|
|
229 | rxvt_strtrim (str); |
|
|
230 | |
|
|
231 | if (str[0]) |
|
|
232 | { |
208 | { |
233 | /* 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 |
234 | geom_flags = XParseGeometry (str, &x, &y, &w, &h); |
297 | geom_flags |= XParseGeometry (arr[i], &x, &y, &w, &h); |
235 | } /* done parsing geometry string */ |
298 | } /* done parsing ops */ |
|
|
299 | |
|
|
300 | rxvt_free_strsplit (arr); |
|
|
301 | } |
236 | |
302 | |
237 | if (!update) |
303 | if (!update) |
238 | { |
304 | { |
239 | if (!(geom_flags & XValue)) |
305 | if (!(geom_flags & XValue)) |
240 | x = y = defaultAlign; |
306 | x = y = defaultAlign; |
… | |
… | |
249 | w = h; |
315 | w = h; |
250 | |
316 | |
251 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
317 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
252 | } |
318 | } |
253 | |
319 | |
254 | if (ops) |
|
|
255 | { |
|
|
256 | char **arr = rxvt_strsplit (':', ops + 1); |
|
|
257 | |
|
|
258 | for (int i = 0; arr[i]; i++) |
|
|
259 | { |
|
|
260 | if (!strcasecmp (arr[i], "tile")) |
|
|
261 | { |
|
|
262 | new_flags |= BG_TILE; |
|
|
263 | w = h = noScale; |
|
|
264 | geom_flags |= WidthValue|HeightValue; |
|
|
265 | } |
|
|
266 | else if (!strcasecmp (arr[i], "propscale")) |
|
|
267 | { |
|
|
268 | new_flags |= BG_PROP_SCALE; |
|
|
269 | } |
|
|
270 | else if (!strcasecmp (arr[i], "scale")) |
|
|
271 | { |
|
|
272 | if (h == 0) h = windowScale; |
|
|
273 | if (w == 0) w = windowScale; |
|
|
274 | |
|
|
275 | geom_flags |= WidthValue|HeightValue; |
|
|
276 | } |
|
|
277 | else if (!strcasecmp (arr[i], "root")) |
|
|
278 | { |
|
|
279 | new_flags |= BG_TILE|BG_ROOT_ALIGN; |
|
|
280 | w = h = noScale; |
|
|
281 | geom_flags |= WidthValue|HeightValue; |
|
|
282 | } |
|
|
283 | } /* done parsing ops */ |
|
|
284 | |
|
|
285 | rxvt_free_strsplit (arr); |
|
|
286 | } |
|
|
287 | |
|
|
288 | 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; |
289 | 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; |
290 | 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; |
291 | 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; |
292 | |
324 | |
… | |
… | |
303 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
335 | rxvt_term::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
304 | { |
336 | { |
305 | int target_width = szHint.width; |
337 | int target_width = szHint.width; |
306 | int target_height = szHint.height; |
338 | int target_height = szHint.height; |
307 | |
339 | |
|
|
340 | w = h_scale * target_width / 100; |
|
|
341 | h = v_scale * target_height / 100; |
|
|
342 | |
308 | if (bg_flags & BG_PROP_SCALE) |
343 | if (bg_flags & BG_PROP_SCALE) |
309 | { |
344 | { |
310 | float scale = (float)target_width / image_width; |
345 | float scale = (float)w / image_width; |
311 | min_it (scale, (float)target_height / image_height); |
346 | min_it (scale, (float)h / image_height); |
312 | w = image_width * scale + 0.5; |
347 | w = image_width * scale + 0.5; |
313 | h = image_height * scale + 0.5; |
348 | h = image_height * scale + 0.5; |
314 | } |
349 | } |
315 | else |
|
|
316 | { |
|
|
317 | w = h_scale * target_width / 100; |
|
|
318 | h = v_scale * target_height / 100; |
|
|
319 | } |
|
|
320 | |
350 | |
321 | if (!w) w = image_width; |
351 | if (!w) w = image_width; |
322 | if (!h) h = image_height; |
352 | if (!h) h = image_height; |
323 | |
353 | |
324 | if (bg_flags & BG_ROOT_ALIGN) |
354 | if (bg_flags & BG_ROOT_ALIGN) |
… | |
… | |
332 | y = make_align_position (v_align, target_height, h); |
362 | y = make_align_position (v_align, target_height, h); |
333 | } |
363 | } |
334 | |
364 | |
335 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
365 | bg_flags &= ~BG_IS_SIZE_SENSITIVE; |
336 | if (!(bg_flags & BG_TILE) |
366 | if (!(bg_flags & BG_TILE) |
337 | || (bg_flags & BG_PROP_SCALE) || h_scale || v_scale |
367 | || h_scale || v_scale |
338 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
368 | || (!(bg_flags & BG_ROOT_ALIGN) && (h_align || v_align)) |
339 | || w > target_width || h > target_height) |
369 | || w > target_width || h > target_height) |
340 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
370 | bg_flags |= BG_IS_SIZE_SENSITIVE; |
341 | } |
371 | } |
342 | |
372 | |