@geastack/apple 0.2.9 → 0.2.10

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/apple",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Generated Apple SDK bindings plus the macOS and iOS native build targets for Gea apps.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -20,14 +20,14 @@ bundle, `<app>/dist/macos/<app-id>/build/` for objects and PCHs, and
20
20
  directory the build runs in: `gea build` runs this script in the app, and a
21
21
  direct run uses the invocation directory.
22
22
 
23
- This package is installed into an app's `node_modules`, so a package-relative
24
- output path hid every build inside a directory nobody opens and npm deletes on
25
- the next install. Set `GEA_MACOS_OUTPUT_DIR` to put the whole tree elsewhere.
23
+ Output does not go under the package because the package lives in the app's
24
+ `node_modules`, which npm replaces on reinstall. Set `GEA_MACOS_OUTPUT_DIR` to
25
+ put the whole tree elsewhere.
26
26
 
27
27
  `<app-id>` is currently any name; when no generated app is present under
28
28
  `dist/macos/.generated/<app-id>/` the build falls back to a built-in
29
29
  Phase B smoke app (`macos_smoke_app.cpp`) that exercises View / Text /
30
- Button / event dispatch. Real geatsc-compiled apps drop into
30
+ Button / event dispatch. geatsc-compiled apps go into
31
31
  `dist/macos/.generated/` and supersede the smoke automatically — the
32
32
  JSX → C++ pipeline for the macOS target is a follow-up.
33
33
 
@@ -116,12 +116,12 @@ Native: View / Text / Button / Image / Canvas / VirtualList; flex
116
116
  layout; click + press events; trackpad-momentum scroll; window resize
117
117
  (live + final); standard menu bar with Cmd-Q.
118
118
 
119
- Audio is real: `targets/shared/apple_audio.mm` (shared with iOS) backs
119
+ Audio: `targets/shared/apple_audio.mm` (shared with iOS) backs
120
120
  `gea::platform::audio` with AVAudioEngine — sample-accurately scheduled,
121
121
  mixed oscillators on an `AVAudioSourceNode`, plus `playFile`/`playPcm` on
122
122
  `AVAudioPlayerNode`s. `targets/shared/build-audio-selftest.sh` builds and
123
123
  runs the measurement harness (offline render, RMS + measured frequency);
124
- `GEA_AUDIO_CAPTURE_RAW=<path>` captures a real app run for
124
+ `GEA_AUDIO_CAPTURE_RAW=<path>` captures an app run for
125
125
  `targets/shared/analyze-audio-capture.mjs`.
126
126
 
127
127
  Stubbed for v1: WiFi (`macos_wifi`), BLE (`macos_ble`), IMU (`macos_imu`)
@@ -195,16 +195,26 @@ static int geaKeyCodeForCommand(SEL sel)
195
195
  }
196
196
  @end
197
197
 
198
- // Root-level click handler. Installed once on the contentView during
199
- // MacosRenderer::sync. On click, asks the recognizer for the location,
198
+ // Root-level press handler. Installed once on the contentView during
199
+ // MacosRenderer::sync. On mouse-down, asks the recognizer for the location,
200
200
  // hit-tests against the root, then walks up via nodeIdForView to find the
201
- // deepest view that's tagged with a node id, and dispatches click+press
202
- // to that nodeId. Matches the framework's event-delegation model — listeners
203
- // bound on document.body fire and check event.target to figure out which
204
- // node was clicked.
201
+ // deepest view that's tagged with a node id, and dispatches the gesture —
202
+ // touchstart, touchmove while dragging, touchend, then click — to that nodeId,
203
+ // each carrying tree coordinates. Matches the framework's event-delegation
204
+ // model — listeners bound on document.body fire and check event.target to
205
+ // figure out which node was pressed.
205
206
  @interface GeaRootClickBridge : NSObject <NSGestureRecognizerDelegate>
206
207
  @property(nonatomic, weak) NSView *rootView;
207
208
  @property(nonatomic, assign) int pressedNodeId; // -1 when no press in flight
209
+ // Tree-space origin of rootView: 0,0 for a window root, the pane node's
210
+ // layout.x/y for a split-view pane.
211
+ @property(nonatomic, assign) int originX;
212
+ @property(nonatomic, assign) int originY;
213
+ @property(nonatomic, assign) int startX;
214
+ @property(nonatomic, assign) int startY;
215
+ @property(nonatomic, assign) int lastX;
216
+ @property(nonatomic, assign) int lastY;
217
+ @property(nonatomic, assign) BOOL dragged;
208
218
  - (void)fire:(NSGestureRecognizer *)gr;
