pub trait Platform: 'static {
Show 99 methods
// Required methods
fn platform_info(&self) -> PlatformInfo;
fn background_executor(&self) -> BackgroundExecutor;
fn foreground_executor(&self) -> ForegroundExecutor;
fn text_system(&self) -> Arc<dyn PlatformTextSystem> ⓘ;
fn run(&self, on_finish_launching: Box<dyn FnOnce()>);
fn quit(&self);
fn restart(&self, binary_path: Option<PathBuf>, arguments: Vec<OsString>);
fn activate(&self, ignoring_other_apps: bool);
fn hide(&self);
fn hide_other_apps(&self);
fn unhide_other_apps(&self);
fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>;
fn primary_display(&self) -> Option<Rc<dyn PlatformDisplay>>;
fn active_window(&self) -> Option<AnyWindowHandle>;
fn open_window(
&self,
handle: AnyWindowHandle,
options: WindowParams,
) -> Result<Box<dyn PlatformWindow>, Error>;
fn window_appearance(&self) -> WindowAppearance;
fn open_url(&self, url: &str);
fn on_open_urls(&self, callback: Box<dyn FnMut(Vec<String>)>);
fn register_url_scheme(&self, url: &str) -> Task<Result<(), Error>> ⓘ;
fn prompt_for_paths(
&self,
options: PathPromptOptions,
) -> Receiver<Result<Option<Vec<PathBuf>>, Error>> ⓘ;
fn prompt_for_new_path(
&self,
directory: &Path,
suggested_name: Option<&str>,
) -> Receiver<Result<Option<PathBuf>, Error>> ⓘ;
fn can_select_mixed_files_and_dirs(&self) -> bool;
fn reveal_path(&self, path: &Path);
fn open_with_system(&self, path: &Path);
fn on_quit(&self, callback: Box<dyn FnMut() -> bool>);
fn on_reopen(&self, callback: Box<dyn FnMut()>);
fn set_menus(&self, menus: Vec<Menu>, keymap: &Keymap);
fn set_dock_menu(&self, menu: Vec<MenuItem>, keymap: &Keymap);
fn on_app_menu_action(
&self,
callback: Box<dyn FnMut(&(dyn Action + 'static))>,
);
fn on_will_open_app_menu(&self, callback: Box<dyn FnMut()>);
fn on_validate_app_menu_command(
&self,
callback: Box<dyn FnMut(&(dyn Action + 'static)) -> bool>,
);
fn prevent_idle_sleep(
&self,
reason: &str,
) -> Task<Result<ActivityGuard, Error>> ⓘ;
fn app_path(&self) -> Result<PathBuf, Error>;
fn path_for_auxiliary_executable(
&self,
name: &str,
) -> Result<PathBuf, Error>;
fn set_cursor_style(&self, style: CursorStyle);
fn should_auto_hide_scrollbars(&self) -> bool;
fn write_to_primary(&self, item: ClipboardItem);
fn write_to_clipboard(&self, item: ClipboardItem);
fn read_from_primary(&self) -> Option<ClipboardItem>;
fn read_from_clipboard(&self) -> Option<ClipboardItem>;
fn write_credentials(
&self,
url: &str,
username: &str,
password: &[u8],
) -> Task<Result<(), Error>> ⓘ;
fn read_credentials(
&self,
url: &str,
) -> Task<Result<Option<(String, Vec<u8>)>, Error>> ⓘ;
fn delete_credentials(&self, url: &str) -> Task<Result<(), Error>> ⓘ;
fn keyboard_layout(&self) -> Box<dyn PlatformKeyboardLayout>;
fn keyboard_mapper(&self) -> Rc<dyn PlatformKeyboardMapper>;
fn on_keyboard_layout_change(&self, callback: Box<dyn FnMut()>);
// Provided methods
fn window_stack(&self) -> Option<Vec<AnyWindowHandle>> { ... }
fn is_screen_capture_supported(&self) -> bool { ... }
fn screen_capture_sources(
&self,
) -> Receiver<Result<Vec<Rc<dyn ScreenCaptureSource>>, Error>> ⓘ { ... }
fn trim_renderer_caches(&self) { ... }
fn configure_gpu_resources(&self, _gpu: &GpuResourceBudget) { ... }
fn renderer_cache_stats(&self) -> RendererCacheStats { ... }
fn set_window_appearance(&self, _appearance: Option<WindowAppearance>) { ... }
fn get_menus(&self) -> Option<Vec<OwnedMenu>> { ... }
fn perform_dock_menu_action(&self, _action: usize) { ... }
fn add_recent_document(&self, _path: &Path) { ... }
fn update_jump_list(
&self,
_menus: Vec<MenuItem>,
_entries: Vec<SmallVec<[PathBuf; 2]>>,
) -> Vec<SmallVec<[PathBuf; 2]>> { ... }
fn thermal_state(&self) -> ThermalState { ... }
fn on_thermal_state_change(&self, _callback: Box<dyn FnMut()>) { ... }
fn power_mode(&self) -> PowerMode { ... }
fn on_power_mode_change(&self, _callback: Box<dyn FnMut()>) { ... }
fn compositor_name(&self) -> &'static str { ... }
fn set_tray_icon(&self, _icon: Option<&[u8]>) { ... }
fn set_tray_icon_rendering_mode(
&self,
_rendering_mode: TrayIconRenderingMode,
) { ... }
fn set_tray_menu(&self, _menu: Vec<TrayMenuItem>) { ... }
fn set_tray_tooltip(&self, _tooltip: &str) { ... }
fn set_tray_panel_mode(&self, _enabled: bool) { ... }
fn get_tray_icon_anchor(&self) -> Option<TrayAnchor> { ... }
fn get_tray_icon_bounds(&self) -> Option<Bounds<Pixels>> { ... }
fn on_tray_icon_event(&self, callback: Box<dyn FnMut(TrayIconEvent)>) { ... }
fn on_tray_icon_click_event(
&self,
_callback: Box<dyn FnMut(TrayIconClickEvent)>,
) { ... }
fn on_tray_menu_action(&self, _callback: Box<dyn FnMut(SharedString)>) { ... }
fn register_global_hotkey(
&self,
_id: u32,
_keystroke: &Keystroke,
) -> Result<(), Error> { ... }
fn unregister_global_hotkey(&self, _id: u32) { ... }
fn on_global_hotkey(&self, _callback: Box<dyn FnMut(u32)>) { ... }
fn focused_window_info(&self) -> Option<FocusedWindowInfo> { ... }
fn accessibility_status(&self) -> PermissionStatus { ... }
fn request_accessibility_permission(&self) -> PermissionRequestStatus { ... }
fn microphone_status(&self) -> PermissionStatus { ... }
fn request_microphone_permission(
&self,
callback: Box<dyn FnOnce(bool)>,
) -> PermissionRequestStatus { ... }
fn set_auto_launch(
&self,
_app_id: &str,
_enabled: bool,
) -> Result<(), Error> { ... }
fn is_auto_launch_enabled(&self, _app_id: &str) -> bool { ... }
fn show_notification(&self, _title: &str, _body: &str) -> Result<(), Error> { ... }
fn set_quit_mode(&self, _mode: QuitMode) { ... }
fn on_system_power_event(&self, _callback: Box<dyn FnMut(SystemPowerEvent)>) { ... }
fn start_power_save_blocker(
&self,
_kind: PowerSaveBlockerKind,
) -> Option<u32> { ... }
fn stop_power_save_blocker(&self, _id: u32) { ... }
fn system_idle_time(&self) -> Option<Duration> { ... }
fn network_status(&self) -> NetworkStatus { ... }
fn on_network_status_change(&self, _callback: Box<dyn FnMut(NetworkStatus)>) { ... }
fn on_media_key_event(&self, _callback: Box<dyn FnMut(MediaKeyEvent)>) { ... }
fn request_user_attention(&self, _attention_type: AttentionType) { ... }
fn cancel_user_attention(&self) { ... }
fn set_dock_badge(&self, _label: Option<&str>) { ... }
fn show_context_menu(
&self,
_position: Point<Pixels>,
_items: Vec<TrayMenuItem>,
_callback: Box<dyn FnMut(SharedString)>,
) { ... }
fn show_dialog(&self, _options: DialogOptions) -> Receiver<usize> ⓘ { ... }
fn os_info(&self) -> OsInfo { ... }
fn biometric_status(&self) -> BiometricStatus { ... }
fn authenticate_biometric(
&self,
_reason: &str,
callback: Box<dyn FnOnce(bool) + Send>,
) { ... }
}Expand description
Low-level operating-system integration contract implemented by GPUI backends.
Required Methods§
Sourcefn platform_info(&self) -> PlatformInfo
fn platform_info(&self) -> PlatformInfo
Returns the host operating system and application target.
fn background_executor(&self) -> BackgroundExecutor
fn foreground_executor(&self) -> ForegroundExecutor
fn text_system(&self) -> Arc<dyn PlatformTextSystem> ⓘ
fn run(&self, on_finish_launching: Box<dyn FnOnce()>)
fn quit(&self)
fn restart(&self, binary_path: Option<PathBuf>, arguments: Vec<OsString>)
fn activate(&self, ignoring_other_apps: bool)
fn hide(&self)
fn hide_other_apps(&self)
fn unhide_other_apps(&self)
fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>
fn primary_display(&self) -> Option<Rc<dyn PlatformDisplay>>
fn active_window(&self) -> Option<AnyWindowHandle>
fn open_window( &self, handle: AnyWindowHandle, options: WindowParams, ) -> Result<Box<dyn PlatformWindow>, Error>
Sourcefn window_appearance(&self) -> WindowAppearance
fn window_appearance(&self) -> WindowAppearance
Returns the appearance of the application’s windows.
fn open_url(&self, url: &str)
fn on_open_urls(&self, callback: Box<dyn FnMut(Vec<String>)>)
fn register_url_scheme(&self, url: &str) -> Task<Result<(), Error>> ⓘ
fn prompt_for_paths( &self, options: PathPromptOptions, ) -> Receiver<Result<Option<Vec<PathBuf>>, Error>> ⓘ
fn prompt_for_new_path( &self, directory: &Path, suggested_name: Option<&str>, ) -> Receiver<Result<Option<PathBuf>, Error>> ⓘ
fn can_select_mixed_files_and_dirs(&self) -> bool
fn reveal_path(&self, path: &Path)
fn open_with_system(&self, path: &Path)
fn on_quit(&self, callback: Box<dyn FnMut() -> bool>)
fn on_reopen(&self, callback: Box<dyn FnMut()>)
Sourcefn prevent_idle_sleep(&self, reason: &str) -> Task<Result<ActivityGuard, Error>> ⓘ
fn prevent_idle_sleep(&self, reason: &str) -> Task<Result<ActivityGuard, Error>> ⓘ
Prevents idle sleep while the returned guard is held.
Dropping the guard restores the previous sleep policy.
fn app_path(&self) -> Result<PathBuf, Error>
fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf, Error>
fn set_cursor_style(&self, style: CursorStyle)
fn should_auto_hide_scrollbars(&self) -> bool
fn write_to_primary(&self, item: ClipboardItem)
fn write_to_clipboard(&self, item: ClipboardItem)
fn read_from_primary(&self) -> Option<ClipboardItem>
fn read_from_clipboard(&self) -> Option<ClipboardItem>
fn write_credentials( &self, url: &str, username: &str, password: &[u8], ) -> Task<Result<(), Error>> ⓘ
fn read_credentials( &self, url: &str, ) -> Task<Result<Option<(String, Vec<u8>)>, Error>> ⓘ
fn delete_credentials(&self, url: &str) -> Task<Result<(), Error>> ⓘ
fn keyboard_layout(&self) -> Box<dyn PlatformKeyboardLayout>
fn keyboard_mapper(&self) -> Rc<dyn PlatformKeyboardMapper>
fn on_keyboard_layout_change(&self, callback: Box<dyn FnMut()>)
Provided Methods§
fn window_stack(&self) -> Option<Vec<AnyWindowHandle>>
fn is_screen_capture_supported(&self) -> bool
fn screen_capture_sources( &self, ) -> Receiver<Result<Vec<Rc<dyn ScreenCaptureSource>>, Error>> ⓘ
Sourcefn trim_renderer_caches(&self)
fn trim_renderer_caches(&self)
Drop any idle GPU buffers held by the renderer’s pools, retaining configuration. Default implementation is a no-op for platforms that do not maintain such pools.
Sourcefn configure_gpu_resources(&self, _gpu: &GpuResourceBudget)
fn configure_gpu_resources(&self, _gpu: &GpuResourceBudget)
Apply renderer GPU resource budgets. Default implementation is a no-op for platforms that do not expose configurable renderer pools.
Sourcefn renderer_cache_stats(&self) -> RendererCacheStats
fn renderer_cache_stats(&self) -> RendererCacheStats
Snapshot of the renderer’s pooled GPU resource usage. Default implementation reports an empty snapshot for platforms that do not maintain such pools.
Sourcefn set_window_appearance(&self, _appearance: Option<WindowAppearance>)
fn set_window_appearance(&self, _appearance: Option<WindowAppearance>)
Overrides the appearance (light/dark) applied to the app’s windows, independent
of the OS-wide setting. Pass None to clear the override and follow the system
again. The override is reflected by Platform::window_appearance.
On macOS this sets NSApplication.appearance so the native window chrome (the
window border and titlebar) of every window matches a dark app theme even when
the system is in light mode (or vice versa). Other backends store the override
for Platform::window_appearance without changing native chrome.
fn add_recent_document(&self, _path: &Path)
fn update_jump_list( &self, _menus: Vec<MenuItem>, _entries: Vec<SmallVec<[PathBuf; 2]>>, ) -> Vec<SmallVec<[PathBuf; 2]>>
fn thermal_state(&self) -> ThermalState
fn on_thermal_state_change(&self, _callback: Box<dyn FnMut()>)
Sourcefn power_mode(&self) -> PowerMode
fn power_mode(&self) -> PowerMode
Returns the operating system’s power mode, or PowerMode::Unknown
when the platform cannot determine it.
Sourcefn on_power_mode_change(&self, _callback: Box<dyn FnMut()>)
fn on_power_mode_change(&self, _callback: Box<dyn FnMut()>)
Registers a callback invoked when the reported power mode changes.
fn compositor_name(&self) -> &'static str
fn set_tray_icon(&self, _icon: Option<&[u8]>)
fn set_tray_icon_rendering_mode(&self, _rendering_mode: TrayIconRenderingMode)
fn set_tray_tooltip(&self, _tooltip: &str)
fn set_tray_panel_mode(&self, _enabled: bool)
fn get_tray_icon_anchor(&self) -> Option<TrayAnchor>
fn get_tray_icon_bounds(&self) -> Option<Bounds<Pixels>>
fn on_tray_icon_event(&self, callback: Box<dyn FnMut(TrayIconEvent)>)
fn on_tray_icon_click_event( &self, _callback: Box<dyn FnMut(TrayIconClickEvent)>, )
fn register_global_hotkey( &self, _id: u32, _keystroke: &Keystroke, ) -> Result<(), Error>
fn unregister_global_hotkey(&self, _id: u32)
fn on_global_hotkey(&self, _callback: Box<dyn FnMut(u32)>)
fn focused_window_info(&self) -> Option<FocusedWindowInfo>
fn accessibility_status(&self) -> PermissionStatus
fn request_accessibility_permission(&self) -> PermissionRequestStatus
fn microphone_status(&self) -> PermissionStatus
fn request_microphone_permission( &self, callback: Box<dyn FnOnce(bool)>, ) -> PermissionRequestStatus
fn set_auto_launch(&self, _app_id: &str, _enabled: bool) -> Result<(), Error>
fn is_auto_launch_enabled(&self, _app_id: &str) -> bool
fn show_notification(&self, _title: &str, _body: &str) -> Result<(), Error>
Sourcefn set_quit_mode(&self, _mode: QuitMode)
fn set_quit_mode(&self, _mode: QuitMode)
Receive the application’s configured QuitMode.
The core application state owns the actual lifecycle decision; platforms
only need this hook when quit mode carries a platform-visible side
effect (for example macOS ActivationPolicy). The default
implementation is a no-op.
fn on_system_power_event(&self, _callback: Box<dyn FnMut(SystemPowerEvent)>)
fn start_power_save_blocker(&self, _kind: PowerSaveBlockerKind) -> Option<u32>
fn stop_power_save_blocker(&self, _id: u32)
fn system_idle_time(&self) -> Option<Duration>
fn network_status(&self) -> NetworkStatus
fn on_network_status_change(&self, _callback: Box<dyn FnMut(NetworkStatus)>)
fn on_media_key_event(&self, _callback: Box<dyn FnMut(MediaKeyEvent)>)
fn request_user_attention(&self, _attention_type: AttentionType)
fn cancel_user_attention(&self)
fn set_dock_badge(&self, _label: Option<&str>)
fn show_dialog(&self, _options: DialogOptions) -> Receiver<usize> ⓘ
fn os_info(&self) -> OsInfo
fn biometric_status(&self) -> BiometricStatus
fn authenticate_biometric( &self, _reason: &str, callback: Box<dyn FnOnce(bool) + Send>, )
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".