do not use events_loop during run_forever

This commit is contained in:
Paul Rouget 2018-02-21 02:20:39 +01:00
parent f9a56e5915
commit 4f72fb8e99

View file

@ -175,6 +175,7 @@ enum WindowKind {
/// The type of a window. /// The type of a window.
pub struct Window { pub struct Window {
kind: WindowKind, kind: WindowKind,
screen: Size2D<u32>,
mouse_down_button: Cell<Option<glutin::MouseButton>>, mouse_down_button: Cell<Option<glutin::MouseButton>>,
mouse_down_point: Cell<Point2D<i32>>, mouse_down_point: Cell<Point2D<i32>>,
@ -229,10 +230,14 @@ impl Window {
// #9996. // #9996.
let visible = is_foreground && !opts::get().no_native_titlebar; let visible = is_foreground && !opts::get().no_native_titlebar;
let screen;
let window_kind = if opts::get().headless { let window_kind = if opts::get().headless {
screen = Size2D::new(width, height);
WindowKind::Headless(HeadlessContext::new(width, height)) WindowKind::Headless(HeadlessContext::new(width, height))
} else { } else {
let events_loop = glutin::EventsLoop::new(); let events_loop = glutin::EventsLoop::new();
let (screen_width, screen_height) = events_loop.get_primary_monitor().get_dimensions();
screen = Size2D::new(screen_width, screen_height);
let mut window_builder = glutin::WindowBuilder::new() let mut window_builder = glutin::WindowBuilder::new()
.with_title("Servo".to_string()) .with_title("Servo".to_string())
.with_decorations(!opts::get().no_native_titlebar) .with_decorations(!opts::get().no_native_titlebar)
@ -314,6 +319,7 @@ impl Window {
gl: gl.clone(), gl: gl.clone(),
animation_state: Cell::new(AnimationState::Idle), animation_state: Cell::new(AnimationState::Idle),
fullscreen: Cell::new(false), fullscreen: Cell::new(false),
screen,
}; };
window.present(); window.present();
@ -887,15 +893,7 @@ impl WindowMethods for Window {
} }
fn screen_size(&self, _: BrowserId) -> Size2D<u32> { fn screen_size(&self, _: BrowserId) -> Size2D<u32> {
match self.kind { self.screen
WindowKind::Window(_, ref events_loop) => {
let (width, height) = events_loop.borrow().get_primary_monitor().get_dimensions();
Size2D::new(width, height)
}
WindowKind::Headless(ref context) => {
Size2D::new(context.width, context.height)
}
}
} }
fn screen_avail_size(&self, browser_id: BrowserId) -> Size2D<u32> { fn screen_avail_size(&self, browser_id: BrowserId) -> Size2D<u32> {