209
219
  @end
210
220
 
@@ -234,16 +244,50 @@ int nodeIdForView(NSView *view)
234
244
  {
235
245
  using gea::framework::events::PointerEvent;
236
246
  using gea::framework::events::PointerEventType;
247
+ using gea::framework::events::TouchPoint;
237
248
  NSView *root = self.rootView;
238
249
  if (!root) return;
239
250
 
240
- auto fireEvent = [&](int nodeId, PointerEventType type) {
251
+ // Recognizer location → tree coordinates. The root is unflipped and
252
+ // applyViewStyle maps layout units to points 1:1, flipping y against the
253
+ // parent's height, so undo that flip and add the root's tree origin.
254
+ const NSPoint pInRoot = [gr locationInView:root];
255
+ const int x = static_cast<int>(std::lround(pInRoot.x)) + self.originX;
256
+ const int y = static_cast<int>(std::lround(root.bounds.size.height - pInRoot.y)) + self.originY;
257
+
258
+ // Same payload as TouchRuntime's dispatchPointer, so a handler reads
259
+ // clientX/clientY (or touches[0]) identically on a canvas and a view.
260
+ auto fireEvent = [&](int nodeId, PointerEventType type, int px, int py, bool activeTouch) {
241
261
  if (nodeId < 0) return;
242
262
  auto &tree = gea::embedded::ui::Tree::instance();
243
263
  if (nodeId >= tree.nodeCount()) return;
244
264
  PointerEvent ev;
245
265
  ev.type = type;
246
266
  ev.targetId = nodeId;
267
+ ev.pointerId = 1;
268
+ ev.x = px;
269
+ ev.y = py;
270
+ ev.clientX = px;
271
+ ev.clientY = py;
272
+ ev.pageX = px;
273
+ ev.pageY = py;
274
+ ev.screenX = px;
275
+ ev.screenY = py;
276
+ ev.touchesLength = activeTouch ? 1 : 0;
277
+ ev.targetTouchesLength = activeTouch ? 1 : 0;
278
+ ev.changedTouchesLength = 1;
279
+ TouchPoint point{};
280
+ point.identifier = 1;
281
+ point.target = gea::framework::events::EventTarget(nodeId);
282
+ point.clientX = px;
283
+ point.clientY = py;
284
+ point.pageX = px;
285
+ point.pageY = py;
286
+ point.screenX = px;
287
+ point.screenY = py;
288
+ ev.touches[0] = point;
289
+ ev.targetTouches[0] = point;
290
+ ev.changedTouches[0] = point;
247
291
  tree.dispatchEvent(ev);
248
292
  };
249
293
 
@@ -258,13 +302,26 @@ int nodeIdForView(NSView *view)
258
302
  if (root.window.firstResponder != root.window) {
259
303
  [root.window makeFirstResponder:nil];
260
304
  }
261
- // Mouse-down: hit-test now, remember the node so the up phase
262
- // dispatches to the same target even if the cursor drifts.
263
- const NSPoint pInRoot = [gr locationInView:root];
305
+ // Mouse-down: hit-test now, remember the node so the move and up
306
+ // phases dispatch to the same target even if the cursor drifts.
264
307
  const NSPoint pInSuper = [root convertPoint:pInRoot toView:root.superview];
265
308
  NSView *hit = [root.superview hitTest:pInSuper];
266
309
  self.pressedNodeId = gea::macos::nodeIdForView(hit);
267
- fireEvent(self.pressedNodeId, PointerEventType::TouchStart);
310
+ self.startX = x;
311
+ self.startY = y;
312
+ self.lastX = x;
313
+ self.lastY = y;
314
+ self.dragged = NO;
315
+ fireEvent(self.pressedNodeId, PointerEventType::TouchStart, x, y, true);
316
+ break;
317
+ }
318
+ case NSGestureRecognizerStateChanged: {
319
+ if (self.pressedNodeId < 0) break;
320
+ if (x == self.lastX && y == self.lastY) break;
321
+ if (!self.dragged && (std::abs(x - self.startX) > 16 || std::abs(y - self.startY) > 16)) self.dragged = YES;
322
+ self.lastX = x;
323
+ self.lastY = y;
324
+ fireEvent(self.pressedNodeId, PointerEventType::TouchMove, x, y, true);
268
325
  break;
269
326
  }
270
327
  case NSGestureRecognizerStateEnded:
@@ -272,10 +329,8 @@ int nodeIdForView(NSView *view)
272
329
  case NSGestureRecognizerStateFailed: {
273
330
  const int nodeId = self.pressedNodeId;
274
331
  self.pressedNodeId = -1;
275
- fireEvent(nodeId, PointerEventType::TouchEnd);
276
- if (gr.state == NSGestureRecognizerStateEnded) {
277
- fireEvent(nodeId, PointerEventType::Click);
278
- }
332
+ fireEvent(nodeId, PointerEventType::TouchEnd, self.lastX, self.lastY, false);
333
+ if (gr.state == NSGestureRecognizerStateEnded && !self.dragged) fireEvent(nodeId, PointerEventType::Click, self.lastX, self.lastY, false);
279
334
  break;
280
335
  }
281
336
  default:
@@ -305,6 +360,9 @@ int nodeIdForView(NSView *view)
305
360
  // (mouseDown/Dragged/Up in GeaCanvasView) — recognizing here too would
306
361
  // double-fire the press, with this path's events carrying no coords.
307
362
  if ([v isKindOfClass:[GeaCanvasView class]]) return NO;
363
+ // A scroll container's scroller tracks its own knob drag; recognizing
364
+ // the press here took the whole drag and the knob never moved.
365
+ if ([v isKindOfClass:[NSScroller class]]) return NO;
308
366
  }
