1#[cfg(all(target_os = "linux", feature = "wayland"))]
4use crate::layer_shell;
5use crate::{
6 Decorations, DispatchEventResult, ExternalDragPayload, GpuSpecs, PlatformDisplay,
7 PlatformInput, PlatformInputHandler, PromptButton, PromptLevel, RequestFrameOptions,
8 ResizeEdge, SystemWindowTab, TextInputConfiguration, TextInputStateChange, WindowAppearance,
9 WindowBackgroundAppearance, WindowBounds, WindowControlArea, WindowControls, WindowDecorations,
10 WindowInsets,
11};
12use futures::channel::oneshot;
13use gpui_engine::SceneRenderer;
14use gpui_types::{Bounds, Capslock, Modifiers, Pixels, Point, Size};
15use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
16#[cfg(any(test, feature = "test-support", feature = "bench-support"))]
17use std::any::Any;
18use std::rc::Rc;
19
20#[derive(Debug, Clone, Copy, PartialEq, Eq)]
41pub enum WindowVisibility {
42 Visible,
45 Hidden,
48}
49
50impl WindowVisibility {
51 pub fn is_visible(self) -> bool {
53 self == Self::Visible
54 }
55}
56
57pub struct A11yCallbacks {
59 pub activation: Box<dyn Fn() -> Option<accesskit::TreeUpdate> + Send + 'static>,
61 pub action: Box<dyn Fn(accesskit::ActionRequest) + Send + 'static>,
63 pub deactivation: Box<dyn Fn() + Send + 'static>,
65}
66
67#[expect(missing_docs)]
68pub trait PlatformWindow: HasWindowHandle + HasDisplayHandle {
69 fn bounds(&self) -> Bounds<Pixels>;
70 fn is_maximized(&self) -> bool;
71 fn window_bounds(&self) -> WindowBounds;
72 fn content_size(&self) -> Size<Pixels>;
73 fn visual_viewport_bounds(&self) -> Bounds<Pixels> {
79 Bounds::new(Point::default(), self.content_size())
80 }
81 fn on_visual_viewport_changed(&self, _callback: Box<dyn FnMut()>) {}
86 fn prepare_frame(&self) -> bool {
91 false
92 }
93 fn resize(&mut self, size: Size<Pixels>);
94 fn scale_factor(&self) -> f32;
95 fn appearance(&self) -> WindowAppearance;
96 fn display(&self) -> Option<Rc<dyn PlatformDisplay>>;
97 fn mouse_position(&self) -> Point<Pixels>;
98 fn modifiers(&self) -> Modifiers;
99 fn capslock(&self) -> Capslock;
100 fn set_input_handler(&mut self, input_handler: PlatformInputHandler);
101 fn take_input_handler(&mut self) -> Option<PlatformInputHandler>;
102 fn set_text_input_configuration(&mut self, _configuration: TextInputConfiguration) {}
107 fn prompt(
108 &self,
109 level: PromptLevel,
110 msg: &str,
111 detail: Option<&str>,
112 answers: &[PromptButton],
113 ) -> Option<oneshot::Receiver<usize>>;
114 fn activate(&self);
115 fn request_attention(&self) {}
117 fn is_active(&self) -> bool;
118 fn visibility(&self) -> WindowVisibility;
121 fn is_hovered(&self) -> bool;
122 fn background_appearance(&self) -> WindowBackgroundAppearance;
123 fn set_title(&mut self, title: &str);
124 fn set_background_appearance(&self, background_appearance: WindowBackgroundAppearance);
125 fn minimize(&self);
126 fn zoom(&self);
127 fn toggle_fullscreen(&self);
128 fn is_fullscreen(&self) -> bool;
129 fn frame_waker(&self) -> Option<Rc<dyn Fn()>> {
130 None
131 }
132 fn on_request_frame(&self, callback: Box<dyn FnMut(RequestFrameOptions)>);
133 fn on_input(&self, callback: Box<dyn FnMut(PlatformInput) -> DispatchEventResult>);
134 fn on_active_status_change(&self, callback: Box<dyn FnMut(bool)>);
135 fn on_visibility_change(&self, callback: Box<dyn FnMut(WindowVisibility)>);
139 fn on_hover_status_change(&self, callback: Box<dyn FnMut(bool)>);
140 fn on_resize(&self, callback: Box<dyn FnMut(Size<Pixels>, f32)>);
141 fn on_moved(&self, callback: Box<dyn FnMut()>);
142 fn on_display_changed(&self, callback: Box<dyn FnMut()>);
146 fn on_should_close(&self, callback: Box<dyn FnMut() -> bool>);
147 fn on_hit_test_window_control(&self, callback: Box<dyn FnMut() -> Option<WindowControlArea>>);
148 fn on_close(&self, callback: Box<dyn FnOnce()>);
149 fn on_appearance_changed(&self, callback: Box<dyn FnMut()>);
150 fn on_button_layout_changed(&self, _callback: Box<dyn FnMut()>) {}
151 fn with_renderer(&mut self, f: &mut dyn FnMut(&mut dyn SceneRenderer));
156 fn present(&mut self, f: &mut dyn FnMut(&mut dyn SceneRenderer) -> bool);
162 fn schedule_frame(&self) {}
163 fn is_subpixel_rendering_supported(&self) -> bool;
164
165 fn get_title(&self) -> String {
167 String::new()
168 }
169 fn tabbed_windows(&self) -> Option<Vec<SystemWindowTab>> {
170 None
171 }
172 fn tab_bar_visible(&self) -> bool {
173 false
174 }
175 fn set_edited(&mut self, _edited: bool) {}
176 fn set_document_path(&self, _path: Option<&std::path::Path>) {}
177 fn toggle_simple_fullscreen(&self) {}
178 fn is_simple_fullscreen(&self) -> bool {
179 false
180 }
181 #[cfg(target_os = "macos")]
182 fn set_traffic_light_position(&self, _position: Point<Pixels>) {}
183 fn show_character_palette(&self) {}
184 fn titlebar_double_click(&self, _is_resizable: bool, _is_minimizable: bool) {}
185 fn on_move_tab_to_new_window(&self, _callback: Box<dyn FnMut()>) {}
186 fn on_merge_all_windows(&self, _callback: Box<dyn FnMut()>) {}
187 fn on_select_previous_tab(&self, _callback: Box<dyn FnMut()>) {}
188 fn on_select_next_tab(&self, _callback: Box<dyn FnMut()>) {}
189 fn on_toggle_tab_bar(&self, _callback: Box<dyn FnMut()>) {}
190 fn merge_all_windows(&self) {}
191 fn move_tab_to_new_window(&self) {}
192 fn toggle_window_tab_overview(&self) {}
193 fn set_tabbing_identifier(&self, _identifier: Option<String>) {}
194
195 fn native_window_state(&self) -> Option<Vec<u8>> {
196 None
197 }
198 fn restore_native_window_state(&self, _state: &[u8]) {}
199
200 #[cfg(target_os = "windows")]
201 fn get_raw_handle(&self) -> windows::Win32::Foundation::HWND;
202
203 fn inner_window_bounds(&self) -> WindowBounds {
205 self.window_bounds()
206 }
207 fn request_decorations(&self, _decorations: WindowDecorations) {}
208 fn show_window_menu(&self, _position: Point<Pixels>) {}
209 fn start_window_move(&self) {}
210 fn can_start_external_drag(&self) -> bool {
211 false
212 }
213 fn start_external_drag(&self, _payload: &ExternalDragPayload) -> bool {
214 false
215 }
216 fn start_window_resize(&self, _edge: ResizeEdge) {}
217 fn set_exclusive_zone(&self, _zone: Pixels) {}
218 #[cfg(all(target_os = "linux", feature = "wayland"))]
219 fn set_exclusive_edge(&self, _edge: layer_shell::Anchor) {}
220 fn set_input_region(&self, _region: Option<&[Bounds<Pixels>]>) {}
221 fn window_decorations(&self) -> Decorations {
222 Decorations::Server
223 }
224 fn set_app_id(&mut self, _app_id: &str) {}
225 fn map_window(&mut self) -> anyhow::Result<()> {
226 Ok(())
227 }
228 fn window_controls(&self) -> WindowControls {
229 WindowControls::default()
230 }
231 fn set_client_inset(&self, _inset: Pixels) {}
232 fn gpu_specs(&self) -> Option<GpuSpecs>;
233
234 fn update_ime_position(&self, _bounds: Bounds<Pixels>);
235
236 fn insets(&self) -> WindowInsets {
241 WindowInsets::default()
242 }
243
244 fn on_insets_changed(&self, _callback: Box<dyn FnMut(WindowInsets)>) {}
250
251 fn set_back_handler(&self, _callback: Box<dyn FnMut()>) {}
254
255 fn set_back_enabled(&self, _enabled: bool) {}
258
259 fn show_soft_keyboard(&self) {}
261
262 fn hide_soft_keyboard(&self) {}
264
265 fn text_input_state_changed(&self, _change: TextInputStateChange) {}
267
268 fn play_system_bell(&self) {}
269
270 fn a11y_init(&self, _callbacks: A11yCallbacks) {}
272
273 fn a11y_tree_update(&self, _tree_update: accesskit::TreeUpdate) {}
275
276 fn a11y_update_window_bounds(&self) {}
278
279 #[cfg(any(test, feature = "test-support", feature = "bench-support"))]
280 fn as_test(&mut self) -> Option<&mut dyn Any> {
281 None
282 }
283}