diff --git a/Cargo.lock b/Cargo.lock index ba71f7d..9c00252 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -93,9 +93,9 @@ checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-activity" -version = "0.5.2" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee91c0c2905bae44f84bfa4e044536541df26b7703fd0888deeb9060fcc44289" +checksum = "ef6978589202a00cd7e118380c448a08b6ed394c3a8df3a430d0898e3a42d046" dependencies = [ "android-properties", "bitflags 2.6.0", @@ -107,7 +107,7 @@ dependencies = [ "log", "ndk", "ndk-context", - "ndk-sys", + "ndk-sys 0.6.0+11769913", "num_enum", "thiserror", ] @@ -153,7 +153,7 @@ dependencies = [ "core-graphics", "image 0.25.2", "log", - "objc2 0.5.2", + "objc2", "objc2-app-kit", "objc2-foundation", "parking_lot", @@ -388,32 +388,13 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block-sys" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae85a0696e7ea3b835a453750bf002770776609115e6d25c6d2ff28a8200f7e7" -dependencies = [ - "objc-sys", -] - -[[package]] -name = "block2" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15b55663a85f33501257357e6421bb33e769d5c9ffb5ba0921c975a123e35e68" -dependencies = [ - "block-sys", - "objc2 0.4.1", -] - [[package]] name = "block2" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" dependencies = [ - "objc2 0.5.2", + "objc2", ] [[package]] @@ -532,9 +513,9 @@ dependencies = [ [[package]] name = "calloop" -version = "0.12.4" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fba7adb4dd5aa98e5553510223000e7148f621165ec5f9acd7113f6ca4995298" +checksum = "b99da2f8558ca23c71f4fd15dc57c906239752dd27ff3c00a1d56b685b7cbfec" dependencies = [ "bitflags 2.6.0", "log", @@ -546,9 +527,9 @@ dependencies = [ [[package]] name = "calloop-wayland-source" -version = "0.2.0" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f0ea9b9476c7fad82841a8dbb380e2eae480c21910feba80725b46931ed8f02" +checksum = "95a66a987056935f7efce4ab5668920b5d0dac4a7c99991a67395f13702ddd20" dependencies = [ "calloop", "rustix", @@ -1352,6 +1333,12 @@ version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" +[[package]] +name = "dpi" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f25c0e292a7ca6d6498557ff1df68f32c99850012b6ea401cf8daf771f22ff53" + [[package]] name = "dtoa" version = "1.0.9" @@ -2294,17 +2281,6 @@ dependencies = [ "cc", ] -[[package]] -name = "icrate" -version = "0.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99d3aaff8a54577104bafdf686ff18565c3b6903ca5782a2026ef06e2c7aa319" -dependencies = [ - "block2 0.3.0", - "dispatch", - "objc2 0.4.1", -] - [[package]] name = "icu_calendar" version = "1.5.2" @@ -3443,17 +3419,16 @@ dependencies = [ [[package]] name = "ndk" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2076a31b7010b17a38c01907c45b945e8f11495ee4dd588309718901b1f7a5b7" +checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" dependencies = [ "bitflags 2.6.0", "jni-sys", "log", - "ndk-sys", + "ndk-sys 0.6.0+11769913", "num_enum", - "raw-window-handle 0.5.2", - "raw-window-handle 0.6.2", + "raw-window-handle", "thiserror", ] @@ -3472,6 +3447,15 @@ dependencies = [ "jni-sys", ] +[[package]] +name = "ndk-sys" +version = "0.6.0+11769913" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" +dependencies = [ + "jni-sys", +] + [[package]] name = "net" version = "0.0.1" @@ -3730,16 +3714,6 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" -[[package]] -name = "objc2" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "559c5a40fdd30eb5e344fbceacf7595a81e242529fb4e21cf5f43fb4f11ff98d" -dependencies = [ - "objc-sys", - "objc2-encode 3.0.0", -] - [[package]] name = "objc2" version = "0.5.2" @@ -3747,7 +3721,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" dependencies = [ "objc-sys", - "objc2-encode 4.0.3", + "objc2-encode", ] [[package]] @@ -3757,15 +3731,39 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" dependencies = [ "bitflags 2.6.0", - "block2 0.5.1", + "block2", "libc", - "objc2 0.5.2", + "objc2", "objc2-core-data", "objc2-core-image", "objc2-foundation", "objc2-quartz-core", ] +[[package]] +name = "objc2-cloud-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74dd3b56391c7a0596a295029734d3c1c5e7e510a4cb30245f8221ccea96b009" +dependencies = [ + "bitflags 2.6.0", + "block2", + "objc2", + "objc2-core-location", + "objc2-foundation", +] + +[[package]] +name = "objc2-contacts" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5ff520e9c33812fd374d8deecef01d4a840e7b41862d849513de77e44aa4889" +dependencies = [ + "block2", + "objc2", + "objc2-foundation", +] + [[package]] name = "objc2-core-data" version = "0.2.2" @@ -3773,8 +3771,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" dependencies = [ "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", + "block2", + "objc2", "objc2-foundation", ] @@ -3784,17 +3782,23 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "55260963a527c99f1819c4f8e3b47fe04f9650694ef348ffd2227e8196d34c80" dependencies = [ - "block2 0.5.1", - "objc2 0.5.2", + "block2", + "objc2", "objc2-foundation", "objc2-metal", ] [[package]] -name = "objc2-encode" -version = "3.0.0" +name = "objc2-core-location" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d079845b37af429bfe5dfa76e6d087d788031045b25cfc6fd898486fd9847666" +checksum = "000cfee34e683244f284252ee206a27953279d370e309649dc3ee317b37e5781" +dependencies = [ + "block2", + "objc2", + "objc2-contacts", + "objc2-foundation", +] [[package]] name = "objc2-encode" @@ -3809,9 +3813,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" dependencies = [ "bitflags 2.6.0", - "block2 0.5.1", + "block2", + "dispatch", "libc", - "objc2 0.5.2", + "objc2", +] + +[[package]] +name = "objc2-link-presentation" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1a1ae721c5e35be65f01a03b6d2ac13a54cb4fa70d8a5da293d7b0020261398" +dependencies = [ + "block2", + "objc2", + "objc2-app-kit", + "objc2-foundation", ] [[package]] @@ -3821,8 +3838,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" dependencies = [ "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", + "block2", + "objc2", "objc2-foundation", ] @@ -3833,12 +3850,67 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" dependencies = [ "bitflags 2.6.0", - "block2 0.5.1", - "objc2 0.5.2", + "block2", + "objc2", "objc2-foundation", "objc2-metal", ] +[[package]] +name = "objc2-symbols" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a684efe3dec1b305badae1a28f6555f6ddd3bb2c2267896782858d5a78404dc" +dependencies = [ + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-ui-kit" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8bb46798b20cd6b91cbd113524c490f1686f4c4e8f49502431415f3512e2b6f" +dependencies = [ + "bitflags 2.6.0", + "block2", + "objc2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-image", + "objc2-core-location", + "objc2-foundation", + "objc2-link-presentation", + "objc2-quartz-core", + "objc2-symbols", + "objc2-uniform-type-identifiers", + "objc2-user-notifications", +] + +[[package]] +name = "objc2-uniform-type-identifiers" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44fa5f9748dbfe1ca6c0b79ad20725a11eca7c2218bceb4b005cb1be26273bfe" +dependencies = [ + "block2", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-user-notifications" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76cfcbf642358e8689af64cee815d139339f3ed8ad05103ed5eaf73db8d84cb3" +dependencies = [ + "bitflags 2.6.0", + "block2", + "objc2", + "objc2-core-location", + "objc2-foundation", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -4326,12 +4398,6 @@ dependencies = [ "typed-arena", ] -[[package]] -name = "raw-window-handle" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9" - [[package]] name = "raw-window-handle" version = "0.6.2" @@ -4367,15 +4433,6 @@ dependencies = [ "bitflags 1.3.2", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "redox_syscall" version = "0.4.1" @@ -4775,9 +4832,9 @@ dependencies = [ [[package]] name = "sctk-adwaita" -version = "0.8.3" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70b31447ca297092c5a9916fc3b955203157b37c19ca8edde4f52e9843e602c7" +checksum = "b6277f0217056f77f1d8f49f2950ac6c278c0d607c45f5ee99328d792ede24ec" dependencies = [ "ab_glyph", "log", @@ -5206,9 +5263,9 @@ dependencies = [ [[package]] name = "smithay-client-toolkit" -version = "0.18.1" +version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "922fd3eeab3bd820d76537ce8f582b1cf951eceb5475c28500c7457d9d17f53a" +checksum = "3457dea1f0eb631b4034d61d4d8c32074caa6cd1ab2d59f2327bd8461e2c0016" dependencies = [ "bitflags 2.6.0", "calloop", @@ -5472,8 +5529,7 @@ dependencies = [ "mach2", "metal 0.24.0", "objc", - "raw-window-handle 0.5.2", - "raw-window-handle 0.6.2", + "raw-window-handle", "serial_test", "servo-display-link", "sparkle", @@ -6097,16 +6153,13 @@ version = "0.0.1" dependencies = [ "arboard", "base", - "block", "bluetooth", "bluetooth_traits", "canvas", "cargo-packager-resource-resolver", "cfg_aliases 0.2.1", - "cocoa", "compositing_traits", "constellation", - "core-graphics", "crossbeam-channel", "devtools", "embedder_traits", @@ -6122,11 +6175,11 @@ dependencies = [ "media", "mozangle", "net", - "objc", - "objc_id", + "objc2", + "objc2-app-kit", "profile", "profile_traits", - "raw-window-handle 0.5.2", + "raw-window-handle", "script", "script_traits", "servo-media", @@ -6330,9 +6383,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.31.2" +version = "0.32.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f81f365b8b4a97f422ac0e8737c438024b5951734506b0e1d775c73030561f4" +checksum = "62989625a776e827cc0f15d41444a3cea5205b963c3a25be48ae1b52d6b4daaa" dependencies = [ "bitflags 2.6.0", "wayland-backend", @@ -6342,9 +6395,9 @@ dependencies = [ [[package]] name = "wayland-protocols-plasma" -version = "0.2.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23803551115ff9ea9bce586860c5c5a971e360825a0309264102a9495a5ff479" +checksum = "f79f2d57c7fcc6ab4d602adba364bf59a5c24de57bd194486bf9b8360e06bfc4" dependencies = [ "bitflags 2.6.0", "wayland-backend", @@ -6355,9 +6408,9 @@ dependencies = [ [[package]] name = "wayland-protocols-wlr" -version = "0.2.0" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad1f61b76b6c2d8742e10f9ba5c3737f6530b4c243132c2a2ccc8aa96fe25cd6" +checksum = "fd993de54a40a40fbe5601d9f1fbcaef0aebcc5fda447d7dc8f6dcbaae4f8953" dependencies = [ "bitflags 2.6.0", "wayland-backend", @@ -6413,9 +6466,9 @@ dependencies = [ [[package]] name = "web-time" -version = "0.2.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa30049b1c872b72c89866d458eae9f20380ab280ffd1b1e18df2d3e2d98cfe0" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" dependencies = [ "js-sys", "wasm-bindgen", @@ -6659,13 +6712,13 @@ dependencies = [ "log", "metal 0.29.0", "naga", - "ndk-sys", + "ndk-sys 0.5.0+25.2.9519653", "objc", "once_cell", "parking_lot", "profiling", "range-alloc", - "raw-window-handle 0.6.2", + "raw-window-handle", "rustc-hash", "smallvec", "thiserror", @@ -7019,38 +7072,41 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winit" -version = "0.29.15" +version = "0.30.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d59ad965a635657faf09c8f062badd885748428933dad8e8bdd64064d92e5ca" +checksum = "0be9e76a1f1077e04a411f0b989cbd3c93339e1771cb41e71ac4aee95bfd2c67" dependencies = [ "ahash", "android-activity", "atomic-waker", "bitflags 2.6.0", + "block2", "bytemuck", "calloop", - "cfg_aliases 0.1.1", + "cfg_aliases 0.2.1", + "concurrent-queue", "core-foundation", "core-graphics", "cursor-icon", - "icrate", + "dpi", "js-sys", "libc", - "log", "memmap2", "ndk", - "ndk-sys", - "objc2 0.4.1", - "once_cell", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "objc2-ui-kit", "orbclient", "percent-encoding", - "raw-window-handle 0.5.2", - "raw-window-handle 0.6.2", - "redox_syscall 0.3.5", + "pin-project", + "raw-window-handle", + "redox_syscall 0.4.1", "rustix", "sctk-adwaita", "smithay-client-toolkit", "smol_str", + "tracing", "unicode-segmentation", "wasm-bindgen", "wasm-bindgen-futures", @@ -7060,7 +7116,7 @@ dependencies = [ "wayland-protocols-plasma", "web-sys", "web-time", - "windows-sys 0.48.0", + "windows-sys 0.52.0", "x11-dl", "x11rb", "xkbcommon-dl", diff --git a/Cargo.toml b/Cargo.toml index 563405b..e436001 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -56,11 +56,11 @@ gleam = "0.15" ipc-channel = "0.18" keyboard-types = "0.7" log = "0.4" -raw-window-handle = { version = "0.5", features = ["std"] } +raw-window-handle = { version = "0.6", features = ["std"] } sparkle = "0.1.26" -surfman = { version = "0.9", features = ["chains", "sm-raw-window-handle-05"] } +surfman = { version = "0.9", features = ["chains", "sm-raw-window-handle-06"] } thiserror = "1.0" -winit = { version = "0.29", features = ["rwh_05"] } +winit = { version = "0.30", features = ["rwh_06"] } # Servo repo crates base = { git = "https://github.com/servo/servo.git", rev = "28430ba" } bluetooth = { git = "https://github.com/servo/servo.git", rev = "28430ba" } @@ -104,11 +104,8 @@ surfman = { version = "0.9", features = ["sm-angle-default"] } mozangle = { version = "0.5.1", features = ["egl", "build_dlls"] } [target.'cfg(any(target_os = "ios", target_os = "macos"))'.dependencies] -block = "0.1" -cocoa = "0.25" -core-graphics = "0.23" -objc = "0.2" -objc_id = "0.1" +objc2 = "0.5" +objc2-app-kit = {version = "0.2", features = ["NSView", "NSResponder", "NSWindow"]} [[test]] name = "general" diff --git a/src/main.rs b/src/main.rs index 258f097..6d4a9e1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,32 +3,46 @@ use verso::config::Config; use verso::{Result, Verso}; -use winit::event::{Event, StartCause}; -use winit::event_loop::EventLoop; -use winit::event_loop::{ControlFlow, DeviceEvents}; +use winit::application::ApplicationHandler; +use winit::event_loop::{self, DeviceEvents}; +use winit::event_loop::{EventLoop, EventLoopProxy}; + +struct App { + verso: Option, + proxy: EventLoopProxy<()>, +} + +impl ApplicationHandler for App { + fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) { + let config = Config::new(resources_dir_path().unwrap()); + self.verso = Some(Verso::new(event_loop, self.proxy.clone(), config)); + } + + fn window_event( + &mut self, + event_loop: &winit::event_loop::ActiveEventLoop, + window_id: winit::window::WindowId, + event: winit::event::WindowEvent, + ) { + self.verso.as_mut().map(|v| { + v.handle_winit_window_event(window_id, event); + v.handle_servo_messages(event_loop); + }); + } + + fn user_event(&mut self, event_loop: &event_loop::ActiveEventLoop, _: ()) { + self.verso.as_mut().map(|v| { + v.handle_servo_messages(event_loop); + }); + } +} fn main() -> Result<()> { let event_loop = EventLoop::new()?; event_loop.listen_device_events(DeviceEvents::Never); let proxy = event_loop.create_proxy(); - let mut verso = None; - event_loop.run(move |event, evl| { - if let Event::NewEvents(StartCause::Init) = event { - let config = Config::new(resources_dir_path().unwrap()); - verso = Some(Verso::new(evl, proxy.clone(), config)); - } else { - if let Some(v) = &mut verso { - v.run(event, evl); - if v.finished_shutting_down() { - evl.exit(); - } else if v.is_animating() { - evl.set_control_flow(ControlFlow::Poll); - } else { - evl.set_control_flow(ControlFlow::Wait); - } - } - } - })?; + let mut app = App { verso: None, proxy }; + event_loop.run_app(&mut app)?; Ok(()) } diff --git a/src/verso.rs b/src/verso.rs index a1d3c37..51e1337 100644 --- a/src/verso.rs +++ b/src/verso.rs @@ -39,8 +39,8 @@ use webrender_api::*; use webrender_traits::*; use webxr_api::{LayerGrandManager, LayerGrandManagerAPI, LayerManager, LayerManagerFactory}; use winit::{ - event::{Event, WindowEvent}, - event_loop::{EventLoopProxy, EventLoopWindowTarget}, + event::WindowEvent, + event_loop::{ActiveEventLoop, ControlFlow, EventLoopProxy}, window::WindowId, }; @@ -82,7 +82,7 @@ impl Verso { /// - Font cache /// - Canvas /// - Constellation - pub fn new(evl: &EventLoopWindowTarget<()>, proxy: EventLoopProxy<()>, config: Config) -> Self { + pub fn new(evl: &ActiveEventLoop, proxy: EventLoopProxy<()>, config: Config) -> Self { // Initialize configurations and Verso window let resource_dir = config.resource_dir.clone(); config.init(); @@ -390,54 +390,34 @@ impl Verso { verso } - /// Run an iteration of Verso handling cycle. An iteration will perform following actions: - /// - /// - Handle Winit's event, updating Compositor and sending messages to Constellation. - /// - Handle Servo's messages and updating Compositor again. - pub fn run(&mut self, event: Event<()>, evl: &EventLoopWindowTarget<()>) { - self.handle_winit_event(event); - self.handle_servo_messages(evl); - if self.windows.is_empty() { - self.compositor - .as_mut() - .map(IOCompositor::maybe_start_shutting_down); - } - } - - /// Handle Winit events - fn handle_winit_event(&mut self, event: Event<()>) { + /// Handle Winit window events + pub fn handle_winit_window_event(&mut self, window_id: WindowId, event: WindowEvent) { log::trace!("Verso is handling Winit event: {event:?}"); - match event { - Event::NewEvents(_) | Event::Suspended | Event::Resumed | Event::UserEvent(()) => {} - Event::WindowEvent { window_id, event } => { - if let Some(compositor) = &mut self.compositor { - if let WindowEvent::CloseRequested = event { - // self.windows.remove(&window_id); - compositor.maybe_start_shutting_down(); - } else { - let mut need_repaint = false; - for (id, window) in &mut self.windows { - if window_id == *id { - need_repaint = window.handle_winit_window_event( - &self.constellation_sender, - compositor, - &event, - ); - } - } - - if need_repaint { - compositor.repaint_synchronously(&mut self.windows); - } + if let Some(compositor) = &mut self.compositor { + if let WindowEvent::CloseRequested = event { + // self.windows.remove(&window_id); + compositor.maybe_start_shutting_down(); + } else { + let mut need_repaint = false; + for (id, window) in &mut self.windows { + if window_id == *id { + need_repaint = window.handle_winit_window_event( + &self.constellation_sender, + compositor, + &event, + ); } } + + if need_repaint { + compositor.repaint_synchronously(&mut self.windows); + } } - e => log::trace!("Verso isn't supporting this event yet: {e:?}"), } } /// Handle message came from Servo. - fn handle_servo_messages(&mut self, evl: &EventLoopWindowTarget<()>) { + pub fn handle_servo_messages(&mut self, evl: &ActiveEventLoop) { let mut shutdown = false; if let Some(compositor) = &mut self.compositor { // Handle Compositor's messages first @@ -514,9 +494,22 @@ impl Verso { } } + // Check if Verso need to start shutting down. + if self.windows.is_empty() { + self.compositor + .as_mut() + .map(IOCompositor::maybe_start_shutting_down); + } + + // Check compositor status and set control flow. if shutdown { // If Compositor has shut down, deinit and remove it. self.compositor.take().map(IOCompositor::deinit); + evl.exit(); + } else if self.is_animating() { + evl.set_control_flow(ControlFlow::Poll); + } else { + evl.set_control_flow(ControlFlow::Wait); } } @@ -528,11 +521,6 @@ impl Verso { .unwrap_or(false) } - /// Return true if Verso has shut down and hence there's no compositor. - pub fn finished_shutting_down(&self) -> bool { - self.compositor.is_none() - } - fn setup_logging(&self) { let constellation_chan = self.constellation_sender.clone(); let env = env_logger::Env::default(); diff --git a/src/window.rs b/src/window.rs index d2bbfe5..9810883 100644 --- a/src/window.rs +++ b/src/window.rs @@ -5,7 +5,7 @@ use compositing_traits::ConstellationMsg; use crossbeam_channel::Sender; use embedder_traits::{Cursor, EmbedderMsg}; use euclid::{Point2D, Size2D}; -use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle}; +use raw_window_handle::{HasDisplayHandle, HasWindowHandle}; use script_traits::{TouchEventType, WheelDelta, WheelMode}; use surfman::Connection; use surfman::SurfaceType; @@ -17,9 +17,9 @@ use webrender_traits::RenderingContext; use winit::{ dpi::PhysicalPosition, event::{ElementState, TouchPhase, WindowEvent}, - event_loop::EventLoopWindowTarget, + event_loop::ActiveEventLoop, keyboard::ModifiersState, - window::{CursorIcon, Window as WinitWindow, WindowBuilder, WindowId}, + window::{CursorIcon, Window as WinitWindow, WindowId}, }; use crate::{ @@ -47,29 +47,35 @@ pub struct Window { impl Window { /// Create a Verso window from Winit window and return the rendering context. - pub fn new(evl: &EventLoopWindowTarget<()>) -> (Self, RenderingContext) { - let window = WindowBuilder::new() + pub fn new(evl: &ActiveEventLoop) -> (Self, RenderingContext) { + let window = evl + .create_window(WinitWindow::default_attributes()) // .with_transparent(true) // .with_decorations(false) - .build(evl) .expect("Failed to create window."); + + let rwh = window.window_handle().expect("Failed to get window handle"); #[cfg(macos)] unsafe { - let rwh = window.raw_window_handle(); - if let RawWindowHandle::AppKit(AppKitWindowHandle { ns_window, .. }) = rwh { - decorate_window(ns_window as *mut Object, LogicalPosition::new(8.0, 40.0)); + if let RawWindowHandle::AppKit(AppKitWindowHandle { ns_view, .. }) = rwh.as_ref() { + decorate_window( + ns_view.as_ptr() as *mut AnyObject, + LogicalPosition::new(8.0, 40.0), + ); } } let window_size = window.inner_size(); let window_size = Size2D::new(window_size.width as i32, window_size.height as i32); - let display_handle = window.raw_display_handle(); - let connection = Connection::from_raw_display_handle(display_handle) - .expect("Failed to create connection"); + let display_handle = window + .display_handle() + .expect("Failed to get display handle"); + let connection = + Connection::from_display_handle(display_handle).expect("Failed to create connection"); let adapter = connection .create_adapter() .expect("Failed to create adapter"); let native_widget = connection - .create_native_widget_from_raw_window_handle(window.raw_window_handle(), window_size) + .create_native_widget_from_window_handle(rwh, window_size) .expect("Failed to create native widget"); let surface_type = SurfaceType::Widget { native_widget }; let rendering_context = RenderingContext::create(&connection, &adapter, surface_type) @@ -91,20 +97,21 @@ impl Window { } /// Create a Verso window with the rendering context. - pub fn new_with_compositor( - evl: &EventLoopWindowTarget<()>, - compositor: &mut IOCompositor, - ) -> Self { - let window = WindowBuilder::new() + pub fn new_with_compositor(evl: &ActiveEventLoop, compositor: &mut IOCompositor) -> Self { + let window = evl + .create_window(WinitWindow::default_attributes()) // .with_transparent(true) // .with_decorations(false) - .build(evl) .expect("Failed to create window."); + + let rwh = window.window_handle().expect("Failed to get window handle"); #[cfg(macos)] unsafe { - let rwh = window.raw_window_handle(); - if let RawWindowHandle::AppKit(AppKitWindowHandle { ns_window, .. }) = rwh { - decorate_window(ns_window as *mut Object, LogicalPosition::new(8.0, 40.0)); + if let RawWindowHandle::AppKit(AppKitWindowHandle { ns_view, .. }) = rwh.as_ref() { + decorate_window( + ns_view.as_ptr() as *mut AnyObject, + LogicalPosition::new(8.0, 40.0), + ); } } let window_size = window.inner_size(); @@ -112,7 +119,7 @@ impl Window { let native_widget = compositor .rendering_context .connection() - .create_native_widget_from_raw_window_handle(window.raw_window_handle(), window_size) + .create_native_widget_from_window_handle(rwh, window_size) .expect("Failed to create native widget"); let surface_type = SurfaceType::Widget { native_widget }; let surface = compositor @@ -186,7 +193,7 @@ impl Window { compositor.on_mouse_window_event_class(event); } } - WindowEvent::TouchpadMagnify { delta, .. } => { + WindowEvent::PinchGesture { delta, .. } => { compositor.on_zoom_window_event(1.0 + *delta as f32, self); } WindowEvent::MouseWheel { delta, phase, .. } => { @@ -375,15 +382,13 @@ impl Window { Cursor::ZoomOut => CursorIcon::ZoomOut, _ => CursorIcon::Default, }; - self.window.set_cursor_icon(winit_cursor); + self.window.set_cursor(winit_cursor); } } /* window decoration */ #[cfg(macos)] -use cocoa::appkit::{NSWindow, NSWindowStyleMask, NSWindowTitleVisibility}; -#[cfg(macos)] -use objc::runtime::Object; +use objc2::runtime::AnyObject; #[cfg(macos)] use raw_window_handle::{AppKitWindowHandle, RawWindowHandle}; #[cfg(macos)] @@ -391,15 +396,21 @@ use winit::dpi::LogicalPosition; /// Window decoration for macOS. #[cfg(macos)] -pub unsafe fn decorate_window(window: *mut Object, _position: LogicalPosition) { - NSWindow::setTitlebarAppearsTransparent_(window, cocoa::base::YES); - NSWindow::setTitleVisibility_(window, NSWindowTitleVisibility::NSWindowTitleHidden); - NSWindow::setStyleMask_( - window, - NSWindowStyleMask::NSTitledWindowMask - | NSWindowStyleMask::NSFullSizeContentViewWindowMask - | NSWindowStyleMask::NSClosableWindowMask - | NSWindowStyleMask::NSResizableWindowMask - | NSWindowStyleMask::NSMiniaturizableWindowMask, +pub unsafe fn decorate_window(view: *mut AnyObject, _position: LogicalPosition) { + use objc2::rc::Id; + use objc2_app_kit::{NSView, NSWindowStyleMask, NSWindowTitleVisibility}; + + let ns_view: Id = unsafe { Id::retain(view.cast()) }.unwrap(); + let window = ns_view + .window() + .expect("view was not installed in a window"); + window.setTitlebarAppearsTransparent(true); + window.setTitleVisibility(NSWindowTitleVisibility::NSWindowTitleHidden); + window.setStyleMask( + NSWindowStyleMask::Titled + | NSWindowStyleMask::FullSizeContentView + | NSWindowStyleMask::Closable + | NSWindowStyleMask::Resizable + | NSWindowStyleMask::Miniaturizable, ); }