@geastack/apple 0.2.14 → 0.2.16
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/dist/index.js +7 -0
- package/generated/ActivityKit.d.ts +3 -0
- package/generated/AppKit.d.ts +5 -0
- package/generated/CoreGraphics.d.ts +3 -0
- package/generated/CoreLocation.d.ts +1 -0
- package/generated/CoreMedia.d.ts +1 -0
- package/generated/Dispatch.d.ts +2 -0
- package/generated/Foundation.d.ts +7 -0
- package/generated/MapKit.d.ts +1 -0
- package/generated/Metal.d.ts +2 -0
- package/generated/Security.d.ts +3 -0
- package/generated/SwiftData.d.ts +5 -0
- package/generated/UIKit.d.ts +1 -0
- package/generated/UserNotifications.d.ts +3 -0
- package/package.json +7 -7
- package/targets/ios/generate-xcode-project.mjs +5 -0
- package/targets/macos/app-compiler-plugins.mjs +22 -0
- package/targets/macos/build-macos.sh +108 -6
- package/targets/macos/generate-resident-entry.mjs +1 -1
- package/targets/macos/main/canvas_view.mm +8 -8
- package/targets/macos/main/color_convert.h +3 -3
- package/targets/macos/main/color_convert.mm +12 -12
- package/targets/macos/main/font_registry.h +2 -0
- package/targets/macos/main/font_registry.mm +72 -51
- package/targets/macos/main/image_bridge.h +5 -2
- package/targets/macos/main/image_bridge.mm +47 -9
- package/targets/macos/main/macos_background_test.h +54 -0
- package/targets/macos/main/macos_control_admission.h +13 -0
- package/targets/macos/main/macos_display.mm +29 -27
- package/targets/macos/main/macos_key_event.h +73 -0
- package/targets/macos/main/macos_main.mm +410 -14
- package/targets/macos/main/macos_renderer.h +5 -0
- package/targets/macos/main/macos_renderer.mm +717 -80
- package/targets/macos/main/press_bridge.h +21 -3
- package/targets/macos/main/press_bridge.mm +126 -26
- package/targets/macos/sync-resources.mjs +24 -2
|
@@ -1,19 +1,51 @@
|
|
|
1
|
+
#include <cstdio>
|
|
2
|
+
#include "host/timers.h"
|
|
3
|
+
#include "host/worker.h"
|
|
4
|
+
#include "ui/tree_events.h"
|
|
1
5
|
#import <Cocoa/Cocoa.h>
|
|
6
|
+
#import <GameController/GameController.h>
|
|
2
7
|
#import <QuartzCore/CADisplayLink.h>
|
|
3
8
|
|
|
9
|
+
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
10
|
+
extern void gea_macos_debugger_start();
|
|
11
|
+
#endif
|
|
12
|
+
|
|
4
13
|
#include "font_registry.h"
|
|
5
14
|
#include "macos_native_shell.h"
|
|
6
15
|
#include "macos_renderer.h"
|
|
16
|
+
#include "macos_background_test.h"
|
|
7
17
|
#include "press_bridge.h"
|
|
8
18
|
#include "thermalright_hid_display.h"
|
|
9
19
|
|
|
20
|
+
// Optional app-owned process cleanup, before the native runtime/static teardown.
|
|
21
|
+
// No callback on a skin/resident-app replacement; this is actual process exit.
|
|
22
|
+
extern "C" __attribute__((weak)) void gea_native_application_terminate() {}
|
|
23
|
+
namespace {
|
|
24
|
+
void geaRetireNativeProcess() noexcept {
|
|
25
|
+
static bool retired = false; // Actual process exit on the application thread.
|
|
26
|
+
if (retired) return;
|
|
27
|
+
retired = true;
|
|
28
|
+
try { gea_native_application_terminate(); }
|
|
29
|
+
catch (...) { std::fputs("Gea: application termination callback failed; retiring SDK callbacks\n", stderr); }
|
|
30
|
+
try { gea::host::retireScheduledCallbacks(); }
|
|
31
|
+
catch (...) { std::fputs("Gea: scheduled callback retirement failed\n", stderr); }
|
|
32
|
+
gea::embedded::ui::retireNativeEventRealm();
|
|
33
|
+
try { gea::host::workers::retireMainContext(); }
|
|
34
|
+
catch (...) { std::fputs("Gea: main Context retirement failed\n", stderr); }
|
|
35
|
+
}
|
|
36
|
+
struct GeaNativeTerminationGuard {
|
|
37
|
+
~GeaNativeTerminationGuard(){geaRetireNativeProcess();}
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
10
41
|
namespace gea::macos { void installAppLauncherPlatform(const char *currentAppId); }
|
|
11
|
-
namespace gea::macos { void installWifiDriver(); }
|
|
42
|
+
namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view); }
|
|
12
43
|
|
|
13
44
|
#include "app.h"
|
|
14
45
|
#include "css/declarative.h"
|
|
15
46
|
#include "css/engine.h"
|
|
16
47
|
#include "display.h"
|
|
48
|
+
#include "platform/file_cache.h"
|
|
17
49
|
#if __has_include("resident_apps.h")
|
|
18
50
|
#include "resident_apps.h"
|
|
19
51
|
#define GEA_MACOS_HAS_RESIDENT_APPS 1
|
|
@@ -57,13 +89,259 @@ static void gea_macos_smoke_log(const char *message)
|
|
|
57
89
|
#define GEA_MACOS_HAS_APPLE_NATIVE_BRIDGE 1
|
|
58
90
|
#endif
|
|
59
91
|
|
|
60
|
-
|
|
92
|
+
// App-owned controls consume ordinary Gea events. AppKit supplies only the
|
|
93
|
+
// window and text services, including keyboard layout and IME composition.
|
|
94
|
+
static int geaCustomInputRoot()
|
|
95
|
+
{
|
|
96
|
+
auto &tree = gea::embedded::ui::Tree::instance();
|
|
97
|
+
for (int i=0;i<tree.nodeCount();++i)
|
|
98
|
+
if (std::strcmp(tree.getAttribute(i,"data-gea-inputs"),"true")==0) return i;
|
|
99
|
+
return -1;
|
|
100
|
+
}
|
|
101
|
+
// Keyboard routing is available to ordinary mounted native apps as well as
|
|
102
|
+
// app-owned custom editors. Do not widen the pointer/custom-editor contract.
|
|
103
|
+
static int geaKeyboardInputRoot() {
|
|
104
|
+
const int custom=geaCustomInputRoot();
|
|
105
|
+
return custom>=0?custom:gea::embedded::ui::Tree::instance().mountedRoot();
|
|
106
|
+
}
|
|
107
|
+
static int geaKeyboardTarget(int root) {
|
|
108
|
+
auto &tree=gea::embedded::ui::Tree::instance();
|
|
109
|
+
const int active=tree.activeInputId();
|
|
110
|
+
for(int id=active;id>=0 && id<tree.nodeCount();id=tree.node(id).parent)
|
|
111
|
+
if(id==root)return active;
|
|
112
|
+
return root;
|
|
113
|
+
}
|
|
114
|
+
#include "macos_key_event.h"
|
|
115
|
+
// Authored silhouettes own their press layer; a rectangular engine fill would
|
|
116
|
+
// paint outside their transparent corners. Ancestors cover image/text hits.
|
|
117
|
+
static bool geaOwnsContourPress(int x, int y) {
|
|
118
|
+
auto &tree=gea::embedded::ui::Tree::instance();
|
|
119
|
+
for (int id=tree.hitTestNode(x,y);id>=0;id=tree.node(id).parent)
|
|
120
|
+
if (std::strcmp(tree.getAttribute(id,"data-gea-contour"),"true")==0) return true;
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
@interface GeaContentView : NSView <NSTextInputClient>
|
|
124
|
+
@property(nonatomic,copy) NSAttributedString *geaMarkedText;
|
|
125
|
+
@property(nonatomic) BOOL geaInterpretingDispatchedKey;
|
|
126
|
+
@property(nonatomic,strong) GCController *geaActiveController;
|
|
127
|
+
@property(nonatomic) unsigned int geaGamepadButtons;
|
|
128
|
+
@property(nonatomic) NSTimeInterval geaGamepadRepeat;
|
|
129
|
+
@property(nonatomic,strong) id geaCursorMonitor;
|
|
130
|
+
@property(nonatomic,strong) NSTrackingArea *geaPointerTracking;
|
|
61
131
|
@end
|
|
62
|
-
|
|
63
132
|
@implementation GeaContentView
|
|
64
|
-
//
|
|
65
|
-
//
|
|
133
|
+
// Optional app cursor is scoped to the content bounds; AppKit restores the
|
|
134
|
+
// standard pointer over the title bar, other windows, and other applications.
|
|
135
|
+
- (void)resetCursorRects {
|
|
136
|
+
[super resetCursorRects];
|
|
137
|
+
static NSCursor *cursor = nil;
|
|
138
|
+
static dispatch_once_t once;
|
|
139
|
+
dispatch_once(&once, ^{
|
|
140
|
+
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"window.json"];
|
|
141
|
+
NSData *data = [NSData dataWithContentsOfFile:path];
|
|
142
|
+
NSDictionary *config = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
143
|
+
if (![config isKindOfClass:[NSDictionary class]]) return;
|
|
144
|
+
NSDictionary *window = config[@"window"] ?: config;
|
|
145
|
+
NSDictionary *spec = window[@"cursor"];
|
|
146
|
+
if (![spec isKindOfClass:[NSDictionary class]] || ![spec[@"style"] isEqual:@"angular"]) return;
|
|
147
|
+
CGFloat size = [spec[@"size"] respondsToSelector:@selector(doubleValue)] ? [spec[@"size"] doubleValue] : 28;
|
|
148
|
+
size = std::clamp((double)size, 20.0, 48.0);
|
|
149
|
+
NSImage *image = [[NSImage alloc] initWithSize:NSMakeSize(size, size + 6)];
|
|
150
|
+
[image lockFocus];
|
|
151
|
+
NSAffineTransform *transform = [NSAffineTransform transform];
|
|
152
|
+
[transform translateXBy:0 yBy:size + 6];
|
|
153
|
+
[transform scaleXBy:size / 28 yBy:-size / 28];
|
|
154
|
+
[transform concat];
|
|
155
|
+
NSBezierPath *arrow = [NSBezierPath bezierPath];
|
|
156
|
+
[arrow moveToPoint:NSMakePoint(2,2)];
|
|
157
|
+
[arrow lineToPoint:NSMakePoint(23,18)];
|
|
158
|
+
[arrow lineToPoint:NSMakePoint(12,21)];
|
|
159
|
+
[arrow lineToPoint:NSMakePoint(3,29)];
|
|
160
|
+
[arrow closePath];
|
|
161
|
+
[[NSColor colorWithCalibratedRed:0.04 green:0.12 blue:0.16 alpha:1] setFill];
|
|
162
|
+
[arrow fill];
|
|
163
|
+
[[NSColor colorWithCalibratedRed:0.69 green:0.93 blue:0.94 alpha:1] setStroke];
|
|
164
|
+
arrow.lineWidth = 1.6; [arrow stroke];
|
|
165
|
+
NSBezierPath *accent = [NSBezierPath bezierPath];
|
|
166
|
+
[accent moveToPoint:NSMakePoint(5,8)]; [accent lineToPoint:NSMakePoint(16,16)];
|
|
167
|
+
[[NSColor whiteColor] setStroke]; accent.lineWidth = 1; [accent stroke];
|
|
168
|
+
[image unlockFocus];
|
|
169
|
+
cursor = [[NSCursor alloc] initWithImage:image hotSpot:NSMakePoint(2 * size / 28, 2 * size / 28)];
|
|
170
|
+
});
|
|
171
|
+
if (cursor) {
|
|
172
|
+
[self addCursorRect:self.bounds cursor:cursor];
|
|
173
|
+
if (!self.geaCursorMonitor) {
|
|
174
|
+
__weak GeaContentView *weakView = self;
|
|
175
|
+
NSMutableArray<NSCursor *> *frames = [NSMutableArray array];
|
|
176
|
+
for (int i=0;i<16;i++) {
|
|
177
|
+
const double t=i/15.0;
|
|
178
|
+
const double scale=1.0-0.17*std::sin(M_PI*t);
|
|
179
|
+
NSSize size=cursor.image.size;
|
|
180
|
+
NSImage *frame=[[NSImage alloc] initWithSize:size];
|
|
181
|
+
[frame lockFocus];
|
|
182
|
+
const NSPoint hotspot=cursor.hotSpot;
|
|
183
|
+
[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];
|
|
184
|
+
[frame unlockFocus];
|
|
185
|
+
[frames addObject:[[NSCursor alloc] initWithImage:frame hotSpot:hotspot]];
|
|
186
|
+
}
|
|
187
|
+
self.geaCursorMonitor=[NSEvent addLocalMonitorForEventsMatchingMask:(NSEventMaskMouseMoved | NSEventMaskLeftMouseDragged | NSEventMaskLeftMouseDown | NSEventMaskLeftMouseUp) handler:^NSEvent *(NSEvent *event) {
|
|
188
|
+
GeaContentView *view=weakView;
|
|
189
|
+
if (!view || event.window!=view.window) return event;
|
|
190
|
+
NSPoint point=[view convertPoint:event.locationInWindow fromView:nil];
|
|
191
|
+
auto &tree=gea::embedded::ui::Tree::instance();
|
|
192
|
+
const bool inside=NSPointInRect(point,view.bounds);
|
|
193
|
+
const int x=std::lround(point.x), y=std::lround(view.bounds.size.height-point.y);
|
|
194
|
+
if (!std::getenv("GEA_MACOS_REPLAY_PLAN") && geaCustomInputRoot()>=0) {
|
|
195
|
+
tree.pointerHover(inside?x:-1,inside?y:-1);
|
|
196
|
+
if (event.type==NSEventTypeLeftMouseDown && inside && !geaOwnsContourPress(x,y)) tree.pointerDown(x,y);
|
|
197
|
+
if (event.type==NSEventTypeLeftMouseUp) { tree.pointerUp(); gea::embedded::ui::StyleSheet::instance().hoverChanged(); }
|
|
198
|
+
}
|
|
199
|
+
if (!inside || event.type!=NSEventTypeLeftMouseDown) return event;
|
|
200
|
+
// Gesture recognizers can consume the up event; never leave a press latched.
|
|
201
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,180*NSEC_PER_MSEC),dispatch_get_main_queue(),^{
|
|
202
|
+
if (!(NSEvent.pressedMouseButtons & 1)) {
|
|
203
|
+
gea::embedded::ui::Tree::instance().pointerUp();
|
|
204
|
+
gea::embedded::ui::StyleSheet::instance().hoverChanged();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
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(),^{
|
|
208
|
+
GeaContentView *current=weakView;
|
|
209
|
+
if (current.window.isKeyWindow && NSApp.isActive && NSPointInRect([current convertPoint:current.window.mouseLocationOutsideOfEventStream fromView:nil],current.bounds)) [frames[i] set];
|
|
210
|
+
});
|
|
211
|
+
return event;
|
|
212
|
+
}];
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
- (void)updateTrackingAreas {
|
|
217
|
+
[super updateTrackingAreas];
|
|
218
|
+
if (self.geaPointerTracking) [self removeTrackingArea:self.geaPointerTracking];
|
|
219
|
+
self.geaPointerTracking=[[NSTrackingArea alloc] initWithRect:NSZeroRect options:(NSTrackingMouseMoved | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect) owner:self userInfo:nil];
|
|
220
|
+
[self addTrackingArea:self.geaPointerTracking];
|
|
221
|
+
}
|
|
222
|
+
- (void)mouseExited:(NSEvent *)event {
|
|
223
|
+
if (geaCustomInputRoot()>=0 && !std::getenv("GEA_MACOS_REPLAY_PLAN")) gea::embedded::ui::Tree::instance().pointerHover(-1,-1);
|
|
224
|
+
[super mouseExited:event];
|
|
225
|
+
}
|
|
226
|
+
- (void)dealloc {
|
|
227
|
+
if (self.geaCursorMonitor) [NSEvent removeMonitor:self.geaCursorMonitor];
|
|
228
|
+
}
|
|
229
|
+
- (void)geaPollGamepad {
|
|
230
|
+
if (!NSApp.isActive || !self.window.isKeyWindow || geaCustomInputRoot()<0) {
|
|
231
|
+
self.geaGamepadButtons=0; self.geaGamepadRepeat=0; return;
|
|
232
|
+
}
|
|
233
|
+
GCController *controller=nil;
|
|
234
|
+
for (GCController *candidate in GCController.controllers) if (candidate.extendedGamepad) { controller=candidate; break; }
|
|
235
|
+
if (controller!=self.geaActiveController) { self.geaActiveController=controller; self.geaGamepadButtons=0; self.geaGamepadRepeat=0; }
|
|
236
|
+
GCExtendedGamepad *pad=controller.extendedGamepad;
|
|
237
|
+
if (!pad) { self.geaGamepadButtons=0; return; }
|
|
238
|
+
// Axis dead zone, edge-triggered face buttons, delayed directional repeat.
|
|
239
|
+
const bool buttons[]={pad.dpad.up.isPressed || pad.leftThumbstick.yAxis.value>0.55f,
|
|
240
|
+
pad.dpad.down.isPressed || pad.leftThumbstick.yAxis.value < -0.55f,
|
|
241
|
+
pad.dpad.left.isPressed || pad.leftThumbstick.xAxis.value < -0.55f,
|
|
242
|
+
pad.dpad.right.isPressed || pad.leftThumbstick.xAxis.value>0.55f,
|
|
243
|
+
pad.buttonA.isPressed,pad.buttonB.isPressed,pad.buttonY.isPressed,pad.buttonX.isPressed,
|
|
244
|
+
pad.leftShoulder.isPressed,pad.rightShoulder.isPressed,pad.leftTrigger.isPressed,pad.rightTrigger.isPressed,
|
|
245
|
+
pad.leftThumbstickButton.isPressed,pad.rightThumbstickButton.isPressed,pad.buttonMenu.isPressed};
|
|
246
|
+
unsigned int current=0; for(int i=0;i<15;i++) if(buttons[i])current|=1u<<i;
|
|
247
|
+
unsigned int pressed=current & ~self.geaGamepadButtons;
|
|
248
|
+
const NSTimeInterval now=NSProcessInfo.processInfo.systemUptime;
|
|
249
|
+
const unsigned int directions=current & 15;
|
|
250
|
+
if(pressed & 15) self.geaGamepadRepeat=now+0.38;
|
|
251
|
+
else if(directions && now>=self.geaGamepadRepeat) { pressed|=directions; self.geaGamepadRepeat=now+0.12; }
|
|
252
|
+
self.geaGamepadButtons=current;
|
|
253
|
+
for(int i=0;i<15;i++) if(pressed & (1u<<i)) [self geaSendKey:2000+i];
|
|
254
|
+
}
|
|
66
255
|
- (BOOL)isFlipped { return NO; }
|
|
256
|
+
- (BOOL)acceptsFirstResponder { return geaKeyboardInputRoot()>=0; }
|
|
257
|
+
- (BOOL)becomeFirstResponder {const BOOL accepted=[super becomeFirstResponder];if(accepted)gea::macos::nativeRootFocusChanged(self,true,geaKeyboardTarget(geaKeyboardInputRoot()));return accepted;}
|
|
258
|
+
- (BOOL)resignFirstResponder {const BOOL accepted=[super resignFirstResponder];if(accepted)gea::macos::nativeRootFocusChanged(self,false,-1);return accepted;}
|
|
259
|
+
|
|
260
|
+
- (BOOL)geaDispatchKey:(gea::framework::events::PointerEvent &)event {
|
|
261
|
+
const int root=geaKeyboardInputRoot();if(root<0)return NO;
|
|
262
|
+
event.targetId=geaKeyboardTarget(root);
|
|
263
|
+
event.target=gea::framework::events::EventTarget(event.targetId);
|
|
264
|
+
event.currentTargetId=root;
|
|
265
|
+
event.currentTarget=gea::framework::events::EventTarget(root);
|
|
266
|
+
gea::embedded::ui::dispatchRootKeyEvent(event, geaCustomInputRoot()>=0);
|
|
267
|
+
return event.defaultPrevented;
|
|
268
|
+
}
|
|
269
|
+
- (void)geaSendKey:(int)code {
|
|
270
|
+
gea::framework::events::PointerEvent event;
|
|
271
|
+
event.type=gea::framework::events::PointerEventType::KeyDown;event.keyCode=code;
|
|
272
|
+
[self geaDispatchKey:event];
|
|
273
|
+
}
|
|
274
|
+
- (void)keyDown:(NSEvent *)native {
|
|
275
|
+
if(geaKeyboardInputRoot()<0){[super keyDown:native];return;}
|
|
276
|
+
auto event=geaNativeKey(native,[self hasMarkedText],false);
|
|
277
|
+
// Preserve the app-owned editor's historical select-all command only there.
|
|
278
|
+
const bool selectAll=geaCustomInputRoot()>=0 && event.metaKey && event.key=="a";
|
|
279
|
+
if(selectAll)event.keyCode=1001;
|
|
280
|
+
if([self geaDispatchKey:event] || selectAll)return;
|
|
281
|
+
// Ordinary native text controls own AppKit text services themselves. Only
|
|
282
|
+
// the explicit app-owned editor root interprets text into Gea attributes.
|
|
283
|
+
if(geaCustomInputRoot()<0) {
|
|
284
|
+
// Unhandled navigation and commands retain AppKit's responder defaults.
|
|
285
|
+
// Handled Gea events returned above and cannot also move native focus.
|
|
286
|
+
if(native.keyCode==48) {
|
|
287
|
+
if(event.shiftKey)[self.window selectPreviousKeyView:self];
|
|
288
|
+
else [self.window selectNextKeyView:self];
|
|
289
|
+
} else [super keyDown:native];
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
self.geaInterpretingDispatchedKey=YES;
|
|
293
|
+
@try { [self interpretKeyEvents:@[native]]; }
|
|
294
|
+
@finally { self.geaInterpretingDispatchedKey=NO; }
|
|
295
|
+
}
|
|
296
|
+
- (void)keyUp:(NSEvent *)native {
|
|
297
|
+
if(geaKeyboardInputRoot()<0){[super keyUp:native];return;}
|
|
298
|
+
auto event=geaNativeKey(native,[self hasMarkedText],true);
|
|
299
|
+
[self geaDispatchKey:event];
|
|
300
|
+
}
|
|
301
|
+
- (void)insertText:(id)text replacementRange:(NSRange)range {
|
|
302
|
+
(void)range;const int root=geaCustomInputRoot();if(root<0)return;
|
|
303
|
+
NSString *value=[text isKindOfClass:[NSAttributedString class]]?[text string]:text;
|
|
304
|
+
auto &tree=gea::embedded::ui::Tree::instance();
|
|
305
|
+
tree.setAttribute(root,"value",value.UTF8String?:"");
|
|
306
|
+
gea::framework::events::PointerEvent event;event.type=gea::framework::events::PointerEventType::Input;event.targetId=root;tree.dispatchEvent(event);
|
|
307
|
+
self.geaMarkedText=nil;
|
|
308
|
+
}
|
|
309
|
+
- (void)doCommandBySelector:(SEL)selector {
|
|
310
|
+
int code=0;
|
|
311
|
+
if(selector==@selector(deleteBackward:))code=8;
|
|
312
|
+
else if(selector==@selector(deleteForward:))code=46;
|
|
313
|
+
else if(selector==@selector(moveLeft:))code=37;
|
|
314
|
+
else if(selector==@selector(moveRight:))code=39;
|
|
315
|
+
else if(selector==@selector(moveUp:))code=38;
|
|
316
|
+
else if(selector==@selector(moveDown:))code=40;
|
|
317
|
+
else if(selector==@selector(moveToBeginningOfLine:))code=36;
|
|
318
|
+
else if(selector==@selector(moveToEndOfLine:))code=35;
|
|
319
|
+
else if(selector==@selector(insertNewline:))code=13;
|
|
320
|
+
else if(selector==@selector(insertTab:))code=9;
|
|
321
|
+
else if(selector==@selector(cancelOperation:))code=27;
|
|
322
|
+
if(code && !self.geaInterpretingDispatchedKey)[self geaSendKey:code];
|
|
323
|
+
}
|
|
324
|
+
- (void)paste:(id)sender { (void)sender;NSString *value=[[NSPasteboard generalPasteboard] stringForType:NSPasteboardTypeString];if(value)[self insertText:value replacementRange:NSMakeRange(NSNotFound,0)]; }
|
|
325
|
+
- (void)copy:(id)sender {
|
|
326
|
+
(void)sender;const int root=geaCustomInputRoot();if(root<0)return;
|
|
327
|
+
NSString *text=[NSString stringWithUTF8String:gea::embedded::ui::Tree::instance().getAttribute(root,"data-gea-selected-text")];
|
|
328
|
+
if(text.length){NSPasteboard *board=[NSPasteboard generalPasteboard];[board clearContents];[board setString:text forType:NSPasteboardTypeString];}
|
|
329
|
+
}
|
|
330
|
+
- (void)cut:(id)sender { [self copy:sender];[self geaSendKey:46]; }
|
|
331
|
+
- (void)selectAll:(id)sender { (void)sender;[self geaSendKey:1001]; }
|
|
332
|
+
- (BOOL)hasMarkedText { return self.geaMarkedText.length>0; }
|
|
333
|
+
- (NSRange)markedRange { return [self hasMarkedText]?NSMakeRange(0,self.geaMarkedText.length):NSMakeRange(NSNotFound,0); }
|
|
334
|
+
- (NSRange)selectedRange { return NSMakeRange(NSNotFound,0); }
|
|
335
|
+
- (void)setMarkedText:(id)text selectedRange:(NSRange)selection replacementRange:(NSRange)replacement {
|
|
336
|
+
(void)selection;(void)replacement;self.geaMarkedText=[text isKindOfClass:[NSAttributedString class]]?text:[[NSAttributedString alloc] initWithString:text];
|
|
337
|
+
}
|
|
338
|
+
- (void)unmarkText { self.geaMarkedText=nil; }
|
|
339
|
+
- (NSArray<NSAttributedStringKey> *)validAttributesForMarkedText { return @[]; }
|
|
340
|
+
- (NSAttributedString *)attributedSubstringForProposedRange:(NSRange)range actualRange:(NSRangePointer)actual { (void)range;if(actual)*actual=NSMakeRange(NSNotFound,0);return nil; }
|
|
341
|
+
- (NSUInteger)characterIndexForPoint:(NSPoint)point { (void)point;return NSNotFound; }
|
|
342
|
+
- (NSRect)firstRectForCharacterRange:(NSRange)range actualRange:(NSRangePointer)actual {
|
|
343
|
+
(void)range;if(actual)*actual=NSMakeRange(NSNotFound,0);return [self.window convertRectToScreen:[self convertRect:self.bounds toView:nil]];
|
|
344
|
+
}
|
|
67
345
|
@end
|
|
68
346
|
|
|
69
347
|
@interface AppDelegate : NSObject <NSApplicationDelegate, NSWindowDelegate>
|
|
@@ -152,6 +430,10 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
152
430
|
// Application::init — apps gate remote fetches on wifi().connected()
|
|
153
431
|
// (e.g. maps skips tile downloads while it reads false).
|
|
154
432
|
gea::macos::installWifiDriver();
|
|
433
|
+
// macOS has an available host filesystem before app initialization.
|
|
434
|
+
// ImageService gates external reads on this provider just as device targets
|
|
435
|
+
// gate theirs on mounted storage.
|
|
436
|
+
gea::platform::storage::setMountProvider(+[]() { return true; });
|
|
155
437
|
const bool thermalrightTarget = gea::macos::thermalright::enabled();
|
|
156
438
|
if (!thermalrightTarget) [self installMainMenu];
|
|
157
439
|
|
|
@@ -241,8 +523,7 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
241
523
|
self.rootView.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
242
524
|
[self.rootView setWantsLayer:YES];
|
|
243
525
|
[self.window setContentView:self.rootView];
|
|
244
|
-
|
|
245
|
-
[NSApp activateIgnoringOtherApps:YES];
|
|
526
|
+
gea::macos::background_test::present(self.window);
|
|
246
527
|
|
|
247
528
|
NSSize size = self.rootView.bounds.size;
|
|
248
529
|
if (gea::macos::thermalright::enabled()) {
|
|
@@ -269,6 +550,9 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
269
550
|
|
|
270
551
|
- (void)startFrameTimer
|
|
271
552
|
{
|
|
553
|
+
#if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
|
|
554
|
+
gea_macos_debugger_start();
|
|
555
|
+
#endif
|
|
272
556
|
if (self.frameTimer) return;
|
|
273
557
|
const BOOL thermalrightTarget = gea::macos::thermalright::enabled();
|
|
274
558
|
if (!thermalrightTarget) {
|
|
@@ -364,10 +648,12 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
364
648
|
[self.frameDisplayLink invalidate];
|
|
365
649
|
self.frameDisplayLink = nil;
|
|
366
650
|
}
|
|
651
|
+
geaRetireNativeProcess();
|
|
367
652
|
}
|
|
368
653
|
|
|
369
654
|
- (void)tick
|
|
370
655
|
{
|
|
656
|
+
gea::macos::background_test::checkApplication(NSApp);
|
|
371
657
|
if (getenv("GEA_MACOS_TICK_DEBUG")) {
|
|
372
658
|
static int tickCount = 0;
|
|
373
659
|
tickCount++;
|
|
@@ -404,6 +690,7 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
404
690
|
static const bool profile = std::getenv("GEA_NATIVE_FRAME_PROFILE") != nullptr;
|
|
405
691
|
using Clock = std::chrono::steady_clock;
|
|
406
692
|
const auto applicationBegin = profile ? Clock::now() : Clock::time_point{};
|
|
693
|
+
[self.rootView geaPollGamepad];
|
|
407
694
|
gea::framework::app::Application::frame(gea_embedded_now_ms());
|
|
408
695
|
if (profile) self.geaProfileApplicationMs = std::chrono::duration<double, std::milli>(Clock::now() - applicationBegin).count();
|
|
409
696
|
auto &tree = gea::embedded::ui::Tree::instance();
|
|
@@ -431,9 +718,9 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
431
718
|
else
|
|
432
719
|
singleAppAnimScanned = true;
|
|
433
720
|
gea::css::DeclarativeAnimations::scanAndStart(gea_embedded_now_ms());
|
|
434
|
-
gea::embedded::ui::StyleSheet::instance().startCssAnimations(gea_embedded_now_ms());
|
|
435
721
|
}
|
|
436
722
|
}
|
|
723
|
+
gea::embedded::ui::StyleSheet::instance().startCssAnimations(gea_embedded_now_ms());
|
|
437
724
|
gea::css::AnimationEngine::instance().tick(
|
|
438
725
|
static_cast<std::uint32_t>(gea_embedded_now_ms()));
|
|
439
726
|
|
|
@@ -474,6 +761,96 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
474
761
|
tree.computeLayout(root, w, h);
|
|
475
762
|
gea::macos::MacosRenderer::instance().sync(self.rootView, root);
|
|
476
763
|
|
|
764
|
+
|
|
765
|
+
// Opt-in deterministic Gea event replay for recorded demos. No OS events or
|
|
766
|
+
// application state shortcuts; the same tree handlers process every step.
|
|
767
|
+
if (const char *planPath = getenv("GEA_MACOS_REPLAY_PLAN")) {
|
|
768
|
+
static NSArray *steps = nil;
|
|
769
|
+
static NSUInteger nextStep = 0;
|
|
770
|
+
static NSDictionary *pending = nil;
|
|
771
|
+
static int settleFrames = 0;
|
|
772
|
+
static double startedAt = 0;
|
|
773
|
+
auto replayLog = [&](NSDictionary *entry) {
|
|
774
|
+
const char *logPath = getenv("GEA_MACOS_REPLAY_LOG");
|
|
775
|
+
if (!logPath) return;
|
|
776
|
+
NSData *json = [NSJSONSerialization dataWithJSONObject:entry options:0 error:nil];
|
|
777
|
+
FILE *file = std::fopen(logPath, "a");
|
|
778
|
+
if (file) { std::fwrite(json.bytes, 1, json.length, file); std::fputc('\n', file); std::fclose(file); }
|
|
779
|
+
};
|
|
780
|
+
auto replayFail = [&](NSString *reason) {
|
|
781
|
+
replayLog(@{@"error":reason}); NSLog(@"[gea-replay] %@", reason); std::exit(2);
|
|
782
|
+
};
|
|
783
|
+
if (!steps) {
|
|
784
|
+
NSData *data = [NSData dataWithContentsOfFile:[NSString stringWithUTF8String:planPath]];
|
|
785
|
+
NSDictionary *plan = data ? [NSJSONSerialization JSONObjectWithData:data options:0 error:nil] : nil;
|
|
786
|
+
if (![plan isKindOfClass:[NSDictionary class]] || ![plan[@"steps"] isKindOfClass:[NSArray class]]) replayFail(@"Invalid replay plan");
|
|
787
|
+
steps = plan[@"steps"];
|
|
788
|
+
}
|
|
789
|
+
if (!startedAt) {
|
|
790
|
+
const char *marker = getenv("GEA_MACOS_REPLAY_START");
|
|
791
|
+
NSString *value = marker ? [NSString stringWithContentsOfFile:[NSString stringWithUTF8String:marker] encoding:NSUTF8StringEncoding error:nil] : nil;
|
|
792
|
+
startedAt = value.doubleValue;
|
|
793
|
+
}
|
|
794
|
+
if (startedAt) {
|
|
795
|
+
const double elapsed = NSDate.date.timeIntervalSince1970 - startedAt;
|
|
796
|
+
if (pending && ++settleFrames >= 3) {
|
|
797
|
+
NSString *expected = pending[@"expect"];
|
|
798
|
+
std::string text;
|
|
799
|
+
for (int i=0;i<tree.nodeCount();++i) { text += tree.node(i).text; text += " "; }
|
|
800
|
+
if (expected.length && text.find(expected.UTF8String) == std::string::npos) replayFail([NSString stringWithFormat:@"Step %@ did not show %@", pending[@"label"], expected]);
|
|
801
|
+
if (NSDictionary *check=pending[@"expectTextIn"]) {
|
|
802
|
+
auto subtreeText = [&](auto &&visit, int node) -> std::string {
|
|
803
|
+
std::string result=tree.node(node).text; result += " ";
|
|
804
|
+
for(int child=tree.node(node).first_child;child>=0;child=tree.node(child).next_sibling) result += visit(visit,child);
|
|
805
|
+
return result;
|
|
806
|
+
};
|
|
807
|
+
bool matched=false;
|
|
808
|
+
for(int i=0;i<tree.nodeCount();++i) if(tree.className(i).find([check[@"class"] UTF8String])!=std::string::npos) {
|
|
809
|
+
std::string raw=subtreeText(subtreeText,i);
|
|
810
|
+
NSString *value=[NSString stringWithUTF8String:raw.c_str()];
|
|
811
|
+
NSMutableArray *words=[NSMutableArray array];
|
|
812
|
+
for(NSString *word in [value componentsSeparatedByCharactersInSet:NSCharacterSet.whitespaceAndNewlineCharacterSet]) if(word.length) [words addObject:word];
|
|
813
|
+
if([[words componentsJoinedByString:@" "] containsString:check[@"contains"]]) matched=true;
|
|
814
|
+
}
|
|
815
|
+
if(!matched) replayFail([NSString stringWithFormat:@"Step %@ did not show %@ in %@",pending[@"label"],check[@"contains"],check[@"class"]]);
|
|
816
|
+
}
|
|
817
|
+
replayLog(@{@"verified":pending[@"label"], @"elapsed":@(elapsed)});
|
|
818
|
+
pending = nil;
|
|
819
|
+
}
|
|
820
|
+
if (!pending && nextStep < steps.count && elapsed >= [steps[nextStep][@"at"] doubleValue]) {
|
|
821
|
+
NSDictionary *step = steps[nextStep++];
|
|
822
|
+
using gea::framework::events::PointerEvent;
|
|
823
|
+
using gea::framework::events::PointerEventType;
|
|
824
|
+
if (NSString *text = step[@"text"]) {
|
|
825
|
+
const int inputRoot = geaCustomInputRoot();
|
|
826
|
+
if (inputRoot < 0) replayFail(@"No Gea input root");
|
|
827
|
+
tree.setAttribute(inputRoot,"value",text.UTF8String);
|
|
828
|
+
PointerEvent event; event.type=PointerEventType::Input; event.targetId=inputRoot; tree.dispatchEvent(event);
|
|
829
|
+
} else {
|
|
830
|
+
const int x=[step[@"x"] intValue], y=[step[@"y"] intValue];
|
|
831
|
+
NSPoint point=NSMakePoint(x,self.rootView.bounds.size.height-y);
|
|
832
|
+
NSView *hit=[self.rootView hitTest:[self.rootView convertPoint:point toView:self.rootView.superview]];
|
|
833
|
+
int target=gea::macos::nodeIdForView(hit), ancestor=target;
|
|
834
|
+
const std::string expected=[step[@"target"] UTF8String];
|
|
835
|
+
while (ancestor>=0 && tree.className(ancestor).find(expected)==std::string::npos) ancestor=tree.node(ancestor).parent;
|
|
836
|
+
if (target<0 || ancestor<0) replayFail([NSString stringWithFormat:@"Wrong hit target for %@",step[@"label"]]);
|
|
837
|
+
tree.pointerHover(x,y);
|
|
838
|
+
if (!geaOwnsContourPress(x,y)) tree.pointerDown(x,y);
|
|
839
|
+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,80*NSEC_PER_MSEC),dispatch_get_main_queue(),^{
|
|
840
|
+
gea::embedded::ui::Tree::instance().pointerUp();
|
|
841
|
+
});
|
|
842
|
+
for (auto phase : {PointerEventType::TouchStart,PointerEventType::TouchEnd,PointerEventType::Click}) {
|
|
843
|
+
PointerEvent event; event.type=phase; event.targetId=target; event.pointerId=1;
|
|
844
|
+
event.x=x; event.y=y; event.clientX=x; event.clientY=y; event.pageX=x; event.pageY=y;
|
|
845
|
+
tree.dispatchEvent(event);
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
replayLog(@{@"action":step[@"label"], @"elapsed":@(elapsed), @"index":@(nextStep-1)});
|
|
849
|
+
pending=step; settleFrames=0;
|
|
850
|
+
}
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
477
854
|
if (const char *clickEnv = getenv("GEA_MACOS_SYNTH_CLICK")) {
|
|
478
855
|
static int frameCount = 0;
|
|
479
856
|
++frameCount;
|
|
@@ -561,14 +938,31 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
561
938
|
view.frame = [self.window.contentView bounds];
|
|
562
939
|
view.autoresizingMask = NSViewWidthSizable | NSViewHeightSizable;
|
|
563
940
|
[self.window setContentView:view];
|
|
564
|
-
|
|
565
|
-
|
|
941
|
+
gea::macos::background_test::present(self.window);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
- (void)windowDidResignKey:(NSNotification *)notification
|
|
945
|
+
{
|
|
946
|
+
if (notification.object != self.window) return;
|
|
947
|
+
gea::embedded::ui::dispatchWindowLifecycleEvent(gea::framework::events::PointerEventType::WindowBlur);
|
|
566
948
|
}
|
|
567
949
|
|
|
568
950
|
- (void)windowDidResize:(NSNotification *)notification
|
|
569
951
|
{
|
|
570
|
-
|
|
952
|
+
if (notification.object != self.window) return;
|
|
571
953
|
if (gea::macos::thermalright::enabled()) return;
|
|
954
|
+
if (!self.splitShell) {
|
|
955
|
+
const NSSize size = self.rootView.bounds.size;
|
|
956
|
+
const int width = static_cast<int>(size.width), height = static_cast<int>(size.height);
|
|
957
|
+
if (width > 0 && height > 0 &&
|
|
958
|
+
(width != gea::embedded::ui::Document::preferredMountWidth() ||
|
|
959
|
+
height != gea::embedded::ui::Document::preferredMountHeight())) {
|
|
960
|
+
gea::embedded::ui::Document::setPreferredMountSize(width, height);
|
|
961
|
+
// AppKit layout uses points; a CSS px is one point, including on Retina.
|
|
962
|
+
gea::embedded::ui::setViewportMetrics(width, height, 1.0);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
gea::embedded::ui::dispatchWindowLifecycleEvent(gea::framework::events::PointerEventType::WindowResize);
|
|
572
966
|
// Sync immediately on resize end too; the live-mode timer covers the
|
|
573
967
|
// drag, this handles the final snap.
|
|
574
968
|
[self tick];
|
|
@@ -643,8 +1037,7 @@ void gea::apple::AppKit::installRootViewController(gea::apple::AppKit::NSViewCon
|
|
|
643
1037
|
[delegate.window setContentSize:wantedContent];
|
|
644
1038
|
[delegate.window center];
|
|
645
1039
|
}
|
|
646
|
-
|
|
647
|
-
[NSApp activateIgnoringOtherApps:YES];
|
|
1040
|
+
gea::macos::background_test::present(delegate.window);
|
|
648
1041
|
// Clear the initial first responder so an editable NSTextField/NSTextView
|
|
649
1042
|
// in the content doesn't grab focus (drawing a blue focus ring + selecting
|
|
650
1043
|
// its text) the instant the window opens — matching a freshly launched
|
|
@@ -813,14 +1206,17 @@ void gea::apple::AppKit::setScrollDocumentTopAligned(gea::apple::AppKit::NSScrol
|
|
|
813
1206
|
|
|
814
1207
|
int main(int argc, const char *argv[])
|
|
815
1208
|
{
|
|
1209
|
+
GeaNativeTerminationGuard terminationGuard;
|
|
816
1210
|
(void)argc;
|
|
817
1211
|
(void)argv;
|
|
818
1212
|
@autoreleasepool {
|
|
819
1213
|
gea_macos_smoke_log("[gea-macos] main entered");
|
|
1214
|
+
const bool backgroundTest = gea::macos::background_test::enabled();
|
|
820
1215
|
NSApplication *app = [NSApplication sharedApplication];
|
|
821
1216
|
AppDelegate *delegate = [[AppDelegate alloc] init];
|
|
822
1217
|
[app setDelegate:delegate];
|
|
823
|
-
|
|
1218
|
+
if (backgroundTest) gea::macos::background_test::configure(app);
|
|
1219
|
+
else [app setActivationPolicy:gea::macos::thermalright::enabled()
|
|
824
1220
|
? NSApplicationActivationPolicyProhibited
|
|
825
1221
|
: NSApplicationActivationPolicyRegular];
|
|
826
1222
|
gea_macos_smoke_log("[gea-macos] before finishLaunching");
|
|
@@ -10,6 +10,11 @@ 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
|
+
// Called only after AppKit accepts the actual root responder transition.
|
|
16
|
+
void nativeRootFocusChanged(NSView*view,bool focused,int nodeId);
|
|
17
|
+
|
|
13
18
|
class MacosRenderer {
|
|
14
19
|
public:
|
|
15
20
|
static MacosRenderer &instance();
|