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:
parent
e2cf2a5754
commit
cac627ed05
12 changed files with 65 additions and 29 deletions
|
|
@ -425,9 +425,22 @@ impl Window {
|
|||
}
|
||||
|
||||
#[inline]
|
||||
pub fn current_monitor(&self) -> RootMonitorHandle {
|
||||
RootMonitorHandle {
|
||||
inner: x11_or_wayland!(match self; Window(window) => window.current_monitor(); as MonitorHandle),
|
||||
pub fn current_monitor(&self) -> Option<RootMonitorHandle> {
|
||||
match self {
|
||||
#[cfg(feature = "x11")]
|
||||
&Window::X(ref window) => {
|
||||
let current_monitor = MonitorHandle::X(window.current_monitor());
|
||||
Some(RootMonitorHandle {
|
||||
inner: current_monitor,
|
||||
})
|
||||
}
|
||||
#[cfg(feature = "wayland")]
|
||||
&Window::Wayland(ref window) => {
|
||||
let current_monitor = MonitorHandle::Wayland(window.current_monitor()?);
|
||||
Some(RootMonitorHandle {
|
||||
inner: current_monitor,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -334,8 +334,10 @@ impl Window {
|
|||
|
||||
pub fn fullscreen(&self) -> Option<Fullscreen> {
|
||||
if *(self.fullscreen.lock().unwrap()) {
|
||||
// If the monitor cannot be determined, we cannot report any fullscreen mode.
|
||||
let current_monitor = self.current_monitor()?;
|
||||
Some(Fullscreen::Borderless(RootMonitorHandle {
|
||||
inner: PlatformMonitorHandle::Wayland(self.current_monitor()),
|
||||
inner: PlatformMonitorHandle::Wayland(current_monitor),
|
||||
}))
|
||||
} else {
|
||||
None
|
||||
|
|
@ -396,12 +398,12 @@ impl Window {
|
|||
&self.surface
|
||||
}
|
||||
|
||||
pub fn current_monitor(&self) -> MonitorHandle {
|
||||
let output = get_outputs(&self.surface).last().unwrap().clone();
|
||||
MonitorHandle {
|
||||
pub fn current_monitor(&self) -> Option<MonitorHandle> {
|
||||
let output = get_outputs(&self.surface).last()?.clone();
|
||||
Some(MonitorHandle {
|
||||
proxy: output,
|
||||
mgr: self.outputs.clone(),
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn available_monitors(&self) -> VecDeque<MonitorHandle> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue