Skip to content

Commit f16a831

Browse files
committed
Update winit to 0.29.4
1 parent dd249a1 commit f16a831

16 files changed

Lines changed: 650 additions & 829 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,4 @@ web-sys = "0.3"
160160
wgpu = "0.18"
161161
winapi = "0.3"
162162
window_clipboard = "0.3"
163-
winit = { git = "https://github.com/iced-rs/winit.git", rev = "c52db2045d0a2f1b8d9923870de1d4ab1994146e", default-features = false }
163+
winit = { git = "https://github.com/iced-rs/winit.git", rev = "3bcdb9abcd7459978ec689523bc21943d38da0f9", default-features = false, features = ["rwh_05", "x11", "wayland"] }

core/src/keyboard/event.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use super::{KeyCode, Modifiers};
66
/// additional events, feel free to [open an issue] and share your use case!_
77
///
88
/// [open an issue]: https://github.com/iced-rs/iced/issues
9-
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9+
#[derive(Debug, Clone, PartialEq, Eq)]
1010
pub enum Event {
1111
/// A keyboard key was pressed.
1212
KeyPressed {
@@ -15,6 +15,9 @@ pub enum Event {
1515

1616
/// The state of the modifier keys
1717
modifiers: Modifiers,
18+
19+
/// The text produced by the key press, if any.
20+
text: Option<String>,
1821
},
1922

2023
/// A keyboard key was released.
@@ -26,9 +29,6 @@ pub enum Event {
2629
modifiers: Modifiers,
2730
},
2831

29-
/// A unicode character was received.
30-
CharacterReceived(char),
31-
3232
/// The keyboard modifiers have changed.
3333
ModifiersChanged(Modifiers),
3434
}

core/src/mouse/button.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ pub enum Button {
1010
/// The middle (wheel) button.
1111
Middle,
1212

13+
/// The back mouse button.
14+
Back,
15+
16+
/// The forward mouse button.
17+
Forward,
18+
1319
/// Some other button.
1420
Other(u16),
1521
}

examples/integration/src/main.rs

Lines changed: 63 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ use iced_winit::winit;
1919
use iced_winit::Clipboard;
2020

2121
use winit::{
22-
event::{Event, ModifiersState, WindowEvent},
22+
event::{Event, WindowEvent},
2323
event_loop::{ControlFlow, EventLoop},
24+
keyboard::ModifiersState,
2425
};
2526

2627
#[cfg(target_arch = "wasm32")]
@@ -48,7 +49,7 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
4849
tracing_subscriber::fmt::init();
4950

5051
// Initialize winit
51-
let event_loop = EventLoop::new();
52+
let event_loop = EventLoop::new()?;
5253

5354
#[cfg(target_arch = "wasm32")]
5455
let window = winit::window::WindowBuilder::new()
@@ -160,67 +161,15 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
160161
);
161162

