summaryrefslogtreecommitdiffstats
path: root/winit/src
diff options
context:
space:
mode:
authorLibravatar Richard <richardsoncusto@gmail.com>2022-09-19 20:59:37 -0300
committerLibravatar bungoboingo <shankern@protonmail.com>2023-01-09 11:27:04 -0800
commit0ad53a3d5c7b5fb5785a64102ee1ad7df9a5fb2b (patch)
treefdb06bd6a9d878bb3eaa9ffb93814660a4809555 /winit/src
parent974cc6b6f55178976b0ace626ba03bdd88cde5e0 (diff)
downloadiced-0ad53a3d5c7b5fb5785a64102ee1ad7df9a5fb2b.tar.gz
iced-0ad53a3d5c7b5fb5785a64102ee1ad7df9a5fb2b.tar.bz2
iced-0ad53a3d5c7b5fb5785a64102ee1ad7df9a5fb2b.zip
add `window::Id` to `Event` and `Action`
Diffstat (limited to '')
-rw-r--r--winit/src/application.rs3
-rw-r--r--winit/src/conversion.rs46
-rw-r--r--winit/src/multi_window.rs77
-rw-r--r--winit/src/window.rs30
4 files changed, 84 insertions, 72 deletions
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 74c73815..4486f5d9 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -502,6 +502,7 @@ async fn run_instance<A, E, C>(
state.update(&window, &window_event, &mut debug);
if let Some(event) = conversion::window_event(
+ crate::window::Id::MAIN,
&window_event,
state.scale_factor(),
state.modifiers(),
@@ -667,7 +668,7 @@ pub fn run_command<A, E>(
clipboard.write(contents);
}
},
- command::Action::Window(action) => match action {
+ command::Action::Window(_id, action) => match action {
window::Action::Close => {
*should_exit = true;
}
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index 1418e346..6c809d19 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -10,6 +10,7 @@ use crate::{Event, Point, Position};
/// Converts a winit window event into an iced event.
pub fn window_event(
+ id: window::Id,
event: &winit::event::WindowEvent<'_>,
scale_factor: f64,
modifiers: winit::event::ModifiersState,
@@ -20,21 +21,27 @@ pub fn window_event(
WindowEvent::Resized(new_size) => {
let logical_size = new_size.to_logical(scale_factor);
- Some(Event::Window(window::Event::Resized {
- width: logical_size.width,
- height: logical_size.height,
- }))
+ Some(Event::Window(
+ id,
+ window::Event::Resized {
+ width: logical_size.width,
+ height: logical_size.height,
+ },
+ ))
}
WindowEvent::ScaleFactorChanged { new_inner_size, .. } => {
let logical_size = new_inner_size.to_logical(scale_factor);
- Some(Event::Window(window::Event::Resized {
- width: logical_size.width,
- height: logical_size.height,
- }))
+ Some(Event::Window(
+ id,
+ window::Event::Resized {
+ width: logical_size.width,
+ height: logical_size.height,
+ },
+ ))
}
WindowEvent::CloseRequested => {
- Some(Event::Window(window::Event::CloseRequested))
+ Some(Event::Window(id, window::Event::CloseRequested))
}
WindowEvent::CursorMoved { position, .. } => {
let position = position.to_logical::<f64>(scale_factor);
@@ -112,19 +119,22 @@ pub fn window_event(
WindowEvent::ModifiersChanged(new_modifiers) => Some(Event::Keyboard(
keyboard::Event::ModifiersChanged(self::modifiers(*new_modifiers)),
)),
- WindowEvent::Focused(focused) => Some(Event::Window(if *focused {
- window::Event::Focused
- } else {
- window::Event::Unfocused
- })),
+ WindowEvent::Focused(focused) => Some(Event::Window(
+ id,
+ if *focused {
+ window::Event::Focused
+ } else {
+ window::Event::Unfocused
+ },
+ )),
WindowEvent::HoveredFile(path) => {
- Some(Event::Window(window::Event::FileHovered(path.clone())))
+ Some(Event::Window(id, window::Event::FileHovered(path.clone())))
}
WindowEvent::DroppedFile(path) => {
- Some(Event::Window(window::Event::FileDropped(path.clone())))
+ Some(Event::Window(id, window::Event::FileDropped(path.clone())))
}
WindowEvent::HoveredFileCancelled => {
- Some(Event::Window(window::Event::FilesHoveredLeft))
+ Some(Event::Window(id, window::Event::FilesHoveredLeft))
}
WindowEvent::Touch(touch) => {
Some(Event::Touch(touch_event(*touch, scale_factor)))
@@ -133,7 +143,7 @@ pub fn window_event(
let winit::dpi::LogicalPosition { x, y } =
position.to_logical(scale_factor);
- Some(Event::Window(window::Event::Moved { x, y }))
+ Some(Event::Window(id, window::Event::Moved { x, y }))
}
_ => None,
}
diff --git a/winit/src/multi_window.rs b/winit/src/multi_window.rs
index 3e7fecd0..9f46b88d 100644
--- a/winit/src/multi_window.rs
+++ b/winit/src/multi_window.rs
@@ -363,7 +363,6 @@ async fn run_instance<A, E, C>(
&mut proxy,
&mut debug,
&windows,
- &window_ids,
|| compositor.fetch_information(),
);
}
@@ -456,7 +455,6 @@ async fn run_instance<A, E, C>(
&mut debug,
&mut messages,
&windows,
- &window_ids,
|| compositor.fetch_information(),
);
@@ -701,6 +699,7 @@ async fn run_instance<A, E, C>(
state.update(window, &window_event, &mut debug);
if let Some(event) = conversion::window_event(
+ *window_ids.get(&window_id).unwrap(),
&window_event,
state.scale_factor(),
state.modifiers(),
@@ -787,7 +786,6 @@ pub fn update<A: Application, E: Executor>(
debug: &mut Debug,
messages: &mut Vec<A::Message>,
windows: &HashMap<window::Id, winit::window::Window>,
- window_ids: &HashMap<winit::window::WindowId, window::Id>,
graphics_info: impl FnOnce() -> compositor::Information + Copy,
) where
<A::Renderer as crate::Renderer>::Theme: StyleSheet,
@@ -810,7 +808,6 @@ pub fn update<A: Application, E: Executor>(
proxy,
debug,
windows,
- window_ids,
graphics_info,
);
}
@@ -831,7 +828,6 @@ pub fn run_command<A, E>(
proxy: &mut winit::event_loop::EventLoopProxy<Event<A::Message>>,
debug: &mut Debug,
windows: &HashMap<window::Id, winit::window::Window>,
- window_ids: &HashMap<winit::window::WindowId, window::Id>,
_graphics_info: impl FnOnce() -> compositor::Information + Copy,
) where
A: Application,
@@ -842,10 +838,6 @@ pub fn run_command<A, E>(
use iced_native::system;
use iced_native::window;
- // TODO(derezzedex)
- let window = windows.values().next().expect("No window found");
- let id = *window_ids.get(&window.id()).unwrap();
-
for action in command.actions() {
match action {
command::Action::Future(future) => {
@@ -863,38 +855,41 @@ pub fn run_command<A, E>(
clipboard.write(contents);
}
},
- command::Action::Window(action) => match action {
- window::Action::Resize { width, height } => {
- window.set_inner_size(winit::dpi::LogicalSize {
- width,
- height,
- });
- }
- window::Action::Move { x, y } => {
- window.set_outer_position(winit::dpi::LogicalPosition {
- x,
- y,
- });
- }
- window::Action::SetMode(mode) => {
- window.set_visible(conversion::visible(mode));
- window.set_fullscreen(conversion::fullscreen(
- window.primary_monitor(),
- mode,
- ));
- }
- window::Action::FetchMode(tag) => {
- let mode = if window.is_visible().unwrap_or(true) {
- conversion::mode(window.fullscreen())
- } else {
- window::Mode::Hidden
- };
-
- proxy
- .send_event(Event::Application(tag(mode)))
- .expect("Send message to event loop");
+ command::Action::Window(id, action) => {
+ let window = windows.get(&id).expect("No window found");
+
+ match action {
+ window::Action::Resize { width, height } => {
+ window.set_inner_size(winit::dpi::LogicalSize {
+ width,
+ height,
+ });
+ }
+ window::Action::Move { x, y } => {
+ window.set_outer_position(
+ winit::dpi::LogicalPosition { x, y },
+ );
+ }
+ window::Action::SetMode(mode) => {
+ window.set_visible(conversion::visible(mode));
+ window.set_fullscreen(conversion::fullscreen(
+ window.primary_monitor(),
+ mode,
+ ));
+ }
+ window::Action::FetchMode(tag) => {
+ let mode = if window.is_visible().unwrap_or(true) {
+ conversion::mode(window.fullscreen())
+ } else {
+ window::Mode::Hidden
+ };
+
+ proxy
+ .send_event(Event::Application(tag(mode)))
+ .expect("Send message to event loop");
+ }
}
- },
+ }
command::Action::System(action) => match action {
system::Action::QueryInformation(_tag) => {
#[cfg(feature = "system")]
@@ -925,7 +920,7 @@ pub fn run_command<A, E>(
renderer,
state.logical_size(),
debug,
- id,
+ window::Id::MAIN, // TODO(derezzedex): run the operation on every widget tree
);
while let Some(mut operation) = current_operation.take() {
diff --git a/winit/src/window.rs b/winit/src/window.rs
index f2c7037a..d9bc0d83 100644
--- a/winit/src/window.rs
+++ b/winit/src/window.rs
@@ -15,11 +15,15 @@ pub fn drag<Message>() -> Command<Message> {
}
/// Resizes the window to the given logical dimensions.
-pub fn resize<Message>(width: u32, height: u32) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Resize {
- width,
- height,
- }))
+pub fn resize<Message>(
+ id: window::Id,
+ width: u32,
+ height: u32,
+) -> Command<Message> {
+ Command::single(command::Action::Window(
+ id,
+ window::Action::Resize { width, height },
+ ))
}
/// Sets the window to maximized or back.
@@ -33,13 +37,13 @@ pub fn minimize<Message>(value: bool) -> Command<Message> {
}
/// Moves a window to the given logical coordinates.
-pub fn move_to<Message>(x: i32, y: i32) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::Move { x, y }))
+pub fn move_to<Message>(id: window::Id, x: i32, y: i32) -> Command<Message> {
+ Command::single(command::Action::Window(id, window::Action::Move { x, y }))
}
/// Sets the [`Mode`] of the window.
-pub fn set_mode<Message>(mode: Mode) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::SetMode(mode)))
+pub fn set_mode<Message>(id: window::Id, mode: Mode) -> Command<Message> {
+ Command::single(command::Action::Window(id, window::Action::SetMode(mode)))
}
/// Sets the window to maximized or back.
@@ -49,9 +53,11 @@ pub fn toggle_maximize<Message>() -> Command<Message> {
/// Fetches the current [`Mode`] of the window.
pub fn fetch_mode<Message>(
+ id: window::Id,
f: impl FnOnce(Mode) -> Message + 'static,
) -> Command<Message> {
- Command::single(command::Action::Window(window::Action::FetchMode(
- Box::new(f),
- )))
+ Command::single(command::Action::Window(
+ id,
+ window::Action::FetchMode(Box::new(f)),
+ ))
}