Skip to content

Commit

Permalink
fix(linux): fallback to primary monitor on current_monitor impl (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed May 18, 2022
1 parent 8945f54 commit 6cdb99f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changes/fix-current-monitor-panic.md
@@ -0,0 +1,5 @@
---
"tao": patch
---

The `current_monitor` function now fallbacks to the primary monitor when the window is invisible.
16 changes: 13 additions & 3 deletions src/platform_impl/linux/window.rs
Expand Up @@ -612,9 +612,19 @@ impl Window {

pub fn current_monitor(&self) -> Option<RootMonitorHandle> {
let screen = self.window.display().default_screen();
let window = self.window.window().unwrap();
#[allow(deprecated)] // Gtk3 Window only accepts Gdkscreen
let number = screen.monitor_at_window(&window);
// `.window()` returns `None` if the window is invisible;
// we fallback to the primary monitor
let number = self
.window
.window()
.map(|window| {
#[allow(deprecated)] // Gtk3 Window only accepts Gdkscreen
screen.monitor_at_window(&window)
})
.unwrap_or_else(|| {
#[allow(deprecated)] // Gtk3 Window only accepts Gdkscreen
screen.primary_monitor()
});
let handle = MonitorHandle::new(&self.window.display(), number);
Some(RootMonitorHandle { inner: handle })
}
Expand Down

0 comments on commit 6cdb99f

Please sign in to comment.