Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/backend/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(target_os = "macos"))]
pub mod x11;

#[cfg(not(target_os = "macos"))]
Expand All @@ -15,6 +16,7 @@ pub trait Backend {
pub enum DisplayServer {
#[cfg(not(target_os = "macos"))]
Wayland,
#[cfg(not(target_os = "macos"))]
X11,
#[cfg(target_os = "macos")]
MacOs,
Expand All @@ -25,21 +27,24 @@ pub fn detect() -> anyhow::Result<DisplayServer> {
return Ok(DisplayServer::MacOs);

#[cfg(not(target_os = "macos"))]
if std::env::var("WAYLAND_DISPLAY").is_ok() {
return Ok(DisplayServer::Wayland);
}

if std::env::var("DISPLAY").is_ok() {
return Ok(DisplayServer::X11);
{
if std::env::var("WAYLAND_DISPLAY").is_ok() {
return Ok(DisplayServer::Wayland);
}
if std::env::var("DISPLAY").is_ok() {
return Ok(DisplayServer::X11);
}
anyhow::bail!(
"no display found: neither WAYLAND_DISPLAY nor DISPLAY is set"
)
}

anyhow::bail!("no display found: neither WAYLAND_DISPLAY nor DISPLAY is set")
}

pub fn build() -> anyhow::Result<Box<dyn Backend>> {
match detect()? {
#[cfg(not(target_os = "macos"))]
DisplayServer::Wayland => Ok(Box::new(wayland::WaylandBackend)),
#[cfg(not(target_os = "macos"))]
DisplayServer::X11 => Ok(Box::new(x11::X11Backend::new()?)),
#[cfg(target_os = "macos")]
DisplayServer::MacOs => Ok(Box::new(macos::MacOsBackend)),
Expand Down