diff options
author | Christian Duerr <chrisduerr@users.noreply.github.com> | 2019-04-04 23:11:29 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-04 23:11:29 +0000 |
commit | f0dbfc9b9c6514bc60e271bb74c2970e645d998f (patch) | |
tree | 2615f12f1335c7d80394d6c6d96dbdd01708c6ad /src | |
parent | 5776ec09d6d56540549fc513273ae511d3316f22 (diff) | |
download | alacritty-f0dbfc9b9c6514bc60e271bb74c2970e645d998f.tar.gz alacritty-f0dbfc9b9c6514bc60e271bb74c2970e645d998f.zip |
Fix build errors on BSDv0.3.0-rc3
This updates winit and glutin to the latest git versions instead of
relying on releases to fix a build failure on BSD.
Unfortunately the upstream version bumps might still take a bit and
there hasn't been any feedback with regards to a planned release date.
This also fixes a slight issue on Windows where selections would start
when focusing a window and a build failure with some Linux systems
Fixes #2243.
Fixes #2170.
Fixes #2244.
Diffstat (limited to 'src')
-rw-r--r-- | src/window.rs | 69 |
1 files changed, 38 insertions, 31 deletions
diff --git a/src/window.rs b/src/window.rs index 85dee273..6e3d7cdc 100644 --- a/src/window.rs +++ b/src/window.rs @@ -21,7 +21,8 @@ use glutin::os::unix::EventsLoopExt; #[cfg(windows)] use glutin::Icon; use glutin::{ - self, ContextBuilder, ContextTrait, ControlFlow, Event, EventsLoop, MouseCursor, WindowBuilder, + self, ContextBuilder, ContextTrait, ControlFlow, Event, EventsLoop, MouseCursor, + PossiblyCurrentContext, PossiblyCurrentContextTrait, WindowBuilder, }; #[cfg(windows)] use image::ImageFormat; @@ -53,7 +54,7 @@ type Result<T> = ::std::result::Result<T, Error>; /// Wraps the underlying windowing library to provide a stable API in Alacritty pub struct Window { event_loop: EventsLoop, - window: glutin::WindowedContext, + windowed_context: glutin::WindowedContext<PossiblyCurrentContext>, mouse_visible: bool, /// Whether or not the window is the focused window. @@ -118,12 +119,17 @@ fn create_gl_window( window: WindowBuilder, event_loop: &EventsLoop, srgb: bool, -) -> ::std::result::Result<glutin::WindowedContext, glutin::CreationError> { - ContextBuilder::new() +) -> Result<glutin::WindowedContext<PossiblyCurrentContext>> { + let windowed_context = ContextBuilder::new() .with_srgb(srgb) .with_vsync(true) .with_hardware_acceleration(None) - .build_windowed(window, event_loop) + .build_windowed(window, event_loop)?; + + // Make the context current so OpenGL operations can run + let windowed_context = unsafe { windowed_context.make_current().map_err(|(_, e)| e)? }; + + Ok(windowed_context) } impl Window { @@ -136,8 +142,9 @@ impl Window { let title = options.title.as_ref().map_or(DEFAULT_NAME, |t| t); let class = options.class.as_ref().map_or(DEFAULT_NAME, |c| c); let window_builder = Window::get_platform_window(title, class, window_config); - let window = create_gl_window(window_builder.clone(), &event_loop, false) + let windowed_context = create_gl_window(window_builder.clone(), &event_loop, false) .or_else(|_| create_gl_window(window_builder, &event_loop, true))?; + let window = windowed_context.window(); window.show(); // Maximize window after mapping in X11 @@ -151,15 +158,11 @@ impl Window { // Text cursor window.set_cursor(MouseCursor::Text); - // Make the context current so OpenGL operations can run - unsafe { - window.make_current()?; - } - // Set OpenGL symbol loader. This call MUST be after window.make_current on windows. - gl::load_with(|symbol| window.get_proc_address(symbol) as *const _); + gl::load_with(|symbol| windowed_context.get_proc_address(symbol) as *const _); - let window = Window { event_loop, window, mouse_visible: true, is_focused: false }; + let window = + Window { event_loop, windowed_context, mouse_visible: true, is_focused: false }; window.run_os_extensions(); @@ -171,27 +174,27 @@ impl Window { /// Some window properties are provided since subsystems like font /// rasterization depend on DPI and scale factor. pub fn device_properties(&self) -> DeviceProperties { - DeviceProperties { scale_factor: self.window.get_hidpi_factor() } + DeviceProperties { scale_factor: self.window().get_hidpi_factor() } } pub fn inner_size_pixels(&self) -> Option<LogicalSize> { - self.window.get_inner_size() + self.window().get_inner_size() } pub fn set_inner_size(&mut self, size: LogicalSize) { - self.window.set_inner_size(size); + self.window().set_inner_size(size); } // TODO: use `with_position` once available // Upstream issue: https://github.com/tomaka/winit/issues/806 pub fn set_position(&mut self, x: i32, y: i32) { - let logical = PhysicalPosition::from((x, y)).to_logical(self.window.get_hidpi_factor()); - self.window.set_position(logical); + let logical = PhysicalPosition::from((x, y)).to_logical(self.window().get_hidpi_factor()); + self.window().set_position(logical); } #[inline] pub fn hidpi_factor(&self) -> f64 { - self.window.get_hidpi_factor() + self.window().get_hidpi_factor() } #[inline] @@ -201,7 +204,7 @@ impl Window { #[inline] pub fn swap_buffers(&self) -> Result<()> { - self.window.swap_buffers().map_err(From::from) + self.windowed_context.swap_buffers().map_err(From::from) } /// Poll for any available events @@ -215,7 +218,7 @@ impl Window { #[inline] pub fn resize(&self, size: PhysicalSize) { - self.window.resize(size); + self.windowed_context.resize(size); } /// Block waiting for events @@ -230,19 +233,19 @@ impl Window { /// Set the window title #[inline] pub fn set_title(&self, title: &str) { - self.window.set_title(title); + self.window().set_title(title); } #[inline] pub fn set_mouse_cursor(&self, cursor: MouseCursor) { - self.window.set_cursor(cursor); + self.window().set_cursor(cursor); } /// Set mouse cursor visible pub fn set_mouse_visible(&mut self, visible: bool) { if visible != self.mouse_visible { self.mouse_visible = visible; - self.window.hide_cursor(!visible); + self.window().hide_cursor(!visible); } } @@ -330,27 +333,27 @@ impl Window { ))] pub fn set_urgent(&self, is_urgent: bool) { use glutin::os::unix::WindowExt; - self.window.set_urgent(is_urgent); + self.window().set_urgent(is_urgent); } #[cfg(target_os = "macos")] pub fn set_urgent(&self, is_urgent: bool) { use glutin::os::macos::WindowExt; - self.window.request_user_attention(is_urgent); + self.window().request_user_attention(is_urgent); } #[cfg(windows)] pub fn set_urgent(&self, _is_urgent: bool) {} pub fn set_ime_spot(&self, pos: LogicalPosition) { - self.window.set_ime_spot(pos); + self.window().set_ime_spot(pos); } #[cfg(not(any(target_os = "macos", target_os = "windows")))] pub fn get_window_id(&self) -> Option<usize> { use glutin::os::unix::WindowExt; - match self.window.get_xlib_window() { + match self.window().get_xlib_window() { Some(xlib_window) => Some(xlib_window as usize), None => None, } @@ -363,7 +366,11 @@ impl Window { /// Hide the window pub fn hide(&self) { - self.window.hide(); + self.window().hide(); + } + + fn window(&self) -> &glutin::Window { + self.windowed_context.window() } } @@ -393,8 +400,8 @@ impl OsExtensions for Window { use std::ptr; use x11_dl::xlib::{self, PropModeReplace, XA_CARDINAL}; - let xlib_display = self.window.get_xlib_display(); - let xlib_window = self.window.get_xlib_window(); + let xlib_display = self.window().get_xlib_display(); + let xlib_window = self.window().get_xlib_window(); if let (Some(xlib_window), Some(xlib_display)) = (xlib_window, xlib_display) { let xlib = xlib::Xlib::open().expect("get xlib"); |