162163
// Run event loop
163-
event_loop.run(move |event, _, control_flow| {
164+
event_loop.run(move |event, window_target| {
164165
// You should change this if you want to render continuosly
165-
*control_flow = ControlFlow::Wait;
166+
window_target.set_control_flow(ControlFlow::Wait);
166167

167168
match event {
168-
Event::WindowEvent { event, .. } => {
169-
match event {
170-
WindowEvent::CursorMoved { position, .. } => {
171-
cursor_position = Some(position);
172-
}
173-
WindowEvent::ModifiersChanged(new_modifiers) => {
174-
modifiers = new_modifiers;
175-
}
176-
WindowEvent::Resized(_) => {
177-
resized = true;
178-
}
179-
WindowEvent::CloseRequested => {
180-
*control_flow = ControlFlow::Exit;
181-
}
182-
_ => {}
183-
}
184-
185-
// Map window event to iced event
186-
if let Some(event) = iced_winit::conversion::window_event(
187-
window::Id::MAIN,
188-
&event,
189-
window.scale_factor(),
190-
modifiers,
191-
) {
192-
state.queue_event(event);
193-
}
194-
}
195-
Event::MainEventsCleared => {
196-
// If there are events pending
197-
if !state.is_queue_empty() {
198-
// We update iced
199-
let _ = state.update(
200-
viewport.logical_size(),
201-
cursor_position
202-
.map(|p| {
203-
conversion::cursor_position(
204-
p,
205-
viewport.scale_factor(),
206-
)
207-
})
208-
.map(mouse::Cursor::Available)
209-
.unwrap_or(mouse::Cursor::Unavailable),
210-
&mut renderer,
211-
&Theme::Dark,
212-
&renderer::Style {
213-
text_color: Color::WHITE,
214-
},
215-
&mut clipboard,
216-
&mut debug,
217-
);
218-
219-
// and request a redraw
220-
window.request_redraw();
221-
}
222-
}
223-
Event::RedrawRequested(_) => {
169+
Event::WindowEvent {
170+
event: WindowEvent::RedrawRequested,
171+
..
172+
} => {
224173
if resized {
225174
let size = window.inner_size();
226175

@@ -309,7 +258,60 @@ pub fn main() -> Result<(), Box<dyn std::error::Error>> {
309258
},
310259
}
311260
}
261+
Event::WindowEvent { event, .. } => {
262+
match event {
263+
WindowEvent::CursorMoved { position, .. } => {
264+
cursor_position = Some(position);
265+
}
266+
WindowEvent::ModifiersChanged(new_modifiers) => {
267+
modifiers = new_modifiers.state();
268+
}
269+
WindowEvent::Resized(_) => {
270+
resized = true;
271+
}
272+
WindowEvent::CloseRequested => {
273+
window_target.exit();
274+
}
275+
_ => {}
276+
}
277+
278+
// Map window event to iced event
279+
if let Some(event) = iced_winit::conversion::window_event(
280+
window::Id::MAIN,
281+
&event,
282+
window.scale_factor(),
283+
modifiers,
284+
) {
285+
state.queue_event(event);
286+
}
287+
}
312288
_ => {}
313289
}
314-
})
290+
291+
// If there are events pending
292+
if !state.is_queue_empty() {
293+
// We update iced
294+
let _ = state.update(
295+
viewport.logical_size(),
296+
cursor_position
297+
.map(|p| {
298+
conversion::cursor_position(p, viewport.scale_factor())
299+
})
300+
.map(mouse::Cursor::Available)
301+
.unwrap_or(mouse::Cursor::Unavailable),
302+
&mut renderer,
303+
&Theme::Dark,
304+
&renderer::Style {
305+
text_color: Color::WHITE,
306+
},
307+
&mut clipboard,
308+
&mut debug,
309+
);
310+
311+
// and request a redraw
312+
window.request_redraw();
313+
}
314+
})?;
315+
316+
Ok(())
315317
}

examples/modal/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ impl Application for App {
8787
Event::Keyboard(keyboard::Event::KeyPressed {
8888
key_code: keyboard::KeyCode::Tab,
8989
modifiers,
90+
..
9091
}) => {
9192
if modifiers.shift() {
9293
widget::focus_previous()

examples/toast/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl Application for App {
9595
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
9696
key_code: keyboard::KeyCode::Tab,
9797
modifiers,
98+
..
9899
})) if modifiers.shift() => widget::focus_previous(),
99100
Message::Event(Event::Keyboard(keyboard::Event::KeyPressed {
100101
key_code: keyboard::KeyCode::Tab,

futures/src/keyboard.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ where
2424
core::Event::Keyboard(Event::KeyPressed {
2525
key_code,
2626
modifiers,
27+
..
2728
}),
2829
core::event::Status::Ignored,
2930
) => f(key_code, modifiers),

widget/src/canvas/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pub use crate::core::event::Status;
88
/// A [`Canvas`] event.
99
///
1010
/// [`Canvas`]: crate::Canvas
11-
#[derive(Debug, Clone, Copy, PartialEq)]
11+
#[derive(Debug, Clone, PartialEq)]
1212
pub enum Event {
1313
/// A mouse event.
1414
Mouse(mouse::Event),

widget/src/shader/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub use crate::core::event::Status;
99
/// A [`Shader`] event.
1010
///
1111
/// [`Shader`]: crate::Shader
12-
#[derive(Debug, Clone, Copy, PartialEq)]
12+
#[derive(Debug, Clone, PartialEq)]
1313
pub enum Event {
1414
/// A mouse event.
1515
Mouse(mouse::Event),

widget/src/text_editor.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,6 +649,7 @@ impl Update {
649649
keyboard::Event::KeyPressed {
650650
key_code,
651651
modifiers,
652+
text,
652653
} if state.is_focused => {
653654
if let Some(motion) = motion(key_code) {
654655
let motion =
@@ -678,12 +679,15 @@ impl Update {
678679
{
679680
Some(Self::Paste)
680681
}
681-
_ => None,
682+
_ => {
683+
let text = text?;
684+
685+
edit(Edit::Insert(
686+
text.chars().next().unwrap_or_default(),
687+
))
688+
}
682689
}
683690
}
684-
keyboard::Event::CharacterReceived(c) if state.is_focused => {
685-
edit(Edit::Insert(c))
686-
}
687691
_ => None,
688692
},
689693
_ => None,

0 commit comments

Comments
 (0)