From 28b53f80c49bbf2ae8902b98a2e28f6451a5a8f1 Mon Sep 17 00:00:00 2001 From: 2e0byo <2e0byo@gmail.com> Date: Wed, 22 Feb 2023 15:29:00 +0000 Subject: [PATCH] fix: don't panic if primary monitor not discoverable. (#705) * fix(linux): don't panic if primary monitor not discoverable. (#704) * chore: add change file. --- .changes/linux-primary-monitor.md | 5 +++++ src/platform_impl/linux/event_loop.rs | 8 +++++--- 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 .changes/linux-primary-monitor.md diff --git a/.changes/linux-primary-monitor.md b/.changes/linux-primary-monitor.md new file mode 100644 index 000000000..8f50d9028 --- /dev/null +++ b/.changes/linux-primary-monitor.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Attempt to get primary monitor on linux will now return None rather than panicking if monitor not found. diff --git a/src/platform_impl/linux/event_loop.rs b/src/platform_impl/linux/event_loop.rs index 0320a6bd4..8974e646e 100644 --- a/src/platform_impl/linux/event_loop.rs +++ b/src/platform_impl/linux/event_loop.rs @@ -79,9 +79,11 @@ impl EventLoopWindowTarget { #[inline] pub fn primary_monitor(&self) -> Option { - let monitor = self.display.primary_monitor().unwrap(); - let handle = MonitorHandle { monitor }; - Some(RootMonitorHandle { inner: handle }) + let monitor = self.display.primary_monitor(); + monitor.and_then(|monitor| { + let handle = MonitorHandle { monitor }; + Some(RootMonitorHandle { inner: handle }) + }) } pub fn raw_display_handle(&self) -> RawDisplayHandle {