Skip to main content

Platform

Trait Platform 

Source
pub trait Platform: 'static {
Show 72 methods // Required methods 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() + 'static>); 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<WindowId>; fn open_window( &self, handle: WindowId, options: WindowParams, ) -> Result<Box<dyn PlatformWindow>>; 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<()>> ⓘ; fn prompt_for_paths( &self, options: PathPromptOptions, ) -> Receiver<Result<Option<Vec<PathBuf>>>> ⓘ; fn prompt_for_new_path( &self, directory: &Path, suggested_name: Option<&str>, ) -> Receiver<Result<Option<PathBuf>>> ⓘ; 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 on_system_sleep(&self, callback: Box<dyn FnMut()>); fn on_system_wake(&self, callback: Box<dyn FnMut()>); fn set_menus(&self, menus: Vec<PlatformMenu>); fn set_dock_menu(&self, menu: Vec<PlatformMenuItem>); fn on_app_menu_action(&self, callback: Box<dyn FnMut(MenuCommandId)>); fn on_will_open_app_menu(&self, callback: Box<dyn FnMut()>); fn on_validate_app_menu_command( &self, callback: Box<dyn FnMut(MenuCommandId) -> bool>, ); fn thermal_state(&self) -> ThermalState; fn on_thermal_state_change(&self, callback: Box<dyn FnMut()>); fn prevent_idle_sleep(&self, reason: &str) -> Task<Result<ActivityGuard>> ⓘ; fn app_path(&self) -> Result<PathBuf>; fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf>; fn set_cursor_style(&self, style: CursorStyle); fn hide_cursor_until_mouse_moves(&self); fn is_cursor_visible(&self) -> bool; fn should_auto_hide_scrollbars(&self) -> bool; fn read_from_clipboard(&self) -> Option<ClipboardItem>; fn write_to_clipboard(&self, item: ClipboardItem); fn read_from_primary(&self) -> Option<ClipboardItem>; fn write_to_primary(&self, item: ClipboardItem); fn write_credentials( &self, url: &str, username: &str, password: &[u8], ) -> Task<Result<()>> ⓘ; fn read_credentials( &self, url: &str, ) -> Task<Result<Option<(String, Vec<u8>)>>> ⓘ; fn delete_credentials(&self, url: &str) -> Task<Result<()>> ⓘ; 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<WindowId>> { ... } fn is_screen_capture_supported(&self) -> bool { ... } fn screen_capture_sources( &self, ) -> Receiver<Result<Vec<Rc<dyn ScreenCaptureSource>>>> ⓘ { ... } fn set_window_appearance(&self, _appearance: Option<WindowAppearance>) { ... } fn set_gpu_preference(&self, _preference: GpuPreference) { ... } fn enumerate_gpus(&self) -> Vec<GpuAdapterInfo> { ... } fn dmabuf_capabilities(&self) -> Option<DmaBufCapabilities> { ... } fn active_gpu(&self) -> Option<GpuAdapterInfo> { ... } fn button_layout(&self) -> Option<WindowButtonLayout> { ... } fn on_app_lifecycle(&self, _callback: Box<dyn FnMut(AppLifecyclePhase)>) { ... } fn on_memory_warning(&self, _callback: Box<dyn FnMut()>) { ... } fn gestures(&self) -> Option<Rc<dyn PlatformGestures>> { ... } fn perform_dock_menu_action(&self, _action: usize) { ... } fn add_recent_document(&self, _path: &Path) { ... } fn update_jump_list( &self, _menus: Vec<PlatformMenuItem>, _entries: Vec<SmallVec<[PathBuf; 2]>>, ) -> Task<Vec<SmallVec<[PathBuf; 2]>>> ⓘ { ... } fn set_app_identity(&self, identifier: &str, name: &str) { ... } fn show_system_notification(&self, notification: SystemNotification) { ... } fn dismiss_system_notification(&self, tag: &str) { ... } fn on_system_notification_response( &self, callback: Box<dyn FnMut(SystemNotificationResponse)>, ) { ... } fn compositor_name(&self) -> &'static str { ... } fn read_from_clipboard_async( &self, ) -> Task<Result<Option<ClipboardItem>, ClipboardReadError>> ⓘ { ... }
}

Required Methods§

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() + 'static>)

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<WindowId>

Source

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

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<()>> ⓘ

Source

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

Source

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

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 on_system_sleep(&self, callback: Box<dyn FnMut()>)

Registers the callback invoked when the system is about to sleep.

Source

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

Registers the callback invoked when the system resumes from sleep.

Source

fn set_menus(&self, menus: Vec<PlatformMenu>)

Source

fn set_dock_menu(&self, menu: Vec<PlatformMenuItem>)

Source

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

Source

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

