Make 'current_monitor' return 'Option<MonitorHandle>'

On certain platforms window couldn't be on any monitor
resulting in failures of 'current_monitor' function.

Such issue was happening on Wayland, since the window
isn't on any monitor, unless the user has drawn something into it.

Returning 'Option<MonitorHandle>' will give an ability to
handle such situations gracefully by properly indicating that
there's no current monitor.

Fixes #793.
This commit is contained in:
Kirill Chibisov 2020-09-07 20:09:24 +03:00 committed by GitHub
parent e2cf2a5754
commit cac627ed05
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 65 additions and 29 deletions

View file

@ -201,7 +201,7 @@ impl Window {
#[inline]
pub fn fullscreen(&self) -> Option<Fullscreen> {
if self.canvas.is_fullscreen() {
Some(Fullscreen::Borderless(self.current_monitor()))
Some(Fullscreen::Borderless(self.current_monitor_inner()))
} else {
None
}
@ -237,12 +237,18 @@ impl Window {
}
#[inline]
pub fn current_monitor(&self) -> RootMH {
// Allow directly accessing the current monitor internally without unwrapping.
fn current_monitor_inner(&self) -> RootMH {
RootMH {
inner: monitor::Handle,
}
}
#[inline]
pub fn current_monitor(&self) -> Option<RootMH> {
Some(self.current_monitor_inner())
}
#[inline]
pub fn available_monitors(&self) -> VecDequeIter<monitor::Handle> {
VecDeque::new().into_iter()