-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy path11_content_picker.rs
More file actions
117 lines (103 loc) · 4.27 KB
/
Copy path11_content_picker.rs
File metadata and controls
117 lines (103 loc) · 4.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//! Content Sharing Picker Example
//!
//! Demonstrates the system UI for selecting content to share (macOS 14.0+).
//!
//! Run with: cargo run --example `11_content_picker` --features `macos_14_0`
#[cfg(not(feature = "macos_14_0"))]
fn main() {
eprintln!("This example requires the 'macos_14_0' feature flag.");
eprintln!("Run with: cargo run --example 11_content_picker --features macos_14_0");
}
#[cfg(feature = "macos_14_0")]
fn main() {
use screencapturekit::content_sharing_picker::{
SCContentSharingPickerConfiguration, SCContentSharingPickerMode,
};
println!("=== Content Sharing Picker Example (macOS 14.0+) ===\n");
// Create picker configuration
let mut config = SCContentSharingPickerConfiguration::new();
// Set allowed picker modes
config.set_allowed_picker_modes(&[
SCContentSharingPickerMode::SingleWindow,
SCContentSharingPickerMode::MultipleWindows,
SCContentSharingPickerMode::SingleDisplay,
SCContentSharingPickerMode::SingleApplication,
SCContentSharingPickerMode::MultipleApplications,
]);
println!("📋 Picker Configuration:");
println!(" Allowed modes: SingleWindow, MultipleWindows, SingleDisplay, SingleApplication, MultipleApplications");
println!(" Pointer: {:?}", config.as_ptr());
// Test configuration cloning
let config_clone = config.clone();
println!("\n📋 Configuration cloned:");
println!(" Original ptr: {:?}", config.as_ptr());
println!(" Clone ptr: {:?}", config_clone.as_ptr());
// Show available picker modes
println!("\n🎯 Available Picker Modes:");
println!(
" SingleWindow = {}",
SCContentSharingPickerMode::SingleWindow as i32
);
println!(
" MultipleWindows = {}",
SCContentSharingPickerMode::MultipleWindows as i32
);
println!(
" SingleDisplay = {}",
SCContentSharingPickerMode::SingleDisplay as i32
);
println!(
" SingleApplication = {}",
SCContentSharingPickerMode::SingleApplication as i32
);
println!(
" MultipleApplications = {}",
SCContentSharingPickerMode::MultipleApplications as i32
);
// Note: Actually showing the picker requires user interaction
// and is typically done in a GUI application context.
println!("\n⚠️ Note: The picker UI requires a GUI context to display.");
println!(" In a real application, call SCContentSharingPicker::show(&config)");
println!(" to present the system picker UI to the user.\n");
// Demonstrate the result types
println!("📦 Picker APIs:");
println!(" Main API:");
println!(" SCContentSharingPicker::pick(&config) -> SCPickerOutcome");
println!(" - SCPickerOutcome::Picked(result) // result.filter(), result.windows(), result.displays()");
println!(" - SCPickerOutcome::Cancelled");
println!(" - SCPickerOutcome::Error(message)");
println!();
println!(" Simple API:");
println!(" SCContentSharingPicker::pick_filter(&config) -> SCPickerFilterOutcome");
println!(" - SCPickerFilterOutcome::Filter(filter)");
println!(" - SCPickerFilterOutcome::Cancelled");
println!(" - SCPickerFilterOutcome::Error(message)");
// Example of how to use the picker (commented out as it needs GUI)
/*
use screencapturekit::content_sharing_picker::{
SCContentSharingPicker, SCPickerOutcome,
};
let result = SCContentSharingPicker::pick(&config);
match result {
SCPickerOutcome::Picked(result) => {
// Get filter + metadata
let filter = result.filter();
let (width, height) = result.pixel_size();
// Access picked content for custom filters
for window in result.windows() {
println!("Selected window: {:?}", window.title());
}
for display in result.displays() {
println!("Selected display: {:?}", display.display_id());
}
}
SCPickerOutcome::Cancelled => {
println!("User cancelled the picker");
}
SCPickerOutcome::Error(msg) => {
eprintln!("Picker error: {}", msg);
}
}
*/
println!("\n✅ Content sharing picker example completed!");
}