Skip to content

Commit bda6cfe

Browse files
committed
Return a XNotSupported for new_x11()
1 parent 9a34e7f commit bda6cfe

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

src/os/unix.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,23 @@ use WindowBuilder;
1212
use platform::x11::XConnection;
1313
use platform::x11::ffi::XVisualInfo;
1414

15-
pub use platform::x11;
15+
pub use platform::XNotSupported;
1616

1717
/// Additional methods on `EventsLoop` that are specific to Linux.
1818
pub trait EventsLoopExt {
1919
/// Builds a new `EventsLoop` that is forced to use X11.
20-
fn new_x11() -> Self;
20+
fn new_x11() -> Result<Self, XNotSupported>
21+
where Self: Sized;
2122

2223
/// Builds a new `EventsLoop` that is forced to use Wayland.
23-
fn new_wayland() -> Self;
24+
fn new_wayland() -> Self
25+
where Self: Sized;
2426
}
2527

2628
impl EventsLoopExt for EventsLoop {
2729
#[inline]
28-
fn new_x11() -> Self {
29-
EventsLoop {
30-
events_loop: match LinuxEventsLoop::new_x11() {
31-
Ok(e) => e,
32-
Err(_) => panic!() // TODO: propagate
33-
}
34-
}
30+
fn new_x11() -> Result<Self, XNotSupported> {
31+
LinuxEventsLoop::new_x11().map(|ev| EventsLoop { events_loop: ev })
3532
}
3633

3734
#[inline]

src/platform/linux/mod.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ use libc;
99

1010
use self::x11::XConnection;
1111
use self::x11::XError;
12-
use self::x11::XNotSupported;
1312
use self::x11::ffi::XVisualInfo;
1413

14+
pub use self::x11::XNotSupported;
15+
1516
mod dlopen;
1617
pub mod wayland;
1718
pub mod x11;
@@ -285,10 +286,7 @@ impl EventsLoop {
285286
if let Ok(env_var) = env::var(BACKEND_PREFERENCE_ENV_VAR) {
286287
match env_var.as_str() {
287288
"x11" => {
288-
match EventsLoop::new_x11() {
289-
Ok(e) => return e,
290-
Err(_) => panic!() // TODO: propagate
291-
}
289+
return EventsLoop::new_x11().unwrap(); // TODO: propagate
292290
},
293291
"wayland" => {
294292
match EventsLoop::new_wayland() {
@@ -318,12 +316,11 @@ impl EventsLoop {
318316
.ok_or(())
319317
}
320318

321-
pub fn new_x11() -> Result<EventsLoop, ()> {
322-
if let Ok(ref x) = *X11_BACKEND {
323-
return Ok(EventsLoop::X(x11::EventsLoop::new(x.clone())));
319+
pub fn new_x11() -> Result<EventsLoop, XNotSupported> {
320+
match *X11_BACKEND {
321+
Ok(ref x) => Ok(EventsLoop::X(x11::EventsLoop::new(x.clone()))),
322+
Err(ref err) => Err(err.clone()),
324323
}
325-
326-
Err(())
327324
}
328325

329326
#[inline]

0 commit comments

Comments
 (0)