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) 2005-2008 Marc Lehmann <pcg@goof.com> |
6 | * Copyright (c) 2005-2008 Marc Lehmann <schmorp@schmorp.de> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
7 | * Copyright (c) 2007 Sasha Vasko <sasha@aftercode.net> |
8 | * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> |
8 | * Copyright (c) 2010 Emanuele Giaquinta <e.giaquinta@glauco.it> |
9 | * |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify |
10 | * This program is free software; you can redistribute it and/or modify |
11 | * it under the terms of the GNU General Public License as published by |
11 | * it under the terms of the GNU General Public License as published by |
… | |
… | |
943 | bg_flags |= BG_NEEDS_BLUR; |
943 | bg_flags |= BG_NEEDS_BLUR; |
944 | |
944 | |
945 | return changed; |
945 | return changed; |
946 | } |
946 | } |
947 | |
947 | |
948 | static inline unsigned long |
948 | void |
949 | compute_tint_shade_flags (rxvt_color *tint, int shade) |
949 | rxvt_term::set_tint_shade_flags () |
950 | { |
950 | { |
951 | unsigned long flags = 0; |
|
|
952 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
951 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
953 | bool has_shade = shade != 100; |
952 | bool has_shade = shade != 100; |
954 | |
953 | |
955 | if (tint) |
954 | bg_flags &= ~BG_TINT_FLAGS; |
|
|
955 | |
|
|
956 | if (bg_flags & BG_TINT_SET) |
956 | { |
957 | { |
957 | tint->get (c); |
958 | tint.get (c); |
958 | if (!has_shade |
959 | if (!has_shade |
959 | && (c.r <= 0x00ff || c.r >= 0xff00) |
960 | && (c.r <= 0x00ff || c.r >= 0xff00) |
960 | && (c.g <= 0x00ff || c.g >= 0xff00) |
961 | && (c.g <= 0x00ff || c.g >= 0xff00) |
961 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
962 | && (c.b <= 0x00ff || c.b >= 0xff00)) |
962 | flags |= rxvt_term::BG_TINT_BITAND; |
963 | bg_flags |= BG_TINT_BITAND; |
963 | } |
964 | } |
964 | |
965 | |
965 | if (has_shade || tint) |
966 | if (has_shade || (bg_flags & BG_TINT_SET)) |
966 | flags |= rxvt_term::BG_NEEDS_TINT; |
967 | bg_flags |= BG_NEEDS_TINT; |
967 | |
|
|
968 | return flags; |
|
|
969 | } |
968 | } |
970 | |
969 | |
971 | bool |
970 | bool |
972 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
971 | rxvt_term::bg_set_tint (rxvt_color &new_tint) |
973 | { |
972 | { |
974 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
973 | if (!(bg_flags & BG_TINT_SET) || tint != new_tint) |
975 | { |
974 | { |
976 | unsigned long new_flags = compute_tint_shade_flags (&new_tint, shade); |
|
|
977 | tint = new_tint; |
975 | tint = new_tint; |
978 | bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags | BG_TINT_SET; |
976 | bg_flags |= BG_TINT_SET; |
|
|
977 | set_tint_shade_flags (); |
979 | return true; |
978 | return true; |
980 | } |
979 | } |
981 | |
980 | |
982 | return false; |
981 | return false; |
983 | } |
982 | } |
… | |
… | |
991 | if (new_shade < 0) |
990 | if (new_shade < 0) |
992 | new_shade = 200 - (100 + new_shade); |
991 | new_shade = 200 - (100 + new_shade); |
993 | |
992 | |
994 | if (new_shade != shade) |
993 | if (new_shade != shade) |
995 | { |
994 | { |
996 | unsigned long new_flags = compute_tint_shade_flags ((bg_flags & BG_TINT_SET) ? &tint : NULL, new_shade); |
|
|
997 | shade = new_shade; |
995 | shade = new_shade; |
998 | bg_flags = (bg_flags & ~BG_TINT_FLAGS) | new_flags; |
996 | set_tint_shade_flags (); |
999 | return true; |
997 | return true; |
1000 | } |
998 | } |
1001 | |
999 | |
1002 | return false; |
1000 | return false; |
1003 | } |
1001 | } |
… | |
… | |
1113 | } |
1111 | } |
1114 | } |
1112 | } |
1115 | else |
1113 | else |
1116 | { |
1114 | { |
1117 | # if XRENDER |
1115 | # if XRENDER |
1118 | rgba c (rgba::MAX_CC,rgba::MAX_CC,rgba::MAX_CC); |
1116 | rgba c (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC); |
1119 | |
1117 | |
1120 | if (bg_flags & BG_TINT_SET) |
1118 | if (bg_flags & BG_TINT_SET) |
1121 | tint.get (c); |
1119 | tint.get (c); |
1122 | |
1120 | |
1123 | if (shade <= 100) |
1121 | if (shade <= 100) |
1124 | { |
1122 | { |
1125 | c.r = (c.r * shade) / 100; |
1123 | c.r = c.r * shade / 100; |
1126 | c.g = (c.g * shade) / 100; |
1124 | c.g = c.g * shade / 100; |
1127 | c.b = (c.b * shade) / 100; |
1125 | c.b = c.b * shade / 100; |
1128 | } |
1126 | } |
1129 | else |
1127 | else |
1130 | { |
1128 | { |
1131 | c.r = (c.r * (200 - shade)) / 100; |
1129 | c.r = c.r * (200 - shade) / 100; |
1132 | c.g = (c.g * (200 - shade)) / 100; |
1130 | c.g = c.g * (200 - shade) / 100; |
1133 | c.b = (c.b * (200 - shade)) / 100; |
1131 | c.b = c.b * (200 - shade) / 100; |
1134 | } |
1132 | } |
1135 | |
1133 | |
1136 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1134 | XRenderPictFormat *solid_format = XRenderFindStandardFormat (dpy, PictStandardARGB32); |
1137 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1135 | XRenderPictFormat *format = XRenderFindVisualFormat (dpy, visual); |
1138 | XRenderPictureAttributes pa; |
1136 | XRenderPictureAttributes pa; |
… | |
… | |
1145 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1143 | Picture overlay_pic = XRenderCreatePicture (dpy, overlay_pmap, solid_format, CPRepeat, &pa); |
1146 | XFreePixmap (dpy, overlay_pmap); |
1144 | XFreePixmap (dpy, overlay_pmap); |
1147 | |
1145 | |
1148 | pa.component_alpha = True; |
1146 | pa.component_alpha = True; |
1149 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1147 | Pixmap mask_pmap = XCreatePixmap (dpy, pixmap, 1, 1, 32); |
1150 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat|CPComponentAlpha, &pa); |
1148 | Picture mask_pic = XRenderCreatePicture (dpy, mask_pmap, solid_format, CPRepeat | CPComponentAlpha, &pa); |
1151 | XFreePixmap (dpy, mask_pmap); |
1149 | XFreePixmap (dpy, mask_pmap); |
1152 | |
1150 | |
1153 | if (mask_pic && overlay_pic && back_pic) |
1151 | if (mask_pic && overlay_pic && back_pic) |
1154 | { |
1152 | { |
1155 | XRenderColor mask_c; |
1153 | XRenderColor mask_c; |
1156 | |
1154 | |
1157 | mask_c.red = mask_c.green = mask_c.blue = 0; |
|
|
1158 | mask_c.alpha = 0xffff; |
1155 | mask_c.alpha = 0xffff; |
|
|
1156 | mask_c.red = |
|
|
1157 | mask_c.green = |
|
|
1158 | mask_c.blue = 0; |
1159 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1159 | XRenderFillRectangle (dpy, PictOpSrc, overlay_pic, &mask_c, 0, 0, 1, 1); |
1160 | |
1160 | |
1161 | mask_c.alpha = 0; |
1161 | mask_c.alpha = 0; |
1162 | mask_c.red = 0xffff - c.r; |
1162 | mask_c.red = 0xffff - c.r; |
1163 | mask_c.green = 0xffff - c.g; |
1163 | mask_c.green = 0xffff - c.g; |
1164 | mask_c.blue = 0xffff - c.b; |
1164 | mask_c.blue = 0xffff - c.b; |
1165 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1165 | XRenderFillRectangle (dpy, PictOpSrc, mask_pic, &mask_c, 0, 0, 1, 1); |
1166 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1166 | XRenderComposite (dpy, PictOpOver, overlay_pic, mask_pic, back_pic, 0, 0, 0, 0, 0, 0, width, height); |
1167 | |
1167 | |
1168 | if (shade > 100) |
1168 | if (shade > 100) |
1169 | { |
1169 | { |
… | |
… | |
1184 | } |
1184 | } |
1185 | |
1185 | |
1186 | return ret; |
1186 | return ret; |
1187 | } |
1187 | } |
1188 | |
1188 | |
1189 | /* make_transparency_pixmap() |
1189 | /* |
1190 | * Builds a pixmap of the same size as the terminal window that contains |
1190 | * Builds a pixmap of the same size as the terminal window that contains |
1191 | * the tiled portion of the root pixmap that is supposed to be covered by |
1191 | * the tiled portion of the root pixmap that is supposed to be covered by |
1192 | * our window. |
1192 | * our window. |
1193 | */ |
1193 | */ |
1194 | unsigned long |
1194 | unsigned long |