@geastack/apple 0.2.23 → 0.2.25
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 +1 -1
- package/targets/macos/build-macos.sh +5 -4
- package/targets/macos/include/gea_appkit_host.h +43 -0
- package/targets/macos/main/appkit_host.mm +43 -0
- package/targets/macos/main/macos_main.mm +15 -6
- package/targets/macos/sync-resources.mjs +10 -3
- package/targets/macos/window-config.mjs +35 -0
package/package.json
CHANGED
|
@@ -1074,6 +1074,7 @@ MM_SOURCES=(
|
|
|
1074
1074
|
# gea::platform::audio — the AVAudioEngine backend, shared verbatim with iOS.
|
|
1075
1075
|
"$ROOT_DIR/targets/shared/apple_audio.mm"
|
|
1076
1076
|
"$ROOT_DIR/targets/macos/main/macos_main.mm"
|
|
1077
|
+
"$ROOT_DIR/targets/macos/main/appkit_host.mm"
|
|
1077
1078
|
"$ROOT_DIR/targets/macos/main/macos_native_shell.mm"
|
|
1078
1079
|
"$ROOT_DIR/targets/macos/main/macos_display.mm"
|
|
1079
1080
|
"$ROOT_DIR/targets/macos/main/macos_timers.mm"
|
|
@@ -2115,12 +2116,12 @@ done
|
|
|
2115
2116
|
|
|
2116
2117
|
# Per-app window config — the macOS main reads window.json out of Resources/
|
|
2117
2118
|
# at launch to pick up size, transparent title bar, dark appearance, etc.
|
|
2118
|
-
# Source
|
|
2119
|
-
#
|
|
2119
|
+
# Source is apps/<id>/macos.json overlaid with gea.targets.macos.window from
|
|
2120
|
+
# the app's package.json (window-config.mjs), written as window.json so the runtime path is stable
|
|
2120
2121
|
# regardless of which app id produced it.
|
|
2121
2122
|
APP_DIR_FOR_CONFIG="$(resolve_app_dir "$APP_ID")"
|
|
2122
|
-
if [[ -n "$APP_DIR_FOR_CONFIG"
|
|
2123
|
-
|
|
2123
|
+
if [[ -n "$APP_DIR_FOR_CONFIG" ]]; then
|
|
2124
|
+
node "$ROOT_DIR/targets/macos/window-config.mjs" "$APP_DIR_FOR_CONFIG" "$RES_DIR/window.json"
|
|
2124
2125
|
fi
|
|
2125
2126
|
else
|
|
2126
2127
|
APP_DIRS_FOR_FONTS=()
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// Host extensions: native code a package (or an app) compiles into a macOS
|
|
3
|
+
// build to own part of the window -- typically a rendering surface such as a
|
|
4
|
+
// CAMetalLayer that a GL or GPU layer presents into, which the generated
|
|
5
|
+
// program draws through. The AppKit counterpart of gea_uikit_host.h, so a
|
|
6
|
+
// program that runs on tvOS runs unchanged on macOS.
|
|
7
|
+
//
|
|
8
|
+
// An extension registers itself from a static initializer:
|
|
9
|
+
//
|
|
10
|
+
// static const gea_appkit_host_extension kSurface = {
|
|
11
|
+
// GEA_APPKIT_HOST_EXTENSION_VERSION, "my-surface", attach, layout };
|
|
12
|
+
// static const bool kRegistered = (gea_appkit_register_host_extension(&kSurface), true);
|
|
13
|
+
//
|
|
14
|
+
// Every callback may be null. Sizes are in points; `scale` is device pixels
|
|
15
|
+
// per point.
|
|
16
|
+
#pragma once
|
|
17
|
+
|
|
18
|
+
#ifdef __cplusplus
|
|
19
|
+
extern "C" {
|
|
20
|
+
#endif
|
|
21
|
+
|
|
22
|
+
#define GEA_APPKIT_HOST_EXTENSION_VERSION 1u
|
|
23
|
+
|
|
24
|
+
typedef struct gea_appkit_host_extension {
|
|
25
|
+
unsigned version; // GEA_APPKIT_HOST_EXTENSION_VERSION
|
|
26
|
+
const char *name; // for diagnostics
|
|
27
|
+
// Once, after the window's root view exists and before the app's top level
|
|
28
|
+
// runs. `rootView` is the root NSView (a bridged NSView *): an extension adds
|
|
29
|
+
// its own subviews to it. Returning zero logs an error naming the extension.
|
|
30
|
+
int (*attach)(void *rootView, double width, double height, double scale);
|
|
31
|
+
// The root view's size or scale changed.
|
|
32
|
+
void (*layout)(double width, double height, double scale);
|
|
33
|
+
} gea_appkit_host_extension;
|
|
34
|
+
|
|
35
|
+
void gea_appkit_register_host_extension(const gea_appkit_host_extension *extension);
|
|
36
|
+
|
|
37
|
+
// Called by the target (macos_main.mm).
|
|
38
|
+
void gea_appkit_host_attach(void *rootView, double width, double height, double scale);
|
|
39
|
+
void gea_appkit_host_layout(double width, double height, double scale);
|
|
40
|
+
|
|
41
|
+
#ifdef __cplusplus
|
|
42
|
+
}
|
|
43
|
+
#endif
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
// The registry and life-cycle calls of macOS host extensions (gea_appkit_host.h).
|
|
3
|
+
#include "gea_appkit_host.h"
|
|
4
|
+
|
|
5
|
+
#include <cstdio>
|
|
6
|
+
|
|
7
|
+
namespace {
|
|
8
|
+
|
|
9
|
+
constexpr int kMaxExtensions = 8;
|
|
10
|
+
const gea_appkit_host_extension *gExtensions[kMaxExtensions];
|
|
11
|
+
int gExtensionCount = 0;
|
|
12
|
+
|
|
13
|
+
} // namespace
|
|
14
|
+
|
|
15
|
+
extern "C" void gea_appkit_register_host_extension(const gea_appkit_host_extension *extension)
|
|
16
|
+
{
|
|
17
|
+
if (!extension || extension->version != GEA_APPKIT_HOST_EXTENSION_VERSION) {
|
|
18
|
+
std::fprintf(stderr, "[gea] host extension %s has an unsupported version\n", extension && extension->name ? extension->name : "?");
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
if (gExtensionCount >= kMaxExtensions) {
|
|
22
|
+
std::fprintf(stderr, "[gea] too many host extensions; %s ignored\n", extension->name ? extension->name : "?");
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
gExtensions[gExtensionCount++] = extension;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
extern "C" void gea_appkit_host_attach(void *rootView, double width, double height, double scale)
|
|
29
|
+
{
|
|
30
|
+
for (int i = 0; i < gExtensionCount; ++i) {
|
|
31
|
+
const auto *extension = gExtensions[i];
|
|
32
|
+
if (extension->attach && !extension->attach(rootView, width, height, scale)) {
|
|
33
|
+
std::fprintf(stderr, "[gea] host extension %s failed to attach\n", extension->name ? extension->name : "?");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
extern "C" void gea_appkit_host_layout(double width, double height, double scale)
|
|
39
|
+
{
|
|
40
|
+
for (int i = 0; i < gExtensionCount; ++i) {
|
|
41
|
+
if (gExtensions[i]->layout) gExtensions[i]->layout(width, height, scale);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -64,6 +64,7 @@ namespace gea::macos { void installWifiDriver(); int nodeIdForView(NSView *view)
|
|
|
64
64
|
#include <cstdio>
|
|
65
65
|
#include <cstdlib>
|
|
66
66
|
#include <cstring>
|
|
67
|
+
#include "gea_appkit_host.h"
|
|
67
68
|
|
|
68
69
|
extern "C" int gea_embedded_now_ms(void);
|
|
69
70
|
// Headless text-input driver used by GEA_MACOS_SYNTH_INPUT (press_bridge.mm).
|
|
@@ -348,6 +349,8 @@ static bool geaOwnsContourPress(int x, int y) {
|
|
|
348
349
|
@property(nonatomic, strong) NSWindow *window;
|
|
349
350
|
@property(nonatomic, strong) GeaContentView *rootView;
|
|
350
351
|
@property(nonatomic, strong) NSTimer *frameTimer;
|
|
352
|
+
// window.json `vsync: false`: frames run uncapped instead of at the display's cadence.
|
|
353
|
+
@property(nonatomic) BOOL vsyncDisabled;
|
|
351
354
|
@property(nonatomic, strong) CADisplayLink *frameDisplayLink API_AVAILABLE(macos(14.0));
|
|
352
355
|
@property(nonatomic, strong) GeaSplitShell *splitShell;
|
|
353
356
|
@property(nonatomic, strong) id geaToolbarDelegate; // NSToolbar.delegate is weak; retain it here
|
|
@@ -473,6 +476,7 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
473
476
|
BOOL fullSizeContentView = NO;
|
|
474
477
|
BOOL transparentTitleBar = NO;
|
|
475
478
|
BOOL titleHidden = NO;
|
|
479
|
+
BOOL startFullscreen = NO;
|
|
476
480
|
NSString *appearanceName = nil;
|
|
477
481
|
|
|
478
482
|
NSString *cfgPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"window.json"];
|
|
@@ -494,6 +498,8 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
494
498
|
if ([tv isKindOfClass:[NSString class]] && [(NSString *)tv isEqualToString:@"hidden"]) titleHidden = YES;
|
|
495
499
|
id ap = win[@"appearance"];
|
|
496
500
|
if ([ap isKindOfClass:[NSString class]]) appearanceName = ap;
|
|
501
|
+
id vs = win[@"vsync"]; if ([vs respondsToSelector:@selector(boolValue)]) self.vsyncDisabled = ![vs boolValue];
|
|
502
|
+
id fs = win[@"fullscreen"]; if ([fs respondsToSelector:@selector(boolValue)]) startFullscreen = [fs boolValue];
|
|
497
503
|
}
|
|
498
504
|
}
|
|
499
505
|
|
|
@@ -529,6 +535,10 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
529
535
|
if (gea::macos::thermalright::enabled()) {
|
|
530
536
|
size = NSMakeSize(gea::platform::display::kWidth, gea::platform::display::kHeight);
|
|
531
537
|
}
|
|
538
|
+
// Host extensions (a package's rendering surface) attach before the
|
|
539
|
+
// program's top level runs, as on iOS and tvOS.
|
|
540
|
+
gea_appkit_host_attach((__bridge void *)self.rootView, size.width, size.height,
|
|
541
|
+
self.window.backingScaleFactor > 0 ? self.window.backingScaleFactor : 1.0);
|
|
532
542
|
gea_macos_smoke_log("[gea-macos] before Application::init");
|
|
533
543
|
gea::framework::app::Application::init(static_cast<int>(size.width), static_cast<int>(size.height));
|
|
534
544
|
gea_macos_smoke_log("[gea-macos] after Application::init");
|
|
@@ -546,10 +556,10 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
546
556
|
|
|
547
557
|
[self tick];
|
|
548
558
|
[self startFrameTimer];
|
|
549
|
-
//
|
|
559
|
+
// window.json `fullscreen: true` starts fullscreen. With `vsync: false` it is
|
|
550
560
|
// the uncapped arm: a windowed CAMetalLayer gets drawables back only as the
|
|
551
561
|
// compositor runs, a fullscreen one presents directly.
|
|
552
|
-
if (
|
|
562
|
+
if (startFullscreen) {
|
|
553
563
|
self.window.collectionBehavior |= NSWindowCollectionBehaviorFullScreenPrimary;
|
|
554
564
|
NSWindow *window = self.window;
|
|
555
565
|
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC / 2), dispatch_get_main_queue(), ^{
|
|
@@ -565,10 +575,9 @@ static __weak AppDelegate *gGeaAppDelegate = nil;
|
|
|
565
575
|
#endif
|
|
566
576
|
if (self.frameTimer) return;
|
|
567
577
|
const BOOL thermalrightTarget = gea::macos::thermalright::enabled();
|
|
568
|
-
//
|
|
569
|
-
// renderer presenting with swap interval 0 runs uncapped
|
|
570
|
-
const
|
|
571
|
-
const BOOL uncapped = vsync && std::strcmp(vsync, "0") == 0;
|
|
578
|
+
// window.json `vsync: false` drops the display-link cadence for the fast
|
|
579
|
+
// timer, so a renderer presenting with swap interval 0 runs uncapped.
|
|
580
|
+
const BOOL uncapped = self.vsyncDisabled;
|
|
572
581
|
if (!thermalrightTarget && !uncapped) {
|
|
573
582
|
if (@available(macOS 14.0, *)) {
|
|
574
583
|
if (self.frameDisplayLink) return;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import fs from 'node:fs'
|
|
4
4
|
import path from 'node:path'
|
|
5
|
+
import { windowConfigText } from './window-config.mjs'
|
|
5
6
|
|
|
6
7
|
const args = process.argv.slice(2)
|
|
7
8
|
|
|
@@ -160,9 +161,15 @@ const windowConfig = path.join(resourcesDir, 'window.json')
|
|
|
160
161
|
for (const entry of fs.readdirSync(resourcesDir, { withFileTypes: true })) {
|
|
161
162
|
if (entry.isFile() && /^window\.json\.tmp\.\d+$/.test(entry.name)) removeFile(path.join(resourcesDir, entry.name))
|
|
162
163
|
}
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
|
|
164
|
+
const windowText = windowConfigText(configDir)
|
|
165
|
+
if (windowText) {
|
|
166
|
+
if (!fs.existsSync(windowConfig) || fs.readFileSync(windowConfig, 'utf8') !== windowText) {
|
|
167
|
+
const temporary = `${windowConfig}.tmp.${process.pid}`
|
|
168
|
+
fs.writeFileSync(temporary, windowText)
|
|
169
|
+
fs.renameSync(temporary, windowConfig)
|
|
170
|
+
changed = true
|
|
171
|
+
}
|
|
172
|
+
} else removeFile(windowConfig)
|
|
166
173
|
|
|
167
174
|
const manifest = `${JSON.stringify({ fonts: [...desiredFonts.keys()].sort(), fontLicenses: [...desiredFontLicenses.keys()].sort() }, null, 2)}\n`
|
|
168
175
|
fs.mkdirSync(path.dirname(manifestPath), { recursive: true })
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The window settings the macOS main reads from Resources/window.json: an app's
|
|
2
|
+
// macos.json, overlaid with `gea.targets.macos.window` from its package.json
|
|
3
|
+
// (size, title bar, appearance, `vsync`, `fullscreen`). Returns the JSON text,
|
|
4
|
+
// or '' when the app configures nothing.
|
|
5
|
+
//
|
|
6
|
+
// Run directly, it writes that file: node window-config.mjs <appDir> <out>
|
|
7
|
+
import fs from 'node:fs'
|
|
8
|
+
import path from 'node:path'
|
|
9
|
+
import { fileURLToPath } from 'node:url'
|
|
10
|
+
|
|
11
|
+
function readJson(file) {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.parse(fs.readFileSync(file, 'utf8'))
|
|
14
|
+
} catch {
|
|
15
|
+
return null
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function windowConfigText(appDir) {
|
|
20
|
+
if (!appDir) return ''
|
|
21
|
+
const file = readJson(path.join(appDir, 'macos.json'))
|
|
22
|
+
const fromPackage = readJson(path.join(appDir, 'package.json'))?.gea?.targets?.macos?.window
|
|
23
|
+
if (!file && !fromPackage) return ''
|
|
24
|
+
const base = file && typeof file === 'object' ? file : {}
|
|
25
|
+
// The main reads `window` when present, else the whole file (flat macos.json).
|
|
26
|
+
const window = { ...(base.window ?? base), ...(fromPackage && typeof fromPackage === 'object' ? fromPackage : {}) }
|
|
27
|
+
return `${JSON.stringify({ ...base, window }, null, 2)}\n`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
31
|
+
const [appDir, out] = process.argv.slice(2)
|
|
32
|
+
const text = windowConfigText(appDir)
|
|
33
|
+
if (text) fs.writeFileSync(out, text)
|
|
34
|
+
else fs.rmSync(out, { force: true })
|
|
35
|
+
}
|