mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2024-12-25 23:01:30 +11:00
Do the linux backend choice only once at startup.
This commit is contained in:
parent
a6c33ef958
commit
1dc2cb27cf
|
@ -17,6 +17,22 @@ use libc;
|
||||||
use api::wayland;
|
use api::wayland;
|
||||||
use api::x11;
|
use api::x11;
|
||||||
|
|
||||||
|
enum Backend {
|
||||||
|
X,
|
||||||
|
Wayland
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_static!(
|
||||||
|
static ref BACKEND: Backend = {
|
||||||
|
// Wayland backend is not production-ready yet so we disable it
|
||||||
|
if false && wayland::is_available() {
|
||||||
|
Backend::Wayland
|
||||||
|
} else {
|
||||||
|
Backend::X
|
||||||
|
}
|
||||||
|
};
|
||||||
|
);
|
||||||
|
|
||||||
pub enum Window {
|
pub enum Window {
|
||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
X(x11::Window),
|
X(x11::Window),
|
||||||
|
@ -49,25 +65,21 @@ pub enum MonitorID {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_available_monitors() -> VecDeque<MonitorID> {
|
pub fn get_available_monitors() -> VecDeque<MonitorID> {
|
||||||
if false && wayland::is_available() {
|
match *BACKEND {
|
||||||
// We are doing wayland
|
Backend::Wayland => wayland::get_available_monitors()
|
||||||
wayland::get_available_monitors()
|
.into_iter()
|
||||||
.into_iter()
|
.map(MonitorID::Wayland)
|
||||||
.map(|m| MonitorID::Wayland(m))
|
.collect(),
|
||||||
.collect()
|
Backend::X => x11::get_available_monitors()
|
||||||
} else {
|
.into_iter()
|
||||||
// Fallback on X
|
.map(MonitorID::X)
|
||||||
x11::get_available_monitors()
|
.collect(),
|
||||||
.into_iter()
|
|
||||||
.map(|m| MonitorID::X(m))
|
|
||||||
.collect()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn get_primary_monitor() -> MonitorID {
|
pub fn get_primary_monitor() -> MonitorID {
|
||||||
if false && wayland::is_available() {
|
match *BACKEND {
|
||||||
MonitorID::Wayland(wayland::get_primary_monitor())
|
Backend::Wayland => MonitorID::Wayland(wayland::get_primary_monitor()),
|
||||||
} else {
|
Backend::X => MonitorID::X(x11::get_primary_monitor()),
|
||||||
MonitorID::X(x11::get_primary_monitor())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,14 +145,9 @@ impl<'a> Iterator for WaitEventsIterator<'a> {
|
||||||
|
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
|
pub fn new(builder: BuilderAttribs) -> Result<Window, CreationError> {
|
||||||
if false && wayland::is_available() {
|
match *BACKEND {
|
||||||
// we have a wayland connection, go for it
|
Backend::Wayland => wayland::Window::new(builder).map(Window::Wayland),
|
||||||
let window = try!(wayland::Window::new(builder));
|
Backend::X => x11::Window::new(builder).map(Window::X),
|
||||||
Ok(Window::Wayland(window))
|
|
||||||
} else {
|
|
||||||
// fallback on X
|
|
||||||
let window = try!(x11::Window::new(builder));
|
|
||||||
Ok(Window::X(window))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue