Commit beed0062 authored by Matt Keeler's avatar Matt Keeler Committed by Peter van der meulen

Update to glutin 0.17

Changes:

• 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

Notes:

The Resized event emitted by glutin carrys a logical/pixel size but I suspect that previously it was a physical/point size
Resizing the terminal, window and renderer all need physical/point sizes so a conversion needs to be made when handling
resized events
parent b22999f1
......@@ -35,7 +35,7 @@ clap = "2"
fnv = "1"
unicode-width = "0.1"
arraydeque = "0.4"
glutin = "0.16"
glutin = "0.17"
env_logger = "0.5"
base64 = "0.9.0"
static_assertions = "0.2.5"
......
......@@ -2119,7 +2119,6 @@ enum Key {
LAlt,
LBracket,
LControl,
LMenu,
LShift,
LWin,
Mail,
......@@ -2144,7 +2143,6 @@ enum Key {
RAlt,
RBracket,
RControl,
RMenu,
RShift,
RWin,
Semicolon,
......@@ -2280,7 +2278,6 @@ impl Key {
Key::LAlt => LAlt,
Key::LBracket => LBracket,
Key::LControl => LControl,
Key::LMenu => LMenu,
Key::LShift => LShift,
Key::LWin => LWin,
Key::Mail => Mail,
......@@ -2305,7 +2302,6 @@ impl Key {
Key::RAlt => RAlt,
Key::RBracket => RBracket,
Key::RControl => RControl,
Key::RMenu => RMenu,
Key::RShift => RShift,
Key::RWin => RWin,
Key::Semicolon => Semicolon,
......
......@@ -18,7 +18,7 @@ use std::sync::mpsc;
use parking_lot::{MutexGuard};
use Rgb;
use {LogicalPosition, LogicalSize, PhysicalSize, Rgb};
use cli;
use config::Config;
use font::{self, Rasterize};
......@@ -27,7 +27,8 @@ use renderer::{self, GlyphCache, QuadRenderer};
use term::{Term, SizeInfo, RenderableCell};
use sync::FairMutex;
use window::{self, Size, Pixels, Window, SetInnerSize};
use window::{self, Window};
#[derive(Debug)]
pub enum Error {
......@@ -93,8 +94,8 @@ pub struct Display {
renderer: QuadRenderer,
glyph_cache: GlyphCache,
render_timer: bool,
rx: mpsc::Receiver<(u32, u32)>,
tx: mpsc::Sender<(u32, u32)>,
rx: mpsc::Receiver<LogicalSize>,
tx: mpsc::Sender<LogicalSize>,
meter: Meter,
font_size: font::Size,
size_info: SizeInfo,
......@@ -150,10 +151,10 @@ impl Display {
info!("device_pixel_ratio: {}", dpr);
// Create renderer
let mut renderer = QuadRenderer::new(config, viewport_size)?;
let mut renderer = QuadRenderer::new(config, viewport_size.to_physical(window.hidpi_factor()))?;
let (glyph_cache, cell_width, cell_height) =
Self::new_glyph_cache(dpr, &mut renderer, config)?;
Self::new_glyph_cache(dpr as f32, &mut renderer, config)?;
let dimensions = options.dimensions()
......@@ -164,21 +165,21 @@ impl Display {
let width = cell_width as u32 * dimensions.columns_u32();
let height = cell_height as u32 * dimensions.lines_u32();
let new_viewport_size = Size {
width: Pixels(width + 2 * u32::from(config.padding().x)),
height: Pixels(height + 2 * u32::from(config.padding().y)),
};
let new_viewport_size = LogicalSize::new(
(width + 2 * u32::from(config.padding().x)) as f64,
(height + 2 * u32::from(config.padding().y)) as f64);
window.set_inner_size(&new_viewport_size);
renderer.resize(new_viewport_size.width.0 as _, new_viewport_size.height.0 as _);
viewport_size = new_viewport_size
window.set_inner_size(new_viewport_size);
renderer.resize(new_viewport_size.to_physical(dpr));
viewport_size = new_viewport_size;
}
info!("Cell Size: ({} x {})", cell_width, cell_height);
let psize = viewport_size.to_physical(window.hidpi_factor());
let size_info = SizeInfo {
width: viewport_size.width.0 as f32,
height: viewport_size.height.0 as f32,
width: psize.width as f32,
height: psize.height as f32,
cell_width: cell_width as f32,
cell_height: cell_height as f32,
padding_x: f32::from(config.padding().x),
......@@ -263,7 +264,7 @@ impl Display {
}
#[inline]
pub fn resize_channel(&self) -> mpsc::Sender<(u32, u32)> {
pub fn resize_channel(&self) -> mpsc::Sender<LogicalSize> {
self.tx.clone()
}
......@@ -285,7 +286,10 @@ impl Display {
// Take most recent resize event, if any
while let Ok(sz) = self.rx.try_recv() {
new_size = Some(sz);
// Resize events are emitted via glutin/winit with logical sizes
// However the terminal, window and renderer use physical sizes
// so a conversion must be done here
new_size = Some(sz.to_physical(self.window.hidpi_factor()));
}
// Font size modification detected
......@@ -295,16 +299,16 @@ impl Display {
if new_size == None {
// Force a resize to refresh things
new_size = Some((self.size_info.width as u32,
self.size_info.height as u32));
new_size = Some(PhysicalSize::new(self.size_info.width as f64,
self.size_info.height as f64));
}
}
// Receive any resize events; only call gl::Viewport on last
// available
if let Some((w, h)) = new_size.take() {
self.size_info.width = w as f32;
self.size_info.height = h as f32;
if let Some(psize) = new_size.take() {
self.size_info.width = psize.width as f32;
self.size_info.height = psize.height as f32;
let size = &self.size_info;
terminal.resize(size);
......@@ -313,8 +317,8 @@ impl Display {
item.on_resize(size)
}
self.window.resize(w, h);
self.renderer.resize(w as i32, h as i32);
self.window.resize(psize);
self.renderer.resize(psize);
}
}
......@@ -412,7 +416,7 @@ impl Display {
padding_y: py, ..} = *terminal.size_info();
let nspot_y = (py + (row + 1) as f32 * ch) as i32;
let nspot_x = (px + col as f32 * cw) as i32;
self.window().set_ime_spot(nspot_x, nspot_y);
self.window().set_ime_spot(LogicalPosition::from((nspot_x, nspot_y)));
}
}
......@@ -23,6 +23,7 @@ use term::{Term, SizeInfo, TermMode};
use util::limit;
use util::fmt::Red;
use window::Window;
use LogicalSize;
/// Byte sequences are sent to a `Notify` in response to some events
pub trait Notify {
......@@ -230,7 +231,7 @@ pub struct Processor<N> {
wait_for_event: bool,
notifier: N,
mouse: Mouse,
resize_tx: mpsc::Sender<(u32, u32)>,
resize_tx: mpsc::Sender<LogicalSize>,
ref_test: bool,
size_info: SizeInfo,
hide_cursor_when_typing: bool,
......@@ -259,7 +260,7 @@ impl<N: Notify> Processor<N> {
/// pty.
pub fn new(
notifier: N,
resize_tx: mpsc::Sender<(u32, u32)>,
resize_tx: mpsc::Sender<LogicalSize>,
options: &Options,
config: &Config,
ref_test: bool,
......@@ -295,7 +296,7 @@ impl<N: Notify> Processor<N> {
processor: &mut input::Processor<'a, ActionContext<'a, N>>,
event: Event,
ref_test: bool,
resize_tx: &mpsc::Sender<(u32, u32)>,
resize_tx: &mpsc::Sender<LogicalSize>,
hide_cursor: &mut bool,
window_is_focused: &mut bool,
) {
......@@ -329,8 +330,8 @@ impl<N: Notify> Processor<N> {
// FIXME should do a more graceful shutdown
::std::process::exit(0);
},
Resized(w, h) => {
resize_tx.send((w, h)).expect("send new size");
Resized(lsize) => {
resize_tx.send(lsize).expect("send new size");
processor.ctx.terminal.dirty = true;
},
KeyboardInput { input, .. } => {
......@@ -351,9 +352,10 @@ impl<N: Notify> Processor<N> {
processor.ctx.terminal.dirty = true;
}
},
CursorMoved { position: (x, y), modifiers, .. } => {
let x = limit(x as i32, 0, processor.ctx.size_info.width as i32);
let y = limit(y as i32, 0, processor.ctx.size_info.height as i32);
CursorMoved { position: lpos, modifiers, .. } => {
let (x, y) = lpos.into();
let x: i32 = limit(x, 0, processor.ctx.size_info.width as i32);
let y: i32 = limit(y, 0, processor.ctx.size_info.height as i32);
*hide_cursor = false;
processor.mouse_moved(x as usize, y as usize, modifiers);
......
......@@ -507,14 +507,15 @@ impl<'a, A: ActionContext + 'a> Processor<'a, A> {
self.ctx.mouse_mut().lines_scrolled = to_scroll % 1.0;
},
MouseScrollDelta::PixelDelta(_x, y) => {
MouseScrollDelta::PixelDelta(lpos) => {
match phase {
TouchPhase::Started => {
// Reset offset to zero
self.ctx.mouse_mut().scroll_px = 0;
},
TouchPhase::Moved => {
self.ctx.mouse_mut().scroll_px += y as i32;
let (_x, y): (i32, i32) = lpos.into();
self.ctx.mouse_mut().scroll_px += y;
let height = self.ctx.size_info().cell_height as i32;
while self.ctx.mouse().scroll_px.abs() >= height {
......
......@@ -80,6 +80,9 @@ use std::ops::Mul;
pub use grid::Grid;
pub use term::Term;
/// Re-export size and position types from glutin/winit
pub use glutin::dpi::{PhysicalSize,LogicalSize,LogicalPosition,PhysicalPosition};
/// Facade around [winit's `MouseCursor`](glutin::MouseCursor)
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
pub enum MouseCursor {
......
......@@ -31,9 +31,7 @@ use notify::{Watcher, watcher, RecursiveMode, DebouncedEvent};
use config::{self, Config, Delta};
use term::{self, cell, RenderableCell};
use window::{Size, Pixels};
use Rgb;
use {PhysicalSize, Rgb};
// Shader paths for live reload
static TEXT_SHADER_F_PATH: &'static str = concat!(env!("CARGO_MANIFEST_DIR"), "/res/text.f.glsl");
......@@ -476,7 +474,7 @@ const ATLAS_SIZE: i32 = 1024;
impl QuadRenderer {
// TODO should probably hand this a transform instead of width/height
pub fn new(config: &Config, size: Size<Pixels<u32>>) -> Result<QuadRenderer, Error> {
pub fn new(config: &Config, size: PhysicalSize) -> Result<QuadRenderer, Error> {
let program = ShaderProgram::new(config, size)?;
let mut vao: GLuint = 0;
......@@ -636,10 +634,7 @@ impl QuadRenderer {
while let Ok(msg) = self.rx.try_recv() {
match msg {
Msg::ShaderReload => {
self.reload_shaders(config, Size {
width: Pixels(props.width as u32),
height: Pixels(props.height as u32)
});
self.reload_shaders(config, PhysicalSize::new(props.width as f64, props.height as f64));
}
}
}
......@@ -690,7 +685,7 @@ impl QuadRenderer {
})
}
pub fn reload_shaders(&mut self, config: &Config, size: Size<Pixels<u32>>) {
pub fn reload_shaders(&mut self, config: &Config, size: PhysicalSize) {
warn!("Reloading shaders ...");
let program = match ShaderProgram::new(config, size) {
Ok(program) => {
......@@ -718,13 +713,15 @@ impl QuadRenderer {
self.program = program;
}
pub fn resize(&mut self, width: i32, height: i32) {
pub fn resize(&mut self, size: PhysicalSize) {
let (width, height) : (u32, u32) = size.into();
let padding_x = i32::from(self.program.padding_x);
let padding_y = i32::from(self.program.padding_y);
// viewport
unsafe {
gl::Viewport(padding_x, padding_y, width - 2 * padding_x, height - 2 * padding_y);
gl::Viewport(padding_x, padding_y, (width as i32) - 2 * padding_x, (height as i32) - 2 * padding_y);
}
// update projection
......@@ -959,7 +956,7 @@ impl ShaderProgram {
pub fn new(
config: &Config,
size: Size<Pixels<u32>>
size: PhysicalSize
) -> Result<ShaderProgram, ShaderCreationError> {
let vertex_source = if cfg!(feature = "live-shader-reload") {
None
......@@ -1027,8 +1024,8 @@ impl ShaderProgram {
padding_y: config.padding().y,
};
shader.update_projection(*size.width as f32, *size.height as f32);
shader.update_projection(size.width as f32, size.height as f32);
shader.deactivate();
Ok(shader)
......
......@@ -12,17 +12,15 @@
// 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::{self, ContextBuilder, ControlFlow, Event, EventsLoop,
MouseCursor as GlutinMouseCursor, WindowBuilder};
use glutin::GlContext;
use glutin::{
self, ContextBuilder, ControlFlow, CursorState, Event, EventsLoop,
MouseCursor as GlutinMouseCursor, WindowBuilder,
};
use MouseCursor;
use {LogicalPosition, LogicalSize, MouseCursor, PhysicalSize};
use cli::Options;
use config::{Decorations, WindowConfig};
......@@ -83,7 +81,7 @@ pub struct DeviceProperties {
///
/// This will be 1. on standard displays and may have a different value on
/// hidpi displays.
pub scale_factor: f32,
pub scale_factor: f64,
}
/// Size of the window
......@@ -203,7 +201,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)
}
......@@ -251,20 +252,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]
......@@ -289,8 +291,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
......@@ -320,13 +322,7 @@ impl Window {
pub fn set_cursor_visible(&mut self, visible: bool) {
if visible != self.cursor_visible {
self.cursor_visible = visible;
if let Err(err) = self.window.set_cursor_state(if visible {
CursorState::Normal
} else {
CursorState::Hide
}) {
warn!("Failed to set cursor visibility: {}", err);
}
self.window.hide_cursor(!visible);
}
}
......@@ -421,8 +417,8 @@ impl Window {
)]
pub fn set_urgent(&self, _is_urgent: bool) {}
pub fn set_ime_spot(&self, x: i32, y: i32) {
self.window.set_ime_spot(x, y);
pub fn set_ime_spot(&self, pos: LogicalPosition) {
self.window.set_ime_spot(pos);
}
#[cfg(not(target_os = "macos"))]
......@@ -525,7 +521,6 @@ impl Proxy {
self.inner.wakeup().unwrap();
}
}
pub trait SetInnerSize<T> {
fn set_inner_size<S: ToPoints>(&mut self, size: &S);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment