Skip to repository content347 lines · 10.3 KB · rust
tenant.openagents/omega
No repository description is available.
OpenAgents Git authority 2026-07-28T04:40:19.631Z Public web read
NIP-34 coordinate
30617:7649603503856e5148d571eac2766b288a8ff1e9e35d380337a1d2b0015b4f92:omegaMaintainersHidden in public view
References2 branches · 1 tag
Read-only clone
git clone https://openagents.com/git/tenant.openagents/omega.gitBrowse files
gpui.rs
1#![doc = include_str!("../README.md")]
2#![warn(missing_docs)]
3#![allow(clippy::type_complexity)] // Not useful, GPUI makes heavy use of callbacks
4#![allow(clippy::collapsible_else_if)] // False positives in platform specific code
5#![allow(unused_mut)] // False positives in platform specific code
6
7extern crate self as gpui;
8#[doc(hidden)]
9pub static GPUI_MANIFEST_DIR: &'static str = env!("CARGO_MANIFEST_DIR");
10#[macro_use]
11mod action;
12mod app;
13
14mod arena;
15mod asset_cache;
16mod assets;
17mod bounds_tree;
18mod color;
19/// The default colors used by GPUI.
20pub mod colors;
21mod element;
22mod elements;
23mod executor;
24mod platform_scheduler;
25pub(crate) use platform_scheduler::PlatformScheduler;
26mod geometry;
27mod gestures;
28mod global;
29mod input;
30mod inspector;
31mod interactive;
32mod key_dispatch;
33mod keymap;
34mod path_builder;
35mod platform;
36pub mod prelude;
37/// Profiling utilities for task, frame, and thread performance tracking.
38pub mod profiler;
39#[cfg(any(
40 test,
41 target_os = "windows",
42 target_os = "linux",
43 target_family = "wasm",
44 feature = "bench"
45))]
46#[expect(missing_docs)]
47pub mod queue;
48mod scene;
49mod shared_uri;
50mod style;
51mod styled;
52mod subscription;
53mod svg_renderer;
54mod tab_stop;
55mod taffy;
56#[cfg(any(test, feature = "test-support"))]
57pub mod test;
58mod text_system;
59mod util;
60mod view;
61mod window;
62
63#[cfg(any(test, feature = "test-support"))]
64pub use proptest;
65
66#[cfg(doc)]
67pub mod _accessibility;
68#[cfg(doc)]
69pub mod _ownership_and_data_flow;
70
71/// Do not touch, here be dragons for use by gpui_macros and such.
72#[doc(hidden)]
73pub mod private {
74 pub use anyhow;
75 pub use inventory;
76 pub use schemars;
77 pub use serde;
78 pub use serde_json;
79}
80
81mod seal {
82 /// A mechanism for restricting implementations of a trait to only those in GPUI.
83 /// See: <https://predr.ag/blog/definitive-guide-to-sealed-traits-in-rust/>
84 pub trait Sealed {}
85}
86
87pub use accesskit;
88pub use accesskit::Action as AccessibleAction;
89pub use accesskit::{Orientation, Role, Toggled};
90pub use action::*;
91pub use anyhow::Result;
92pub use app::*;
93pub(crate) use arena::*;
94pub use asset_cache::*;
95pub use assets::*;
96pub use color::*;
97pub use ctor::ctor;
98pub use element::*;
99pub use elements::*;
100pub use executor::*;
101pub use geometry::*;
102pub use gestures::*;
103pub use global::*;
104pub use gpui_macros::{
105 AppContext, IntoElement, Render, VisualContext, bench, property_test, register_action, test,
106};
107
108/// Defines a Criterion benchmark group for benchmarks annotated with [`gpui::bench`].
109///
110/// This mirrors `criterion::criterion_group!` so GPUI benchmark files can keep the
111/// same shape as ordinary Criterion benchmarks.
112///
113/// [`gpui::bench`]: crate::bench
114#[macro_export]
115macro_rules! bench_group {
116 ($($tokens:tt)*) => {
117 criterion::criterion_group!($($tokens)*);
118 };
119}
120
121/// Defines the entry point for GPUI Criterion benchmark groups.
122///
123/// This mirrors `criterion::criterion_main!` so GPUI benchmark files can keep the
124/// same shape as ordinary Criterion benchmarks.
125#[macro_export]
126macro_rules! bench_main {
127 ($($tokens:tt)*) => {
128 criterion::criterion_main!($($tokens)*);
129 };
130}
131pub use gpui_shared_string::*;
132pub use gpui_util::arc_cow::ArcCow;
133pub use http_client;
134pub use input::*;
135pub use inspector::*;
136pub use interactive::*;
137use key_dispatch::*;
138pub use keymap::*;
139pub use path_builder::*;
140pub use platform::*;
141pub use profiler::*;
142#[cfg(any(target_os = "windows", target_os = "linux", target_family = "wasm"))]
143pub use queue::{PriorityQueueReceiver, PriorityQueueSender};
144pub use refineable::*;
145pub use scene::*;
146pub use shared_uri::*;
147use std::{any::Any, future::Future};
148pub use style::*;
149pub use styled::*;
150pub use subscription::*;
151pub use svg_renderer::*;
152pub(crate) use tab_stop::*;
153use taffy::TaffyLayoutEngine;
154pub use taffy::{AvailableSpace, LayoutId};
155#[cfg(any(test, feature = "test-support"))]
156pub use test::*;
157pub use text_system::*;
158pub use util::{FutureExt, Timeout};
159pub use view::*;
160pub use window::*;
161
162pub use pollster::block_on;
163
164/// The context trait, allows the different contexts in GPUI to be used
165/// interchangeably for certain operations.
166pub trait AppContext {
167 /// Create a new entity in the app context.
168 #[expect(
169 clippy::wrong_self_convention,
170 reason = "`App::new` is an ubiquitous function for creating entities"
171 )]
172 fn new<T: 'static>(&mut self, build_entity: impl FnOnce(&mut Context<T>) -> T) -> Entity<T>;
173
174 /// Reserve a slot for a entity to be inserted later.
175 /// The returned [Reservation] allows you to obtain the [EntityId] for the future entity.
176 fn reserve_entity<T: 'static>(&mut self) -> Reservation<T>;
177
178 /// Insert a new entity in the app context based on a [Reservation] previously obtained from [`reserve_entity`].
179 ///
180 /// [`reserve_entity`]: Self::reserve_entity
181 fn insert_entity<T: 'static>(
182 &mut self,
183 reservation: Reservation<T>,
184 build_entity: impl FnOnce(&mut Context<T>) -> T,
185 ) -> Entity<T>;
186
187 /// Update a entity in the app context.
188 fn update_entity<T, R>(
189 &mut self,
190 handle: &Entity<T>,
191 update: impl FnOnce(&mut T, &mut Context<T>) -> R,
192 ) -> R
193 where
194 T: 'static;
195
196 /// Update a entity in the app context.
197 fn as_mut<'a, T>(&'a mut self, handle: &Entity<T>) -> GpuiBorrow<'a, T>
198 where
199 T: 'static;
200
201 /// Read a entity from the app context.
202 fn read_entity<T, R>(&self, handle: &Entity<T>, read: impl FnOnce(&T, &App) -> R) -> R
203 where
204 T: 'static;
205
206 /// Update a window for the given handle.
207 fn update_window<T, F>(&mut self, window: AnyWindowHandle, f: F) -> Result<T>
208 where
209 F: FnOnce(AnyView, &mut Window, &mut App) -> T;
210
211 /// Run `f` against the entity's *current* window — the most recently
212 /// rendered window that referenced the entity. Returns `None` if the
213 /// entity has no current window or that window is unavailable. See
214 /// [`App::with_window`] for the underlying lookup.
215 fn with_window<R>(
216 &mut self,
217 entity_id: EntityId,
218 f: impl FnOnce(&mut Window, &mut App) -> R,
219 ) -> Option<R>;
220
221 /// Read a window off of the application context.
222 fn read_window<T, R>(
223 &self,
224 window: &WindowHandle<T>,
225 read: impl FnOnce(Entity<T>, &App) -> R,
226 ) -> Result<R>
227 where
228 T: 'static;
229
230 /// Spawn a future on a background thread
231 fn background_spawn<R>(&self, future: impl Future<Output = R> + Send + 'static) -> Task<R>
232 where
233 R: Send + 'static;
234
235 /// Read a global from this app context
236 fn read_global<G, R>(&self, callback: impl FnOnce(&G, &App) -> R) -> R
237 where
238 G: Global;
239}
240
241/// Returned by [Context::reserve_entity] to later be passed to [Context::insert_entity].
242/// Allows you to obtain the [EntityId] for a entity before it is created.
243pub struct Reservation<T>(pub(crate) Slot<T>);
244
245impl<T: 'static> Reservation<T> {
246 /// Returns the [EntityId] that will be associated with the entity once it is inserted.
247 pub fn entity_id(&self) -> EntityId {
248 self.0.entity_id()
249 }
250}
251
252/// This trait is used for the different visual contexts in GPUI that
253/// require a window to be present.
254pub trait VisualContext: AppContext {
255 /// The result type for window operations.
256 type Result<T>;
257
258 /// Returns the handle of the window associated with this context.
259 fn window_handle(&self) -> AnyWindowHandle;
260
261 /// Update a view with the given callback
262 fn update_window_entity<T: 'static, R>(
263 &mut self,
264 entity: &Entity<T>,
265 update: impl FnOnce(&mut T, &mut Window, &mut Context<T>) -> R,
266 ) -> Self::Result<R>;
267
268 /// Create a new entity, with access to `Window`.
269 fn new_window_entity<T: 'static>(
270 &mut self,
271 build_entity: impl FnOnce(&mut Window, &mut Context<T>) -> T,
272 ) -> Self::Result<Entity<T>>;
273
274 /// Replace the root view of a window with a new view.
275 fn replace_root_view<V>(
276 &mut self,
277 build_view: impl FnOnce(&mut Window, &mut Context<V>) -> V,
278 ) -> Self::Result<Entity<V>>
279 where
280 V: 'static + Render;
281
282 /// Focus a entity in the window, if it implements the [`Focusable`] trait.
283 fn focus<V>(&mut self, entity: &Entity<V>) -> Self::Result<()>
284 where
285 V: Focusable;
286}
287
288/// A trait for tying together the types of a GPUI entity and the events it can
289/// emit.
290pub trait EventEmitter<E: Any>: 'static {}
291
292/// A helper trait for auto-implementing certain methods on contexts that
293/// can be used interchangeably.
294pub trait BorrowAppContext {
295 /// Set a global value on the context.
296 fn set_global<T: Global>(&mut self, global: T);
297 /// Updates the global state of the given type.
298 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
299 where
300 G: Global;
301 /// Updates the global state of the given type, creating a default if it didn't exist before.
302 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
303 where
304 G: Global + Default;
305}
306
307impl<C> BorrowAppContext for C
308where
309 C: std::borrow::BorrowMut<App>,
310{
311 fn set_global<G: Global>(&mut self, global: G) {
312 self.borrow_mut().set_global(global)
313 }
314
315 #[track_caller]
316 fn update_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
317 where
318 G: Global,
319 {
320 let mut global = self.borrow_mut().lease_global::<G>();
321 let result = f(&mut global, self);
322 self.borrow_mut().end_global_lease(global);
323 result
324 }
325
326 fn update_default_global<G, R>(&mut self, f: impl FnOnce(&mut G, &mut Self) -> R) -> R
327 where
328 G: Global + Default,
329 {
330 self.borrow_mut().default_global::<G>();
331 self.update_global(f)
332 }
333}
334
335/// Information about the GPU GPUI is running on.
336#[derive(Default, Debug, serde::Serialize, serde::Deserialize, Clone)]
337pub struct GpuSpecs {
338 /// Whether the GPU is really a fake (like `llvmpipe`) running on the CPU.
339 pub is_software_emulated: bool,
340 /// The name of the device, as reported by Vulkan.
341 pub device_name: String,
342 /// The name of the driver, as reported by Vulkan.
343 pub driver_name: String,
344 /// Further information about the driver, as reported by Vulkan.
345 pub driver_info: String,
346}
347