1#![allow(unused)]
2
3use crate::{
4 Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CursorStyle, DisplayId,
5 ForegroundExecutor, Keymap, LinuxDispatcher, LinuxDisplay, LinuxTextSystem, LinuxWindow, Menu,
6 PathPromptOptions, Platform, PlatformDisplay, PlatformInput, PlatformTextSystem,
7 PlatformWindow, Result, SemanticVersion, Task, WindowOptions,
8};
9
10use futures::channel::oneshot;
11use parking_lot::Mutex;
12
13use std::{
14 path::{Path, PathBuf},
15 rc::Rc,
16 sync::Arc,
17 time::Duration,
18};
19use time::UtcOffset;
20
21pub(crate) struct LinuxPlatform(Mutex<LinuxPlatformState>);
22
23pub(crate) struct LinuxPlatformState {
24 gpu: Arc<blade::Context>,
25 background_executor: BackgroundExecutor,
26 foreground_executor: ForegroundExecutor,
27 text_system: Arc<LinuxTextSystem>,
28}
29
30impl Default for LinuxPlatform {
31 fn default() -> Self {
32 Self::new()
33 }
34}
35
36impl LinuxPlatform {
37 pub(crate) fn new() -> Self {
38 let dispatcher = Arc::new(LinuxDispatcher::new());
39 let gpu = Arc::new(
40 unsafe {
41 blade::Context::init(blade::ContextDesc {
42 validation: true, //FIXME
43 capture: false,
44 })
45 }
46 .unwrap(),
47 );
48 Self(Mutex::new(LinuxPlatformState {
49 gpu,
50 background_executor: BackgroundExecutor::new(dispatcher.clone()),
51 foreground_executor: ForegroundExecutor::new(dispatcher),
52 text_system: Arc::new(LinuxTextSystem::new()),
53 }))
54 }
55}
56
57impl Platform for LinuxPlatform {
58 fn background_executor(&self) -> BackgroundExecutor {
59 self.0.lock().background_executor.clone()
60 }
61
62 fn foreground_executor(&self) -> crate::ForegroundExecutor {
63 self.0.lock().foreground_executor.clone()
64 }
65
66 fn text_system(&self) -> Arc<dyn PlatformTextSystem> {
67 self.0.lock().text_system.clone()
68 }
69
70 fn run(&self, on_finish_launching: Box<dyn FnOnce()>) {
71 on_finish_launching()
72 }
73
74 fn quit(&self) {}
75
76 fn restart(&self) {}
77
78 fn activate(&self, ignoring_other_apps: bool) {}
79
80 fn hide(&self) {}
81
82 fn hide_other_apps(&self) {}
83
84 fn unhide_other_apps(&self) {}
85
86 fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>> {
87 Vec::new()
88 }
89
90 fn display(&self, id: DisplayId) -> Option<Rc<dyn PlatformDisplay>> {
91 None
92 }
93
94 fn active_window(&self) -> Option<AnyWindowHandle> {
95 None
96 }
97
98 fn open_window(
99 &self,
100 handle: AnyWindowHandle,
101 options: WindowOptions,
102 ) -> Box<dyn PlatformWindow> {
103 let lock = self.0.lock();
104 Box::new(LinuxWindow::new(
105 options,
106 handle,
107 Rc::new(LinuxDisplay),
108 &lock.gpu,
109 ))
110 }
111
112 fn set_display_link_output_callback(
113 &self,
114 display_id: DisplayId,
115 callback: Box<dyn FnMut() + Send>,
116 ) {
117 unimplemented!()
118 }
119
120 fn start_display_link(&self, display_id: DisplayId) {}
121
122 fn stop_display_link(&self, display_id: DisplayId) {}
123
124 fn open_url(&self, url: &str) {}
125
126 fn on_open_urls(&self, callback: Box<dyn FnMut(Vec<String>)>) {}
127
128 fn prompt_for_paths(
129 &self,
130 options: PathPromptOptions,
131 ) -> oneshot::Receiver<Option<Vec<PathBuf>>> {
132 unimplemented!()
133 }
134
135 fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver<Option<PathBuf>> {
136 unimplemented!()
137 }
138
139 fn reveal_path(&self, path: &Path) {}
140
141 fn on_become_active(&self, callback: Box<dyn FnMut()>) {}
142
143 fn on_resign_active(&self, callback: Box<dyn FnMut()>) {}
144
145 fn on_quit(&self, callback: Box<dyn FnMut()>) {}
146
147 fn on_reopen(&self, callback: Box<dyn FnMut()>) {}
148
149 fn on_event(&self, callback: Box<dyn FnMut(PlatformInput) -> bool>) {}
150
151 fn on_app_menu_action(&self, callback: Box<dyn FnMut(&dyn Action)>) {}
152
153 fn on_will_open_app_menu(&self, callback: Box<dyn FnMut()>) {}
154
155 fn on_validate_app_menu_command(&self, callback: Box<dyn FnMut(&dyn Action) -> bool>) {}
156
157 fn os_name(&self) -> &'static str {
158 "Linux"
159 }
160
161 fn double_click_interval(&self) -> Duration {
162 Duration::default()
163 }
164
165 fn os_version(&self) -> Result<SemanticVersion> {
166 Ok(SemanticVersion {
167 major: 1,
168 minor: 0,
169 patch: 0,
170 })
171 }
172
173 fn app_version(&self) -> Result<SemanticVersion> {
174 Ok(SemanticVersion {
175 major: 1,
176 minor: 0,
177 patch: 0,
178 })
179 }
180
181 fn app_path(&self) -> Result<PathBuf> {
182 unimplemented!()
183 }
184
185 fn set_menus(&self, menus: Vec<Menu>, keymap: &Keymap) {}
186
187 fn local_timezone(&self) -> UtcOffset {
188 UtcOffset::UTC
189 }
190
191 fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf> {
192 unimplemented!()
193 }
194
195 fn set_cursor_style(&self, style: CursorStyle) {}
196
197 fn should_auto_hide_scrollbars(&self) -> bool {
198 false
199 }
200
201 fn write_to_clipboard(&self, item: ClipboardItem) {}
202
203 fn read_from_clipboard(&self) -> Option<ClipboardItem> {
204 None
205 }
206
207 fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Task<Result<()>> {
208 unimplemented!()
209 }
210
211 fn read_credentials(&self, url: &str) -> Task<Result<Option<(String, Vec<u8>)>>> {
212 unimplemented!()
213 }
214
215 fn delete_credentials(&self, url: &str) -> Task<Result<()>> {
216 unimplemented!()
217 }
218}
219
220#[cfg(test)]
221mod tests {
222 use crate::ClipboardItem;
223
224 use super::*;
225
226 fn build_platform() -> LinuxPlatform {
227 let platform = LinuxPlatform::new();
228 platform
229 }
230}