summaryrefslogtreecommitdiffstats
path: root/winit
diff options
context:
space:
mode:
Diffstat (limited to 'winit')
-rw-r--r--winit/Cargo.toml6
-rw-r--r--winit/src/application.rs31
-rw-r--r--winit/src/conversion.rs28
-rw-r--r--winit/src/lib.rs2
-rw-r--r--winit/src/window.rs7
5 files changed, 51 insertions, 23 deletions
diff --git a/winit/Cargo.toml b/winit/Cargo.toml
index a3ac3ddd..ebbadb12 100644
--- a/winit/Cargo.toml
+++ b/winit/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "iced_winit"
-version = "0.5.1"
+version = "0.6.0"
authors = ["Héctor Ramón Jiménez <hector0193@gmail.com>"]
edition = "2021"
description = "A winit runtime for Iced"
@@ -26,11 +26,11 @@ git = "https://github.com/iced-rs/winit.git"
rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c"
[dependencies.iced_native]
-version = "0.6"
+version = "0.7"
path = "../native"
[dependencies.iced_graphics]
-version = "0.4"
+version = "0.5"
path = "../graphics"
[dependencies.iced_futures]
diff --git a/winit/src/application.rs b/winit/src/application.rs
index 1706d2e9..7092e124 100644
--- a/winit/src/application.rs
+++ b/winit/src/application.rs
@@ -93,13 +93,6 @@ where
fn scale_factor(&self) -> f64 {
1.0
}
-
- /// Returns whether the [`Application`] should be terminated.
- ///
- /// By default, it returns `false`.
- fn should_exit(&self) -> bool {
- false
- }
}
/// Runs an [`Application`] with an executor, compositor, and the provided
@@ -255,6 +248,7 @@ async fn run_instance<A, E, C>(
let mut clipboard = Clipboard::connect(&window);
let mut cache = user_interface::Cache::default();
let mut surface = compositor.create_surface(&window);
+ let mut should_exit = false;
let mut state = State::new(&application, &window);
let mut viewport_version = state.viewport_version();
@@ -275,6 +269,7 @@ async fn run_instance<A, E, C>(
init_command,
&mut runtime,
&mut clipboard,
+ &mut should_exit,
&mut proxy,
&mut debug,
&window,
@@ -336,6 +331,7 @@ async fn run_instance<A, E, C>(
&mut renderer,
&mut runtime,
&mut clipboard,
+ &mut should_exit,
&mut proxy,
&mut debug,
&mut messages,
@@ -346,8 +342,6 @@ async fn run_instance<A, E, C>(
// Update window
state.synchronize(&application, &window);
- let should_exit = application.should_exit();
-
user_interface = ManuallyDrop::new(build_user_interface(
&application,
cache,
@@ -555,6 +549,7 @@ pub fn update<A: Application, E: Executor>(
renderer: &mut A::Renderer,
runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>,
clipboard: &mut Clipboard,
+ should_exit: &mut bool,
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
debug: &mut Debug,
messages: &mut Vec<A::Message>,
@@ -578,6 +573,7 @@ pub fn update<A: Application, E: Executor>(
command,
runtime,
clipboard,
+ should_exit,
proxy,
debug,
window,
@@ -598,6 +594,7 @@ pub fn run_command<A, E>(
command: Command<A::Message>,
runtime: &mut Runtime<E, Proxy<A::Message>, A::Message>,
clipboard: &mut Clipboard,
+ should_exit: &mut bool,
proxy: &mut winit::event_loop::EventLoopProxy<A::Message>,
debug: &mut Debug,
window: &winit::window::Window,
@@ -629,6 +626,9 @@ pub fn run_command<A, E>(
}
},
command::Action::Window(action) => match action {
+ window::Action::Close => {
+ *should_exit = true;
+ }
window::Action::Drag => {
let _res = window.drag_window();
}
@@ -657,9 +657,6 @@ pub fn run_command<A, E>(
mode,
));
}
- window::Action::ToggleMaximize => {
- window.set_maximized(!window.is_maximized())
- }
window::Action::FetchMode(tag) => {
let mode = if window.is_visible().unwrap_or(true) {
conversion::mode(window.fullscreen())
@@ -671,6 +668,16 @@ pub fn run_command<A, E>(
.send_event(tag(mode))
.expect("Send message to event loop");
}
+ window::Action::ToggleMaximize => {
+ window.set_maximized(!window.is_maximized())
+ }
+ window::Action::ToggleDecorations => {
+ window.set_decorations(!window.is_decorated())
+ }
+ window::Action::RequestUserAttention(user_attention) => window
+ .request_user_attention(
+ user_attention.map(conversion::user_attention),
+ ),
},
command::Action::System(action) => match action {
system::Action::QueryInformation(_tag) => {
diff --git a/winit/src/conversion.rs b/winit/src/conversion.rs
index 0707aed5..1418e346 100644
--- a/winit/src/conversion.rs
+++ b/winit/src/conversion.rs
@@ -1,7 +1,7 @@
//! Convert [`winit`] types into [`iced_native`] types, and viceversa.
//!
//! [`winit`]: https://github.com/rust-windowing/winit
-//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
use crate::keyboard;
use crate::mouse;
use crate::touch;
@@ -218,7 +218,7 @@ pub fn mode(mode: Option<winit::window::Fullscreen>) -> window::Mode {
/// Converts a `MouseCursor` from [`iced_native`] to a [`winit`] cursor icon.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn mouse_interaction(
interaction: mouse::Interaction,
) -> winit::window::CursorIcon {
@@ -242,7 +242,7 @@ pub fn mouse_interaction(
/// Converts a `MouseButton` from [`winit`] to an [`iced_native`] mouse button.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
match mouse_button {
winit::event::MouseButton::Left => mouse::Button::Left,
@@ -258,7 +258,7 @@ pub fn mouse_button(mouse_button: winit::event::MouseButton) -> mouse::Button {
/// modifiers state.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn modifiers(
modifiers: winit::event::ModifiersState,
) -> keyboard::Modifiers {
@@ -285,7 +285,7 @@ pub fn cursor_position(
/// Converts a `Touch` from [`winit`] to an [`iced_native`] touch event.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn touch_event(
touch: winit::event::Touch,
scale_factor: f64,
@@ -316,7 +316,7 @@ pub fn touch_event(
/// Converts a `VirtualKeyCode` from [`winit`] to an [`iced_native`] key code.
///
/// [`winit`]: https://github.com/rust-windowing/winit
-/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+/// [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
pub fn key_code(
virtual_keycode: winit::event::VirtualKeyCode,
) -> keyboard::KeyCode {
@@ -493,6 +493,22 @@ pub fn key_code(
}
}
+/// Converts some [`UserAttention`] into it's `winit` counterpart.
+///
+/// [`UserAttention`]: window::UserAttention
+pub fn user_attention(
+ user_attention: window::UserAttention,
+) -> winit::window::UserAttentionType {
+ match user_attention {
+ window::UserAttention::Critical => {
+ winit::window::UserAttentionType::Critical
+ }
+ window::UserAttention::Informational => {
+ winit::window::UserAttentionType::Informational
+ }
+ }
+}
+
// As defined in: http://www.unicode.org/faq/private_use.html
pub(crate) fn is_private_use_character(c: char) -> bool {
matches!(
diff --git a/winit/src/lib.rs b/winit/src/lib.rs
index bb3a3d5b..b8ed492d 100644
--- a/winit/src/lib.rs
+++ b/winit/src/lib.rs
@@ -11,7 +11,7 @@
//! Additionally, a [`conversion`] module is available for users that decide to
//! implement a custom event loop.
//!
-//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.5/native
+//! [`iced_native`]: https://github.com/iced-rs/iced/tree/0.6/native
//! [`winit`]: https://github.com/rust-windowing/winit
//! [`conversion`]: crate::conversion
#![doc(
diff --git a/winit/src/window.rs b/winit/src/window.rs
index 1e704c5b..89db3262 100644
--- a/winit/src/window.rs
+++ b/winit/src/window.rs
@@ -2,7 +2,12 @@
use crate::command::{self, Command};
use iced_native::window;
-pub use window::{Event, Mode};
+pub use window::{Event, Mode, UserAttention};
+
+/// Closes the current window and exits the application.
+pub fn close<Message>() -> Command<Message> {
+ Command::single(command::Action::Window(window::Action::Close))
+}
/// Begins dragging the window while the left mouse button is held.
pub fn drag<Message>() -> Command<Message> {