From 6bc13af4874030fb798a5fac3246889a2ced3df6 Mon Sep 17 00:00:00 2001 From: Jason Lee Date: Wed, 18 Sep 2024 14:23:59 +0800 Subject: [PATCH] gpui: Export raw_window_handle for wry to render WebView, and with a WebView example. Fix borrow_mut error on Windows. Co-authored-by: Sunli --- Cargo.lock | 953 ++++++++++++++++++++++++++++++-- crates/gpui/Cargo.toml | 9 +- crates/gpui/examples/webview.rs | 175 ++++++ crates/gpui/src/app.rs | 53 +- crates/gpui/src/platform.rs | 4 +- crates/gpui/src/window.rs | 5 + 6 files changed, 1139 insertions(+), 60 deletions(-) create mode 100644 crates/gpui/examples/webview.rs diff --git a/Cargo.lock b/Cargo.lock index f5c45f8d4ae5f..905312e34d7fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -156,7 +156,7 @@ version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ab99eae5ee58501ab236beb6f20f6ca39be615267b014899c89b2f0bc18a459" dependencies = [ - "html5ever", + "html5ever 0.27.0", "maplit", "once_cell", "tendril", @@ -336,7 +336,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52bca67b61cb81e5553babde81b8211f713cb6db79766f80168f3e5f40ea6c82" dependencies = [ "ash", - "raw-window-handle", + "raw-window-handle 0.6.2", "raw-window-metal", ] @@ -1028,6 +1028,29 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "atk" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4af014b17dd80e8af9fa689b2d4a211ddba6eb583c1622f35d0cb543f6b17e4" +dependencies = [ + "atk-sys", + "glib", + "libc", +] + +[[package]] +name = "atk-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "251e0b7d90e33e0ba930891a505a9a35ece37b2dd37a14f3ffc306c13b980009" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "atoi" version = "2.0.0" @@ -1495,7 +1518,7 @@ dependencies = [ "http-body 0.4.6", "http-body 1.0.1", "http-body-util", - "itoa", + "itoa 1.0.11", "num-integer", "pin-project-lite", "pin-utils", @@ -1545,7 +1568,7 @@ dependencies = [ "http 0.2.12", "http-body 0.4.6", "hyper 0.14.31", - "itoa", + "itoa 1.0.11", "matchit", "memchr", "mime", @@ -1809,7 +1832,7 @@ dependencies = [ "mint", "naga", "objc", - "raw-window-handle", + "raw-window-handle 0.6.2", "slab", "wasm-bindgen", "web-sys", @@ -1903,7 +1926,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2593a3b8b938bd68373196c9832f516be11fa487ef4ae745eb282e6a56a7244" dependencies = [ "once_cell", - "proc-macro-crate", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 2.0.87", @@ -2031,6 +2054,31 @@ dependencies = [ "either", ] +[[package]] +name = "cairo-rs" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca26ef0159422fb77631dc9d17b102f253b876fe1586b03b803e63a309b4ee2" +dependencies = [ + "bitflags 2.6.0", + "cairo-sys-rs", + "glib", + "libc", + "once_cell", + "thiserror 1.0.69", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685c9fa8e590b8b3d678873528d83411db17242a73fccaed827770ea0fedda51" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + [[package]] name = "call" version = "0.1.0" @@ -3138,7 +3186,7 @@ dependencies = [ "js-sys", "libc", "mach2", - "ndk", + "ndk 0.8.0", "ndk-context", "oboe", "wasm-bindgen", @@ -3438,6 +3486,33 @@ dependencies = [ "typenum", ] +[[package]] +name = "cssparser" +version = "0.27.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "754b69d351cdc2d8ee09ae203db831e005560fc6030da058f86ad60c92a9cb0a" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa 0.4.8", + "matches", + "phf 0.8.0", + "proc-macro2", + "quote", + "smallvec", + "syn 1.0.109", +] + +[[package]] +name = "cssparser-macros" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13b588ba4ac1a99f7f2964d24b3d896ddc6bf847ee3855dbd4366f058cfcd331" +dependencies = [ + "quote", + "syn 2.0.87", +] + [[package]] name = "ctor" version = "0.2.9" @@ -3749,7 +3824,28 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "415b6ec780d34dcf624666747194393603d0373b7141eef01d12ee58881507d9" dependencies = [ - "phf", + "phf 0.11.2", +] + +[[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" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbb2bf8e87535c23f7a8a321e364ce21462d0ff10cb6407820e8e96dfff6653" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", ] [[package]] @@ -3932,7 +4028,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "99e1f1df1f181f2539bac8bf027d31ca5ffbf9e559e3f2d09413b9107b5c02f4" dependencies = [ - "phf", + "phf 0.11.2", ] [[package]] @@ -4434,6 +4530,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "field-offset" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +dependencies = [ + "memoffset", + "rustc_version", +] + [[package]] name = "file_finder" version = "0.1.0" @@ -4935,6 +5041,100 @@ dependencies = [ "thread_local", ] +[[package]] +name = "fxhash" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c" +dependencies = [ + "byteorder", +] + +[[package]] +name = "gdk" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f5ba081bdef3b75ebcdbfc953699ed2d7417d6bd853347a42a37d76406a33646" +dependencies = [ + "cairo-rs", + "gdk-pixbuf", + "gdk-sys", + "gio", + "glib", + "libc", + "pango", +] + +[[package]] +name = "gdk-pixbuf" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e1f5f1b0bfb830d6ccc8066d18db35c487b1b2b1e8589b5dfe9f07e8defaec" +dependencies = [ + "gdk-pixbuf-sys", + "gio", + "glib", + "libc", + "once_cell", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gdk-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31ff856cb3386dae1703a920f803abafcc580e9b5f711ca62ed1620c25b51ff2" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps", +] + +[[package]] +name = "gdkx11" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2ea8a4909d530f79921290389cbd7c34cb9d623bfe970eaae65ca5f9cd9cce" +dependencies = [ + "gdk", + "gdkx11-sys", + "gio", + "glib", + "libc", + "x11", +] + +[[package]] +name = "gdkx11-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fee8f00f4ee46cad2939b8990f5c70c94ff882c3028f3cc5abf950fa4ab53043" +dependencies = [ + "gdk-sys", + "glib-sys", + "libc", + "system-deps", + "x11", +] + [[package]] name = "generic-array" version = "0.14.7" @@ -5006,6 +5206,38 @@ version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" +[[package]] +name = "gio" +version = "0.18.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fc8f532f87b79cbc51a79748f16a6828fb784be93145a322fa14d06d354c73" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys", + "glib", + "libc", + "once_cell", + "pin-project-lite", + "smallvec", + "thiserror 1.0.69", +] + +[[package]] +name = "gio-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + [[package]] name = "git" version = "0.1.0" @@ -5065,6 +5297,53 @@ dependencies = [ "util", ] +[[package]] +name = "glib" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233daaf6e83ae6a12a52055f568f9d7cf4671dabb78ff9560ab6da230ce00ee5" +dependencies = [ + "bitflags 2.6.0", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys", + "glib-macros", + "glib-sys", + "gobject-sys", + "libc", + "memchr", + "once_cell", + "smallvec", + "thiserror 1.0.69", +] + +[[package]] +name = "glib-macros" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" +dependencies = [ + "heck 0.4.1", + "proc-macro-crate 2.0.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "glib-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" +dependencies = [ + "libc", + "system-deps", +] + [[package]] name = "glob" version = "0.3.1" @@ -5133,6 +5412,17 @@ dependencies = [ "workspace", ] +[[package]] +name = "gobject-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + [[package]] name = "google_ai" version = "0.1.0" @@ -5229,7 +5519,7 @@ dependencies = [ "postage", "profiling", "rand 0.8.5", - "raw-window-handle", + "raw-window-handle 0.6.2", "refineable", "resvg", "schemars", @@ -5257,6 +5547,7 @@ dependencies = [ "wayland-protocols-plasma", "windows 0.58.0", "windows-core 0.58.0", + "wry", "x11-clipboard", "x11rb", "xim", @@ -5289,6 +5580,58 @@ dependencies = [ "subtle", ] +[[package]] +name = "gtk" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93c4f5e0e20b60e10631a5f06da7fe3dda744b05ad0ea71fee2f47adf865890c" +dependencies = [ + "atk", + "cairo-rs", + "field-offset", + "futures-channel", + "gdk", + "gdk-pixbuf", + "gio", + "glib", + "gtk-sys", + "gtk3-macros", + "libc", + "pango", + "pkg-config", +] + +[[package]] +name = "gtk-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "771437bf1de2c1c0b496c11505bdf748e26066bbe942dfc8f614c9460f6d7722" +dependencies = [ + "atk-sys", + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "system-deps", +] + +[[package]] +name = "gtk3-macros" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6063efb63db582968fb7df72e1ae68aa6360dcfb0a75143f34fc7d616bad75e" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "h2" version = "0.3.26" @@ -5578,6 +5921,20 @@ version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "62adaabb884c94955b19907d60019f4e145d091c75345379e70d1ee696f7854f" +[[package]] +name = "html5ever" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bea68cab48b8459f17cf1c944c67ddc572d272d9f2b274140f223ecb1da4a3b7" +dependencies = [ + "log", + "mac", + "markup5ever 0.11.0", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "html5ever" version = "0.27.0" @@ -5586,7 +5943,7 @@ checksum = "c13771afe0e6e846f1e67d038d4cb29998a6779f93c809212e4e9c32efd244d4" dependencies = [ "log", "mac", - "markup5ever", + "markup5ever 0.12.1", "proc-macro2", "quote", "syn 2.0.87", @@ -5597,7 +5954,7 @@ name = "html_to_markdown" version = "0.1.0" dependencies = [ "anyhow", - "html5ever", + "html5ever 0.27.0", "indoc", "markup5ever_rcdom", "pretty_assertions", @@ -5612,7 +5969,7 @@ checksum = "601cbb57e577e2f5ef5be8e7b83f0f63994f25aa94d673e54a92d5c516d101f1" dependencies = [ "bytes 1.8.0", "fnv", - "itoa", + "itoa 1.0.11", ] [[package]] @@ -5623,7 +5980,7 @@ checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes 1.8.0", "fnv", - "itoa", + "itoa 1.0.11", ] [[package]] @@ -5741,7 +6098,7 @@ dependencies = [ "http-body 0.4.6", "httparse", "httpdate", - "itoa", + "itoa 1.0.11", "pin-project-lite", "socket2 0.5.7", "tokio", @@ -5763,7 +6120,7 @@ dependencies = [ "http 1.1.0", "http-body 1.0.1", "httparse", - "itoa", + "itoa 1.0.11", "pin-project-lite", "smallvec", "tokio", @@ -6371,12 +6728,41 @@ dependencies = [ "either", ] +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + [[package]] name = "itoa" version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +[[package]] +name = "javascriptcore-rs" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca5671e9ffce8ffba57afc24070e906da7fc4b1ba66f2cabebf61bf2ea257fcc" +dependencies = [ + "bitflags 1.3.2", + "glib", + "javascriptcore-rs-sys", +] + +[[package]] +name = "javascriptcore-rs-sys" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1be78d14ffa4b75b66df31840478fef72b51f8c2465d4ca7c194da9f7a5124" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "jni" version = "0.21.1" @@ -6533,6 +6919,19 @@ dependencies = [ "libc", ] +[[package]] +name = "kuchikiki" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f29e4755b7b995046f510a7520c42b2fed58b77bd94d5a87a8eb43d2fd126da8" +dependencies = [ + "cssparser", + "html5ever 0.26.0", + "indexmap 1.9.3", + "matches", + "selectors", +] + [[package]] name = "kurbo" version = "0.11.1" @@ -7181,6 +7580,20 @@ dependencies = [ "workspace", ] +[[package]] +name = "markup5ever" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a2629bb1404f3d34c2e921f21fd34ba00b206124c81f65c50b43b6aaefeb016" +dependencies = [ + "log", + "phf 0.10.1", + "phf_codegen 0.10.0", + "string_cache", + "string_cache_codegen", + "tendril", +] + [[package]] name = "markup5ever" version = "0.12.1" @@ -7188,8 +7601,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16ce3abbeba692c8b8441d036ef91aea6df8da2c6b6e21c7e14d3c18e526be45" dependencies = [ "log", - "phf", - "phf_codegen", + "phf 0.11.2", + "phf_codegen 0.11.2", "string_cache", "string_cache_codegen", "tendril", @@ -7201,8 +7614,8 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "edaa21ab3701bfee5099ade5f7e1f84553fd19228cf332f13cd6e964bf59be18" dependencies = [ - "html5ever", - "markup5ever", + "html5ever 0.27.0", + "markup5ever 0.12.1", "tendril", "xml5ever", ] @@ -7216,6 +7629,12 @@ dependencies = [ "regex-automata 0.1.10", ] +[[package]] +name = "matches" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" + [[package]] name = "matchit" version = "0.7.3" @@ -7544,6 +7963,20 @@ dependencies = [ "uuid", ] +[[package]] +name = "ndk" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" +dependencies = [ + "bitflags 1.3.2", + "jni-sys", + "ndk-sys 0.4.1+23.1.7779620", + "num_enum 0.5.11", + "raw-window-handle 0.5.2", + "thiserror 1.0.69", +] + [[package]] name = "ndk" version = "0.8.0" @@ -7553,8 +7986,8 @@ dependencies = [ "bitflags 2.6.0", "jni-sys", "log", - "ndk-sys", - "num_enum", + "ndk-sys 0.5.0+25.2.9519653", + "num_enum 0.7.3", "thiserror 1.0.69", ] @@ -7564,6 +7997,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" +[[package]] +name = "ndk-sys" +version = "0.4.1+23.1.7779620" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cf2aae958bd232cac5069850591667ad422d263686d75b52a065f9badeee5a3" +dependencies = [ + "jni-sys", +] + [[package]] name = "ndk-sys" version = "0.5.0+25.2.9519653" @@ -7617,6 +8059,12 @@ dependencies = [ "which 6.0.3", ] +[[package]] +name = "nodrop" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72ef4a56884ca558e5ddb05a1d1e7e1bfd9a68d9ed024c21704cc98872dae1bb" + [[package]] name = "nom" version = "7.1.3" @@ -7783,7 +8231,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" dependencies = [ "arrayvec", - "itoa", + "itoa 1.0.11", ] [[package]] @@ -7852,13 +8300,34 @@ dependencies = [ "libc", ] +[[package]] +name = "num_enum" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f646caf906c20226733ed5b1374287eb97e3c2a5c227ce668c1f2ce20ae57c9" +dependencies = [ + "num_enum_derive 0.5.11", +] + [[package]] name = "num_enum" version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e613fc340b2220f734a8595782c551f1250e969d87d3be1ae0579e8d4065179" dependencies = [ - "num_enum_derive", + "num_enum_derive 0.7.3", +] + +[[package]] +name = "num_enum_derive" +version = "0.5.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcbff9bc912032c62bf65ef1d5aea88983b420f4f839db1e9b0c281a25c9c799" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro2", + "quote", + "syn 1.0.109", ] [[package]] @@ -7867,7 +8336,7 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af1844ef2428cc3e1cb900be36181049ef3d3193c63e43026cfe202983b27a56" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 2.0.87", @@ -7899,12 +8368,31 @@ dependencies = [ ] [[package]] -name = "objc" -version = "0.2.7" +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", + "objc_exception", +] + +[[package]] +name = "objc_exception" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4" +dependencies = [ + "cc", +] + +[[package]] +name = "objc_id" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" dependencies = [ - "malloc_buf", + "objc", ] [[package]] @@ -7926,7 +8414,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8b61bebd49e5d43f5f8cc7ee2891c16e0f41ec7954d36bcb6c14c5e0de867fb" dependencies = [ "jni", - "ndk", + "ndk 0.8.0", "ndk-context", "num-derive", "num-traits", @@ -8260,6 +8748,31 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "pango" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ca27ec1eb0457ab26f3036ea52229edbdb74dee1edd29063f5b9b010e7ebee4" +dependencies = [ + "gio", + "glib", + "libc", + "once_cell", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "parity-tokio-ipc" version = "0.9.0" @@ -8811,16 +9324,56 @@ dependencies = [ "indexmap 2.6.0", ] +[[package]] +name = "phf" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dfb61232e34fcb633f43d12c58f83c1df82962dcdfa565a4e866ffc17dafe12" +dependencies = [ + "phf_macros 0.8.0", + "phf_shared 0.8.0", + "proc-macro-hack", +] + +[[package]] +name = "phf" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259" +dependencies = [ + "phf_shared 0.10.0", +] + [[package]] name = "phf" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ade2d8b8f33c7333b51bcf0428d37e217e9f32192ae4772156f65063b8ce03dc" dependencies = [ - "phf_macros", + "phf_macros 0.11.2", "phf_shared 0.11.2", ] +[[package]] +name = "phf_codegen" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cbffee61585b0411840d3ece935cce9cb6321f01c45477d30066498cd5e1a815" +dependencies = [ + "phf_generator 0.8.0", + "phf_shared 0.8.0", +] + +[[package]] +name = "phf_codegen" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", +] + [[package]] name = "phf_codegen" version = "0.11.2" @@ -8831,6 +9384,16 @@ dependencies = [ "phf_shared 0.11.2", ] +[[package]] +name = "phf_generator" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17367f0cc86f2d25802b2c26ee58a7b23faeccf78a396094c13dced0d0182526" +dependencies = [ + "phf_shared 0.8.0", + "rand 0.7.3", +] + [[package]] name = "phf_generator" version = "0.10.0" @@ -8851,6 +9414,20 @@ dependencies = [ "rand 0.8.5", ] +[[package]] +name = "phf_macros" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f6fde18ff429ffc8fe78e2bf7f8b7a5a5a6e2a8b58bc5a9ac69198bbda9189c" +dependencies = [ + "phf_generator 0.8.0", + "phf_shared 0.8.0", + "proc-macro-hack", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "phf_macros" version = "0.11.2" @@ -8864,6 +9441,15 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "phf_shared" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c00cf8b9eafe68dde5e9eaa2cef8ee84a9336a47d566ec55ca16589633b65af7" +dependencies = [ + "siphasher 0.3.11", +] + [[package]] name = "phf_shared" version = "0.10.0" @@ -9164,6 +9750,25 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit 0.19.15", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e8366a6159044a37876a2b9817124296703c586a5c92e2c53751fa06d8d43e8" +dependencies = [ + "toml_edit 0.20.7", +] + [[package]] name = "proc-macro-crate" version = "3.2.0" @@ -9219,6 +9824,12 @@ dependencies = [ "syn 2.0.87", ] +[[package]] +name = "proc-macro-hack" +version = "0.5.20+deprecated" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" + [[package]] name = "proc-macro2" version = "1.0.89" @@ -9613,6 +10224,7 @@ dependencies = [ "rand_chacha 0.2.2", "rand_core 0.5.1", "rand_hc", + "rand_pcg", ] [[package]] @@ -9673,6 +10285,15 @@ dependencies = [ "rand_core 0.5.1", ] +[[package]] +name = "rand_pcg" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16abd0c1b639e9eb4d7c50c0b8100b0d0f849be2349829c740fe8e6eb4816429" +dependencies = [ + "rand_core 0.5.1", +] + [[package]] name = "rangemap" version = "1.5.1" @@ -9729,6 +10350,12 @@ dependencies = [ "rgb", ] +[[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" @@ -9744,7 +10371,7 @@ dependencies = [ "cocoa 0.25.0", "core-graphics 0.23.2", "objc", - "raw-window-handle", + "raw-window-handle 0.6.2", ] [[package]] @@ -10492,7 +11119,7 @@ checksum = "99e4ea3e1cdc4b559b8e5650f9c8e5998e3e5c1343b4eaf034565f32318d63c0" dependencies = [ "bitflags 2.6.0", "errno 0.3.9", - "itoa", + "itoa 1.0.11", "libc", "linux-raw-sys 0.4.14", "once_cell", @@ -10904,6 +11531,26 @@ dependencies = [ "libc", ] +[[package]] +name = "selectors" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df320f1889ac4ba6bc0cdc9c9af7af4bd64bb927bccdf32d81140dc1f9be12fe" +dependencies = [ + "bitflags 1.3.2", + "cssparser", + "derive_more", + "fxhash", + "log", + "matches", + "phf 0.8.0", + "phf_codegen 0.8.0", + "precomputed-hash", + "servo_arc", + "smallvec", + "thin-slice", +] + [[package]] name = "self_cell" version = "1.0.4" @@ -11026,7 +11673,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7fceb2473b9166b2294ef05efcb65a3db80803f0b03ef86a5fc88a2b85ee377" dependencies = [ "indexmap 2.6.0", - "itoa", + "itoa 1.0.11", "memchr", "ryu", "serde", @@ -11039,7 +11686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bf0c7e21364d0e199dd2f6c339ca18d6fca75b69458a247e8b27ff1c92f5b86" dependencies = [ "indexmap 2.6.0", - "itoa", + "itoa 1.0.11", "memchr", "ryu", "serde", @@ -11051,7 +11698,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" dependencies = [ - "itoa", + "itoa 1.0.11", "serde", ] @@ -11104,11 +11751,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" dependencies = [ "form_urlencoded", - "itoa", + "itoa 1.0.11", "ryu", "serde", ] +[[package]] +name = "servo_arc" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d98238b800e0d1576d8b6e3de32827c2d74bee68bb97748dcf5071fb53965432" +dependencies = [ + "nodrop", + "stable_deref_trait", +] + [[package]] name = "session" version = "0.1.0" @@ -11486,6 +12143,32 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "soup3" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "471f924a40f31251afc77450e781cb26d55c0b650842efafc9c6cbd2f7cc4f9f" +dependencies = [ + "futures-channel", + "gio", + "glib", + "libc", + "soup3-sys", +] + +[[package]] +name = "soup3-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebe8950a680a12f24f15ebe1bf70db7af98ad242d9db43596ad3108aab86c27" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + [[package]] name = "spdx" version = "0.10.7" @@ -11705,7 +12388,7 @@ dependencies = [ "hex", "hkdf", "hmac", - "itoa", + "itoa 1.0.11", "log", "md-5", "memchr", @@ -11750,7 +12433,7 @@ dependencies = [ "hkdf", "hmac", "home", - "itoa", + "itoa 1.0.11", "log", "md-5", "memchr", @@ -12018,7 +12701,7 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c01c27a80b6151b0557f9ccbe89c11db571dc5f68113690c1e028d7e974bae94" dependencies = [ - "itoa", + "itoa 1.0.11", "ryu", "sval", ] @@ -12029,7 +12712,7 @@ version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0deef63c70da622b2a8069d8600cf4b05396459e665862e7bdb290fd6cf3f155" dependencies = [ - "itoa", + "itoa 1.0.11", "ryu", "sval", ] @@ -12285,6 +12968,17 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bdb6fa0dfa67b38c1e66b7041ba9dcf23b99d8121907cd31c807a332f7a0bbb" +[[package]] +name = "tao-macros" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4e16beb8b2ac17db28eab8bca40e62dbfbb34c0fcdc6d9826b11b7b5d047dfd" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + [[package]] name = "tap" version = "1.0.1" @@ -12552,6 +13246,12 @@ dependencies = [ "zed_actions", ] +[[package]] +name = "thin-slice" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8eaa81235c7058867fa8c0e7314f33dcce9c215f535d1913822a2b3f5e289f3c" + [[package]] name = "thiserror" version = "1.0.69" @@ -12635,7 +13335,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ "deranged", - "itoa", + "itoa 1.0.11", "libc", "num-conv", "num_threads", @@ -12971,6 +13671,17 @@ dependencies = [ "winnow 0.5.40", ] +[[package]] +name = "toml_edit" +version = "0.20.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70f427fce4d84c72b5b732388bf4a9f4531b53f74e2887e3ecb2481f68f66d81" +dependencies = [ + "indexmap 2.6.0", + "toml_datetime", + "winnow 0.5.40", +] + [[package]] name = "toml_edit" version = "0.22.22" @@ -14521,6 +15232,50 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "webkit2gtk" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "76b1bc1e54c581da1e9f179d0b38512ba358fb1af2d634a1affe42e37172361a" +dependencies = [ + "bitflags 1.3.2", + "cairo-rs", + "gdk", + "gdk-sys", + "gio", + "gio-sys", + "glib", + "glib-sys", + "gobject-sys", + "gtk", + "gtk-sys", + "javascriptcore-rs", + "libc", + "once_cell", + "soup3", + "webkit2gtk-sys", +] + +[[package]] +name = "webkit2gtk-sys" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62daa38afc514d1f8f12b8693d30d5993ff77ced33ce30cd04deebc267a6d57c" +dependencies = [ + "bitflags 1.3.2", + "cairo-sys-rs", + "gdk-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "gtk-sys", + "javascriptcore-rs-sys", + "libc", + "pkg-config", + "soup3-sys", + "system-deps", +] + [[package]] name = "webpki" version = "0.22.4" @@ -14546,6 +15301,42 @@ version = "0.25.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5f20c57d8d7db6d3b86154206ae5d8fba62dd39573114de97c2cb0578251f8e1" +[[package]] +name = "webview2-com" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6516cfa64c6b3212686080eeec378e662c2af54bb2a5b2a22749673f5cb2226f" +dependencies = [ + "webview2-com-macros", + "webview2-com-sys", + "windows 0.57.0", + "windows-core 0.57.0", + "windows-implement 0.57.0", + "windows-interface 0.57.0", +] + +[[package]] +name = "webview2-com-macros" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac1345798ecd8122468840bcdf1b95e5dc6d2206c5e4b0eafa078d061f59c9bc" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.87", +] + +[[package]] +name = "webview2-com-sys" +version = "0.31.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c76d5b77320ff155660be1df3e6588bc85c75f1a9feef938cc4dc4dd60d1d7cf" +dependencies = [ + "thiserror 1.0.69", + "windows 0.57.0", + "windows-core 0.57.0", +] + [[package]] name = "weezl" version = "0.1.8" @@ -14939,6 +15730,15 @@ dependencies = [ "windows_x86_64_msvc 0.52.6", ] +[[package]] +name = "windows-version" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6998aa457c9ba8ff2fb9f13e9d2a930dabcea28f1d0ab94d687d8b3654844515" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows_aarch64_gnullvm" version = "0.42.2" @@ -15358,6 +16158,48 @@ version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" +[[package]] +name = "wry" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68b00c945786b02d7805d09a969fa36d0eee4e0bd4fb3ec2a79d2bf45a1b44cd" +dependencies = [ + "base64 0.22.1", + "block", + "cocoa 0.25.0", + "core-graphics 0.23.2", + "crossbeam-channel", + "dpi", + "dunce", + "gdkx11", + "gtk", + "html5ever 0.26.0", + "http 1.1.0", + "javascriptcore-rs", + "jni", + "kuchikiki", + "libc", + "ndk 0.7.0", + "ndk-context", + "ndk-sys 0.4.1+23.1.7779620", + "objc", + "objc_id", + "once_cell", + "percent-encoding", + "raw-window-handle 0.6.2", + "sha2", + "soup3", + "tao-macros", + "thiserror 1.0.69", + "webkit2gtk", + "webkit2gtk-sys", + "webview2-com", + "windows 0.57.0", + "windows-core 0.57.0", + "windows-version", + "x11-dl", +] + [[package]] name = "wyz" version = "0.5.1" @@ -15367,6 +16209,16 @@ dependencies = [ "tap", ] +[[package]] +name = "x11" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e" +dependencies = [ + "libc", + "pkg-config", +] + [[package]] name = "x11-clipboard" version = "0.9.3" @@ -15377,6 +16229,17 @@ dependencies = [ "x11rb", ] +[[package]] +name = "x11-dl" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f" +dependencies = [ + "libc", + "once_cell", + "pkg-config", +] + [[package]] name = "x11rb" version = "0.13.1" @@ -15475,7 +16338,7 @@ checksum = "9bbb26405d8e919bc1547a5aa9abc95cbfa438f04844f5fdd9dc7596b748bf69" dependencies = [ "log", "mac", - "markup5ever", + "markup5ever 0.12.1", ] [[package]] @@ -15602,7 +16465,7 @@ version = "4.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "267db9407081e90bbfa46d841d3cbc60f59c0351838c4bc65199ecd79ab1983e" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 2.0.87", @@ -16122,7 +16985,7 @@ version = "4.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73e2ba546bda683a90652bac4a279bc146adad1386f25379cf73200d2002c449" dependencies = [ - "proc-macro-crate", + "proc-macro-crate 3.2.0", "proc-macro2", "quote", "syn 2.0.87", diff --git a/crates/gpui/Cargo.toml b/crates/gpui/Cargo.toml index 347e5502ca39d..b469a37f042dc 100644 --- a/crates/gpui/Cargo.toml +++ b/crates/gpui/Cargo.toml @@ -87,8 +87,8 @@ parking = "2.0.0" parking_lot.workspace = true postage.workspace = true profiling.workspace = true -rand = { optional = true, workspace = true } -raw-window-handle = "0.6" +rand = { optional = true, workspace = true} +raw-window-handle = { version = "0.6", features = ["std"] } refineable.workspace = true resvg = { version = "0.44.0", default-features = false } usvg = { version = "0.44.0", default-features = false } @@ -117,6 +117,7 @@ rand.workspace = true util = { workspace = true, features = ["test-support"] } http_client = { workspace = true, features = ["test-support"] } unicode-segmentation.workspace = true +wry = "0.41.0" [build-dependencies] embed-resource = "2.4" @@ -226,6 +227,10 @@ path = "examples/set_menus.rs" name = "window_shadow" path = "examples/window_shadow.rs" +[[example]] +name = 'webview' +path = "examples/webview.rs" + [[example]] name = "input" path = "examples/input.rs" diff --git a/crates/gpui/examples/webview.rs b/crates/gpui/examples/webview.rs new file mode 100644 index 0000000000000..5cc687ee12e51 --- /dev/null +++ b/crates/gpui/examples/webview.rs @@ -0,0 +1,175 @@ +use std::rc::Rc; + +use gpui::*; +use wry::{ + dpi::{self, LogicalSize}, + Rect, +}; + +struct WebViewWindow { + webview: View, +} + +impl WebViewWindow { + fn new(cx: &mut WindowContext) -> Self { + Self { + webview: cx.new_view(|cx| WebView::new(cx)), + } + } +} + +impl Render for WebViewWindow { + fn render(&mut self, _cx: &mut ViewContext) -> impl IntoElement { + div().flex().bg(rgb(0xF0F0F0)).size_full().p_10().child( + div() + .flex() + .flex_col() + .size_full() + .justify_center() + .items_center() + .gap_4() + .child("Wry WebView Demo") + .child(self.webview.clone()), + ) + } +} + +fn main() { + App::new().run(|cx: &mut AppContext| { + let bounds = Bounds::centered(None, size(px(1200.0), px(800.0)), cx); + let window = cx + .open_window( + WindowOptions { + window_bounds: Some(WindowBounds::Windowed(bounds)), + kind: WindowKind::Normal, + ..Default::default() + }, + |cx| cx.new_view(|cx| WebViewWindow::new(cx)), + ) + .unwrap(); + + cx.spawn(|mut cx| async move { + window + .update(&mut cx, |_, cx| { + cx.activate_window(); + cx.set_window_title("WebView Example"); + cx.on_release(|_, _, _cx| { + // exit app + std::process::exit(0); + }) + .detach(); + }) + .unwrap(); + }) + .detach(); + }); +} + +/// A webview element that can display a URL or HTML content. +pub struct WebView { + view: Rc, +} + +impl WebView { + /// Create a new webview element. + pub fn new(cx: &mut WindowContext) -> Self { + let view = Rc::new( + wry::WebViewBuilder::new_as_child(&cx.raw_window_handle()) + .with_url("https://zed.dev") + .build() + .expect("Failed to create webview."), + ); + + Self { view } + } +} + +impl Render for WebView { + fn render(&mut self, _cx: &mut ViewContext) -> impl IntoElement { + div() + .id("WebView") + .block() + .overflow_y_scroll() + .size_full() + .justify_center() + .items_center() + .shadow_lg() + .border_1() + .rounded_md() + .bg(gpui::white()) + .border_color(rgb(0xD0D0D0)) + .child(WebViewElement { + view: self.view.clone(), + }) + } +} + +struct WebViewElement { + view: Rc, +} +impl IntoElement for WebViewElement { + type Element = WebViewElement; + + fn into_element(self) -> Self::Element { + self + } +} + +impl Element for WebViewElement { + type RequestLayoutState = (); + type PrepaintState = (); + + fn id(&self) -> Option { + None + } + + fn request_layout( + &mut self, + _: Option<&GlobalElementId>, + cx: &mut WindowContext, + ) -> (LayoutId, Self::RequestLayoutState) { + let mut style = Style::default(); + style.flex_grow = 1.0; + style.size = Size::full(); + let id = cx.request_layout(style, []); + (id, ()) + } + + fn prepaint( + &mut self, + _: Option<&GlobalElementId>, + bounds: Bounds, + _: &mut Self::RequestLayoutState, + cx: &mut WindowContext, + ) -> Self::PrepaintState { + if bounds.top() > cx.viewport_size().height || bounds.bottom() < Pixels::ZERO { + self.view.set_visible(false).unwrap(); + } else { + self.view.set_visible(true).unwrap(); + + self.view + .set_bounds(Rect { + size: dpi::Size::Logical(LogicalSize { + width: (bounds.size.width.0).into(), + height: (bounds.size.height.0).into(), + }), + position: dpi::Position::Logical(dpi::LogicalPosition::new( + bounds.origin.x.into(), + bounds.origin.y.into(), + )), + }) + .unwrap(); + } + } + + fn paint( + &mut self, + _: Option<&GlobalElementId>, + _: Bounds, + _: &mut Self::RequestLayoutState, + _: &mut Self::PrepaintState, + _: &mut WindowContext, + ) { + // Nothing to do here + } +} diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index 87ee3942dd44a..009c3b3f8753d 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -1,6 +1,6 @@ use std::{ any::{type_name, TypeId}, - cell::{Ref, RefCell, RefMut}, + cell::RefCell, marker::PhantomData, ops::{Deref, DerefMut}, path::{Path, PathBuf}, @@ -10,7 +10,6 @@ use std::{ }; use anyhow::{anyhow, Result}; -use derive_more::{Deref, DerefMut}; use futures::{ channel::oneshot, future::{LocalBoxFuture, Shared}, @@ -50,7 +49,7 @@ pub const SHUTDOWN_TIMEOUT: Duration = Duration::from_millis(100); /// Strongly consider removing after stabilization. #[doc(hidden)] pub struct AppCell { - app: RefCell, + app: AppContext, } impl AppCell { @@ -61,7 +60,10 @@ impl AppCell { let thread_id = std::thread::current().id(); eprintln!("borrowed {thread_id:?}"); } - AppRef(self.app.borrow()) + AppRef { + _mark: PhantomData, + app: &self.app as *const _, + } } #[doc(hidden)] @@ -71,13 +73,26 @@ impl AppCell { let thread_id = std::thread::current().id(); eprintln!("borrowed {thread_id:?}"); } - AppRefMut(self.app.borrow_mut()) + AppRefMut { + _mark: PhantomData, + app: &self.app as *const _ as *mut _, + } } } #[doc(hidden)] -#[derive(Deref, DerefMut)] -pub struct AppRef<'a>(Ref<'a, AppContext>); +pub struct AppRef<'a> { + _mark: PhantomData<&'a ()>, + app: *const AppContext, +} + +impl<'a> Deref for AppRef<'a> { + type Target = AppContext; + + fn deref(&self) -> &Self::Target { + unsafe { &*self.app } + } +} impl<'a> Drop for AppRef<'a> { fn drop(&mut self) { @@ -89,9 +104,24 @@ impl<'a> Drop for AppRef<'a> { } #[doc(hidden)] -#[derive(Deref, DerefMut)] -pub struct AppRefMut<'a>(RefMut<'a, AppContext>); +pub struct AppRefMut<'a> { + _mark: PhantomData<&'a ()>, + app: *mut AppContext, +} + +impl<'a> Deref for AppRefMut<'a> { + type Target = AppContext; + fn deref(&self) -> &Self::Target { + unsafe { &*self.app } + } +} + +impl<'a> DerefMut for AppRefMut<'a> { + fn deref_mut(&mut self) -> &mut Self::Target { + unsafe { &mut *self.app } + } +} impl<'a> Drop for AppRefMut<'a> { fn drop(&mut self) { if option_env!("TRACK_THREAD_BORROWS").is_some() { @@ -284,7 +314,7 @@ impl AppContext { let keyboard_layout = SharedString::from(platform.keyboard_layout()); let app = Rc::new_cyclic(|this| AppCell { - app: RefCell::new(AppContext { + app: AppContext { this: this.clone(), platform: platform.clone(), text_system, @@ -320,10 +350,9 @@ impl AppContext { layout_id_buffer: Default::default(), propagate_event: true, prompt_builder: Some(PromptBuilder::Default), - #[cfg(any(test, feature = "test-support", debug_assertions))] name: None, - }), + }, }); init_app_menus(platform.as_ref(), &mut app.borrow_mut()); diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index 8228d44bb4f49..0a0e3f34a3ca2 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -345,7 +345,9 @@ pub(crate) struct RequestFrameOptions { pub(crate) require_presentation: bool, } -pub(crate) trait PlatformWindow: HasWindowHandle + HasDisplayHandle { +#[doc(hidden)] +#[allow(private_interfaces)] +pub trait PlatformWindow: HasWindowHandle + HasDisplayHandle { fn bounds(&self) -> Bounds; fn is_maximized(&self) -> bool; fn window_bounds(&self) -> WindowBounds; diff --git a/crates/gpui/src/window.rs b/crates/gpui/src/window.rs index 902c699cb72d1..5edf8f13fdcec 100644 --- a/crates/gpui/src/window.rs +++ b/crates/gpui/src/window.rs @@ -890,6 +890,11 @@ impl<'a> WindowContext<'a> { self.window.handle } + /// Obtain a raw handle to the platform_window that belongs to this context. + pub fn raw_window_handle(&self) -> &dyn PlatformWindow { + self.window.platform_window.as_ref() + } + /// Mark the window as dirty, scheduling it to be redrawn on the next frame. pub fn refresh(&mut self) { if self.window.draw_phase == DrawPhase::None {