1#![allow(unused)]
2
3use std::any::{type_name, Any};
4use std::cell::{self, RefCell};
5use std::env;
6use std::fs::File;
7use std::io::Read;
8use std::ops::{Deref, DerefMut};
9use std::os::fd::{AsRawFd, FromRawFd};
10use std::panic::Location;
11use std::{
12 path::{Path, PathBuf},
13 process::Command,
14 rc::Rc,
15 sync::Arc,
16 time::Duration,
17};
18
19use anyhow::anyhow;
20use ashpd::desktop::file_chooser::{OpenFileRequest, SaveFileRequest};
21use async_task::Runnable;
22use calloop::channel::Channel;
23use calloop::{EventLoop, LoopHandle, LoopSignal};
24use copypasta::ClipboardProvider;
25use filedescriptor::FileDescriptor;
26use flume::{Receiver, Sender};
27use futures::channel::oneshot;
28use parking_lot::Mutex;
29use time::UtcOffset;
30use wayland_client::Connection;
31use wayland_protocols::wp::cursor_shape::v1::client::wp_cursor_shape_device_v1::Shape;
32use xkbcommon::xkb::{self, Keycode, Keysym, State};
33
34use crate::platform::linux::wayland::WaylandClient;
35use crate::{
36 px, Action, AnyWindowHandle, BackgroundExecutor, ClipboardItem, CosmicTextSystem, CursorStyle,
37 DisplayId, ForegroundExecutor, Keymap, Keystroke, LinuxDispatcher, Menu, Modifiers,
38 PathPromptOptions, Pixels, Platform, PlatformDisplay, PlatformInput, PlatformInputHandler,
39 PlatformTextSystem, PlatformWindow, Point, PromptLevel, Result, SemanticVersion, Size, Task,
40 WindowAppearance, WindowOptions, WindowParams,
41};
42
43use super::x11::X11Client;
44
45pub(crate) const SCROLL_LINES: f64 = 3.0;
46
47// Values match the defaults on GTK.
48// Taken from https://github.com/GNOME/gtk/blob/main/gtk/gtksettings.c#L320
49pub(crate) const DOUBLE_CLICK_INTERVAL: Duration = Duration::from_millis(400);
50pub(crate) const DOUBLE_CLICK_DISTANCE: Pixels = px(5.0);
51pub(crate) const KEYRING_LABEL: &str = "zed-github-account";
52
53pub trait LinuxClient {
54 fn with_common<R>(&self, f: impl FnOnce(&mut LinuxCommon) -> R) -> R;
55 fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>>;
56 fn primary_display(&self) -> Option<Rc<dyn PlatformDisplay>>;
57 fn display(&self, id: DisplayId) -> Option<Rc<dyn PlatformDisplay>>;
58 fn open_window(
59 &self,
60 handle: AnyWindowHandle,
61 options: WindowParams,
62 ) -> Box<dyn PlatformWindow>;
63 fn set_cursor_style(&self, style: CursorStyle);
64 fn write_to_primary(&self, item: ClipboardItem);
65 fn write_to_clipboard(&self, item: ClipboardItem);
66 fn read_from_primary(&self) -> Option<ClipboardItem>;
67 fn read_from_clipboard(&self) -> Option<ClipboardItem>;
68 fn run(&self);
69}
70
71#[derive(Default)]
72pub(crate) struct PlatformHandlers {
73 pub(crate) open_urls: Option<Box<dyn FnMut(Vec<String>)>>,
74 pub(crate) become_active: Option<Box<dyn FnMut()>>,
75 pub(crate) resign_active: Option<Box<dyn FnMut()>>,
76 pub(crate) quit: Option<Box<dyn FnMut()>>,
77 pub(crate) reopen: Option<Box<dyn FnMut()>>,
78 pub(crate) event: Option<Box<dyn FnMut(PlatformInput) -> bool>>,
79 pub(crate) app_menu_action: Option<Box<dyn FnMut(&dyn Action)>>,
80 pub(crate) will_open_app_menu: Option<Box<dyn FnMut()>>,
81 pub(crate) validate_app_menu_command: Option<Box<dyn FnMut(&dyn Action) -> bool>>,
82}
83
84pub(crate) struct LinuxCommon {
85 pub(crate) background_executor: BackgroundExecutor,
86 pub(crate) foreground_executor: ForegroundExecutor,
87 pub(crate) text_system: Arc<CosmicTextSystem>,
88 pub(crate) callbacks: PlatformHandlers,
89 pub(crate) signal: LoopSignal,
90}
91
92impl LinuxCommon {
93 pub fn new(signal: LoopSignal) -> (Self, Channel<Runnable>) {
94 let (main_sender, main_receiver) = calloop::channel::channel::<Runnable>();
95 let text_system = Arc::new(CosmicTextSystem::new());
96 let callbacks = PlatformHandlers::default();
97
98 let dispatcher = Arc::new(LinuxDispatcher::new(main_sender));
99
100 let common = LinuxCommon {
101 background_executor: BackgroundExecutor::new(dispatcher.clone()),
102 foreground_executor: ForegroundExecutor::new(dispatcher.clone()),
103 text_system,
104 callbacks,
105 signal,
106 };
107
108 (common, main_receiver)
109 }
110}
111
112impl<P: LinuxClient + 'static> Platform for P {
113 fn background_executor(&self) -> BackgroundExecutor {
114 self.with_common(|common| common.background_executor.clone())
115 }
116
117 fn foreground_executor(&self) -> ForegroundExecutor {
118 self.with_common(|common| common.foreground_executor.clone())
119 }
120
121 fn text_system(&self) -> Arc<dyn PlatformTextSystem> {
122 self.with_common(|common| common.text_system.clone())
123 }
124
125 fn run(&self, on_finish_launching: Box<dyn FnOnce()>) {
126 on_finish_launching();
127
128 LinuxClient::run(self);
129
130 self.with_common(|common| {
131 if let Some(mut fun) = common.callbacks.quit.take() {
132 fun();
133 }
134 });
135 }
136
137 fn quit(&self) {
138 self.with_common(|common| common.signal.stop());
139 }
140
141 fn restart(&self) {
142 use std::os::unix::process::CommandExt as _;
143
144 // get the process id of the current process
145 let app_pid = std::process::id().to_string();
146 // get the path to the executable
147 let app_path = match self.app_path() {
148 Ok(path) => path,
149 Err(err) => {
150 log::error!("Failed to get app path: {:?}", err);
151 return;
152 }
153 };
154
155 // script to wait for the current process to exit and then restart the app
156 let script = format!(
157 r#"
158 while kill -O {pid} 2>/dev/null; do
159 sleep 0.1
160 done
161 {app_path}
162 "#,
163 pid = app_pid,
164 app_path = app_path.display()
165 );
166
167 // execute the script using /bin/bash
168 let restart_process = Command::new("/bin/bash")
169 .arg("-c")
170 .arg(script)
171 .process_group(0)
172 .spawn();
173
174 match restart_process {
175 Ok(_) => self.quit(),
176 Err(e) => log::error!("failed to spawn restart script: {:?}", e),
177 }
178 }
179
180 // todo(linux)
181 fn activate(&self, ignoring_other_apps: bool) {}
182
183 // todo(linux)
184 fn hide(&self) {}
185
186 fn hide_other_apps(&self) {
187 log::warn!("hide_other_apps is not implemented on Linux, ignoring the call")
188 }
189
190 // todo(linux)
191 fn unhide_other_apps(&self) {}
192
193 fn primary_display(&self) -> Option<Rc<dyn PlatformDisplay>> {
194 self.primary_display()
195 }
196
197 fn displays(&self) -> Vec<Rc<dyn PlatformDisplay>> {
198 self.displays()
199 }
200
201 fn display(&self, id: DisplayId) -> Option<Rc<dyn PlatformDisplay>> {
202 self.display(id)
203 }
204
205 // todo(linux)
206 fn active_window(&self) -> Option<AnyWindowHandle> {
207 None
208 }
209
210 fn open_window(
211 &self,
212 handle: AnyWindowHandle,
213 options: WindowParams,
214 ) -> Box<dyn PlatformWindow> {
215 self.open_window(handle, options)
216 }
217
218 fn open_url(&self, url: &str) {
219 open::that(url);
220 }
221
222 fn on_open_urls(&self, callback: Box<dyn FnMut(Vec<String>)>) {
223 self.with_common(|common| common.callbacks.open_urls = Some(callback));
224 }
225
226 fn prompt_for_paths(
227 &self,
228 options: PathPromptOptions,
229 ) -> oneshot::Receiver<Option<Vec<PathBuf>>> {
230 let (done_tx, done_rx) = oneshot::channel();
231 self.foreground_executor()
232 .spawn(async move {
233 let title = if options.multiple {
234 if !options.files {
235 "Open folders"
236 } else {
237 "Open files"
238 }
239 } else {
240 if !options.files {
241 "Open folder"
242 } else {
243 "Open file"
244 }
245 };
246
247 let result = OpenFileRequest::default()
248 .modal(true)
249 .title(title)
250 .accept_label("Select")
251 .multiple(options.multiple)
252 .directory(options.directories)
253 .send()
254 .await
255 .ok()
256 .and_then(|request| request.response().ok())
257 .and_then(|response| {
258 response
259 .uris()
260 .iter()
261 .map(|uri| uri.to_file_path().ok())
262 .collect()
263 });
264
265 done_tx.send(result);
266 })
267 .detach();
268 done_rx
269 }
270
271 fn prompt_for_new_path(&self, directory: &Path) -> oneshot::Receiver<Option<PathBuf>> {
272 let (done_tx, done_rx) = oneshot::channel();
273 let directory = directory.to_owned();
274 self.foreground_executor()
275 .spawn(async move {
276 let result = SaveFileRequest::default()
277 .modal(true)
278 .title("Select new path")
279 .accept_label("Accept")
280 .send()
281 .await
282 .ok()
283 .and_then(|request| request.response().ok())
284 .and_then(|response| {
285 response
286 .uris()
287 .first()
288 .and_then(|uri| uri.to_file_path().ok())
289 });
290
291 done_tx.send(result);
292 })
293 .detach();
294
295 done_rx
296 }
297
298 fn reveal_path(&self, path: &Path) {
299 if path.is_dir() {
300 open::that(path);
301 return;
302 }
303 // If `path` is a file, the system may try to open it in a text editor
304 let dir = path.parent().unwrap_or(Path::new(""));
305 open::that(dir);
306 }
307
308 fn on_become_active(&self, callback: Box<dyn FnMut()>) {
309 self.with_common(|common| {
310 common.callbacks.become_active = Some(callback);
311 });
312 }
313
314 fn on_resign_active(&self, callback: Box<dyn FnMut()>) {
315 self.with_common(|common| {
316 common.callbacks.resign_active = Some(callback);
317 });
318 }
319
320 fn on_quit(&self, callback: Box<dyn FnMut()>) {
321 self.with_common(|common| {
322 common.callbacks.quit = Some(callback);
323 });
324 }
325
326 fn on_reopen(&self, callback: Box<dyn FnMut()>) {
327 self.with_common(|common| {
328 common.callbacks.reopen = Some(callback);
329 });
330 }
331
332 fn on_event(&self, callback: Box<dyn FnMut(PlatformInput) -> bool>) {
333 self.with_common(|common| {
334 common.callbacks.event = Some(callback);
335 });
336 }
337
338 fn on_app_menu_action(&self, callback: Box<dyn FnMut(&dyn Action)>) {
339 self.with_common(|common| {
340 common.callbacks.app_menu_action = Some(callback);
341 });
342 }
343
344 fn on_will_open_app_menu(&self, callback: Box<dyn FnMut()>) {
345 self.with_common(|common| {
346 common.callbacks.will_open_app_menu = Some(callback);
347 });
348 }
349
350 fn on_validate_app_menu_command(&self, callback: Box<dyn FnMut(&dyn Action) -> bool>) {
351 self.with_common(|common| {
352 common.callbacks.validate_app_menu_command = Some(callback);
353 });
354 }
355
356 fn os_name(&self) -> &'static str {
357 "Linux"
358 }
359
360 fn os_version(&self) -> Result<SemanticVersion> {
361 Ok(SemanticVersion::new(1, 0, 0))
362 }
363
364 fn app_version(&self) -> Result<SemanticVersion> {
365 Ok(SemanticVersion::new(1, 0, 0))
366 }
367
368 fn app_path(&self) -> Result<PathBuf> {
369 // get the path of the executable of the current process
370 let exe_path = std::env::current_exe()?;
371 Ok(exe_path)
372 }
373
374 // todo(linux)
375 fn set_menus(&self, menus: Vec<Menu>, keymap: &Keymap) {}
376
377 fn local_timezone(&self) -> UtcOffset {
378 UtcOffset::UTC
379 }
380
381 //todo(linux)
382 fn path_for_auxiliary_executable(&self, name: &str) -> Result<PathBuf> {
383 Err(anyhow::Error::msg(
384 "Platform<LinuxPlatform>::path_for_auxiliary_executable is not implemented yet",
385 ))
386 }
387
388 fn set_cursor_style(&self, style: CursorStyle) {
389 self.set_cursor_style(style)
390 }
391
392 // todo(linux)
393 fn should_auto_hide_scrollbars(&self) -> bool {
394 false
395 }
396
397 fn write_credentials(&self, url: &str, username: &str, password: &[u8]) -> Task<Result<()>> {
398 let url = url.to_string();
399 let username = username.to_string();
400 let password = password.to_vec();
401 self.background_executor().spawn(async move {
402 let keyring = oo7::Keyring::new().await?;
403 keyring.unlock().await?;
404 keyring
405 .create_item(
406 KEYRING_LABEL,
407 &vec![("url", &url), ("username", &username)],
408 password,
409 true,
410 )
411 .await?;
412 Ok(())
413 })
414 }
415
416 fn read_credentials(&self, url: &str) -> Task<Result<Option<(String, Vec<u8>)>>> {
417 let url = url.to_string();
418 self.background_executor().spawn(async move {
419 let keyring = oo7::Keyring::new().await?;
420 keyring.unlock().await?;
421
422 let items = keyring.search_items(&vec![("url", &url)]).await?;
423
424 for item in items.into_iter() {
425 if item.label().await.is_ok_and(|label| label == KEYRING_LABEL) {
426 let attributes = item.attributes().await?;
427 let username = attributes
428 .get("username")
429 .ok_or_else(|| anyhow!("Cannot find username in stored credentials"))?;
430 let secret = item.secret().await?;
431
432 // we lose the zeroizing capabilities at this boundary,
433 // a current limitation GPUI's credentials api
434 return Ok(Some((username.to_string(), secret.to_vec())));
435 } else {
436 continue;
437 }
438 }
439 Ok(None)
440 })
441 }
442
443 fn delete_credentials(&self, url: &str) -> Task<Result<()>> {
444 let url = url.to_string();
445 self.background_executor().spawn(async move {
446 let keyring = oo7::Keyring::new().await?;
447 keyring.unlock().await?;
448
449 let items = keyring.search_items(&vec![("url", &url)]).await?;
450
451 for item in items.into_iter() {
452 if item.label().await.is_ok_and(|label| label == KEYRING_LABEL) {
453 item.delete().await?;
454 return Ok(());
455 }
456 }
457
458 Ok(())
459 })
460 }
461
462 fn window_appearance(&self) -> crate::WindowAppearance {
463 crate::WindowAppearance::Light
464 }
465
466 fn register_url_scheme(&self, _: &str) -> Task<anyhow::Result<()>> {
467 Task::ready(Err(anyhow!("register_url_scheme unimplemented")))
468 }
469
470 fn write_to_primary(&self, item: ClipboardItem) {
471 self.write_to_primary(item)
472 }
473
474 fn write_to_clipboard(&self, item: ClipboardItem) {
475 self.write_to_clipboard(item)
476 }
477
478 fn read_from_primary(&self) -> Option<ClipboardItem> {
479 self.read_from_primary()
480 }
481
482 fn read_from_clipboard(&self) -> Option<ClipboardItem> {
483 self.read_from_clipboard()
484 }
485}
486
487pub(super) fn is_within_click_distance(a: Point<Pixels>, b: Point<Pixels>) -> bool {
488 let diff = a - b;
489 diff.x.abs() <= DOUBLE_CLICK_DISTANCE && diff.y.abs() <= DOUBLE_CLICK_DISTANCE
490}
491
492pub(super) unsafe fn read_fd(mut fd: FileDescriptor) -> Result<String> {
493 let mut file = File::from_raw_fd(fd.as_raw_fd());
494
495 let mut buffer = String::new();
496 file.read_to_string(&mut buffer)?;
497
498 // Normalize the text to unix line endings, otherwise
499 // copying from eg: firefox inserts a lot of blank
500 // lines, and that is super annoying.
501 let result = buffer.replace("\r\n", "\n");
502 Ok(result)
503}
504
505impl CursorStyle {
506 pub(super) fn to_shape(&self) -> Shape {
507 match self {
508 CursorStyle::Arrow => Shape::Default,
509 CursorStyle::IBeam => Shape::Text,
510 CursorStyle::Crosshair => Shape::Crosshair,
511 CursorStyle::ClosedHand => Shape::Grabbing,
512 CursorStyle::OpenHand => Shape::Grab,
513 CursorStyle::PointingHand => Shape::Pointer,
514 CursorStyle::ResizeLeft => Shape::WResize,
515 CursorStyle::ResizeRight => Shape::EResize,
516 CursorStyle::ResizeLeftRight => Shape::EwResize,
517 CursorStyle::ResizeUp => Shape::NResize,
518 CursorStyle::ResizeDown => Shape::SResize,
519 CursorStyle::ResizeUpDown => Shape::NsResize,
520 CursorStyle::DisappearingItem => Shape::Grabbing, // todo(linux) - couldn't find equivalent icon in linux
521 CursorStyle::IBeamCursorForVerticalLayout => Shape::VerticalText,
522 CursorStyle::OperationNotAllowed => Shape::NotAllowed,
523 CursorStyle::DragLink => Shape::Alias,
524 CursorStyle::DragCopy => Shape::Copy,
525 CursorStyle::ContextualMenu => Shape::ContextMenu,
526 }
527 }
528
529 pub(super) fn to_icon_name(&self) -> String {
530 // Based on cursor names from https://gitlab.gnome.org/GNOME/adwaita-icon-theme (GNOME)
531 // and https://github.com/KDE/breeze (KDE). Both of them seem to be also derived from
532 // Web CSS cursor names: https://developer.mozilla.org/en-US/docs/Web/CSS/cursor#values
533 match self {
534 CursorStyle::Arrow => "arrow",
535 CursorStyle::IBeam => "text",
536 CursorStyle::Crosshair => "crosshair",
537 CursorStyle::ClosedHand => "grabbing",
538 CursorStyle::OpenHand => "grab",
539 CursorStyle::PointingHand => "pointer",
540 CursorStyle::ResizeLeft => "w-resize",
541 CursorStyle::ResizeRight => "e-resize",
542 CursorStyle::ResizeLeftRight => "ew-resize",
543 CursorStyle::ResizeUp => "n-resize",
544 CursorStyle::ResizeDown => "s-resize",
545 CursorStyle::ResizeUpDown => "ns-resize",
546 CursorStyle::DisappearingItem => "grabbing", // todo(linux) - couldn't find equivalent icon in linux
547 CursorStyle::IBeamCursorForVerticalLayout => "vertical-text",
548 CursorStyle::OperationNotAllowed => "not-allowed",
549 CursorStyle::DragLink => "alias",
550 CursorStyle::DragCopy => "copy",
551 CursorStyle::ContextualMenu => "context-menu",
552 }
553 .to_string()
554 }
555}
556
557impl Keystroke {
558 pub(super) fn from_xkb(state: &State, modifiers: Modifiers, keycode: Keycode) -> Self {
559 let mut modifiers = modifiers;
560
561 let key_utf32 = state.key_get_utf32(keycode);
562 let key_utf8 = state.key_get_utf8(keycode);
563 let key_sym = state.key_get_one_sym(keycode);
564
565 // The logic here tries to replicate the logic in `../mac/events.rs`
566 // "Consumed" modifiers are modifiers that have been used to translate a key, for example
567 // pressing "shift" and "1" on US layout produces the key `!` but "consumes" the shift.
568 // Notes:
569 // - macOS gets the key character directly ("."), xkb gives us the key name ("period")
570 // - macOS logic removes consumed shift modifier for symbols: "{", not "shift-{"
571 // - macOS logic keeps consumed shift modifiers for letters: "shift-a", not "a" or "A"
572
573 let mut handle_consumed_modifiers = true;
574 let key = match key_sym {
575 Keysym::Return => "enter".to_owned(),
576 Keysym::Prior => "pageup".to_owned(),
577 Keysym::Next => "pagedown".to_owned(),
578
579 Keysym::comma => ",".to_owned(),
580 Keysym::period => ".".to_owned(),
581 Keysym::less => "<".to_owned(),
582 Keysym::greater => ">".to_owned(),
583 Keysym::slash => "/".to_owned(),
584 Keysym::question => "?".to_owned(),
585
586 Keysym::semicolon => ";".to_owned(),
587 Keysym::colon => ":".to_owned(),
588 Keysym::apostrophe => "'".to_owned(),
589 Keysym::quotedbl => "\"".to_owned(),
590
591 Keysym::bracketleft => "[".to_owned(),
592 Keysym::braceleft => "{".to_owned(),
593 Keysym::bracketright => "]".to_owned(),
594 Keysym::braceright => "}".to_owned(),
595 Keysym::backslash => "\\".to_owned(),
596 Keysym::bar => "|".to_owned(),
597
598 Keysym::grave => "`".to_owned(),
599 Keysym::asciitilde => "~".to_owned(),
600 Keysym::exclam => "!".to_owned(),
601 Keysym::at => "@".to_owned(),
602 Keysym::numbersign => "#".to_owned(),
603 Keysym::dollar => "$".to_owned(),
604 Keysym::percent => "%".to_owned(),
605 Keysym::asciicircum => "^".to_owned(),
606 Keysym::ampersand => "&".to_owned(),
607 Keysym::asterisk => "*".to_owned(),
608 Keysym::parenleft => "(".to_owned(),
609 Keysym::parenright => ")".to_owned(),
610 Keysym::minus => "-".to_owned(),
611 Keysym::underscore => "_".to_owned(),
612 Keysym::equal => "=".to_owned(),
613 Keysym::plus => "+".to_owned(),
614
615 Keysym::ISO_Left_Tab => {
616 handle_consumed_modifiers = false;
617 "tab".to_owned()
618 }
619
620 _ => {
621 handle_consumed_modifiers = false;
622 xkb::keysym_get_name(key_sym).to_lowercase()
623 }
624 };
625
626 // Ignore control characters (and DEL) for the purposes of ime_key,
627 // but if key_utf32 is 0 then assume it isn't one
628 let ime_key = ((key_utf32 == 0 || (key_utf32 >= 32 && key_utf32 != 127))
629 && !key_utf8.is_empty())
630 .then_some(key_utf8);
631
632 if handle_consumed_modifiers {
633 let mod_shift_index = state.get_keymap().mod_get_index(xkb::MOD_NAME_SHIFT);
634 let is_shift_consumed = state.mod_index_is_consumed(keycode, mod_shift_index);
635
636 if modifiers.shift && is_shift_consumed {
637 modifiers.shift = false;
638 }
639 }
640
641 Keystroke {
642 modifiers,
643 key,
644 ime_key,
645 }
646 }
647}
648
649impl Modifiers {
650 pub(super) fn from_xkb(keymap_state: &State) -> Self {
651 let shift = keymap_state.mod_name_is_active(xkb::MOD_NAME_SHIFT, xkb::STATE_MODS_EFFECTIVE);
652 let alt = keymap_state.mod_name_is_active(xkb::MOD_NAME_ALT, xkb::STATE_MODS_EFFECTIVE);
653 let control =
654 keymap_state.mod_name_is_active(xkb::MOD_NAME_CTRL, xkb::STATE_MODS_EFFECTIVE);
655 let platform =
656 keymap_state.mod_name_is_active(xkb::MOD_NAME_LOGO, xkb::STATE_MODS_EFFECTIVE);
657 Modifiers {
658 shift,
659 alt,
660 control,
661 platform,
662 function: false,
663 }
664 }
665}
666
667#[cfg(test)]
668mod tests {
669 use super::*;
670 use crate::{px, Point};
671
672 #[test]
673 fn test_is_within_click_distance() {
674 let zero = Point::new(px(0.0), px(0.0));
675 assert_eq!(
676 is_within_click_distance(zero, Point::new(px(5.0), px(5.0))),
677 true
678 );
679 assert_eq!(
680 is_within_click_distance(zero, Point::new(px(-4.9), px(5.0))),
681 true
682 );
683 assert_eq!(
684 is_within_click_distance(Point::new(px(3.0), px(2.0)), Point::new(px(-2.0), px(-2.0))),
685 true
686 );
687 assert_eq!(
688 is_within_click_distance(zero, Point::new(px(5.0), px(5.1))),
689 false
690 );
691 }
692}