From 206d303bd8319e4f9a4456d6f5a1886c1296d59e Mon Sep 17 00:00:00 2001 From: Timon Date: Fri, 4 Sep 2026 18:56:13 +0000 Subject: [PATCH 1/2] Desktop: Upgrade winit and port DnD to the new data transfer API --- Cargo.lock | 248 +++++++++++++++++++++++++------------------ Cargo.toml | 1 + desktop/src/app.rs | 50 ++++++--- desktop/src/input.rs | 2 + 4 files changed, 183 insertions(+), 118 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index e36ea02788d..9fe3955fa3b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,19 +33,6 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" -[[package]] -name = "ahash" -version = "0.8.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" -dependencies = [ - "cfg-if", - "getrandom 0.3.3", - "once_cell", - "version_check", - "zerocopy", -] - [[package]] name = "aho-corasick" version = "1.1.3" @@ -652,9 +639,9 @@ checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "cfg_aliases" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" [[package]] name = "chrono" @@ -1290,9 +1277,9 @@ dependencies = [ [[package]] name = "dlib" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "330c60081dcc4c72131f8eb70510f1ac07223e5d4163db481a04a0befcffa412" +checksum = "ab8ecd87370524b461f8557c119c405552c396ed91fc0a8eec68679eab26f94a" dependencies = [ "libloading 0.8.8", ] @@ -1393,6 +1380,11 @@ name = "dpi" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" + +[[package]] +name = "dpi" +version = "0.1.2" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "serde", ] @@ -3239,9 +3231,9 @@ checksum = "2c4a545a15244c7d945065b5d392b2d2d7f21526fba56ce51467b06ed445e8f7" [[package]] name = "libc" -version = "0.2.175" +version = "0.2.189" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" +checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2" [[package]] name = "libloading" @@ -3271,13 +3263,14 @@ checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de" [[package]] name = "libredox" -version = "0.1.9" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3" +checksum = "8d8f1ea3f21fd3405dcaf6c9b5c1630af9afc422d9073ea39c5f6d6c772e08ed" dependencies = [ "bitflags 2.11.0", "libc", - "redox_syscall", + "plain", + "redox_syscall 0.9.3", ] [[package]] @@ -3310,9 +3303,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.9.4" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" [[package]] name = "litemap" @@ -3510,7 +3503,7 @@ version = "0.17.1" source = "git+https://github.com/timon-schelling/muda.git?rev=e5bc28bbd6781b18afbfc237981f9ef47eddf863#e5bc28bbd6781b18afbfc237981f9ef47eddf863" dependencies = [ "crossbeam-channel", - "dpi", + "dpi 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "keyboard-types", "objc2 0.6.3", "objc2-app-kit 0.3.2", @@ -4049,9 +4042,9 @@ checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" [[package]] name = "orbclient" -version = "0.3.48" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba0b26cec2e24f08ed8bb31519a9333140a6599b867dac464bb150bdb796fd43" +checksum = "bb08138df30517916447489a70848de31244c40c7b520bcf5ebdc9db6299da59" dependencies = [ "libredox", ] @@ -4081,7 +4074,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d8fae84b431384b68627d0f9b3b1245fcf9f46f6c0e3dc902e9dce64edd1967" dependencies = [ "libc", - "windows-sys 0.45.0", + "windows-sys 0.59.0", ] [[package]] @@ -4111,7 +4104,7 @@ checksum = "bc838d2a56b5b1a6c25f55575dfc605fabb63bb2365f6c2353ef9159aa69e4a5" dependencies = [ "cfg-if", "libc", - "redox_syscall", + "redox_syscall 0.5.17", "smallvec", "windows-targets 0.52.6", ] @@ -4306,6 +4299,12 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" +[[package]] +name = "plain" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" + [[package]] name = "plist" version = "1.8.0" @@ -4540,18 +4539,18 @@ checksum = "4339fc7a1021c9c1621d87f5e3505f2805c8c105420ba2f2a4df86814590c142" [[package]] name = "quick-xml" -version = "0.37.5" +version = "0.38.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "331e97a1af0bf59823e6eadffe373d7b27f485be8748f71471c662c1f269b7fb" +checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89" dependencies = [ "memchr", ] [[package]] name = "quick-xml" -version = "0.38.3" +version = "0.41.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42a232e7487fc2ef313d96dde7948e7a3c05101870d8985e4fd8d26aedd27b89" +checksum = "e660451e55124f798a69a5af3f49ccfbefbd41910eefd25caf2393e1f3473ec1" dependencies = [ "memchr", ] @@ -4813,6 +4812,16 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3edd4d5d42c92f0a659926464d4cce56b562761267ecf0f469d85b7de384175" +[[package]] +name = "redox_event" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5018d583d6d2f5499352aea8d177e9067d1eb03ab17c78169d5ba7a30001b15" +dependencies = [ + "bitflags 2.11.0", + "libredox", +] + [[package]] name = "redox_syscall" version = "0.5.17" @@ -4822,6 +4831,15 @@ dependencies = [ "bitflags 2.11.0", ] +[[package]] +name = "redox_syscall" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d678d17679829e73d371e96880897e98fee2ded7acc0a50bdf8af2affa4b2fe5" +dependencies = [ + "bitflags 2.11.0", +] + [[package]] name = "redox_users" version = "0.5.2" @@ -5118,9 +5136,9 @@ dependencies = [ [[package]] name = "rustix" -version = "1.0.8" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11181fbabf243db407ef8df94a6ce0b2f9a733bd8be4ad02b4eda9602296cac8" +checksum = "b6fe4565b9518b83ef4f91bb47ce29620ca828bd32cb7e408f0062e9930ba190" dependencies = [ "bitflags 2.11.0", "errno", @@ -5292,14 +5310,14 @@ dependencies = [ [[package]] name = "sctk-adwaita" -version = "0.11.0" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd3accc0f3f4bbaf2c9e1957a030dc582028130c67660d44c0a0345a22ca69b" +checksum = "1f8ea028b7cb32e2f577b0a55a7b54cb206376bdb1221bd5c81dcf20b68db1fb" dependencies = [ "ab_glyph", "log", "memmap2 0.9.10", - "smithay-client-toolkit", + "smithay-client-toolkit 0.21.1", "tiny-skia", ] @@ -5632,7 +5650,32 @@ dependencies = [ "wayland-csd-frame", "wayland-cursor", "wayland-protocols", - "wayland-protocols-experimental", + "wayland-protocols-experimental 20250721.0.1", + "wayland-protocols-misc", + "wayland-protocols-wlr", + "wayland-scanner", + "xkeysym", +] + +[[package]] +name = "smithay-client-toolkit" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74dc9ee14b0fdcb535f9556141bacac070c994a977d2240ee455d7438a617f00" +dependencies = [ + "bitflags 2.11.0", + "calloop", + "calloop-wayland-source", + "cursor-icon", + "log", + "memmap2 0.9.10", + "rustix", + "thiserror 2.0.18", + "wayland-client", + "wayland-csd-frame", + "wayland-cursor", + "wayland-protocols", + "wayland-protocols-experimental 20251230.0.3", "wayland-protocols-misc", "wayland-protocols-wlr", "wayland-scanner", @@ -5646,7 +5689,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226" dependencies = [ "libc", - "smithay-client-toolkit", + "smithay-client-toolkit 0.20.0", "wayland-backend", ] @@ -6079,27 +6122,16 @@ dependencies = [ [[package]] name = "tiny-skia" -version = "0.11.4" +version = "0.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83d13394d44dae3207b52a326c0c85a8bf87f1541f23b0d143811088497b09ab" +checksum = "47ffee5eaaf5527f630fb0e356b90ebdec84d5d18d937c5e440350f88c5a91ea" dependencies = [ "arrayref", "arrayvec", "bytemuck", "cfg-if", "log", - "tiny-skia-path 0.11.4", -] - -[[package]] -name = "tiny-skia-path" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c9e7fc0c2e86a30b117d0462aa261b72b7a99b7ebd7deb3a14ceda95c5bdc93" -dependencies = [ - "arrayref", - "bytemuck", - "strict-num", + "tiny-skia-path", ] [[package]] @@ -6575,7 +6607,7 @@ dependencies = [ "siphasher", "strict-num", "svgtypes", - "tiny-skia-path 0.12.0", + "tiny-skia-path", "ttf-parser", "unicode-bidi", "unicode-script", @@ -6813,9 +6845,9 @@ dependencies = [ [[package]] name = "wayland-backend" -version = "0.3.11" +version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "673a33c33048a5ade91a6b139580fa174e19fb0d23f396dca9fa15f2e1e49b35" +checksum = "38a91b4eaddff87b1cd1074985e3713da4af2c49742d1b356b2c01670a67a078" dependencies = [ "cc", "downcast-rs", @@ -6827,9 +6859,9 @@ dependencies = [ [[package]] name = "wayland-client" -version = "0.31.11" +version = "0.31.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c66a47e840dc20793f2264eb4b3e4ecb4b75d91c0dd4af04b456128e0bdd449d" +checksum = "e3c36a0f861ad76d0901f2800b46321410d9f73f2ea88aac0650d86c32688073" dependencies = [ "bitflags 2.11.0", "rustix", @@ -6850,9 +6882,9 @@ dependencies = [ [[package]] name = "wayland-cursor" -version = "0.31.11" +version = "0.31.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "447ccc440a881271b19e9989f75726d60faa09b95b0200a9b7eb5cc47c3eeb29" +checksum = "4a52d18780be9b1314328a3de5f930b73d2200112e3849ca6cb11822793fb34d" dependencies = [ "rustix", "wayland-client", @@ -6861,9 +6893,9 @@ dependencies = [ [[package]] name = "wayland-protocols" -version = "0.32.9" +version = "0.32.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "efa790ed75fbfd71283bd2521a1cfdc022aabcc28bdcff00851f9e4ae88d9901" +checksum = "23d0c813de3daa2ed6520af85a3bd49b0e722a3078506899aa9686fea58dc4b6" dependencies = [ "bitflags 2.11.0", "wayland-backend", @@ -6884,6 +6916,19 @@ dependencies = [ "wayland-scanner", ] +[[package]] +name = "wayland-protocols-experimental" +version = "20251230.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91c6c3e7178e553d093d46999032bc79aafea9dedd71dd702c8ace7bbc25cf13" +dependencies = [ + "bitflags 2.11.0", + "wayland-backend", + "wayland-client", + "wayland-protocols", + "wayland-scanner", +] + [[package]] name = "wayland-protocols-misc" version = "0.3.9" @@ -6925,20 +6970,20 @@ dependencies = [ [[package]] name = "wayland-scanner" -version = "0.31.7" +version = "0.31.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54cb1e9dc49da91950bdfd8b848c49330536d9d1fb03d4bfec8cae50caa50ae3" +checksum = "338e30461b3a2b67d70eb30a6d89f8e0c93a833e07d2ae89085cd070c4a00ac0" dependencies = [ "proc-macro2", - "quick-xml 0.37.5", + "quick-xml 0.41.0", "quote", ] [[package]] name = "wayland-sys" -version = "0.31.7" +version = "0.31.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34949b42822155826b41db8e5d0c1be3a2bd296c747577a43a3e6daefc296142" +checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be" dependencies = [ "dlib", "log", @@ -7692,13 +7737,12 @@ checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" [[package]] name = "winit" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2879d2854d1a43e48f67322d4bd097afcb6eb8f8f775c8de0260a71aea1df1aa" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", "cfg_aliases", "cursor-icon", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "libc", "raw-window-handle", "rustix", @@ -7720,12 +7764,11 @@ dependencies = [ [[package]] name = "winit-android" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d9c0d2cd93efec3a9f9ad819cfaf0834782403af7c0d248c784ec0c61761df" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "android-activity", "bitflags 2.11.0", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "ndk", "raw-window-handle", "smol_str", @@ -7736,13 +7779,12 @@ dependencies = [ [[package]] name = "winit-appkit" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21310ca07851a49c348e0c2cc768e36b52ca65afda2c2354d78ed4b90074d8aa" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", "block2 0.6.2", "dispatch2", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "objc2 0.6.3", "objc2-app-kit 0.3.2", "objc2-core-foundation", @@ -7759,12 +7801,13 @@ dependencies = [ [[package]] name = "winit-common" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45375fbac4cbb77260d83a30b1f9d8105880dbac99a9ae97f56656694680ff69" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ + "block2 0.6.2", "memmap2 0.9.10", "objc2 0.6.3", "objc2-core-foundation", + "objc2-foundation 0.3.2", "smol_str", "tracing", "winit-core", @@ -7775,30 +7818,30 @@ dependencies = [ [[package]] name = "winit-core" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4f0ccd7abb43740e2c6124ac7cae7d865ecec74eec63783e8922577ac232583" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", "cursor-icon", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "keyboard-types", "raw-window-handle", "serde", "smol_str", + "url", "web-time", ] [[package]] name = "winit-orbital" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ea1fb262e7209f265f12bd0cc792c399b14355675e65531e9c8a87db287d46" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", + "libredox", "orbclient", "raw-window-handle", - "redox_syscall", + "redox_event", "smol_str", "tracing", "winit-core", @@ -7807,13 +7850,12 @@ dependencies = [ [[package]] name = "winit-uikit" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "680a356e798837d8eb274d4556e83bceaf81698194e31aafc5cfb8a9f2fab643" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", "block2 0.6.2", "dispatch2", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "objc2 0.6.3", "objc2-core-foundation", "objc2-foundation 0.3.2", @@ -7829,20 +7871,20 @@ dependencies = [ [[package]] name = "winit-wayland" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce5afb2ba07da603f84b722c95f9f9396d2cedae3944fb6c0cda4a6f88de545" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ - "ahash", "bitflags 2.11.0", "calloop", "cursor-icon", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", + "foldhash 0.2.0", "libc", "memmap2 0.9.10", + "percent-encoding", "raw-window-handle", "rustix", "sctk-adwaita", - "smithay-client-toolkit", + "smithay-client-toolkit 0.21.1", "smol_str", "tracing", "wayland-backend", @@ -7856,14 +7898,13 @@ dependencies = [ [[package]] name = "winit-web" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c2490a953fb776fbbd5e295d54f1c3847f4f15b6c3929ec53c09acda6487a92" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "atomic-waker", "bitflags 2.11.0", "concurrent-queue", "cursor-icon", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "js-sys", "pin-project", "raw-window-handle", @@ -7879,31 +7920,30 @@ dependencies = [ [[package]] name = "winit-win32" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "644ea78af0e858aa3b092e5d1c67c41995a98220c81813f1353b28bc8bb91eaa" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", "cursor-icon", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "raw-window-handle", "smol_str", "tracing", "unicode-segmentation", - "windows-sys 0.59.0", + "url", + "windows-sys 0.61.2", "winit-core", ] [[package]] name = "winit-x11" version = "0.31.0-beta.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa5b600756534c7041aa93cd0d244d44b09fca1b89e202bd1cd80dd9f3636c46" +source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", "bytemuck", "calloop", "cursor-icon", - "dpi", + "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", "libc", "percent-encoding", "raw-window-handle", diff --git a/Cargo.toml b/Cargo.toml index e0e55b65e31..972f3191fd5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -260,6 +260,7 @@ lto = "thin" debug = true [patch.crates-io] +winit = { git = "https://github.com/timon-schelling/winit", branch = "graphite" } rfd = { git = "https://github.com/timon-schelling/rfd.git", branch = "graphite" } # TODO: Remove this once https://github.com/PolyMeilex/rfd/pull/317 is merged and released cef = { git = "https://github.com/timon-schelling/cef-rs.git", branch = "graphite-151" } cef-dll-sys = { git = "https://github.com/timon-schelling/cef-rs.git", branch = "graphite-151" } diff --git a/desktop/src/app.rs b/desktop/src/app.rs index b89d1a5a964..3988bc41dca 100644 --- a/desktop/src/app.rs +++ b/desktop/src/app.rs @@ -9,10 +9,11 @@ use std::sync::mpsc::{Receiver, SyncSender}; use std::thread; use std::time::{Duration, Instant}; use winit::application::ApplicationHandler; +use winit::data_transfer::TypeHint; use winit::dpi::PhysicalSize; use winit::event::{ElementState, MouseButton, StartCause, WindowEvent}; use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand; -use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; +use winit::event_loop::{ActiveEventLoop, AsyncRequestSerial, ControlFlow, DndAction, EventLoop}; use winit::window::WindowId; use crate::dirs; @@ -35,6 +36,7 @@ pub(crate) struct App { window_maximized: bool, window_fullscreen: bool, window_pending_drag: bool, + pending_dnd_fetch: Option, input_state: InputState, ui_scale: f64, app_event_receiver: Receiver, @@ -107,6 +109,7 @@ impl App { window_maximized: false, window_fullscreen: false, window_pending_drag: false, + pending_dnd_fetch: None, input_state: InputState::new(), ui_scale: 1., app_event_receiver, @@ -538,7 +541,7 @@ impl ApplicationHandler for App { } } - fn window_event(&mut self, _event_loop: &dyn ActiveEventLoop, _window_id: WindowId, event: WindowEvent) { + fn window_event(&mut self, event_loop: &dyn ActiveEventLoop, _window_id: WindowId, event: WindowEvent) { // Handle pointer lock release if let WindowEvent::PointerButton { state: ElementState::Released, @@ -601,20 +604,39 @@ impl ApplicationHandler for App { self.exit(Some(ExitReason::UiAccelerationFailure)); } } - WindowEvent::DragDropped { paths, .. } => { - for path in paths { - match fs::read(&path) { - Ok(content) => { - let message = DesktopWrapperMessage::ImportFile { path, content }; - self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message)); - } - Err(e) => { - tracing::error!("Failed to read dropped file {}: {}", path.display(), e); - return; - } - }; + WindowEvent::DragEntered { id, .. } => { + let accepts = event_loop.data_transfer(id).is_ok_and(|data_transfer| data_transfer.has_type(&TypeHint::UriList)); + let actions: &[DndAction] = if accepts { &[DndAction::Copy] } else { &[] }; + if let Err(e) = event_loop.set_valid_dnd_actions(id, actions) { + tracing::error!("Failed to set valid drag and drop actions: {e}"); } } + WindowEvent::DragDropped { id, .. } => match event_loop.fetch_data_transfer(id, &TypeHint::UriList) { + Ok(serial) => self.pending_dnd_fetch = Some(serial), + Err(e) => tracing::error!("Failed to fetch dropped data: {e}"), + }, + WindowEvent::DataTransferReceived { serial, ref value, .. } if self.pending_dnd_fetch == Some(serial) => match value.try_as_file_paths() { + Ok(paths) => { + self.pending_dnd_fetch = None; + for path in paths { + match fs::read(&path) { + Ok(content) => { + let message = DesktopWrapperMessage::ImportFile { path, content }; + self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message)); + } + Err(e) => { + tracing::error!("Failed to read dropped file {}: {}", path.display(), e); + return; + } + }; + } + } + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {} + Err(e) => { + self.pending_dnd_fetch = None; + tracing::error!("Failed to read dropped data: {e}"); + } + }, WindowEvent::PointerMoved { .. } | WindowEvent::PointerLeft { position: Some(_), .. } | WindowEvent::PointerEntered { .. } if !self.input_state.pointer_locked() && self.window_pending_drag => diff --git a/desktop/src/input.rs b/desktop/src/input.rs index 731f43fdba1..dcc438f35b5 100644 --- a/desktop/src/input.rs +++ b/desktop/src/input.rs @@ -221,6 +221,7 @@ impl InputState { let input = match delta { MouseScrollDelta::LineDelta(x, y) => InputEvent::pointer().scrolled_lines(f64::from(*x), f64::from(*y)), MouseScrollDelta::PixelDelta(position) => InputEvent::pointer().scrolled_pixels(position.x, position.y), + _ => return, }; ui_callback(input.modifiers(self.modifiers).build()); return; @@ -229,6 +230,7 @@ impl InputState { let (x, y) = match delta { MouseScrollDelta::LineDelta(x, y) => (f64::from(*x) * SCROLL_LINE_WIDTH, f64::from(*y) * SCROLL_LINE_HEIGHT), MouseScrollDelta::PixelDelta(position) => (position.x, position.y), + _ => return, }; let scroll_delta = ScrollDelta::new(-x * SCROLL_SPEED_X, -y * SCROLL_SPEED_Y, 0.); From 7404406d0257abf626665750da54929dda572adb Mon Sep 17 00:00:00 2001 From: Timon Date: Fri, 4 Sep 2026 19:09:50 +0000 Subject: [PATCH 2/2] Desktop: Read and write the clipboard via the winit data transfer API --- Cargo.lock | 325 ++++++++---------------------------------- desktop/Cargo.toml | 1 - desktop/src/app.rs | 54 +++++-- desktop/src/event.rs | 4 + desktop/src/window.rs | 33 ----- 5 files changed, 105 insertions(+), 312 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9fe3955fa3b..713ee34437d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,22 +326,13 @@ dependencies = [ "generic-array", ] -[[package]] -name = "block2" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c132eebf10f5cad5289222520a4a058514204aed6d791f1cf4fe8088b82d15f" -dependencies = [ - "objc2 0.5.2", -] - [[package]] name = "block2" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" dependencies = [ - "objc2 0.6.3", + "objc2", ] [[package]] @@ -605,7 +596,7 @@ dependencies = [ "cef-dll-sys", "clap", "libloading 0.9.0", - "objc2 0.6.3", + "objc2", "plist", "semver", "serde", @@ -737,45 +728,6 @@ version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" -[[package]] -name = "clipboard-win" -version = "5.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bde03770d3df201d4fb868f2c9c59e66a3e4e2bd06692a0fe701e7103c7e84d4" -dependencies = [ - "error-code", -] - -[[package]] -name = "clipboard_macos" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b7f4aaa047ba3c3630b080bb9860894732ff23e2aee290a418909aa6d5df38f" -dependencies = [ - "objc2 0.5.2", - "objc2-app-kit 0.2.2", - "objc2-foundation 0.2.2", -] - -[[package]] -name = "clipboard_wayland" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "003f886bc4e2987729d10c1db3424e7f80809f3fc22dbc16c685738887cb37b8" -dependencies = [ - "smithay-clipboard", -] - -[[package]] -name = "clipboard_x11" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4274ea815e013e0f9f04a2633423e14194e408a0576c943ce3d14ca56c50031c" -dependencies = [ - "thiserror 1.0.69", - "x11rb", -] - [[package]] name = "cmake" version = "0.1.54" @@ -1259,9 +1211,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" dependencies = [ "bitflags 2.11.0", - "block2 0.6.2", + "block2", "libc", - "objc2 0.6.3", + "objc2", ] [[package]] @@ -1536,12 +1488,6 @@ dependencies = [ "windows-sys 0.59.0", ] -[[package]] -name = "error-code" -version = "3.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dea2df4cf52843e0452895c455a1a2cfbb842a1e7329671acf418fdc53ed4c59" - [[package]] name = "euclid" version = "0.22.14" @@ -2262,9 +2208,9 @@ dependencies = [ "interprocess", "lzma-rust2", "muda", - "objc2 0.6.3", - "objc2-app-kit 0.3.2", - "objc2-foundation 0.3.2", + "objc2", + "objc2-app-kit", + "objc2-foundation", "open", "rand", "rfd", @@ -2276,7 +2222,6 @@ dependencies = [ "tracing-subscriber", "vello", "wgpu", - "window_clipboard", "windows 0.62.2", "winit", ] @@ -2331,11 +2276,11 @@ dependencies = [ "ipc-channel", "libc", "mach2", - "objc2 0.6.3", - "objc2-app-kit 0.3.2", - "objc2-foundation 0.3.2", + "objc2", + "objc2-app-kit", + "objc2-foundation", "objc2-io-surface", - "objc2-metal 0.3.2", + "objc2-metal", "rand", "serde", "serde_json", @@ -3505,10 +3450,10 @@ dependencies = [ "crossbeam-channel", "dpi 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "keyboard-types", - "objc2 0.6.3", - "objc2-app-kit 0.3.2", + "objc2", + "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.2", + "objc2-foundation", "once_cell", "png 0.17.16", "thiserror 2.0.18", @@ -3770,22 +3715,6 @@ dependencies = [ "syn 2.0.106", ] -[[package]] -name = "objc-sys" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb91bdd390c7ce1a8607f35f3ca7151b65afc0ff5ff3b34fa350f7d7c7e4310" - -[[package]] -name = "objc2" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a785d4eeff09c14c487497c162e92766fbb3e4059a71840cecc03d9a50b804" -dependencies = [ - "objc-sys", - "objc2-encode", -] - [[package]] name = "objc2" version = "0.6.3" @@ -3795,22 +3724,6 @@ dependencies = [ "objc2-encode", ] -[[package]] -name = "objc2-app-kit" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4e89ad9e3d7d297152b17d39ed92cd50ca8063a89a9fa569046d41568891eff" -dependencies = [ - "bitflags 2.11.0", - "block2 0.5.1", - "libc", - "objc2 0.5.2", - "objc2-core-data", - "objc2-core-image", - "objc2-foundation 0.2.2", - "objc2-quartz-core 0.2.2", -] - [[package]] name = "objc2-app-kit" version = "0.3.2" @@ -3818,22 +3731,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" dependencies = [ "bitflags 2.11.0", - "block2 0.6.2", - "objc2 0.6.3", + "block2", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", -] - -[[package]] -name = "objc2-core-data" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "617fbf49e071c178c0b24c080767db52958f716d9eabdf0890523aeae54773ef" -dependencies = [ - "bitflags 2.11.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation 0.2.2", + "objc2-foundation", ] [[package]] @@ -3843,9 +3744,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.11.0", - "block2 0.6.2", + "block2", "dispatch2", - "objc2 0.6.3", + "objc2", ] [[package]] @@ -3859,18 +3760,6 @@ dependencies = [ "objc2-core-foundation", ] -[[package]] -name = "objc2-core-image" -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", - "objc2-foundation 0.2.2", - "objc2-metal 0.2.2", -] - [[package]] name = "objc2-core-video" version = "0.3.2" @@ -3888,18 +3777,6 @@ version = "4.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" -[[package]] -name = "objc2-foundation" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ee638a5da3799329310ad4cfa62fbf045d5f56e3ef5ba4149e7452dcf89d5a8" -dependencies = [ - "bitflags 2.11.0", - "block2 0.5.1", - "libc", - "objc2 0.5.2", -] - [[package]] name = "objc2-foundation" version = "0.3.2" @@ -3907,8 +3784,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" dependencies = [ "bitflags 2.11.0", - "block2 0.6.2", - "objc2 0.6.3", + "block2", + "objc2", "objc2-core-foundation", ] @@ -3920,21 +3797,9 @@ checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d" dependencies = [ "bitflags 2.11.0", "libc", - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", -] - -[[package]] -name = "objc2-metal" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0cba1276f6023976a406a14ffa85e1fdd19df6b0f737b063b95f6c8c7aadd6" -dependencies = [ - "bitflags 2.11.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation 0.2.2", + "objc2-foundation", ] [[package]] @@ -3944,27 +3809,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0125f776a10d00af4152d74616409f0d4a2053a6f57fa5b7d6aa2854ac04794" dependencies = [ "bitflags 2.11.0", - "block2 0.6.2", + "block2", "dispatch2", - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", + "objc2-foundation", "objc2-io-surface", ] -[[package]] -name = "objc2-quartz-core" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e42bee7bff906b14b167da2bac5efe6b6a07e6f7c0a21a7308d40c960242dc7a" -dependencies = [ - "bitflags 2.11.0", - "block2 0.5.1", - "objc2 0.5.2", - "objc2-foundation 0.2.2", - "objc2-metal 0.2.2", -] - [[package]] name = "objc2-quartz-core" version = "0.3.2" @@ -3972,10 +3824,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" dependencies = [ "bitflags 2.11.0", - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", - "objc2-metal 0.3.2", + "objc2-foundation", + "objc2-metal", ] [[package]] @@ -3985,9 +3837,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d87d638e33c06f577498cbcc50491496a3ed4246998a7fbba7ccb98b1e7eab22" dependencies = [ "bitflags 2.11.0", - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", + "objc2-foundation", ] [[package]] @@ -4752,10 +4604,10 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40d213455a5f1dc59214213c7330e074ddf8114c9a42411eb890c767357ce135" dependencies = [ - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", - "objc2-quartz-core 0.3.2", + "objc2-foundation", + "objc2-quartz-core", ] [[package]] @@ -4994,15 +4846,15 @@ name = "rfd" version = "0.17.2" source = "git+https://github.com/timon-schelling/rfd.git?branch=graphite#ebaf54232782629070e770bfe9cd90cb472ff137" dependencies = [ - "block2 0.6.2", + "block2", "dispatch2", "js-sys", "libc", "log", - "objc2 0.6.3", - "objc2-app-kit 0.3.2", + "objc2", + "objc2-app-kit", "objc2-core-foundation", - "objc2-foundation 0.3.2", + "objc2-foundation", "percent-encoding", "pollster", "raw-window-handle", @@ -5317,7 +5169,7 @@ dependencies = [ "ab_glyph", "log", "memmap2 0.9.10", - "smithay-client-toolkit 0.21.1", + "smithay-client-toolkit", "tiny-skia", ] @@ -5630,33 +5482,6 @@ dependencies = [ "serde", ] -[[package]] -name = "smithay-client-toolkit" -version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0512da38f5e2b31201a93524adb8d3136276fa4fe4aafab4e1f727a82b534cc0" -dependencies = [ - "bitflags 2.11.0", - "calloop", - "calloop-wayland-source", - "cursor-icon", - "libc", - "log", - "memmap2 0.9.10", - "rustix", - "thiserror 2.0.18", - "wayland-backend", - "wayland-client", - "wayland-csd-frame", - "wayland-cursor", - "wayland-protocols", - "wayland-protocols-experimental 20250721.0.1", - "wayland-protocols-misc", - "wayland-protocols-wlr", - "wayland-scanner", - "xkeysym", -] - [[package]] name = "smithay-client-toolkit" version = "0.21.1" @@ -5675,24 +5500,13 @@ dependencies = [ "wayland-csd-frame", "wayland-cursor", "wayland-protocols", - "wayland-protocols-experimental 20251230.0.3", + "wayland-protocols-experimental", "wayland-protocols-misc", "wayland-protocols-wlr", "wayland-scanner", "xkeysym", ] -[[package]] -name = "smithay-clipboard" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71704c03f739f7745053bde45fa203a46c58d25bc5c4efba1d9a60e9dba81226" -dependencies = [ - "libc", - "smithay-client-toolkit 0.20.0", - "wayland-backend", -] - [[package]] name = "smol_str" version = "0.3.2" @@ -6903,19 +6717,6 @@ dependencies = [ "wayland-scanner", ] -[[package]] -name = "wayland-protocols-experimental" -version = "20250721.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40a1f863128dcaaec790d7b4b396cc9b9a7a079e878e18c47e6c2d2c5a8dcbb1" -dependencies = [ - "bitflags 2.11.0", - "wayland-backend", - "wayland-client", - "wayland-protocols", - "wayland-scanner", -] - [[package]] name = "wayland-protocols-experimental" version = "20251230.0.3" @@ -7168,7 +6969,7 @@ dependencies = [ "ash", "bit-set 0.9.1", "bitflags 2.11.0", - "block2 0.6.2", + "block2", "bytemuck", "cfg-if", "cfg_aliases", @@ -7184,11 +6985,11 @@ dependencies = [ "log", "naga", "ndk-sys", - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", - "objc2-metal 0.3.2", - "objc2-quartz-core 0.3.2", + "objc2-foundation", + "objc2-metal", + "objc2-quartz-core", "once_cell", "ordered-float 4.6.0", "parking_lot", @@ -7279,20 +7080,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "window_clipboard" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5793d0b08c9e6a1240fe9ab2bd8db277487bf92436fd1a6321861a90a1b0cb7e" -dependencies = [ - "clipboard-win", - "clipboard_macos", - "clipboard_wayland", - "clipboard_x11", - "raw-window-handle", - "thiserror 1.0.69", -] - [[package]] name = "windows" version = "0.61.3" @@ -7782,15 +7569,15 @@ version = "0.31.0-beta.2" source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", - "block2 0.6.2", + "block2", "dispatch2", "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", - "objc2 0.6.3", - "objc2-app-kit 0.3.2", + "objc2", + "objc2-app-kit", "objc2-core-foundation", "objc2-core-graphics", "objc2-core-video", - "objc2-foundation 0.3.2", + "objc2-foundation", "raw-window-handle", "smol_str", "tracing", @@ -7803,11 +7590,11 @@ name = "winit-common" version = "0.31.0-beta.2" source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ - "block2 0.6.2", + "block2", "memmap2 0.9.10", - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", + "objc2-foundation", "smol_str", "tracing", "winit-core", @@ -7853,12 +7640,12 @@ version = "0.31.0-beta.2" source = "git+https://github.com/timon-schelling/winit?branch=graphite#1226add1bb6473ebaae83c3e1a43b81f170aca54" dependencies = [ "bitflags 2.11.0", - "block2 0.6.2", + "block2", "dispatch2", "dpi 0.1.2 (git+https://github.com/timon-schelling/winit?branch=graphite)", - "objc2 0.6.3", + "objc2", "objc2-core-foundation", - "objc2-foundation 0.3.2", + "objc2-foundation", "objc2-ui-kit", "raw-window-handle", "serde", @@ -7884,7 +7671,7 @@ dependencies = [ "raw-window-handle", "rustix", "sctk-adwaita", - "smithay-client-toolkit 0.21.1", + "smithay-client-toolkit", "smol_str", "tracing", "wayland-backend", diff --git a/desktop/Cargo.toml b/desktop/Cargo.toml index b68f76ac764..0a7c6b71023 100644 --- a/desktop/Cargo.toml +++ b/desktop/Cargo.toml @@ -49,7 +49,6 @@ clap = { workspace = true, features = ["derive"] } interprocess = "2.4.2" fd-lock = "4.0.4" ctrlc = "3.5.1" -window_clipboard = "0.5" # Windows-specific dependencies [target.'cfg(target_os = "windows")'.dependencies] diff --git a/desktop/src/app.rs b/desktop/src/app.rs index 3988bc41dca..1f48b438b00 100644 --- a/desktop/src/app.rs +++ b/desktop/src/app.rs @@ -9,7 +9,7 @@ use std::sync::mpsc::{Receiver, SyncSender}; use std::thread; use std::time::{Duration, Instant}; use winit::application::ApplicationHandler; -use winit::data_transfer::TypeHint; +use winit::data_transfer::{DataTransferSendBuilder, TypeHint}; use winit::dpi::PhysicalSize; use winit::event::{ElementState, MouseButton, StartCause, WindowEvent}; use winit::event_loop::run_on_demand::EventLoopExtRunOnDemand; @@ -37,6 +37,7 @@ pub(crate) struct App { window_fullscreen: bool, window_pending_drag: bool, pending_dnd_fetch: Option, + pending_clipboard_fetch: Option, input_state: InputState, ui_scale: f64, app_event_receiver: Receiver, @@ -110,6 +111,7 @@ impl App { window_fullscreen: false, window_pending_drag: false, pending_dnd_fetch: None, + pending_clipboard_fetch: None, input_state: InputState::new(), ui_scale: 1., app_event_receiver, @@ -338,16 +340,10 @@ impl App { } } DesktopFrontendMessage::ClipboardRead => { - if let Some(window) = &self.window { - let content = window.clipboard_read(); - let message = DesktopWrapperMessage::ClipboardReadResult { content }; - self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message)); - } + self.app_event_scheduler.schedule(AppEvent::ClipboardRead); } DesktopFrontendMessage::ClipboardWrite { content } => { - if let Some(window) = &mut self.window { - window.clipboard_write(content); - } + self.app_event_scheduler.schedule(AppEvent::ClipboardWrite { content }); } DesktopFrontendMessage::PointerLock => { self.input_state.lock_pointer(); @@ -470,6 +466,32 @@ impl App { self.ui_frame_received = true; } } + AppEvent::ClipboardRead => { + let result = event_loop.clipboard().and_then(|id| { + let Some(id) = id else { return Ok(None) }; + let data_transfer = event_loop.data_transfer(id)?; + if !data_transfer.has_type(&TypeHint::Plaintext) { + return Ok(None); + } + event_loop.fetch_data_transfer(id, &TypeHint::Plaintext).map(Some) + }); + match result { + Ok(Some(serial)) => self.pending_clipboard_fetch = Some(serial), + Ok(None) => self.dispatch_desktop_wrapper_message(DesktopWrapperMessage::ClipboardReadResult { content: None }), + Err(e) => { + tracing::error!("Failed to read from clipboard: {e}"); + self.dispatch_desktop_wrapper_message(DesktopWrapperMessage::ClipboardReadResult { content: None }); + } + } + } + AppEvent::ClipboardWrite { content } => { + let send_data = DataTransferSendBuilder::new(content) + .with_type(TypeHint::Plaintext, |content: &String, _| Some(content.clone())) + .build(); + if let Err(e) = event_loop.set_clipboard(send_data) { + tracing::error!("Failed to write to clipboard: {e}"); + } + } AppEvent::CursorChange(cursor) => { if let Some(window) = &mut self.window { window.set_cursor(event_loop, cursor); @@ -615,6 +637,20 @@ impl ApplicationHandler for App { Ok(serial) => self.pending_dnd_fetch = Some(serial), Err(e) => tracing::error!("Failed to fetch dropped data: {e}"), }, + WindowEvent::DataTransferReceived { serial, ref value, .. } if self.pending_clipboard_fetch == Some(serial) => match value.try_as_string() { + Ok(content) => { + self.pending_clipboard_fetch = None; + let message = DesktopWrapperMessage::ClipboardReadResult { content: Some(content) }; + self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message)); + } + Err(e) if e.kind() == std::io::ErrorKind::WouldBlock => {} + Err(e) => { + self.pending_clipboard_fetch = None; + tracing::error!("Failed to read from clipboard: {e}"); + let message = DesktopWrapperMessage::ClipboardReadResult { content: None }; + self.app_event_scheduler.schedule(AppEvent::DesktopWrapperMessage(message)); + } + }, WindowEvent::DataTransferReceived { serial, ref value, .. } if self.pending_dnd_fetch == Some(serial) => match value.try_as_file_paths() { Ok(paths) => { self.pending_dnd_fetch = None; diff --git a/desktop/src/event.rs b/desktop/src/event.rs index 1d7a8283de7..cbe0f77f3b4 100644 --- a/desktop/src/event.rs +++ b/desktop/src/event.rs @@ -8,6 +8,10 @@ pub(crate) enum AppEvent { WebCommunicationInitialized, DesktopWrapperMessage(DesktopWrapperMessage), NodeGraphExecutionResult(NodeGraphExecutionResult), + ClipboardRead, + ClipboardWrite { + content: String, + }, Exit, UiCrashed, OpenFiles(Vec), diff --git a/desktop/src/window.rs b/desktop/src/window.rs index 7693719b033..6b984e0d2af 100644 --- a/desktop/src/window.rs +++ b/desktop/src/window.rs @@ -43,13 +43,6 @@ pub(crate) struct Window { #[allow(dead_code)] native_handle: native::NativeWindowImpl, custom_cursors: HashMap, - clipboard: Option, -} -impl Drop for Window { - fn drop(&mut self) { - // Clipboard must be dropped before `winit_window` - drop(self.clipboard.take()); - } } impl Window { @@ -70,12 +63,10 @@ impl Window { let winit_window = event_loop.create_window(attributes).unwrap(); let native_handle = native::NativeWindowImpl::new(winit_window.as_ref(), app_event_scheduler); - let clipboard = unsafe { window_clipboard::Clipboard::connect(&winit_window) }.ok(); Self { winit_window: winit_window.into(), native_handle, custom_cursors: HashMap::new(), - clipboard, } } @@ -208,28 +199,4 @@ impl Window { pub(crate) fn update_menu(&self, entries: Vec) { self.native_handle.update_menu(entries); } - - pub(crate) fn clipboard_read(&self) -> Option { - let Some(clipboard) = &self.clipboard else { - tracing::error!("Clipboard not available"); - return None; - }; - match clipboard.read() { - Ok(data) => Some(data), - Err(e) => { - tracing::error!("Failed to read from clipboard: {e}"); - None - } - } - } - - pub(crate) fn clipboard_write(&mut self, data: String) { - let Some(clipboard) = &mut self.clipboard else { - tracing::error!("Clipboard not available"); - return; - }; - if let Err(e) = clipboard.write(data) { - tracing::error!("Failed to write to clipboard: {e}") - } - } }