Skip to content

Commit

Permalink
update winit
Browse files Browse the repository at this point in the history
  • Loading branch information
wash2 committed Aug 28, 2024
1 parent b00ea5b commit 2e06574
Show file tree
Hide file tree
Showing 13 changed files with 411 additions and 475 deletions.
15 changes: 10 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,17 @@ web-time = "0.2"

winapi = "0.3"
# window_clipboard = "0.4.1"
window_clipboard = { git = "https://github.com/pop-os/window_clipboard.git", tag = "pop-dnd-8" }
dnd = { git = "https://github.com/pop-os/window_clipboard.git", tag = "pop-dnd-8" }
mime = { git = "https://github.com/pop-os/window_clipboard.git", tag = "pop-dnd-8" }
window_clipboard = { path = "../../../window_clipboard" }
dnd = { path = "../../../window_clipboard/dnd" }
mime = { path = "../../../window_clipboard/mime" }

# window_clipboard = { git = "https://github.com/pop-os/window_clipboard.git", tag = "pop-dnd-8" }
# dnd = { git = "https://github.com/pop-os/window_clipboard.git", tag = "pop-dnd-8" }
# mime = { git = "https://github.com/pop-os/window_clipboard.git", tag = "pop-dnd-8" }
# winit = { git = "https://github.com/pop-os/winit.git", branch = "winit-0.29" }
# winit = { path = "../../winit" }
winit = { git = "https://github.com/iced-rs/winit.git", rev = "254d6b3420ce4e674f516f7a2bd440665e05484d" }
# winit = { git = "https://github.com/iced-rs/winit.git", rev = "254d6b3420ce4e674f516f7a2bd440665e05484d" }
winit = { git = "https://github.com/rust-windowing/winit.git", rev = "241b7a80bba96c91fa3901729cd5dec66abb9be4" }


[workspace.lints.rust]
Expand Down Expand Up @@ -258,4 +263,4 @@ useless_conversion = "deny"
broken_intra_doc_links = "forbid"

[patch.crates-io]
winit = { git = "https://github.com/iced-rs/winit.git", rev = "254d6b3420ce4e674f516f7a2bd440665e05484d" }
winit = { git = "https://github.com/rust-windowing/winit.git", rev = "241b7a80bba96c91fa3901729cd5dec66abb9be4" }
17 changes: 12 additions & 5 deletions accessibility/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ async-io = ["accesskit_unix?/async-io", "accesskit_winit?/async-io"]
tokio = ["accesskit_unix?/tokio", "accesskit_winit?/tokio"]

