Skip to main content

Platform

Trait Platform 

Source
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§

Source

fn platform_info(&self) -> PlatformInfo

Returns the host operating system and application target.

Source

fn background_executor(&self) -> BackgroundExecutor

Source

fn foreground_executor(&self) -> ForegroundExecutor

Source

fn text_system(&self) -> Arc<dyn PlatformTextSystem> ⓘ

Source

fn run(&self, on_finish_launching: Box<dyn FnOnce()>)

Source

fn quit(&self)

Source

fn restart(&self, binary_path: Option<PathBuf>, arguments: Vec<OsString>)

Source

fn activate(&self, ignoring_other_apps: bool)

Source

fn hide(&self)

Source

fn hide_other_apps(&self)

Source

fn unhide_other_apps(&self)

Source

fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>

Source

fn primary_display(&self) -> Option<Rc<dyn PlatformDisplay>>

Source

fn active_window(&self) -> Option<AnyWindowHandle>

Source

fn open_window( &self, handle: AnyWindowHandle, options: WindowParams, ) -> Result<Box<dyn PlatformWindow>, Error>

Source

fn window_appearance(&self) -> WindowAppearance

Returns the appearance of the application’s windows.

Source

fn open_url(&self, url: &str)

Source

fn on_open_urls(&self, callback: Box<dyn FnMut(Vec<String>)>)

Source

fn register_url_scheme(&self, url: &str) -> Task<Result<(), Error>> ⓘ

Source

fn prompt_for_paths( &self, options: PathPromptOptions, ) -> Receiver<Result<Option<Vec<PathBuf>>, Error>> ⓘ

Source

fn prompt_for_new_path( &self, directory: &Path, suggested_name: Option<&str>, ) -> Receiver<Result<Option<PathBuf>, Error>> ⓘ

Source

fn can_select_mixed_files_and_dirs(&self) -> bool

Source

fn reveal_path(&self, path: &Path)

Source

fn open_with_system(&self, path: &Path)

Source

fn on_quit(&self, callback: Box<dyn FnMut() -> bool>)

Source

fn on_reopen(&self, callback: Box<dyn FnMut()>)

Source

fn set_menus(&self, menus: Vec<Menu>, keymap: &Keymap)

Source

fn set_dock_menu(&self, menu: Vec<MenuItem>, keymap: &Keymap)

Source

