Update winit
This commit is contained in:
parent
dbaf4f7746
commit
115eb4d200
|
@ -13,7 +13,7 @@ slog = { version = "2.0.0" }
|
||||||
slog-stdlog = "2.0.0-0.2"
|
slog-stdlog = "2.0.0-0.2"
|
||||||
libloading = "0.4.0"
|
libloading = "0.4.0"
|
||||||
wayland-client = { version = "~0.8.6", optional = true }
|
wayland-client = { version = "~0.8.6", optional = true }
|
||||||
winit = { version = "~0.6.4", optional = true }
|
winit = { git = "https://github.com/tomaka/winit.git", optional = true }
|
||||||
glium = { version = "~0.16.0", optional = true }
|
glium = { version = "~0.16.0", optional = true }
|
||||||
input = { version = "~0.1.1", optional = true }
|
input = { version = "~0.1.1", optional = true }
|
||||||
clippy = { version = "*", optional = true }
|
clippy = { version = "*", optional = true }
|
||||||
|
|
|
@ -15,7 +15,7 @@ use std::error::Error;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use wayland_client::egl as wegl;
|
use wayland_client::egl as wegl;
|
||||||
use winit::{CreationError as WinitCreationError, ElementState, Event, EventsLoop,
|
use winit::{CreationError as WinitCreationError, ElementState, Event, EventsLoop, KeyboardInput,
|
||||||
MouseButton as WinitMouseButton, MouseCursor, MouseScrollDelta, Touch, TouchPhase, Window,
|
MouseButton as WinitMouseButton, MouseCursor, MouseScrollDelta, Touch, TouchPhase, Window,
|
||||||
WindowBuilder, WindowEvent};
|
WindowBuilder, WindowEvent};
|
||||||
use winit::os::unix::{WindowExt, get_x11_xconnection};
|
use winit::os::unix::{WindowExt, get_x11_xconnection};
|
||||||
|
@ -45,7 +45,10 @@ pub struct WinitInputBackend {
|
||||||
/// graphics backend trait and a corresponding `WinitInputBackend`, which implements
|
/// graphics backend trait and a corresponding `WinitInputBackend`, which implements
|
||||||
/// the `InputBackend` trait
|
/// the `InputBackend` trait
|
||||||
pub fn init() -> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError> {
|
pub fn init() -> Result<(WinitGraphicsBackend, WinitInputBackend), CreationError> {
|
||||||
init_from_builder(WindowBuilder::new())
|
init_from_builder(WindowBuilder::new()
|
||||||
|
.with_dimensions(1280, 800)
|
||||||
|
.with_title("Smithay")
|
||||||
|
.with_visibility(true))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Create a new `WinitGraphicsBackend`, which implements the `EGLGraphicsBackend`
|
/// Create a new `WinitGraphicsBackend`, which implements the `EGLGraphicsBackend`
|
||||||
|
@ -85,14 +88,20 @@ pub fn init_from_builder_with_gl_attr(builder: WindowBuilder, attributes: GlAttr
|
||||||
};
|
};
|
||||||
|
|
||||||
let context = unsafe {
|
let context = unsafe {
|
||||||
EGLContext::new(native,
|
match EGLContext::new(native,
|
||||||
attributes,
|
attributes,
|
||||||
PixelFormatRequirements {
|
PixelFormatRequirements {
|
||||||
hardware_accelerated: Some(true),
|
hardware_accelerated: Some(true),
|
||||||
color_bits: Some(24),
|
color_bits: Some(24),
|
||||||
alpha_bits: Some(8),
|
alpha_bits: Some(8),
|
||||||
..Default::default()
|
..Default::default()
|
||||||
})?
|
}) {
|
||||||
|
Ok(context) => context,
|
||||||
|
Err(err) => {
|
||||||
|
println!("EGLContext creation failed:\n{}", err);
|
||||||
|
return Err(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok((WinitGraphicsBackend {
|
Ok((WinitGraphicsBackend {
|
||||||
|
@ -182,7 +191,7 @@ impl fmt::Display for WinitInputError {
|
||||||
/// Winit-Backend internal event wrapping winit's types into a `KeyboardKeyEvent`
|
/// Winit-Backend internal event wrapping winit's types into a `KeyboardKeyEvent`
|
||||||
pub struct WinitKeyboardInputEvent {
|
pub struct WinitKeyboardInputEvent {
|
||||||
time: u32,
|
time: u32,
|
||||||
key: u8,
|
key: u32,
|
||||||
count: u32,
|
count: u32,
|
||||||
state: ElementState,
|
state: ElementState,
|
||||||
}
|
}
|
||||||
|
@ -195,7 +204,7 @@ impl BackendEvent for WinitKeyboardInputEvent {
|
||||||
|
|
||||||
impl KeyboardKeyEvent for WinitKeyboardInputEvent {
|
impl KeyboardKeyEvent for WinitKeyboardInputEvent {
|
||||||
fn key_code(&self) -> u32 {
|
fn key_code(&self) -> u32 {
|
||||||
self.key as u32
|
self.key
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state(&self) -> KeyState {
|
fn state(&self) -> KeyState {
|
||||||
|
@ -212,8 +221,8 @@ impl KeyboardKeyEvent for WinitKeyboardInputEvent {
|
||||||
pub struct WinitMouseMovedEvent {
|
pub struct WinitMouseMovedEvent {
|
||||||
window: Rc<Window>,
|
window: Rc<Window>,
|
||||||
time: u32,
|
time: u32,
|
||||||
x: i32,
|
x: f64,
|
||||||
y: i32,
|
y: f64,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BackendEvent for WinitMouseMovedEvent {
|
impl BackendEvent for WinitMouseMovedEvent {
|
||||||
|
@ -224,23 +233,24 @@ impl BackendEvent for WinitMouseMovedEvent {
|
||||||
|
|
||||||
impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent {
|
impl PointerMotionAbsoluteEvent for WinitMouseMovedEvent {
|
||||||
fn x(&self) -> f64 {
|
fn x(&self) -> f64 {
|
||||||
self.x as f64
|
self.x
|
||||||
}
|
}
|
||||||
|
|
||||||
fn y(&self) -> f64 {
|
fn y(&self) -> f64 {
|
||||||
self.y as f64
|
self.y
|
||||||
}
|
}
|
||||||
|
|
||||||
fn x_transformed(&self, width: u32) -> u32 {
|
fn x_transformed(&self, width: u32) -> u32 {
|
||||||
cmp::min(self.x * width as i32 /
|
cmp::min((self.x * width as f64 /
|
||||||
self.window.get_inner_size_points().unwrap_or((width, 0)).0 as i32,
|
self.window.get_inner_size_points().unwrap_or((width, 0)).0 as f64) as u32,
|
||||||
0) as u32
|
0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn y_transformed(&self, height: u32) -> u32 {
|
fn y_transformed(&self, height: u32) -> u32 {
|
||||||
cmp::min(self.y * height as i32 /
|
cmp::min((self.y * height as f64 /
|
||||||
self.window.get_inner_size_points().unwrap_or((0, height)).1 as i32,
|
self.window.get_inner_size_points().unwrap_or((0, height)).1 as f64) as
|
||||||
0) as u32
|
u32,
|
||||||
|
0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -484,16 +494,19 @@ impl InputBackend for WinitInputBackend {
|
||||||
let mut handler = self.handler.as_mut();
|
let mut handler = self.handler.as_mut();
|
||||||
|
|
||||||
self.events_loop
|
self.events_loop
|
||||||
.poll_events(move |event| if let Some(ref mut handler) = handler {
|
.poll_events(move |event| match event {
|
||||||
let Event::WindowEvent { event, .. } = event;
|
Event::WindowEvent { event, .. } => {
|
||||||
match event {
|
match (event, handler.as_mut()) {
|
||||||
WindowEvent::Resized(x, y) => {
|
(WindowEvent::Resized(x, y), _) => {
|
||||||
window.set_inner_size(x, y);
|
window.set_inner_size(x, y);
|
||||||
if let Some(wl_egl_surface) = surface.as_ref() {
|
if let Some(wl_egl_surface) = surface.as_ref() {
|
||||||
wl_egl_surface.resize(x as i32, y as i32, 0, 0);
|
wl_egl_surface.resize(x as i32, y as i32, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput(state, key_code, _, _) => {
|
(WindowEvent::KeyboardInput {
|
||||||
|
input: KeyboardInput { scancode, state, .. }, ..
|
||||||
|
},
|
||||||
|
Some(handler)) => {
|
||||||
match state {
|
match state {
|
||||||
ElementState::Pressed => *key_counter += 1,
|
ElementState::Pressed => *key_counter += 1,
|
||||||
ElementState::Released => {
|
ElementState::Released => {
|
||||||
|
@ -503,12 +516,13 @@ impl InputBackend for WinitInputBackend {
|
||||||
handler.on_keyboard_key(seat,
|
handler.on_keyboard_key(seat,
|
||||||
WinitKeyboardInputEvent {
|
WinitKeyboardInputEvent {
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
key: key_code,
|
key: scancode,
|
||||||
count: *key_counter,
|
count: *key_counter,
|
||||||
state: state,
|
state: state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WindowEvent::MouseMoved(x, y) => {
|
(WindowEvent::MouseMoved { position: (x, y), .. },
|
||||||
|
Some(handler)) => {
|
||||||
handler.on_pointer_move_absolute(seat,
|
handler.on_pointer_move_absolute(seat,
|
||||||
WinitMouseMovedEvent {
|
WinitMouseMovedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -517,7 +531,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
y: y,
|
y: y,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WindowEvent::MouseWheel(delta, _) => {
|
(WindowEvent::MouseWheel { delta, .. }, Some(handler)) => {
|
||||||
let event = WinitMouseWheelEvent {
|
let event = WinitMouseWheelEvent {
|
||||||
axis: Axis::Horizontal,
|
axis: Axis::Horizontal,
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
|
@ -535,7 +549,7 @@ impl InputBackend for WinitInputBackend {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
WindowEvent::MouseInput(state, button) => {
|
(WindowEvent::MouseInput { state, button, .. }, Some(handler)) => {
|
||||||
handler.on_pointer_button(seat,
|
handler.on_pointer_button(seat,
|
||||||
WinitMouseInputEvent {
|
WinitMouseInputEvent {
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
|
@ -543,11 +557,13 @@ impl InputBackend for WinitInputBackend {
|
||||||
state: state,
|
state: state,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WindowEvent::Touch(Touch {
|
(WindowEvent::Touch(Touch {
|
||||||
phase: TouchPhase::Started,
|
phase: TouchPhase::Started,
|
||||||
location: (x, y),
|
location: (x, y),
|
||||||
id,
|
id,
|
||||||
}) => {
|
..
|
||||||
|
}),
|
||||||
|
Some(handler)) => {
|
||||||
handler.on_touch_down(seat,
|
handler.on_touch_down(seat,
|
||||||
WinitTouchStartedEvent {
|
WinitTouchStartedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -556,11 +572,13 @@ impl InputBackend for WinitInputBackend {
|
||||||
id: id,
|
id: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WindowEvent::Touch(Touch {
|
(WindowEvent::Touch(Touch {
|
||||||
phase: TouchPhase::Moved,
|
phase: TouchPhase::Moved,
|
||||||
location: (x, y),
|
location: (x, y),
|
||||||
id,
|
id,
|
||||||
}) => {
|
..
|
||||||
|
}),
|
||||||
|
Some(handler)) => {
|
||||||
handler.on_touch_motion(seat,
|
handler.on_touch_motion(seat,
|
||||||
WinitTouchMovedEvent {
|
WinitTouchMovedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -569,11 +587,13 @@ impl InputBackend for WinitInputBackend {
|
||||||
id: id,
|
id: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WindowEvent::Touch(Touch {
|
(WindowEvent::Touch(Touch {
|
||||||
phase: TouchPhase::Ended,
|
phase: TouchPhase::Ended,
|
||||||
location: (x, y),
|
location: (x, y),
|
||||||
id,
|
id,
|
||||||
}) => {
|
..
|
||||||
|
}),
|
||||||
|
Some(handler)) => {
|
||||||
handler.on_touch_motion(seat,
|
handler.on_touch_motion(seat,
|
||||||
WinitTouchMovedEvent {
|
WinitTouchMovedEvent {
|
||||||
window: window.clone(),
|
window: window.clone(),
|
||||||
|
@ -587,21 +607,24 @@ impl InputBackend for WinitInputBackend {
|
||||||
id: id,
|
id: id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
WindowEvent::Touch(Touch {
|
(WindowEvent::Touch(Touch {
|
||||||
phase: TouchPhase::Cancelled,
|
phase: TouchPhase::Cancelled,
|
||||||
id,
|
id,
|
||||||
..
|
..
|
||||||
}) => {
|
}),
|
||||||
|
Some(handler)) => {
|
||||||
handler.on_touch_cancel(seat,
|
handler.on_touch_cancel(seat,
|
||||||
WinitTouchCancelledEvent {
|
WinitTouchCancelledEvent {
|
||||||
time: *time_counter,
|
time: *time_counter,
|
||||||
id: id,
|
id: id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
WindowEvent::Closed => *closed_ptr = true,
|
(WindowEvent::Closed, _) => *closed_ptr = true,
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
*time_counter += 1;
|
*time_counter += 1;
|
||||||
|
}
|
||||||
|
Event::DeviceEvent { .. } => {}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue