Skip to content

Commit 2f8015b

Browse files
committed
refactor: improve metal overlay UX and mic device API
- Widen menu and config menu for better readability - Add debug output when applying stream configuration - Simplify microphone_capture_device_id API to take &str directly - Add clear_microphone_capture_device_id() for reverting to default - Update examples to use set_ methods for mutations - Rename AsyncSCContentSharingPicker::pick to show for consistency
1 parent 0e5163f commit 2f8015b

4 files changed

Lines changed: 27 additions & 21 deletions

File tree

examples/01_basic_capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
7171
#[cfg(feature = "macos_15_0")]
7272
{
7373
// Show mouse click indicators (circle around cursor when clicking)
74-
config = config.with_shows_mouse_clicks(true);
74+
config.set_shows_mouse_clicks(true);
7575
println!("Mouse click indicators: enabled");
7676
}
7777

examples/08_async.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ async fn async_content_picker() -> Result<(), Box<dyn std::error::Error>> {
234234
let config = SCContentSharingPickerConfiguration::new();
235235

236236
// Async picker - doesn't block the executor thread
237-
match AsyncSCContentSharingPicker::pick(&config).await {
237+
match AsyncSCContentSharingPicker::show(&config).await {
238238
SCPickerOutcome::Picked(result) => {
239239
let (width, height) = result.pixel_size();
240240
let scale = result.scale();

examples/metal_overlay/main.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ impl VertexBufferBuilder {
776776
];
777777

778778
// Calculate box dimensions - wider menu
779-
let box_w = (280.0 * base_scale).min(viewport_w * 0.85);
779+
let box_w = (400.0 * base_scale).min(viewport_w * 0.85);
780780
let box_h = (line_h * (menu_items.len() as f32 + 3.5) + padding * 2.0).min(viewport_h * 0.6);
781781

782782
// Center the box
@@ -840,7 +840,7 @@ impl VertexBufferBuilder {
840840
let hint_color = [0.6, 0.6, 0.6, 1.0];
841841

842842
let option_count = StreamConfig::option_count();
843-
let box_w = (label_col_w + value_col_w + padding * 3.0).min(viewport_w * 0.6);
843+
let box_w = (350.0 * base_scale).min(viewport_w * 0.7);
844844
let box_h = (line_h * (option_count as f32 + 3.0) + padding * 2.0).min(viewport_h * 0.5);
845845

846846
let x = (viewport_w - box_w) / 2.0;
@@ -1275,9 +1275,12 @@ fn main() {
12751275
// Apply config to running stream
12761276
if capturing.load(Ordering::Relaxed) {
12771277
if let Some(ref s) = stream {
1278+
println!("📝 Applying config: FPS={}, Cursor={}, Audio={}, Mic={}",
1279+
stream_config.fps, stream_config.show_cursor,
1280+
stream_config.captures_audio, stream_config.captures_mic);
12781281
let new_config = stream_config.to_stream_config(capture_size.0, capture_size.1);
12791282
match s.update_configuration(&new_config) {
1280-
Ok(()) => println!("✅ Config updated"),
1283+
Ok(()) => println!("✅ Config updated successfully"),
12811284
Err(e) => eprintln!("❌ Config update failed: {:?}", e),
12821285
}
12831286
}

src/stream/configuration/audio.rs

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ impl SCStreamConfiguration {
197197

198198
/// Set microphone capture device ID (macOS 15.0+).
199199
///
200-
/// Specifies which microphone device to capture from. Use `None` for the
201-
/// default system microphone.
200+
/// Specifies which microphone device to capture from.
202201
///
203202
/// # Availability
204203
/// macOS 15.0+. On earlier versions, this setting has no effect.
@@ -207,23 +206,16 @@ impl SCStreamConfiguration {
207206
/// ```rust,no_run
208207
/// use screencapturekit::prelude::*;
209208
///
210-
/// let config = SCStreamConfiguration::new()
211-
/// .with_captures_microphone(true)
212-
/// .with_microphone_capture_device_id(Some("AppleHDAEngineInput:1B,0,1,0:1"));
209+
/// let mut config = SCStreamConfiguration::new()
210+
/// .with_captures_microphone(true);
211+
/// config.set_microphone_capture_device_id("AppleHDAEngineInput:1B,0,1,0:1");
213212
/// ```
214-
pub fn set_microphone_capture_device_id(&mut self, device_id: Option<&str>) -> &mut Self {
213+
pub fn set_microphone_capture_device_id(&mut self, device_id: &str) -> &mut Self {
215214
unsafe {
216-
if let Some(id) = device_id {
217-
if let Ok(c_id) = std::ffi::CString::new(id) {
218-
crate::ffi::sc_stream_configuration_set_microphone_capture_device_id(
219-
self.as_ptr(),
220-
c_id.as_ptr(),
221-
);
222-
}
223-
} else {
215+
if let Ok(c_id) = std::ffi::CString::new(device_id) {
224216
crate::ffi::sc_stream_configuration_set_microphone_capture_device_id(
225217
self.as_ptr(),
226-
std::ptr::null(),
218+
c_id.as_ptr(),
227219
);
228220
}
229221
}
@@ -232,11 +224,22 @@ impl SCStreamConfiguration {
232224

233225
/// Set microphone capture device ID (builder pattern)
234226
#[must_use]
235-
pub fn with_microphone_capture_device_id(mut self, device_id: Option<&str>) -> Self {
227+
pub fn with_microphone_capture_device_id(mut self, device_id: &str) -> Self {
236228
self.set_microphone_capture_device_id(device_id);
237229
self
238230
}
239231

232+
/// Clear microphone capture device ID, reverting to default system microphone
233+
pub fn clear_microphone_capture_device_id(&mut self) -> &mut Self {
234+
unsafe {
235+
crate::ffi::sc_stream_configuration_set_microphone_capture_device_id(
236+
self.as_ptr(),
237+
std::ptr::null(),
238+
);
239+
}
240+
self
241+
}
242+
240243
/// Get microphone capture device ID (macOS 15.0+).
241244
pub fn get_microphone_capture_device_id(&self) -> Option<String> {
242245
unsafe {

0 commit comments

Comments
 (0)