summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/events/src/main.rs2
-rw-r--r--examples/integration_opengl/src/main.rs2
-rw-r--r--examples/integration_wgpu/src/main.rs5
-rw-r--r--glutin/src/application.rs1
-rw-r--r--native/src/command/action.rs8
-rw-r--r--native/src/event.rs2
-rw-r--r--native/src/window/id.rs3
-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
11 files changed, 100 insertions, 79 deletions
diff --git a/examples/events/src/main.rs b/examples/events/src/main.rs
index 234e1423..e9709377 100644
--- a/examples/events/src/main.rs
+++ b/examples/events/src/main.rs
@@ -52,7 +52,7 @@ impl Application for Events {
}
}
Message::EventOccurred(event) => {
- if let Event::Window(window::Event::CloseRequested) = event {
+ if let Event::Window(_, window::Event::CloseRequested) = event {
self.should_exit = true;
}
}
diff --git a/examples/integration_opengl/src/main.rs b/examples/integration_opengl/src/main.rs
index f161c8a0..56470190 100644
--- a/examples/integration_opengl/src/main.rs
+++ b/examples/integration_opengl/src/main.rs
@@ -13,6 +13,7 @@ use iced_glow::{Backend, Renderer, Settings, Viewport};
use iced_glutin::conversion;
use iced_glutin::glutin;
use iced_glutin::renderer;
+use iced_glutin::window;
use iced_glutin::{program, Clipboard, Color, Debug, Size};
pub fn main() {
@@ -107,6 +108,7 @@ pub fn main() {
// Map window event to iced event
if let Some(event) = iced_winit::conversion::window_event(
+ window::Id::MAIN,
&event,
windowed_context.window().scale_factor(),
modifiers,
diff --git a/examples/integration_wgpu/src/main.rs b/examples/integration_wgpu/src/main.rs
index 70f9a48b..219573ea 100644
--- a/examples/integration_wgpu/src/main.rs
+++ b/examples/integration_wgpu/src/main.rs
@@ -6,8 +6,8 @@ use scene::Scene;
use iced_wgpu::{wgpu, Backend, Renderer, Settings, Viewport};
use iced_winit::{
- conversion, futures, program, renderer, winit, Clipboard, Color, Debug,
- Size,
+ conversion, futures, program, renderer, window, winit, Clipboard, Color,
+ Debug, Size,
};
use winit::{
@@ -169,6 +169,7 @@ pub fn main() {
// Map window event to iced event
if let Some(event) = iced_winit::conversion::window_event(
+ window::Id::MAIN,
&event,
window.scale_factor(),
modifiers,
diff --git a/glutin/src/application.rs b/glutin/src/application.rs
index 1464bb2d..108d7ffa 100644
--- a/glutin/src/application.rs
+++ b/glutin/src/application.rs
@@ -435,6 +435,7 @@ async fn run_instance<A, E, C>(
state.update(context.window(), &window_event, &mut debug);
if let Some(event) = conversion::window_event(
+ crate::window::Id::MAIN,
&window_event,
state.scale_factor(),
state.modifiers(),
diff --git a/native/src/command/action.rs b/native/src/command/action.rs
index a6954f8f..924f95e6 100644
--- a/native/src/command/action.rs
+++ b/native/src/command/action.rs
@@ -20,7 +20,7 @@ pub enum Action<T> {
Clipboard(clipboard::Action<T>),
/// Run a window action.
- Window(window::Action<T>),
+ Window(window::Id, window::Action<T>),
/// Run a system action.
System(system::Action<T>),
@@ -46,7 +46,7 @@ impl<T> Action<T> {
match self {
Self::Future(future) => Action::Future(Box::pin(future.map(f))),
Self::Clipboard(action) => Action::Clipboard(action.map(f)),
- Self::Window(window) => Action::Window(window.map(f)),
+ Self::Window(id, window) => Action::Window(id, window.map(f)),
Self::System(system) => Action::System(system.map(f)),
Self::Widget(widget) => Action::Widget(widget.map(f)),
}
@@ -60,7 +60,9 @@ impl<T> fmt::Debug for Action<T> {
Self::Clipboard(action) => {
write!(f, "Action::Clipboard({:?})", action)
}
- Self::Window(action) => write!(f, "Action::Window({:?})", action),
+ Self::Window(id, action) => {
+ write!(f, "Action::Window({:?}, {:?})", id, action)
+ }
Self::System(action) => write!(f, "Action::System({:?})", action),
Self::Widget(_action) => write!(f, "Action::Widget"),
}
diff --git a/native/src/event.rs b/native/src/event.rs
index bcfaf891..eb826399 100644
--- a/native/src/event.rs
+++ b/native/src/event.rs
@@ -19,7 +19,7 @@ pub enum Event {
Mouse(mouse::Event),
/// A window event
- Window(window::Event),
+ Window(window::Id, window::Event),
/// A touch event
Touch(touch::Event),
diff --git a/native/src/window/id.rs b/native/src/window/id.rs
index 059cf4e7..5060e162 100644
--- a/native/src/window/id.rs
+++ b/native/src/window/id.rs
@@ -6,6 +6,9 @@ use std::hash::{Hash, Hasher};
pub struct Id(u64);
impl Id {
+ /// TODO(derezzedex): maybe change `u64` to an enum `Type::{Single, Multi(u64)}`
+ pub const MAIN: Self = Id(0);
+
/// TODO(derezzedex)
pub fn new(id: impl Hash) -> Id {
let mut hasher = DefaultHasher::new();
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)),
+ ))
}