Source

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

Source

fn thermal_state(&self) -> ThermalState

Source

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

Source

fn prevent_idle_sleep(&self, reason: &str) -> Task<Result<ActivityGuard>> ⓘ

Source

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

Source

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

Source

fn set_cursor_style(&self, style: CursorStyle)

Source

fn hide_cursor_until_mouse_moves(&self)

Hides the mouse cursor until the user moves the mouse over one of this application’s windows.

Source

fn is_cursor_visible(&self) -> bool

Returns whether the mouse cursor is currently visible.

Source

fn should_auto_hide_scrollbars(&self) -> bool

Source

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

Source

fn write_to_clipboard(&self, item: ClipboardItem)

Source

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

Source

fn write_to_primary(&self, item: ClipboardItem)

Source

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

Source

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

Source

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

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<WindowId>>

Source

fn is_screen_capture_supported(&self) -> bool

Source

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

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.

Currently only implemented on macOS, where it 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). A no-op on other platforms.

Source

fn set_gpu_preference(&self, _preference: GpuPreference)

States which GPU the application prefers the renderer to run on.

The device is process-wide and chosen before the first window, so this has to be set before the application runs. A backend that cannot choose ignores it. See decision 0008 in the project record, decisions/0008-gpu-preference-and-enumeration.md.

Source

fn enumerate_gpus(&self) -> Vec<GpuAdapterInfo>

The adapters the application could render on.

Enumeration happens without creating a device, so this is safe to call before run and is what a preferences panel reads; it is also the list a GpuPreference::Custom selector chooses from. The order is the platform’s; a caller that wants a particular one states a preference rather than indexing into this list.

A backend that cannot enumerate returns one synthesized entry rather than an empty list: the identity contract is that every reported adapter has a permanent part and a session, and a single-GPU platform should still answer “which GPU” with “the GPU”.

Source

fn dmabuf_capabilities(&self) -> Option<DmaBufCapabilities>

What the renderer can import as a dma-buf surface, once it has a device.

Answered on the device the renderer already made — no device is created — and None before the first window or on a platform whose surfaces are not dma-bufs. A producer uses it to choose a layout rather than discover a refusal at import time.

Source

fn active_gpu(&self) -> Option<GpuAdapterInfo>

The adapter the renderer actually chose, once it has chosen one.

The device is process-wide and selected before the first window, so the answer is None until a window has created one; after that it is the adapter every window draws through. A platform that cannot report it returns None.

Source

fn button_layout(&self) -> Option<WindowButtonLayout>

Returns the window button layout configuration when supported.

Source

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

Registers a callback invoked whenever the application’s lifecycle phase changes. See AppLifecyclePhase for the phase vocabulary and its mapping onto iOS and Android.

Desktop platforms never invoke this.

Source

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

Registers a callback invoked when the OS signals memory pressure (iOS didReceiveMemoryWarning, Android onTrimMemory).

Desktop platforms never invoke this.

Source

fn gestures(&self) -> Option<Rc<dyn PlatformGestures>>

The platform’s gesture recognition services, if it provides any beyond gpui’s portable recognizers. See PlatformGestures.

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<PlatformMenuItem>, _entries: Vec<SmallVec<[PathBuf; 2]>>, ) -> Task<Vec<SmallVec<[PathBuf; 2]>>> ⓘ

Source

fn set_app_identity(&self, identifier: &str, name: &str)

Sets the application’s process-wide identity and user-visible name.

The identifier is used for platform identity mechanisms such as the Windows AppUserModelID. The name is used wherever the operating system presents the application to the user. Call this once, early in startup, before opening windows or posting notifications.

Source

fn show_system_notification(&self, notification: SystemNotification)

Posts a notification to the operating system’s notification center.

Posting a notification whose SystemNotification::tag matches an earlier one replaces that notification where the platform supports it. No-op on platforms without notification support, or when delivery is unavailable (e.g. authorization was denied).

Source

fn dismiss_system_notification(&self, tag: &str)

Removes the delivered or pending notification with this tag.

Best-effort: some platforms cannot retract a notification once shown, in which case it ages out of the notification center on its own.

Source

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

Registers the callback invoked when the user activates a system notification, either by clicking its body or one of its action buttons.

Implementations must invoke the callback on the main thread.

Source

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

Source

fn read_from_clipboard_async( &self, ) -> Task<Result<Option<ClipboardItem>, ClipboardReadError>> ⓘ

Reads the clipboard, resolving once its contents are available.

Most platforms read synchronously and return a ready task. Platforms whose clipboard access is inherently asynchronous and permission-gated (e.g. the browser’s async clipboard API) override this method; on those platforms Platform::read_from_clipboard cannot return the clipboard contents, so callers that can await should prefer this method.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§