Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ is missing or empty.
`orchard launch` starts a system from internal storage: m1n1 freed its
storage command queue twice while shutting storage down.

### Development

- Orchard Simulator: an iPhone 7 alongside the iPad 6 (Device menu), each in
a realistic frame. Rotate Left and Right (⌃⌘← and ⌃⌘→) turn the device,
and the desktop follows through the same rotation-sensor path as a real
tablet. The frame's buttons no longer take the keyboard away from the
guest, and the screen comes back by itself after the VM restarts.

## [0.3.2] - 2026-11-19

### Devices
Expand Down
31 changes: 25 additions & 6 deletions simulator/GuestDisplay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ final class GuestDisplay {

init(qmpPath: String) { self.qmpPath = qmpPath }

// Set up once per connection; when the VM goes away (a restart for
// another device, say) the window connects to the next one by itself.
private var connecting = false

func start() {
guard !connecting else { return }
connecting = true
Thread.detachNewThread { [weak self] in
while let self {
var error = [CChar](repeating: 0, count: 512)
Expand All @@ -33,18 +39,31 @@ final class GuestDisplay {
Unmanaged<GuestDisplay>.fromOpaque(context!).takeUnretainedValue().changed()
},
disable: { context in
let display = Unmanaged<GuestDisplay>.fromOpaque(context!).takeUnretainedValue()
display.lock.lock()
display.pixels = nil
display.lock.unlock()
DispatchQueue.main.async { display.onConnection?(false) }
Unmanaged<GuestDisplay>.fromOpaque(context!).takeUnretainedValue().lost(reconnect: false)
},
closed: { context in
Unmanaged<GuestDisplay>.fromOpaque(context!).takeUnretainedValue().lost(reconnect: true)
})
if qd_start(self.qmpPath, callbacks, &error, Int32(error.count)) == 0 { return }
if qd_start(self.qmpPath, callbacks, &error, Int32(error.count)) == 0 {
DispatchQueue.main.async { self.connecting = false }
return
}
Thread.sleep(forTimeInterval: 1)
}
}
}

// No surface any more. A closed connection (the VM went away, a restart
// for another device, say) is followed by connecting to the next VM; a
// guest that only stopped showing one keeps its connection.
private func lost(reconnect: Bool) {
lock.lock()
pixels = nil
lock.unlock()
DispatchQueue.main.async { self.onConnection?(false) }
if reconnect { DispatchQueue.main.asyncAfter(deadline: .now() + 1) { self.start() } }
}

// One redraw per main-loop turn, however many rectangles arrived.
private func changed() {
lock.lock()
Expand Down
4 changes: 2 additions & 2 deletions simulator/build-vm-backlight
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ podman run --rm -v "$ROOT:/work" localhost/orchard-hardware-kernel-toolchain:boo
set -e
cp -r /work/simulator/vm-support /tmp/module
make -C "/work/out/simulator/kernel-build/usr/src/kernels/'"$KVER"'" M=/tmp/module CC=/work/out/simulator/kernel-build/gcc-compat modules
cp /tmp/module/orchard-vm-backlight.ko /work/out/simulator/vm/orchard-vm-backlight.ko
cp /tmp/module/orchard-vm-backlight.ko /tmp/module/orchard-vm-accel.ko /work/out/simulator/vm/
'
echo "VM backlight module built for $KVER"
echo "VM backlight and accelerometer modules built for $KVER"
26 changes: 20 additions & 6 deletions simulator/display/qemu-display.c
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ static GVariant *get_property(GDBusConnection *connection, const char *sender, c

static const GDBusInterfaceVTable LISTENER_VTABLE = {method_call, get_property, NULL};

// The listener connection went away with QEMU: the viewer hears it first
// (so it lets go of the surface), then this connection's loop ends.
static void closed(GDBusConnection *connection, gboolean vanished, GError *error, gpointer user)
{
display *d = user;
d->cb.disable(d->cb.context);
d->cb.closed(d->cb.context);
g_main_loop_quit(d->loop);
}

static GDBusConnection *connection_on(int fd, const char *guid, GDBusConnectionFlags flags, GError **error)
Expand Down Expand Up @@ -199,7 +202,17 @@ static gpointer run_loop(gpointer user)
job->done = TRUE;
g_cond_signal(&job->ready);
g_mutex_unlock(&job->lock);
if (connection) g_main_loop_run(d->loop);
if (!connection) return NULL;
g_main_loop_run(d->loop);
// Closed: nothing of this connection stays behind.
drop_surface(d);
g_object_unref(d->listener);
g_object_unref(d->qemu);
g_dbus_node_info_unref(d->info);
g_main_loop_unref(d->loop);
g_main_context_pop_thread_default(d->context);
g_main_context_unref(d->context);
g_free(d);
return NULL;
}

Expand Down Expand Up @@ -298,12 +311,13 @@ int qd_start(const char *qmp_path, qd_callbacks callbacks, char *error, int erro
g_mutex_lock(&job->lock);
while (!job->done) g_cond_wait(&job->ready, &job->lock);
g_mutex_unlock(&job->lock);
if (!d->listener) err = job->error;
g_mutex_clear(&job->lock);
g_cond_clear(&job->ready);
g_free(job);
if (!reply) goto fail;
g_variant_unref(reply);
if (!d->listener) {
err = job->error;
goto fail;
}
if (!d->listener) goto fail;
return 0;
fail:
snprintf(error, error_size, "%s", err ? err->message : "D-Bus display failed");
Expand Down
5 changes: 4 additions & 1 deletion simulator/display/qemu-display.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ typedef struct {
void (*scanout)(void *context, const void *pixels, uint32_t width, uint32_t height, uint32_t stride);
// A rectangle of the current surface changed.
void (*update)(void *context, int32_t x, int32_t y, int32_t width, int32_t height);
// The display went away (guest off, connection lost).
// The guest stopped showing a surface; the connection stays.
void (*disable)(void *context);
// The connection is gone (QEMU quit or restarted). Its thread has ended;
// a viewer that wants the next VM calls qd_start again.
void (*closed)(void *context);
} qd_callbacks;

// Connects through the QMP socket at QMP_PATH (one QEMU started with
Expand Down
Loading
Loading