@windowkit/appkit 0.5.0 → 0.6.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 +28 -2
- package/package.json +2 -2
- package/prebuilds/darwin-arm64/calayers.node +0 -0
- package/prebuilds/darwin-x64/calayers.node +0 -0
- package/src/addon.mm +22 -3
- package/src/backend.mm +49 -2
package/README.md
CHANGED
|
@@ -182,9 +182,19 @@ be additive; for that there is `presentationValue`.
|
|
|
182
182
|
value the render server is showing for that key path right now, animations applied: a
|
|
183
183
|
number, a point or size as `[x, y]`, a rect as `[x, y, w, h]`, a colour as `[r, g, b, a]`, a
|
|
184
184
|
transform as its sixteen components; `null` before the layer's first commit. A colour comes
|
|
185
|
-
back in
|
|
185
|
+
back in sRGB, the space it went in, so it can be handed straight back as a `from` —
|
|
186
186
|
but CA interpolates in the display's space, so the components' midpoint there is not this
|
|
187
|
-
space's midpoint.
|
|
187
|
+
space's midpoint.
|
|
188
|
+
|
|
189
|
+
**`native.colorSpace()`** — `'sRGB'`: the space every colour crossing this bridge is in —
|
|
190
|
+
a layer's `backgroundColor`, `borderColor` and `shadowColor`, a shape's fill and stroke,
|
|
191
|
+
a gradient's stops, an animation's `from`/`to`, a presentation value, a text span's ink
|
|
192
|
+
and the surfaces `createSurface` makes. One space, so a colour set on a layer and the
|
|
193
|
+
same colour rastered into a surface composite to the same pixels. (Before 0.6 the layer
|
|
194
|
+
half was Generic RGB, which the compositor converts on its way to the display: `#dbe7f4`
|
|
195
|
+
on a layer showed as (228, 236, 245) beside a surface's (219, 231, 244), and a colour
|
|
196
|
+
animation landed on a model value that did not match its own `to`. A caller that draws
|
|
197
|
+
both ways — react-x11's layer promotion — feature-detects the verb.) `speed: 0, timeOffset: t` plus a read is how a curve is sampled without
|
|
188
198
|
waiting for it, which is how `test/animation.js` checks every curve above.
|
|
189
199
|
|
|
190
200
|
**The end of an animation.** With an `id`, the animation's delegate forwards
|
|
@@ -407,6 +417,22 @@ native.beginDrag(win, {
|
|
|
407
417
|
default — at its own size unless `imageWidth` / `imageHeight` say otherwise.
|
|
408
418
|
A drop on one of our own windows arrives through the destination events of
|
|
409
419
|
that window with `local: true` and the source's `sourceWindowNumber`.
|
|
420
|
+
- **A preview window of your own is the window under the pointer.** A
|
|
421
|
+
renderer that draws its drag preview as a live window of its own — a
|
|
422
|
+
borderless popup following the pointer, instead of the session's image —
|
|
423
|
+
has put a window between the pointer and every destination, and the window
|
|
424
|
+
server finds that one first. Registering it for no dragged types is not a
|
|
425
|
+
way past it: the drag then simply has no destination, and the window
|
|
426
|
+
beneath never hears of it; transparent pixels pass no hit either.
|
|
427
|
+
`createWindow2({ …, ignoresMouseEvents: true })`, or
|
|
428
|
+
`setWindowIgnoresMouseEvents(win, flag)` on a live window, makes it one
|
|
429
|
+
the pointer passes through, so a click or a drag reaches whatever is
|
|
430
|
+
beneath; `getWindowFrame` reports the flag beside `visible` and `key`.
|
|
431
|
+
`windowNumberAtPoint(x, y, belowWindowNumber?)` is the window server's own
|
|
432
|
+
answer to which window a mouse-down at a global top-left point would
|
|
433
|
+
reach, any application's, or 0 — the question the flag changes — and
|
|
434
|
+
handing an answer back as `belowWindowNumber` looks beneath it, which is
|
|
435
|
+
how a test finds its own windows under another application's.
|
|
410
436
|
- **`postDragEvent(win, phase, { x, y, items, operations, local })`** drives
|
|
411
437
|
the destination methods with a dragging info of the bridge's own over a
|
|
412
438
|
private pasteboard — what `postMouseEvent` is to clicks. `'enter'` and
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@windowkit/appkit",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.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/accessibility-display.js"
|
|
46
|
+
"test": "node test/app-lifecycle.js && node test/animation.js && node test/accessibility-display.js && node test/ignores-mouse-events.js"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
49
|
"node-addon-api": "^8.3.0"
|
|
Binary file
|
|
Binary file
|
package/src/addon.mm
CHANGED
|
@@ -44,13 +44,29 @@ static NSString* StrOr(Napi::Object o, const char* k, NSString* d) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
// [r,g,b] or [r,g,b,a], components 0..1 — caller owns the returned color.
|
|
47
|
+
//
|
|
48
|
+
// sRGB, like every other colour this bridge makes: the surfaces
|
|
49
|
+
// (createSurface, backend.mm), a text span's ink, an animation's from/to
|
|
50
|
+
// (BMakeColor). This one used to be Generic RGB, which the compositor
|
|
51
|
+
// converts on its way to the display, so a layer's backgroundColor came out
|
|
52
|
+
// paler than the same colour rastered into a surface — #dbe7f4 showed as
|
|
53
|
+
// (228, 236, 245) beside a bitmap's (219, 231, 244) — and a colour animation
|
|
54
|
+
// landed on a model value that did not match its own `to`. One space
|
|
55
|
+
// everywhere, and `colorSpace()` says so.
|
|
47
56
|
static CGColorRef MakeColor(Napi::Value v) {
|
|
48
57
|
Napi::Array a = v.As<Napi::Array>();
|
|
49
58
|
double r = a.Get(0u).As<Napi::Number>().DoubleValue();
|
|
50
59
|
double g = a.Get(1u).As<Napi::Number>().DoubleValue();
|
|
51
60
|
double b = a.Get(2u).As<Napi::Number>().DoubleValue();
|
|
52
61
|
double al = a.Length() > 3 ? a.Get(3u).As<Napi::Number>().DoubleValue() : 1.0;
|
|
53
|
-
return
|
|
62
|
+
return CGColorCreateSRGB(r, g, b, al);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// The colour space every colour crossing this bridge is in — layer
|
|
66
|
+
// properties, animation values, presentation values, surfaces. A caller
|
|
67
|
+
// that rasters in sRGB can feature-detect that a layer colour will match.
|
|
68
|
+
static Napi::Value ColorSpace(const Napi::CallbackInfo& info) {
|
|
69
|
+
return Napi::String::New(info.Env(), "sRGB");
|
|
54
70
|
}
|
|
55
71
|
|
|
56
72
|
static CGPoint PointFrom(Napi::Value v) {
|
|
@@ -863,7 +879,9 @@ static Napi::Value JSFromCAValue(Napi::Env env, id v) {
|
|
|
863
879
|
}
|
|
864
880
|
if (CFGetTypeID((__bridge CFTypeRef)v) == CGColorGetTypeID()) {
|
|
865
881
|
CGColorRef c = (__bridge CGColorRef)v;
|
|
866
|
-
|
|
882
|
+
// read back in the space colours go in by (MakeColor), so a value that
|
|
883
|
+
// went out comes back as the same numbers
|
|
884
|
+
CGColorSpaceRef rgb = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
|
|
867
885
|
CGColorRef conv = CGColorCreateCopyByMatchingToColorSpace(rgb, kCGRenderingIntentDefault, c, NULL);
|
|
868
886
|
CGColorSpaceRelease(rgb);
|
|
869
887
|
CGColorRef src = conv ? conv : c;
|
|
@@ -960,7 +978,7 @@ static NSAttributedString* AttrString(Napi::Object o, CGColorRef* outColor) {
|
|
|
960
978
|
NSString* fontName = StrOr(o, "fontName", @"Helvetica");
|
|
961
979
|
double fontSize = NumOr(o, "fontSize", 14);
|
|
962
980
|
CGColorRef color = o.Has("color") ? MakeColor(o.Get("color"))
|
|
963
|
-
:
|
|
981
|
+
: CGColorCreateSRGB(0, 0, 0, 1);
|
|
964
982
|
CTFontRef font = CTFontCreateWithName((__bridge CFStringRef)fontName, fontSize, NULL);
|
|
965
983
|
NSDictionary* attrs = @{
|
|
966
984
|
(__bridge id)kCTFontAttributeName : (__bridge id)font,
|
|
@@ -1295,6 +1313,7 @@ static Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
|
1295
1313
|
FN("txBegin", TxBegin);
|
|
1296
1314
|
FN("txCommit", TxCommit);
|
|
1297
1315
|
FN("presentationValue", PresentationValue);
|
|
1316
|
+
FN("colorSpace", ColorSpace);
|
|
1298
1317
|
FN("hitTest", HitTest);
|
|
1299
1318
|
FN("measureText", MeasureText);
|
|
1300
1319
|
FN("createTextImage", CreateTextImage);
|
package/src/backend.mm
CHANGED
|
@@ -503,6 +503,7 @@ static char kDelegateKey;
|
|
|
503
503
|
// title, kind, // 'normal' | 'popup' | 'borderless'
|
|
504
504
|
// x, y, // top-left global, points (optional)
|
|
505
505
|
// resizable, opaque, hasShadow, level, // level: 'normal'|'popup'|'floating'
|
|
506
|
+
// ignoresMouseEvents, // the pointer passes through (below)
|
|
506
507
|
// backgroundColor }) // [r,g,b,a] or absent
|
|
507
508
|
static Napi::Value CreateWindow2(const Napi::CallbackInfo& info) {
|
|
508
509
|
Napi::Env env = info.Env();
|
|
@@ -559,6 +560,14 @@ static Napi::Value CreateWindow2(const Napi::CallbackInfo& info) {
|
|
|
559
560
|
win.opaque = BBoolOr(o, "opaque", true);
|
|
560
561
|
if (!win.opaque) win.backgroundColor = NSColor.clearColor;
|
|
561
562
|
}
|
|
563
|
+
// A window the pointer passes through. The window server hit-tests
|
|
564
|
+
// past it, so a click or a drag reaches whatever is beneath — what a
|
|
565
|
+
// drag preview following the pointer needs. Registering no dragged
|
|
566
|
+
// types is not that: the window under the pointer is found first, an
|
|
567
|
+
// unregistered one is still the one found, and the drag then has no
|
|
568
|
+
// destination at all. Transparent pixels do not pass a hit either.
|
|
569
|
+
if (o.Has("ignoresMouseEvents"))
|
|
570
|
+
win.ignoresMouseEvents = BBoolOr(o, "ignoresMouseEvents", false);
|
|
562
571
|
|
|
563
572
|
CALBackendView* view = [[CALBackendView alloc] initWithFrame:rect];
|
|
564
573
|
view->env_ = (napi_env)env;
|
|
@@ -622,6 +631,15 @@ static Napi::Value SetWindowTitle(const Napi::CallbackInfo& info) {
|
|
|
622
631
|
return info.Env().Undefined();
|
|
623
632
|
}
|
|
624
633
|
|
|
634
|
+
// setWindowIgnoresMouseEvents(win, flag) — createWindow2's option of the
|
|
635
|
+
// same name, changed on a live window; the next hit the window server
|
|
636
|
+
// resolves honours it.
|
|
637
|
+
static Napi::Value SetWindowIgnoresMouseEvents(const Napi::CallbackInfo& info) {
|
|
638
|
+
NSWindow* win = BDeref<NSWindow*>(info[0]);
|
|
639
|
+
win.ignoresMouseEvents = info.Length() > 1 && info[1].ToBoolean().Value();
|
|
640
|
+
return info.Env().Undefined();
|
|
641
|
+
}
|
|
642
|
+
|
|
625
643
|
// setWindowFrame(win, x, y, w, h) — any argument may be null to keep it.
|
|
626
644
|
// x/y are the content's top-left in global top-left coordinates, points.
|
|
627
645
|
static Napi::Value SetWindowFrame(const Napi::CallbackInfo& info) {
|
|
@@ -642,8 +660,8 @@ static Napi::Value SetWindowFrame(const Napi::CallbackInfo& info) {
|
|
|
642
660
|
return info.Env().Undefined();
|
|
643
661
|
}
|
|
644
662
|
|
|
645
|
-
// -> { x, y, width, height, scale, visible, occluded, key }
|
|
646
|
-
// global coordinates, points.
|
|
663
|
+
// -> { x, y, width, height, scale, visible, occluded, key, ignoresMouseEvents }
|
|
664
|
+
// — content rect, top-left global coordinates, points.
|
|
647
665
|
static Napi::Value GetWindowFrame(const Napi::CallbackInfo& info) {
|
|
648
666
|
Napi::Env env = info.Env();
|
|
649
667
|
NSWindow* win = BDeref<NSWindow*>(info[0]);
|
|
@@ -658,9 +676,36 @@ static Napi::Value GetWindowFrame(const Napi::CallbackInfo& info) {
|
|
|
658
676
|
// visible but with no pixel on glass: fully behind another app's window
|
|
659
677
|
r.Set("occluded", win.isVisible && !WindowOnGlass(win));
|
|
660
678
|
r.Set("key", (bool)win.isKeyWindow);
|
|
679
|
+
r.Set("ignoresMouseEvents", (bool)win.ignoresMouseEvents);
|
|
661
680
|
return r;
|
|
662
681
|
}
|
|
663
682
|
|
|
683
|
+
// windowNumberAtPoint(x, y, belowWindowNumber?) -> number — the window the
|
|
684
|
+
// window server would hand a mouse-down at a global top-left point, any
|
|
685
|
+
// application's, or 0 for none. It is the question `ignoresMouseEvents`
|
|
686
|
+
// changes the answer to, and where a drag's destination lookup starts. A
|
|
687
|
+
// window number in `belowWindowNumber` starts the search beneath that
|
|
688
|
+
// window, so walking the answers back in finds what sits under another
|
|
689
|
+
// application's window — a lock screen, a floating panel.
|
|
690
|
+
static Napi::Value WindowNumberAtPoint(const Napi::CallbackInfo& info) {
|
|
691
|
+
Napi::Env env = info.Env();
|
|
692
|
+
if (!info[0].IsNumber() || !info[1].IsNumber()) {
|
|
693
|
+
Napi::TypeError::New(env, "windowNumberAtPoint: x and y must be numbers")
|
|
694
|
+
.ThrowAsJavaScriptException();
|
|
695
|
+
return env.Undefined();
|
|
696
|
+
}
|
|
697
|
+
BEnsureApp();
|
|
698
|
+
double x = info[0].As<Napi::Number>().DoubleValue();
|
|
699
|
+
double y = info[1].As<Napi::Number>().DoubleValue();
|
|
700
|
+
NSInteger below = info.Length() > 2 && info[2].IsNumber()
|
|
701
|
+
? (NSInteger)info[2].As<Napi::Number>().Int64Value()
|
|
702
|
+
: 0;
|
|
703
|
+
NSInteger hit =
|
|
704
|
+
[NSWindow windowNumberAtPoint:NSMakePoint(x, PrimaryScreenTop() - y)
|
|
705
|
+
belowWindowWithWindowNumber:below];
|
|
706
|
+
return Napi::Number::New(env, (double)hit);
|
|
707
|
+
}
|
|
708
|
+
|
|
664
709
|
static Napi::Value SetWindowMinMax(const Napi::CallbackInfo& info) {
|
|
665
710
|
NSWindow* win = BDeref<NSWindow*>(info[0]);
|
|
666
711
|
Napi::Object o = info[1].As<Napi::Object>();
|
|
@@ -4970,6 +5015,8 @@ void InitBackend(Napi::Env env, Napi::Object exports) {
|
|
|
4970
5015
|
BFN("showWindow", ShowWindowFn);
|
|
4971
5016
|
BFN("hideWindow", HideWindowFn);
|
|
4972
5017
|
BFN("setWindowTitle", SetWindowTitle);
|
|
5018
|
+
BFN("setWindowIgnoresMouseEvents", SetWindowIgnoresMouseEvents);
|
|
5019
|
+
BFN("windowNumberAtPoint", WindowNumberAtPoint);
|
|
4973
5020
|
BFN("setWindowFrame", SetWindowFrame);
|
|
4974
5021
|
BFN("getWindowFrame", GetWindowFrame);
|
|
4975
5022
|
BFN("setWindowMinMax", SetWindowMinMax);
|