Repository: alacritty/alacritty
File: alacritty/src/renderer/platform.rs (Rust)

Code before:
#[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
use winit::platform::x11;

/// Create the GL display.
pub fn create_gl_display(
    raw_display_handle: RawDisplayHandle,
    display_api: DisplayApiPreference,
) -> GlutinResult<Display> {
    let display = unsafe { Display::new(raw_display_handle, display_api)? };
    log::info!("Using {}", { display.version_string() });
    Ok(display)
}

pub fn preferred_display_api(_raw_window_handle: Option<RawWindowHandle>) -> DisplayApiPreference {
    #[cfg(target_os = "macos")]
    return DisplayApiPreference::Cgl;

    #[cfg(windows)]
    return DisplayApiPreference::Wgl(Some(_raw_window_handle.unwrap()));

    #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
    {
        let egl_over_glx = match env::var("EGL_OVER_GLX") {
            Ok(egl) => egl,
            Err(_) => panic!("Could not find environment variable 'EGL_OVER_GLX'"),
        };

        if matches!(egl_over_glx.as_ref(), "yes" | "true" | "1") {
            DisplayApiPreference::EglThenGlx(Box::new(x11::register_xlib_error_hook))
        } else {
            DisplayApiPreference::GlxThenEgl(Box::new(x11::register_xlib_error_hook))
        }
    }

    #[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))]
    return DisplayApiPreference::Egl;
}

pub fn pick_gl_config(
    gl_display: &Display,
    raw_window_handle: Option<RawWindowHandle>,
) -> Result<Config, String> {
    let mut default_config = ConfigTemplateBuilder::new()
        .with_depth_size(0)
        .with_stencil_size(0)
        .with_transparency(true);

    if let Some(raw_window_handle) = raw_window_handle {
        default_config = default_config.compatible_with_native_window(raw_window_handle);
    }


Review comment (suggestion):
No need to do any sort of panics like that it's just error prone, simply handle good value and use prefer otherwise use standard behavior.

So it'll be 
```rust
Ok("1") => DisplayApiPreference::EglThenGlx(Box::new(x11::register_xlib_error_hook)), // Or wgl
_ => // default
```

Code after:

/// Create the GL display.
pub fn create_gl_display(
    raw_display_handle: RawDisplayHandle,
    _raw_window_handle: Option<RawWindowHandle>,
    _prefer_egl: bool,
) -> GlutinResult<Display> {
    #[cfg(target_os = "macos")]
    let preference = DisplayApiPreference::Cgl;

    #[cfg(windows)]
    let preference = if _prefer_egl {
        DisplayApiPreference::EglThenWgl(Some(_raw_window_handle.unwrap()))
    } else {
        DisplayApiPreference::WglThenEgl(Some(_raw_window_handle.unwrap()))
    };

    #[cfg(all(feature = "x11", not(any(target_os = "macos", windows))))]
    let preference = if _prefer_egl {
        DisplayApiPreference::EglThenGlx(Box::new(x11::register_xlib_error_hook))
    } else {
        DisplayApiPreference::GlxThenEgl(Box::new(x11::register_xlib_error_hook))
    };

    #[cfg(all(not(feature = "x11"), not(any(target_os = "macos", windows))))]
    let preference = DisplayApiPreference::Egl;

    let display = unsafe { Display::new(raw_display_handle, preference)? };
    log::info!("Using {}", { display.version_string() });
    Ok(display)
}

pub fn pick_gl_config(
    gl_display: &Display,
    raw_window_handle: Option<RawWindowHandle>,
) -> Result<Config, String> {
    let mut default_config = ConfigTemplateBuilder::new()
        .with_depth_size(0)
        .with_stencil_size(0)
        .with_transparency(true);

    if let Some(raw_window_handle) = raw_window_handle {
        default_config = default_config.compatible_with_native_window(raw_window_handle);
    }

    let config_10bit = default_config
        .clone()
        .with_buffer_type(ColorBufferType::Rgb { r_size: 10, g_size: 10, b_size: 10 })
        .with_alpha_size(2);

    let configs = [