@geastack/apple 0.2.33 → 0.2.34
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 +6 -6
- package/targets/macos/README.md +178 -6
- package/targets/macos/build-macos.sh +22 -3
- package/targets/macos/main/font_registry.h +8 -1
- package/targets/macos/main/font_registry.mm +42 -17
- package/targets/macos/main/macos_content_view.h +20 -0
- package/targets/macos/main/macos_main.mm +233 -34
- package/targets/macos/main/macos_microphone.mm +134 -0
- package/targets/macos/main/macos_native_shell.h +12 -0
- package/targets/macos/main/macos_native_shell.mm +102 -3
- package/targets/macos/main/macos_renderer.h +40 -0
- package/targets/macos/main/macos_renderer.mm +681 -12
- package/targets/macos/main/macos_windows.h +46 -0
- package/targets/macos/main/macos_windows.mm +704 -0
- package/targets/macos/window-config.mjs +9 -4
- package/targets/shared/apple_audio.mm +121 -2
- package/targets/shared/apple_audio_selftest.mm +74 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/apple",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.34",
|
|
4
4
|
"description": "Generated Apple SDK bindings plus the macOS, iOS and tvOS native build targets for Gea apps.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -115,13 +115,13 @@
|
|
|
115
115
|
"access": "public"
|
|
116
116
|
},
|
|
117
117
|
"dependencies": {
|
|
118
|
-
"@geastack/compiler": "^1.0.
|
|
119
|
-
"@geastack/core": "^0.1.
|
|
118
|
+
"@geastack/compiler": "^1.0.74",
|
|
119
|
+
"@geastack/core": "^0.1.72",
|
|
120
120
|
"@geastack/elements": "^0.1.7",
|
|
121
|
-
"@geastack/engine": "^0.1.
|
|
121
|
+
"@geastack/engine": "^0.1.37",
|
|
122
122
|
"@geastack/geatsc-plugin-apple-native": "^0.1.4",
|
|
123
|
-
"@geastack/geatsc-plugin-gea": "^0.1.
|
|
124
|
-
"@geastack/host": "^0.1.
|
|
123
|
+
"@geastack/geatsc-plugin-gea": "^0.1.32",
|
|
124
|
+
"@geastack/host": "^0.1.29"
|
|
125
125
|
},
|
|
126
126
|
"scripts": {
|
|
127
127
|
"prepublishOnly": "npm run build",
|
package/targets/macos/README.md
CHANGED
|
@@ -86,7 +86,11 @@ run uncapped. Both are scheduled on `NSRunLoopCommonModes` so the loop keeps
|
|
|
86
86
|
firing during live window-resize and other event-tracking modes. The window
|
|
87
87
|
config is `macos.json` in the app folder overlaid with
|
|
88
88
|
`gea.targets.macos.window` from its `package.json` (`width`, `height`,
|
|
89
|
-
`vsync`, `fullscreen`, ...), bundled as `Resources/window.json
|
|
89
|
+
`vsync`, `fullscreen`, ...), bundled as `Resources/window.json` together
|
|
90
|
+
with the app's `cssDevicePixelRatio` (`gea.targets.macos.cssDevicePixelRatio`,
|
|
91
|
+
else `gea.cssDevicePixelRatio`): points per CSS px, as on the boards. The
|
|
92
|
+
window's `width` and `height` are points; pointer `clientX`/`clientY` reach
|
|
93
|
+
listeners in CSS px. Each tick:
|
|
90
94
|
|
|
91
95
|
1. `Application::frame(timestampMs)` lets the app update state
|
|
92
96
|
2. Force `style.width/height` on the mounted root to the current window
|
|
@@ -95,6 +99,127 @@ config is `macos.json` in the app folder overlaid with
|
|
|
95
99
|
3. `Tree::computeLayout(root, w, h)`
|
|
96
100
|
4. `MacosRenderer::sync(rootView, root)`
|
|
97
101
|
|
|
102
|
+
## Windows (`<window>`)
|
|
103
|
+
|
|
104
|
+
A `<window>` element anywhere in the tree is its own titled, resizable
|
|
105
|
+
NSWindow in the same process, showing the element's children
|
|
106
|
+
(`main/macos_windows.mm`). A menu bar app (`MenuBar.install`) uses it for a
|
|
107
|
+
full window beside its panel:
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
{dashboard.open ? (
|
|
111
|
+
<window title="Library" width={1100} height={720} minWidth={760} minHeight={480}
|
|
112
|
+
focus={dashboard.focus} onClose={() => (dashboard.open = false)}>
|
|
113
|
+
<glass-split>...</glass-split>
|
|
114
|
+
</window>
|
|
115
|
+
) : null}
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
- Mounting the element opens and focuses the window; unmounting it closes it.
|
|
119
|
+
The close button (Cmd-W) hides the window and fires `close` (`onClose`);
|
|
120
|
+
unmount it there. A new `focus` value, or `el.focus()`, brings the window
|
|
121
|
+
to the front (and back, if it was hidden). `title`, `minWidth`/`minHeight`
|
|
122
|
+
follow later changes; `width`/`height` are the initial content size
|
|
123
|
+
(default 960 x 640, minimum 320 x 240). Outside a replay the frame is
|
|
124
|
+
remembered per title.
|
|
125
|
+
- The engine keeps the element out of its parent's layout, painting and hit
|
|
126
|
+
testing (`isDetachedRoot`, `engine/ui/node_model.h`); the target lays its
|
|
127
|
+
children out at the window's content size, relays out on live resize, and
|
|
128
|
+
renders every root -- the main window's and each window's -- in one
|
|
129
|
+
`MacosRenderer::syncRoots` pass. Layout runs only when the tree changed or a
|
|
130
|
+
size did. `<glass-split>` as the child gives the window the native split
|
|
131
|
+
view and toolbar.
|
|
132
|
+
- Clicks, wheel and momentum scrolling, text fields and keys work inside the
|
|
133
|
+
window; keys go to the key window. Events bubble through the element's JSX
|
|
134
|
+
ancestors like a React portal, so stop them on `<window>` when an
|
|
135
|
+
ancestor's handler must not see them.
|
|
136
|
+
- In a menu bar app the activation policy turns Regular (Dock icon, app menu,
|
|
137
|
+
Cmd-Tab) while any window is open and back to Accessory when the last one
|
|
138
|
+
closes; the panel keeps working, and closes when a window takes the keyboard.
|
|
139
|
+
With the panel hidden, the first visible window's display link drives frames.
|
|
140
|
+
A Dock click shows the windows again.
|
|
141
|
+
- `chrome="none"` lets the app draw its own chrome: the children fill the
|
|
142
|
+
whole window under a transparent, untitled title bar with the standard
|
|
143
|
+
buttons hidden; the shadow, rounded corners, edge resizing, Cmd-W/Cmd-M and
|
|
144
|
+
a dark appearance stay. It also applies when changed while open. A
|
|
145
|
+
mouse-down on a `data-window-drag` element (or a descendant with no event
|
|
146
|
+
handler of its own that is not a text field) drags the window with
|
|
147
|
+
`performWindowDragWithEvent`, and a double-click there follows the system's
|
|
148
|
+
title-bar double-click setting. A click on a
|
|
149
|
+
`data-window-action="close"|"minimize"|"zoom"` element does that to its
|
|
150
|
+
window; close goes through the close button's path, so `onClose` fires.
|
|
151
|
+
In a `<glass-split>` window the panes still start below the title bar strip.
|
|
152
|
+
- `vw`/`vh` and media queries still resolve against the main window. Each
|
|
153
|
+
`<glass-split>` reads its panes and toolbar once, when its window opens.
|
|
154
|
+
- Other native targets compile the element and show nothing; the web
|
|
155
|
+
simulator renders it as an unknown inline element, so guard it with the
|
|
156
|
+
app's platform check.
|
|
157
|
+
|
|
158
|
+
The replay harness (below) aims a click (`x`/`y` from the window's content
|
|
159
|
+
top left), `keyCode`, `wheel` or `text` step at a window with `"window":
|
|
160
|
+
"<title>"` (or its 0-based opening index); `expect` then reads only that
|
|
161
|
+
window's subtree. `{"kind": "windows", "at", "label"}` logs
|
|
162
|
+
`{"windows": [{title, windowNumber, visible, key, width, height, shell,
|
|
163
|
+
chrome}], "policy": "regular"|"accessory"}`, `{"kind": "resizeWindow", "at",
|
|
164
|
+
"label", "window", "width", "height"}` sets that window's content size, and
|
|
165
|
+
`{"kind": "closeWindow", "at", "label", "window"}` clicks its close button. A
|
|
166
|
+
window click on a `data-window-action` element performs the action and logs
|
|
167
|
+
`{"windowAction": <label>}`. `{"kind": "dragWindow", "at", "label", "window",
|
|
168
|
+
"x", "y", "dx", "dy"}` checks that (x,y) is on a `data-window-drag` area
|
|
169
|
+
(failing otherwise), moves the window by (dx,dy) points and logs `{"drag":
|
|
170
|
+
<label>, "element": <node>}`. `apple/examples/menu-bar-window` is a worked
|
|
171
|
+
example with a `replay.json`.
|
|
172
|
+
|
|
173
|
+
## Wheel events
|
|
174
|
+
|
|
175
|
+
A two-finger trackpad scroll or a mouse wheel over a Gea view dispatches a DOM
|
|
176
|
+
`wheel` event (`WheelEvent`, `onWheel`) to the node under the pointer, bubbling
|
|
177
|
+
through its ancestors like the pointer events:
|
|
178
|
+
|
|
179
|
+
```tsx
|
|
180
|
+
<div onWheel={(e) => {
|
|
181
|
+
if (Math.abs(e.deltaX) > Math.abs(e.deltaY)) e.preventDefault() // a sideways swipe is ours
|
|
182
|
+
if (e.phase === 'ended' || e.momentumPhase === 'ended') settle()
|
|
183
|
+
}}>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
- `deltaX`/`deltaY` are CSS px with the browser's sign: positive `deltaY`
|
|
187
|
+
scrolls toward what is below, positive `deltaX` toward what is to the right
|
|
188
|
+
(a leftward two-finger swipe with natural scrolling). `deltaMode` is always 0.
|
|
189
|
+
A notched mouse wheel reports 10 px per line. `clientX`/`clientY` and the
|
|
190
|
+
modifier keys are filled as for pointer events.
|
|
191
|
+
- `phase` / `momentumPhase` (a gea extension; the web has none) carry AppKit's
|
|
192
|
+
gesture phases as `'mayBegin' | 'began' | 'changed' | 'ended' |
|
|
193
|
+
'cancelled'`, or `''` outside that stream: finger-driven events have a
|
|
194
|
+
`phase` and an empty `momentumPhase`, the inertial tail after the fingers
|
|
195
|
+
lift has an empty `phase` and a `momentumPhase`, and a notched mouse wheel
|
|
196
|
+
has neither. A gesture end is therefore observable without a timer; code
|
|
197
|
+
that must also run where there are no phases should debounce.
|
|
198
|
+
- Every event of one trackpad gesture, momentum included, targets the node the
|
|
199
|
+
gesture began over (as browsers latch a wheel transaction), even after the
|
|
200
|
+
content scrolled another node under the pointer.
|
|
201
|
+
- `preventDefault()` consumes the event: the enclosing `overflow: scroll`
|
|
202
|
+
NSScrollView does not scroll for it. Otherwise the event continues to AppKit
|
|
203
|
+
unchanged, with native momentum and elastic edges. To own a whole gesture,
|
|
204
|
+
decide on its first events and keep preventing until it ends.
|
|
205
|
+
- With no `wheel` listener in the tree, scrolling is untouched.
|
|
206
|
+
|
|
207
|
+
The bridge is an app-wide local scroll-wheel monitor
|
|
208
|
+
(`gea::macos::dispatchWheelEvent`, `main/macos_renderer.mm`). The replay
|
|
209
|
+
harness (`GEA_MACOS_REPLAY_PLAN`) drives it headlessly with a step
|
|
210
|
+
`{"kind": "wheel", "at", "label", "x", "y", "deltaX", "deltaY", "phase",
|
|
211
|
+
"momentumPhase"}` (DOM sign convention, whole points as a trackpad reports them;
|
|
212
|
+
x/y in window points): it posts a real
|
|
213
|
+
scroll-wheel event through the same bridge and, unless a listener prevented
|
|
214
|
+
it, on to the view under the point and its scroll view. The replay log records
|
|
215
|
+
`{"wheel": <label>, "consumed": true|false}`.
|
|
216
|
+
|
|
217
|
+
A menu bar app's right-click menu (`MenuBar.setMenu`) is driven the same way
|
|
218
|
+
with `{"kind": "statusMenu", "at", "label", "choose"?, "expect"?}`: it logs the
|
|
219
|
+
menu the icon would show, `{"statusMenu": <label>, "items": [...]}` (titles,
|
|
220
|
+
`(disabled)`, `key:` equivalents, `---` for separators), and with `choose`
|
|
221
|
+
picks the item of that title through its own target/action, as a click does.
|
|
222
|
+
|
|
98
223
|
## Verification stub
|
|
99
224
|
|
|
100
225
|
Running with `GEA_MACOS_VERIFY_ONCE=1` logs the tree, NSView hierarchy,
|
|
@@ -104,9 +229,40 @@ quick regression checks after changes to the renderer.
|
|
|
104
229
|
## What works / what's stubbed
|
|
105
230
|
|
|
106
231
|
Native: View / Text / Button / Image / Canvas / VirtualList; flex
|
|
107
|
-
layout;
|
|
232
|
+
layout; `white-space: nowrap` with `text-overflow: ellipsis` (on the text or
|
|
233
|
+
the element holding it) cut by AppKit with "…" at the box's edge; click + press events; trackpad-momentum scroll; `wheel` events; window resize
|
|
108
234
|
(live + final); standard menu bar with Cmd-Q.
|
|
109
235
|
|
|
236
|
+
Text and borders:
|
|
237
|
+
|
|
238
|
+
- `letter-spacing` (`normal`, px, em, rem, `calc()`, negative values) is
|
|
239
|
+
resolved by the engine against the element's own font and inherited as that
|
|
240
|
+
length. The text is drawn with the same `NSKernAttributeName` the
|
|
241
|
+
measurement hook (`gea_host_measure_text_with_spacing`, `font_registry.mm`)
|
|
242
|
+
lays it out with, so a spaced run is exactly as wide as its box.
|
|
243
|
+
- `text-transform` (uppercase / lowercase / capitalize) and `white-space`
|
|
244
|
+
collapsing are applied to the drawn string by the engine's
|
|
245
|
+
`TextRenderer::prepareText`, the same text the layout measured.
|
|
246
|
+
- `border-style: dashed | dotted` from `border`, `border-<side>`,
|
|
247
|
+
`border-style` and `border-<side>-style`, and per-side border widths and
|
|
248
|
+
colours, are stroked by `CAShapeLayer`s (`applyEdgeBorders`,
|
|
249
|
+
`macos_renderer.mm`). Dashes are 3x the border width (at least 4px) with
|
|
250
|
+
equal gaps, dots are width-sized (round from 3px), and the gaps stretch so
|
|
251
|
+
each edge starts and ends on a dash. A uniform border on a rounded box is
|
|
252
|
+
one stroke along the rounded outline; mixed sides on a rounded box are drawn
|
|
253
|
+
as straight edges. `groove`/`ridge`/`inset`/`outset` draw as a flat colour.
|
|
254
|
+
|
|
255
|
+
Backgrounds: a `radial-gradient()` background image is drawn with its
|
|
256
|
+
`background-size`, `background-position`, `background-repeat` and
|
|
257
|
+
`background-clip`, from the longhands or the `background` shorthand
|
|
258
|
+
(`radial-gradient(circle, #03140a 1px, transparent 1.4px) 0 0 / 14px 14px,
|
|
259
|
+
#000` is a 14px dot grid over black). Stops may be px (absolute, as in a
|
|
260
|
+
browser) or percent of the radius. `applyBackgroundImage`
|
|
261
|
+
(`macos_renderer.mm`) renders one tile with CoreGraphics at the backing scale,
|
|
262
|
+
composes the tiles into a sublayer above the background colour and below the
|
|
263
|
+
border, inset shadow and children, and rebuilds it only when the gradient,
|
|
264
|
+
placement or size changes. Linear-gradient images are not drawn yet.
|
|
265
|
+
|
|
110
266
|
Audio: `targets/shared/apple_audio.mm` (shared with iOS) backs
|
|
111
267
|
`gea::platform::audio` with AVAudioEngine — sample-accurately scheduled,
|
|
112
268
|
mixed oscillators on an `AVAudioSourceNode`, plus `playFile`/`playPcm` on
|
|
@@ -117,8 +273,21 @@ runs the measurement harness (offline render, RMS + measured frequency);
|
|
|
117
273
|
|
|
118
274
|
Also implemented in `main/`: HTTP(S) `fetch` over `NSURLSession`
|
|
119
275
|
(`macos_network.mm`), battery level from IOKit power sources and pointer
|
|
120
|
-
input as touch (`macos_sensors.cpp`), timers (`macos_timers.mm`),
|
|
121
|
-
`
|
|
276
|
+
input as touch (`macos_sensors.cpp`), timers (`macos_timers.mm`), the
|
|
277
|
+
microphone behind `getUserMedia({ audio: true })` -- MediaRecorder, Web Audio
|
|
278
|
+
sources and streams -- as an AVAudioEngine input tap (`macos_microphone.mm`;
|
|
279
|
+
the app's `macos.json` `infoPlist` needs `NSMicrophoneUsageDescription`), and
|
|
280
|
+
the `runDeviceCommand` shell escape hatch (`macos_device_control.mm`).
|
|
281
|
+
|
|
282
|
+
Files: a Mac has no card, so `/sdcard` is the app's own data directory,
|
|
283
|
+
`~/Library/Application Support/<app name>`, the folder `Files.dataDirectory()`
|
|
284
|
+
returns (on a board both are `/sdcard`). `installStorageProviders()` in
|
|
285
|
+
`main/macos_main.mm` registers that mapping with
|
|
286
|
+
`gea::platform::storage::setPathProvider`, and every file operation -- `Files`,
|
|
287
|
+
the cache-file API, MediaRecorder, `uploadFile`/`downloadFile`, map tiles,
|
|
288
|
+
`<audio>` -- resolves its path through `hostPath()`, so an app reads and writes
|
|
289
|
+
`/sdcard/...` the same way on both. A file the app ships under `/sdcard` in its
|
|
290
|
+
bundle resources stays readable until the app writes its own copy.
|
|
122
291
|
|
|
123
292
|
One build is one app: a single app never compiles, includes or links GeaOS.
|
|
124
293
|
GeaOS is a separate product with its own build; `GEA_GEAOS=1` requests that
|
|
@@ -130,5 +299,8 @@ Stubbed in `main/macos_sensors.cpp`: the accelerometer/gyroscope (tilt 0,
|
|
|
130
299
|
gravity on Z) and the embedded memory diagnostics (all zeros).
|
|
131
300
|
`main/macos_display.mm` keeps the framebuffer display inert because AppKit
|
|
132
301
|
draws. `main/` has no WiFi or Bluetooth backend. Code signing with
|
|
133
|
-
entitlements and notarisation are not done by the build
|
|
134
|
-
|
|
302
|
+
entitlements and notarisation are not done by the build. A development bundle
|
|
303
|
+
is signed with the keychain's first "Apple Development" certificate (or
|
|
304
|
+
`GEA_MACOS_SIGN_IDENTITY`; `-` forces ad hoc), so every rebuild keeps the same
|
|
305
|
+
code identity and the Bluetooth and microphone permissions granted to the last
|
|
306
|
+
one; with no certificate it is signed ad hoc and macOS asks again per build.
|
|
@@ -872,7 +872,9 @@ NODE
|
|
|
872
872
|
hooksText='#pragma once
|
|
873
873
|
#ifdef __cplusplus
|
|
874
874
|
extern "C" void gea_debugger_note_listener(int node, const char *type, void *const *sites, int count);
|
|
875
|
+
extern "C" void gea_ui_note_delegated_listener(int node, const char *type);
|
|
875
876
|
#define GEA_JSX_NODE_LISTENER_HOOK(node, type) do { \
|
|
877
|
+
gea_ui_note_delegated_listener((node), (type)); \
|
|
876
878
|
_Pragma("clang diagnostic push") _Pragma("clang diagnostic ignored \"-Wframe-address\"") \
|
|
877
879
|
void *const geaDebuggerSites[] = {__builtin_return_address(1), __builtin_return_address(2), \
|
|
878
880
|
__builtin_return_address(3), __builtin_return_address(4)}; \
|
|
@@ -1026,6 +1028,7 @@ MM_SOURCES=(
|
|
|
1026
1028
|
"$ROOT_DIR/targets/macos/main/macos_main.mm"
|
|
1027
1029
|
"$ROOT_DIR/targets/macos/main/appkit_host.mm"
|
|
1028
1030
|
"$ROOT_DIR/targets/macos/main/macos_native_shell.mm"
|
|
1031
|
+
"$ROOT_DIR/targets/macos/main/macos_windows.mm"
|
|
1029
1032
|
"$ROOT_DIR/targets/macos/main/macos_display.mm"
|
|
1030
1033
|
"$ROOT_DIR/targets/macos/main/macos_timers.mm"
|
|
1031
1034
|
"$ROOT_DIR/targets/macos/main/macos_renderer.mm"
|
|
@@ -1038,6 +1041,7 @@ MM_SOURCES=(
|
|
|
1038
1041
|
"$ROOT_DIR/targets/macos/main/macos_device_control.mm"
|
|
1039
1042
|
"$ROOT_DIR/targets/macos/main/macos_host_device_control.mm"
|
|
1040
1043
|
"$ROOT_DIR/targets/macos/main/macos_network.mm"
|
|
1044
|
+
"$ROOT_DIR/targets/macos/main/macos_microphone.mm"
|
|
1041
1045
|
)
|
|
1042
1046
|
if [[ "$GEAOS_BUILD" == "1" ]]; then
|
|
1043
1047
|
MM_SOURCES+=("$ROOT_DIR/targets/macos/main/macos_app_platform.mm")
|
|
@@ -2191,23 +2195,38 @@ if [[ -n "$SINGLE_APP_DIR" ]]; then
|
|
|
2191
2195
|
fi
|
|
2192
2196
|
timing_mark resources
|
|
2193
2197
|
|
|
2194
|
-
#
|
|
2198
|
+
# Sign only after an input changed. The completion stamp is deliberately
|
|
2195
2199
|
# written after codesign so an interrupted resource stage is repaired next run.
|
|
2200
|
+
#
|
|
2201
|
+
# The identity: GEA_MACOS_SIGN_IDENTITY when set ("-" forces ad hoc), else the
|
|
2202
|
+
# keychain's first "Apple Development" certificate, else ad hoc. A certificate
|
|
2203
|
+
# gives every build the same designated requirement (bundle id + team), so the
|
|
2204
|
+
# privacy permissions a user grants (Bluetooth, microphone) carry over to the
|
|
2205
|
+
# next build; an ad-hoc signature is a new identity per build and macOS asks
|
|
2206
|
+
# again each time.
|
|
2207
|
+
CODESIGN_IDENTITY="${GEA_MACOS_SIGN_IDENTITY:-}"
|
|
2208
|
+
if [[ -z "$CODESIGN_IDENTITY" ]]; then
|
|
2209
|
+
CODESIGN_IDENTITY="$(security find-identity -v -p codesigning 2>/dev/null \
|
|
2210
|
+
| sed -n 's/^ *[0-9][0-9]*) \([0-9A-F]\{40\}\) "Apple Development: .*/\1/p' | head -n 1)"
|
|
2211
|
+
fi
|
|
2212
|
+
[[ -n "$CODESIGN_IDENTITY" ]] || CODESIGN_IDENTITY="-"
|
|
2196
2213
|
CODESIGN_STAMP="$BUILD_DIR/codesign.complete"
|
|
2197
2214
|
CODESIGN_NEEDED="$BUNDLE_CONTENT_CHANGED"
|
|
2198
2215
|
if [[ "$MACOS_PIPELINE_CACHE" == "0" || ! -f "$CODESIGN_STAMP" || ! -d "$APP_BUNDLE/Contents/_CodeSignature" ]]; then
|
|
2199
2216
|
CODESIGN_NEEDED=1
|
|
2217
|
+
elif [[ "$(cat "$CODESIGN_STAMP")" != "$CODESIGN_IDENTITY" ]]; then
|
|
2218
|
+
CODESIGN_NEEDED=1
|
|
2200
2219
|
elif find "$APP_BUNDLE/Contents" -path "$APP_BUNDLE/Contents/_CodeSignature" -prune -o \
|
|
2201
2220
|
-type f -newer "$CODESIGN_STAMP" -print -quit | grep -q .; then
|
|
2202
2221
|
CODESIGN_NEEDED=1
|
|
2203
2222
|
fi
|
|
2204
2223
|
if (( CODESIGN_NEEDED != 0 )); then
|
|
2205
2224
|
rm -f "$CODESIGN_STAMP"
|
|
2206
|
-
if ! codesign --force --sign
|
|
2225
|
+
if ! codesign --force --sign "$CODESIGN_IDENTITY" "$APP_BUNDLE"; then
|
|
2207
2226
|
echo "Code signing failed for $APP_BUNDLE" >&2
|
|
2208
2227
|
exit 1
|
|
2209
2228
|
fi
|
|
2210
|
-
|
|
2229
|
+
printf '%s' "$CODESIGN_IDENTITY" > "$CODESIGN_STAMP"
|
|
2211
2230
|
fi
|
|
2212
2231
|
timing_mark codesign
|
|
2213
2232
|
|
|
@@ -34,7 +34,14 @@ void useSoftwareTextMeasurement();
|
|
|
34
34
|
// (like "TYPOGRAPHY") gets split mid-glyph instead of overflowing and being
|
|
35
35
|
// clipped at the field edge. Shared between the host measurement hook and
|
|
36
36
|
// the NSTextField renderer so both compute identical geometry.
|
|
37
|
-
|
|
37
|
+
// `kern` is the NSKernAttributeName value the text is drawn with (CSS
|
|
38
|
+
// letter-spacing), so chunk widths include the spacing.
|
|
39
|
+
NSLineBreakMode lineBreakModeForText(NSString *text, NSFont *font, CGFloat maxWidth, CGFloat kern = 0);
|
|
40
|
+
|
|
41
|
+
// CSS letter-spacing (ComputedStyle::letter_spacing, hundredths of a layout
|
|
42
|
+
// pixel) as the NSKernAttributeName value. The measurement hook and the
|
|
43
|
+
// renderer both use it, so measured and drawn widths agree.
|
|
44
|
+
inline CGFloat letterSpacingKern(int hundredths) { return static_cast<CGFloat>(hundredths) / 100.0; }
|
|
38
45
|
#endif
|
|
39
46
|
|
|
40
47
|
} // namespace gea::macos
|
|
@@ -360,23 +360,41 @@ namespace gea::macos {
|
|
|
360
360
|
// falling back to mid-character when an unbreakable run is wider than the
|
|
361
361
|
// available width. The renderer and the measurement path share this logic
|
|
362
362
|
// so AppKit's render geometry always matches the framework's measurement.
|
|
363
|
-
|
|
363
|
+
// The width of the widest whitespace-separated word of `text`, set in `font`
|
|
364
|
+
// with `kern`. Shaping is the expensive part, and the renderer asks again for
|
|
365
|
+
// every text field on every sync, so the answer is kept: it depends only on the
|
|
366
|
+
// text and its font, never on the box it is fitted to.
|
|
367
|
+
static CGFloat widestWordWidth(NSString *text, NSFont *font, CGFloat kern)
|
|
364
368
|
{
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
369
|
+
static NSCache<NSString *, NSNumber *> *cache = [] {
|
|
370
|
+
NSCache *created = [[NSCache alloc] init];
|
|
371
|
+
created.countLimit = 4096;
|
|
372
|
+
return created;
|
|
373
|
+
}();
|
|
374
|
+
NSString *key = [NSString stringWithFormat:@"%@\x1f%.3f\x1f%.4f\x1f%@", font.fontName, font.pointSize, kern, text];
|
|
375
|
+
if (NSNumber *cached = [cache objectForKey:key]) return cached.doubleValue;
|
|
376
|
+
NSDictionary *probeAttrs = kern != 0 ? @{ NSFontAttributeName: font, NSKernAttributeName: @(kern) }
|
|
377
|
+
: @{ NSFontAttributeName: font };
|
|
378
|
+
CGFloat widest = 0;
|
|
372
379
|
NSArray<NSString *> *chunks = [text componentsSeparatedByCharactersInSet:
|
|
373
380
|
[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
|
374
381
|
for (NSString *chunk in chunks) {
|
|
375
382
|
if (chunk.length == 0) continue;
|
|
376
|
-
|
|
377
|
-
if (chunkWidth > maxWidth) return NSLineBreakByCharWrapping;
|
|
383
|
+
widest = std::max<CGFloat>(widest, [chunk sizeWithAttributes:probeAttrs].width);
|
|
378
384
|
}
|
|
379
|
-
|
|
385
|
+
[cache setObject:@(widest) forKey:key];
|
|
386
|
+
return widest;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
NSLineBreakMode lineBreakModeForText(NSString *text, NSFont *font, CGFloat maxWidth, CGFloat kern)
|
|
390
|
+
{
|
|
391
|
+
if (maxWidth <= 0 || text.length == 0 || !font) return NSLineBreakByWordWrapping;
|
|
392
|
+
// Check each whitespace-separated chunk. If even one "word" wouldn't fit
|
|
393
|
+
// on a line by itself, word-wrap can't help us — we'd render that word
|
|
394
|
+
// overflowing the field width and the parent tile's overflow:hidden would
|
|
395
|
+
// clip it mid-glyph with no indication. Char-wrap breaks inside the word
|
|
396
|
+
// so all of it stays visible.
|
|
397
|
+
return widestWordWidth(text, font, kern) > maxWidth ? NSLineBreakByCharWrapping : NSLineBreakByWordWrapping;
|
|
380
398
|
}
|
|
381
399
|
|
|
382
400
|
} // namespace gea::macos
|
|
@@ -388,6 +406,7 @@ static bool measureNativeText(const char *text,
|
|
|
388
406
|
int maxWidth,
|
|
389
407
|
int fontId,
|
|
390
408
|
int fontSize, int fontWeight, int fontStretch, int lineHeight,
|
|
409
|
+
int letterSpacing,
|
|
391
410
|
int *outWidth,
|
|
392
411
|
int *outHeight)
|
|
393
412
|
{
|
|
@@ -417,6 +436,7 @@ static bool measureNativeText(const char *text,
|
|
|
417
436
|
key.push_back('\x1f'); key.append(std::to_string(fontWeight));
|
|
418
437
|
key.push_back('\x1f'); key.append(std::to_string(fontStretch));
|
|
419
438
|
key.push_back('\x1f'); key.append(std::to_string(lineHeight));
|
|
439
|
+
key.push_back('\x1f'); key.append(std::to_string(letterSpacing));
|
|
420
440
|
{
|
|
421
441
|
std::scoped_lock guard(measureLock);
|
|
422
442
|
auto it = measureCache.find(key);
|
|
@@ -432,12 +452,15 @@ static bool measureNativeText(const char *text,
|
|
|
432
452
|
NSString *str = [NSString stringWithUTF8String:text] ?: @"";
|
|
433
453
|
const CGFloat boundedMax = maxWidth > 0 ? maxWidth : CGFLOAT_MAX;
|
|
434
454
|
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle alloc] init];
|
|
435
|
-
paragraph.lineBreakMode = gea::macos::lineBreakModeForText(str, font, boundedMax);
|
|
455
|
+
paragraph.lineBreakMode = gea::macos::lineBreakModeForText(str, font, boundedMax, gea::macos::letterSpacingKern(letterSpacing));
|
|
436
456
|
if (lineHeight > 0) { paragraph.minimumLineHeight = lineHeight; paragraph.maximumLineHeight = lineHeight; }
|
|
437
|
-
|
|
457
|
+
NSMutableDictionary *attrs = [NSMutableDictionary dictionaryWithDictionary:@{
|
|
438
458
|
NSFontAttributeName: font,
|
|
439
459
|
NSParagraphStyleAttributeName: paragraph,
|
|
440
|
-
};
|
|
460
|
+
}];
|
|
461
|
+
// CSS letter-spacing: the renderer draws with the same kern attribute
|
|
462
|
+
// (gea::macos::letterSpacingKern), which CoreText adds after every glyph.
|
|
463
|
+
if (letterSpacing != 0) attrs[NSKernAttributeName] = @(gea::macos::letterSpacingKern(letterSpacing));
|
|
441
464
|
NSAttributedString *attributed = [[NSAttributedString alloc] initWithString:str attributes:attrs];
|
|
442
465
|
// Measure with the exact call the renderer draws with: GeaTextCell's
|
|
443
466
|
// drawInteriorWithFrame: draws the attributed string with
|
|
@@ -470,9 +493,11 @@ extern "C" bool gea_host_packaged_font_available(int familyId)
|
|
|
470
493
|
&& glyphs[0] != 0 && glyphs[1] != 0;
|
|
471
494
|
}
|
|
472
495
|
extern "C" bool gea_host_measure_text(const char *text, int maxWidth, int fontId, int fontSize, int *width, int *height)
|
|
473
|
-
{ return measureNativeText(text, maxWidth, fontId, fontSize, 400, 1000, 0, width, height); }
|
|
496
|
+
{ return measureNativeText(text, maxWidth, fontId, fontSize, 400, 1000, 0, 0, width, height); }
|
|
474
497
|
extern "C" bool gea_host_measure_text_with_style(const char *text, int maxWidth, int fontId, int fontSize, int weight, int lineHeight, int *width, int *height)
|
|
475
|
-
{ return measureNativeText(text, maxWidth, fontId, fontSize, weight, 1000, lineHeight, width, height); }
|
|
498
|
+
{ return measureNativeText(text, maxWidth, fontId, fontSize, weight, 1000, lineHeight, 0, width, height); }
|
|
476
499
|
extern "C" bool gea_host_measure_text_with_variations(const char *text, int maxWidth, int fontId, int fontSize, int weight, int stretch, int lineHeight, int *width, int *height)
|
|
477
|
-
{ return measureNativeText(text, maxWidth, fontId, fontSize, weight, stretch, lineHeight, width, height); }
|
|
500
|
+
{ return measureNativeText(text, maxWidth, fontId, fontSize, weight, stretch, lineHeight, 0, width, height); }
|
|
501
|
+
extern "C" bool gea_host_measure_text_with_spacing(const char *text, int maxWidth, int fontId, int fontSize, int weight, int stretch, int lineHeight, int letterSpacing, int *width, int *height)
|
|
502
|
+
{ return measureNativeText(text, maxWidth, fontId, fontSize, weight, stretch, lineHeight, letterSpacing, width, height); }
|
|
478
503
|
#endif
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#import <Cocoa/Cocoa.h>
|
|
3
|
+
#import <GameController/GameController.h>
|
|
4
|
+
|
|
5
|
+
// The flat content view a Gea root renders into: the main window's (implemented
|
|
6
|
+
// in macos_main.mm) and the content view of every `<window>` (macos_windows.mm).
|
|
7
|
+
// It is the keyboard root for its subtree -- key events it receives dispatch to
|
|
8
|
+
// the focused element inside that subtree, else to the subtree's own element.
|
|
9
|
+
@interface GeaContentView : NSView <NSTextInputClient>
|
|
10
|
+
@property(nonatomic,copy) NSAttributedString *geaMarkedText;
|
|
11
|
+
@property(nonatomic) BOOL geaInterpretingDispatchedKey;
|
|
12
|
+
@property(nonatomic,strong) GCController *geaActiveController;
|
|
13
|
+
@property(nonatomic) unsigned int geaGamepadButtons;
|
|
14
|
+
@property(nonatomic) NSTimeInterval geaGamepadRepeat;
|
|
15
|
+
@property(nonatomic,strong) id geaCursorMonitor;
|
|
16
|
+
@property(nonatomic,strong) NSTrackingArea *geaPointerTracking;
|
|
17
|
+
// The `<window>` node this view hosts, or -1 for the main window's view.
|
|
18
|
+
@property(nonatomic) int geaHostedRoot;
|
|
19
|
+
- (void)geaPollGamepad;
|
|
20
|
+
@end
|