Windows share picker is a live thumbnail grid: xcap lists screens and windows without cloaked/tool/own junk, rescans every 1.5s, thumbnails refresh within a 100ms budget per tick and are cached per window, rows virtualized. 🐛 fix: window share follows resizes (encoders reopen once the new size holds 300ms)
Browse files at this commit38b4cd2b4197ffa3eb48fcbe008fe2f2640bc9f4Parent: 526a1a8- feat
- Windows share picker is a live thumbnail grid: xcap lists screens and windows without cloaked/tool/own junk, rescans every 1.5s, thumbnails refresh within a 100ms budget per tick and are cached per window, rows virtualized. 🐛 fix: window share follows resizes (encoders reopen once the new size holds 300ms)
- share button ignores clicks while a start/stop is in flight, so Linux no longer stacks portals
10 changed files +478 -72
- Cargo.lock +213 -2
- crates/client/Cargo.toml +1 -0
- crates/client/src/gui.rs +2 -0
- crates/client/src/gui/share_view.rs +159 -39
- crates/client/src/share/capture.rs +3 -1
- crates/client/src/share/capture_windows.rs +59 -25
- crates/client/src/share/encode.rs +30 -2
- crates/client/src/share/mod.rs +7 -1
- crates/client/src/share/session.rs +1 -1
- crates/client/src/share/unsupported.rs +3 -1
Cargo.lockmodified+213 -2
| @@ -400,8 +400,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 400 | 400 | checksum = "b60a01f4fbcba6a522ec4d285893bd0ce36f5987a8b3bf636e6aeb2d2acdf8ac" |
| 401 | 401 | dependencies = [ |
| 402 | 402 | "bitflags 2.13.2", |
| 403 | + "futures-channel", | |
| 403 | 404 | "futures-util", |
| 404 | 405 | "getrandom 0.4.3", |
| 406 | + "pipewire", | |
| 405 | 407 | "serde", |
| 406 | 408 | "serde_repr", |
| 407 | 409 | "tokio", |
| @@ -1314,6 +1316,7 @@ dependencies = [ | ||
| 1314 | 1316 | "wasapi", |
| 1315 | 1317 | "windows-capture 2.0.1", |
| 1316 | 1318 | "winreg", |
| 1319 | + "xcap", | |
| 1317 | 1320 | ] |
| 1318 | 1321 | |
| 1319 | 1322 | [[package]] |
| @@ -2029,6 +2032,7 @@ checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" | ||
| 2029 | 2032 | dependencies = [ |
| 2030 | 2033 | "bitflags 2.13.2", |
| 2031 | 2034 | "block2 0.6.2", |
| 2035 | + "libc", | |
| 2032 | 2036 | "objc2 0.6.5", |
| 2033 | 2037 | ] |
| 2034 | 2038 | |
| @@ -2073,6 +2077,61 @@ version = "0.1.2" | ||
| 2073 | 2077 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 2074 | 2078 | checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" |
| 2075 | 2079 | |
| 2080 | +[[package]] | |
| 2081 | +name = "drm" | |
| 2082 | +version = "0.14.1" | |
| 2083 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2084 | +checksum = "80bc8c5c6c2941f70a55c15f8d9f00f9710ebda3ffda98075f996a0e6c92756f" | |
| 2085 | +dependencies = [ | |
| 2086 | + "bitflags 2.13.2", | |
| 2087 | + "bytemuck", | |
| 2088 | + "drm-ffi", | |
| 2089 | + "drm-fourcc", | |
| 2090 | + "libc", | |
| 2091 | + "rustix 0.38.44", | |
| 2092 | +] | |
| 2093 | + | |
| 2094 | +[[package]] | |
| 2095 | +name = "drm" | |
| 2096 | +version = "0.15.0" | |
| 2097 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2098 | +checksum = "7a41816e58f47f49acfd956651055ddcf137c4882c2098c30c448817af21183a" | |
| 2099 | +dependencies = [ | |
| 2100 | + "bitflags 2.13.2", | |
| 2101 | + "bytemuck", | |
| 2102 | + "bytemuck_derive", | |
| 2103 | + "drm-ffi", | |
| 2104 | + "drm-fourcc", | |
| 2105 | + "libc", | |
| 2106 | + "rustix 1.1.6", | |
| 2107 | +] | |
| 2108 | + | |
| 2109 | +[[package]] | |
| 2110 | +name = "drm-ffi" | |
| 2111 | +version = "0.9.1" | |
| 2112 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2113 | +checksum = "51a91c9b32ac4e8105dec255e849e0d66e27d7c34d184364fb93e469db08f690" | |
| 2114 | +dependencies = [ | |
| 2115 | + "drm-sys", | |
| 2116 | + "rustix 1.1.6", | |
| 2117 | +] | |
| 2118 | + | |
| 2119 | +[[package]] | |
| 2120 | +name = "drm-fourcc" | |
| 2121 | +version = "2.2.0" | |
| 2122 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2123 | +checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4" | |
| 2124 | + | |
| 2125 | +[[package]] | |
| 2126 | +name = "drm-sys" | |
| 2127 | +version = "0.8.1" | |
| 2128 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 2129 | +checksum = "ecc8e1361066d91f5ffccff060a3c3be9c3ecde15be2959c1937595f7a82a9f8" | |
| 2130 | +dependencies = [ | |
| 2131 | + "libc", | |
| 2132 | + "linux-raw-sys 0.9.4", | |
| 2133 | +] | |
| 2134 | + | |
| 2076 | 2135 | [[package]] |
| 2077 | 2136 | name = "dunce" |
| 2078 | 2137 | version = "1.0.5" |
| @@ -3006,6 +3065,30 @@ dependencies = [ | ||
| 3006 | 3065 | "slab", |
| 3007 | 3066 | ] |
| 3008 | 3067 | |
| 3068 | +[[package]] | |
| 3069 | +name = "gbm" | |
| 3070 | +version = "0.18.0" | |
| 3071 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3072 | +checksum = "ce852e998d3ca5e4a97014fb31c940dc5ef344ec7d364984525fd11e8a547e6a" | |
| 3073 | +dependencies = [ | |
| 3074 | + "bitflags 2.13.2", | |
| 3075 | + "drm 0.14.1", | |
| 3076 | + "drm-fourcc", | |
| 3077 | + "gbm-sys", | |
| 3078 | + "libc", | |
| 3079 | + "wayland-backend", | |
| 3080 | + "wayland-server", | |
| 3081 | +] | |
| 3082 | + | |
| 3083 | +[[package]] | |
| 3084 | +name = "gbm-sys" | |
| 3085 | +version = "0.4.0" | |
| 3086 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3087 | +checksum = "c13a5f2acc785d8fb6bf6b7ab6bfb0ef5dad4f4d97e8e70bb8e470722312f76f" | |
| 3088 | +dependencies = [ | |
| 3089 | + "libc", | |
| 3090 | +] | |
| 3091 | + | |
| 3009 | 3092 | [[package]] |
| 3010 | 3093 | name = "generator" |
| 3011 | 3094 | version = "0.8.12" |
| @@ -3117,6 +3200,15 @@ version = "0.34.0" | ||
| 3117 | 3200 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 3118 | 3201 | checksum = "1033caf0b349c518623b5396bfb2cf0bddf44f0306d543a250e5743297aafd10" |
| 3119 | 3202 | |
| 3203 | +[[package]] | |
| 3204 | +name = "gl" | |
| 3205 | +version = "0.14.0" | |
| 3206 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 3207 | +checksum = "a94edab108827d67608095e269cf862e60d920f144a5026d3dbcfd8b877fb404" | |
| 3208 | +dependencies = [ | |
| 3209 | + "gl_generator", | |
| 3210 | +] | |
| 3211 | + | |
| 3120 | 3212 | [[package]] |
| 3121 | 3213 | name = "gl_generator" |
| 3122 | 3214 | version = "0.14.0" |
| @@ -3343,7 +3435,7 @@ dependencies = [ | ||
| 3343 | 3435 | "parking", |
| 3344 | 3436 | "parking_lot", |
| 3345 | 3437 | "pin-project", |
| 3346 | - "pollster", | |
| 3438 | + "pollster 0.4.0", | |
| 3347 | 3439 | "profiling", |
| 3348 | 3440 | "rand 0.9.5", |
| 3349 | 3441 | "raw-window-handle", |
| @@ -3699,7 +3791,7 @@ dependencies = [ | ||
| 3699 | 3791 | "parking", |
| 3700 | 3792 | "parking_lot", |
| 3701 | 3793 | "pin-project", |
| 3702 | - "pollster", | |
| 3794 | + "pollster 0.4.0", | |
| 3703 | 3795 | "profiling", |
| 3704 | 3796 | "rand 0.9.5", |
| 3705 | 3797 | "raw-window-handle", |
| @@ -5229,6 +5321,27 @@ dependencies = [ | ||
| 5229 | 5321 | "system-deps", |
| 5230 | 5322 | ] |
| 5231 | 5323 | |
| 5324 | +[[package]] | |
| 5325 | +name = "libwayshot-xcap" | |
| 5326 | +version = "0.3.3" | |
| 5327 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 5328 | +checksum = "ea8a46e4d016ef464e386e4970f5415fe0939c2d63abe0c2f539c05ef88c5fe5" | |
| 5329 | +dependencies = [ | |
| 5330 | + "drm 0.15.0", | |
| 5331 | + "gbm", | |
| 5332 | + "gl", | |
| 5333 | + "image", | |
| 5334 | + "khronos-egl", | |
| 5335 | + "memmap2", | |
| 5336 | + "rustix 1.1.6", | |
| 5337 | + "thiserror 2.0.21", | |
| 5338 | + "tracing", | |
| 5339 | + "wayland-backend", | |
| 5340 | + "wayland-client", | |
| 5341 | + "wayland-protocols", | |
| 5342 | + "wayland-protocols-wlr", | |
| 5343 | +] | |
| 5344 | + | |
| 5232 | 5345 | [[package]] |
| 5233 | 5346 | name = "linebender_resource_handle" |
| 5234 | 5347 | version = "0.1.1" |
| @@ -5273,6 +5386,12 @@ version = "0.4.15" | ||
| 5273 | 5386 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 5274 | 5387 | checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" |
| 5275 | 5388 | |
| 5389 | +[[package]] | |
| 5390 | +name = "linux-raw-sys" | |
| 5391 | +version = "0.9.4" | |
| 5392 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 5393 | +checksum = "cd945864f07fe9f5371a27ad7b52a172b4b499999f1d97574c9fa68373937e12" | |
| 5394 | + | |
| 5276 | 5395 | [[package]] |
| 5277 | 5396 | name = "linux-raw-sys" |
| 5278 | 5397 | version = "0.12.1" |
| @@ -6216,6 +6335,7 @@ checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" | ||
| 6216 | 6335 | dependencies = [ |
| 6217 | 6336 | "bitflags 2.13.2", |
| 6218 | 6337 | "dispatch2", |
| 6338 | + "libc", | |
| 6219 | 6339 | "objc2 0.6.5", |
| 6220 | 6340 | "objc2-core-foundation", |
| 6221 | 6341 | "objc2-io-surface", |
| @@ -6243,6 +6363,21 @@ dependencies = [ | ||
| 6243 | 6363 | "objc2-foundation 0.3.2", |
| 6244 | 6364 | ] |
| 6245 | 6365 | |
| 6366 | +[[package]] | |
| 6367 | +name = "objc2-core-media" | |
| 6368 | +version = "0.3.2" | |
| 6369 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 6370 | +checksum = "05ec576860167a15dd9fce7fbee7512beb4e31f532159d3482d1f9c6caedf31d" | |
| 6371 | +dependencies = [ | |
| 6372 | + "bitflags 2.13.2", | |
| 6373 | + "dispatch2", | |
| 6374 | + "objc2 0.6.5", | |
| 6375 | + "objc2-core-audio", | |
| 6376 | + "objc2-core-audio-types", | |
| 6377 | + "objc2-core-foundation", | |
| 6378 | + "objc2-core-video", | |
| 6379 | +] | |
| 6380 | + | |
| 6246 | 6381 | [[package]] |
| 6247 | 6382 | name = "objc2-core-services" |
| 6248 | 6383 | version = "0.3.2" |
| @@ -6383,6 +6518,22 @@ dependencies = [ | ||
| 6383 | 6518 | "objc2-metal 0.3.2", |
| 6384 | 6519 | ] |
| 6385 | 6520 | |
| 6521 | +[[package]] | |
| 6522 | +name = "objc2-screen-capture-kit" | |
| 6523 | +version = "0.3.2" | |
| 6524 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 6525 | +checksum = "74b7c5390f477482f001bc354d6571a70db7e4f8d5288e860c45521fbce11394" | |
| 6526 | +dependencies = [ | |
| 6527 | + "block2 0.6.2", | |
| 6528 | + "dispatch2", | |
| 6529 | + "libc", | |
| 6530 | + "objc2 0.6.5", | |
| 6531 | + "objc2-core-foundation", | |
| 6532 | + "objc2-core-graphics", | |
| 6533 | + "objc2-core-media", | |
| 6534 | + "objc2-foundation 0.3.2", | |
| 6535 | +] | |
| 6536 | + | |
| 6386 | 6537 | [[package]] |
| 6387 | 6538 | name = "objc2-security" |
| 6388 | 6539 | version = "0.3.2" |
| @@ -6897,6 +7048,12 @@ version = "0.4.0" | ||
| 6897 | 7048 | source = "registry+https://github.com/rust-lang/crates.io-index" |
| 6898 | 7049 | checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3" |
| 6899 | 7050 | |
| 7051 | +[[package]] | |
| 7052 | +name = "pollster" | |
| 7053 | +version = "1.0.3" | |
| 7054 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 7055 | +checksum = "7e9b9cf600136f5b976fbc5727d58c26e1ecab8ee23088d44ef1c7af793550ab" | |
| 7056 | + | |
| 6900 | 7057 | [[package]] |
| 6901 | 7058 | name = "polycool" |
| 6902 | 7059 | version = "0.4.0" |
| @@ -10150,6 +10307,19 @@ dependencies = [ | ||
| 10150 | 10307 | "quote", |
| 10151 | 10308 | ] |
| 10152 | 10309 | |
| 10310 | +[[package]] | |
| 10311 | +name = "wayland-server" | |
| 10312 | +version = "0.31.14" | |
| 10313 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 10314 | +checksum = "0dde9c29be0f723a573977de51ee455bf3dfa03652730a74f9dd3b337e374d75" | |
| 10315 | +dependencies = [ | |
| 10316 | + "bitflags 2.13.2", | |
| 10317 | + "downcast-rs", | |
| 10318 | + "rustix 1.1.6", | |
| 10319 | + "wayland-backend", | |
| 10320 | + "wayland-scanner", | |
| 10321 | +] | |
| 10322 | + | |
| 10153 | 10323 | [[package]] |
| 10154 | 10324 | name = "wayland-sys" |
| 10155 | 10325 | version = "0.31.11" |
| @@ -10157,7 +10327,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" | ||
| 10157 | 10327 | checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be" |
| 10158 | 10328 | dependencies = [ |
| 10159 | 10329 | "dlib", |
| 10330 | + "libc", | |
| 10160 | 10331 | "log", |
| 10332 | + "memoffset", | |
| 10161 | 10333 | "once_cell", |
| 10162 | 10334 | "pkg-config", |
| 10163 | 10335 | ] |
| @@ -10420,6 +10592,12 @@ dependencies = [ | ||
| 10420 | 10592 | "safe_arch", |
| 10421 | 10593 | ] |
| 10422 | 10594 | |
| 10595 | +[[package]] | |
| 10596 | +name = "widestring" | |
| 10597 | +version = "1.2.1" | |
| 10598 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 10599 | +checksum = "72069c3113ab32ab29e5584db3c6ec55d416895e60715417b5b883a357c3e471" | |
| 10600 | + | |
| 10423 | 10601 | [[package]] |
| 10424 | 10602 | name = "winapi" |
| 10425 | 10603 | version = "0.3.9" |
| @@ -11259,6 +11437,39 @@ dependencies = [ | ||
| 11259 | 11437 | "time", |
| 11260 | 11438 | ] |
| 11261 | 11439 | |
| 11440 | +[[package]] | |
| 11441 | +name = "xcap" | |
| 11442 | +version = "0.9.11" | |
| 11443 | +source = "registry+https://github.com/rust-lang/crates.io-index" | |
| 11444 | +checksum = "ba87463fc0a904e360fbdc53eaa97f08d133f4ec5d04052a4ec73af0979dfae4" | |
| 11445 | +dependencies = [ | |
| 11446 | + "ashpd 0.14.3", | |
| 11447 | + "block2 0.6.2", | |
| 11448 | + "dispatch2", | |
| 11449 | + "image", | |
| 11450 | + "libwayshot-xcap", | |
| 11451 | + "log", | |
| 11452 | + "objc2 0.6.5", | |
| 11453 | + "objc2-app-kit 0.3.2", | |
| 11454 | + "objc2-core-foundation", | |
| 11455 | + "objc2-core-graphics", | |
| 11456 | + "objc2-core-media", | |
| 11457 | + "objc2-core-video", | |
| 11458 | + "objc2-foundation 0.3.2", | |
| 11459 | + "objc2-screen-capture-kit", | |
| 11460 | + "percent-encoding", | |
| 11461 | + "pipewire", | |
| 11462 | + "pollster 1.0.3", | |
| 11463 | + "rand 0.10.4", | |
| 11464 | + "scopeguard", | |
| 11465 | + "serde", | |
| 11466 | + "thiserror 2.0.21", | |
| 11467 | + "url", | |
| 11468 | + "widestring", | |
| 11469 | + "windows 0.62.2", | |
| 11470 | + "xcb", | |
| 11471 | +] | |
| 11472 | + | |
| 11262 | 11473 | [[package]] |
| 11263 | 11474 | name = "xcb" |
| 11264 | 11475 | version = "1.7.1" |
crates/client/Cargo.tomlmodified+1 -0
| @@ -54,6 +54,7 @@ ashpd = { version = "0.14.3", default-features = false, features = ["tokio", "sc | ||
| 54 | 54 | [target.'cfg(target_os = "windows")'.dependencies] |
| 55 | 55 | wasapi = "0.27.0" |
| 56 | 56 | windows-capture = "2.0.1" |
| 57 | +xcap = { version = "0.9.11", default-features = false } | |
| 57 | 58 | tray-icon = { version = "0.27.0", default-features = false } |
| 58 | 59 | winreg = "0.56.0" |
| 59 | 60 | sysinfo = { version = "0.40.4", default-features = false, features = ["system"] } |
crates/client/src/gui.rsmodified+2 -0
| @@ -625,6 +625,7 @@ pub struct Yumush { | ||
| 625 | 625 | camera_modes: Vec<common::share::Mode>, |
| 626 | 626 | camera_devices: Vec<String>, |
| 627 | 627 | share_more: bool, |
| 628 | + share_busy: bool, | |
| 628 | 629 | fullscreen: bool, |
| 629 | 630 | pumping: bool, |
| 630 | 631 | pumped: Instant, |
| @@ -726,6 +727,7 @@ impl Yumush { | ||
| 726 | 727 | camera_modes: Vec::new(), |
| 727 | 728 | camera_devices: Vec::new(), |
| 728 | 729 | share_more: false, |
| 730 | + share_busy: false, | |
| 729 | 731 | fullscreen: false, |
| 730 | 732 | pumping: false, |
| 731 | 733 | pumped: Instant::now(), |
crates/client/src/gui/share_view.rsmodified+159 -39
| @@ -1,5 +1,6 @@ | ||
| 1 | 1 | use common::model::Id; |
| 2 | 2 | use std::{ |
| 3 | + collections::HashMap, | |
| 3 | 4 | sync::Arc, |
| 4 | 5 | time::{Duration, Instant}, |
| 5 | 6 | }; |
| @@ -12,6 +13,17 @@ use crate::share::Target; | ||
| 12 | 13 | const FULL_VOLUME: f32 = 100.; |
| 13 | 14 | const VOLUME_WIDTH: f32 = 80.; |
| 14 | 15 | const APPS_HEIGHT: f32 = 160.; |
| 16 | +const PICK_COLUMNS: usize = 3; | |
| 17 | +const PICK_REFRESH: Duration = Duration::from_millis(1500); | |
| 18 | + | |
| 19 | +const PICK_ROW: f32 = size::THUMB + size::ROW; | |
| 20 | +const PREVIEW_AGE: Duration = Duration::from_secs(3); | |
| 21 | + | |
| 22 | +#[derive(Default)] | |
| 23 | +struct Picker { | |
| 24 | + sources: Vec<(Target, String)>, | |
| 25 | + previews: HashMap<Target, (Instant, Arc<RenderImage>)>, | |
| 26 | +} | |
| 15 | 27 | |
| 16 | 28 | const TOP_QUALITY: Quality = Quality { |
| 17 | 29 | resolution: Resolution::P2160, |
| @@ -19,17 +31,17 @@ const TOP_QUALITY: Quality = Quality { | ||
| 19 | 31 | }; |
| 20 | 32 | use gpui_kit::{ |
| 21 | 33 | Anchor, AnyElement, App, AppContext, Context, Div, Entity, InteractiveElement, IntoElement, |
| 22 | - KeyDownEvent, Keystroke, Modifiers, MouseButton, ParentElement, PlatformInput, | |
| 23 | - StatefulInteractiveElement, Styled, Subscription, Window, | |
| 34 | + KeyDownEvent, Keystroke, Modifiers, MouseButton, ObjectFit, ParentElement, PlatformInput, | |
| 35 | + RenderImage, StatefulInteractiveElement, Styled, StyledImage, Subscription, Window, | |
| 24 | 36 | assets::IconName, |
| 25 | 37 | component::{ |
| 26 | 38 | WindowExt, |
| 27 | 39 | popover::Popover, |
| 28 | 40 | slider::{SliderEvent, SliderState}, |
| 29 | 41 | }, |
| 30 | - div, | |
| 42 | + div, img, | |
| 31 | 43 | prelude::FluentBuilder as _, |
| 32 | - px, | |
| 44 | + px, uniform_list, | |
| 33 | 45 | }; |
| 34 | 46 | |
| 35 | 47 | use super::{ |
| @@ -150,6 +162,65 @@ pub(super) struct Viewer { | ||
| 150 | 162 | _subscriptions: Vec<Subscription>, |
| 151 | 163 | } |
| 152 | 164 | |
| 165 | +impl Picker { | |
| 166 | + fn refresh(&mut self, sources: Vec<crate::share::Source>) -> Vec<Arc<RenderImage>> { | |
| 167 | + let mut dropped = Vec::new(); | |
| 168 | + let now = Instant::now(); | |
| 169 | + self.sources = sources | |
| 170 | + .into_iter() | |
| 171 | + .map(|source| { | |
| 172 | + if let Some(preview) = source.preview { | |
| 173 | + let image = Arc::new(RenderImage::new(vec![image::Frame::new(preview)])); | |
| 174 | + if let Some((_, old)) = self.previews.insert(source.target, (now, image)) { | |
| 175 | + dropped.push(old); | |
| 176 | + } | |
| 177 | + } | |
| 178 | + (source.target, source.name) | |
| 179 | + }) | |
| 180 | + .collect(); | |
| 181 | + let alive: Vec<Target> = self.sources.iter().map(|(target, _)| *target).collect(); | |
| 182 | + self.previews.retain(|target, (_, image)| { | |
| 183 | + let keep = alive.contains(target); | |
| 184 | + if !keep { | |
| 185 | + dropped.push(image.clone()); | |
| 186 | + } | |
| 187 | + keep | |
| 188 | + }); | |
| 189 | + dropped | |
| 190 | + } | |
| 191 | +} | |
| 192 | + | |
| 193 | +fn pick_tile( | |
| 194 | + index: usize, | |
| 195 | + target: Target, | |
| 196 | + name: String, | |
| 197 | + preview: Option<Arc<RenderImage>>, | |
| 198 | + entity: &Entity<Yumush>, | |
| 199 | + palette: Palette, | |
| 200 | +) -> impl IntoElement { | |
| 201 | + let entity = entity.clone(); | |
| 202 | + clickable(("share_target", index), palette, move |window, cx| { | |
| 203 | + window.close_dialog(cx); | |
| 204 | + entity.update(cx, |yumush, cx| yumush.share_to(Some(target), window, cx)); | |
| 205 | + }) | |
| 206 | + .flex_1() | |
| 207 | + .min_w_0() | |
| 208 | + .p(px(space::XS)) | |
| 209 | + .flex() | |
| 210 | + .flex_col() | |
| 211 | + .gap(px(space::XS)) | |
| 212 | + .rounded(px(radius::MD)) | |
| 213 | + .child( | |
| 214 | + div() | |
| 215 | + .h(px(size::THUMB)) | |
| 216 | + .rounded(px(radius::SM)) | |
| 217 | + .overflow_hidden() | |
| 218 | + .bg(palette.field) | |
| 219 | + .children(preview.map(|image| img(image).size_full().object_fit(ObjectFit::Contain))), | |
| 220 | + ) | |
| 221 | + .child(div().truncate().text_size(px(text::LABEL)).child(name)) | |
| 222 | +} | |
| 223 | + | |
| 153 | 224 | impl Yumush { |
| 154 | 225 | pub(super) fn load_shares(&self, community_id: Id, cx: &mut Context<Self>) { |
| 155 | 226 | let network = self.network.clone(); |
| @@ -167,55 +238,101 @@ impl Yumush { | ||
| 167 | 238 | } |
| 168 | 239 | |
| 169 | 240 | pub(super) fn toggle_share(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 170 | - if !self.network.sharing() | |
| 171 | - && let Some(targets) = crate::share::capture::targets() | |
| 172 | - { | |
| 173 | - self.pick_share(targets, window, cx); | |
| 241 | + if self.share_busy { | |
| 242 | + return; | |
| 243 | + } | |
| 244 | + if self.network.sharing() || !crate::share::capture::PICKS { | |
| 245 | + self.share_to(None, window, cx); | |
| 174 | 246 | return; |
| 175 | 247 | } |
| 176 | - self.share_to(None, window, cx); | |
| 248 | + self.pick_share(window, cx); | |
| 177 | 249 | } |
| 178 | 250 | |
| 179 | - fn pick_share( | |
| 180 | - &mut self, | |
| 181 | - targets: Vec<(Target, String)>, | |
| 182 | - window: &mut Window, | |
| 183 | - cx: &mut Context<Self>, | |
| 184 | - ) { | |
| 251 | + fn pick_share(&mut self, window: &mut Window, cx: &mut Context<Self>) { | |
| 185 | 252 | let entity = cx.entity(); |
| 186 | 253 | let palette = super::palette(cx); |
| 187 | - window.open_dialog(cx, move |dialog, _, _| { | |
| 188 | - let rows = targets.iter().enumerate().map(|(index, (target, name))| { | |
| 189 | - let target = *target; | |
| 254 | + let picker: Entity<Picker> = cx.new(|_| Picker::default()); | |
| 255 | + let weak = picker.downgrade(); | |
| 256 | + window.open_dialog(cx, move |dialog, _, cx| { | |
| 257 | + let rows = picker.read(cx).sources.len().div_ceil(PICK_COLUMNS); | |
| 258 | + let list = { | |
| 259 | + let picker = picker.clone(); | |
| 190 | 260 | let entity = entity.clone(); |
| 191 | - clickable(("share_target", index), palette, move |window, cx| { | |
| 192 | - window.close_dialog(cx); | |
| 193 | - entity.update(cx, |yumush, cx| yumush.share_to(Some(target), window, cx)); | |
| 261 | + uniform_list("share_targets", rows, move |range, _, cx| { | |
| 262 | + let picker = picker.read(cx); | |
| 263 | + range | |
| 264 | + .map(|row| { | |
| 265 | + let start = row * PICK_COLUMNS; | |
| 266 | + let end = (start + PICK_COLUMNS).min(picker.sources.len()); | |
| 267 | + let tiles = (start..end).map(|index| { | |
| 268 | + let (target, name) = &picker.sources[index]; | |
| 269 | + let preview = | |
| 270 | + picker.previews.get(target).map(|(_, image)| image.clone()); | |
| 271 | + pick_tile(index, *target, name.clone(), preview, &entity, palette) | |
| 272 | + }); | |
| 273 | + let fillers = (end..start + PICK_COLUMNS).map(|_| div().flex_1()); | |
| 274 | + div() | |
| 275 | + .h(px(PICK_ROW)) | |
| 276 | + .flex() | |
| 277 | + .gap(px(space::SM)) | |
| 278 | + .children(tiles) | |
| 279 | + .children(fillers) | |
| 280 | + }) | |
| 281 | + .collect() | |
| 194 | 282 | }) |
| 195 | - .h(px(size::CONTROL_SM)) | |
| 196 | - .px(px(space::SM)) | |
| 197 | - .flex() | |
| 198 | - .items_center() | |
| 199 | - .rounded(px(radius::MD)) | |
| 200 | - .child(div().flex_1().min_w_0().truncate().child(name.clone())) | |
| 201 | - }); | |
| 202 | - dialog.title(w().share_view.share).w(px(size::SHEET)).child( | |
| 203 | - div() | |
| 204 | - .id("share_targets") | |
| 205 | - .max_h(px(size::POPOVER)) | |
| 206 | - .flex() | |
| 207 | - .flex_col() | |
| 208 | - .gap(px(space::XXS)) | |
| 209 | - .overflow_y_scroll() | |
| 210 | - .children(rows), | |
| 211 | - ) | |
| 283 | + .h(px((rows as f32 * PICK_ROW).min(size::PAGE))) | |
| 284 | + }; | |
| 285 | + dialog | |
| 286 | + .title(w().share_view.share) | |
| 287 | + .w(px(size::PAGE)) | |
| 288 | + .child(list) | |
| 212 | 289 | }); |
| 290 | + cx.spawn_in(window, async move |_, cx| { | |
| 291 | + loop { | |
| 292 | + let Ok(ages) = weak.read_with(cx, |picker, _| { | |
| 293 | + picker | |
| 294 | + .previews | |
| 295 | + .iter() | |
| 296 | + .map(|(target, (taken, _))| (*target, *taken)) | |
| 297 | + .collect::<HashMap<_, _>>() | |
| 298 | + }) else { | |
| 299 | + return; | |
| 300 | + }; | |
| 301 | + let sources = cx | |
| 302 | + .background_executor() | |
| 303 | + .spawn(async move { | |
| 304 | + let stale = |target: Target| { | |
| 305 | + ages.get(&target) | |
| 306 | + .is_none_or(|taken| taken.elapsed() >= PREVIEW_AGE) | |
| 307 | + }; | |
| 308 | + crate::share::capture::targets(&stale).unwrap_or_default() | |
| 309 | + }) | |
| 310 | + .await; | |
| 311 | + let Some(picker) = weak.upgrade() else { | |
| 312 | + return; | |
| 313 | + }; | |
| 314 | + let alive = cx.update(|window, cx| { | |
| 315 | + let dropped = picker.update(cx, |picker, _| picker.refresh(sources)); | |
| 316 | + for image in dropped { | |
| 317 | + cx.drop_image(image, Some(window)); | |
| 318 | + } | |
| 319 | + window.refresh(); | |
| 320 | + }); | |
| 321 | + drop(picker); | |
| 322 | + if alive.is_err() { | |
| 323 | + return; | |
| 324 | + } | |
| 325 | + cx.background_executor().timer(PICK_REFRESH).await; | |
| 326 | + } | |
| 327 | + }) | |
| 328 | + .detach(); | |
| 213 | 329 | } |
| 214 | 330 | |
| 215 | 331 | fn share_to(&mut self, target: Option<Target>, window: &mut Window, cx: &mut Context<Self>) { |
| 216 | 332 | let network = self.network.clone(); |
| 217 | 333 | let sharing = network.sharing(); |
| 218 | 334 | let settings = self.settings.share.clone(); |
| 335 | + self.share_busy = true; | |
| 219 | 336 | |
| 220 | 337 | cx.spawn_in(window, async move |this, cx| { |
| 221 | 338 | if sharing { |
| @@ -223,7 +340,10 @@ impl Yumush { | ||
| 223 | 340 | } else if let Err(error) = network.start_share(&settings, target).await { |
| 224 | 341 | notify_error(&this, cx, error); |
| 225 | 342 | } |
| 226 | - let _ = this.update(cx, |_, cx| cx.notify()); | |
| 343 | + let _ = this.update(cx, |yumush, cx| { | |
| 344 | + yumush.share_busy = false; | |
| 345 | + cx.notify(); | |
| 346 | + }); | |
| 227 | 347 | }) |
| 228 | 348 | .detach(); |
| 229 | 349 | } |
crates/client/src/share/capture.rsmodified+3 -1
| @@ -73,7 +73,9 @@ impl Drop for Capture { | ||
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | -pub fn targets() -> Option<Vec<(super::Target, String)>> { | |
| 76 | +pub const PICKS: bool = false; | |
| 77 | + | |
| 78 | +pub fn targets(_: &dyn Fn(super::Target) -> bool) -> Option<Vec<super::Source>> { | |
| 77 | 79 | None |
| 78 | 80 | } |
| 79 | 81 |
crates/client/src/share/capture_windows.rsmodified+59 -25
| @@ -20,11 +20,13 @@ use windows_capture::{ | ||
| 20 | 20 | }; |
| 21 | 21 | |
| 22 | 22 | use super::{ |
| 23 | - Target, fake, | |
| 23 | + Source, Target, fake, | |
| 24 | 24 | frame::{BYTES_PER_PIXEL, DEFAULT_REFRESH, FRAME_QUEUE, Frame, Gpu, Release, take_gpu_failed}, |
| 25 | 25 | }; |
| 26 | 26 | |
| 27 | 27 | const IN_FLIGHT: usize = 3; |
| 28 | +const PREVIEW_WIDTH: u32 = 320; | |
| 29 | +const PREVIEW_BUDGET: std::time::Duration = std::time::Duration::from_millis(100); | |
| 28 | 30 | |
| 29 | 31 | pub struct Capture { |
| 30 | 32 | pub width: u32, |
| @@ -43,33 +45,65 @@ impl Drop for Capture { | ||
| 43 | 45 | } |
| 44 | 46 | } |
| 45 | 47 | |
| 46 | -pub fn targets() -> Option<Vec<(Target, String)>> { | |
| 47 | - let screens = Monitor::enumerate().unwrap_or_default(); | |
| 48 | +pub const PICKS: bool = true; | |
| 49 | + | |
| 50 | +pub fn targets(stale: &dyn Fn(Target) -> bool) -> Option<Vec<Source>> { | |
| 51 | + let started = Instant::now(); | |
| 52 | + let due = |target: Target| stale(target) && started.elapsed() < PREVIEW_BUDGET; | |
| 53 | + let screens = xcap::Monitor::all().unwrap_or_default(); | |
| 48 | 54 | let count = screens.len(); |
| 49 | - let screens = screens | |
| 50 | - .into_iter() | |
| 51 | - .enumerate() | |
| 52 | - .map(move |(index, monitor)| { | |
| 53 | - let name = if count > 1 { | |
| 54 | - w().capture_windows.screen_numbered(index + 1) | |
| 55 | - } else { | |
| 56 | - w().capture_windows.screen.into() | |
| 57 | - }; | |
| 58 | - (Target::Screen(monitor.as_raw_hmonitor() as usize), name) | |
| 55 | + let mut sources = Vec::new(); | |
| 56 | + for (index, monitor) in screens.into_iter().enumerate() { | |
| 57 | + let Ok(id) = monitor.id() else { | |
| 58 | + continue; | |
| 59 | + }; | |
| 60 | + let target = Target::Screen(raw(id)); | |
| 61 | + let name = if count > 1 { | |
| 62 | + w().capture_windows.screen_numbered(index + 1) | |
| 63 | + } else { | |
| 64 | + w().capture_windows.screen.into() | |
| 65 | + }; | |
| 66 | + let preview = due(target) | |
| 67 | + .then(|| monitor.capture_image().ok().map(shrink)) | |
| 68 | + .flatten(); | |
| 69 | + sources.push(Source { | |
| 70 | + target, | |
| 71 | + name, | |
| 72 | + preview, | |
| 59 | 73 | }); |
| 60 | - let me = std::process::id(); | |
| 61 | - let windows = Window::enumerate() | |
| 62 | - .unwrap_or_default() | |
| 63 | - .into_iter() | |
| 64 | - .filter(|window| window.process_id().is_ok_and(|id| id != me)) | |
| 65 | - .filter_map(|window| { | |
| 66 | - let title = window | |
| 67 | - .title() | |
| 68 | - .ok() | |
| 69 | - .filter(|title| !title.trim().is_empty())?; | |
| 70 | - Some((Target::Window(window.as_raw_hwnd() as usize), title)) | |
| 74 | + } | |
| 75 | + for window in xcap::Window::all().unwrap_or_default() { | |
| 76 | + let (Ok(id), Some(name)) = ( | |
| 77 | + window.id(), | |
| 78 | + window.title().ok().filter(|title| !title.trim().is_empty()), | |
| 79 | + ) else { | |
| 80 | + continue; | |
| 81 | + }; | |
| 82 | + let target = Target::Window(raw(id)); | |
| 83 | + let shown = !window.is_minimized().unwrap_or(true); | |
| 84 | + let preview = (shown && due(target)) | |
| 85 | + .then(|| window.capture_image().ok().map(shrink)) | |
| 86 | + .flatten(); | |
| 87 | + sources.push(Source { | |
| 88 | + target, | |
| 89 | + name, | |
| 90 | + preview, | |
| 71 | 91 | }); |
| 72 | - Some(screens.chain(windows).collect()) | |
| 92 | + } | |
| 93 | + Some(sources) | |
| 94 | +} | |
| 95 | + | |
| 96 | +fn raw(id: u32) -> usize { | |
| 97 | + id as i32 as isize as usize | |
| 98 | +} | |
| 99 | + | |
| 100 | +fn shrink(image: image::RgbaImage) -> image::RgbaImage { | |
| 101 | + let height = PREVIEW_WIDTH * image.height() / image.width().max(1); | |
| 102 | + let mut image = image::imageops::thumbnail(&image, PREVIEW_WIDTH, height.max(1)); | |
| 103 | + for pixel in image.pixels_mut() { | |
| 104 | + pixel.0.swap(0, 2); | |
| 105 | + } | |
| 106 | + image | |
| 73 | 107 | } |
| 74 | 108 | |
| 75 | 109 | pub async fn open(target: Option<Target>) -> Result<Capture, String> { |
crates/client/src/share/encode.rsmodified+30 -2
| @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicU8, AtomicU32, AtomicU64, Ordering}; | ||
| 3 | 3 | use std::sync::mpsc::{Receiver, Sender, SyncSender, sync_channel}; |
| 4 | 4 | use std::sync::{Arc, OnceLock}; |
| 5 | 5 | use std::thread; |
| 6 | -use std::time::Instant; | |
| 6 | +use std::time::{Duration, Instant}; | |
| 7 | 7 | |
| 8 | 8 | use common::share::{Codec, Layer}; |
| 9 | 9 | |
| @@ -14,6 +14,7 @@ const SOFTWARE: Codec = Codec::H264; | ||
| 14 | 14 | const DEFAULT_MAX_HEIGHT: u32 = 2160; |
| 15 | 15 | const KEYFRAME_SECONDS: u32 = 3600; |
| 16 | 16 | const SLACK_MS: u32 = 4; |
| 17 | +const RESIZE_SETTLE: Duration = Duration::from_millis(300); | |
| 17 | 18 | const OVERLOAD: f32 = 1.2; |
| 18 | 19 | const GAIN: f32 = 0.8; |
| 19 | 20 | const SETTLE_FRAMES: u32 = 4; |
| @@ -523,6 +524,7 @@ pub struct Encoders { | ||
| 523 | 524 | lanes: HashMap<Layer, Lane>, |
| 524 | 525 | scale: Arc<AtomicU32>, |
| 525 | 526 | budget: Arc<AtomicU64>, |
| 527 | + resized: Option<((u32, u32), Instant)>, | |
| 526 | 528 | } |
| 527 | 529 | |
| 528 | 530 | impl Encoders { |
| @@ -534,6 +536,7 @@ impl Encoders { | ||
| 534 | 536 | lanes: HashMap::new(), |
| 535 | 537 | scale: Arc::new(AtomicU32::new(1f32.to_bits())), |
| 536 | 538 | budget: Arc::new(AtomicU64::new(u64::MAX)), |
| 539 | + resized: None, | |
| 537 | 540 | } |
| 538 | 541 | } |
| 539 | 542 | |
| @@ -575,12 +578,37 @@ impl Encoders { | ||
| 575 | 578 | self.scale.store(scale.to_bits(), Ordering::Relaxed); |
| 576 | 579 | } |
| 577 | 580 | |
| 578 | - pub fn push(&self, frame: Arc<Frame>) { | |
| 581 | + pub fn push(&mut self, frame: Arc<Frame>) { | |
| 582 | + self.follow(frame.width, frame.height); | |
| 579 | 583 | for lane in self.lanes.values() { |
| 580 | 584 | let _ = lane.input.try_send(Arc::clone(&frame)); |
| 581 | 585 | } |
| 582 | 586 | } |
| 583 | 587 | |
| 588 | + fn follow(&mut self, width: u32, height: u32) { | |
| 589 | + let size = (width, height); | |
| 590 | + if size == (self.source_width, self.source_height) { | |
| 591 | + self.resized = None; | |
| 592 | + return; | |
| 593 | + } | |
| 594 | + let since = match self.resized { | |
| 595 | + Some((pending, since)) if pending == size => since, | |
| 596 | + _ => { | |
| 597 | + self.resized = Some((size, Instant::now())); | |
| 598 | + return; | |
| 599 | + } | |
| 600 | + }; | |
| 601 | + if since.elapsed() < RESIZE_SETTLE { | |
| 602 | + return; | |
| 603 | + } | |
| 604 | + tracing::info!(width, height, "share source resized"); | |
| 605 | + self.resized = None; | |
| 606 | + (self.source_width, self.source_height) = size; | |
| 607 | + let layers: Vec<Layer> = self.lanes.keys().copied().collect(); | |
| 608 | + self.lanes.clear(); | |
| 609 | + self.set_layers(&layers); | |
| 610 | + } | |
| 611 | + | |
| 584 | 612 | fn spawn(&self, layer: Layer) -> Lane { |
| 585 | 613 | let (width, height) = layer |
| 586 | 614 | .quality |
crates/client/src/share/mod.rsmodified+7 -1
| @@ -13,11 +13,17 @@ pub mod capture; | ||
| 13 | 13 | pub mod capture; |
| 14 | 14 | pub mod congestion; |
| 15 | 15 | |
| 16 | -#[derive(Clone, Copy, PartialEq, Eq, Debug)] | |
| 16 | +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] | |
| 17 | 17 | pub enum Target { |
| 18 | 18 | Screen(usize), |
| 19 | 19 | Window(usize), |
| 20 | 20 | } |
| 21 | + | |
| 22 | +pub struct Source { | |
| 23 | + pub target: Target, | |
| 24 | + pub name: String, | |
| 25 | + pub preview: Option<image::RgbaImage>, | |
| 26 | +} | |
| 21 | 27 | pub mod encode; |
| 22 | 28 | #[cfg(any(target_os = "linux", target_os = "windows"))] |
| 23 | 29 | pub mod fake; |
crates/client/src/share/session.rsmodified+1 -1
| @@ -419,7 +419,7 @@ fn feed( | ||
| 419 | 419 | && last.bgra == frame.bgra |
| 420 | 420 | && frame.timestamp_ms.saturating_sub(last.timestamp_ms) < 1000 |
| 421 | 421 | }); |
| 422 | - let encoders = lock(&encoders); | |
| 422 | + let mut encoders = lock(&encoders); | |
| 423 | 423 | if unchanged && !encoders.keyframe_pending() { |
| 424 | 424 | skipped += 1; |
| 425 | 425 | } else { |
crates/client/src/share/unsupported.rsmodified+3 -1
| @@ -17,7 +17,9 @@ pub mod capture { | ||
| 17 | 17 | pub frames: Receiver<Frame>, |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - pub fn targets() -> Option<Vec<(crate::share::Target, String)>> { | |
| 20 | + pub const PICKS: bool = false; | |
| 21 | + | |
| 22 | + pub fn targets(_: &dyn Fn(crate::share::Target) -> bool) -> Option<Vec<crate::share::Source>> { | |
| 21 | 23 | None |
| 22 | 24 | } |
| 23 | 25 |