Upgrade winit backend to 0.17
This commit is contained in:
parent
ae5b9e55f4
commit
ffdf245259
|
@ -19,7 +19,7 @@ slog = "2.1.1"
|
|||
slog-stdlog = "3.0.2"
|
||||
libloading = "0.4.0"
|
||||
wayland-client = { version = "0.20.5", optional = true }
|
||||
winit = { version = "0.14.0", optional = true }
|
||||
winit = { version = "0.17.0", optional = true }
|
||||
drm = { version = "^0.3.1", optional = true }
|
||||
gbm = { version = "^0.4.0", optional = true, default-features = false, features = ["drm-support"] }
|
||||
glium = { version = "0.19.0", optional = true, default-features = false }
|
||||
|
|
|
@ -187,8 +187,10 @@ unsafe impl NativeDisplay<Wayland> for WinitWindow {
|
|||
|
||||
fn create_surface(&self, _args: ()) -> Result<wegl::WlEglSurface> {
|
||||
if let Some(surface) = self.get_wayland_surface() {
|
||||
let (w, h) = self.get_inner_size().unwrap();
|
||||
Ok(unsafe { wegl::WlEglSurface::new_from_raw(surface as *mut _, w as i32, h as i32) })
|
||||
let size = self.get_inner_size().unwrap();
|
||||
Ok(unsafe {
|
||||
wegl::WlEglSurface::new_from_raw(surface as *mut _, size.width as i32, size.height as i32)
|
||||
})
|
||||
} else {
|
||||
bail!(ErrorKind::NonMatchingBackend("Wayland"))
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ use std::rc::Rc;
|
|||
use std::time::Instant;
|
||||
use wayland_client::egl as wegl;
|
||||
use wayland_server::Display;
|
||||
use winit::dpi::{LogicalPosition, LogicalSize};
|
||||
use winit::{
|
||||
ElementState, Event, EventsLoop, KeyboardInput, MouseButton as WinitMouseButton, MouseCursor,
|
||||
MouseScrollDelta, Touch, TouchPhase, Window as WinitWindow, WindowBuilder, WindowEvent,
|
||||
|
@ -95,7 +96,7 @@ where
|
|||
{
|
||||
init_from_builder(
|
||||
WindowBuilder::new()
|
||||
.with_dimensions(1280, 800)
|
||||
.with_dimensions(LogicalSize::new(1280.0, 800.0))
|
||||
.with_title("Smithay")
|
||||
.with_visibility(true),
|
||||
logger,
|
||||
|
@ -214,7 +215,12 @@ impl GraphicsBackend for WinitGraphicsBackend {
|
|||
|
||||
fn set_cursor_position(&self, x: u32, y: u32) -> ::std::result::Result<(), ()> {
|
||||
debug!(self.logger, "Setting cursor position to {:?}", (x, y));
|
||||
self.window.window().set_cursor_position(x as i32, y as i32)
|
||||
self.window
|
||||
.window()
|
||||
.set_cursor_position(LogicalPosition::new(x as f64, y as f64))
|
||||
.map_err(|err| {
|
||||
debug!(self.logger, "{}", err);
|
||||
})
|
||||
}
|
||||
|
||||
fn set_cursor_representation(
|
||||
|
@ -251,6 +257,7 @@ impl EGLGraphicsBackend for WinitGraphicsBackend {
|
|||
.window()
|
||||
.get_inner_size()
|
||||
.expect("Window does not exist anymore")
|
||||
.into()
|
||||
}
|
||||
|
||||
fn is_current(&self) -> bool {
|
||||
|
@ -369,16 +376,24 @@ impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent {
|
|||
|
||||
fn x_transformed(&self, width: u32) -> u32 {
|
||||
cmp::max(
|
||||
(self.x * width as f64 / self.window.window().get_inner_size().unwrap_or((width, 0)).0 as f64)
|
||||
as i32,
|
||||
(self.x * width as f64 / self
|
||||
.window
|
||||
.window()
|
||||
.get_inner_size()
|
||||
.unwrap_or(LogicalSize::new(width.into(), 0.0))
|
||||
.width) as i32,
|
||||
0,
|
||||
) as u32
|
||||
}
|
||||
|
||||
fn y_transformed(&self, height: u32) -> u32 {
|
||||
cmp::max(
|
||||
(self.y * height as f64 / self.window.window().get_inner_size().unwrap_or((0, height)).1 as f64)
|
||||
as i32,
|
||||
(self.y * height as f64 / self
|
||||
.window
|
||||
.window()
|
||||
.get_inner_size()
|
||||
.unwrap_or(LogicalSize::new(0.0, height.into()))
|
||||
.height) as i32,
|
||||
0,
|
||||
) as u32
|
||||
}
|
||||
|
@ -401,14 +416,14 @@ impl PointerAxisEvent for WinitMouseWheelEvent {
|
|||
fn source(&self) -> AxisSource {
|
||||
match self.delta {
|
||||
MouseScrollDelta::LineDelta(_, _) => AxisSource::Wheel,
|
||||
MouseScrollDelta::PixelDelta(_, _) => AxisSource::Continuous,
|
||||
MouseScrollDelta::PixelDelta(_) => AxisSource::Continuous,
|
||||
}
|
||||
}
|
||||
|
||||
fn amount(&self, axis: &Axis) -> Option<f64> {
|
||||
match (axis, self.delta) {
|
||||
(&Axis::Horizontal, MouseScrollDelta::PixelDelta(x, _)) => Some(x as f64),
|
||||
(&Axis::Vertical, MouseScrollDelta::PixelDelta(_, y)) => Some(y as f64),
|
||||
(&Axis::Horizontal, MouseScrollDelta::PixelDelta(delta)) => Some(delta.x),
|
||||
(&Axis::Vertical, MouseScrollDelta::PixelDelta(delta)) => Some(delta.y),
|
||||
(_, MouseScrollDelta::LineDelta(_, _)) => None,
|
||||
}
|
||||
}
|
||||
|
@ -417,7 +432,7 @@ impl PointerAxisEvent for WinitMouseWheelEvent {
|
|||
match (axis, self.delta) {
|
||||
(&Axis::Horizontal, MouseScrollDelta::LineDelta(x, _)) => Some(x as f64),
|
||||
(&Axis::Vertical, MouseScrollDelta::LineDelta(_, y)) => Some(y as f64),
|
||||
(_, MouseScrollDelta::PixelDelta(_, _)) => None,
|
||||
(_, MouseScrollDelta::PixelDelta(_)) => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -476,16 +491,24 @@ impl TouchDownEvent for WinitTouchStartedEvent {
|
|||
|
||||
fn x_transformed(&self, width: u32) -> u32 {
|
||||
cmp::min(
|
||||
self.location.0 as i32 * width as i32
|
||||
/ self.window.window().get_inner_size().unwrap_or((width, 0)).0 as i32,
|
||||
self.location.0 as i32 * width as i32 / self
|
||||
.window
|
||||
.window()
|
||||
.get_inner_size()
|
||||
.unwrap_or(LogicalSize::new(width.into(), 0.0))
|
||||
.width as i32,
|
||||
0,
|
||||
) as u32
|
||||
}
|
||||
|
||||
fn y_transformed(&self, height: u32) -> u32 {
|
||||
cmp::min(
|
||||
self.location.1 as i32 * height as i32
|
||||
/ self.window.window().get_inner_size().unwrap_or((0, height)).1 as i32,
|
||||
self.location.1 as i32 * height as i32 / self
|
||||
.window
|
||||
.window()
|
||||
.get_inner_size()
|
||||
.unwrap_or(LogicalSize::new(0.0, height.into()))
|
||||
.height as i32,
|
||||
0,
|
||||
) as u32
|
||||
}
|
||||
|
@ -520,11 +543,21 @@ impl TouchMotionEvent for WinitTouchMovedEvent {
|
|||
}
|
||||
|
||||
fn x_transformed(&self, width: u32) -> u32 {
|
||||
self.location.0 as u32 * width / self.window.window().get_inner_size().unwrap_or((width, 0)).0
|
||||
self.location.0 as u32 * width / self
|
||||
.window
|
||||
.window()
|
||||
.get_inner_size()
|
||||
.unwrap_or(LogicalSize::new(width.into(), 0.0))
|
||||
.width as u32
|
||||
}
|
||||
|
||||
fn y_transformed(&self, height: u32) -> u32 {
|
||||
self.location.1 as u32 * height / self.window.window().get_inner_size().unwrap_or((0, height)).1
|
||||
self.location.1 as u32 * height / self
|
||||
.window
|
||||
.window()
|
||||
.get_inner_size()
|
||||
.unwrap_or(LogicalSize::new(0.0, height.into()))
|
||||
.height as u32
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -666,23 +699,25 @@ impl InputBackend for WinitInputBackend {
|
|||
let nanos = duration.subsec_nanos() as u64;
|
||||
let time = ((1000 * duration.as_secs()) + (nanos / 1_000_000)) as u32;
|
||||
match (event, handler.as_mut(), events_handler.as_mut()) {
|
||||
(WindowEvent::Resized(w, h), _, events_handler) => {
|
||||
trace!(logger, "Resizing window to {:?}", (w, h));
|
||||
window.window().set_inner_size(w, h);
|
||||
(WindowEvent::Resized(size), _, events_handler) => {
|
||||
trace!(logger, "Resizing window to {:?}", size);
|
||||
window.window().set_inner_size(size);
|
||||
if let Window::Wayland { ref surface, .. } = **window {
|
||||
surface.resize(w as i32, h as i32, 0, 0);
|
||||
surface.resize(size.width as i32, size.height as i32, 0, 0);
|
||||
}
|
||||
if let Some(events_handler) = events_handler {
|
||||
events_handler.resized(w, h);
|
||||
events_handler.resized(size.width as u32, size.height as u32);
|
||||
}
|
||||
}
|
||||
(WindowEvent::Moved(x, y), _, Some(events_handler)) => events_handler.moved(x, y),
|
||||
(WindowEvent::Moved(position), _, Some(events_handler)) => {
|
||||
events_handler.moved(position.x as i32, position.y as i32)
|
||||
}
|
||||
(WindowEvent::Focused(focus), _, Some(events_handler)) => {
|
||||
events_handler.focus_changed(focus)
|
||||
}
|
||||
(WindowEvent::Refresh, _, Some(events_handler)) => events_handler.refresh(),
|
||||
(WindowEvent::HiDPIFactorChanged(factor), _, Some(events_handler)) => {
|
||||
events_handler.hidpi_changed(factor)
|
||||
(WindowEvent::HiDpiFactorChanged(factor), _, Some(events_handler)) => {
|
||||
events_handler.hidpi_changed(factor as f32)
|
||||
}
|
||||
(
|
||||
WindowEvent::KeyboardInput {
|
||||
|
@ -709,15 +744,15 @@ impl InputBackend for WinitInputBackend {
|
|||
},
|
||||
)
|
||||
}
|
||||
(WindowEvent::CursorMoved { position: (x, y), .. }, Some(handler), _) => {
|
||||
trace!(logger, "Calling on_pointer_move_absolute with {:?}", (x, y));
|
||||
(WindowEvent::CursorMoved { position, .. }, Some(handler), _) => {
|
||||
trace!(logger, "Calling on_pointer_move_absolute with {:?}", position);
|
||||
handler.on_pointer_move_absolute(
|
||||
seat,
|
||||
WinitMouseMovedEvent {
|
||||
window: window.clone(),
|
||||
time,
|
||||
x,
|
||||
y,
|
||||
x: position.x,
|
||||
y: position.y,
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -733,20 +768,20 @@ impl InputBackend for WinitInputBackend {
|
|||
(
|
||||
WindowEvent::Touch(Touch {
|
||||
phase: TouchPhase::Started,
|
||||
location: (x, y),
|
||||
location,
|
||||
id,
|
||||
..
|
||||
}),
|
||||
Some(handler),
|
||||
_,
|
||||
) => {
|
||||
trace!(logger, "Calling on_touch_down at {:?}", (x, y));
|
||||
trace!(logger, "Calling on_touch_down at {:?}", location);
|
||||
handler.on_touch_down(
|
||||
seat,
|
||||
WinitTouchStartedEvent {
|
||||
window: window.clone(),
|
||||
time,
|
||||
location: (x, y),
|
||||
location: location.into(),
|
||||
id,
|
||||
},
|
||||
)
|
||||
|
@ -754,20 +789,20 @@ impl InputBackend for WinitInputBackend {
|
|||
(
|
||||
WindowEvent::Touch(Touch {
|
||||
phase: TouchPhase::Moved,
|
||||
location: (x, y),
|
||||
location,
|
||||
id,
|
||||
..
|
||||
}),
|
||||
Some(handler),
|
||||
_,
|
||||
) => {
|
||||
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
||||
trace!(logger, "Calling on_touch_motion at {:?}", location);
|
||||
handler.on_touch_motion(
|
||||
seat,
|
||||
WinitTouchMovedEvent {
|
||||
window: window.clone(),
|
||||
time,
|
||||
location: (x, y),
|
||||
location: location.into(),
|
||||
id,
|
||||
},
|
||||
)
|
||||
|
@ -775,20 +810,20 @@ impl InputBackend for WinitInputBackend {
|
|||
(
|
||||
WindowEvent::Touch(Touch {
|
||||
phase: TouchPhase::Ended,
|
||||
location: (x, y),
|
||||
location,
|
||||
id,
|
||||
..
|
||||
}),
|
||||
Some(handler),
|
||||
_,
|
||||
) => {
|
||||
trace!(logger, "Calling on_touch_motion at {:?}", (x, y));
|
||||
trace!(logger, "Calling on_touch_motion at {:?}", location);
|
||||
handler.on_touch_motion(
|
||||
seat,
|
||||
WinitTouchMovedEvent {
|
||||
window: window.clone(),
|
||||
time,
|
||||
location: (x, y),
|
||||
location: location.into(),
|
||||
id,
|
||||
},
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue