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.118 by sf-exg, Tue Nov 16 15:49:56 2010 UTC vs.
Revision 1.124 by sf-exg, Tue Nov 23 16:37:36 2010 UTC

66 * 66 *
67 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%. 67 * WxH+X+Y Set scaling to W% by H%, and position to X% by Y%.
68 * W and H are percentages of the terminal window size. 68 * W and H are percentages of the terminal window size.
69 * X and Y are also percentages; e.g., +50+50 centers 69 * X and Y are also percentages; e.g., +50+50 centers
70 * the image in the window. 70 * the image in the window.
71 * WxH+X Assumes Y == X
72 * WxH Assumes Y == X == 50 (centers the image)
73 * W+X+Y Assumes H == W
74 * W+X Assumes H == W and Y == X
75 * W Assumes H == W and Y == X == 50
76 *
77 * Adjusting position only :
78 * =+X+Y Set position to X% by Y% (absolute).
79 * =+X Set position to X% by X%.
80 * +X+Y Adjust position horizontally X% and vertically Y%
81 * from current position (relative).
82 * +X Adjust position horizontally X% and vertically X%
83 * from current position.
84 *
85 * Adjusting scale only :
86 * Wx0 Multiply horizontal scaling factor by W%
87 * 0xH Multiply vertical scaling factor by H%
88 * 0x0 No scaling (show image at normal size).
89 * 71 *
90 * Pixmap Operations : (should be prepended by a colon) 72 * Pixmap Operations : (should be prepended by a colon)
91 * tile Tile image. Scaling/position modifiers above will affect 73 * tile Tile image. Scaling/position modifiers above will affect
92 * the tile size and origin. 74 * the tile size and origin.
93 * propscale When scaling, scale proportionally. That is, maintain the 75 * propscale When scaling, scale proportionally. That is, maintain the
121#endif 103#endif
122 flags = 0; 104 flags = 0;
123 pixmap = None; 105 pixmap = None;
124 valid_since = invalid_since = 0; 106 valid_since = invalid_since = 0;
125 target = 0; 107 target = 0;
108 target_x = target_y = 0;
126} 109}
127 110
128void 111void
129bgPixmap_t::destroy () 112bgPixmap_t::destroy ()
130{ 113{
138 g_object_unref (pixbuf); 121 g_object_unref (pixbuf);
139#endif 122#endif
140 123
141 if (pixmap && target) 124 if (pixmap && target)
142 XFreePixmap (target->dpy, pixmap); 125 XFreePixmap (target->dpy, pixmap);
126}
127
128bool
129bgPixmap_t::set_position (int x, int y)
130{
131
132 if (target_x != x
133 || target_y != y)
134 {
135 target_x = x;
136 target_y = y;
137 return true;
138 }
139 return false;
143} 140}
144 141
145bool 142bool
146bgPixmap_t::window_size_sensitive () 143bgPixmap_t::window_size_sensitive ()
147{ 144{
256 dst_size = target_size - dst_pos; 253 dst_size = target_size - dst_pos;
257 return src_pos; 254 return src_pos;
258} 255}
259 256
260bool 257bool
261bgPixmap_t::set_geometry (const char *geom) 258bgPixmap_t::set_geometry (const char *geom, bool update)
262{ 259{
263 bool changed = false; 260 bool changed = false;
264 int geom_flags = 0; 261 int geom_flags = 0;
265 int x = 0, y = 0; 262 int x = 0, y = 0;
266 unsigned int w = 0, h = 0; 263 unsigned int w = 0, h = 0;
267 unsigned int n; 264 unsigned int n;
268 unsigned long new_flags = (flags & (~geometryFlags)); 265 unsigned long new_flags = (flags & (~geometryFlags));
269 const char *p; 266 const char *ops;
270# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */ 267# define MAXLEN_GEOM 256 /* could be longer than regular geometry string */
271 268
272 if (geom == NULL) 269 if (geom == NULL)
273 return false; 270 return false;
274 271
275 char str[MAXLEN_GEOM]; 272 char str[MAXLEN_GEOM];
276 273
277 while (isspace(*geom)) ++geom;
278 if ((p = strchr (geom, ';')) == NULL)
279 p = strchr (geom, '\0'); 274 ops = strchr (geom, ':');
280 275 if (ops == NULL)
276 n = strlen (geom);
277 else
281 n = (p - geom); 278 n = ops - geom;
279
282 if (n < MAXLEN_GEOM) 280 if (n >= MAXLEN_GEOM)
283 { 281 return false;
284 char *ops;
285 new_flags |= geometrySet;
286 282
287 memcpy (str, geom, n); 283 memcpy (str, geom, n);
288 str[n] = '\0'; 284 str[n] = '\0';
289 if (str[0] == ':') 285 rxvt_strtrim (str);
290 ops = &str[0];
291 else if (str[0] != 'x' && str[0] != 'X' && isalpha(str[0]))
292 ops = &str[0];
293 else
294 {
295 char *tmp;
296 ops = strchr (str, ':');
297 if (ops != NULL)
298 {
299 for (tmp = ops-1; tmp >= str && isspace(*tmp); --tmp);
300 *(++tmp) = '\0';
301 if (ops == tmp) ++ops;
302 }
303 }
304 286
305 if (ops > str || ops == NULL) 287 if (str[0])
306 { 288 {
307 /* we have geometry string - let's handle it prior to applying ops */ 289 /* we have geometry string - let's handle it prior to applying ops */
308 geom_flags = XParseGeometry (str, &x, &y, &w, &h); 290 geom_flags = XParseGeometry (str, &x, &y, &w, &h);
309
310 if ((geom_flags & XValue) && !(geom_flags & YValue))
311 {
312 y = x;
313 geom_flags |= YValue;
314 }
315
316 if (flags & geometrySet)
317 {
318 /* new geometry is an adjustment to the old one ! */
319 if ((geom_flags & WidthValue) && (geom_flags & HeightValue))
320 {
321 if (w == 0 && h != 0)
322 {
323 w = h_scale;
324 h = (v_scale * h) / 100;
325 }
326 else if (h == 0 && w != 0)
327 {
328 w = (h_scale * w) / 100;
329 h = v_scale;
330 }
331 }
332 if (geom_flags & XValue)
333 {
334 if (str[0] != '=')
335 {
336 y += v_align;
337 x += h_align;
338 }
339 }
340 }
341 else /* setting up geometry from scratch */
342 {
343 if (!(geom_flags & XValue))
344 {
345 /* use default geometry - centered */
346 x = y = defaultAlign;
347 }
348 else if (!(geom_flags & YValue))
349 y = x;
350
351 if ((geom_flags & (WidthValue|HeightValue)) == 0)
352 {
353 /* use default geometry - scaled */
354 w = h = defaultScale;
355 }
356 else if (geom_flags & WidthValue)
357 {
358 if (!(geom_flags & HeightValue))
359 h = w;
360 }
361 else
362 w = h;
363 }
364 } /* done parsing geometry string */ 291 } /* done parsing geometry string */
365 else if (!(flags & geometrySet)) 292
366 { 293 if (!update)
367 /* default geometry - scaled and centered */ 294 {
295 if (!(geom_flags & XValue))
368 x = y = defaultAlign; 296 x = y = defaultAlign;
297 else if (!(geom_flags & YValue))
298 y = x;
299
300 if (!(geom_flags & (WidthValue|HeightValue)))
369 w = h = defaultScale; 301 w = h = defaultScale;
370 } 302 else if (!(geom_flags & HeightValue))
303 h = w;
304 else if (!(geom_flags & WidthValue))
305 w = h;
371 306
372 if (!(flags & geometrySet))
373 geom_flags |= WidthValue|HeightValue|XValue|YValue; 307 geom_flags |= WidthValue|HeightValue|XValue|YValue;
308 }
374 309
375 if (ops) 310 if (ops)
376 { 311 {
377 while (*ops) 312 while (*ops)
378 { 313 {
379 while (*ops == ':' || isspace(*ops)) ++ops; 314 while (*ops == ':' || isspace(*ops)) ++ops;
380 315
381# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0) 316# define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof (op_str) - 1) == 0)
382 if (CHECK_GEOM_OPS ("tile")) 317 if (CHECK_GEOM_OPS ("tile"))
383 { 318 {
384 w = h = noScale; 319 w = h = noScale;
385 geom_flags |= WidthValue|HeightValue; 320 geom_flags |= WidthValue|HeightValue;
386 } 321 }
387 else if (CHECK_GEOM_OPS ("propscale")) 322 else if (CHECK_GEOM_OPS ("propscale"))
388 { 323 {
389 new_flags |= propScale; 324 new_flags |= propScale;
390 } 325 }
391 else if (CHECK_GEOM_OPS ("hscale")) 326 else if (CHECK_GEOM_OPS ("hscale"))
392 { 327 {
393 if (w == 0) w = windowScale; 328 if (w == 0) w = windowScale;
394 329
395 h = noScale; 330 h = noScale;
396 geom_flags |= WidthValue|HeightValue; 331 geom_flags |= WidthValue|HeightValue;
397 } 332 }
398 else if (CHECK_GEOM_OPS ("vscale")) 333 else if (CHECK_GEOM_OPS ("vscale"))
399 { 334 {
400 if (h == 0) h = windowScale; 335 if (h == 0) h = windowScale;
401 336
402 w = noScale; 337 w = noScale;
403 geom_flags |= WidthValue|HeightValue; 338 geom_flags |= WidthValue|HeightValue;
404 } 339 }
405 else if (CHECK_GEOM_OPS ("scale")) 340 else if (CHECK_GEOM_OPS ("scale"))
406 { 341 {
407 if (h == 0) h = windowScale; 342 if (h == 0) h = windowScale;
408 if (w == 0) w = windowScale; 343 if (w == 0) w = windowScale;
409 344
410 geom_flags |= WidthValue|HeightValue; 345 geom_flags |= WidthValue|HeightValue;
411 } 346 }
412 else if (CHECK_GEOM_OPS ("auto")) 347 else if (CHECK_GEOM_OPS ("auto"))
413 { 348 {
414 w = h = windowScale; 349 w = h = windowScale;
415 x = y = centerAlign; 350 x = y = centerAlign;
416 geom_flags |= WidthValue|HeightValue|XValue|YValue; 351 geom_flags |= WidthValue|HeightValue|XValue|YValue;
417 } 352 }
418 else if (CHECK_GEOM_OPS ("root")) 353 else if (CHECK_GEOM_OPS ("root"))
419 { 354 {
420 new_flags |= rootAlign; 355 new_flags |= rootAlign;
421 w = h = noScale; 356 w = h = noScale;
422 geom_flags |= WidthValue|HeightValue; 357 geom_flags |= WidthValue|HeightValue;
423 } 358 }
424# undef CHECK_GEOM_OPS 359# undef CHECK_GEOM_OPS
425 360
426 while (*ops != ':' && *ops != '\0') ++ops; 361 while (*ops != ':' && *ops != '\0') ++ops;
427 } /* done parsing ops */ 362 } /* done parsing ops */
428 } 363 }
429 364
430 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true; 365 if (check_set_scale_value (geom_flags, WidthValue, h_scale, w)) changed = true;
431 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true; 366 if (check_set_scale_value (geom_flags, HeightValue, v_scale, h)) changed = true;
432 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true; 367 if (check_set_align_value (geom_flags, XValue, h_align, x)) changed = true;
433 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true; 368 if (check_set_align_value (geom_flags, YValue, v_align, y)) changed = true;
434 }
435 369
436 if (new_flags != flags) 370 if (new_flags != flags)
437 { 371 {
438 flags = new_flags; 372 flags = new_flags;
439 changed = true; 373 changed = true;
464 if (!w) w = image_width; 398 if (!w) w = image_width;
465 if (!h) h = image_height; 399 if (!h) h = image_height;
466 400
467 if (flags & rootAlign) 401 if (flags & rootAlign)
468 { 402 {
469 target->get_window_origin (x, y);
470 x = -x; 403 x = -target_x;
471 y = -y; 404 y = -target_y;
472 } 405 }
473 else 406 else
474 { 407 {
475 x = make_align_position (h_align, target_width, w); 408 x = make_align_position (h_align, target_width, w);
476 y = make_align_position (v_align, target_height, h); 409 y = make_align_position (v_align, target_height, h);
1007 bool has_shade = shade != 100; 940 bool has_shade = shade != 100;
1008 941
1009 if (tint) 942 if (tint)
1010 { 943 {
1011 tint->get (c); 944 tint->get (c);
1012# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x000700 || (cmp) >= 0x00f700) 945# define IS_COMPONENT_WHOLESOME(cmp) ((cmp) <= 0x00ff || (cmp) >= 0xff00)
946 if (!has_shade
1013 if (!has_shade && IS_COMPONENT_WHOLESOME (c.r) 947 && IS_COMPONENT_WHOLESOME (c.r)
1014 && IS_COMPONENT_WHOLESOME (c.g) 948 && IS_COMPONENT_WHOLESOME (c.g)
1015 && IS_COMPONENT_WHOLESOME (c.b)) 949 && IS_COMPONENT_WHOLESOME (c.b))
1016 flags |= bgPixmap_t::tintWholesome; 950 flags |= bgPixmap_t::tintWholesome;
1017# undef IS_COMPONENT_WHOLESOME 951# undef IS_COMPONENT_WHOLESOME
1018 } 952 }
1019 953
1020 if (has_shade) 954 if (has_shade || tint)
1021 flags |= bgPixmap_t::tintNeeded; 955 flags |= bgPixmap_t::tintNeeded;
1022 else if (tint)
1023 {
1024 if ((c.r > 0x000700 || c.g > 0x000700 || c.b > 0x000700)
1025 && (c.r < 0x00f700 || c.g < 0x00f700 || c.b < 0x00f700))
1026 {
1027 flags |= bgPixmap_t::tintNeeded;
1028 }
1029 }
1030 956
1031 return flags; 957 return flags;
1032} 958}
1033 959
1034bool 960bool
1281 int window_height = target->szHint.height; 1207 int window_height = target->szHint.height;
1282 int sx, sy; 1208 int sx, sy;
1283 XGCValues gcv; 1209 XGCValues gcv;
1284 GC gc; 1210 GC gc;
1285 1211
1286 target->get_window_origin (sx, sy); 1212 sx = target_x;
1213 sy = target_y;
1287 1214
1288 /* check if we are outside of the visible part of the virtual screen : */ 1215 /* check if we are outside of the visible part of the virtual screen : */
1289 if (sx + window_width <= 0 || sy + window_height <= 0 1216 if (sx + window_width <= 0 || sy + window_height <= 0
1290 || sx >= root_width || sy >= root_height) 1217 || sx >= root_width || sy >= root_height)
1291 return 0; 1218 return 0;
1344 1271
1345 if (tiled_root_pmap == None) /* something really bad happened - abort */ 1272 if (tiled_root_pmap == None) /* something really bad happened - abort */
1346 return 0; 1273 return 0;
1347 1274
1348 /* straightforward pixmap copy */ 1275 /* straightforward pixmap copy */
1276 while (sx < 0) sx += (int)root_width;
1277 while (sy < 0) sy += (int)root_height;
1278
1349 gcv.tile = recoded_root_pmap; 1279 gcv.tile = recoded_root_pmap;
1350 gcv.fill_style = FillTiled; 1280 gcv.fill_style = FillTiled;
1351
1352 while (sx < 0) sx += (int)root_width;
1353 while (sy < 0) sy += (int)root_height;
1354
1355 gcv.ts_x_origin = -sx; 1281 gcv.ts_x_origin = -sx;
1356 gcv.ts_y_origin = -sy; 1282 gcv.ts_y_origin = -sy;
1357 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv); 1283 gc = XCreateGC (dpy, target->vt, GCFillStyle | GCTile | GCTileStipXOrigin | GCTileStipYOrigin, &gcv);
1358 1284
1359 if (gc) 1285 if (gc)
1425 /* we need to re-generate transparency pixmap in that case ! */ 1351 /* we need to re-generate transparency pixmap in that case ! */
1426 background_flags = make_transparency_pixmap (); 1352 background_flags = make_transparency_pixmap ();
1427 if (background_flags == 0) 1353 if (background_flags == 0)
1428 return false; 1354 return false;
1429 else if ((background_flags & transpTransformations) == (flags & transpTransformations)) 1355 else if ((background_flags & transpTransformations) == (flags & transpTransformations))
1430 flags = flags & ~isInvalid; 1356 flags &= ~isInvalid;
1431 } 1357 }
1432# endif 1358# endif
1433 1359
1434# ifdef BG_IMAGE_FROM_FILE 1360# ifdef BG_IMAGE_FROM_FILE
1435 if (have_image 1361 if (have_image
1436 || (background_flags & transpTransformations) != (flags & transpTransformations)) 1362 || (background_flags & transpTransformations) != (flags & transpTransformations))
1437 { 1363 {
1438 if (render_image (background_flags)) 1364 if (render_image (background_flags))
1439 flags = flags & ~isInvalid; 1365 flags &= ~isInvalid;
1440 } 1366 }
1441# endif 1367# endif
1442 1368
1443# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE) 1369# if defined(ENABLE_TRANSPARENCY) && !defined(HAVE_AFTERIMAGE)
1444 XImage *result = NULL; 1370 XImage *result = NULL;
1464 if (gc) 1390 if (gc)
1465 { 1391 {
1466 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height); 1392 XPutImage (target->dpy, pixmap, gc, result, 0, 0, 0, 0, result->width, result->height);
1467 1393
1468 XFreeGC (target->dpy, gc); 1394 XFreeGC (target->dpy, gc);
1469 flags = flags & ~isInvalid; 1395 flags &= ~isInvalid;
1470 } 1396 }
1471 1397
1472 XDestroyImage (result); 1398 XDestroyImage (result);
1473 } 1399 }
1474# endif 1400# endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines