@geastack/apple 0.2.13 → 0.2.15

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.
@@ -20,7 +20,7 @@
20
20
  namespace {
21
21
 
22
22
  gea::framework::graphics::Canvas g_canvas;
23
- std::uint16_t *g_framebuffer = nullptr;
23
+ gea::framework::graphics::pixel::native_t *g_framebuffer = nullptr;
24
24
  // Logical canvas size. Starts at the compile-time panel dims and follows the
25
25
  // app's orientation: applyOrientation() below reallocates the surface (and
26
26
  // resizes the window) to the rotated logical size, so window.innerWidth, the
@@ -37,7 +37,7 @@ int g_flush_pixels = 0;
37
37
  void ensure_canvas()
38
38
  {
39
39
  if (g_framebuffer) return;
40
- g_framebuffer = static_cast<std::uint16_t *>(std::calloc((size_t)g_canvas_w * (size_t)g_canvas_h, sizeof(std::uint16_t)));
40
+ g_framebuffer = static_cast<gea::framework::graphics::pixel::native_t *>(std::calloc((size_t)g_canvas_w * (size_t)g_canvas_h, sizeof(gea::framework::graphics::pixel::native_t)));
41
41
  g_canvas.bindPixels(g_framebuffer, g_canvas_w, g_canvas_h);
42
42
  }
43
43
 
@@ -62,9 +62,11 @@ void submit_full_frame()
62
62
  {
63
63
  if (!framebuffer_target()) return;
64
64
  ensure_canvas();
65
+ #if GEA_MACOS_THERMALRIGHT_DISPLAY_TARGET
65
66
  gea::macos::thermalright::submitRgb565(g_framebuffer,
66
67
  gea::platform::display::kWidth,
67
68
  gea::platform::display::kHeight);
69
+ #endif
68
70
  }
69
71
 
70
72
  } // namespace
@@ -132,12 +134,11 @@ void Display::flushRectsRasterized(const DisplayFlushRect *rects, int count, Dis
132
134
  if (x0 > x1 || y0 > y1) continue;
133
135
  const int w = x1 - x0 + 1;
134
136
  const int h = y1 - y0 + 1;
135
- std::vector<std::uint16_t> pixels(static_cast<std::size_t>(w) * static_cast<std::size_t>(h));
137
+ std::vector<gea::framework::graphics::pixel::native_t> pixels(static_cast<std::size_t>(w) * static_cast<std::size_t>(h));
136
138
  raster(pixels.data(), w, h, x0, y0, user);
137
139
  for (int row = 0; row < h; row++) {
138
- std::memcpy(g_framebuffer + static_cast<std::size_t>(y0 + row) * kWidth + x0,
139
- pixels.data() + static_cast<std::size_t>(row) * w,
140
- static_cast<std::size_t>(w) * sizeof(std::uint16_t));
140
+ for (int col = 0; col < w; ++col)
141
+ g_framebuffer[static_cast<std::size_t>(y0 + row) * kWidth + x0 + col] = pixels[static_cast<std::size_t>(row) * w + col];
141
142
  }
142
143
  g_canvas.markDirty(x0, y0, x1, y1);
143
144
  }
@@ -163,12 +164,11 @@ bool Display::streamRect(int x, int y, int w, int h, DisplayStreamRasterFn raste
163
164
 
164
165
  const int rw = x1 - x0 + 1;
165
166
  const int rh = y1 - y0 + 1;
166
- std::vector<std::uint16_t> pixels(static_cast<std::size_t>(rw) * static_cast<std::size_t>(rh));
167
+ std::vector<gea::framework::graphics::pixel::native_t> pixels(static_cast<std::size_t>(rw) * static_cast<std::size_t>(rh));
167
168
  raster(pixels.data(), rw, rh, x0, y0, user);
168
169
  for (int row = 0; row < rh; row++) {
169
- std::memcpy(g_framebuffer + static_cast<std::size_t>(y0 + row) * kWidth + x0,
170
- pixels.data() + static_cast<std::size_t>(row) * rw,
171
- static_cast<std::size_t>(rw) * sizeof(std::uint16_t));
170
+ for (int col = 0; col < rw; ++col)
171
+ g_framebuffer[static_cast<std::size_t>(y0 + row) * kWidth + x0 + col] = pixels[static_cast<std::size_t>(row) * rw + col];
172
172
  }
173
173
  g_canvas.markDirty(x0, y0, x1, y1);
174
174
  flush();
@@ -338,17 +338,17 @@ void Display::clip(int *x0, int *y0, int *x1, int *y1)
338
338
  if (y1) *y1 = g_canvas_h - 1;
339
339
  }
340
340
 
341
- void Display::fillRect(int x, int y, int w, int h, uint16_t c) { if (framebuffer_target()) canvas()->fillRect(x, y, w, h, c); }
341
+ void Display::fillRect(int x, int y, int w, int h, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->fillRect(x, y, w, h, c); }
342
342
  void Display::scrollRect(int x, int y, int w, int h, int dx, int dy) { if (framebuffer_target()) canvas()->scrollRect(x, y, w, h, dx, dy); }
343
343
  void Display::resetScrollRegion() { if (framebuffer_target()) canvas()->setScrollRegion(0, 0, 0); }
344
- void Display::strokeRect(int x, int y, int w, int h, uint16_t c) { if (framebuffer_target()) canvas()->strokeRect(x, y, w, h, c); }
345
- void Display::fillCircle(int cx, int cy, int r, uint16_t c) { if (framebuffer_target()) canvas()->fillCircle(cx, cy, r, c); }
346
- void Display::strokeCircle(int cx, int cy, int r, uint16_t c) { if (framebuffer_target()) canvas()->strokeCircle(cx, cy, r, c); }
347
- void Display::drawLine(int x0, int y0, int x1, int y1, uint16_t c) { if (framebuffer_target()) canvas()->drawLine(x0, y0, x1, y1, c); }
348
- void Display::drawArc(int cx, int cy, int r, int start_deg, int end_deg, uint16_t c) { if (framebuffer_target()) canvas()->drawArc(cx, cy, r, start_deg, end_deg, c); }
349
- void Display::fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, uint16_t c) { if (framebuffer_target()) canvas()->fillTriangle(x0, y0, x1, y1, x2, y2, c); }
350
- void Display::drawText(const char *text, int x, int y, uint16_t c, float scale) { if (framebuffer_target()) canvas()->drawText(text, x, y, c, scale); }
351
- void Display::drawTextFont(const char *text, int x, int y, uint16_t c, int font_id)
344
+ void Display::strokeRect(int x, int y, int w, int h, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->strokeRect(x, y, w, h, c); }
345
+ void Display::fillCircle(int cx, int cy, int r, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->fillCircle(cx, cy, r, c); }
346
+ void Display::strokeCircle(int cx, int cy, int r, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->strokeCircle(cx, cy, r, c); }
347
+ void Display::drawLine(int x0, int y0, int x1, int y1, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->drawLine(x0, y0, x1, y1, c); }
348
+ void Display::drawArc(int cx, int cy, int r, int start_deg, int end_deg, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->drawArc(cx, cy, r, start_deg, end_deg, c); }
349
+ void Display::fillTriangle(int x0, int y0, int x1, int y1, int x2, int y2, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->fillTriangle(x0, y0, x1, y1, x2, y2, c); }
350
+ void Display::drawText(const char *text, int x, int y, gea::framework::graphics::pixel::native_t c, float scale) { if (framebuffer_target()) canvas()->drawText(text, x, y, c, scale); }
351
+ void Display::drawTextFont(const char *text, int x, int y, gea::framework::graphics::pixel::native_t c, int font_id)
352
352
  {
353
353
  if (!framebuffer_target()) return;
354
354
  #ifdef GEA_EMBEDDED_HAS_GENERATED_FONTS
@@ -358,14 +358,14 @@ void Display::drawTextFont(const char *text, int x, int y, uint16_t c, int font_
358
358
  canvas()->drawText(text, x, y, c, 1.0f);
359
359
  #endif
360
360
  }
361
- void Display::drawTextFontFamily(const char *text, int x, int y, uint16_t c, int family_id, int size_px) { if (framebuffer_target()) canvas()->drawTextFontFamily(text, x, y, c, family_id, size_px); }
362
- void Display::setPixel(int x, int y, uint16_t c) { if (framebuffer_target()) canvas()->fillRect(x, y, 1, 1, c); }
363
- void Display::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, uint16_t c) { if (framebuffer_target()) canvas()->fillRoundedRect(x, y, w, h, tl, tr, br, bl, c); }
364
- void Display::fillRoundedRectBoxesRgb565(const int16_t *xs, const int16_t *ys, int count, int w, int h, int tl, int tr, int br, int bl, const uint16_t *colors)
361
+ void Display::drawTextFontFamily(const char *text, int x, int y, gea::framework::graphics::pixel::native_t c, int family_id, int size_px) { if (framebuffer_target()) canvas()->drawTextFontFamily(text, x, y, c, family_id, size_px); }
362
+ void Display::setPixel(int x, int y, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->fillRect(x, y, 1, 1, c); }
363
+ void Display::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->fillRoundedRect(x, y, w, h, tl, tr, br, bl, c); }
364
+ void Display::fillRoundedRectBoxesRgb565(const int16_t *xs, const int16_t *ys, int count, int w, int h, int tl, int tr, int br, int bl, const gea::framework::graphics::pixel::native_t *colors)
365
365
  {
366
366
  if (framebuffer_target()) canvas()->fillRoundedRectBoxesRgb565(xs, ys, count, w, h, tl, tr, br, bl, colors);
367
367
  }
368
- void Display::strokeRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, int lw, uint16_t c) { if (framebuffer_target()) canvas()->strokeRoundedRect(x, y, w, h, tl, tr, br, bl, lw, c); }
368
+ void Display::strokeRoundedRect(int x, int y, int w, int h, int tl, int tr, int br, int bl, int lw, gea::framework::graphics::pixel::native_t c) { if (framebuffer_target()) canvas()->strokeRoundedRect(x, y, w, h, tl, tr, br, bl, lw, c); }
369
369
  void Display::blitImage(const gea::framework::graphics::pixel::native_t *src, const uint8_t *alpha, int src_w, int src_h, int dx, int dy) { if (framebuffer_target()) canvas()->drawImage(src, alpha, src_w, src_h, dx, dy); }
