@windowkit/appkit 0.5.1 → 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 CHANGED
@@ -417,6 +417,22 @@ native.beginDrag(win, {
417
417
  default — at its own size unless `imageWidth` / `imageHeight` say otherwise.
418
418
  A drop on one of our own windows arrives through the destination events of
419
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.
420
436
  - **`postDragEvent(win, phase, { x, y, items, operations, local })`** drives
421
437
  the destination methods with a dragging info of the bridge's own over a
422
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.5.1",
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
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 } — content rect, top-left
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);