linux_wayland_support: dup detecting function of x11 or wayland

Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
fufesou
2022-07-20 10:44:27 -07:00
parent 634cb5ef1a
commit 00dc473703
12 changed files with 130 additions and 155 deletions

View File

@@ -52,31 +52,30 @@ pub enum Display {
}
#[inline]
pub fn is_wayland() -> bool {
std::env::var("IS_WAYLAND").is_ok()
|| std::env::var("XDG_SESSION_TYPE") == Ok("wayland".to_owned())
pub fn is_x11() -> bool {
"x11" == hbb_common::platform::linux::get_display_server()
}
impl Display {
pub fn primary() -> io::Result<Display> {
Ok(if is_wayland() {
Display::WAYLAND(wayland::Display::primary()?)
} else {
Ok(if is_x11() {
Display::X11(x11::Display::primary()?)
} else {
Display::WAYLAND(wayland::Display::primary()?)
})
}
pub fn all() -> io::Result<Vec<Display>> {
Ok(if is_wayland() {
wayland::Display::all()?
.drain(..)
.map(|x| Display::WAYLAND(x))
.collect()
} else {
Ok(if is_x11() {
x11::Display::all()?
.drain(..)
.map(|x| Display::X11(x))
.collect()
} else {
wayland::Display::all()?
.drain(..)
.map(|x| Display::WAYLAND(x))
.collect()
})
}