Skip to content

Commit 87fc198

Browse files
psychonkchibisov
authored andcommitted
On X11, simplify available_monitors() impl
This code confused me. I tried to understand it. I tried to simplify it while keeping the functional style. But in the end, this just seems too complicated for its own good. Just doing the exact same thing with a match statement and the question mark operator makes it sooo much more obvious what is happening. Signed-off-by: Uli Schlachter <psychon@znc.in>
1 parent 11d1b7a commit 87fc198

1 file changed

Lines changed: 10 additions & 16 deletions

File tree

src/platform_impl/linux/x11/monitor.rs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -284,22 +284,16 @@ impl XConnection {
284284

285285
pub fn available_monitors(&self) -> Result<Vec<MonitorHandle>, X11Error> {
286286
let mut monitors_lock = self.monitor_handles.lock().unwrap();
287-
(*monitors_lock)
288-
.as_ref()
289-
.cloned()
290-
.map(Ok)
291-
.or_else(|| {
292-
self.query_monitor_list()
293-
.map(|mon_list| {
294-
let monitors = Some(mon_list);
295-
if !DISABLE_MONITOR_LIST_CACHING {
296-
(*monitors_lock) = monitors.clone();
297-
}
298-
monitors
299-
})
300-
.transpose()
301-
})
302-
.unwrap()
287+
match *monitors_lock {
288+
Some(ref monitors) => Ok(monitors.clone()),
289+
None => {
290+
let monitors = self.query_monitor_list()?;
291+
if !DISABLE_MONITOR_LIST_CACHING {
292+
*monitors_lock = Some(monitors.clone());
293+
}
294+
Ok(monitors)
295+
}
296+
}
303297
}
304298

305299
#[inline]

0 commit comments

Comments
 (0)