diff --git a/ports/cef/core.rs b/ports/cef/core.rs index dbd7985539b..04218bd9ae9 100644 --- a/ports/cef/core.rs +++ b/ports/cef/core.rs @@ -5,6 +5,7 @@ use command_line::command_line_init; use interfaces::cef_app_t; use types::{cef_main_args_t, cef_settings_t}; +use window::init_window; use libc::{c_char, c_int, c_void}; use util::opts; @@ -67,6 +68,8 @@ pub extern "C" fn cef_initialize(args: *const cef_main_args_t, temp_opts.resources_path = None; opts::set(temp_opts); + init_window(); + return 1 } diff --git a/ports/cef/window.rs b/ports/cef/window.rs index 06104484475..fd93081b1d6 100644 --- a/ports/cef/window.rs +++ b/ports/cef/window.rs @@ -35,13 +35,14 @@ extern crate x11; #[cfg(target_os="linux")] use self::x11::xlib::XOpenDisplay; +#[cfg(target_os="linux")] +pub static mut DISPLAY: *mut c_void = 0 as *mut c_void; + /// The type of an off-screen window. #[allow(raw_pointer_derive)] #[derive(Clone)] pub struct Window { cef_browser: RefCell>, -#[cfg(target_os="linux")] - display: *mut c_void, } #[cfg(target_os="macos")] @@ -76,16 +77,6 @@ fn load_gl() { impl Window { /// Creates a new window. -#[cfg(target_os="linux")] - pub fn new() -> Rc { - load_gl(); - - Rc::new(Window { - cef_browser: RefCell::new(None), - display: unsafe { XOpenDisplay(ptr::null()) as *mut c_void }, - }) - } -#[cfg(not(target_os="linux"))] pub fn new() -> Rc { load_gl(); @@ -246,8 +237,10 @@ impl WindowMethods for Window { #[cfg(target_os="linux")] fn native_metadata(&self) -> NativeGraphicsMetadata { - NativeGraphicsMetadata { - display: self.display, + unsafe { + NativeGraphicsMetadata { + display: DISPLAY, + } } } @@ -389,3 +382,20 @@ impl CompositorProxy for CefCompositorProxy { } } +#[cfg(target_os="linux")] +pub fn init_window() { + unsafe { DISPLAY = XOpenDisplay(ptr::null()) as *mut c_void ; } +} +#[cfg(not(target_os="linux"))] +pub fn init_window() {} + +#[cfg(target_os="linux")] +#[no_mangle] +pub extern "C" fn cef_get_xdisplay() -> *mut c_void { + unsafe { DISPLAY } +} +#[cfg(not(target_os="linux"))] +#[no_mangle] +pub extern "C" fn cef_get_xdisplay() -> *mut c_void { + ptr::null_mut() +}