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
34 changes: 34 additions & 0 deletions crates/ocs_plugin_api/src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,21 @@ pub enum HostNotification {
snapshot: Option<DocumentDeltaSnapshot>,
full_refresh_required: bool,
},
/// A semantic panel-surface event (api v29): what the user did to
/// which element of `panel_id`, with the surface's monotonic event
/// `sequence` as the explicit event identity — identical-looking
/// activations are DISTINCT events, and equality is not identity.
/// Best-effort by contract: never acknowledged by re-publishing
/// values; drag moves may be coalesced (positions are absolute), but
/// `DragSettled` and `DragCancelled` are authoritative and never
/// dropped. Only routed to plugins whose manifest declares v29 — a
/// v28 runner cannot decode tag 16
/// (`notification_api_version` gate). Discriminant 16.
PanelSurfaceEvent {
panel_id: String,
sequence: u64,
event: crate::scene::SurfaceEvent,
},
/// Fallback for notification variants added in future minor revisions.
/// Carries the raw bincode payload so an older peer can ignore it without
/// failing deserialization.
Expand Down Expand Up @@ -722,6 +737,16 @@ impl Serialize for HostNotification {
bincode::serialize_into(&mut bytes, full_refresh_required)
.map_err(serde::ser::Error::custom)?;
}
HostNotification::PanelSurfaceEvent {
panel_id,
sequence,
event,
} => {
bytes.push(16);
bincode::serialize_into(&mut bytes, panel_id).map_err(serde::ser::Error::custom)?;
bincode::serialize_into(&mut bytes, sequence).map_err(serde::ser::Error::custom)?;
bincode::serialize_into(&mut bytes, event).map_err(serde::ser::Error::custom)?;
}
HostNotification::Unknown(raw) => bytes.extend_from_slice(raw),
}
bytes.serialize(serializer)
Expand Down Expand Up @@ -853,6 +878,15 @@ impl<'de> Deserialize<'de> for HostNotification {
},
)
.map_err(serde::de::Error::custom),
16 => bincode::deserialize(rest)
.map(
|(panel_id, sequence, event)| HostNotification::PanelSurfaceEvent {
panel_id,
sequence,
event,
},
)
.map_err(serde::de::Error::custom),
_ => Ok(HostNotification::Unknown(bytes)),
}
}
Expand Down
44 changes: 43 additions & 1 deletion crates/ocs_plugin_api/src/ipc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ mod tests {
use std::thread;

use interprocess::local_socket::{
traits::{Listener, Stream as StreamTrait},
GenericNamespaced, ListenerOptions, Stream, ToNsName,
traits::{Listener, Stream as StreamTrait},
};

use crate::ipc::protocol::{HostRequest, HostResponse, HostToPlugin, PluginToHost};
Expand Down Expand Up @@ -712,4 +712,46 @@ mod tests {
other => panic!("unexpected: {other:?}"),
}
}

