diff options
author | Matt Keeler <mkeeler@users.noreply.github.com> | 2018-11-10 11:08:48 -0500 |
---|---|---|
committer | Christian Duerr <chrisduerr@users.noreply.github.com> | 2018-11-10 16:08:48 +0000 |
commit | 2434547fce7bf47a848f088f2600e8ba7027a62b (patch) | |
tree | 551a50b1071e6208c76c9e26b38b40f60605f2c7 /src/window.rs | |
parent | 81617983bb4b3b17f18dab938bb572757aa54920 (diff) | |
download | alacritty-2434547fce7bf47a848f088f2600e8ba7027a62b.tar.gz alacritty-2434547fce7bf47a848f088f2600e8ba7027a62b.zip |
Upgrade Glutin to v0.19.0
Some changes include:
• Use the with_hardware_acceleration function on the ContextBuilder to not require the discrete GPU
• Remove the LMenu and RMenu virtual key codes (winit 0.16.0 removed these because Windows now generates LAlt and RAlt instead
• Replace set_cursor_state with hide_cursor (winit 0.16.0 removed the set_cursor_state function)
• Replace GlWindow::hidpi_factor with GlWindow::get_hidpi_factor and change to expecting an f64
• Use the glutin/winit dpi size and position types where possible
Glutin's dpi change event has been implemented. All size events now
return logical sizes. As a result of that, the logical sizes are translated
in the `display::handle_rezize` method so DPI scaling works correctly.
When the DPI is changed, the glyph cache is updated to make use of the
correct font size again.
Moving a window to a different screen which is a different DPI caused a
racing condition where the logical size of the event was sent to the
`handle_resize` method in `src/display.rs`, however if there was a DPI
change event before `handle_resize` is able to process this message, it
would incorrectly use the new DPI to scale the resize event.
To solve this issue instead of sending the logical size to the
`handle_resize` method and then converting it to a physical size in
there, the `LogicalSize` of the resize event is transformed into a
`PhysicalSize` as soon as it's received. This fixes potential racing
conditions since all events are processed in order.
The padding has been changed so it's also scaled by DPR.
The `scale_with_dpi` config option has been removed. If it's not present
a warning will be emitted.
The `winit` dependency on Windows has been removed. All interactions
with winit in Alacritty are handled through glutin.
Diffstat (limited to 'src/window.rs')
-rw-r--r-- | src/window.rs | 139 |
1 files changed, 24 insertions, 115 deletions
diff --git a/src/window.rs b/src/window.rs index cb753d40..a19fd9c5 100644 --- a/src/window.rs +++ b/src/window.rs @@ -12,21 +12,21 @@ // See the License for the specific language governing permissions and // limitations under the License. use std::convert::From; -use std::fmt::{self, Display}; -use std::ops::Deref; +use std::fmt::Display; use gl; use glutin::GlContext; #[cfg(windows)] -use winit::Icon; +use glutin::Icon; #[cfg(windows)] use image::ImageFormat; use glutin::{ - self, ContextBuilder, ControlFlow, CursorState, Event, EventsLoop, + self, ContextBuilder, ControlFlow, Event, EventsLoop, MouseCursor as GlutinMouseCursor, WindowBuilder, }; -use MouseCursor; +use {LogicalPosition, LogicalSize, MouseCursor, PhysicalSize}; + use cli::Options; use config::{Decorations, WindowConfig}; @@ -90,82 +90,7 @@ pub struct DeviceProperties { /// /// This will be 1. on standard displays and may have a different value on /// hidpi displays. - pub scale_factor: f32, -} - -/// Size of the window -#[derive(Debug, Copy, Clone)] -pub struct Size<T> { - pub width: T, - pub height: T, -} - -/// Strongly typed Pixels unit -#[derive(Debug, Copy, Clone)] -pub struct Pixels<T>(pub T); - -/// Strongly typed Points unit -/// -/// Points are like pixels but adjusted for DPI. -#[derive(Debug, Copy, Clone)] -pub struct Points<T>(pub T); - -pub trait ToPoints { - fn to_points(&self, scale: f32) -> Size<Points<u32>>; -} - -impl ToPoints for Size<Points<u32>> { - #[inline] - fn to_points(&self, _scale: f32) -> Size<Points<u32>> { - *self - } -} - -impl ToPoints for Size<Pixels<u32>> { - fn to_points(&self, scale: f32) -> Size<Points<u32>> { - let width_pts = (*self.width as f32 / scale) as u32; - let height_pts = (*self.height as f32 / scale) as u32; - - Size { - width: Points(width_pts), - height: Points(height_pts), - } - } -} - -impl<T: Display> Display for Size<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{} × {}", self.width, self.height) - } -} - -macro_rules! deref_newtype { - ($($src:ty),+) => { - $( - impl<T> Deref for $src { - type Target = T; - - #[inline] - fn deref(&self) -> &Self::Target { - &self.0 - } - } - )+ - } -} - -deref_newtype! { Points<T>, Pixels<T> } - -impl<T: Display> Display for Pixels<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}px", self.0) - } -} - -impl<T: Display> Display for Points<T> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}pts", self.0) - } + pub scale_factor: f64, } impl ::std::error::Error for Error { @@ -210,7 +135,10 @@ fn create_gl_window( event_loop: &EventsLoop, srgb: bool, ) -> ::std::result::Result<glutin::GlWindow, glutin::CreationError> { - let context = ContextBuilder::new().with_srgb(srgb).with_vsync(true); + let context = ContextBuilder::new() + .with_srgb(srgb) + .with_vsync(true) + .with_hardware_acceleration(None); ::glutin::GlWindow::new(window, context, event_loop) } @@ -258,20 +186,21 @@ impl Window { /// rasterization depend on DPI and scale factor. pub fn device_properties(&self) -> DeviceProperties { DeviceProperties { - scale_factor: self.window.hidpi_factor(), + scale_factor: self.window.get_hidpi_factor(), } } - pub fn inner_size_pixels(&self) -> Option<Size<Pixels<u32>>> { - self.window.get_inner_size().map(|(w, h)| Size { - width: Pixels(w), - height: Pixels(h), - }) + pub fn inner_size_pixels(&self) -> Option<LogicalSize> { + self.window.get_inner_size() + } + + pub fn set_inner_size(&mut self, size: LogicalSize) { + self.window.set_inner_size(size); } #[inline] - pub fn hidpi_factor(&self) -> f32 { - self.window.hidpi_factor() + pub fn hidpi_factor(&self) -> f64 { + self.window.get_hidpi_factor() } #[inline] @@ -296,8 +225,8 @@ impl Window { } #[inline] - pub fn resize(&self, width: u32, height: u32) { - self.window.resize(width, height); + pub fn resize(&self, size: PhysicalSize) { + self.window.resize(size); } /// Block waiting for events @@ -330,13 +259,7 @@ impl Window { pub fn set_mouse_visible(&mut self, visible: bool) { if visible != self.mouse_visible { self.mouse_visible = visible; - if let Err(err) = self.window.set_cursor_state(if visible { - CursorState::Normal - } else { - CursorState::Hide - }) { - warn!("Failed to set mouse cursor visibility: {}", err); - } + self.window.hide_cursor(!visible); } } @@ -448,10 +371,8 @@ impl Window { )] pub fn set_urgent(&self, _is_urgent: bool) {} - pub fn set_ime_spot(&self, _x: i32, _y: i32) { - // This is not implemented on windows as of winit 0.15.1 - #[cfg(not(windows))] - self.window.set_ime_spot(_x, _y); + pub fn set_ime_spot(&self, pos: LogicalPosition) { + self.window.set_ime_spot(pos); } #[cfg(not(any(target_os = "macos", target_os = "windows")))] @@ -554,15 +475,3 @@ impl Proxy { self.inner.wakeup().unwrap(); } } - -pub trait SetInnerSize<T> { - fn set_inner_size<S: ToPoints>(&mut self, size: &S); -} - -impl SetInnerSize<Pixels<u32>> for Window { - fn set_inner_size<T: ToPoints>(&mut self, size: &T) { - let size = size.to_points(self.hidpi_factor()); - self.window - .set_inner_size(*size.width as _, *size.height as _); - } -} |