fn on_app_menu_action(&self, callback: Box<dyn FnMut(&(dyn Action + 'static))>)

Source

fn on_will_open_app_menu(&self, callback: Box<dyn FnMut()>)

Source

fn on_validate_app_menu_command( &self, callback: Box<dyn FnMut(&(dyn Action + 'static)) -> bool>, )

Source

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.

Source

fn app_path(&self) -> Result<PathBuf, Error>

Source

fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf, Error>

Source

fn set_cursor_style(&self, style: CursorStyle)

Source

fn should_auto_hide_scrollbars(&self) -> bool

Source

fn write_to_primary(&self, item: ClipboardItem)

Source

fn write_to_clipboard(&self, item: ClipboardItem)

Source

fn read_from_primary(&self) -> Option<ClipboardItem>

Source

fn read_from_clipboard(&self) -> Option<ClipboardItem>

Source

fn write_credentials( &self, url: &str, username: &str, password: &[u8], ) -> Task<Result<(), Error>> ⓘ

Source

fn read_credentials( &self, url: &str, ) -> Task<Result<Option<(String, Vec<u8>)>, Error>> ⓘ

Source

fn delete_credentials(&self, url: &str) -> Task<Result<(), Error>> ⓘ

Source

fn keyboard_layout(&self) -> Box<dyn PlatformKeyboardLayout>

Source

fn keyboard_mapper(&self) -> Rc<dyn PlatformKeyboardMapper>

Source

fn on_keyboard_layout_change(&self, callback: Box<dyn FnMut()>)

Provided Methods§

Source

fn window_stack(&self) -> Option<Vec<AnyWindowHandle>>

Source

fn is_screen_capture_supported(&self) -> bool

Source

fn screen_capture_sources( &self, ) -> Receiver<Result<Vec<Rc<dyn ScreenCaptureSource>>, Error>> ⓘ

Source

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.

Source

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.

Source

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.

Source

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.

Source

fn get_menus(&self) -> Option<Vec<OwnedMenu>>

Source

fn perform_dock_menu_action(&self, _action: usize)

Source

fn add_recent_document(&self, _path: &Path)

Source

fn update_jump_list( &self, _menus: Vec<MenuItem>, _entries: Vec<SmallVec<[PathBuf; 2]>>, ) -> Vec<SmallVec<[PathBuf; 2]>>

Source

fn thermal_state(&self) -> ThermalState

Source

fn on_thermal_state_change(&self, _callback: Box<dyn FnMut()>)

Source

fn power_mode(&self) -> PowerMode

Returns the operating system’s power mode, or PowerMode::Unknown when the platform cannot determine it.

Source

fn on_power_mode_change(&self, _callback: Box<dyn FnMut()>)

Registers a callback invoked when the reported power mode changes.

Source

fn compositor_name(&self) -> &'static str

Source

fn set_tray_icon(&self, _icon: Option<&[u8]>)

Source

fn set_tray_icon_rendering_mode(&self, _rendering_mode: TrayIconRenderingMode)

Source

fn set_tray_menu(&self, _menu: Vec<TrayMenuItem>)

Source

fn set_tray_tooltip(&self, _tooltip: &str)

Source

fn set_tray_panel_mode(&self, _enabled: bool)

Source

fn get_tray_icon_anchor(&self) -> Option<TrayAnchor>

Source

fn get_tray_icon_bounds(&self) -> Option<Bounds<Pixels>>

Source

fn on_tray_icon_event(&self, callback: Box<dyn FnMut(TrayIconEvent)>)

Source

fn on_tray_icon_click_event( &self, _callback: Box<dyn FnMut(TrayIconClickEvent)>, )

Source

fn on_tray_menu_action(&self, _callback: Box<dyn FnMut(SharedString)>)

Source

fn register_global_hotkey( &self, _id: u32, _keystroke: &Keystroke, ) -> Result<(), Error>

Source

fn unregister_global_hotkey(&self, _id: u32)

Source

fn on_global_hotkey(&self, _callback: Box<dyn FnMut(u32)>)

Source

fn focused_window_info(&self) -> Option<FocusedWindowInfo>

Source

fn accessibility_status(&self) -> PermissionStatus

Source

fn request_accessibility_permission(&self) -> PermissionRequestStatus

Source

fn microphone_status(&self) -> PermissionStatus

Source

fn request_microphone_permission( &self, callback: Box<dyn FnOnce(bool)>, ) -> PermissionRequestStatus

Source

fn set_auto_launch(&self, _app_id: &str, _enabled: bool) -> Result<(), Error>

Source

fn is_auto_launch_enabled(&self, _app_id: &str) -> bool

Source

fn show_notification(&self, _title: &str, _body: &str) -> Result<(), Error>

Source

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.

Source

fn on_system_power_event(&self, _callback: Box<dyn FnMut(SystemPowerEvent)>)

Source

fn start_power_save_blocker(&self, _kind: PowerSaveBlockerKind) -> Option<u32>

Source

fn stop_power_save_blocker(&self, _id: u32)

Source

fn system_idle_time(&self) -> Option<Duration>

Source

fn network_status(&self) -> NetworkStatus

Source

fn on_network_status_change(&self, _callback: Box<dyn FnMut(NetworkStatus)>)

Source

fn on_media_key_event(&self, _callback: Box<dyn FnMut(MediaKeyEvent)>)

Source

fn request_user_attention(&self, _attention_type: AttentionType)

Source

fn cancel_user_attention(&self)

Source

fn set_dock_badge(&self, _label: Option<&str>)

Source

fn show_context_menu( &self, _position: Point<Pixels>, _items: Vec<TrayMenuItem>, _callback: Box<dyn FnMut(SharedString)>, )

Source

fn show_dialog(&self, _options: DialogOptions) -> Receiver<usize> ⓘ

Source

fn os_info(&self) -> OsInfo

Source

fn biometric_status(&self) -> BiometricStatus

Source

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".

Implementors§