1 | /*----------------------------------------------------------------------* |
1 | /*----------------------------------------------------------------------* |
2 | * File: background.C - former xpm.C |
2 | * File: background.C - former xpm.C |
3 | *----------------------------------------------------------------------* |
3 | *----------------------------------------------------------------------* |
4 | * |
4 | * |
5 | * All portions of code are copyright by their respective author/s. |
5 | * All portions of code are copyright by their respective author/s. |
6 | * Copyright (c) 1997 Carsten Haitzler <raster@zip.com.au> |
|
|
7 | * Copyright (c) 1997,1998 Oezguer Kesim <kesim@math.fu-berlin.de> |
|
|
8 | * Copyright (c) 1998-2001 Geoff Wing <gcw@pobox.com> |
|
|
9 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2006 Marc Lehmann <pcg@goof.com> |
10 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
11 | * |
8 | * |
12 | * This program is free software; you can redistribute it and/or modify |
9 | * This program is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU General Public License as published by |
10 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
87 | * scale Scale both up and down |
84 | * scale Scale both up and down |
88 | * auto Same as 100x100+50+50 |
85 | * auto Same as 100x100+50+50 |
89 | */ |
86 | */ |
90 | |
87 | |
91 | #ifdef HAVE_BG_PIXMAP |
88 | #ifdef HAVE_BG_PIXMAP |
92 | bgPixmap_t::bgPixmap_t() |
89 | bgPixmap_t::bgPixmap_t () |
93 | { |
90 | { |
94 | #ifdef HAVE_AFTERIMAGE |
91 | #ifdef HAVE_AFTERIMAGE |
95 | original_asim = NULL; |
92 | original_asim = NULL; |
96 | #endif |
93 | #endif |
97 | #ifdef BG_IMAGE_FROM_FILE |
94 | #ifdef BG_IMAGE_FROM_FILE |
… | |
… | |
100 | #endif |
97 | #endif |
101 | flags = 0; |
98 | flags = 0; |
102 | pixmap = None; |
99 | pixmap = None; |
103 | } |
100 | } |
104 | |
101 | |
105 | bgPixmap_t::~bgPixmap_t() |
102 | void |
|
|
103 | bgPixmap_t::destroy () |
106 | { |
104 | { |
107 | #ifdef HAVE_AFTERIMAGE |
105 | #ifdef HAVE_AFTERIMAGE |
108 | if (original_asim) |
106 | if (original_asim) |
109 | safe_asimage_destroy (original_asim); |
107 | safe_asimage_destroy (original_asim); |
110 | #endif |
108 | #endif |
|
|
109 | |
111 | if (pixmap && target) |
110 | if (pixmap && target) |
112 | XFreePixmap (target->dpy, pixmap); |
111 | XFreePixmap (target->dpy, pixmap); |
113 | } |
112 | } |
114 | |
113 | |
115 | bool |
114 | bool |
116 | bgPixmap_t::window_size_sensitive () |
115 | bgPixmap_t::window_size_sensitive () |
117 | { |
116 | { |
|
|
117 | # ifdef ENABLE_TRANSPARENCY |
|
|
118 | if (flags & isTransparent) |
|
|
119 | return true; |
|
|
120 | # endif |
|
|
121 | |
118 | # ifdef BG_IMAGE_FROM_FILE |
122 | # ifdef BG_IMAGE_FROM_FILE |
119 | # ifdef HAVE_AFTERIMAGE |
123 | # ifdef HAVE_AFTERIMAGE |
120 | if (original_asim != NULL) |
124 | if (original_asim != NULL) |
121 | # endif |
125 | # endif |
122 | { |
126 | { |
123 | if (h_scale != 0 || v_scale != 0 |
127 | if (h_scale != 0 || v_scale != 0 |
124 | || h_align != 0 || v_align != 0) |
128 | || h_align != 0 || v_align != 0) |
125 | return true; |
129 | return true; |
126 | } |
130 | } |
127 | # endif |
131 | # endif |
|
|
132 | |
|
|
133 | return false; |
|
|
134 | } |
|
|
135 | |
|
|
136 | bool |
|
|
137 | bgPixmap_t::window_position_sensitive () |
|
|
138 | { |
128 | # ifdef ENABLE_TRANSPARENCY |
139 | # ifdef ENABLE_TRANSPARENCY |
129 | if (flags & isTransparent) |
140 | if (flags & isTransparent) |
130 | return true; |
141 | return true; |
131 | # endif |
142 | # endif |
|
|
143 | |
|
|
144 | # ifdef BG_IMAGE_FROM_FILE |
|
|
145 | # ifdef HAVE_AFTERIMAGE |
|
|
146 | if (original_asim != NULL) |
|
|
147 | # endif |
|
|
148 | { |
|
|
149 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
150 | return true; |
|
|
151 | } |
|
|
152 | # endif |
|
|
153 | |
132 | return false; |
154 | return false; |
133 | } |
155 | }; |
134 | |
156 | |
135 | bool bgPixmap_t::need_client_side_rendering () |
157 | bool bgPixmap_t::need_client_side_rendering () |
136 | { |
158 | { |
137 | # ifdef HAVE_AFTERIMAGE |
159 | # ifdef HAVE_AFTERIMAGE |
138 | if (original_asim != NULL) |
160 | if (original_asim != NULL) |
… | |
… | |
172 | static inline bool |
194 | static inline bool |
173 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
195 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
174 | { |
196 | { |
175 | if (geom_flags & flag) |
197 | if (geom_flags & flag) |
176 | { |
198 | { |
|
|
199 | if (new_value != bgPixmap_t::rootAlign) |
|
|
200 | { |
177 | if (new_value < -100) |
201 | if (new_value < -100) |
178 | new_value = -100; |
202 | new_value = -100; |
179 | else if (new_value > 200) |
203 | else if (new_value > 200) |
180 | new_value = 200; |
204 | new_value = 200; |
|
|
205 | } |
181 | if (new_value != align) |
206 | if (new_value != align) |
182 | { |
207 | { |
183 | align = new_value; |
208 | align = new_value; |
184 | return true; |
209 | return true; |
185 | } |
210 | } |
… | |
… | |
323 | else |
348 | else |
324 | w = h; |
349 | w = h; |
325 | } |
350 | } |
326 | } /* done parsing geometry string */ |
351 | } /* done parsing geometry string */ |
327 | else if (!(flags & geometrySet)) |
352 | else if (!(flags & geometrySet)) |
|
|
353 | { |
328 | { /* default geometry - scaled and centered */ |
354 | /* default geometry - scaled and centered */ |
329 | x = y = defaultAlign; |
355 | x = y = defaultAlign; |
330 | w = h = defaultScale; |
356 | w = h = defaultScale; |
331 | } |
357 | } |
332 | |
358 | |
333 | if (!(flags & geometrySet)) |
359 | if (!(flags & geometrySet)) |
… | |
… | |
339 | { |
365 | { |
340 | while (*ops == ':' || isspace(*ops)) ++ops; |
366 | while (*ops == ':' || isspace(*ops)) ++ops; |
341 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
367 | # define CHECK_GEOM_OPS(op_str) (strncasecmp (ops, (op_str), sizeof(op_str)-1) == 0) |
342 | if (CHECK_GEOM_OPS("tile")) |
368 | if (CHECK_GEOM_OPS("tile")) |
343 | { |
369 | { |
344 | w = h = 0; |
370 | w = h = noScale; |
345 | geom_flags |= WidthValue|HeightValue; |
371 | geom_flags |= WidthValue|HeightValue; |
346 | } |
372 | } |
347 | else if (CHECK_GEOM_OPS("propscale")) |
373 | else if (CHECK_GEOM_OPS("propscale")) |
348 | { |
374 | { |
349 | if (w == 0 && h == 0) |
375 | if (w == 0 && h == 0) |
350 | { |
376 | { |
351 | w = 100; |
377 | w = windowScale; |
352 | geom_flags |= WidthValue; |
378 | geom_flags |= WidthValue; |
353 | } |
379 | } |
354 | new_flags |= propScale; |
380 | new_flags |= propScale; |
355 | } |
381 | } |
356 | else if (CHECK_GEOM_OPS("hscale")) |
382 | else if (CHECK_GEOM_OPS("hscale")) |
357 | { |
383 | { |
358 | if (w == 0) |
384 | if (w == 0) |
359 | w = 100; |
385 | w = windowScale; |
360 | h = 0; |
386 | h = noScale; |
361 | geom_flags |= WidthValue|HeightValue; |
387 | geom_flags |= WidthValue|HeightValue; |
362 | } |
388 | } |
363 | else if (CHECK_GEOM_OPS("vscale")) |
389 | else if (CHECK_GEOM_OPS("vscale")) |
364 | { |
390 | { |
365 | if (h == 0) |
391 | if (h == 0) |
366 | h = 100; |
392 | h = windowScale; |
367 | w = 0; |
393 | w = noScale; |
368 | geom_flags |= WidthValue|HeightValue; |
394 | geom_flags |= WidthValue|HeightValue; |
369 | } |
395 | } |
370 | else if (CHECK_GEOM_OPS("scale")) |
396 | else if (CHECK_GEOM_OPS("scale")) |
371 | { |
397 | { |
372 | if (h == 0) |
398 | if (h == 0) |
373 | h = 100; |
399 | h = windowScale; |
374 | if (w == 0) |
400 | if (w == 0) |
375 | w = 100; |
401 | w = windowScale; |
376 | geom_flags |= WidthValue|HeightValue; |
402 | geom_flags |= WidthValue|HeightValue; |
377 | } |
403 | } |
378 | else if (CHECK_GEOM_OPS("auto")) |
404 | else if (CHECK_GEOM_OPS("auto")) |
379 | { |
405 | { |
|
|
406 | w = h = windowScale; |
|
|
407 | x = y = centerAlign; |
|
|
408 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
|
|
409 | } |
|
|
410 | else if (CHECK_GEOM_OPS("root")) |
|
|
411 | { |
380 | w = h = 100; |
412 | w = h = noScale; |
381 | x = y = 50; |
413 | x = y = rootAlign; |
382 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
414 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
383 | } |
415 | } |
384 | # undef CHECK_GEOM_OPS |
416 | # undef CHECK_GEOM_OPS |
385 | while (*ops != ':' && *ops != '\0') ++ops; |
417 | while (*ops != ':' && *ops != '\0') ++ops; |
386 | } /* done parsing ops */ |
418 | } /* done parsing ops */ |
… | |
… | |
425 | |
457 | |
426 | TIMING_TEST_START (asim); |
458 | TIMING_TEST_START (asim); |
427 | |
459 | |
428 | if (original_asim) |
460 | if (original_asim) |
429 | { |
461 | { |
|
|
462 | if (h_align == rootAlign || v_align == rootAlign) |
|
|
463 | { |
|
|
464 | target->get_window_origin(x, y); |
|
|
465 | x = -x; |
|
|
466 | y = -y; |
|
|
467 | } |
|
|
468 | if (h_align != rootAlign) |
430 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
469 | x = make_align_position (h_align, target_width, w > 0 ? w : (int)original_asim->width); |
|
|
470 | if (v_align != rootAlign) |
431 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
471 | y = make_align_position (v_align, target_height, h > 0 ? h : (int)original_asim->height); |
432 | } |
472 | } |
433 | |
473 | |
434 | if (original_asim == NULL |
474 | if (original_asim == NULL |
435 | || x >= target_width |
475 | || x >= target_width |
436 | || y >= target_height |
476 | || y >= target_height |
… | |
… | |
465 | h > 0 ? h : original_asim->height, |
505 | h > 0 ? h : original_asim->height, |
466 | background ? ASA_ASImage : ASA_XImage, |
506 | background ? ASA_ASImage : ASA_XImage, |
467 | 100, ASIMAGE_QUALITY_DEFAULT); |
507 | 100, ASIMAGE_QUALITY_DEFAULT); |
468 | } |
508 | } |
469 | if (background == NULL) |
509 | if (background == NULL) |
470 | {/* if tiling - pixmap has to be sized exactly as the image */ |
510 | {/* if tiling - pixmap has to be sized exactly as the image, |
|
|
511 | but there is no need to make it bigger then the window! */ |
471 | if (h_scale == 0) |
512 | if (h_scale == 0) |
472 | new_pmap_width = result->width; |
513 | new_pmap_width = min (result->width, target_width); |
473 | if (v_scale == 0) |
514 | if (v_scale == 0) |
474 | new_pmap_height = result->height; |
515 | new_pmap_height = min (result->height, target_height); |
475 | /* we also need to tile our image in one or both directions */ |
516 | /* we also need to tile our image in one or both directions */ |
476 | if (h_scale == 0 || v_scale == 0) |
517 | if (h_scale == 0 || v_scale == 0) |
477 | { |
518 | { |
478 | ASImage *tmp = tile_asimage (target->asv, result, |
519 | ASImage *tmp = tile_asimage (target->asv, result, |
479 | (h_scale > 0) ? 0 : (int)result->width - x, |
520 | (h_scale > 0) ? 0 : (int)result->width - x, |
480 | (v_scale > 0) ? 0 : (int)result->height - y, |
521 | (v_scale > 0) ? 0 : (int)result->height - y, |
|
|
522 | new_pmap_width, |
481 | result->width, result->height, |
523 | new_pmap_height, |
482 | TINT_LEAVE_SAME, ASA_XImage, |
524 | TINT_LEAVE_SAME, ASA_XImage, |
483 | 100, ASIMAGE_QUALITY_DEFAULT); |
525 | 100, ASIMAGE_QUALITY_DEFAULT); |
484 | if (tmp) |
526 | if (tmp) |
485 | { |
527 | { |
486 | if (result != original_asim) |
528 | if (result != original_asim) |
… | |
… | |
820 | |
862 | |
821 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
863 | if (tiled_root_pmap == None) /* something really bad happened - abort */ |
822 | return 0; |
864 | return 0; |
823 | |
865 | |
824 | if (root_pixmap == None) |
866 | if (root_pixmap == None) |
|
|
867 | { |
825 | { /* use tricks to obtain the root background image :*/ |
868 | /* use tricks to obtain the root background image :*/ |
826 | /* we want to create Overrideredirect window overlapping out window |
869 | /* we want to create Overrideredirect window overlapping out window |
827 | with background type of Parent Relative and then grab it */ |
870 | with background type of Parent Relative and then grab it */ |
828 | XSetWindowAttributes attr; |
871 | XSetWindowAttributes attr; |
829 | Window src; |
872 | Window src; |
830 | bool success = false; |
873 | bool success = false; |
… | |
… | |
850 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
893 | * but to be on the safe side - let's check for the actuall event to arrive : */ |
851 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
894 | while (XCheckWindowEvent (dpy, src, ExposureMask, &event)) |
852 | ++ev_count; |
895 | ++ev_count; |
853 | |
896 | |
854 | if (ev_count > 0); |
897 | if (ev_count > 0); |
|
|
898 | { |
855 | { /* hooray! - we can grab the image! */ |
899 | /* hooray! - we can grab the image! */ |
856 | gc = XCreateGC (dpy, root, 0, NULL); |
900 | gc = XCreateGC (dpy, root, 0, NULL); |
857 | if (gc) |
901 | if (gc) |
858 | { |
902 | { |
859 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
903 | XCopyArea (dpy, src, tiled_root_pmap, gc, 0, 0, window_width, window_height, 0, 0); |
860 | success = true; |
904 | success = true; |
… | |
… | |
1145 | pmap_width = result->width; |
1189 | pmap_width = result->width; |
1146 | pmap_height = result->height; |
1190 | pmap_height = result->height; |
1147 | pmap_depth = target->depth; |
1191 | pmap_depth = target->depth; |
1148 | } |
1192 | } |
1149 | if (pmap_depth != result->depth) |
1193 | if (pmap_depth != result->depth) |
|
|
1194 | { |
1150 | { /* Bad Match error will ensue ! stupid X !!!! */ |
1195 | /* Bad Match error will ensue ! stupid X !!!! */ |
1151 | if( result->depth == 24 && pmap_depth == 32) |
1196 | if( result->depth == 24 && pmap_depth == 32) |
1152 | result->depth = 32; |
1197 | result->depth = 32; |
1153 | else if( result->depth == 32 && pmap_depth == 24) |
1198 | else if( result->depth == 32 && pmap_depth == 24) |
1154 | result->depth = 24; |
1199 | result->depth = 24; |
1155 | else |
1200 | else |
… | |
… | |
1201 | { |
1246 | { |
1202 | if (target) |
1247 | if (target) |
1203 | { |
1248 | { |
1204 | flags &= ~isVtOrigin; |
1249 | flags &= ~isVtOrigin; |
1205 | if (pixmap != None) |
1250 | if (pixmap != None) |
|
|
1251 | { |
1206 | { /* set target's background to pixmap */ |
1252 | /* set target's background to pixmap */ |
1207 | # ifdef ENABLE_TRANSPARENCY |
1253 | # ifdef ENABLE_TRANSPARENCY |
1208 | if (flags & isTransparent) |
1254 | if (flags & isTransparent) |
1209 | { |
1255 | { |
1210 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1256 | XSetWindowBackgroundPixmap (target->dpy, target->parent[0], pixmap); |
1211 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
1257 | XSetWindowBackgroundPixmap (target->dpy, target->vt, ParentRelative); |
… | |
… | |
1227 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1273 | XSetWindowBackground (target->dpy, target->scrollBar.win, target->pix_colors[Color_border]); |
1228 | # endif |
1274 | # endif |
1229 | } |
1275 | } |
1230 | } |
1276 | } |
1231 | else |
1277 | else |
|
|
1278 | { |
1232 | { /* set target background to a pixel */ |
1279 | /* set target background to a pixel */ |
1233 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1280 | XSetWindowBackground (target->dpy, target->parent[0], target->pix_colors[Color_border]); |
1234 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1281 | XSetWindowBackground (target->dpy, target->vt, target->pix_colors[Color_bg]); |
1235 | /* do we also need to set scrollbar's background here ? */ |
1282 | /* do we also need to set scrollbar's background here ? */ |
1236 | # if HAVE_SCROLLBARS |
1283 | # if HAVE_SCROLLBARS |
1237 | if (target->scrollBar.win) |
1284 | if (target->scrollBar.win) |