… | |
… | |
138 | # endif |
138 | # endif |
139 | |
139 | |
140 | # ifdef BG_IMAGE_FROM_FILE |
140 | # ifdef BG_IMAGE_FROM_FILE |
141 | if (have_image) |
141 | if (have_image) |
142 | { |
142 | { |
143 | if (h_scale != 0 || v_scale != 0 |
143 | if (flags & sizeSensitive) |
144 | || h_align != 0 || v_align != 0) |
|
|
145 | return true; |
144 | return true; |
146 | } |
145 | } |
147 | # endif |
146 | # endif |
148 | |
147 | |
149 | return false; |
148 | return false; |
… | |
… | |
158 | # endif |
157 | # endif |
159 | |
158 | |
160 | # ifdef BG_IMAGE_FROM_FILE |
159 | # ifdef BG_IMAGE_FROM_FILE |
161 | if (have_image) |
160 | if (have_image) |
162 | { |
161 | { |
163 | if (h_align == rootAlign || v_align == rootAlign) |
162 | if (flags & rootAlign) |
164 | return true; |
163 | return true; |
165 | } |
164 | } |
166 | # endif |
165 | # endif |
167 | |
166 | |
168 | return false; |
167 | return false; |
… | |
… | |
208 | static inline bool |
207 | static inline bool |
209 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
208 | check_set_align_value (int geom_flags, int flag, int &align, int new_value) |
210 | { |
209 | { |
211 | if (geom_flags & flag) |
210 | if (geom_flags & flag) |
212 | { |
211 | { |
213 | if (new_value != bgPixmap_t::rootAlign) |
|
|
214 | { |
|
|
215 | if (new_value < -100) |
212 | if (new_value < -100) |
216 | new_value = -100; |
213 | new_value = -100; |
217 | else if (new_value > 200) |
214 | else if (new_value > 200) |
218 | new_value = 200; |
215 | new_value = 200; |
219 | } |
|
|
220 | if (new_value != align) |
216 | if (new_value != align) |
221 | { |
217 | { |
222 | align = new_value; |
218 | align = new_value; |
223 | return true; |
219 | return true; |
224 | } |
220 | } |
… | |
… | |
230 | make_align_position (int align, int window_size, int image_size) |
226 | make_align_position (int align, int window_size, int image_size) |
231 | { |
227 | { |
232 | int diff = window_size - image_size; |
228 | int diff = window_size - image_size; |
233 | int smaller = min (image_size, window_size); |
229 | int smaller = min (image_size, window_size); |
234 | |
230 | |
235 | if (align >= 0 && align <= 50) |
231 | if (align >= 0 && align <= 100) |
236 | return diff * align / 100; |
232 | return diff * align / 100; |
237 | else if (align > 50 && align <= 100) |
|
|
238 | return window_size - image_size - diff * (100 - align) / 100; |
|
|
239 | else if (align > 100 && align <= 200 ) |
233 | else if (align > 100 && align <= 200 ) |
240 | return ((align - 100) * smaller / 100) + window_size - smaller; |
234 | return ((align - 100) * smaller / 100) + window_size - smaller; |
241 | else if (align > -100 && align < 0) |
235 | else if (align >= -100 && align < 0) |
242 | return ((align + 100) * smaller / 100) - image_size; |
236 | return ((align + 100) * smaller / 100) - image_size; |
243 | return 0; |
237 | return 0; |
244 | } |
238 | } |
245 | |
239 | |
246 | static inline int |
240 | static inline int |
247 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
241 | make_clip_rectangle (int pos, int size, int target_size, int &dst_pos, int &dst_size) |
248 | { |
242 | { |
249 | int src_pos = 0; |
243 | int src_pos = 0; |
250 | dst_pos = 0; |
244 | dst_pos = pos; |
251 | dst_size = size; |
245 | dst_size = size; |
252 | if (pos < 0 && size > target_size) |
246 | if (pos < 0) |
253 | { |
247 | { |
254 | src_pos = -pos; |
248 | src_pos = -pos; |
|
|
249 | dst_pos = 0; |
255 | dst_size += pos; |
250 | dst_size += pos; |
256 | } |
251 | } |
257 | else if (pos > 0) |
|
|
258 | dst_pos = pos; |
|
|
259 | |
252 | |
260 | if (dst_pos + dst_size > target_size) |
253 | if (dst_pos + dst_size > target_size) |
261 | dst_size = target_size - dst_pos; |
254 | dst_size = target_size - dst_pos; |
262 | return src_pos; |
255 | return src_pos; |
263 | } |
256 | } |
… | |
… | |
388 | w = h = noScale; |
381 | w = h = noScale; |
389 | geom_flags |= WidthValue|HeightValue; |
382 | geom_flags |= WidthValue|HeightValue; |
390 | } |
383 | } |
391 | else if (CHECK_GEOM_OPS ("propscale")) |
384 | else if (CHECK_GEOM_OPS ("propscale")) |
392 | { |
385 | { |
393 | if (w == 0 && h == 0) |
|
|
394 | { |
|
|
395 | w = windowScale; |
|
|
396 | geom_flags |= WidthValue; |
|
|
397 | } |
|
|
398 | new_flags |= propScale; |
386 | new_flags |= propScale; |
399 | } |
387 | } |
400 | else if (CHECK_GEOM_OPS ("hscale")) |
388 | else if (CHECK_GEOM_OPS ("hscale")) |
401 | { |
389 | { |
402 | if (w == 0) w = windowScale; |
390 | if (w == 0) w = windowScale; |
… | |
… | |
424 | x = y = centerAlign; |
412 | x = y = centerAlign; |
425 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
413 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
426 | } |
414 | } |
427 | else if (CHECK_GEOM_OPS ("root")) |
415 | else if (CHECK_GEOM_OPS ("root")) |
428 | { |
416 | { |
|
|
417 | new_flags |= rootAlign; |
429 | w = h = noScale; |
418 | w = h = noScale; |
430 | x = y = rootAlign; |
|
|
431 | geom_flags |= WidthValue|HeightValue|XValue|YValue; |
419 | geom_flags |= WidthValue|HeightValue; |
432 | } |
420 | } |
433 | # undef CHECK_GEOM_OPS |
421 | # undef CHECK_GEOM_OPS |
434 | |
422 | |
435 | while (*ops != ':' && *ops != '\0') ++ops; |
423 | while (*ops != ':' && *ops != '\0') ++ops; |
436 | } /* done parsing ops */ |
424 | } /* done parsing ops */ |
… | |
… | |
457 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
445 | bgPixmap_t::get_image_geometry (int image_width, int image_height, int &w, int &h, int &x, int &y) |
458 | { |
446 | { |
459 | int target_width = target->szHint.width; |
447 | int target_width = target->szHint.width; |
460 | int target_height = target->szHint.height; |
448 | int target_height = target->szHint.height; |
461 | |
449 | |
|
|
450 | if (flags & propScale) |
|
|
451 | { |
|
|
452 | float scale = (float)target_width / image_width; |
|
|
453 | min_it (scale, (float)target_height / image_height); |
|
|
454 | w = image_width * scale + 0.5; |
|
|
455 | h = image_height * scale + 0.5; |
|
|
456 | } |
|
|
457 | else |
|
|
458 | { |
462 | w = h_scale * target_width / 100; |
459 | w = h_scale * target_width / 100; |
463 | h = v_scale * target_height / 100; |
460 | h = v_scale * target_height / 100; |
|
|
461 | } |
464 | |
462 | |
465 | if (h_align == rootAlign || v_align == rootAlign) |
463 | if (flags & rootAlign) |
466 | { |
464 | { |
467 | target->get_window_origin (x, y); |
465 | target->get_window_origin (x, y); |
468 | x = -x; |
466 | x = -x; |
469 | y = -y; |
467 | y = -y; |
470 | } |
468 | } |
471 | |
469 | else |
472 | if (h_align != rootAlign) |
470 | { |
473 | x = make_align_position (h_align, target_width, w > 0 ? w : image_width); |
471 | x = make_align_position (h_align, target_width, w > 0 ? w : image_width); |
474 | |
|
|
475 | if (v_align != rootAlign) |
|
|
476 | y = make_align_position (v_align, target_height, h > 0 ? h : image_height); |
472 | y = make_align_position (v_align, target_height, h > 0 ? h : image_height); |
|
|
473 | } |
|
|
474 | |
|
|
475 | flags &= ~sizeSensitive; |
|
|
476 | if (h_scale != 0 || v_scale != 0 |
|
|
477 | || h_align != 0 || v_align != 0 |
|
|
478 | || image_width > target_width || image_height > target_height) |
|
|
479 | flags |= sizeSensitive; |
477 | } |
480 | } |
478 | |
481 | |
479 | # ifdef HAVE_AFTERIMAGE |
482 | # ifdef HAVE_AFTERIMAGE |
480 | bool |
483 | bool |
481 | bgPixmap_t::render_image (unsigned long background_flags) |
484 | bgPixmap_t::render_image (unsigned long background_flags) |
… | |
… | |
536 | |
539 | |
537 | if (original_asim) |
540 | if (original_asim) |
538 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
541 | get_image_geometry (original_asim->width, original_asim->height, w, h, x, y); |
539 | |
542 | |
540 | if (!original_asim |
543 | if (!original_asim |
|
|
544 | || (!(flags & rootAlign) |
541 | || x >= target_width |
545 | && (x >= target_width |
542 | || y >= target_height |
546 | || y >= target_height |
543 | || (w > 0 && x + w <= 0) |
547 | || (w > 0 && x + w <= 0) |
544 | || (h > 0 && y + h <= 0)) |
548 | || (h > 0 && y + h <= 0)))) |
545 | { |
549 | { |
546 | if (background) |
550 | if (background) |
547 | { |
551 | { |
548 | new_pmap_width = background->width; |
552 | new_pmap_width = background->width; |
549 | new_pmap_height = background->height; |
553 | new_pmap_height = background->height; |
… | |
… | |
756 | int w = 0; |
760 | int w = 0; |
757 | int h = 0; |
761 | int h = 0; |
758 | |
762 | |
759 | get_image_geometry (image_width, image_height, w, h, x, y); |
763 | get_image_geometry (image_width, image_height, w, h, x, y); |
760 | |
764 | |
|
|
765 | if (!(flags & rootAlign) |
761 | if (x >= target_width |
766 | && (x >= target_width |
762 | || y >= target_height |
767 | || y >= target_height |
763 | || (w > 0 && x + w <= 0) |
768 | || (w > 0 && x + w <= 0) |
764 | || (h > 0 && y + h <= 0)) |
769 | || (h > 0 && y + h <= 0))) |
765 | return false; |
770 | return false; |
766 | |
771 | |
767 | result = pixbuf; |
772 | result = pixbuf; |
768 | |
773 | |
769 | if ((w > 0 && w != image_width) |
774 | if ((w > 0 && w != image_width) |
… | |
… | |
1039 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
1044 | flags = (flags & (~tintFlags | tintSet)) | new_flags; |
1040 | return true; |
1045 | return true; |
1041 | } |
1046 | } |
1042 | |
1047 | |
1043 | return false; |
1048 | return false; |
|
|
1049 | } |
|
|
1050 | |
|
|
1051 | bool |
|
|
1052 | bgPixmap_t::tint_pixmap (Pixmap pixmap) |
|
|
1053 | { |
|
|
1054 | Window root = target->display->root; |
|
|
1055 | Display *dpy = target->dpy; |
|
|
1056 | int window_width = target->szHint.width; |
|
|
1057 | int window_height = target->szHint.height; |
|
|
1058 | bool ret = false; |
|
|
1059 | |
|
|
1060 | if (flags & tintWholesome) |
|
|
1061 | { |
|
|
1062 | XGCValues gcv; |
|
|
1063 | GC gc; |
|
|
1064 | |
|
|
1065 | /* In this case we can tint image server-side getting significant |
|
|
1066 | * performance improvements, as we eliminate XImage transfer |
|
|
1067 | */ |
|
|
1068 | gcv.foreground = Pixel (tint); |
|
|
1069 | gcv.function = GXand; |
|
|
1070 | gcv.fill_style = FillSolid; |
|
|
1071 | gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
1072 | if (gc) |
|
|
1073 | { |
|
|
1074 | XFillRectangle (dpy, pixmap, gc, 0, 0, window_width, window_height); |
|
|
1075 | ret = true; |
|
|
1076 | XFreeGC (dpy, gc); |
|
|
1077 | } |
|
|
1078 | } |
|
|
1079 | else |
|
|
1080 | { |
|
|
1081 | # if XFT |
|
|
1082 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1083 | |
|
|
1084 | if (flags & tintSet) |
|
|
1085 | tint.get (c); |
|
|
1086 | |
|
|
1087 | if (shade > 0 && shade < 100) |
|
|
1088 | { |
|
|
1089 | c.r = (c.r * shade) / 100; |
|
|
1090 | c.g = (c.g * shade) / 100; |
|
|
1091 | c.b = (c.b * shade) / 100; |
|
|
1092 | } |
|
|
1093 | else if (shade > 100 && shade < 200) |
|
|
1094 | { |
|
|
1095 | c.r = (c.r * (200 - shade)) / 100; |
|
|
1096 | c.g = (c.g * (200 - shade)) / 100; |
|
|
1097 | c.b = (c.b * (200 - shade)) / 100; |
|
|
1098 | } |
|
|
1099 | |
|
|
1100 | XRenderPictFormat pf; |
|
|
1101 | pf.type = PictTypeDirect; |
|
|
1102 | pf.depth = 32; |
|
|
1103 | pf.direct.redMask = 0xff; |
|
|
1104 | pf.direct.greenMask = 0xff; |
|
|
1105 | pf.direct.blueMask = 0xff; |
|
|
1106 | pf.direct.alphaMask = 0xff; |
|
|
1107 | |
|
|
1108 | XRenderPictFormat *solid_format = XRenderFindFormat (dpy, |
|
|
1109 | (PictFormatType| |
|
|
1110 | PictFormatDepth| |
|
|
1111 | PictFormatRedMask| |
|
|
1112 | PictFormatGreenMask| |
|
|
1113 | PictFormatBlueMask| |
|
|
1114 | PictFormatAlphaMask), |
|
|
1115 | &pf, |
|
|
1116 | 0); |
|
|
1117 | XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); |
|
|
1118 | XRenderPictureAttributes pa; |
|
|
1119 | |
|
|
1120 | Picture back_pic = XRenderCreatePicture (dpy, pixmap, root_format, 0, &pa); |
|
|
1121 | |
|
|
1122 | pa.repeat = True; |
|
|
1123 | |
|
|
1124 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
|
|
1125 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
|
|
1126 | XFreePixmap (dpy, overlay_pmap); |
|
|
1127 | |
|
|
1128 | pa.component_alpha = True; |
|
|
1129 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
|
|
1130 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
|
|
1131 | XFreePixmap (dpy, mask_pmap); |
|
|
1132 | |
|
|
1133 | if (mask_pic && overlay_pic && back_pic) |
|
|
1134 | { |
|
|
1135 | XRenderColor mask_c; |
|
|
1136 | |
|
|
1137 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
|
|
1138 | mask_c.alpha = 0xffff; |
|
|
1139 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1140 | |
|
|
1141 | mask_c.alpha = 0; |
|
|
1142 | mask_c.red = 0xffff - c.r; |
|
|
1143 | mask_c.green = 0xffff - c.g; |
|
|
1144 | mask_c.blue = 0xffff - c.b; |
|
|
1145 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1146 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
|
|
1147 | ret = true; |
|
|
1148 | } |
|
|
1149 | |
|
|
1150 | XRenderFreePicture (dpy, mask_pic); |
|
|
1151 | XRenderFreePicture (dpy, overlay_pic); |
|
|
1152 | XRenderFreePicture (dpy, back_pic); |
|
|
1153 | # if DO_TIMING_TEST |
|
|
1154 | XSync (dpy, False); |
|
|
1155 | # endif |
|
|
1156 | # endif |
|
|
1157 | } |
|
|
1158 | |
|
|
1159 | return ret; |
1044 | } |
1160 | } |
1045 | |
1161 | |
1046 | /* make_transparency_pixmap() |
1162 | /* make_transparency_pixmap() |
1047 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
1163 | * Builds a pixmap sized the same as terminal window, with depth same as the root window |
1048 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
1164 | * that pixmap contains tiled portion of the root pixmap that is supposed to be covered by |
… | |
… | |
1178 | { |
1294 | { |
1179 | if (!need_client_side_rendering ()) |
1295 | if (!need_client_side_rendering ()) |
1180 | { |
1296 | { |
1181 | if ((flags & tintNeeded)) |
1297 | if ((flags & tintNeeded)) |
1182 | { |
1298 | { |
1183 | if (flags & tintWholesome) |
1299 | if (tint_pixmap (tiled_root_pmap)) |
1184 | { |
|
|
1185 | /* In this case we can tint image server-side getting significant |
|
|
1186 | * performance improvements, as we eliminate XImage transfer |
|
|
1187 | */ |
|
|
1188 | gcv.foreground = Pixel (tint); |
|
|
1189 | gcv.function = GXand; |
|
|
1190 | gcv.fill_style = FillSolid; |
|
|
1191 | if (gc) |
|
|
1192 | XChangeGC (dpy, gc, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
1193 | else |
|
|
1194 | gc = XCreateGC (dpy, root, GCFillStyle | GCForeground | GCFunction, &gcv); |
|
|
1195 | if (gc) |
|
|
1196 | { |
|
|
1197 | XFillRectangle (dpy, tiled_root_pmap, gc, 0, 0, window_width, window_height); |
|
|
1198 | result |= transpPmapTinted; |
1300 | result |= transpPmapTinted; |
1199 | } |
|
|
1200 | } |
|
|
1201 | else |
|
|
1202 | { |
|
|
1203 | # if XFT |
|
|
1204 | Picture back_pic = 0; |
|
|
1205 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
|
|
1206 | |
|
|
1207 | if (flags & tintSet) |
|
|
1208 | tint.get (c); |
|
|
1209 | |
|
|
1210 | if (shade > 0 && shade < 100) |
|
|
1211 | { |
|
|
1212 | c.r = (c.r * shade) / 100; |
|
|
1213 | c.g = (c.g * shade) / 100; |
|
|
1214 | c.b = (c.b * shade) / 100; |
|
|
1215 | } |
|
|
1216 | else if (shade > 100 && shade < 200) |
|
|
1217 | { |
|
|
1218 | c.r = (c.r * (200 - shade)) / 100; |
|
|
1219 | c.g = (c.g * (200 - shade)) / 100; |
|
|
1220 | c.b = (c.b * (200 - shade)) / 100; |
|
|
1221 | } |
|
|
1222 | |
|
|
1223 | XRenderPictFormat pf; |
|
|
1224 | pf.type = PictTypeDirect; |
|
|
1225 | pf.depth = 32; |
|
|
1226 | pf.direct.redMask = 0xff; |
|
|
1227 | pf.direct.greenMask = 0xff; |
|
|
1228 | pf.direct.blueMask = 0xff; |
|
|
1229 | pf.direct.alphaMask = 0xff; |
|
|
1230 | |
|
|
1231 | XRenderPictFormat *solid_format = XRenderFindFormat (dpy, |
|
|
1232 | (PictFormatType| |
|
|
1233 | PictFormatDepth| |
|
|
1234 | PictFormatRedMask| |
|
|
1235 | PictFormatGreenMask| |
|
|
1236 | PictFormatBlueMask| |
|
|
1237 | PictFormatAlphaMask), |
|
|
1238 | &pf, |
|
|
1239 | 0); |
|
|
1240 | XRenderPictFormat *root_format = XRenderFindVisualFormat (dpy, DefaultVisualOfScreen (ScreenOfDisplay (dpy, target->display->screen))); |
|
|
1241 | XRenderPictureAttributes pa ; |
|
|
1242 | |
|
|
1243 | back_pic = XRenderCreatePicture (dpy, tiled_root_pmap, root_format, 0, &pa); |
|
|
1244 | |
|
|
1245 | pa.repeat = True; |
|
|
1246 | |
|
|
1247 | Pixmap overlay_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
|
|
1248 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
|
|
1249 | XFreePixmap (dpy, overlay_pmap); |
|
|
1250 | |
|
|
1251 | pa.component_alpha = True; |
|
|
1252 | Pixmap mask_pmap = XCreatePixmap (dpy, root, 1, 1, 32); |
|
|
1253 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
|
|
1254 | XFreePixmap (dpy, mask_pmap); |
|
|
1255 | |
|
|
1256 | if (mask_pic && overlay_pic && back_pic) |
|
|
1257 | { |
|
|
1258 | XRenderColor mask_c; |
|
|
1259 | |
|
|
1260 | memset (&mask_c, (shade > 100) ? 0xFF : 0x0, sizeof (mask_c)); |
|
|
1261 | mask_c.alpha = 0xffff; |
|
|
1262 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
|
|
1263 | |
|
|
1264 | mask_c.alpha = 0; |
|
|
1265 | mask_c.red = 0xffff - c.r; |
|
|
1266 | mask_c.green = 0xffff - c.g; |
|
|
1267 | mask_c.blue = 0xffff - c.b; |
|
|
1268 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
|
|
1269 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, window_width, window_height); |
|
|
1270 | result |= transpPmapTinted; |
|
|
1271 | } |
|
|
1272 | |
|
|
1273 | XRenderFreePicture (dpy, mask_pic); |
|
|
1274 | XRenderFreePicture (dpy, overlay_pic); |
|
|
1275 | XRenderFreePicture (dpy, back_pic); |
|
|
1276 | # if DO_TIMING_TEST |
|
|
1277 | XSync (dpy, False); |
|
|
1278 | # endif |
|
|
1279 | # endif |
|
|
1280 | } |
|
|
1281 | } |
1301 | } |
1282 | } /* server side rendering completed */ |
1302 | } /* server side rendering completed */ |
1283 | |
1303 | |
1284 | if (pixmap) |
1304 | if (pixmap) |
1285 | XFreePixmap (dpy, pixmap); |
1305 | XFreePixmap (dpy, pixmap); |