[dependencies]
accesskit = { git = "https://github.com/accesskit/accesskit" }
accesskit_unix = { git = "https://github.com/accesskit/accesskit", optional = true }
accesskit_windows = { git = "https://github.com/accesskit/accesskit", optional = true }
accesskit_macos = { git = "https://github.com/accesskit/accesskit", optional = true }
accesskit_winit = { git = "https://github.com/accesskit/accesskit", optional = true, default-features = false, features = [
# accesskit = { git = "https://github.com/accesskit/accesskit" }
# accesskit_unix = { git = "https://github.com/accesskit/accesskit", optional = true }
# accesskit_windows = { git = "https://github.com/accesskit/accesskit", optional = true }
# accesskit_macos = { git = "https://github.com/accesskit/accesskit", optional = true }
# accesskit_winit = { git = "https://github.com/accesskit/accesskit", optional = true, default-features = false, features = [
# "rwh_06",
# ] }
accesskit = { path = "../../../../accesskit/common" }
accesskit_unix = { path = "../../../../accesskit/platforms/unix", optional = true }
accesskit_windows = { path = "../../../../accesskit/platforms/windows", optional = true }
accesskit_macos = { path = "../../../../accesskit/platforms/macos", optional = true }
accesskit_winit = { path = "../../../../accesskit/platforms/winit", optional = true, default-features = false, features = [
"rwh_06",
] }
6 changes: 3 additions & 3 deletions examples/integration/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
enum Runner {
Loading,
Ready {
window: Arc<winit::window::Window>,
window: Arc<dyn winit::window::Window>,
device: wgpu::Device,
queue: wgpu::Queue,
surface: wgpu::Surface<'static>,
Expand All @@ -54,7 +54,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {
}

impl winit::application::ApplicationHandler for Runner {
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
fn resumed(&mut self, event_loop: &dyn winit::event_loop::ActiveEventLoop) {
if let Self::Loading = self {
let window = Arc::new(
event_loop
Expand Down Expand Up @@ -186,7 +186,7 @@ pub fn main() -> Result<(), winit::error::EventLoopError> {

fn window_event(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
event_loop: &dyn winit::event_loop::ActiveEventLoop,
_window_id: winit::window::WindowId,
event: WindowEvent,
) {
Expand Down
9 changes: 7 additions & 2 deletions examples/sctk_session_lock/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ edition = "2021"

[dependencies]
sctk = { package = "smithay-client-toolkit", git = "https://github.com/smithay/client-toolkit", rev = "828b1eb" }
iced = { path = "../..", default-features = false, features = ["async-std", "wayland", "debug", "a11y"] }
iced = { path = "../..", default-features = false, features = [
"async-std",
"wayland",
"debug",
"a11y",
] }
iced_runtime = { path = "../../runtime" }
env_logger = "0.10"
async-std = "1.0"
async-std = "1"
2 changes: 1 addition & 1 deletion examples/todos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ iced.workspace = true
iced_core.workspace = true
# iced.features = ["async-std", "debug", "winit", "a11y", "tiny-skia"]
# TODO(POP): Fix a11y not working with new winit
iced.features = ["a11y", "async-std", "debug", "winit", "tiny-skia"]
iced.features = ["tokio", "debug", "winit", "tiny-skia"]

once_cell.workspace = true
serde = { version = "1.0", features = ["derive"] }
Expand Down
21 changes: 12 additions & 9 deletions winit/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,10 @@ where
F: Future<Output = ()>,
C: Compositor + 'static,
{
fn resumed(&mut self, event_loop: &winit::event_loop::ActiveEventLoop) {
fn resumed(
&mut self,
event_loop: &dyn winit::event_loop::ActiveEventLoop,
) {
let Some(BootConfig {
sender,
id,
Expand Down Expand Up @@ -448,7 +451,7 @@ where

fn new_events(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
event_loop: &dyn winit::event_loop::ActiveEventLoop,
cause: winit::event::StartCause,
) {
if self.boot.is_some() {
Expand All @@ -463,7 +466,7 @@ where

fn window_event(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
event_loop: &dyn winit::event_loop::ActiveEventLoop,
window_id: winit::window::WindowId,
event: winit::event::WindowEvent,
) {
Expand Down Expand Up @@ -496,7 +499,7 @@ where

fn user_event(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
event_loop: &dyn winit::event_loop::ActiveEventLoop,
action: UserEventWrapper<Action<Message>>,
) {
self.process_event(
Expand All @@ -507,7 +510,7 @@ where

fn about_to_wait(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
event_loop: &dyn winit::event_loop::ActiveEventLoop,
) {
self.process_event(event_loop, winit::event::Event::AboutToWait);
}
Expand All @@ -519,7 +522,7 @@ where
{
fn process_event(
&mut self,
event_loop: &winit::event_loop::ActiveEventLoop,
event_loop: &dyn winit::event_loop::ActiveEventLoop,
event: winit::event::Event<UserEventWrapper<Action<Message>>>,
) {
// On Wasm, events may start being processed before the compositor
Expand Down Expand Up @@ -576,7 +579,7 @@ where
}

struct Boot<C> {
window: Arc<winit::window::Window>,
window: Arc<dyn winit::window::Window>,
compositor: C,
should_be_visible: bool,
exit_on_close_request: bool,
Expand Down Expand Up @@ -1318,7 +1321,7 @@ pub fn update<A: Application + 'static, E: Executor + 'static>(
>,
debug: &mut Debug,
messages: &mut Vec<A::Message>,
window: &winit::window::Window,
window: &dyn winit::window::Window,
) where
A::Theme: DefaultStyle,
{
Expand Down Expand Up @@ -1354,7 +1357,7 @@ pub fn run_action<A, C>(
clipboard: &mut Clipboard<Action<A::Message>>,
should_exit: &mut bool,
debug: &mut Debug,
window: &winit::window::Window,
window: &dyn winit::window::Window,
) where
A: Application,
C: Compositor<Renderer = A::Renderer> + 'static,
Expand Down
16 changes: 11 additions & 5 deletions winit/src/application/drag_resize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ use winit::window::{CursorIcon, ResizeDirection};

/// If supported by winit, returns a closure that implements cursor resize support.
pub fn event_func(
window: &winit::window::Window,
window: &dyn winit::window::Window,
border_size: f64,
) -> Option<
Box<dyn FnMut(&winit::window::Window, &winit::event::WindowEvent) -> bool>,
Box<
dyn FnMut(
&dyn winit::window::Window,
&winit::event::WindowEvent,
) -> bool,
>,
> {
if window.drag_resize_window(ResizeDirection::East).is_ok() {
// Keep track of cursor when it is within a resizeable border.
let mut cursor_prev_resize_direction = None;

Some(Box::new(
move |window: &winit::window::Window,
move |window: &dyn winit::window::Window,
window_event: &winit::event::WindowEvent|
-> bool {
// Keep track of border resize state and set cursor icon when in range
Expand All @@ -27,8 +32,9 @@ pub fn event_func(
border_size,
);
if location != cursor_prev_resize_direction {
window.set_cursor_icon(
resize_direction_cursor_icon(location),
window.set_cursor(
resize_direction_cursor_icon(location)
.into(),
);
cursor_prev_resize_direction = location;
return true;
Expand Down
4 changes: 2 additions & 2 deletions winit/src/clipboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum State {
//
// Note that the field ordering is load-bearing.
#[allow(dead_code)]
window: Arc<Window>,
window: Arc<dyn Window>,
},
Unavailable,
}
Expand Down Expand Up @@ -62,7 +62,7 @@ impl dnd::Sender<DndSurface> for ControlSender {

impl Clipboard {
/// Creates a new [`Clipboard`] for the given window.
pub fn connect(window: Arc<Window>, proxy: ControlSender) -> Clipboard {
pub fn connect(window: Arc<dyn Window>, proxy: ControlSender) -> Clipboard {
#[allow(unsafe_code)]
let state =
unsafe { window_clipboard::Clipboard::connect(window.as_ref()) }
Expand Down
26 changes: 19 additions & 7 deletions winit/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
//!
//! [`winit`]: https://github.com/rust-windowing/winit
//! [`iced_runtime`]: https://github.com/iced-rs/iced/tree/0.12/runtime
use std::hash::DefaultHasher;
use std::hash::Hash;
use std::hash::Hasher;

use crate::core::keyboard;
use crate::core::mouse;
use crate::core::touch;
Expand Down Expand Up @@ -322,10 +326,12 @@ pub fn position(
}
window::Position::SpecificWith(to_position) => {
if let Some(monitor) = monitor {
let start = monitor.position();
let start = monitor.position().unwrap_or_default();

let resolution: winit::dpi::LogicalSize<f32> =
monitor.size().to_logical(monitor.scale_factor());
let resolution: winit::dpi::LogicalSize<f32> = monitor
.current_video_mode()
.map(|m| m.size().to_logical(monitor.scale_factor()))
.unwrap_or_default();

let position = to_position(
size,
Expand All @@ -351,10 +357,12 @@ pub fn position(
}
window::Position::Centered => {
if let Some(monitor) = monitor {
let start = monitor.position();
let start = monitor.position().unwrap_or_default();

let resolution: winit::dpi::LogicalSize<f64> =
monitor.size().to_logical(monitor.scale_factor());
let resolution: winit::dpi::LogicalSize<f64> = monitor
.current_video_mode()
.map(|m| m.size().to_logical(monitor.scale_factor()))
.unwrap_or_default();

let centered: winit::dpi::PhysicalPosition<i32> =
winit::dpi::LogicalPosition {
Expand Down Expand Up @@ -487,7 +495,11 @@ pub fn touch_event(
touch: winit::event::Touch,
scale_factor: f64,
) -> touch::Event {
let id = touch::Finger(touch.id);
// TODO we probably should get the actual internal id in some way instead
let mut s = DefaultHasher::new();
touch.finger_id.hash(&mut s);

let id = touch::Finger(s.finish());
let position = {
let location = touch.location.to_logical::<f64>(scale_factor);

Expand Down
Loading

0 comments on commit 2e06574

Please sign in to comment.