app: cherry-pick rune's pause and sound fixes onto the checkout
Rune comes from app/vendor/rune now, a checkout of 63ad0209 on branch ported, carrying the four commits of upstream issues 1320 (a pause while a clip is layered holds the layer's picture and time) and 1325 (a video's sound is read ahead of the clock and leads it). Both were written against eb9f1104 and ported across the refactors since. The faults are the first two and the third in docs/rune-upstream.md; the app's workarounds in review.rs stay until the fixes arrive upstream.
This commit is contained in:
1 parent
80fef698ce
commit
5bf262b82b
3795 files changed
+663463
-28
No files matched your search
+11
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "overlay"
|
||||
version = "0.0.1"
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
rune = { workspace = true, default-features = true, features = ["keys-overlay"] }
|
||||
|
||||
[lints]
|
||||
workspace = true
|
||||
+71
@@ -0,0 +1,71 @@
|
||||
# Display overlays
|
||||
|
||||
One normal control window and one transparent, borderless, always-on-top overlay
|
||||
per display. The overlays pass clicks through by default. “Test overlay input”
|
||||
enables hit-testing; clicking any overlay restores click-through on all of them.
|
||||
This keeps the normal control window reachable. Each overlay draws a stroke and shares one
|
||||
background-driven `Live<[f32; 2]>` remote cursor. Updates stop after four seconds.
|
||||
|
||||
```rust
|
||||
rune::run_windows(|displays| {
|
||||
displays.iter().enumerate().map(|(i, display)| {
|
||||
rune::WindowSpec::new(format!("overlay-{i}"), app_spec())
|
||||
.options(rune::WindowOptions::overlay(display))
|
||||
.on_created(|window| {
|
||||
// CGWindowID on macOS; retain these for ScreenCaptureKit exclusions.
|
||||
let number = window.window_number();
|
||||
// window.set_click_through(false)?;
|
||||
})
|
||||
}).collect()
|
||||
});
|
||||
```
|
||||
|
||||
`WindowSpec::state(state)` supplies distinct initial state while sharing services
|
||||
or Live handles. The factory runs once after monitor enumeration. Display origins
|
||||
and `WindowOptions::position/physical_size` are physical pixels, including negative
|
||||
origins; `AppSpec::size` and view layout use logical points.
|
||||
|
||||
Use `WindowSpec::from_app(key, App::new(spec).keep_running())` when a window must
|
||||
retain its state after closing. The App's handle opens/activates/updates that window;
|
||||
`WindowHandle::open` can also reopen a retained host. Default hosts are removed on
|
||||
close, and the last host ends the loop. Any `AppHandle::quit` or `Tx::quit` quits the
|
||||
whole loop. The outer tooling arguments apply to all specs; `App::args` is ignored
|
||||
inside `run_windows`. `App::accessory` is a process launch option for `App::run`,
|
||||
not a per-window option; `run_windows` starts with regular activation policy.
|
||||
Use `run_windows_with_args(RunOptions { accessory: true }, [], factory)`
|
||||
for a menu-bar app whose command-line flags belong to its host, not Rune.
|
||||
An AppHandle's `set_dock_icon` still changes the whole process at runtime.
|
||||
|
||||
```sh
|
||||
cargo build --release -p overlay
|
||||
target/release/overlay --list-windows
|
||||
target/release/overlay --window controls --snap controls.png
|
||||
target/release/overlay --window overlay-0 --snap overlay.png --at 2
|
||||
target/release/overlay --window overlay-0 --trace overlay.jsonl --frames 720 --fps 120
|
||||
```
|
||||
|
||||
Headless tools select one window by its stable key and use one virtual display
|
||||
(1920×1080 physical pixels, 2× scale by default). They create no native windows;
|
||||
`on_created` does not run. `--size` and `--scale` override the selected capture.
|
||||
Overlay PNGs retain transparency. A stroke is an SVG icon rasterized by Rune;
|
||||
an interactive drawing editor is outside this example.
|
||||
|
||||
## Native boundaries
|
||||
|
||||
Windowed paths are compile-checked, not exercised on a desktop. Window-manager support
|
||||
for transparency, topmost placement and click-through varies. Monitor placement
|
||||
is a startup snapshot; hot-plug reconciliation is the app's next integration step.
|
||||
The native window-number accessor supplies the macOS CGWindowID that a host app can
|
||||
match to `SCWindow` for `SCContentFilter`; ScreenCaptureKit itself stays in the host app.
|
||||
It can initially be `None` until AppKit registers the window; retain the handle
|
||||
and query again. The native reference refreshes if a retained host is recreated.
|
||||
Borrow raw-window-handles only through the handle's callback while the native
|
||||
window is alive, on a platform-appropriate thread.
|
||||
|
||||
These are winit windows, not non-activating `NSPanel`s. Non-activating panels,
|
||||
all-Spaces/fullscreen-space behavior and a status item still require Rune's own
|
||||
Mac shell. This example does not implement them.
|
||||
|
||||
All windows share a GPU device. Unsupported transparency uses opaque rendering
|
||||
with a diagnostic, and unsupported click-through reports the platform error.
|
||||
Metal surfaces stay premultiplied for Core Animation; PNG exports are straight alpha.
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
use std::sync::{Arc, Mutex, atomic::{AtomicBool, Ordering}};
|
||||
use rune::{AppSpec, Color, Cx, El, Icon, Live, Tx, WindowHandle, WindowOptions, WindowSpec, col, el, icon, text};
|
||||
|
||||
static WINDOWED: AtomicBool = AtomicBool::new(false);
|
||||
static STROKE: Icon = Icon {
|
||||
name: "shared-stroke", view: 240.0,
|
||||
body: r#"<path d="M 12 190 C 55 30 90 210 130 70 S 190 170 228 35" fill="none" stroke="currentColor" stroke-width="4" stroke-linecap="round"/>"#,
|
||||
};
|
||||
struct State {
|
||||
overlay: bool,
|
||||
cursor: Live<[f32; 2]>,
|
||||
overlays: Arc<Mutex<Vec<WindowHandle>>>,
|
||||
}
|
||||
impl Drop for State {
|
||||
fn drop(&mut self) {
|
||||
if !self.overlay {
|
||||
for window in self.overlays.lock().unwrap().iter() { window.close(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
fn init() -> State {
|
||||
State { overlay: false, cursor: Live::new([120.0, 90.0]), overlays: Arc::new(Mutex::new(Vec::new())) }
|
||||
}
|
||||
fn view(s: &State, _: &mut Cx<State>) -> El {
|
||||
let green = Color { r: 0.1, g: 0.85, b: 0.45, a: 1.0 };
|
||||
if s.overlay {
|
||||
return el().w_full().h_full().child(icon(&STROKE, 240.0).key("stroke").color(green)
|
||||
.pin(Some(80.0), Some(80.0), None, None))
|
||||
.child(el().key("remote-cursor").size(12.0, 18.0).radius(3.0).fill(green)
|
||||
.pin(Some(0.0), Some(0.0), None, None).live_offset(&s.cursor))
|
||||
.on_press(|s: &mut State| {
|
||||
for window in s.overlays.lock().unwrap().iter() { window.set_click_through(true).ok(); }
|
||||
});
|
||||
}
|
||||
col().w_full().h_full().padding(40.0).gap(20.0)
|
||||
.fill(Color { r: 0.018, g: 0.024, b: 0.03, a: 1.0 })
|
||||
.child(text("Display overlays").font(rune::tok::type_::BODY))
|
||||
.child(el().padding(16.0).radius(8.0).fill(green.alpha(0.15))
|
||||
.child(text("Test overlay input"))
|
||||
.on_press(|s: &mut State| {
|
||||
for window in s.overlays.lock().unwrap().iter() {
|
||||
if let Err(e) = window.set_click_through(false) { eprintln!("click-through: {e}"); }
|
||||
}
|
||||
}))
|
||||
}
|
||||
fn point(t: f64) -> [f32; 2] {
|
||||
let t = t.min(4.0) as f32;
|
||||
[120.0 + 120.0 * (t * 0.7).sin(), 90.0 + 50.0 * t.sin()]
|
||||
}
|
||||
fn poll(s: &mut State, t: f64, _: &mut Tx) -> bool {
|
||||
if !WINDOWED.load(Ordering::Relaxed) { s.cursor.set(point(t)); }
|
||||
false
|
||||
}
|
||||
fn setup(s: &mut State, _: rune::Waker) {
|
||||
if !WINDOWED.load(Ordering::Relaxed) || s.overlay { return; }
|
||||
let cursor = s.cursor.clone();
|
||||
std::thread::spawn(move || {
|
||||
let start = rune::time::now();
|
||||
for tick in 1..=480 {
|
||||
let t = tick as f64 / 120.0;
|
||||
std::thread::sleep((start + std::time::Duration::from_secs_f64(t)).saturating_duration_since(rune::time::now()));
|
||||
cursor.set(point(t));
|
||||
}
|
||||
});
|
||||
}
|
||||
fn spec() -> AppSpec<State> {
|
||||
AppSpec { setup: Some(setup), poll: Some(poll), ..AppSpec::new("Rooms overlay example", (560.0, 440.0), init, view) }
|
||||
}
|
||||
fn main() {
|
||||
WINDOWED.store(!std::env::args().any(|a| matches!(a.as_str(), "--snap" | "--trace" | "--tree" | "--frames" | "--strip" | "--first-pixels" | "--list-scenes" | "--list-windows")), Ordering::Relaxed);
|
||||
rune::run_windows(|displays| {
|
||||
let controls = init();
|
||||
let cursor = controls.cursor.clone();
|
||||
let overlays = controls.overlays.clone();
|
||||
let mut windows = vec![WindowSpec::new("controls", spec()).state(controls)];
|
||||
for (i, display) in displays.iter().enumerate() {
|
||||
let state = State { overlay: true, cursor: cursor.clone(), overlays: overlays.clone() };
|
||||
let handles = overlays.clone();
|
||||
windows.push(WindowSpec::new(format!("overlay-{i}"), spec()).state(state)
|
||||
.options(WindowOptions::overlay(display)).on_created(move |window| {
|
||||
// ScreenCaptureKit: exclude this CGWindowID using SCContentFilter.
|
||||
eprintln!("overlay native window number: {:?}", window.window_number());
|
||||
handles.lock().unwrap().push(window);
|
||||
}));
|
||||
}
|
||||
windows
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user