Repository navigation
android: Use the system clipboard, and only tear down the surface a destroy names - #24
Merged
Merged
Conversation
Bombatomica64
added a commit
to Bombatomica64/Gpui-android
that referenced
this pull request
Oct 6, 2026
gpui-mobile: sync patch 3 with longbridge/gpui-mobile#24
AndroidClipboard kept copied text in process memory only, so copy/paste did not reach other apps and paste never saw the system clipboard. With the clipboard feature enabled, read/write now go through packages::clipboard (ClipboardManager via JNI), keeping the in-memory copy as a fallback when the JNI call fails. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
`surface_destroyed` waited on a single `SURFACE_RELEASED` flag that the render thread set on `SurfaceDestroyed` and cleared on `SurfaceCreated`. The flag can still read "released" from an earlier destroy while a `SurfaceCreated` posted before the new destroy sits unhandled in the queue, so the wait returned before the render thread had processed either command, and the `Surface` could go away just as the render thread attached to it and drew. Number each destroy request instead and wait until the render thread has handled that many. Commands are handled in order, so everything posted before the destroy has been handled too. `on_surface_created` no longer touches the state. Co-authored-by: lorenzomicheli <lorenzo.micheli@instal.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
madcodelife
force-pushed
the
fix/android
branch
from
October 9, 2026 06:23
777089c to
aadd682
Compare
Member
|
Thanks for the PR! I rebased it onto main and pushed here. The clipboard commit is unchanged. The surface one I had to rework, since #26 landed in the meantime and Your counters were still worth keeping, though. With the single |
Bombatomica64
added a commit
to Bombatomica64/Gpui-android
that referenced
this pull request
Oct 9, 2026
…18) * Build against gpui-mobile main after longbridge/gpui-mobile#24, #26 and #27 Upstream reworked #24 on top of #26, which gives each host Activity its own window keyed by a HostId. LabActivity keeps its HostId in its saved state, so a recreated instance gets its window back and a fresh launch opens a new one; onDestroy closes the window when the Activity finishes. The catalog window now opens from host::on_open_window, and back sends IME event 5. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * CI: build the release APK on GitHub Actions Builds arm64-v8a + x86_64 with ./build.sh on pushes to main, PRs and v* tags, uploads the APK as an artifact, and attaches it to the release for a v* tag. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thank you for gpui-mobile. The host-driven entry point made it possible to build a full on-device test gallery for GPUI Kit 0.7.0. While running it, I found two small Android problems and am proposing fixes for them here (the wider report is longbridge/gpui-kit#3310). Each is a separate commit, and I'm happy to split them, rework them, or drop either one if you'd prefer a different approach.
1. Back the platform clipboard with ClipboardManager
Problem
AndroidClipboardstored copied text in process memory only. Text copied in a GPUI app (for example Kit's input or TextView "Copy") could not be pasted into other apps, and paste inside the app never saw what other apps had copied. Theclipboardpackage (packages::clipboard, backed byGpuiClipboard.javaandClipboardManager) already existed but the platform clipboard did not use it.Change
With the
clipboardfeature (on by default),AndroidClipboard::read/writego throughpackages::clipboard::{get_text, set_text}. The in-process copy is kept and used as a fallback, with alog::warn!, when the JNI call fails (for example if a host does not packageGpuiClipboard.java). Without the feature, behaviour is unchanged.Testing
cargo fmt --all,cargo check,cargo ndk -t arm64-v8a checkwith and without--features clipboard, andcargo test --lib(46 passed).cargo testdoc tests:platform_viewandplatform_view_elementfail identically onmain, so that failure is not from this change.aarch64-apple-ioswas not checked (Linux machine); the change is Android-only code.2. Only tear down the surface a destroy names
Problem
On the host-driven entry point (
android::host), recreating the Activity in the same process (e.g.FLAG_ACTIVITY_CLEAR_TASK) could leave a black screen with a working app underneath. The new Activity'ssurfaceCreatedcan arrive before the old Activity'ssurfaceDestroyed.SurfaceDestroyedcarried no identity, so the render thread terminated the window that was already attached to the new surface, and nothing re-attached it.The wait in
surface_destroyed()had a related problem: it waited on one sharedSURFACE_RELEASEDflag that a latersurfaceCreatedcould reset, so overlapping destroy/create pairs could time out or return early.Change
Command::SurfaceDestroyed(Option<usize>)carries theANativeWindowbeing destroyed. The render thread callsterm_windowonly if it matchesCURRENT_SURFACE; otherwise it logs and ignores the stale destroy.pub fn surface_destroyed_for(window: &NativeWindow)for hosts that know which surface went away.surface_destroyed()keeps its signature and old meaning (it tears down whatever is attached), and its docs now point to the new function. The module docs recommendsurface_destroyed_for.DESTROYS_REQUESTED/DESTROYS_HANDLED), so each caller waits for its own request. The 2 s bound is unchanged.The
android-activitypath is untouched.Testing
cargo fmt --all,cargo check,cargo ndk -t arm64-v8a check --all-features, andcargo test --lib(46 passed).cargo testdoc tests:platform_viewandplatform_view_elementfail identically onmain, so that failure is not from this change.aarch64-apple-ioswas not checked (Linux machine); the change is Android-only code.surface_destroyed_forfromsurfaceDestroyed. Before the change, an in-process recreation turned the screen black. After it, 5 consecutive in-process recreations all had their late destroys ignored, and rendering, touch and GPUI state stayed intact.Playground used for the on-device testing: Bombatomica64/Gpui-android (prebuilt APK), in case you want to try these changes on Android.
Thanks for taking the time to review this.
🤖 Generated with Claude Code