diff --git a/Cargo.toml b/Cargo.toml index 062db94..7291c30 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,9 +13,9 @@ slog = { version = "2.0.0" } slog-stdlog = "2.0.0-0.2" libloading = "0.4.0" wayland-client = { version = "0.9.9", optional = true } -winit = { version = "0.8.0", optional = true } -drm = { version = "0.2.1", optional = true } -gbm = { version = "0.2.1", optional = true } +winit = { version = "0.8.2", optional = true } +drm = { version = "=0.2.1", optional = true } +gbm = { version = "=0.2.1", optional = true } glium = { version = "0.17.1", optional = true, default-features = false } input = { version = "0.2.0", optional = true } clippy = { version = "*", optional = true } diff --git a/examples/winit.rs b/examples/winit.rs index 5529e5f..c06d922 100644 --- a/examples/winit.rs +++ b/examples/winit.rs @@ -53,7 +53,7 @@ impl InputHandler for WinitInputHandler { /* never happens with winit */ } fn on_keyboard_key(&mut self, _: &input::Seat, evt: winit::WinitKeyboardInputEvent) { - let keycode = evt.key_code() - 8; + let keycode = evt.key_code(); let state = evt.state(); debug!(self.log, "key"; "keycode" => keycode, "state" => format!("{:?}", state)); let serial = self.next_serial(); diff --git a/src/backend/winit.rs b/src/backend/winit.rs index eae5fd7..f3c971c 100644 --- a/src/backend/winit.rs +++ b/src/backend/winit.rs @@ -10,12 +10,14 @@ use backend::input::{Axis, AxisSource, Event as BackendEvent, InputBackend, Inpu TouchMotionEvent, TouchSlot, TouchUpEvent, UnusedEvent}; use nix::c_void; use rental::TryNewError; +use std::cell::Cell; use std::cmp; use std::error; use std::fmt; use std::rc::Rc; use winit::{ElementState, Event, EventsLoop, KeyboardInput, MouseButton as WinitMouseButton, MouseCursor, MouseScrollDelta, Touch, TouchPhase, WindowBuilder, WindowEvent}; +use winit::os::unix::WindowExt; rental! { mod rental { @@ -61,6 +63,7 @@ impl From> for Error { /// `EGLGraphicsBackend` graphics backend trait pub struct WinitGraphicsBackend { window: Rc, + ready: Cell, logger: ::slog::Logger, } @@ -156,6 +159,7 @@ where Ok(( WinitGraphicsBackend { window: window.clone(), + ready: Cell::new(false), logger: log.new(o!("smithay_winit_component" => "graphics")), }, WinitInputBackend { @@ -199,6 +203,15 @@ impl GraphicsBackend for WinitGraphicsBackend { impl EGLGraphicsBackend for WinitGraphicsBackend { fn swap_buffers(&self) -> ::std::result::Result<(), SwapBuffersError> { trace!(self.logger, "Swapping buffers"); + if !self.ready.get() { + if self.window.head().is_ready() { + // avoid locking the mutex every time once the window is ready + self.ready.set(true); + } else { + // Not yet ready, just silently ignore the swap-buffers call + return Ok(()); + } + } self.window .rent(|egl| egl.rent(|surface| surface.swap_buffers())) }