/// The v29 panel-surface event notification is pinned at tag 16
/// (appended after the v27 delta's 15) and round-trips with its
/// sequence (the explicit event identity) and typed event payload.
#[test]
fn panel_surface_event_notification_tag_is_sixteen() {
let notification = crate::host::HostNotification::PanelSurfaceEvent {
panel_id: "acme:graph".to_owned(),
sequence: 42,
event: crate::scene::SurfaceEvent::DragSettled {
element: crate::scene::StableId(3),
pos: crate::scene::Vec2([7.0, 9.0]),
},
};
fn tag(notification: &crate::host::HostNotification) -> u8 {
// The wire frame is [u64 length][tag byte][fields] — the tag
// sits after the bincode length prefix (the v27 comment above
// explains the append-only tag story).
let bytes = bincode::serialize(notification).unwrap();
bytes[8]
}
assert_eq!(tag(&notification), 16);
let bytes = bincode::serialize(&notification).expect("serialize notification");
match bincode::deserialize::<crate::host::HostNotification>(&bytes)
.expect("deserialize notification")
{
crate::host::HostNotification::PanelSurfaceEvent {
panel_id,
sequence,
event,
} => {
assert_eq!(panel_id, "acme:graph");
assert_eq!(sequence, 42);
assert!(matches!(
event,
crate::scene::SurfaceEvent::DragSettled { element, pos }
if element == crate::scene::StableId(3) && pos == crate::scene::Vec2([7.0, 9.0])
));
}
other => panic!("unexpected: {other:?}"),
}
}
}
2 changes: 1 addition & 1 deletion crates/ocs_plugin_api/src/ipc/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ fn read_with_poll<R: Read>(
return Err(PollError::Io(ProxyError::Io(std::io::Error::new(
std::io::ErrorKind::UnexpectedEof,
"proxy disconnected",
))))
))));
}
Ok(n) => off += n,
Err(e) if e.kind() == ErrorKind::WouldBlock || e.kind() == ErrorKind::TimedOut => {
Expand Down
2 changes: 1 addition & 1 deletion crates/ocs_plugin_api/src/ipc/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use std::io::{Read, Write};

use interprocess::local_socket::Stream;
use serde::{de::DeserializeOwned, Serialize};
use serde::{Serialize, de::DeserializeOwned};

/// Maximum serialized message size accepted over the wire (1 GiB). Prevents
/// a malicious or buggy peer from exhausting host/runner memory, while a full
Expand Down
23 changes: 14 additions & 9 deletions crates/ocs_plugin_api/src/ipc/v4/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ use std::collections::{HashMap, VecDeque};
use std::path::Path;
use std::rc::Rc;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{mpsc, Arc, Mutex};
use std::sync::{Arc, Mutex, mpsc};
use std::time::{Duration, Instant};

use document::xdata::ExtendedDataRecord;
use document::{Document, EntityType, Handle};
use interprocess::TryClone;
use interprocess::local_socket::traits::Stream as StreamTrait;
use interprocess::local_socket::{GenericNamespaced, Stream, ToNsName};
use interprocess::TryClone;

use crate::host::{
DocumentReader, ExecutionResult, HostApi, HostNotification, HostSettingValue,
Expand All @@ -22,7 +22,7 @@ use crate::host::{
use crate::ipc::protocol::{
HostRequest, HostResponse, PluginRequest, PluginResponse, RunnerHandshake,
};
use crate::ipc::transport::{recv, send, TransportError};
use crate::ipc::transport::{TransportError, recv, send};
use crate::ipc::v4::protocol::{
HostToPluginV4, NotificationEnvelope, PluginToHostV4, V4_PROTOCOL_VERSION,
};
Expand Down Expand Up @@ -106,8 +106,9 @@ impl V4Client {
});

let shared_for_reader = Arc::clone(&shared);
let notifications =
Arc::new(Mutex::new(VecDeque::<(Option<u64>, HostNotification)>::new()));
let notifications = Arc::new(Mutex::new(
VecDeque::<(Option<u64>, HostNotification)>::new(),
));
let notifications_for_loop = Arc::clone(&notifications);
std::thread::spawn(move || {
reader_thread(reader, shared_for_reader, runner_tx, notifications)
Expand Down Expand Up @@ -229,7 +230,10 @@ fn reader_thread(
}
}
Ok(HostToPluginV4::Notification(envelope)) => {
let is_sel4 = matches!(&envelope.payload, HostNotification::SelectionChangedV4 { .. });
let is_sel4 = matches!(
&envelope.payload,
HostNotification::SelectionChangedV4 { .. }
);
let mut queue = notifications.lock().unwrap_or_else(|e| e.into_inner());
if is_sel4 {
// Latest-wins, head-priority: a selection change is
Expand Down Expand Up @@ -1560,8 +1564,9 @@ impl V4Client {
in_flight: Mutex::new(HashMap::new()),
});
let shared_for_reader = Arc::clone(&shared);
let notifications =
Arc::new(Mutex::new(VecDeque::<(Option<u64>, HostNotification)>::new()));
let notifications = Arc::new(Mutex::new(
VecDeque::<(Option<u64>, HostNotification)>::new(),
));
let notifications_for_loop = Arc::clone(&notifications);
std::thread::spawn(move || {
reader_thread(reader, shared_for_reader, runner_tx, notifications)
Expand Down Expand Up @@ -1595,8 +1600,8 @@ mod tests {
use std::thread;

use interprocess::local_socket::{
traits::{Listener, Stream as StreamTrait},
GenericNamespaced, ListenerOptions, Stream, ToNsName,
traits::{Listener, Stream as StreamTrait},
};

use super::*;
Expand Down
30 changes: 16 additions & 14 deletions crates/ocs_plugin_api/src/ipc/v4/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,20 +1018,22 @@ mod tests {
// API v15: quad registration frames survive one bincode hop intact;
// the icon rides the OwnedIconKind encoding (ribbon precedent) and
// the response keeps one outcome per panel.
let panels = vec![crate::dialog::QuadPanelDef::new("align_tools", "Align")
.with_applies_to(vec!["LWPOLYLINE".to_owned()])
.with_item(crate::dialog::QuadItemDef {
control_id: "flip".to_owned(),
label: "Flip".to_owned(),
icon: crate::ribbon::owned::OwnedIconKind::Svg("<svg/>".into()),
action: crate::dialog::QuadActionDef::Command("FLIPALIGNED".to_owned()),
})
.with_item(crate::dialog::QuadItemDef {
control_id: "report".to_owned(),
label: "Report".to_owned(),
icon: crate::ribbon::owned::OwnedIconKind::Glyph("\u{1F4CA}".to_owned()),
action: crate::dialog::QuadActionDef::Callback,
})];
let panels = vec![
crate::dialog::QuadPanelDef::new("align_tools", "Align")
.with_applies_to(vec!["LWPOLYLINE".to_owned()])
.with_item(crate::dialog::QuadItemDef {
control_id: "flip".to_owned(),
label: "Flip".to_owned(),
icon: crate::ribbon::owned::OwnedIconKind::Svg("<svg/>".into()),
action: crate::dialog::QuadActionDef::Command("FLIPALIGNED".to_owned()),
})
.with_item(crate::dialog::QuadItemDef {
control_id: "report".to_owned(),
label: "Report".to_owned(),
icon: crate::ribbon::owned::OwnedIconKind::Glyph("\u{1F4CA}".to_owned()),
action: crate::dialog::QuadActionDef::Callback,
}),
];
let bytes = bincode::serialize(&PluginRequest::RegisterQuadPanels {
panels: panels.clone(),
})
Expand Down
4 changes: 2 additions & 2 deletions crates/ocs_plugin_api/src/ipc/v4/server.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Host-side V4 IPC reader and dispatcher helpers.

use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{mpsc, Arc, Mutex};
use std::sync::{Arc, Mutex, mpsc};
use std::time::{Duration, Instant};

use interprocess::local_socket::Stream;

use crate::host::PluginNotification;
use crate::ipc::transport::{recv, TransportError};
use crate::ipc::transport::{TransportError, recv};
use crate::ipc::v4::protocol::PluginToHostV4;

/// Default plugin→host notification rate limit (notifications per second).
Expand Down
9 changes: 5 additions & 4 deletions crates/ocs_plugin_api/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::rc::Rc;
use crate::host::{BuiltinPlugin, CommandStep, HostNotification, InteractiveCommand};
use crate::ipc::client::{InteractiveRegistry, IpcClient, PluginHostApi};
use crate::ipc::protocol::{
HostRequest, HostResponse, HostToPlugin, InteractiveEvent, PluginToHost, PLUGIN_TOKEN_ENV,
HostRequest, HostResponse, HostToPlugin, InteractiveEvent, PLUGIN_TOKEN_ENV, PluginToHost,
};
use crate::ipc::transport::{recv, send};
use crate::ipc::v4::client::{RunnerFrame, V4Client};
Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn run_with_plugin(
version: u32,
mut plugin: Box<dyn BuiltinPlugin>,
) -> Result<(), Box<dyn std::error::Error>> {
use crate::version_info::{wire_schema, SELF_HOSTED_API_VERSION, WIRE_SCHEMA_ENV};
use crate::version_info::{SELF_HOSTED_API_VERSION, WIRE_SCHEMA_ENV, wire_schema};
if version >= SELF_HOSTED_API_VERSION {
if let Ok(host) = std::env::var(WIRE_SCHEMA_ENV) {
if host != wire_schema() {
Expand Down Expand Up @@ -354,6 +354,7 @@ fn notification_api_version(notification: &crate::host::HostNotification) -> u32
N::SelectionChangedDigest { .. } => 22,
N::DocumentChangedRegions { .. } => 13,
N::DocumentChangedDelta { .. } => 27,
N::PanelSurfaceEvent { .. } => 29,
N::DocumentOpened { .. } => 9,
N::CommandStateChanged { .. } | N::DrawingChanged { .. } => 7,
N::DocumentChangedV4 { .. }
Expand Down Expand Up @@ -663,7 +664,7 @@ fn handle_host_request_v4(
Err(_) => {
return Some(HostResponse::Error(
"plugin entity_classes() panicked".to_string(),
))
));
}
};
}
Expand Down Expand Up @@ -1066,8 +1067,8 @@ mod tests {
use std::thread;

use interprocess::local_socket::{
traits::{Listener, Stream as StreamTrait},
GenericNamespaced, ListenerOptions, Stream, ToNsName,
traits::{Listener, Stream as StreamTrait},
};

use super::*;
Expand Down
27 changes: 27 additions & 0 deletions crates/ocs_plugin_api/src/scene.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,33 @@ pub struct SurfaceReject {
pub current_revision: Option<SceneRevision>,
}

/// One semantic event from a panel surface (api v29, S04): what the user
/// did to WHICH element, carrying absolute scene-space positions. Events
/// are best-effort notifications — never acked by re-publishing values
/// (identical-looking activations are DISTINCT events; equality is not
/// event identity). Drag moves may be coalesced by the host (absolute
/// positions carry all the information); `DragSettled` and
/// `DragCancelled` are authoritative and never dropped.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SurfaceEvent {
/// A click (press + release without drag) on an element. The plugin
/// binds its own semantics to the element id — the host does not
/// interpret scene vocabulary.
ElementClicked { element: StableId, pos: Vec2 },
/// A drag began on an element; `origin` is the scene-space point the
/// element occupied when the drag started.
DragStarted { element: StableId, origin: Vec2 },
/// A coalesced drag move; `pos` is the element's CURRENT scene-space
/// origin (absolute — dropped intermediate moves lose nothing).
DragMoved { element: StableId, pos: Vec2 },
/// THE authoritative settle: the final origin after the drop.
/// Exactly one per drag; never coalesced away.
DragSettled { element: StableId, pos: Vec2 },
/// The drag was cancelled (escape, focus loss, teardown). `origin` is
/// the PRE-DRAG origin, so the plugin can restore losslessly.
DragCancelled { element: StableId, origin: Vec2 },
}

/// Maximum patch ops accepted in one patch frame, bounding allocation and
/// CPU magnification per frame (mirrors [`MAX_SCENE_NODES`]'s spirit: the
/// cap is well above any authored update and far below a denial budget).
Expand Down
5 changes: 4 additions & 1 deletion src/app/dock/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,10 @@ impl OpenCADStudio {
.map(|scene| (owner.to_owned(), scene))
}) {
let (owner, scene) = scene;
crate::ui::window::plugin_scene::scene_view(&owner, panel_id, scene)
let preview = self.panel_event_router.drag_preview(panel_id);
crate::ui::window::plugin_scene::scene_view(
&owner, panel_id, scene, preview,
)
} else {
state.view(num, width, chrome)
}
Expand Down
11 changes: 11 additions & 0 deletions src/app/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,17 @@ pub enum Message {
},
/// Live text change in a plugin modal dialog control.
PluginDialogTextChange(String, String),
/// Raw pointer transition on a plugin scene surface (api v29): the
/// canvas resolved the scene-space position and the topmost element;
/// the app's `PanelEventRouter` owns the semantics (click vs drag,
/// coalescing, settle/cancel) and delivery to the owning plugin.
PanelSurfacePointer {
owner: String,
panel: String,
pointer: crate::app::panel_events::Pointer,
element: Option<ocs_plugin_api::scene::StableId>,
pos: ocs_plugin_api::scene::Vec2,
},
/// Checkbox toggle in a plugin modal dialog control.
PluginDialogBoolToggle(String, bool),
/// Dropdown choice selection in a plugin modal dialog control.
Expand Down
10 changes: 10 additions & 0 deletions src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ pub(crate) mod node_graph;
#[cfg(test)]
mod object_isolation_tests;
mod options_session;
/// Pure panel-surface event routing (api v29): pointer semantics, drag
/// state machine, per-surface event identity. Host-owned input; no
/// renderer or wire coupling.
pub mod panel_events;
#[cfg(test)]
mod paste_special_tests;
#[cfg(not(target_arch = "wasm32"))]
Expand Down Expand Up @@ -1638,6 +1642,10 @@ pub(super) struct OpenCADStudio {
/// UI projects from it, nothing here draws.
pub(crate) panel_surfaces:
crate::app::panel_surfaces::PanelSurfaceStore,
/// Pointer semantics for panel scene surfaces (api v29): click vs
/// drag, move coalescing, settle/cancel; per-surface event identity.
pub(crate) panel_event_router:
crate::app::panel_events::PanelEventRouter,
/// Numeric mapping for PanelId::Plugin(u32).
pub(crate) plugin_panel_ids: std::collections::HashMap<String, u32>,
pub(crate) plugin_panel_by_num: std::collections::HashMap<u32, String>,
Expand Down Expand Up @@ -3243,6 +3251,8 @@ impl OpenCADStudio {
plugin_panels: std::collections::BTreeMap::new(),
panel_surfaces:
crate::app::panel_surfaces::PanelSurfaceStore::default(),
panel_event_router:
crate::app::panel_events::PanelEventRouter::new(),
plugin_panel_ids: std::collections::HashMap::new(),
plugin_panel_by_num: std::collections::HashMap::new(),
hyperlink_editor_handles: Vec::new(),
Expand Down
Loading
Loading