-
Notifications
You must be signed in to change notification settings - Fork 1
/
ns-alpha-background.patch
266 lines (238 loc) · 10.1 KB
/
ns-alpha-background.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
diff --git a/src/macfont.m b/src/macfont.m
index e3b3d40df43..862ccaa66d0 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -2994,9 +2994,14 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
CG_SET_FILL_COLOR_WITH_FACE_FOREGROUND (context, face);
else
CG_SET_FILL_COLOR_WITH_FRAME_CURSOR (context, f);
+ CGContextSetAlpha (context, 1);
}
else
- CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face);
+ {
+ CGContextSetAlpha (context, f->alpha_background);
+ CG_SET_FILL_COLOR_WITH_FACE_BACKGROUND (context, face);
+ }
+ CGContextClearRect (context, background_rect);
CGContextFillRects (context, &background_rect, 1);
}
@@ -3005,6 +3010,7 @@ So we use CTFontDescriptorCreateMatchingFontDescriptor (no
CGAffineTransform atfm;
CGContextScaleCTM (context, 1, -1);
+ CGContextSetAlpha (context, 1);
if (s->hl == DRAW_CURSOR)
{
if (face && (NS_FACE_BACKGROUND (face)
diff --git a/src/nsfns.m b/src/nsfns.m
index c521140bd68..3d1ac5c01eb 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -301,7 +301,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
struct face *face;
NSColor *col;
NSView *view = FRAME_NS_VIEW (f);
- EmacsCGFloat alpha;
+ EmacsCGFloat alpha = f->alpha_background;
block_input ();
if (ns_lisp_to_color (arg, &col))
@@ -316,11 +316,10 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
f->output_data.ns->background_color = col;
FRAME_BACKGROUND_PIXEL (f) = [col unsignedLong];
- alpha = [col alphaComponent];
if (view != nil)
{
- [[view window] setBackgroundColor: col];
+ [[view window] setBackgroundColor: [col colorWithAlphaComponent: alpha]];
if (alpha != (EmacsCGFloat) 1.0)
[[view window] setOpaque: NO];
@@ -330,10 +329,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
face = FRAME_DEFAULT_FACE (f);
if (face)
{
- col = [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)];
- face->background = [[col colorWithAlphaComponent: alpha]
- unsignedLong];
-
+ face->background = [col unsignedLong];
update_face_from_frame_parameter (f, Qbackground_color, arg);
}
@@ -346,6 +342,36 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
unblock_input ();
}
+static void
+ns_set_alpha_background (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+{
+ NSView *view = FRAME_NS_VIEW (f);
+ double alpha = 1.0;
+
+ if (NILP (arg))
+ alpha = 1.0;
+ else if (FLOATP (arg))
+ {
+ alpha = XFLOAT_DATA (arg);
+ if (! (0 <= alpha && alpha <= 1.0))
+ args_out_of_range (make_float (0.0), make_float (1.0));
+ }
+ else if (FIXNUMP (arg))
+ {
+ EMACS_INT ialpha = XFIXNUM (arg);
+ if (! (0 <= ialpha && ialpha <= 100))
+ args_out_of_range (make_fixnum (0), make_fixnum (100));
+ alpha = ialpha / 100.0;
+ }
+ else
+ wrong_type_argument (Qnumberp, arg);
+
+ f->alpha_background = alpha;
+ [[view window] setBackgroundColor: [f->output_data.ns->background_color
+ colorWithAlphaComponent: alpha]];
+ recompute_basic_faces (f);
+ SET_FRAME_GARBAGED (f);
+}
static void
ns_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
@@ -1107,7 +1133,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
ns_set_z_group,
0, /* x_set_override_redirect */
gui_set_no_special_glyphs,
- gui_set_alpha_background,
+ ns_set_alpha_background,
NULL,
#ifdef NS_IMPL_COCOA
ns_set_appearance,
diff --git a/src/nsterm.m b/src/nsterm.m
index f26cdb17903..182aa3ff74f 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2627,8 +2627,9 @@ Hide the window (X11 semantics)
block_input ();
ns_focus (f, &r, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
- (FACE_FROM_ID (f, DEFAULT_FACE_ID))] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
+ (FACE_FROM_ID (f, DEFAULT_FACE_ID))]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (r);
ns_unfocus (f);
@@ -2656,7 +2657,7 @@ Hide the window (X11 semantics)
r = NSIntersectionRect (r, [view frame]);
ns_focus (f, &r, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (r);
@@ -2760,7 +2761,7 @@ Hide the window (X11 semantics)
return;
ns_focus (f, NULL, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (NSMakeRect (0, margin, width, border));
NSRectFill (NSMakeRect (0, 0, border, height));
NSRectFill (NSMakeRect (0, margin, width, border));
@@ -2812,7 +2813,8 @@ Hide the window (X11 semantics)
NSRect r = NSMakeRect (0, y, FRAME_PIXEL_WIDTH (f), height);
ns_focus (f, &r, 1);
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (NSMakeRect (0, y, width, height));
NSRectFill (NSMakeRect (FRAME_PIXEL_WIDTH (f) - width,
y, width, height));
@@ -2977,7 +2979,8 @@ Hide the window (X11 semantics)
{
NSTRACE_RECT ("clearRect", clearRect);
- [[NSColor colorWithUnsignedLong:face->background] set];
+ [[[NSColor colorWithUnsignedLong:face->background]
+ colorWithAlphaComponent: f->alpha_background] set];
NSRectFill (clearRect);
}
@@ -3008,7 +3011,7 @@ Hide the window (X11 semantics)
else
bm_color = f->output_data.ns->cursor_color;
- [bm_color set];
+ [[bm_color colorWithAlphaComponent:f->alpha_background] set];
[bmp fill];
[bmp release];
@@ -3797,7 +3800,8 @@ Function modeled after x_draw_glyph_string_box ().
if (s->face->box == FACE_SIMPLE_BOX && s->face->box_color)
{
ns_draw_box (r, abs (hthickness), abs (vthickness),
- [NSColor colorWithUnsignedLong:face->box_color],
+ [[NSColor colorWithUnsignedLong:face->box_color]
+ colorWithAlphaComponent: s->f->alpha_background],
left_p, right_p);
}
else
@@ -3842,7 +3846,8 @@ Function modeled after x_draw_glyph_string_box ().
{
if (s->hl != DRAW_CURSOR)
[(NS_FACE_BACKGROUND (face) != 0
- ? [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ ? [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: s->f->alpha_background]
: FRAME_BACKGROUND_COLOR (s->f)) set];
else if (face && (NS_FACE_BACKGROUND (face)
== [(NSColor *) FRAME_CURSOR_COLOR (s->f)
@@ -3981,7 +3986,8 @@ Function modeled after x_draw_glyph_string_box ().
otherwise, since we composite the image under NS (instead of mucking
with its background color), we must clear just the image area. */
- [[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)] set];
+ [[[NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: s->f->alpha_background] set];
if (bg_height > s->slice.height || s->img->hmargin || s->img->vmargin
|| s->img->mask || s->img->pixmap == 0 || s->width != s->background_width)
@@ -4051,7 +4057,8 @@ Function modeled after x_draw_glyph_string_box ().
if (s->hl == DRAW_CURSOR)
{
[FRAME_CURSOR_COLOR (s->f) set];
- tdCol = [NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)];
+ tdCol = [[NSColor colorWithUnsignedLong: NS_FACE_BACKGROUND (face)]
+ colorWithAlphaComponent: s->f->alpha_background];
}
else
tdCol = [NSColor colorWithUnsignedLong: NS_FACE_FOREGROUND (face)];
@@ -4144,10 +4151,12 @@ Function modeled after x_draw_glyph_string_box ().
face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
prepare_face_for_display (s->f, face);
- [[NSColor colorWithUnsignedLong: face->background] set];
+ [[[NSColor colorWithUnsignedLong: face->background]
+ colorWithAlphaComponent: s->f->alpha_background] set];
}
else
- [[NSColor colorWithUnsignedLong: s->face->background] set];
+ [[[NSColor colorWithUnsignedLong: s->face->background]
+ colorWithAlphaComponent: s->f->alpha_background] set];
NSRectFill (NSMakeRect (x, y, w, h));
}
}
@@ -4178,7 +4187,8 @@ Function modeled after x_draw_glyph_string_box ().
else if (s->stippled_p)
[[dpyinfo->bitmaps[s->face->stipple - 1].img stippleMask] set];
else
- [[NSColor colorWithUnsignedLong: s->face->background] set];
+ [[[NSColor colorWithUnsignedLong: s->face->background]
+ colorWithAlphaComponent: s->f->alpha_background] set];
NSRectFill (NSMakeRect (x, s->y, background_width, s->height));
}
@@ -8546,8 +8556,9 @@ - (void)toggleFullScreen: (id)sender
}
[w setContentView:[fw contentView]];
- [w setBackgroundColor: col];
- if ([col alphaComponent] != (EmacsCGFloat) 1.0)
+ [w setBackgroundColor: [col colorWithAlphaComponent:
+ f->alpha_background]];
+ if (f->alpha_background != (EmacsCGFloat) 1.0)
[w setOpaque: NO];
f->border_width = [w borderWidth];
@@ -9284,9 +9295,10 @@ - (instancetype) initWithEmacsFrame: (struct frame *) f
f->border_width = [self borderWidth];
col = [NSColor colorWithUnsignedLong:NS_FACE_BACKGROUND
- (FACE_FROM_ID (f, DEFAULT_FACE_ID))];
- [self setBackgroundColor:col];
- if ([col alphaComponent] != (EmacsCGFloat) 1.0)
+ (FACE_FROM_ID (f, DEFAULT_FACE_ID))];
+ [self setBackgroundColor:
+ [col colorWithAlphaComponent:f->alpha_background]];
+ if (f->alpha_background != (EmacsCGFloat) 1.0)
[self setOpaque:NO];
/* toolbar support */