Skip to main content

Crate gpui_platform

Crate gpui_platform 

Source
Expand description

Abstract platform traits shared by gpui and its platform backends.

This crate is the contract between the GPUI facade and the concrete platform implementations (gpui_macos, gpui_linux, gpui_windows, gpui_web). It depends only on gpui_types and other low-level leaf crates, never on gpui, so a backend can implement these traits without depending on the entire framework.

The gpui crate re-exports everything here, so consumers keep using gpui::PlatformKeyboardMapper and friends.

Re-exports§

pub use profiler::ForegroundRunnableCounter;
pub use profiler::foreground_runnable_counter;
pub use profiler::foreground_runnable_finished;
pub use queue::*;

Modules§

popup
Parent-anchored popup window options shared by gpui and its platform backends.
profiler
Profiler hooks used by the executor runtime.
queue

Structs§

A11yCallbacks
Callbacks for the accessibility adapter.
ActivityGuard
Keeps an operating system activity, such as an idle sleep inhibitor, alive until dropped.
Background
A background color, which can be either a solid color or a linear gradient.
BackgroundExecutor
A pointer to the executor that is currently running, for spawning background tasks.
Bounds
Represents a rectangular area in a 2D space with an origin point and a size.
BoundsRefinement
A refinable version of [#ident], see that documentation for details.
Capslock
The state of the capslock key at some point in time
ClipboardItem
A clipboard item that should be copied to the clipboard
ClipboardString
A clipboard item that should be copied to the clipboard
ContentMask
Indicates which region of the window is visible. Content falling outside of this mask will not be rendered. Currently, only rectangular content masks are supported, but we give the mask its own type to leave room to support more complex shapes in the future.
Corners
Represents the corners of a box in a 2D space, such as border radius.
CornersRefinement
A refinable version of [#ident], see that documentation for details.
DedicatedExecutor
A long-lived handle to one dedicated session: every future spawned on it runs on that session’s single thread, never on the background pool.
DevicePixels
Represents physical pixels on the display.
DispatchEventResult
DisplayId
An opaque identifier for a hardware display
DummyKeyboardMapper
A dummy implementation of the platform keyboard mapper
DynRendererFactory
A shared RendererFactory, which is also Debug because the window options it lives in are.
Edges
Represents the edges of a box in a 2D space, such as padding or margin.
EdgesRefinement
A refinable version of [#ident], see that documentation for details.
ExternalPaths
A collection of paths from the platform, such as from a file drop.
FallibleTask
A task that returns Option<T> instead of panicking when cancelled.
FileDragPaths
Paths handed to the platform for a native file drag. Directory metadata is provided by the caller to avoid querying it when the platform drag starts.
FnRendererFactory
The spelling for the common case: a closure is a factory.
ForegroundExecutor
A pointer to the executor that is currently running, for spawning tasks on the main thread.
GestureKinds
The gesture kinds a platform recognizes natively, rather than leaving to gpui core’s portable recognizers.
GestureTuning
Feel constants consumed by gesture recognizers. Provided on a best-effort basis, depending on each platform’s support, defaulting to GPUI’s own (iOS flavored) values
GpuAdapterInfo
One adapter an application can choose between.
GpuId
The identity of an adapter, for GpuPreference::Device.
GpuRank
The sort key for one adapter under a GpuPreference.
GpuSpecs
Information about the GPU GPUI is running on.
GraphicalEnvironment
The graphical session to connect to: the variables that locate its display server, as some process sees them.
GridLocation
A location in a grid layout.
Hsla
An HSLA color
Image
An image, with a format and certain bytes
ImageFormatIter
An iterator over the variants of ImageFormat
InvalidKeystrokeError
Error type for Keystroke::parse. This is used instead of anyhow::Error so that Zed can use markdown to display it.
KeyDownEvent
The key down event equivalent for the platform.
KeyUpEvent
The key up event equivalent for the platform.
KeybindingKeystroke
Represents a keystroke that can be used in keybindings and displayed to the user.
Keystroke
A keystroke and associated metadata generated by the platform
LinearColorStop
A color stop in a linear gradient.
LongPressEvent
A phased long-press gesture recognized from a touch.
Modifiers
The state of the modifier keys at some point in time
ModifiersChangedEvent
The modifiers changed event equivalent for the platform.
MouseDownEvent
A mouse down event from the platform
MouseExitEvent
A mouse exit event from the platform, generated when the mouse leaves the window.
MouseMoveEvent
A mouse move event from the platform.
MousePressureEvent
A mouse pressure event from the platform. Generated when a force-sensitive trackpad is pressed hard. Currently only implemented for macOS trackpads.
MouseUpEvent
A mouse up event from the platform
NullPlatformGestures
A no-op PlatformGestures implementation: no native recognizers and default tuning. Suitable for desktop platforms and tests.
PathPromptOptions
The options that can be configured for a file dialog prompt
Percentage
A type representing a percentage value.
PinchEvent
A pinch gesture event from the platform, generated when the user performs a pinch-to-zoom gesture (typically on a trackpad).
Pixels
Represents a length in pixels, the base unit of measurement in the UI framework.
PlatformFrameSignal
Preserves the first platform frame request time across coalesced notifications.
PlatformInputHandler
Handles text input from the platform’s IME system on behalf of a window.
PlatformMenu
A menu of the application, either a main menu or a submenu.
PlatformOsMenu
A menu managed by the operating system.
PlatformScheduler
A production implementation of Scheduler that wraps a [PlatformDispatcher].
Point
Describes a location in a 2D cartesian space.
PointRefinement
A refinable version of [#ident], see that documentation for details.
Radians
Represents an angle in Radians
Rems
Represents a length in rems, a unit based on the font-size of the window, which can be assigned with Window::set_rem_size.
RendererTarget
What a renderer is built against: the window’s handles, its geometry, and whatever the backend needs to add.
RequestFrameOptions
Rgba
An RGBA color
RunnableMeta
Metadata attached to runnables for debugging and profiling.
ScaledPixels
Represents scaled pixels that take into account the device’s scale factor.
SchedulerLocalExecutor
A !Send executor pinned to a single session. Tasks spawned on it run in order on whichever thread drains the dispatch destination supplied at construction time — typically the main thread for the default session, or a dedicated OS thread for sessions created by spawn_dedicated_thread.
Scope
Scope manages a set of tasks that are enqueued and waited on together. See BackgroundExecutor::scoped.
ScreenCaptureFrame
A frame of video captured from a screen.
ScrollWheelEvent
A mouse wheel event from the platform.
Shadow
SharedString
A shared string is an immutable string that can be cheaply cloned in GPUI tasks. Essentially an abstraction over an Arc<str> and &'static str, currently backed by a SmolStr.
Size
A structure representing a two-dimensional size with width and height in a given unit.
SizeRefinement
A refinable version of [#ident], see that documentation for details.
SourceMetadata
Metadata for a given screen capture source
StrikethroughStyle
The properties that can be applied to a strikethrough.
StrikethroughStyleRefinement
A refinable version of [#ident], see that documentation for details.
SystemNotification
A notification posted to the operating system’s notification center, rather than rendered as in-app UI.
SystemNotificationAction
A button offered on a SystemNotification.
SystemNotificationResponse
The user’s activation of a SystemNotification.
Task
Task is a primitive that allows work to happen in the background.
TextInputConfiguration
The configuration of a focused text region’s input session.
Tiling
A type to describe which sides of the window are currently tiled in some way
TitlebarOptions
The options that can be configured for a window’s titlebar
TouchDragEvent
A direct touch drag claimed by an element before touch input becomes a tap, long press, or scrolling gesture.
TouchEvent
A raw touch event from the platform.
TouchId
Identifies one touch (finger or stylus contact) for its lifetime, from TouchPhase::Started through TouchPhase::Ended or TouchPhase::Cancelled.
UTF16Selection
A struct representing a selection in a text buffer, in UTF16 characters. This is different from a range because the head may be before the tail.
UnderlineStyle
The properties that can be applied to an underline.
UnderlineStyleRefinement
A refinable version of [#ident], see that documentation for details.
WindowButtonLayout
Describes which WindowButtons appear on each side of the titlebar.
WindowControls
What window controls this platform supports
WindowId
A unique identifier for a window.
WindowInsets
Regions of a window that are obscured or reserved by the system.
WindowMetrics
The state a window is presenting, sampled once from its platform window.
WindowOptions
The variables that can be configured when creating a new window
WindowParams
The variables that can be configured when creating a new window
WindowingModes
The windowing modes a platform may start in or switch to.

Enums§

AbsoluteLength
Represents an absolute length in pixels or rems.
ActivationPolicy
Controls whether the application participates in the system’s foreground UI.
Anchor
Identifies a reference point on a 2D box, used to anchor positioned elements.
AppLifecyclePhase
The application’s lifecycle phase, as owned and reported by a mobile OS.
Autocapitalize
Automatic capitalization applied by software keyboards.
AvailableSpace
The space available for an element to be laid out in
Axis
Axis in a 2D cartesian space.
BackgroundTag
Identifies which kind of Background is being described.
ClipboardEntry
Either a ClipboardString or a ClipboardImage
ClipboardReadError
An error produced by Platform::read_from_clipboard_async.
ColorSpace
A color space for color interpolation.
CursorStyle
The style of the cursor (pointer)
Decorations
A type to describe how this window is currently configured
DefiniteLength
A non-auto length that can be defined in pixels, rems, or percent of parent.
ExternalDragPayload
Data offered to the platform when an internal drag leaves the window and is promoted to a native drag session.
FileDropEvent
A file drop event from the platform, generated when files are dragged and dropped onto the window.
FrameRequestSource
The source of a platform frame request’s timestamp.
GpuBackend
The graphics API a GpuAdapterInfo runs on, without naming wgpu.
GpuDeviceType
The class of adapter a GpuAdapterInfo describes, without naming wgpu.
GpuPreference
Which GPU an application prefers the renderer to run on.
GridPlacement
The placement of an item within a grid layout’s column or row.
ImageFormat
One of the editor’s supported image formats (e.g. PNG, JPEG) - used when dealing with images in the clipboard
Length
A length that can be defined in pixels, rems, percent of parent, or auto.
MouseButton
An enum representing the mouse button that was pressed.
NavigationDirection
A navigation direction, such as back or forward.
OsAction
An action that the operating system recognizes and can give specialized behavior to.
PermanentGpuId
The stable part of a GpuId. Every adapter enumerate_gpus reports carries one.
PlatformInput
An enum corresponding to all kinds of platform input events.
PlatformMenuItem
The different kinds of items that can be in a menu.
PressureStage
The stage of a pressure click event.
Priority
Task priority for background tasks.
PromptButton
Prompt Button
PromptLevel
The options that can be configured for a file dialog prompt What kind of prompt styling to show
ResizeEdge
Which part of the window to resize
ScrollDelta
The scroll delta for a scroll wheel event.
ScrollPhysics
How free scrolling decelerates after a fling.
SessionGpuId
The backend’s handle for an adapter in this session.
SystemMenuType
The type of a system-managed menu.
TextInputAction
The action a software keyboard advertises on its confirm (“enter”) key.
TextInputStateChange
A change in the state of the focused text input.
ThermalState
Thermal state of the system
TouchPhase
The phase of a touch motion event. Based on the winit enum of the same name.
WindowAppearance
The appearance of the window, as defined by the operating system.
WindowBackgroundAppearance
The appearance of the background of the window itself, when there is no content or the content is transparent.
WindowBounds
Represents the status of how a window should be opened.
WindowButton
A window control button type used in WindowButtonLayout.
WindowControlArea
A type of window control area that corresponds to the platform window.
WindowDecorations
A type to describe the appearance of a window
WindowKind
The kind of window to create
WindowVisibility
Whether the platform is presenting a window’s frames.
WindowingRequest
A display mode for [App::request_windowing] to switch to.

Constants§

DEFAULT_WINDOW_SIZE
Default window size used when no explicit size is provided.
KEYSTROKE_PARSE_EXPECTED_MESSAGE
Sentence explaining what keystroke parser expects, starting with “Expected …”
MAX_BUTTONS_PER_SIDE
Maximum number of WindowButtons per side in the titlebar.

Traits§

Along
A trait for accessing the given unit along a certain axis.
AsKeystroke
This is a helper trait so that we can simplify the implementation of some functions
Half
Provides a trait for types that can calculate half of their value.
HasRemSize
A source of the current rem size, used to convert Pixels to Rems.
IsZero
A trait for checking if a value is zero.
NativeSceneHooks
The platform’s native hooks, as a supertrait every PlatformRenderer has.
Platform
PlatformDisplay
A handle to a platform’s display, e.g. a monitor or laptop screen.
PlatformGestures
Platform gesture recognition services.
PlatformInputHandlerDelegate
The gpui-side implementation backing a PlatformInputHandler.
PlatformKeyboardLayout
A trait for platform-specific keyboard layouts
PlatformKeyboardMapper
A trait for platform-specific keyboard mappings
PlatformRenderer
What a window asks of whatever renders into it.
PlatformWindow
RendererFactory
Builds a window’s renderer from the surface the window has already made.
ScreenCaptureSource
A source of on-screen video content that can be captured.
ScreenCaptureStream
A video stream captured from a screen.

Functions§

auto
Returns a Length representing an automatic length.
black
Pure black in Hsla
blue
The color blue in Hsla
bounds
Create a bounds with the given origin and size
ceil_to_device_pixel
Rounds a logical coordinate up to a device pixel boundary.
checkerboard
Creates a checkerboard pattern background
custom_choice
Resolve a GpuPreference::Custom selector against the adapters that were enumerated.
floor_to_device_pixel
Rounds a logical coordinate down to a device pixel boundary.
green
The color green in Hsla
guess_compositor
Return which compositor we’re guessing we’ll use. Does not attempt to connect to the given compositor.
hash
Use a quick, non-cryptographically secure hash function to get an identifier from data
hsla
Construct an Hsla object from plain values
linear_color_stop
Creates a new linear color stop.
linear_gradient
Creates a LinearGradient background color.
opaque_grey
Opaque grey in Hsla, values will be clamped to the range [0, 1]
pattern_slash
Creates a hash pattern background
percentage
Generate a Radian from a percentage of a full circle.
phi
Returns the Golden Ratio, i.e. ~(1.0 + sqrt(5.0)) / 2.0.
point
Constructs a new Point<T> with the given x and y coordinates.
px
Constructs a Pixels value representing a length in pixels.
radians
Create a Radian from a raw value
rank
Rank one adapter under preference.
red
The color red in Hsla
relative
Constructs a DefiniteLength representing a relative fraction of a parent size.
rems
Constructs a Rems value representing a length in rems.
rgb
Convert an RGB hex color code number to a color type
rgba
Convert an RGBA hex color code number to Rgba
round_half_toward_zero
Rounds to the nearest integer with 0.5 ties toward zero.
round_half_toward_zero_f64
Rounds to the nearest integer with 0.5 ties toward zero.
round_stroke_to_device_pixel
Snaps a stroke width to at least one device pixel.
round_to_device_pixel
Rounds a logical coordinate to the nearest device pixel.
size
Constructs a new Size<T> with the provided width and height.
solid_background
Creates a solid background color.
swap_rgba_pa_to_bgra
Swap from RGBA with premultiplied alpha to BGRA
transparent_black
Transparent black in Hsla
transparent_white
Transparent white in Hsla
white
Pure white in Hsla
yellow
The color yellow in Hsla

Type Aliases§

DrawOrder
The order in which a primitive is painted within a frame.
MenuCommandId
Identifies a menu command whose action gpui will dispatch.
PlatformScreenCaptureFrame
The platform-specific representation of a captured frame.
RunnableVariant
Type alias for runnables with metadata. Previously an enum with a single variant, now simplified to a direct type alias.
TimerResolutionGuard