@windowkit/appkit 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -1
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/backend.mm +135 -0
package/README.md
CHANGED
|
@@ -126,7 +126,7 @@ waits on the UI thread (`test/threaded-verbs.js` covers each row):
|
|
|
126
126
|
| from a worker | verbs |
|
|
127
127
|
| --- | --- |
|
|
128
128
|
| unchanged, on the calling thread | surfaces and video surfaces, every `ctx*` (`ctxDrawSymbol` included), layouts and fonts, `symbolSize`, `pasteboardTypeForMIME`, `pasteboardTypeInfo`, `contentTypeFor`, `colorSpace`, `lastInputMs` |
|
|
129
|
-
| a command, answering nothing | `initApp`, `setActivationPolicy`, `setAppName`, `activateApp`, `showWindow`, `hideWindow`, `setWindowFrame`, `setWindowTitle`, `setWindowMinMax`, `setWindowIgnoresMouseEvents`, `invalidateWindowShadow`, `destroyWindow2`, `setCursor`, `setMainMenu`, `setDockMenu`, `setDockBadge`, `cancelUserAttention`, `setStatusItem`, `setStatusItemMenu`, `removeStatusItem`, `registerDropTypes`, `setDropResponse`, `pasteboardWriteText`, `pasteboardWrite`, `pasteboardClear`, `cancelPanel`, `cancelPopUpMenu`; the test posts `postMouseEvent`, `postKeyEvent`, `postAppleEvent`, `postAccessibilityDisplayChange` |
|
|
129
|
+
| a command, answering nothing | `initApp`, `setActivationPolicy`, `setAppName`, `activateApp`, `showWindow`, `hideWindow`, `setWindowFrame`, `setWindowTitle`, `setWindowMinMax`, `setWindowFullScreen`, `setWindowZoomed`, `setWindowMiniaturized`, `setWindowIgnoresMouseEvents`, `invalidateWindowShadow`, `destroyWindow2`, `setCursor`, `setMainMenu`, `setDockMenu`, `setDockBadge`, `cancelUserAttention`, `setStatusItem`, `setStatusItemMenu`, `removeStatusItem`, `registerDropTypes`, `setDropResponse`, `pasteboardWriteText`, `pasteboardWrite`, `pasteboardClear`, `cancelPanel`, `cancelPopUpMenu`; the test posts `postMouseEvent`, `postKeyEvent`, `postAppleEvent`, `postAccessibilityDisplayChange` |
|
|
130
130
|
| a handle at the call | `createWindow2`, followed by `window-created { handle, windowNumber }`; every event about the window, input included, carries `handle`, so `ev.handle === win` |
|
|
131
131
|
| | `windowRootLayer`, allocated with the window |
|
|
132
132
|
| | `createStatusItem`: its clicks carry the handle, and it is held until `removeStatusItem` |
|
|
@@ -188,6 +188,23 @@ handshake the edge moves first while the content catches up a frame or more behi
|
|
|
188
188
|
end is how a renderer knows to run the measured layout it deferred during the drag. The
|
|
189
189
|
published window state (`getWindowFrame`, `windowState`) carries `liveResize` too.
|
|
190
190
|
|
|
191
|
+
**Window states.** What the title bar's buttons do to a window can be asked for and is
|
|
192
|
+
reported back:
|
|
193
|
+
|
|
194
|
+
- `setWindowFullScreen(win, on)` takes a window into a full-screen Space of its own and back,
|
|
195
|
+
as the green button does. The transition is bracketed by
|
|
196
|
+
`window-fullscreen { fullscreen, phase: 'begin' | 'end' }`. The begin comes before the
|
|
197
|
+
animation, so a renderer can take its window chrome away while the window grows rather
|
|
198
|
+
than after it; a transition AppKit could not finish ends with the state it started from.
|
|
199
|
+
AppKit drops a toggle during a transition, so one asked for then is applied when it ends.
|
|
200
|
+
A transition is also a live resize, and comes inside `window-live-resize`'s two ends.
|
|
201
|
+
- `setWindowZoomed(win, on)` zooms to the standard frame and back (the green button with
|
|
202
|
+
Option held). AppKit sends nothing for a zoom but the resize, so read it back then.
|
|
203
|
+
- `setWindowMiniaturized(win, on)` minimizes to the Dock and back, reported as
|
|
204
|
+
`window-miniaturize { miniaturized }`.
|
|
205
|
+
- The published window state carries `fullscreen`, `zoomed` and `miniaturized`.
|
|
206
|
+
`fullscreen` says the target from a transition's begin; `zoomed` is false while full screen.
|
|
207
|
+
|
|
191
208
|
JS never waits on the UI thread, so the worst case is the deadline. A frame that misses it
|
|
192
209
|
shows the last frame at the new size, with the root layer's `backgroundColor` in the newly
|
|
193
210
|
exposed edge. The deadline is a strict dispatch timer (`DISPATCH_TIMER_STRICT`, zero
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "Retained-mode AppKit backend for Node.js: Core Animation (CALayer) layer trees, CoreText layout and drawing, IOSurface presentation, NSMenu, and native control bezels — the macOS half of react-x11.",
|
|
5
5
|
"author": "Andrey Sidorov <andrey.sidorov@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"install": "node scripts/install.js",
|
|
44
44
|
"build": "node-gyp rebuild",
|
|
45
45
|
"demo": "node demo/demo.js",
|
|
46
|
-
"test": "node test/app-lifecycle.js && node test/animation.js && node test/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/pasteboard-write.js && node test/surface-blit.js && node test/surface-faded.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/radial-gradient.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/text-justify.js && node test/text-scale.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/notifications.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/activation-policy.js && node test/last-input.js"
|
|
46
|
+
"test": "node test/app-lifecycle.js && node test/animation.js && node test/layer-transform.js && node test/contents-gravity.js && node test/contents-center.js && node test/accessibility-display.js && node test/ignores-mouse-events.js && node test/popup-menu.js && node test/pasteboard-write.js && node test/surface-blit.js && node test/surface-faded.js && node test/image-smoothing.js && node test/surface-colorspace.js && node test/video-surface.js && node test/player.js && node test/round-rect-xy.js && node test/clip-rule.js && node test/radial-gradient.js && node test/control-bezels.js && node test/text-features.js && node test/font-from-data.js && node test/text-coverage.js && node test/text-typesetter.js && node test/text-line-height.js && node test/text-line-width.js && node test/text-justify.js && node test/text-scale.js && node test/symbols.js && node test/eventkit-permissions.js && node test/calendars.js && node test/calendar-writes.js && node test/screencolor.js && node test/notifications.js && node test/threaded.js && node test/threaded-verbs.js && node test/threaded-frames.js && node test/threaded-resize.js && node test/ending-worker.js && node test/live-resize.js && node test/window-states.js && node test/threaded-window-states.js && node test/activation-policy.js && node test/last-input.js"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"node-addon-api": "^8.3.0"
|
|
Binary file
|
|
Binary file
|
package/src/backend.mm
CHANGED
|
@@ -225,6 +225,9 @@ struct PubWindow {
|
|
|
225
225
|
double x = 0, y = 0, width = 0, height = 0, scale = 1;
|
|
226
226
|
bool visible = false, occluded = false, key = false, ignoresMouseEvents = false;
|
|
227
227
|
bool liveResize = false; // inside a live resize (windowkit/appkit#63)
|
|
228
|
+
// what the window manager did with the window: full screen in a Space of
|
|
229
|
+
// its own, zoomed to its standard frame, minimized to the Dock
|
|
230
|
+
bool fullscreen = false, zoomed = false, miniaturized = false;
|
|
228
231
|
};
|
|
229
232
|
|
|
230
233
|
struct PubScreen {
|
|
@@ -273,6 +276,21 @@ static void PublishBadge() {
|
|
|
273
276
|
gPubBadge = [badge copy];
|
|
274
277
|
}
|
|
275
278
|
|
|
279
|
+
// Full screen as the window's delegate last said it, from the start of a
|
|
280
|
+
// transition (see windowWillEnterFullScreen:). NSWindowStyleMaskFullScreen
|
|
281
|
+
// says it only once AppKit has put the window in its Space, and a renderer
|
|
282
|
+
// told at the end hides its window chrome after the animation has shown it
|
|
283
|
+
// shrinking away; nil where nothing has been said, and the mask answers.
|
|
284
|
+
static char kFullScreenKey;
|
|
285
|
+
// set from a full-screen transition's begin to its end
|
|
286
|
+
static char kFullScreenTransitionKey;
|
|
287
|
+
|
|
288
|
+
static bool WindowFullScreen(NSWindow* win) {
|
|
289
|
+
NSNumber* said = objc_getAssociatedObject(win, &kFullScreenKey);
|
|
290
|
+
if (said) return said.boolValue;
|
|
291
|
+
return (win.styleMask & NSWindowStyleMaskFullScreen) != 0;
|
|
292
|
+
}
|
|
293
|
+
|
|
276
294
|
static bool WindowOnGlass(NSWindow* win) {
|
|
277
295
|
return (win.occlusionState & NSWindowOcclusionStateVisible) != 0;
|
|
278
296
|
}
|
|
@@ -292,6 +310,14 @@ static PubWindow WindowStateOf(NSWindow* win) {
|
|
|
292
310
|
s.key = win.isKeyWindow;
|
|
293
311
|
s.ignoresMouseEvents = win.ignoresMouseEvents;
|
|
294
312
|
s.liveResize = win.inLiveResize;
|
|
313
|
+
s.fullscreen = WindowFullScreen(win);
|
|
314
|
+
s.miniaturized = win.isMiniaturized;
|
|
315
|
+
// a full-screen window fills its screen, which isZoomed would call zoomed
|
|
316
|
+
// — through the exit animation too, where `fullscreen` already says false
|
|
317
|
+
// and the window is still the screen's size
|
|
318
|
+
bool transition = objc_getAssociatedObject(win, &kFullScreenTransitionKey) != nil;
|
|
319
|
+
s.zoomed = !s.fullscreen && !s.miniaturized && !transition &&
|
|
320
|
+
(win.styleMask & NSWindowStyleMaskResizable) && win.isZoomed;
|
|
295
321
|
return s;
|
|
296
322
|
}
|
|
297
323
|
|
|
@@ -308,6 +334,9 @@ static Napi::Object WindowStateObject(Napi::Env env, const PubWindow& s) {
|
|
|
308
334
|
r.Set("key", s.key);
|
|
309
335
|
r.Set("ignoresMouseEvents", s.ignoresMouseEvents);
|
|
310
336
|
r.Set("liveResize", s.liveResize);
|
|
337
|
+
r.Set("fullscreen", s.fullscreen);
|
|
338
|
+
r.Set("zoomed", s.zoomed);
|
|
339
|
+
r.Set("miniaturized", s.miniaturized);
|
|
311
340
|
return r;
|
|
312
341
|
}
|
|
313
342
|
|
|
@@ -683,6 +712,10 @@ static Napi::Value PostAccessibilityDisplayChange(const Napi::CallbackInfo& info
|
|
|
683
712
|
@interface CALBackendDelegate : NSObject <NSWindowDelegate> {
|
|
684
713
|
@public
|
|
685
714
|
double handshakeMs_; // setResizeHandshake's budget; 0 is off
|
|
715
|
+
// setWindowFullScreen during a transition, which AppKit ignores a toggle
|
|
716
|
+
// in: -1 for none, else the state to toggle to once it ends
|
|
717
|
+
int wantFullScreen_;
|
|
718
|
+
bool inFullScreenTransition_;
|
|
686
719
|
}
|
|
687
720
|
@end
|
|
688
721
|
|
|
@@ -788,6 +821,64 @@ static void AwaitFrameForResize(NSWindow* win, double waitMs) {
|
|
|
788
821
|
ev.Bool("visible", WindowOnGlass(win));
|
|
789
822
|
CALEmit(std::move(ev));
|
|
790
823
|
}
|
|
824
|
+
// Full screen (windowkit/appkit#15's remainder): window-fullscreen
|
|
825
|
+
// { fullscreen, phase: 'begin' | 'end' }. The begin is AppKit's will-enter
|
|
826
|
+
// or will-exit, before the animation, so a renderer can take its chrome
|
|
827
|
+
// away while the window grows rather than after; the published state says
|
|
828
|
+
// the target from then on. A transition AppKit could not finish ends with
|
|
829
|
+
// the state it started from.
|
|
830
|
+
- (void)fullScreen:(NSWindow*)win is:(bool)on phase:(const char*)phase {
|
|
831
|
+
objc_setAssociatedObject(win, &kFullScreenKey, @(on), OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
832
|
+
objc_setAssociatedObject(win, &kFullScreenTransitionKey,
|
|
833
|
+
inFullScreenTransition_ ? @YES : nil,
|
|
834
|
+
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
835
|
+
PublishWindow(win);
|
|
836
|
+
CALEvent ev = WindowEvent(win, "window-fullscreen");
|
|
837
|
+
ev.Bool("fullscreen", on).Str("phase", phase);
|
|
838
|
+
CALEmit(std::move(ev));
|
|
839
|
+
}
|
|
840
|
+
- (void)endFullScreen:(NSWindow*)win is:(bool)on {
|
|
841
|
+
inFullScreenTransition_ = false;
|
|
842
|
+
[self fullScreen:win is:on phase:"end"];
|
|
843
|
+
int want = wantFullScreen_;
|
|
844
|
+
wantFullScreen_ = -1;
|
|
845
|
+
if (want >= 0 && (bool)want != on) [win toggleFullScreen:nil];
|
|
846
|
+
}
|
|
847
|
+
- (void)windowWillEnterFullScreen:(NSNotification*)n {
|
|
848
|
+
inFullScreenTransition_ = true;
|
|
849
|
+
[self fullScreen:n.object is:true phase:"begin"];
|
|
850
|
+
}
|
|
851
|
+
- (void)windowDidEnterFullScreen:(NSNotification*)n {
|
|
852
|
+
[self endFullScreen:n.object is:true];
|
|
853
|
+
}
|
|
854
|
+
- (void)windowDidFailToEnterFullScreen:(NSWindow*)win {
|
|
855
|
+
[self endFullScreen:win is:false];
|
|
856
|
+
}
|
|
857
|
+
- (void)windowWillExitFullScreen:(NSNotification*)n {
|
|
858
|
+
inFullScreenTransition_ = true;
|
|
859
|
+
[self fullScreen:n.object is:false phase:"begin"];
|
|
860
|
+
}
|
|
861
|
+
- (void)windowDidExitFullScreen:(NSNotification*)n {
|
|
862
|
+
[self endFullScreen:n.object is:false];
|
|
863
|
+
}
|
|
864
|
+
- (void)windowDidFailToExitFullScreen:(NSWindow*)win {
|
|
865
|
+
[self endFullScreen:win is:true];
|
|
866
|
+
}
|
|
867
|
+
// Minimized to the Dock and back: window-miniaturize { miniaturized }.
|
|
868
|
+
- (void)windowDidMiniaturize:(NSNotification*)n {
|
|
869
|
+
NSWindow* win = n.object;
|
|
870
|
+
PublishWindow(win);
|
|
871
|
+
CALEvent ev = WindowEvent(win, "window-miniaturize");
|
|
872
|
+
ev.Bool("miniaturized", true);
|
|
873
|
+
CALEmit(std::move(ev));
|
|
874
|
+
}
|
|
875
|
+
- (void)windowDidDeminiaturize:(NSNotification*)n {
|
|
876
|
+
NSWindow* win = n.object;
|
|
877
|
+
PublishWindow(win);
|
|
878
|
+
CALEvent ev = WindowEvent(win, "window-miniaturize");
|
|
879
|
+
ev.Bool("miniaturized", false);
|
|
880
|
+
CALEmit(std::move(ev));
|
|
881
|
+
}
|
|
791
882
|
- (void)windowDidChangeBackingProperties:(NSNotification*)n {
|
|
792
883
|
NSWindow* win = n.object;
|
|
793
884
|
PublishWindow(win);
|
|
@@ -996,6 +1087,7 @@ static NSWindow* BuildWindow(const WindowSpec& spec) {
|
|
|
996
1087
|
}
|
|
997
1088
|
|
|
998
1089
|
CALBackendDelegate* delegate = [[CALBackendDelegate alloc] init];
|
|
1090
|
+
delegate->wantFullScreen_ = -1;
|
|
999
1091
|
win.delegate = delegate;
|
|
1000
1092
|
objc_setAssociatedObject(win, &kDelegateKey, delegate,
|
|
1001
1093
|
OBJC_ASSOCIATION_RETAIN_NONATOMIC);
|
|
@@ -1169,6 +1261,46 @@ static Napi::Value WindowNumberAtPoint(const Napi::CallbackInfo& info) {
|
|
|
1169
1261
|
});
|
|
1170
1262
|
}
|
|
1171
1263
|
|
|
1264
|
+
// setWindowFullScreen(win, on) — into or out of a full-screen Space, as the
|
|
1265
|
+
// title bar's green button takes it; window-fullscreen reports the
|
|
1266
|
+
// transition. A no-op where the window already is, and one asked for during
|
|
1267
|
+
// a transition is applied when it ends, since AppKit drops a toggle then.
|
|
1268
|
+
static Napi::Value SetWindowFullScreen(const Napi::CallbackInfo& info) {
|
|
1269
|
+
bool on = info.Length() > 1 && info[1].ToBoolean().Value();
|
|
1270
|
+
OnWindow(info[0], ^(NSWindow* win) {
|
|
1271
|
+
CALBackendDelegate* d = objc_getAssociatedObject(win, &kDelegateKey);
|
|
1272
|
+
if (d && d->inFullScreenTransition_) {
|
|
1273
|
+
d->wantFullScreen_ = on;
|
|
1274
|
+
return;
|
|
1275
|
+
}
|
|
1276
|
+
if (WindowFullScreen(win) != on) [win toggleFullScreen:nil];
|
|
1277
|
+
});
|
|
1278
|
+
return info.Env().Undefined();
|
|
1279
|
+
}
|
|
1280
|
+
|
|
1281
|
+
// setWindowZoomed(win, on) — to the window's standard frame and back, the
|
|
1282
|
+
// green button with Option held. AppKit sends no notification for a zoom,
|
|
1283
|
+
// only the resize, so the published `zoomed` is read back at each one.
|
|
1284
|
+
static Napi::Value SetWindowZoomed(const Napi::CallbackInfo& info) {
|
|
1285
|
+
bool on = info.Length() > 1 && info[1].ToBoolean().Value();
|
|
1286
|
+
OnWindow(info[0], ^(NSWindow* win) {
|
|
1287
|
+
if (WindowFullScreen(win) || win.isMiniaturized) return;
|
|
1288
|
+
if ((bool)win.isZoomed != on) [win zoom:nil];
|
|
1289
|
+
});
|
|
1290
|
+
return info.Env().Undefined();
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// setWindowMiniaturized(win, on) — to the Dock and back; window-miniaturize
|
|
1294
|
+
// reports it.
|
|
1295
|
+
static Napi::Value SetWindowMiniaturized(const Napi::CallbackInfo& info) {
|
|
1296
|
+
bool on = info.Length() > 1 && info[1].ToBoolean().Value();
|
|
1297
|
+
OnWindow(info[0], ^(NSWindow* win) {
|
|
1298
|
+
if (on && !win.isMiniaturized) [win miniaturize:nil];
|
|
1299
|
+
else if (!on && win.isMiniaturized) [win deminiaturize:nil];
|
|
1300
|
+
});
|
|
1301
|
+
return info.Env().Undefined();
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1172
1304
|
static Napi::Value SetWindowMinMax(const Napi::CallbackInfo& info) {
|
|
1173
1305
|
Napi::Object o = info[1].As<Napi::Object>();
|
|
1174
1306
|
bool setMin = o.Has("minWidth") || o.Has("minHeight");
|
|
@@ -7988,6 +8120,9 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
7988
8120
|
BFN("getWindowFrame", GetWindowFrame);
|
|
7989
8121
|
BFN("windowState", WindowStateFn);
|
|
7990
8122
|
BFN("setWindowMinMax", SetWindowMinMax);
|
|
8123
|
+
BFN("setWindowFullScreen", SetWindowFullScreen);
|
|
8124
|
+
BFN("setWindowZoomed", SetWindowZoomed);
|
|
8125
|
+
BFN("setWindowMiniaturized", SetWindowMiniaturized);
|
|
7991
8126
|
BFN("setResizeHandshake", SetResizeHandshake);
|
|
7992
8127
|
BFN("destroyWindow2", DestroyWindow2);
|
|
7993
8128
|
BFN("invalidateWindowShadow", InvalidateWindowShadow);
|