370
370
  void Display::blitImageScaled(const gea::framework::graphics::pixel::native_t *src, const uint8_t *alpha, int src_w, int src_h, int dx, int dy, int dst_w, int dst_h) { if (framebuffer_target()) canvas()->drawImage(src, alpha, src_w, src_h, dx, dy, dst_w, dst_h); }
371
371
  void Display::setWorldOverlay(const uint16_t *, int, int, int, int) {}
@@ -387,7 +387,7 @@ bool Display::copySnapshotRgb565(uint16_t *dst, int pixel_capacity, int *width,
387
387
  if (width) *width = g_canvas_w;
388
388
  if (height) *height = g_canvas_h;
389
389
  if (!dst || pixel_capacity < pixels) return false;
390
- std::memcpy(dst, g_framebuffer, static_cast<std::size_t>(pixels) * sizeof(std::uint16_t));
390
+ for (int i = 0; i < pixels; ++i) dst[i] = gea::framework::graphics::pixel::toRgb565(g_framebuffer[i]);
391
391
  return true;
392
392
  }
393
393
  int Display::countNonBlackPixels(bool)
@@ -395,7 +395,9 @@ int Display::countNonBlackPixels(bool)
395
395
  ensure_canvas();
396
396
  int count = 0;
397
397
  for (int i = 0; i < g_canvas_w * g_canvas_h; i++) {
398
- if (g_framebuffer[i] != 0) count++;
398
+ int r, g, b, a;
399
+ gea::framework::graphics::pixel::unpackNative8(g_framebuffer[i], &r, &g, &b, &a);
400
+ if (r || g || b) count++;
399
401
  }
400
402
  return count;
401
403
  }
@@ -469,7 +471,7 @@ void applyOrientation(gea::framework::display::DisplayOrientation)
469
471
  g_canvas_w = w;
470
472
  g_canvas_h = h;
471
473
  std::free(g_framebuffer);
472
- g_framebuffer = static_cast<std::uint16_t *>(std::calloc((size_t)w * (size_t)h, sizeof(std::uint16_t)));
474
+ g_framebuffer = static_cast<gea::framework::graphics::pixel::native_t *>(std::calloc((size_t)w * (size_t)h, sizeof(gea::framework::graphics::pixel::native_t)));
473
475
  g_canvas.bindPixels(g_framebuffer, w, h);
474
476
  // Orientation is set from the app's top level inside Application::init,
475
477
  // which runs on the main thread with the window already on screen.
@@ -1,6 +1,11 @@
1
1
  #import <Cocoa/Cocoa.h>
2
+ #import <GameController/GameController.h>
2
3
  #import <QuartzCore/CADisplayLink.h>
3
4
 
5
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
6
+ extern void gea_macos_debugger_start();
7
+ #endif
8
+
4
9
  #include "font_registry.h"
5
10
  #include "macos_native_shell.h"
6
11
  #include "macos_renderer.h"
@@ -8,12 +13,13 @@
8
13
  #include "thermalright_hid_display.h"
9
14
 
10
15
  namespace gea::macos { void installAppLauncherPlatform(const char *currentAppId); }
11
- namespace gea::macos { void installWifiDriver(); }
16
+ namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view); }
12
17
 
13
18
  #include "app.h"
14
19
  #include "css/declarative.h"
15
20
  #include "css/engine.h"
16
21
  #include "display.h"
22
+ #include "platform/file_cache.h"
17
23
  #if __has_include("resident_apps.h")
18
24
  #include "resident_apps.h"
19
25
  #define GEA_MACOS_HAS_RESIDENT_APPS 1
@@ -57,13 +63,213 @@ static void gea_macos_smoke_log(const char *message)
57
63
  #define GEA_MACOS_HAS_APPLE_NATIVE_BRIDGE 1
58
64
  #endif
59
65
 
60
- @interface GeaContentView : NSView
66
+ // App-owned controls consume ordinary Gea events. AppKit supplies only the
67
+ // window and text services, including keyboard layout and IME composition.
68
+ static int geaCustomInputRoot()
69
+ {
70
+ auto &tree = gea::embedded::ui::Tree::instance();
71
+ for (int i=0;i<tree.nodeCount();++i)
72
+ if (std::strcmp(tree.getAttribute(i,"data-gea-inputs"),"true")==0) return i;
73
+ return -1;
74
+ }
75
+ // Authored silhouettes own their press layer; a rectangular engine fill would
76
+ // paint outside their transparent corners. Ancestors cover image/text hits.
77
+ static bool geaOwnsContourPress(int x, int y) {
78
+ auto &tree=gea::embedded::ui::Tree::instance();
79
+ for (int id=tree.hitTestNode(x,y);id>=0;id=tree.node(id).parent)
80
+ if (std::strcmp(tree.getAttribute(id,"data-gea-contour"),"true")==0) return true;
81
+ return false;
82
+ }
83
+ @interface GeaContentView : NSView <NSTextInputClient>
84
+ @property(nonatomic,copy) NSAttributedString *geaMarkedText;
85
+ @property(nonatomic,strong) GCController *geaActiveController;
86
+ @property(nonatomic) unsigned int geaGamepadButtons;
87
+ @property(nonatomic) NSTimeInterval geaGamepadRepeat;
88
+ @property(nonatomic,strong) id geaCursorMonitor;
89
+ @property(nonatomic,strong) NSTrackingArea *geaPointerTracking;
61
90
  @end