309
367
  return YES;
310
368
  }
@@ -316,10 +374,65 @@ int nodeIdForView(NSView *view)
316
374
  // (unflipped) clip view, short content bottom-aligns, leaving a gap above the
317
375
  // first row. The document view itself stays unflipped, so syncRecursive's
318
376
  // y-flip against scroll_content_height is unchanged.
377
+ //
378
+ // AppKit owns the scroll position, but the engine has to be told it: a
379
+ // VirtualList windows its rows from Tree::scrollTop, the engine offsets child
380
+ // layout by it, and Tree::setScrollTop is what dispatches `scroll`. Without the
381
+ // commit a trackpad scroll moved the document while the engine stayed at 0, so
382
+ // rows past the first window were blank and onScroll never fired. Like the iOS
383
+ // container, an overscrolled (rubber-banding) offset is not committed; the
384
+ // settled one is.
385
+ static int g_macosSyncDepth = 0;
386
+ struct GeaSyncDepthScope {
387
+ GeaSyncDepthScope() { ++g_macosSyncDepth; }
388
+ ~GeaSyncDepthScope() { --g_macosSyncDepth; }
389
+ };
390
+
319
391
  @interface GeaFlippedClipView : NSClipView
392
+ @property(nonatomic, assign) int nodeId;
320
393
  @end
321
394
  @implementation GeaFlippedClipView
395
+ - (instancetype)initWithFrame:(NSRect)frameRect
396
+ {
397
+ if ((self = [super initWithFrame:frameRect])) {
398
+ _nodeId = -1;
399
+ self.postsBoundsChangedNotifications = YES;
400
+ [[NSNotificationCenter defaultCenter] addObserver:self
401
+ selector:@selector(geaBoundsDidChange:)
402
+ name:NSViewBoundsDidChangeNotification
403
+ object:self];
404
+ }
405
+ return self;
406
+ }
407
+ - (void)dealloc
408
+ {
409
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
410
+ }
322
411
  - (BOOL)isFlipped { return YES; }
412
+ - (void)geaBoundsDidChange:(NSNotification *)notification
413
+ {
414
+ (void)notification;
415
+ // A bounds change made by sync itself (content resized, offset clamped) is
416
+ // committed after the walk: mid-walk it would move scrollTop under children
417
+ // whose layout was computed for the old offset.
418
+ if (g_macosSyncDepth > 0) {
419
+ dispatch_async(dispatch_get_main_queue(), ^{
420
+ [self commitScrollTop];
421
+ });
422
+ return;
423
+ }
424
+ [self commitScrollTop];
425
+ }
426
+ - (void)commitScrollTop
427
+ {
428
+ if (self.nodeId < 0) return;
429
+ auto &tree = gea::embedded::ui::Tree::instance();
430
+ if (self.nodeId >= tree.nodeCount()) return;
431
+ const CGFloat y = self.bounds.origin.y;
432
+ const CGFloat maxY = std::max<CGFloat>(0, NSHeight(self.documentView.frame) - NSHeight(self.bounds));
433
+ if (y < -0.5 || y > maxY + 0.5) return;
434
+ tree.setScrollTop(self.nodeId, static_cast<int>(std::lround(std::clamp<CGFloat>(y, 0, maxY))));
435
+ }
323
436
  @end
