Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/backends/winit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ lyon_path = "1.0"
once_cell = "1.5"
pin-weak = "1"
scoped-tls-hkt = "0.1"
winit = { version = "0.28.2", default-features = false }
# Pinned due to https://github.com/slint-ui/slint/issues/2424
winit = { version = "=0.28.3", default-features = false }
instant = "0.1"
raw-window-handle = { version = "0.5", features = ["alloc"] }
scopeguard = { version = "1.1.0", default-features = false }
Expand Down
14 changes: 13 additions & 1 deletion internal/backends/winit/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub trait WinitWindow: WindowAdapter {
/// Returns true if during the drawing request_redraw() was called.
fn draw(&self) -> bool;
fn with_window_handle(&self, callback: &mut dyn FnMut(&winit::window::Window));
fn winit_window(&self) -> Option<Rc<winit::window::Window>>;
fn constraints(&self) -> (corelib::layout::LayoutInfo, corelib::layout::LayoutInfo);
fn set_constraints(
&self,
Expand Down Expand Up @@ -408,7 +409,18 @@ fn process_window_event(
runtime_window.process_mouse_input(ev);
}
WindowEvent::Touch(touch) => {
let location = touch.location.to_logical(runtime_window.scale_factor() as f64);
let location = touch.location;
// https://github.com/slint-ui/slint/issues/2424: Work around winit reporting absolute coordinates for touch - until https://github.com/rust-windowing/winit/pull/2704 is merged & released.
#[cfg(target_family = "wasm")]
let location = {
let window_pos =
window.winit_window().and_then(|w| w.inner_position().ok()).unwrap_or_default();
winit::dpi::PhysicalPosition::new(
location.x - window_pos.x as f64,
location.y - window_pos.y as f64,
)
};
let location = location.to_logical(runtime_window.scale_factor() as f64);
let position = euclid::point2(location.x, location.y);
let ev = match touch.phase {
winit::event::TouchPhase::Started => {
Expand Down
62 changes: 31 additions & 31 deletions internal/backends/winit/glwindow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WinitWindow for GLWindow<Rende
}
}

fn winit_window(&self) -> Option<Rc<winit::window::Window>> {
self.borrow_mapped_window().map(|mapped_window| mapped_window.winit_window.clone())
}

fn constraints(&self) -> (corelib::layout::LayoutInfo, corelib::layout::LayoutInfo) {
self.borrow_mapped_window().map(|window| window.constraints.get()).unwrap_or_default()
}
Expand Down Expand Up @@ -287,50 +291,46 @@ impl<Renderer: WinitCompatibleRenderer + 'static> WindowAdapterSealed for GLWind
}

fn apply_window_properties(&self, window_item: Pin<&i_slint_core::items::WindowItem>) {
// Make the unwrap() calls on self.borrow_mapped_window*() safe
if !self.is_mapped() {
return;
}
let winit_window = match self.winit_window() {
Some(handle) => handle,
None => return,
};

let mut width = window_item.width().get() as f32;
let mut height = window_item.height().get() as f32;

let mut must_resize = false;

self.with_window_handle(&mut |winit_window| {
winit_window.set_window_icon(icon_to_winit(window_item.icon()));
winit_window.set_title(&window_item.title());
winit_window
.set_decorations(!window_item.no_frame() || winit_window.fullscreen().is_some());
winit_window.set_window_icon(icon_to_winit(window_item.icon()));
winit_window.set_title(&window_item.title());
winit_window
.set_decorations(!window_item.no_frame() || winit_window.fullscreen().is_some());

if width <= 0. || height <= 0. {
must_resize = true;
if width <= 0. || height <= 0. {
must_resize = true;

let winit_size =
winit_window.inner_size().to_logical(self.window.scale_factor() as f64);
let winit_size =
winit_window.inner_size().to_logical(self.window.scale_factor() as f64);

if width <= 0. {
width = winit_size.width;
}
if height <= 0. {
height = winit_size.height;
}
if width <= 0. {
width = winit_size.width;
}
if height <= 0. {
height = winit_size.height;
}
}

let existing_size: winit::dpi::LogicalSize<f32> =
winit_window.inner_size().to_logical(self.window.scale_factor().into());
let existing_size: winit::dpi::LogicalSize<f32> =
winit_window.inner_size().to_logical(self.window.scale_factor().into());

if (existing_size.width - width).abs() > 1.
|| (existing_size.height - height).abs() > 1.
{
// If we're in fullscreen state, don't try to resize the window but maintain the surface
// size we've been assigned to from the windowing system. Weston/Wayland don't like it
// when we create a surface that's bigger than the screen due to constraints (#532).
if winit_window.fullscreen().is_none() {
winit_window.set_inner_size(winit::dpi::LogicalSize::new(width, height));
}
if (existing_size.width - width).abs() > 1. || (existing_size.height - height).abs() > 1. {
// If we're in fullscreen state, don't try to resize the window but maintain the surface
// size we've been assigned to from the windowing system. Weston/Wayland don't like it
// when we create a surface that's bigger than the screen due to constraints (#532).
if winit_window.fullscreen().is_none() {
winit_window.set_inner_size(winit::dpi::LogicalSize::new(width, height));
}
});
}

if must_resize {
self.window.set_size(i_slint_core::api::LogicalSize::new(width, height));
Expand Down
2 changes: 1 addition & 1 deletion internal/renderers/skia/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ glow = { version = "0.12" }
unicode-segmentation = { version = "1.8.0" }

glutin = { version = "0.30", default-features = false, features = ["egl", "wgl"] }
winit = { version = "0.28.2", optional = true, default-features = false }
winit = { version = "0.28.3", optional = true, default-features = false }

[target.'cfg(target_family = "windows")'.dependencies]
winapi = { version = "0.3", features = ["impl-default", "dwrite", "d3d12", "dxgi", "dxgi1_2", "dxgi1_3", "dxgi1_4", "d3d12sdklayers", "synchapi", "winbase"] }
Expand Down