62
-
63
91
  @implementation GeaContentView
64
- // Override to keep the default AppKit y-flip semantics (origin bottom-left).
65
- // MacosRenderer::applyViewStyle does its own coordinate flipping.
92
+ // Optional app cursor is scoped to the content bounds; AppKit restores the
93
+ // standard pointer over the title bar, other windows, and other applications.
94
+ - (void)resetCursorRects {
95
+ [super resetCursorRects];
96
+ static NSCursor *cursor = nil;
97
+ static dispatch_once_t once;
98
+ dispatch_once(&once, ^{
99
+ NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"window.json"];
100
+ NSData *data = [NSData dataWithContentsOfFile:path];
101
+ NSDictionary *config = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
102
+ if (![config isKindOfClass:[NSDictionary class]]) return;
103
+ NSDictionary *window = config[@"window"] ?: config;
104
+ NSDictionary *spec = window[@"cursor"];
105
+ if (![spec isKindOfClass:[NSDictionary class]] || ![spec[@"style"] isEqual:@"angular"]) return;
106
+ CGFloat size = [spec[@"size"] respondsToSelector:@selector(doubleValue)] ? [spec[@"size"] doubleValue] : 28;
107
+ size = std::clamp((double)size, 20.0, 48.0);
108
+ NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(size, size + 6)];
109
+ [image lockFocus];
110
+ NSAffineTransform *transform = [NSAffineTransform transform];
111
+ [transform translateXBy:0 yBy:size + 6];
112
+ [transform scaleXBy:size / 28 yBy:-size / 28];
113
+ [transform concat];
114
+ NSBezierPath *arrow = [NSBezierPath bezierPath];
115
+ [arrow moveToPoint:NSMakePoint(2,2)];
116
+ [arrow lineToPoint:NSMakePoint(23,18)];
117
+ [arrow lineToPoint:NSMakePoint(12,21)];
118
+ [arrow lineToPoint:NSMakePoint(3,29)];
119
+ [arrow closePath];
120
+ [[NSColor colorWithCalibratedRed:0.04 green:0.12 blue:0.16 alpha:1] setFill];
121
+ [arrow fill];
122
+ [[NSColor colorWithCalibratedRed:0.69 green:0.93 blue:0.94 alpha:1] setStroke];
123
+ arrow.lineWidth = 1.6; [arrow stroke];
124
+ NSBezierPath *accent = [NSBezierPath bezierPath];
125
+ [accent moveToPoint:NSMakePoint(5,8)]; [accent lineToPoint:NSMakePoint(16,16)];
126
+ [[NSColor whiteColor] setStroke]; accent.lineWidth = 1; [accent stroke];
127
+ [image unlockFocus];
128
+ cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(2 * size / 28, 2 * size / 28)];
129
+ });
130
+ if (cursor) {
131
+ [self addCursorRect:self.bounds cursor:cursor];
132
+ if (!self.geaCursorMonitor) {
133
+ __weak GeaContentView *weakView = self;
134
+ NSMutableArray<NSCursor *> *frames = [NSMutableArray array];
135
+ for (int i=0;i<16;i++) {
136
+ const double t=i/15.0;
137
+ const double scale=1.0-0.17*std::sin(M_PI*t);
138
+ NSSize size=cursor.image.size;
139
+ NSImage *frame=[[NSImage alloc] initWithSize:size];
140
+ [frame lockFocus];
141
+ const NSPoint hotspot=cursor.hotSpot;
142
+ [cursor.image drawInRect:NSMakeRect(hotspot.x*(1-scale),(size.height-hotspot.y)*(1-scale),size.width*scale,size.height*scale) fromRect:NSZeroRect operation:NSCompositingOperationSourceOver fraction:1];
143
+ [frame unlockFocus];
144
+ [frames addObject:[[NSCursor alloc] initWithImage:frame hotSpot:hotspot]];
145
+ }
146
+ self.geaCursorMonitor=[NSEvent addLocalMonitorForEventsMatchingMask:(NSEventMaskMouseMoved | NSEventMaskLeftMouseDragged | NSEventMaskLeftMouseDown | NSEventMaskLeftMouseUp) handler:^NSEvent *(NSEvent *event) {
147
+ GeaContentView *view=weakView;
148
+ if (!view || event.window!=view.window) return event;
149
+ NSPoint point=[view convertPoint:event.locationInWindow fromView:nil];
150
+ auto &tree=gea::embedded::ui::Tree::instance();
151
+ const bool inside=NSPointInRect(point,view.bounds);
152
+ const int x=std::lround(point.x), y=std::lround(view.bounds.size.height-point.y);
153
+ if (!std::getenv("GEA_MACOS_REPLAY_PLAN") && geaCustomInputRoot()>=0) {
154
+ tree.pointerHover(inside?x:-1,inside?y:-1);
155
+ if (event.type==NSEventTypeLeftMouseDown && inside && !geaOwnsContourPress(x,y)) tree.pointerDown(x,y);
156
+ if (event.type==NSEventTypeLeftMouseUp) { tree.pointerUp(); gea::embedded::ui::StyleSheet::instance().hoverChanged(); }
157
+ }
158
+ if (!inside || event.type!=NSEventTypeLeftMouseDown) return event;
159
+ // Gesture recognizers can consume the up event; never leave a press latched.
160
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW,180*NSEC_PER_MSEC),dispatch_get_main_queue(),^{
161
+ if (!(NSEvent.pressedMouseButtons & 1)) {
162
+ gea::embedded::ui::Tree::instance().pointerUp();
163
+ gea::embedded::ui::StyleSheet::instance().hoverChanged();
164
+ }
165
+ });
166
+ for (int i=0;i<16;i++) dispatch_after(dispatch_time(DISPATCH_TIME_NOW,(int64_t)(i*0.008*NSEC_PER_SEC)),dispatch_get_main_queue(),^{
167
+ GeaContentView *current=weakView;
168
+ if (current.window.isKeyWindow && NSApp.isActive && NSPointInRect([current convertPoint:current.window.mouseLocationOutsideOfEventStream fromView:nil],current.bounds)) [frames[i] set];
169
+ });
170
+ return event;
171
+ }];
172
+ }
173
+ }
174
+ }
175
+ - (void)updateTrackingAreas {
176
+ [super updateTrackingAreas];
177
+ if (self.geaPointerTracking) [self removeTrackingArea:self.geaPointerTracking];
178
+ self.geaPointerTracking=[[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil];
179
+ [self addTrackingArea:self.geaPointerTracking];
180
+ }
181
+ - (void)mouseExited:(NSEvent *)event {
182
+ if (geaCustomInputRoot()>=0 && !std::getenv("GEA_MACOS_REPLAY_PLAN")) gea::embedded::ui::Tree::instance().pointerHover(-1,-1);
183
+ [super mouseExited:event];
184
+ }
185
+ - (void)dealloc {
186
+ if (self.geaCursorMonitor) [NSEvent removeMonitor:self.geaCursorMonitor];
187
+ }
188
+ - (void)geaPollGamepad {
189
+ if (!NSApp.isActive || !self.window.isKeyWindow || geaCustomInputRoot()<0) {
190
+ self.geaGamepadButtons=0; self.geaGamepadRepeat=0; return;
191
+ }
192
+ GCController *controller=nil;
193
+ for (GCController *candidate in GCController.controllers) if (candidate.extendedGamepad) { controller=candidate; break; }
194
+ if (controller!=self.geaActiveController) { self.geaActiveController=controller; self.geaGamepadButtons=0; self.geaGamepadRepeat=0; }
195
+ GCExtendedGamepad *pad=controller.extendedGamepad;
196
+ if (!pad) { self.geaGamepadButtons=0; return; }
197
+ // Axis dead zone, edge-triggered face buttons, delayed directional repeat.
198
+ const bool buttons[]={pad.dpad.up.isPressed || pad.leftThumbstick.yAxis.value>0.55f,
199
+ pad.dpad.down.isPressed || pad.leftThumbstick.yAxis.value < -0.55f,
200
+ pad.dpad.left.isPressed || pad.leftThumbstick.xAxis.value < -0.55f,
201
+ pad.dpad.right.isPressed || pad.leftThumbstick.xAxis.value>0.55f,
202
+ pad.buttonA.isPressed,pad.buttonB.isPressed,pad.buttonY.isPressed,pad.buttonX.isPressed,
203
+ pad.leftShoulder.isPressed,pad.rightShoulder.isPressed,pad.leftTrigger.isPressed,pad.rightTrigger.isPressed,
204
+ pad.leftThumbstickButton.isPressed,pad.rightThumbstickButton.isPressed,pad.buttonMenu.isPressed};
205
+ unsigned int current=0; for(int i=0;i<15;i++) if(buttons[i])current|=1u<<i;
206
+ unsigned int pressed=current & ~self.geaGamepadButtons;
207
+ const NSTimeInterval now=NSProcessInfo.processInfo.systemUptime;
208
+ const unsigned int directions=current & 15;
209
+ if(pressed & 15) self.geaGamepadRepeat=now+0.38;
210
+ else if(directions && now>=self.geaGamepadRepeat) { pressed|=directions; self.geaGamepadRepeat=now+0.12; }
211
+ self.geaGamepadButtons=current;
212
+ for(int i=0;i<15;i++) if(pressed & (1u<<i)) [self geaSendKey:2000+i];
213
+ }
66
214
  - (BOOL)isFlipped { return NO; }
215
+ - (BOOL)acceptsFirstResponder { return geaCustomInputRoot()>=0; }
216
+ - (void)geaSendKey:(int)code {
217
+ const int root=geaCustomInputRoot();if(root<0)return;
218
+ gea::framework::events::PointerEvent event;
219
+ event.type=gea::framework::events::PointerEventType::KeyDown;
220
+ event.targetId=root;event.keyCode=code;
221
+ if(!gea::embedded::ui::dispatchDocumentKeyDown(event)) gea::embedded::ui::Tree::instance().dispatchEvent(event);
222
+ }
223
+ - (void)keyDown:(NSEvent *)event {
224
+ if(geaCustomInputRoot()<0){[super keyDown:event];return;}
225
+ if((event.modifierFlags & NSEventModifierFlagCommand) && [[event.charactersIgnoringModifiers lowercaseString] isEqualToString:@"a"]){[self geaSendKey:1001];return;}
226
+ if([event.charactersIgnoringModifiers isEqualToString:@" "]){[self geaSendKey:32];if(![self hasMarkedText])[self insertText:@" " replacementRange:NSMakeRange(NSNotFound,0)];return;}
227
+ [self interpretKeyEvents:@[event]];
228
+ }
229
+ - (void)insertText:(id)text replacementRange:(NSRange)range {
230
+ (void)range;const int root=geaCustomInputRoot();if(root<0)return;
231
+ NSString *value=[text isKindOfClass:[NSAttributedString class]]?[text string]:text;
232
+ auto &tree=gea::embedded::ui::Tree::instance();
233
+ tree.setAttribute(root,"value",value.UTF8String?:"");
234
+ gea::framework::events::PointerEvent event;event.type=gea::framework::events::PointerEventType::Input;event.targetId=root;tree.dispatchEvent(event);
235
+ self.geaMarkedText=nil;
236
+ }
237
+ - (void)doCommandBySelector:(SEL)selector {
238
+ int code=0;
239
+ if(selector==@selector(deleteBackward:))code=8;
240
+ else if(selector==@selector(deleteForward:))code=46;
241
+ else if(selector==@selector(moveLeft:))code=37;
242
+ else if(selector==@selector(moveRight:))code=39;
243
+ else if(selector==@selector(moveUp:))code=38;
244
+ else if(selector==@selector(moveDown:))code=40;
245
+ else if(selector==@selector(moveToBeginningOfLine:))code=36;
246
+ else if(selector==@selector(moveToEndOfLine:))code=35;
247
+ else if(selector==@selector(insertNewline:))code=13;
248
+ else if(selector==@selector(insertTab:))code=9;
249
+ else if(selector==@selector(cancelOperation:))code=27;
250
+ if(code)[self geaSendKey:code];
251
+ }
252
+ - (void)paste:(id)sender { (void)sender;NSString *value=[[NSPasteboard generalPasteboard] stringForType:NSPasteboardTypeString];if(value)[self insertText:value replacementRange:NSMakeRange(NSNotFound,0)]; }
253
+ - (void)copy:(id)sender {
254
+ (void)sender;const int root=geaCustomInputRoot();if(root<0)return;
255
+ NSString *text=[NSString stringWithUTF8String:gea::embedded::ui::Tree::instance().getAttribute(root,"data-gea-selected-text")];
256
+ if(text.length){NSPasteboard *board=[NSPasteboard generalPasteboard];[board clearContents];[board setString:text forType:NSPasteboardTypeString];}
257
+ }
258
+ - (void)cut:(id)sender { [self copy:sender];[self geaSendKey:46]; }
259
+ - (void)selectAll:(id)sender { (void)sender;[self geaSendKey:1001]; }
260
+ - (BOOL)hasMarkedText { return self.geaMarkedText.length>0; }
261
+ - (NSRange)markedRange { return [self hasMarkedText]?NSMakeRange(0,self.geaMarkedText.length):NSMakeRange(NSNotFound,0); }
262
+ - (NSRange)selectedRange { return NSMakeRange(NSNotFound,0); }
263
+ - (void)setMarkedText:(id)text selectedRange:(NSRange)selection replacementRange:(NSRange)replacement {
264
+ (void)selection;(void)replacement;self.geaMarkedText=[text isKindOfClass:[NSAttributedString class]]?text:[[NSAttributedString alloc] initWithString:text];
265
+ }
266
+ - (void)unmarkText { self.geaMarkedText=nil; }
267
+ - (NSArray<NSAttributedStringKey> *)validAttributesForMarkedText { return @[]; }
268
+ - (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(NSRangePointer)actual { (void)range;if(actual)*actual=NSMakeRange(NSNotFound,0);return nil; }
269
+ - (NSUInteger)characterIndexForPoint:(NSPoint)point { (void)point;return NSNotFound; }
270
+ - (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actual {
271
+ (void)range;if(actual)*actual=NSMakeRange(NSNotFound,0);return [self.window convertRectToScreen:[self convertRect:self.bounds toView:nil]];
272
+ }
67
273
  @end
68
274
 
69
275
  @interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>
@@ -152,6 +358,10 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
152
358
  // Application::init — apps gate remote fetches on wifi().connected()
153
359
  // (e.g. maps skips tile downloads while it reads false).
154
360
  gea::macos::installWifiDriver();
361
+ // macOS has an available host filesystem before app initialization.
362
+ // ImageService gates external reads on this provider just as device targets
363
+ // gate theirs on mounted storage.
364
+ gea::platform::storage::setMountProvider(+[]() { return true; });
155
365
  const bool thermalrightTarget = gea::macos::thermalright::enabled();
156
366
  if (!thermalrightTarget) [self installMainMenu];
157
367
 
@@ -269,6 +479,9 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
269
479
 
270
480
  - (void)startFrameTimer
271
481
  {
482
+ #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
483
+ gea_macos_debugger_start();
484
+ #endif
272
485
  if (self.frameTimer) return;
273
486
  const BOOL thermalrightTarget = gea::macos::thermalright::enabled();
274
487
  if (!thermalrightTarget) {
@@ -404,6 +617,7 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
404
617
  static const bool profile = std::getenv("GEA_NATIVE_FRAME_PROFILE") != nullptr;
405
618
  using Clock = std::chrono::steady_clock;
406
619
  const auto applicationBegin = profile ? Clock::now() : Clock::time_point{};
620
+ [self.rootView geaPollGamepad];
407
621
  gea::framework::app::Application::frame(gea_embedded_now_ms());
408
622
  if (profile) self.geaProfileApplicationMs = std::chrono::duration<double, std::milli>(Clock::now() - applicationBegin).count();
409
623
  auto &tree = gea::embedded::ui::Tree::instance();
@@ -431,9 +645,9 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
431
645
  else
432
646
  singleAppAnimScanned = true;
433
647
  gea::css::DeclarativeAnimations::scanAndStart(gea_embedded_now_ms());
434
- gea::embedded::ui::StyleSheet::instance().startCssAnimations(gea_embedded_now_ms());
435
648
  }
436
649
  }
650
+ gea::embedded::ui::StyleSheet::instance().startCssAnimations(gea_embedded_now_ms());
437
651
  gea::css::AnimationEngine::instance().tick(
438
652
  static_cast<std::uint32_t>(gea_embedded_now_ms()));
439
653
 
@@ -474,6 +688,96 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
474
688
  tree.computeLayout(root, w, h);
475
689
  gea::macos::MacosRenderer::instance().sync(self.rootView, root);
476
690
 
691
+
692
+ // Opt-in deterministic Gea event replay for recorded demos. No OS events or
693
+ // application state shortcuts; the same tree handlers process every step.
694
+ if (const char *planPath = getenv("GEA_MACOS_REPLAY_PLAN")) {
695
+ static NSArray *steps = nil;
696
+ static NSUInteger nextStep = 0;
697
+ static NSDictionary *pending = nil;
698
+ static int settleFrames = 0;
699
+ static double startedAt = 0;
700
+ auto replayLog = [&](NSDictionary *entry) {
701
+ const char *logPath = getenv("GEA_MACOS_REPLAY_LOG");
702
+ if (!logPath) return;
703
+ NSData *json = [NSJSONSerialization dataWithJSONObject:entry options:0 error:nil];
704
+ FILE *file = std::fopen(logPath, "a");
705
+ if (file) { std::fwrite(json.bytes, 1, json.length, file); std::fputc('\n', file); std::fclose(file); }
706
+ };
707
+ auto replayFail = [&](NSString *reason) {
708
+ replayLog(@{@"error":reason}); NSLog(@"[gea-replay] %@", reason); std::exit(2);
709
+ };
710
+ if (!steps) {
711
+ NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithUTF8String:planPath]];
712
+ NSDictionary *plan = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
713
+ if (![plan isKindOfClass:[NSDictionary class]] || ![plan[@"steps"] isKindOfClass:[NSArray class]]) replayFail(@"Invalid replay plan");
714
+ steps = plan[@"steps"];
715
+ }
716
+ if (!startedAt) {
717
+ const char *marker = getenv("GEA_MACOS_REPLAY_START");
718
+ NSString *value = marker ? [NSString stringWithContentsOfFile:[NSString stringWithUTF8String:marker] encoding:NSUTF8StringEncoding error:nil] : nil;
719
+ startedAt = value.doubleValue;
720
+ }
721
+ if (startedAt) {
722
+ const double elapsed = NSDate.date.timeIntervalSince1970 - startedAt;
723
+ if (pending && ++settleFrames >= 3) {
724
+ NSString *expected = pending[@"expect"];
725
+ std::string text;
726
+ for (int i=0;i<tree.nodeCount();++i) { text += tree.node(i).text; text += " "; }
727
+ if (expected.length && text.find(expected.UTF8String) == std::string::npos) replayFail([NSString stringWithFormat:@"Step %@ did not show %@", pending[@"label"], expected]);
728
+ if (NSDictionary *check=pending[@"expectTextIn"]) {
729
+ auto subtreeText = [&](auto &&visit, int node) -> std::string {
730
+ std::string result=tree.node(node).text; result += " ";
731
+ for(int child=tree.node(node).first_child;child>=0;child=tree.node(child).next_sibling) result += visit(visit,child);
732
+ return result;
733
+ };
734
+ bool matched=false;
735
+ for(int i=0;i<tree.nodeCount();++i) if(tree.className(i).find([check[@"class"] UTF8String])!=std::string::npos) {
736
+ std::string raw=subtreeText(subtreeText,i);
737
+ NSString *value=[NSString stringWithUTF8String:raw.c_str()];
738
+ NSMutableArray *words=[NSMutableArray array];
739
+ for(NSString *word in [value componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]) if(word.length) [words addObject:word];
740
+ if([[words componentsJoinedByString:@" "] containsString:check[@"contains"]]) matched=true;
741
+ }
742
+ if(!matched) replayFail([NSString stringWithFormat:@"Step %@ did not show %@ in %@",pending[@"label"],check[@"contains"],check[@"class"]]);
743
+ }
744
+ replayLog(@{@"verified":pending[@"label"], @"elapsed":@(elapsed)});
745
+ pending = nil;
746
+ }
747
+ if (!pending && nextStep < steps.count && elapsed >= [steps[nextStep][@"at"] doubleValue]) {
748
+ NSDictionary *step = steps[nextStep++];
749
+ using gea::framework::events::PointerEvent;
750
+ using gea::framework::events::PointerEventType;
751
+ if (NSString *text = step[@"text"]) {
752
+ const int inputRoot = geaCustomInputRoot();
753
+ if (inputRoot < 0) replayFail(@"No Gea input root");
754
+ tree.setAttribute(inputRoot,"value",text.UTF8String);
755
+ PointerEvent event; event.type=PointerEventType::Input; event.targetId=inputRoot; tree.dispatchEvent(event);
756
+ } else {
757
+ const int x=[step[@"x"] intValue], y=[step[@"y"] intValue];
758
+ NSPoint point=NSMakePoint(x,self.rootView.bounds.size.height-y);
759
+ NSView *hit=[self.rootView hitTest:[self.rootView convertPoint:point toView:self.rootView.superview]];
760
+ int target=gea::macos::nodeIdForView(hit), ancestor=target;
761
+ const std::string expected=[step[@"target"] UTF8String];
762
+ while (ancestor>=0 && tree.className(ancestor).find(expected)==std::string::npos) ancestor=tree.node(ancestor).parent;
763
+ if (target<0 || ancestor<0) replayFail([NSString stringWithFormat:@"Wrong hit target for %@",step[@"label"]]);
764
+ tree.pointerHover(x,y);
765
+ if (!geaOwnsContourPress(x,y)) tree.pointerDown(x,y);
766
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW,80*NSEC_PER_MSEC),dispatch_get_main_queue(),^{
767
+ gea::embedded::ui::Tree::instance().pointerUp();
768
+ });
769
+ for (auto phase : {PointerEventType::TouchStart,PointerEventType::TouchEnd,PointerEventType::Click}) {
770
+ PointerEvent event; event.type=phase; event.targetId=target; event.pointerId=1;
771
+ event.x=x; event.y=y; event.clientX=x; event.clientY=y; event.pageX=x; event.pageY=y;
772
+ tree.dispatchEvent(event);
773
+ }
774
+ }
775
+ replayLog(@{@"action":step[@"label"], @"elapsed":@(elapsed), @"index":@(nextStep-1)});
776
+ pending=step; settleFrames=0;
777
+ }
778
+ }
779
+ }
780
+
477
781
  if (const char *clickEnv = getenv("GEA_MACOS_SYNTH_CLICK")) {
478
782
  static int frameCount = 0;
479
783
  ++frameCount;
@@ -569,6 +873,17 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
569
873
  {
570
874
  (void)notification;
571
875
  if (gea::macos::thermalright::enabled()) return;
876
+ if (!self.splitShell) {
877
+ const NSSize size = self.rootView.bounds.size;
878
+ const int width = static_cast<int>(size.width), height = static_cast<int>(size.height);
879
+ if (width > 0 && height > 0 &&
880
+ (width != gea::embedded::ui::Document::preferredMountWidth() ||
881
+ height != gea::embedded::ui::Document::preferredMountHeight())) {
882
+ gea::embedded::ui::Document::setPreferredMountSize(width, height);
883
+ // AppKit layout uses points; a CSS px is one point, including on Retina.
884
+ gea::embedded::ui::setViewportMetrics(width, height, 1.0);
885
+ }
886
+ }
572
887
  // Sync immediately on resize end too; the live-mode timer covers the
573
888
  // drag, this handles the final snap.
574
889
  [self tick];
@@ -10,6 +10,9 @@ struct NSArray;
10
10
 
11
11
  namespace gea::macos {
12
12
 
13
+ // Publish arranged geometry for app-owned Gea controls before dispatch.
14
+ void publishControlEventBounds(int nodeId);
15
+
13
16
  class MacosRenderer {
14
17
  public:
15
18
  static MacosRenderer &instance();