324
437
 
325
438
  // NSSlider materialized by `<input type="range">`. Continuous; on each value
@@ -1522,13 +1635,20 @@ void applyScrollContentSize(NSScrollView *sv, const gea::embedded::ui::Node &nod
1522
1635
  {
1523
1636
  NSView *content = sv.documentView;
1524
1637
  if (!content) return;
1638
+ // The engine reserves no scrollbar gutter: every target lays content out
1639
+ // across the container's full width and draws its scroller over it. A
1640
+ // legacy (always-shown) NSScroller takes its width out of the clip instead,
1641
+ // hiding that strip of the layout and leaving the document sideways play, so
1642
+ // the scroller stays in the overlay style.
1643
+ if (sv.scrollerStyle != NSScrollerStyleOverlay) sv.scrollerStyle = NSScrollerStyleOverlay;
1525
1644
  const CGFloat w = node.layout.width;
1526
1645
  const CGFloat h = node.layout.scroll_content_height > 0
1527
1646
  ? node.layout.scroll_content_height
1528
1647
  : node.layout.height;
1529
1648
  // documentView always sized to the full scroll content; NSScrollView's
1530
1649
  // own scrollers handle the visible window. We don't apply the tree's
1531
- // scroll_y here — AppKit owns the scroll position via NSScrollView.
1650
+ // scroll_y here — AppKit owns the scroll position via NSScrollView, and
1651
+ // GeaFlippedClipView mirrors it into the tree.
1532
1652
  if (content.frame.size.width != w || content.frame.size.height != h) {
1533
1653
  content.frame = NSMakeRect(0, 0, w, h);
1534
1654
  }
@@ -1574,7 +1694,11 @@ void applyTypeSpecificProps(NSView *view, const gea::embedded::ui::Node &node, i
1574
1694
  applyTextAreaProps((NSScrollView *)view, node, nodeId);
1575
1695
  } else if (isScrollView(view)) {
1576
1696
  // Both NodeType::VirtualList and overflow:scroll Views land here.
1577
- applyScrollContentSize((NSScrollView *)view, node);
1697
+ NSScrollView *sv = (NSScrollView *)view;
1698
+ if ([sv.contentView isKindOfClass:[GeaFlippedClipView class]]) {
1699
+ ((GeaFlippedClipView *)sv.contentView).nodeId = nodeId;
1700
+ }
1701
+ applyScrollContentSize(sv, node);
1578
1702
  }
1579
1703
 
1580
1704
  // Per-View click recognizers don't fit the framework's event-delegation
@@ -1858,6 +1982,9 @@ void syncRecursive(int nodeId, NSView *parent, int parentAbsX, int parentAbsY, i
1858
1982
  parentHeightForChildren = node.layout.scroll_content_height > 0
1859
1983
  ? node.layout.scroll_content_height
1860
1984
  : node.layout.height;
1985
+ // The engine lays children out at their scrolled position; the document
1986
+ // view is already scrolled by AppKit, so place them in document space.
1987
+ parentAbsYForChildren = node.layout.y - tree.scrollTop(nodeId);
1861
1988
  }
1862
1989
 
1863
1990
  for (int child = node.first_child; child >= 0; child = tree.node(child).next_sibling) {
@@ -1877,34 +2004,41 @@ MacosRenderer &MacosRenderer::instance()
1877
2004
  namespace {
1878
2005
  // Install the centralized press/click handler on a root container once.
1879
2006
  // Idempotent via an associated object so repeated sync passes don't stack
1880
- // recognizers.
1881
- void ensureRootClickBridge(NSView *parentForRoot)
1882
- {
1883
- if (objc_getAssociatedObject(parentForRoot, "gea.root_click_bridge")) return;
1884
- GeaRootClickBridge *bridge = [[GeaRootClickBridge alloc] init];
1885
- bridge.rootView = parentForRoot;
1886
- objc_setAssociatedObject(parentForRoot, "gea.root_click_bridge", bridge, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
1887
- // NSPressGestureRecognizer (not NSClickGestureRecognizer) — we need the
1888
- // began/ended state transitions so press-and-hold semantics work.
1889
- // minimumPressDuration=0 fires began immediately on mouseDown.
1890
- NSPressGestureRecognizer *gr =
1891
- [[NSPressGestureRecognizer alloc] initWithTarget:bridge action:@selector(fire:)];
1892
- gr.minimumPressDuration = 0;
1893
- gr.allowableMovement = 10000; // don't cancel on drag — keep the press
1894
- // The delegate declines clicks on editable text controls so they focus and
1895
- // edit natively instead of being swallowed by this recognizer.
1896
- gr.delegate = bridge;
1897
- [parentForRoot addGestureRecognizer:gr];
2007
+ // recognizers. The tree origin is refreshed on every pass: a pane's layout
2008
+ // origin moves when its split is resized.
2009
+ void ensureRootClickBridge(NSView *parentForRoot, int originX, int originY)
2010
+ {
2011
+ GeaRootClickBridge *bridge = objc_getAssociatedObject(parentForRoot, "gea.root_click_bridge");
2012
+ if (!bridge) {
2013
+ bridge = [[GeaRootClickBridge alloc] init];
2014
+ bridge.rootView = parentForRoot;
2015
+ objc_setAssociatedObject(parentForRoot, "gea.root_click_bridge", bridge, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
2016
+ // NSPressGestureRecognizer (not NSClickGestureRecognizer) — we need the
2017
+ // began/changed/ended state transitions so press-and-hold and drag
2018
+ // semantics work. minimumPressDuration=0 fires began immediately on
2019
+ // mouseDown.
2020
+ NSPressGestureRecognizer *gr =
2021
+ [[NSPressGestureRecognizer alloc] initWithTarget:bridge action:@selector(fire:)];
2022
+ gr.minimumPressDuration = 0;
2023
+ gr.allowableMovement = 10000; // don't cancel on drag — keep the press
2024
+ // The delegate declines clicks on editable text controls so they focus and
2025
+ // edit natively instead of being swallowed by this recognizer.
2026
+ gr.delegate = bridge;
2027
+ [parentForRoot addGestureRecognizer:gr];
2028
+ }
2029
+ bridge.originX = originX;
2030
+ bridge.originY = originY;
1898
2031
  }
1899
2032
  } // namespace
1900
2033
 
1901
2034
  void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
1902
2035
  {
2036
+ const GeaSyncDepthScope syncScope;
1903
2037
  using namespace gea::embedded::ui;
1904
2038
  Tree &tree = Tree::instance();
1905
2039
  if (rootNodeId < 0 || rootNodeId >= tree.nodeCount()) return;
1906
2040
 
1907
- ensureRootClickBridge(parentForRoot);
2041
+ ensureRootClickBridge(parentForRoot, 0, 0);
1908
2042
 
1909
2043
  // Mark every existing entry stale; syncRecursive removes the keys it
1910
2044
  // touches. Anything still in the set after the walk corresponds to a
@@ -1928,6 +2062,7 @@ void MacosRenderer::sync(NSView *parentForRoot, int rootNodeId)
1928
2062
 
1929
2063
  void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
1930
2064
  {
2065
+ const GeaSyncDepthScope syncScope;
1931
2066
  using namespace gea::embedded::ui;
1932
2067
  Tree &tree = Tree::instance();
1933
2068
  const NSUInteger paneCount = paneViews.count;
@@ -1943,11 +2078,11 @@ void MacosRenderer::syncPanes(NSArray *paneViews, const int *rootNodeIds)
1943
2078
  NSView *paneView = paneViews[i];
1944
2079
  const int rootNodeId = rootNodeIds[i];
1945
2080
  if (rootNodeId < 0 || rootNodeId >= tree.nodeCount()) continue;
1946
- ensureRootClickBridge(paneView);
1947
2081
  const int parentHeight = static_cast<int>(paneView.bounds.size.height);
1948
2082
  // Each pane node's own layout.x/y act as its document origin, so the
1949
2083
  // pane's children land relative to the pane container's top-left.
1950
2084
  const Node &paneNode = tree.node(rootNodeId);
2085
+ ensureRootClickBridge(paneView, paneNode.layout.x, paneNode.layout.y);
1951
2086
  syncRecursive(rootNodeId, paneView, paneNode.layout.x, paneNode.layout.y, parentHeight, unseen);
1952
2087
  }
1953
2088