Watch
1
0
Fork
You've already forked smithay
0

winit: Update winit to 0.31.0-beta.2

This commit is contained in:
Ian Douglas Scott 2025-12-04 21:57:34 -08:00 • committed by Ian Douglas Scott
commit f949fa4865
6 changed files with 129 additions and 127 deletions

View file

@ -63,7 +63,7 @@ wayland-protocols-misc = { version = "0.3.12", features = ["server"], optional =
wayland-server = { version = "0.31.13", optional = true }
wayland-sys = { version = "0.31.11", optional = true }
wayland-backend = { version = "0.3.15", optional = true }
winit = { version = "0.30.0", default-features = false, features = ["wayland", "wayland-dlopen", "x11", "rwh_06"], optional = true }
winit = { version = "0.31.0-beta.2", default-features = false, features = ["wayland", "wayland-dlopen", "x11"], optional = true }
x11rb = { version = "0.13.0", optional = true, features = ["res", "sync"]}
xkbcommon = { version = "0.9.0", features = ["wayland"]}
encoding_rs = { version = "0.8.33", optional = true }

View file

@ -33,7 +33,7 @@ use smithay::{
calloop::EventLoop,
wayland_protocols::wp::presentation_time::server::wp_presentation_feedback,
wayland_server::{Display, protocol::wl_surface},
winit::platform::pump_events::PumpStatus,
winit::event_loop::pump_events::PumpStatus,
},
utils::{IsAlive, Scale, Transform},
wayland::{

View file

@ -1,6 +1,6 @@
use std::sync::Arc;
use ::winit::platform::pump_events::PumpStatus;
use ::winit::event_loop::pump_events::PumpStatus;
use smithay::{
backend::{
input::{InputEvent, KeyboardKeyEvent},

View file

@ -161,7 +161,7 @@ impl<A: AsFd + Send + 'static> EGLNativeDisplay for GbmDevice<A> {
}
#[cfg(feature = "backend_winit")]
impl EGLNativeDisplay for Arc<WinitWindow> {
impl EGLNativeDisplay for Arc<dyn WinitWindow> {
fn supported_platforms(&self) -> Vec<EGLPlatform<'_>> {
use winit::raw_window_handle::{self, HasDisplayHandle};

View file

@ -190,11 +190,11 @@ impl PointerButtonEvent<WinitInput> for WinitMouseInputEvent {
WinitMouseButton::Middle => 0x112,
WinitMouseButton::Forward => 0x115,
WinitMouseButton::Back => 0x116,
WinitMouseButton::Other(b) => {
_ => {
if self.is_x11 {
input::xorg_mouse_to_libinput(b as u32)
input::xorg_mouse_to_libinput(self.button as u32 + 1)
} else {
b as u32
self.button as u32 + 1
}
}
}

View file

@ -26,15 +26,16 @@ use calloop::generic::Generic;
use calloop::{EventSource, Interest, PostAction, Readiness, Token};
use tracing::{debug, info, info_span, instrument, trace, warn};
use wayland_egl as wegl;
use winit::platform::pump_events::PumpStatus;
use winit::platform::scancode::PhysicalKeyExtScancode;
use winit::raw_window_handle::{HasWindowHandle, RawWindowHandle};
use winit::{
application::ApplicationHandler,
dpi::LogicalSize,
event::{ElementState, Touch, TouchPhase, WindowEvent},
event_loop::{ActiveEventLoop, EventLoop},
platform::pump_events::EventLoopExtPumpEvents,
event::{ButtonSource, ElementState, PointerKind, PointerSource, WindowEvent},
event_loop::{
ActiveEventLoop, EventLoop,
pump_events::{EventLoopExtPumpEvents, PumpStatus},
},
window::{Window as WinitWindow, WindowAttributes, WindowId},
};
@ -67,8 +68,8 @@ where
crate::backend::SwapBuffersError: From<R::Error>,
{
init_from_attributes(
WinitWindow::default_attributes()
.with_inner_size(LogicalSize::new(1280.0, 800.0))
WindowAttributes::default()
.with_surface_size(LogicalSize::new(1280.0, 800.0))
.with_title("Smithay")
.with_visible(true),
)
@ -143,7 +144,7 @@ where
Ok(RawWindowHandle::Xlib(_))
);
span.record("window", Into::<u64>::into(window.id()));
span.record("window", window.id().into_raw());
debug!("Window created");
let winit_graphics_backend =
@ -175,7 +176,7 @@ pub enum Error {
EventLoopCreation(#[from] winit::error::EventLoopError),
/// Failed to initialize a window.
#[error("Failed to initialize a window")]
WindowCreation(#[from] winit::error::OsError),
WindowCreation(#[from] winit::error::RequestError),
#[error("Failed to create a surface for the window")]
/// Surface creation error.
Surface(Box<dyn std::error::Error>),
@ -197,7 +198,7 @@ pub struct WinitGraphicsBackend<R> {
// The display isn't used past this point but must be kept alive.
_display: EGLDisplay,
egl_surface: EGLSurface,
window: Arc<WinitWindow>,
window: Arc<dyn WinitWindow>,
damage_tracking: bool,
bind_size: Option<Size<i32, Physical>>,
span: tracing::Span,
@ -209,7 +210,7 @@ where
crate::backend::SwapBuffersError: From<R::Error>,
{
fn new_with_gl_attr(
window: Arc<winit::window::Window>,
window: Arc<dyn winit::window::Window>,
span: &tracing::Span,
gl_attributes: GlAttributes,
) -> Result<Self, Error>
@ -232,7 +233,7 @@ where
let surface = match window.window_handle().map(|handle| handle.as_raw()) {
Ok(RawWindowHandle::Wayland(handle)) => {
debug!("Winit backend: Wayland");
let size = window.inner_size();
let size = window.surface_size();
let surface = unsafe {
wegl::WlEglSurface::new_from_raw(
handle.surface.as_ptr() as *mut _,
@ -286,7 +287,7 @@ where
/// Window size of the underlying window
pub fn window_size(&self) -> Size<i32, Physical> {
let (w, h): (i32, i32) = self.window.inner_size().into();
let (w, h): (i32, i32) = self.window.surface_size().into();
(w, h).into()
}
@ -296,8 +297,8 @@ where
}
/// Reference to the underlying window
pub fn window(&self) -> &WinitWindow {
&self.window
pub fn window(&self) -> &dyn WinitWindow {
&*self.window
}
/// Access the underlying renderer
@ -386,7 +387,7 @@ where
#[derive(Debug)]
struct WinitEventLoopInner {
window_attributes: WindowAttributes,
window: Option<Arc<WinitWindow>>,
window: Option<Arc<dyn WinitWindow>>,
window_create_error: Option<Error>,
clock: Clock<Monotonic>,
key_counter: u32,
@ -405,7 +406,7 @@ pub struct WinitEventLoop {
fake_token: Option<Token>,
initial_events: Vec<WinitEvent>,
pending_events: Vec<WinitEvent>,
event_loop: Generic<EventLoop<()>>,
event_loop: Generic<EventLoop>,
span: tracing::Span,
}
@ -457,10 +458,10 @@ impl<F: FnMut(WinitEvent)> WinitEventLoopApp<'_, F> {
}
impl<F: FnMut(WinitEvent)> ApplicationHandler for WinitEventLoopApp<'_, F> {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
fn can_create_surfaces(&mut self, event_loop: &dyn ActiveEventLoop) {
if self.inner.window.is_none() {
match event_loop.create_window(self.inner.window_attributes.clone()) {
Ok(window) => self.inner.window = Some(Arc::new(window)),
Ok(window) => self.inner.window = Some(Arc::from(window)),
Err(err) => self.inner.window_create_error = Some(err.into()),
}
@ -470,13 +471,13 @@ impl<F: FnMut(WinitEvent)> ApplicationHandler for WinitEventLoopApp<'_, F> {
}
}
fn window_event(&mut self, _event_loop: &ActiveEventLoop, _window_id: WindowId, event: WindowEvent) {
fn window_event(&mut self, _event_loop: &dyn ActiveEventLoop, _window_id: WindowId, event: WindowEvent) {
let Some(window) = self.inner.window.as_ref() else {
return;
};
match event {
WindowEvent::Resized(size) => {
WindowEvent::SurfaceResized(size) => {
trace!("Resizing window to {size:?}");
let (w, h): (i32, i32) = size.into();
@ -491,7 +492,7 @@ impl<F: FnMut(WinitEvent)> ApplicationHandler for WinitEventLoopApp<'_, F> {
} => {
trace!("Scale factor changed to {new_scale_factor}");
self.inner.scale_factor = new_scale_factor;
let (w, h): (i32, i32) = window.inner_size().into();
let (w, h): (i32, i32) = window.surface_size().into();
(self.callback)(WinitEvent::Resized {
size: (w, h).into(),
scale_factor: self.inner.scale_factor,
@ -527,18 +528,38 @@ impl<F: FnMut(WinitEvent)> ApplicationHandler for WinitEventLoopApp<'_, F> {
};
(self.callback)(WinitEvent::Input(event));
}
WindowEvent::CursorMoved { position, .. } => {
let size = window.inner_size();
WindowEvent::PointerMoved { position, source, .. } => {
let size = window.surface_size();
let x = position.x / size.width as f64;
let y = position.y / size.height as f64;
let event = InputEvent::PointerMotionAbsolute {
event: WinitMouseMovedEvent {
time: self.timestamp(),
position: RelativePosition::new(x, y),
global_position: position,
},
};
(self.callback)(WinitEvent::Input(event));
let relative_position = RelativePosition::new(x, y);
match source {
PointerSource::Mouse => {
let event = InputEvent::PointerMotionAbsolute {
event: WinitMouseMovedEvent {
time: self.timestamp(),
position: relative_position,
global_position: position,
},
};
(self.callback)(WinitEvent::Input(event));
}
PointerSource::Touch { finger_id, force: _ } => {
let event = InputEvent::TouchMotion {
event: WinitTouchMovedEvent {
time: self.timestamp(),
position: relative_position,
global_position: position,
id: finger_id.into_raw() as u64,
},
};
(self.callback)(WinitEvent::Input(event));
}
// TODO Handle tablet events
PointerSource::TabletTool { .. } => {}
PointerSource::Unknown => {}
}
}
WindowEvent::MouseWheel { delta, .. } => {
let event = InputEvent::PointerAxis {
@ -549,109 +570,90 @@ impl<F: FnMut(WinitEvent)> ApplicationHandler for WinitEventLoopApp<'_, F> {
};
(self.callback)(WinitEvent::Input(event));
}
WindowEvent::MouseInput { state, button, .. } => {
let event = InputEvent::PointerButton {
event: WinitMouseInputEvent {
time: self.timestamp(),
button,
state,
is_x11: self.inner.is_x11,
},
};
(self.callback)(WinitEvent::Input(event));
}
WindowEvent::Touch(Touch {
phase: TouchPhase::Started,
location,
id,
WindowEvent::PointerButton {
state,
button,
position,
..
}) => {
let size = window.inner_size();
let x = location.x / size.width as f64;
let y = location.y / size.width as f64;
let event = InputEvent::TouchDown {
event: WinitTouchStartedEvent {
time: self.timestamp(),
global_position: location,
position: RelativePosition::new(x, y),
id,
},
};
} => {
match button {
ButtonSource::Mouse(button) => {
let event = InputEvent::PointerButton {
event: WinitMouseInputEvent {
time: self.timestamp(),
button,
state,
is_x11: self.inner.is_x11,
},
};
(self.callback)(WinitEvent::Input(event));
}
ButtonSource::Touch { finger_id, force: _ } => match state {
ElementState::Pressed => {
let size = window.surface_size();
let x = position.x / size.width as f64;
let y = position.y / size.width as f64;
let event = InputEvent::TouchDown {
event: WinitTouchStartedEvent {
time: self.timestamp(),
global_position: position,
position: RelativePosition::new(x, y),
id: finger_id.into_raw() as u64,
},
};
(self.callback)(WinitEvent::Input(event));
(self.callback)(WinitEvent::Input(event));
}
ElementState::Released => {
let size = window.surface_size();
let x = position.x / size.width as f64;
let y = position.y / size.width as f64;
let event = InputEvent::TouchMotion {
event: WinitTouchMovedEvent {
time: self.timestamp(),
position: RelativePosition::new(x, y),
global_position: position,
id: finger_id.into_raw() as u64,
},
};
(self.callback)(WinitEvent::Input(event));
let event = InputEvent::TouchUp {
event: WinitTouchEndedEvent {
time: self.timestamp(),
id: finger_id.into_raw() as u64,
},
};
(self.callback)(WinitEvent::Input(event));
}
},
// TODO Handle tablet events
ButtonSource::TabletTool { .. } => {}
ButtonSource::Unknown(_) => {}
}
}
WindowEvent::Touch(Touch {
phase: TouchPhase::Moved,
location,
id,
WindowEvent::PointerLeft {
kind: PointerKind::Touch(finger_id),
..
}) => {
let size = window.inner_size();
let x = location.x / size.width as f64;
let y = location.y / size.width as f64;
let event = InputEvent::TouchMotion {
event: WinitTouchMovedEvent {
time: self.timestamp(),
position: RelativePosition::new(x, y),
global_position: location,
id,
},
};
(self.callback)(WinitEvent::Input(event));
}
WindowEvent::Touch(Touch {
phase: TouchPhase::Ended,
location,
id,
..
}) => {
let size = window.inner_size();
let x = location.x / size.width as f64;
let y = location.y / size.width as f64;
let event = InputEvent::TouchMotion {
event: WinitTouchMovedEvent {
time: self.timestamp(),
position: RelativePosition::new(x, y),
global_position: location,
id,
},
};
(self.callback)(WinitEvent::Input(event));
let event = InputEvent::TouchUp {
event: WinitTouchEndedEvent {
time: self.timestamp(),
id,
},
};
(self.callback)(WinitEvent::Input(event));
}
WindowEvent::Touch(Touch {
phase: TouchPhase::Cancelled,
id,
..
}) => {
} => {
let event = InputEvent::TouchCancel {
event: WinitTouchCancelledEvent {
time: self.timestamp(),
id,
id: finger_id.into_raw() as u64,
},
};
(self.callback)(WinitEvent::Input(event));
}
WindowEvent::DroppedFile(_)
WindowEvent::DragDropped { .. }
| WindowEvent::Destroyed
| WindowEvent::CursorEntered { .. }
| WindowEvent::AxisMotion { .. }
| WindowEvent::CursorLeft { .. }
| WindowEvent::PointerEntered { .. }
| WindowEvent::PointerLeft { .. }
| WindowEvent::ModifiersChanged(_)
| WindowEvent::KeyboardInput { .. }
| WindowEvent::HoveredFile(_)
| WindowEvent::HoveredFileCancelled
| WindowEvent::DragEntered { .. }
| WindowEvent::DragLeft { .. }
| WindowEvent::DragMoved { .. }
| WindowEvent::Ime(_)
| WindowEvent::Moved(_)
| WindowEvent::Occluded(_)