forge
Explore
Log in

Don't you dare go Hollow

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 commit

38b4cd2b4197ffa3eb48fcbe008fe2f2640bc9f4Ahmet Kaan GümüşParent: 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
Show full message
✨ 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
Cargo.lockmodified+213 -2
@@ -400,8 +400,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
400400 checksum = "b60a01f4fbcba6a522ec4d285893bd0ce36f5987a8b3bf636e6aeb2d2acdf8ac"
401401 dependencies = [
402402 "bitflags 2.13.2",
403+ "futures-channel",
403404 "futures-util",
404405 "getrandom 0.4.3",
406+ "pipewire",
405407 "serde",
406408 "serde_repr",
407409 "tokio",
@@ -1314,6 +1316,7 @@ dependencies = [
13141316 "wasapi",
13151317 "windows-capture 2.0.1",
13161318 "winreg",
1319+ "xcap",
13171320 ]
13181321
13191322 [[package]]
@@ -2029,6 +2032,7 @@ checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38"
20292032 dependencies = [
20302033 "bitflags 2.13.2",
20312034 "block2 0.6.2",
2035+ "libc",
20322036 "objc2 0.6.5",
20332037 ]
20342038
@@ -2073,6 +2077,61 @@ version = "0.1.2"
20732077 source = "registry+https://github.com/rust-lang/crates.io-index"
20742078 checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
20752079
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+
20762135 [[package]]
20772136 name = "dunce"
20782137 version = "1.0.5"
@@ -3006,6 +3065,30 @@ dependencies = [
30063065 "slab",
30073066 ]
30083067
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+
30093092 [[package]]
30103093 name = "generator"
30113094 version = "0.8.12"
@@ -3117,6 +3200,15 @@ version = "0.34.0"
31173200 source = "registry+https://github.com/rust-lang/crates.io-index"
31183201 checksum = "1033caf0b349c518623b5396bfb2cf0bddf44f0306d543a250e5743297aafd10"
31193202
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+
31203212 [[package]]
31213213 name = "gl_generator"
31223214 version = "0.14.0"
@@ -3343,7 +3435,7 @@ dependencies = [
33433435 "parking",
33443436 "parking_lot",
33453437 "pin-project",
3346- "pollster",
3438+ "pollster 0.4.0",
33473439 "profiling",
33483440 "rand 0.9.5",
33493441 "raw-window-handle",
@@ -3699,7 +3791,7 @@ dependencies = [
36993791 "parking",
37003792 "parking_lot",
37013793 "pin-project",
3702- "pollster",
3794+ "pollster 0.4.0",
37033795 "profiling",
37043796 "rand 0.9.5",
37053797 "raw-window-handle",
@@ -5229,6 +5321,27 @@ dependencies = [
52295321 "system-deps",
52305322 ]
52315323
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+
52325345 [[package]]
52335346 name = "linebender_resource_handle"
52345347 version = "0.1.1"
@@ -5273,6 +5386,12 @@ version = "0.4.15"
52735386 source = "registry+https://github.com/rust-lang/crates.io-index"
52745387 checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
52755388
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+
52765395 [[package]]
52775396 name = "linux-raw-sys"
52785397 version = "0.12.1"
@@ -6216,6 +6335,7 @@ checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807"
62166335 dependencies = [
62176336 "bitflags 2.13.2",
62186337 "dispatch2",
6338+ "libc",
62196339 "objc2 0.6.5",
62206340 "objc2-core-foundation",
62216341 "objc2-io-surface",
@@ -6243,6 +6363,21 @@ dependencies = [
62436363 "objc2-foundation 0.3.2",
62446364 ]
62456365
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+
62466381 [[package]]
62476382 name = "objc2-core-services"
62486383 version = "0.3.2"
@@ -6383,6 +6518,22 @@ dependencies = [
63836518 "objc2-metal 0.3.2",
63846519 ]
63856520
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+
63866537 [[package]]
63876538 name = "objc2-security"
63886539 version = "0.3.2"
@@ -6897,6 +7048,12 @@ version = "0.4.0"
68977048 source = "registry+https://github.com/rust-lang/crates.io-index"
68987049 checksum = "2f3a9f18d041e6d0e102a0a46750538147e5e8992d3b4873aaafee2520b00ce3"
68997050
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+
69007057 [[package]]
69017058 name = "polycool"
69027059 version = "0.4.0"
@@ -10150,6 +10307,19 @@ dependencies = [
1015010307 "quote",
1015110308 ]
1015210309
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+
1015310323 [[package]]
1015410324 name = "wayland-sys"
1015510325 version = "0.31.11"
@@ -10157,7 +10327,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1015710327 checksum = "d8eab23fefc9e41f8e841df4a9c707e8a8c4ed26e944ef69297184de2785e3be"
1015810328 dependencies = [
1015910329 "dlib",
10330+ "libc",
1016010331 "log",
10332+ "memoffset",
1016110333 "once_cell",
1016210334 "pkg-config",
1016310335 ]
@@ -10420,6 +10592,12 @@ dependencies = [
1042010592 "safe_arch",
1042110593 ]
1042210594
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+
1042310601 [[package]]
1042410602 name = "winapi"
1042510603 version = "0.3.9"
@@ -11259,6 +11437,39 @@ dependencies = [
1125911437 "time",
1126011438 ]
1126111439
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+
1126211473 [[package]]
1126311474 name = "xcb"
1126411475 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
5454 [target.'cfg(target_os = "windows")'.dependencies]
5555 wasapi = "0.27.0"
5656 windows-capture = "2.0.1"
57+xcap = { version = "0.9.11", default-features = false }
5758 tray-icon = { version = "0.27.0", default-features = false }
5859 winreg = "0.56.0"
5960 sysinfo = { version = "0.40.4", default-features = false, features = ["system"] }
crates/client/src/gui.rsmodified+2 -0
@@ -625,6 +625,7 @@ pub struct Yumush {
625625 camera_modes: Vec<common::share::Mode>,
626626 camera_devices: Vec<String>,
627627 share_more: bool,
628+ share_busy: bool,
628629 fullscreen: bool,
629630 pumping: bool,
630631 pumped: Instant,
@@ -726,6 +727,7 @@ impl Yumush {
726727 camera_modes: Vec::new(),
727728 camera_devices: Vec::new(),
728729 share_more: false,
730+ share_busy: false,
729731 fullscreen: false,
730732 pumping: false,
731733 pumped: Instant::now(),
crates/client/src/gui/share_view.rsmodified+159 -39
@@ -1,5 +1,6 @@
11 use common::model::Id;
22 use std::{
3+ collections::HashMap,
34 sync::Arc,
45 time::{Duration, Instant},
56 };
@@ -12,6 +13,17 @@ use crate::share::Target;
1213 const FULL_VOLUME: f32 = 100.;
1314 const VOLUME_WIDTH: f32 = 80.;
1415 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+}
1527
1628 const TOP_QUALITY: Quality = Quality {
1729 resolution: Resolution::P2160,
@@ -19,17 +31,17 @@ const TOP_QUALITY: Quality = Quality {
1931 };
2032 use gpui_kit::{
2133 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,
2436 assets::IconName,
2537 component::{
2638 WindowExt,
2739 popover::Popover,
2840 slider::{SliderEvent, SliderState},
2941 },
30- div,
42+ div, img,
3143 prelude::FluentBuilder as _,
32- px,
44+ px, uniform_list,
3345 };
3446
3547 use super::{
@@ -150,6 +162,65 @@ pub(super) struct Viewer {
150162 _subscriptions: Vec<Subscription>,
151163 }
152164
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+
153224 impl Yumush {
154225 pub(super) fn load_shares(&self, community_id: Id, cx: &mut Context<Self>) {
155226 let network = self.network.clone();
@@ -167,55 +238,101 @@ impl Yumush {
167238 }
168239
169240 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);
174246 return;
175247 }
176- self.share_to(None, window, cx);
248+ self.pick_share(window, cx);
177249 }
178250
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>) {
185252 let entity = cx.entity();
186253 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();
190260 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()
194282 })
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)
212289 });
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();
213329 }
214330
215331 fn share_to(&mut self, target: Option<Target>, window: &mut Window, cx: &mut Context<Self>) {
216332 let network = self.network.clone();
217333 let sharing = network.sharing();
218334 let settings = self.settings.share.clone();
335+ self.share_busy = true;
219336
220337 cx.spawn_in(window, async move |this, cx| {
221338 if sharing {
@@ -223,7 +340,10 @@ impl Yumush {
223340 } else if let Err(error) = network.start_share(&settings, target).await {
224341 notify_error(&this, cx, error);
225342 }
226- let _ = this.update(cx, |_, cx| cx.notify());
343+ let _ = this.update(cx, |yumush, cx| {
344+ yumush.share_busy = false;
345+ cx.notify();
346+ });
227347 })
228348 .detach();
229349 }
crates/client/src/share/capture.rsmodified+3 -1
@@ -73,7 +73,9 @@ impl Drop for Capture {
7373 }
7474 }
7575
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>> {
7779 None
7880 }
7981
crates/client/src/share/capture_windows.rsmodified+59 -25
@@ -20,11 +20,13 @@ use windows_capture::{
2020 };
2121
2222 use super::{
23- Target, fake,
23+ Source, Target, fake,
2424 frame::{BYTES_PER_PIXEL, DEFAULT_REFRESH, FRAME_QUEUE, Frame, Gpu, Release, take_gpu_failed},
2525 };
2626
2727 const IN_FLIGHT: usize = 3;
28+const PREVIEW_WIDTH: u32 = 320;
29+const PREVIEW_BUDGET: std::time::Duration = std::time::Duration::from_millis(100);
2830
2931 pub struct Capture {
3032 pub width: u32,
@@ -43,33 +45,65 @@ impl Drop for Capture {
4345 }
4446 }
4547
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();
4854 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,
5973 });
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,
7191 });
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
73107 }
74108
75109 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};
33 use std::sync::mpsc::{Receiver, Sender, SyncSender, sync_channel};
44 use std::sync::{Arc, OnceLock};
55 use std::thread;
6-use std::time::Instant;
6+use std::time::{Duration, Instant};
77
88 use common::share::{Codec, Layer};
99
@@ -14,6 +14,7 @@ const SOFTWARE: Codec = Codec::H264;
1414 const DEFAULT_MAX_HEIGHT: u32 = 2160;
1515 const KEYFRAME_SECONDS: u32 = 3600;
1616 const SLACK_MS: u32 = 4;
17+const RESIZE_SETTLE: Duration = Duration::from_millis(300);
1718 const OVERLOAD: f32 = 1.2;
1819 const GAIN: f32 = 0.8;
1920 const SETTLE_FRAMES: u32 = 4;
@@ -523,6 +524,7 @@ pub struct Encoders {
523524 lanes: HashMap<Layer, Lane>,
524525 scale: Arc<AtomicU32>,
525526 budget: Arc<AtomicU64>,
527+ resized: Option<((u32, u32), Instant)>,
526528 }
527529
528530 impl Encoders {
@@ -534,6 +536,7 @@ impl Encoders {
534536 lanes: HashMap::new(),
535537 scale: Arc::new(AtomicU32::new(1f32.to_bits())),
536538 budget: Arc::new(AtomicU64::new(u64::MAX)),
539+ resized: None,
537540 }
538541 }
539542
@@ -575,12 +578,37 @@ impl Encoders {
575578 self.scale.store(scale.to_bits(), Ordering::Relaxed);
576579 }
577580
578- pub fn push(&self, frame: Arc<Frame>) {
581+ pub fn push(&mut self, frame: Arc<Frame>) {
582+ self.follow(frame.width, frame.height);
579583 for lane in self.lanes.values() {
580584 let _ = lane.input.try_send(Arc::clone(&frame));
581585 }
582586 }
583587
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+
584612 fn spawn(&self, layer: Layer) -> Lane {
585613 let (width, height) = layer
586614 .quality
crates/client/src/share/mod.rsmodified+7 -1
@@ -13,11 +13,17 @@ pub mod capture;
1313 pub mod capture;
1414 pub mod congestion;
1515
16-#[derive(Clone, Copy, PartialEq, Eq, Debug)]
16+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
1717 pub enum Target {
1818 Screen(usize),
1919 Window(usize),
2020 }
21+
22+pub struct Source {
23+ pub target: Target,
24+ pub name: String,
25+ pub preview: Option<image::RgbaImage>,
26+}
2127 pub mod encode;
2228 #[cfg(any(target_os = "linux", target_os = "windows"))]
2329 pub mod fake;
crates/client/src/share/session.rsmodified+1 -1
@@ -419,7 +419,7 @@ fn feed(
419419 && last.bgra == frame.bgra
420420 && frame.timestamp_ms.saturating_sub(last.timestamp_ms) < 1000
421421 });
422- let encoders = lock(&encoders);
422+ let mut encoders = lock(&encoders);
423423 if unchanged && !encoders.keyframe_pending() {
424424 skipped += 1;
425425 } else {
crates/client/src/share/unsupported.rsmodified+3 -1
@@ -17,7 +17,9 @@ pub mod capture {
1717 pub frames: Receiver<Frame>,
1818 }
1919
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>> {
2123 None
2224 }
2325