From eecd1c7920b58ce70ae8315af2e49d7d95526b21 Mon Sep 17 00:00:00 2001 From: amrbashir Date: Tue, 17 Oct 2023 02:29:00 +0300 Subject: [PATCH] fix(linux): avoid unwrapping in `Window::current_monitor` closes tauri-apps/tauri#7986 --- .changes/linux-current-monitor.md | 5 +++++ src/platform_impl/linux/window.rs | 11 ++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .changes/linux-current-monitor.md diff --git a/.changes/linux-current-monitor.md b/.changes/linux-current-monitor.md new file mode 100644 index 000000000..db67e62b5 --- /dev/null +++ b/.changes/linux-current-monitor.md @@ -0,0 +1,5 @@ +--- +"tao": patch +--- + +Fix `Window::current_monitor` sometimes panicking on Linux when the window is invisible. diff --git a/src/platform_impl/linux/window.rs b/src/platform_impl/linux/window.rs index c97a077d5..0f6c6009a 100644 --- a/src/platform_impl/linux/window.rs +++ b/src/platform_impl/linux/window.rs @@ -678,11 +678,12 @@ impl Window { let monitor = self .window .window() - .map(|window| display.monitor_at_window(&window)) - .unwrap_or_else(|| display.primary_monitor()) - .unwrap(); - let handle = MonitorHandle { monitor }; - Some(RootMonitorHandle { inner: handle }) + .and_then(|window| display.monitor_at_window(&window)) + .or_else(|| display.primary_monitor()); + + monitor.map(|monitor| RootMonitorHandle { + inner: MonitorHandle { monitor }, + }) } #[inline]