mirror of
https://github.com/storytold/craft-libs.git
synced 2026-11-17 01:44:25 +00:00
fwb2-fix: web SCREEN_CAPTURE from the browser's EyeDropper
(cherry picked from commit 0e2c2c65e7ed9c8394ed9dc7efa523c71b7ce530)
This commit is contained in:
@@ -103,10 +103,9 @@ pub fn capture(scale: f32, wake: Wake) -> CaptureHandle {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether the browser has the EyeDropper API. A web host sets `Caps::SCREEN_CAPTURE` from it at
|
||||
/// startup, so the picker's button shows only where a pick can work. Native builds take the
|
||||
/// capability from `Caps::native`; a session without a display answers [`ScreenError::Unsupported`]
|
||||
/// at its first capture.
|
||||
/// Whether the browser has the EyeDropper API. The runtime's install sets `Caps::SCREEN_CAPTURE` from it, so the
|
||||
/// picker's button shows only where a pick can work. Native builds take the capability from `Caps::native`; a session
|
||||
/// without a display answers [`ScreenError::Unsupported`] at its first capture.
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn available() -> bool {
|
||||
web::available()
|
||||
|
||||
@@ -75,6 +75,10 @@ egui_kittest = { version = "0.37", features = ["wgpu"], optional = true }
|
||||
image = { version = "0.25", default-features = false, features = ["png"], optional = true }
|
||||
|
||||
# The window host's end hook sets `NSWindow.movable` through craft-window's AppKit code.
|
||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||
# `screen::available`: whether the browser has the EyeDropper, read at install for `Caps::SCREEN_CAPTURE`.
|
||||
craft-platform = { workspace = true, features = ["screen", "browser"] }
|
||||
|
||||
[target.'cfg(target_os = "macos")'.dependencies]
|
||||
craft-window = { workspace = true, features = ["ui", "appkit"] }
|
||||
|
||||
|
||||
@@ -149,6 +149,22 @@ impl std::fmt::Display for InstallError {
|
||||
|
||||
impl std::error::Error for InstallError {}
|
||||
|
||||
/// The shell with what the running browser offers: a browser build captures a screen colour only where the browser
|
||||
/// has the EyeDropper, so `Caps::SCREEN_CAPTURE` is read here, once for every app. Native capabilities are the
|
||||
/// build's own (`Caps::native`).
|
||||
fn with_browser_caps(shell: ShellInfo) -> ShellInfo {
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
{
|
||||
let mut shell = shell;
|
||||
if craft_platform::screen::available() {
|
||||
shell.caps.insert(craft_host::target::Caps::SCREEN_CAPTURE);
|
||||
}
|
||||
shell
|
||||
}
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
shell
|
||||
}
|
||||
|
||||
/// Adds the runtime plugin to `ctx` and sets the egui options the runtime owns: interface scale is a command, quit goes
|
||||
/// through the close guard, and the wheel's modifiers are the spec's. A second call on the same context is an error,
|
||||
/// checked first so an app that installs again (a language change) gets that answer; a call inside a pass is one too.
|
||||
@@ -167,7 +183,7 @@ pub fn install(ctx: &Context, spec: InstallSpec) -> Result<(), InstallError> {
|
||||
input::set_wheel_modifiers(ctx, spec.wheel.zoom, spec.wheel.sideways);
|
||||
system::install(ctx, spec.system);
|
||||
pen::install(ctx, spec.pen);
|
||||
windows::install(ctx, spec.shell_info, spec.window_system, spec.placement, spec.frame, spec.app_id);
|
||||
windows::install(ctx, with_browser_caps(spec.shell_info), spec.window_system, spec.placement, spec.frame, spec.app_id);
|
||||
frame::set_frame_layers(ctx, spec.frame_layers);
|
||||
frame::seed_hooked_passes(ctx);
|
||||
plugin::register(ctx);
|
||||
|
||||
Reference in New Issue
Block a user