8000 Apple clipboard and haptics: thicket-clipboard-apple, thicket-haptics-apple (#123) by rleibman · Pull Request #127 · rleibman/thicket · GitHub
[go: up one dir, main page]

Skip to content

Apple clipboard and haptics: thicket-clipboard-apple, thicket-haptics-apple (#123) - #127

Merged
rleibman merged 6 commits into
mainfrom
issue/123-apple-clipboard-haptics
Nov 2, 2026
Merged

rleibman merged 6 commits into
mainfrom
issue/123-apple-clipboard-haptics

Conversation

@rleibman
Copy link
Copy Markdown
Owner

Closes #123. The Apple half of docs/16 §16.10 item 5.

Built on #124 (feat/clipboard-haptics), which must merge first. Until then this diff includes #124's commit; the change here is the last commit.

What it adds

  • thicket-clipboard-apple
    • macOS: NSPasteboard.general, using clearContents() then setString(_, forType: .string).
    • iOS: UIPasteboard.general.string.
    • The read is synchronous; get answers on the next run-loop turn through AppleApp.postToUi. Because of that it depends on rendererApple, the way clipboardGtk depends on its renderer.
  • thicket-haptics-apple
    • iOS: UIImpactFeedbackGenerator (light, medium, heavy; one per strength, kept) and UISelectionFeedbackGenerator.
    • macOS: NSHapticFeedbackManager.defaultPerformer.
    • Needs no renderer.
  • C, not Swift. Each module has one C file under resources/scala-native.
  • macOS haptics are mapped, not Haptics.none. A Force Touch trackpad (current MacBooks, Magic Trackpad 2) plays them; with a mouse nothing is felt and nothing fails.
    • Mapping: Light → .alignment, Medium → .generic, Heavy → .levelChange, selection → .alignment.
    • availability is Available, because AppKit does not say whether such a trackpad is attached.
  • Galleries: both Apple hosts pass clipboard and haptics in Services.
    • The Apple self-test mirrors clipboardChecks: Copy then Paste, twice, then the haptics label and "Tap".
    • It pastes only after the copy has raised the pasteboard's changeCount (see below).
  • bin/verify-apple.sh reads the gallery's last copy from outside the app after each run: pbpaste on macOS, which also puts the user's clipboard back afterwards, and xcrun simctl pbpaste on iOS.

Measured

bin/verify-apple.sh "iPhone Air" (macOS 27.0.1, Xcode 27.0, iOS 27.0 simulator): all 16 steps PASS.

Check Result
macOS gallery, both runs 188/188 (185 + 3)
iOS gallery ("iPhone Air") 182/182 (179 + 3)
pbpaste after each macOS run Thicket gallery 44460, copy 2 / Thicket gallery 9382, copy 2, matching the gallery's last copy
xcrun simctl pbpaste "iPhone Air" Thicket gallery 1759, copy 2, matching
Copy → paste answer time iOS 25–77 ms; macOS ~220 ms (not investigated; well inside the 5 s wait)
Haptics on the simulator Available; the "Tap" call returns. The simulator plays nothing, so that is all it can show

iOS "Allow Paste" on the simulator (screenshots taken during the runs):

  • Text the process copied itself: no prompt.
  • Text from xcrun simctl pbcopy: prompt, "GalleryIos would like to paste from CoreSimulatorBridge".
  • The same app's copy from an earlier launch: prompt as well, "… would like to paste from GalleryIos".
  • While the prompt is up, UIPasteboard.string blocks the main thread until the user answers. In the run it waited the full 120 s and was never answered. Nothing can tap the prompt from the command line, so neither answer was measured.
  • That is why the self-test pastes only after its copy has registered. Without that check, a broken set hung the run instead of failing it.

Falsified

  • set doing nothing, with the final self-test: bo 8000 th rounds fail on macOS and on the simulator. The change count stays put, and the outside reads show the older text.
  • The earlier version without the changeCount gate:
    • macOS failed both rounds by pasting the old (empty) clipboard.
    • iOS hung on "Allow Paste", which is what led to the gate.

Not done

  • Haptics not felt on a device or a Force Touch trackpad: that needs a person.
  • No unit tests in the two new modules: they would overwrite the user's real pasteboard. The gallery self-test is the test.
  • The user's macOS clipboard is restored as text only (pbpaste/pbcopy). An image on it would not survive a run. Here it was empty before and after.

🤖 Generated with Claude Code

rleibman and others added 2 commits October 30, 2026 12:27
…ptics (-android), the gallery's section

docs/16 §16.10 item 5, first half. Also records the owner's decisions for the pickers: picked
files copied into the app's cache and returned as a Path; results by UI-thread callback.

- thicket-clipboard: set(text), get(onResult), text only; GdkClipboard (async read) and
  Android's ClipboardManager; MemoryClipboard for tests.
- thicket-haptics: impact(Light | Medium | Heavy), selection(), availability; Android's
  performHapticFeedback; GTK uses Haptics.none; RecordingHaptics for tests.

Measured:
- bin/with-keyring.sh sbt -J-Xmx8G --error checkLinux: exit 0; clipboard 1, haptics 2 tests.
- bin/gtk-selftests.sh: gallery 131 (128 + 3), todo 69. wl-paste in another process read the
  gallery's copy.
- SELFTEST=1 examples/gallery/android/build.sh on s2test: 76/76 (71 + 5); build.sh now finds
  the gallery's taps in dumpsys vibrator_manager (2 played, Prebaked=CLICK).

Falsified: with set doing nothing, both copy-and-paste rounds fail on GTK and Android (each
pasting a previous run's text). With performHapticFeedback not called, the in-app check and
build.sh's vibrator count both fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-apple (#123)

The Apple half of docs/16 §16.10 item 5, built on #124.

- thicket-clipboard-apple: NSPasteboard (clearContents, setString(_, forType: .string)) and
  UIPasteboard.general.string. Reads synchronously, answers on the next run-loop turn.
- thicket-haptics-apple: UIImpactFeedbackGenerator (light/medium/heavy) and
  UISelectionFeedbackGenerator; on macOS NSHapticFeedbackManager (mapped, not Haptics.none:
  Force Touch trackpads).
- Both are one C file each through the Objective-C runtime, compiled by Scala Native's clang,
  frameworks named in the object (as #108). No Swift, no shim-gen ABI.
- Both galleries pass them in Services; the Apple self-test copies and pastes twice, pasting
  only after the copy raised changeCount, then checks the haptics label and "Tap".
- bin/verify-apple.sh reads the last copy from outside: pbpaste (restoring the user's
  clipboard) and xcrun simctl pbpaste.

Measured (bin/verify-apple.sh "iPhone Air", iOS 27.0 sim, Xcode 27.0): all 16 steps PASS.
Gallery macOS 188 (185 + 3) on both runs, iOS 182 (179 + 3). Outside reads matched the last
copy on all three runs. Own copies read back with no prompt in 25-77 ms on iOS (~220 ms on
macOS). Text from simctl pbcopy, and the same app's copy from an earlier launch, show "Allow
Paste" and block the read until answered.

Falsified: with set doing nothing, both rounds fail on macOS and on the simulator.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The change hinges on hand-written Objective-C FFI correctness that only the author could verify by running on macOS/iOS, which is not reproducible in this Linux review environment.

No open issues 🎉

What changed in this PR

This PR adds the Apple half of Thicket's clipboard and haptics device services (docs/16 §16.10 item 5, issue #123), stacked on #124 which built the base modules plus GTK/Android. It introduces two new Scala Native modules — thicket-clipboard-apple (NSPasteboard/UIPasteboard) and thicket-haptics-apple (UIImpactFeedbackGenerator/UISelectionFeedbackGenerator/NSHapticFeedbackManager) — each backed by a small C helper that drives Objective‑C through objc_msgSend and links UIKit/AppKit via LC_LINKER_OPTION, mirroring #108's Keychain helper rather than adding a Swift shim. Both galleries pass the services through, a combined ClipboardDemo and self-tests exercise copy/paste/tap, and bin/verify-apple.sh reads the pasteboard back from outside the app.

Changes:

  • New thicket-clipboard-apple / thicket-haptics-apple modules (C helpers + Scala FFI), wired into build.sbt (platforms, galleries), with clipboard depending on rendererApple for postToUi and haptics needing no renderer.
  • Gallery integration: Services gains clipboard/haptics, a "Clipboard and haptics" section, ClipboardDemo, and self-test checks on all four hosts (Apple gates each paste on a raised pasteboard changeCount to avoid the iOS "Allow Paste" hang).
  • Documentation and verification updates (decision log, docs/12/14/16, module READMEs, verify-apple.sh pasteboard read-back, Android build.sh vibrator check).

I reviewed the native Objective‑C FFI (msgSend casts, autorelease/retain of kept generators, CoreFoundation string bridging, framework linking), the Scala↔C ABI signatures, the strength→pattern mappings (light→Alignment, medium→Generic, heavy→LevelChange; selection→Alignment), the gallery/self-test wiring, build aggregation, -release 17 placement, and doc counts. Verified all Services(...) call sites and the single screen(...) caller are updated, and that self-test helpers (eventually, buttonIn, AppleInspect.*, Await) and the integration points exist and match. I found no objective defects to report; the implementation is internally consistent and matches the established C-helper pattern.

File Description
modules/​clipboard-apple/​.../​AppleClipboard.scala Scala FFI + synchronous read answered via postToUi; changeCount for self-test
modules/​clipboard-apple/​.../​thicket_pasteboard.c C helper: general pasteboard set/get/free/changeCount via objc_msgSend
modules/​haptics-apple/​.../​AppleHaptics.scala Scala FFI for impact/selection + availability
modules/​haptics-apple/​.../​thicket_feedback.c C helper: iOS feedback generators, macOS NSHapticFeedbackManager
modules/​clipboard/​.../​Clipboard.scala, MemoryClipboard.scala, ClipboardSpec.scala Core clipboard API + in-memory fake + unit test
modules/​haptics/​.../​Haptics.scala, RecordingHaptics.scala, HapticsSpec.scala Core haptics API + recording fake + unit tests
`modules/​clipboard-gtk android/..., haptics-android/...`
examples/​gallery/​.../​ClipboardDemo.scala, Gallery.scala, StorageDemo.scala Combined demo, gallery section, Services fields
examples/​gallery/​{macos,ios,gtk,android}/​... Host wiring + self-test checks for clipboard/haptics
examples/​gallery/​android/​build.sh, bin/​verify-apple.sh External pasteboard/vibrator verification
build.sbt New module defs, dependencies, platforms/root aggregation
README.md, docs/​{12,14,16}, docs/​decisions.md, module READMEs Status, release, counts, decision log

No blocking issues found. The native Apple FFI and iOS pasteboard-prompt behavior are only verifiable on macOS/iOS (done by the author: all 16 verify-apple.sh steps pass), which can't be reproduced in this Linux review environment.

Review effort: Balanced

@rleibman
Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request

…oard-haptics

# Conflicts:
#	README.md
#	build.sbt
#	docs/12-component-status.md
#	docs/14-releasing.md
#	docs/16-device-services.md
#	docs/decisions.md
#	examples/gallery/README.md
#	examples/gallery/shared/shared/src/main/scala/example/gallery/StorageDemo.scala
#	modules/clipboard/README.md
#	modules/haptics/README.md

Co-authored-by: rleibman <3268890+rleibman@users.noreply.github.com>
Copilot AI commented Oct 31, 2026
Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Done — I merged origin/main into this branch and resolved the conflicts in commit d33688a.

…oard-haptics

# Conflicts:
#	README.md
#	build.sbt
#	docs/12-component-status.md
#	docs/14-releasing.md
#	docs/16-device-services.md
#	docs/decisions.md
#	examples/gallery/README.md
#	examples/gallery/shared/shared/src/main/scala/example/gallery/StorageDemo.scala
@rleibman
rleibman commented Nov 1, 2026
Copy link
Copy Markdown
Owner Author

Merged main into this branch (9cbcb76) to resolve the conflicts with the pickers (#131). All eight conflicts were both sides adding lines in the same places, so each keeps both:

  • build.sbt: clipboardApple and hapticsApple beside pickers, pickersGtk and pickersAndroid, and both pairs in platforms.
  • StorageDemo.scala: your haptics @PARAM wording, plus @param pickers.
  • The docs (README, docs/12, docs/14, docs/16, the decision log, the gallery README): your Apple text, plus the pickers' lines. Both decision-log entries are kept, yours first.

Checked on Linux: sbt -J-Xmx8G --error platforms/Test/compile is clean, which type-checks the Apple modules too. Not run here: the Apple self-tests. The macOS and iOS galleries now also show the Pickers section ("No pickers on this platform yet" until #125), so their check counts may move. Apple CI on this push will show it.

The camera, #130, also merged into a stale base; #133 brings it to main, and it will touch the same files when it lands.

…top of #124 as merged

#124 merged as a squash, so this tree is main plus #127's own commit
(634e2c4), not a merge of the old feat/clipboard-haptics snapshot. The commit
applied onto main with no conflicts.

Measured on the result, "iPhone 18 Pro": bin/verify-apple.sh 16 of 17 on the
first pass, with the macOS gallery failing a preferences check. That was a
collision with another worktree's gallery writing the same Application Support
file at the same time. Run alone, after clearing the gallery's Keychain item as
verify-apple does: macOS gallery 188/188, twice. iOS gallery 182/182; pbpaste
and simctl pbpaste show the last copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rleibman
rleibman commented Nov 1, 2026
Copy link
Copy Markdown
Owner Author

Merged main (#124 had merged as a squash). The branch is now main plus this PR's own commit, which applied with no conflicts. Re-verified on "iPhone 18 Pro": macOS gallery 188/188 twice, iOS 182/182, and the HTTP, todo and getting-started steps pass. The one first-pass failure was another worktree's gallery writing the same preferences file at the same time; it passed run alone.

Copilot AI left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

A critical finding shows the PR appears based on a stale main and would revert the entire unrelated pickers feature across many files, an active issue that must be resolved before merging.

No open issues 🎉

Review effort: Balanced

63613bf rebuilt this branch's tree as #124 plus 634e2c4, but its parents already
held the pickers (#131), so as a merge it deleted them: modules/pickers*,
PickersDemo, PickerDriver, GtkPickers, AndroidPickers, ThicketActivity's
onActivityResult, and their docs (-1319 lines against main). Merging #127 would
have removed the pickers from main.

This tree is main plus the Apple-only diff (ca56ab2..63613bf: 18 files, the two
C helpers, AppleClipboard, AppleHaptics, the Apple galleries, verify-apple.sh and
the docs), with the doc and build conflicts keeping both sides.

Measured: platforms/Test/compile clean (type-checks the Apple Scala);
git diff --stat origin/main: 18 files, nothing outside the Apple change. Not
measured here: the Apple self-tests, which need the Mac.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rleibman
rleibman commented Nov 1, 2026
Copy link
Copy Markdown
Owner Author

Heads-up for the Mac session: 63613bf rebuilt this branch's tree as #124 + 634e2c4, but its parents already contained the pickers (#131), so as a merge it deleted them (modules/pickers*, PickersDemo, PickerDriver, GtkPickers, AndroidPickers, ThicketActivity.onActivityResult, their docs: −1319 lines against main). Merging this PR as it stood would have removed the pickers from main.

b18dbc7 fixes that without a force-push: its tree is current main (pickers and camera) plus only the Apple diff ca56ab2..63613bf (18 files). git diff --stat origin/main is now those 18 files and nothing else. platforms/Test/compile is clean; the Apple self-tests weren't run here. Please pull before pushing again, and when bringing main in, merge it rather than rebuilding the tree from an older base.

🤖 Generated with Claude Code

@rleibman
rleibman merged commit a969c41 into main Nov 2, 2026
2 checks passed
rleibman added a commit that referenced this pull request Nov 2, 2026
Conflicts in build.sbt, docs/14, docs/16 and the decision log, both sides kept.

Measured: checkLinux exit 0; platforms/Test/compile clean. #127 is Apple-only,
so the GTK (138) and Android (90) gallery counts from b566122 stand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rleibman added a commit that referenced this pull request Nov 2, 2026
Both sides grew the Apple galleries:
- GalleryIos/GalleryMac: Services get device, clipboard and haptics.
- GallerySelfTest: storage -> device -> clipboard -> sheet -> big list, both
  check groups kept.
- build.sbt: the Apple galleries depend on deviceApple, clipboardApple and
  hapticsApple.
- verify-apple.sh's header, docs/12's Apple counts (the two measured apart; the
  combined run is the Mac's) and the decision log keep both.

Measured: platforms/Test/compile clean (type-checks the Apple Scala). Not
measured: the Apple self-tests on the combined gallery, which need the Mac.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rleibman added a commit that referenced this pull request Nov 2, 2026
Both sides grew the Apple galleries: Services get device, motion, clipboard and
haptics; the self-test runs storage -> device -> motion -> clipboard -> sheet ->
big list; the Apple galleries depend on motionIos, clipboardApple and
hapticsApple. Docs keep both sides (README, docs/12, 14, 16); the decision log's
2026-11-01 entry moved back to the top.

Measured: platforms/Test/compile clean. #127 is Apple-only, so cc3ee5a's GTK
(137) and Android (86) counts stand. Not measured: the Apple self-tests on the
combined gallery (the Mac's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rleibman added a commit that referenced this pull request Nov 2, 2026
Both sides grew the Apple galleries: Services get device, location, clipboard
and haptics; the self-test runs storage -> device -> location -> clipboard ->
sheet -> big list; the Apple galleries depend on locationApple, clipboardApple
and hapticsApple. docs/12, 14 and the decision log keep both sides; its
2026-11-01 entry moved back to the top.

Measured: platforms/Test/compile clean. Shared gallery code is unchanged from
427494e but for #127's Apple-only additions. Not measured: the Apple self-tests
on the combined gallery (the Mac's).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apple clipboard and haptics: NSPasteboard / UIPasteboard, UIImpactFeedbackGenerator

3 participants

0