Merge pull request #1738 from nicoburns/update-winit-0.28

Update to winit 0.28
This commit is contained in:
Héctor Ramón 2023-05-25 23:37:14 +02:00 committed by GitHub
commit c61a4cc21c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 78 additions and 45 deletions

View file

@ -2,12 +2,14 @@
pub mod icon; pub mod icon;
mod event; mod event;
mod level;
mod mode; mod mode;
mod redraw_request; mod redraw_request;
mod user_attention; mod user_attention;
pub use event::Event; pub use event::Event;
pub use icon::Icon; pub use icon::Icon;
pub use level::Level;
pub use mode::Mode; pub use mode::Mode;
pub use redraw_request::RedrawRequest; pub use redraw_request::RedrawRequest;
pub use user_attention::UserAttention; pub use user_attention::UserAttention;

19
core/src/window/level.rs Normal file
View file

@ -0,0 +1,19 @@
/// A window level groups windows with respect to their z-position.
///
/// The relative ordering between windows in different window levels is fixed.
/// The z-order of a window within the same window level may change dynamically
/// on user interaction.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum Level {
/// The default behavior.
#[default]
Normal,
/// The window will always be below normal windows.
///
/// This is useful for a widget-based app.
AlwaysOnBottom,
/// The window will always be on top of normal windows.
AlwaysOnTop,
}

View file

@ -5,7 +5,7 @@ pub use action::Action;
use crate::command::{self, Command}; use crate::command::{self, Command};
use crate::core::time::Instant; use crate::core::time::Instant;
use crate::core::window::{Event, Icon, Mode, UserAttention}; use crate::core::window::{Event, Icon, Level, Mode, UserAttention};
use crate::futures::subscription::{self, Subscription}; use crate::futures::subscription::{self, Subscription};
/// Subscribes to the frames of the window of the running application. /// Subscribes to the frames of the window of the running application.
@ -53,7 +53,7 @@ pub fn move_to<Message>(x: i32, y: i32) -> Command<Message> {
Command::single(command::Action::Window(Action::Move { x, y })) Command::single(command::Action::Window(Action::Move { x, y }))
} }
/// Sets the [`Mode`] of the window. /// Changes the [`Mode`] of the window.
pub fn change_mode<Message>(mode: Mode) -> Command<Message> { pub fn change_mode<Message>(mode: Mode) -> Command<Message> {
Command::single(command::Action::Window(Action::ChangeMode(mode))) Command::single(command::Action::Window(Action::ChangeMode(mode)))
} }
@ -99,9 +99,9 @@ pub fn gain_focus<Message>() -> Command<Message> {
Command::single(command::Action::Window(Action::GainFocus)) Command::single(command::Action::Window(Action::GainFocus))
} }
/// Changes whether or not the window will always be on top of other windows. /// Changes the window [`Level`].
pub fn change_always_on_top<Message>(on_top: bool) -> Command<Message> { pub fn change_level<Message>(level: Level) -> Command<Message> {
Command::single(command::Action::Window(Action::ChangeAlwaysOnTop(on_top))) Command::single(command::Action::Window(Action::ChangeLevel(level)))
} }
/// Fetches an identifier unique to the window. /// Fetches an identifier unique to the window.

View file

@ -1,13 +1,13 @@
use crate::core::window::{Icon, Mode, UserAttention}; use crate::core::window::{Icon, Level, Mode, UserAttention};
use crate::futures::MaybeSend; use crate::futures::MaybeSend;
use std::fmt; use std::fmt;
/// An operation to be performed on some window. /// An operation to be performed on some window.
pub enum Action<T> { pub enum Action<T> {
/// Closes the current window and exits the application. /// Close the current window and exits the application.
Close, Close,
/// Moves the window with the left mouse button until the button is /// Move the window with the left mouse button until the button is
/// released. /// released.
/// ///
/// Theres no guarantee that this will work unless the left mouse /// Theres no guarantee that this will work unless the left mouse
@ -20,7 +20,7 @@ pub enum Action<T> {
/// The new logical height of the window /// The new logical height of the window
height: u32, height: u32,
}, },
/// Sets the window to maximized or back /// Set the window to maximized or back
Maximize(bool), Maximize(bool),
/// Set the window to minimized or back /// Set the window to minimized or back
Minimize(bool), Minimize(bool),
@ -70,15 +70,11 @@ pub enum Action<T> {
/// ///
/// - **Web / Wayland:** Unsupported. /// - **Web / Wayland:** Unsupported.
GainFocus, GainFocus,
/// Change whether or not the window will always be on top of other windows. /// Change the window [`Level`].
/// ChangeLevel(Level),
/// ## Platform-specific
///
/// - **Web / Wayland:** Unsupported.
ChangeAlwaysOnTop(bool),
/// Fetch an identifier unique to the window. /// Fetch an identifier unique to the window.
FetchId(Box<dyn FnOnce(u64) -> T + 'static>), FetchId(Box<dyn FnOnce(u64) -> T + 'static>),
/// Changes the window [`Icon`]. /// Change the window [`Icon`].
/// ///
/// On Windows and X11, this is typically the small icon in the top-left /// On Windows and X11, this is typically the small icon in the top-left
/// corner of the titlebar. /// corner of the titlebar.
@ -119,9 +115,7 @@ impl<T> Action<T> {
Action::RequestUserAttention(attention_type) Action::RequestUserAttention(attention_type)
} }
Self::GainFocus => Action::GainFocus, Self::GainFocus => Action::GainFocus,
Self::ChangeAlwaysOnTop(on_top) => { Self::ChangeLevel(level) => Action::ChangeLevel(level),
Action::ChangeAlwaysOnTop(on_top)
}
Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))), Self::FetchId(o) => Action::FetchId(Box::new(move |s| f(o(s)))),
Self::ChangeIcon(icon) => Action::ChangeIcon(icon), Self::ChangeIcon(icon) => Action::ChangeIcon(icon),
} }
@ -154,8 +148,8 @@ impl<T> fmt::Debug for Action<T> {
write!(f, "Action::RequestUserAttention") write!(f, "Action::RequestUserAttention")
} }
Self::GainFocus => write!(f, "Action::GainFocus"), Self::GainFocus => write!(f, "Action::GainFocus"),
Self::ChangeAlwaysOnTop(on_top) => { Self::ChangeLevel(level) => {
write!(f, "Action::AlwaysOnTop({on_top})") write!(f, "Action::ChangeLevel({level:?})")
} }
Self::FetchId(_) => write!(f, "Action::FetchId"), Self::FetchId(_) => write!(f, "Action::FetchId"),
Self::ChangeIcon(_icon) => { Self::ChangeIcon(_icon) => {

View file

@ -1,4 +1,4 @@
use crate::window::{Icon, Position}; use crate::window::{Icon, Level, Position};
pub use iced_winit::settings::PlatformSpecific; pub use iced_winit::settings::PlatformSpecific;
@ -29,8 +29,8 @@ pub struct Settings {
/// Whether the window should be transparent. /// Whether the window should be transparent.
pub transparent: bool, pub transparent: bool,
/// Whether the window will always be on top of other windows. /// The window [`Level`].
pub always_on_top: bool, pub level: Level,
/// The icon of the window. /// The icon of the window.
pub icon: Option<Icon>, pub icon: Option<Icon>,
@ -50,7 +50,7 @@ impl Default for Settings {
resizable: true, resizable: true,
decorations: true, decorations: true,
transparent: false, transparent: false,
always_on_top: false, level: Level::default(),
icon: None, icon: None,
platform_specific: Default::default(), platform_specific: Default::default(),
} }
@ -68,7 +68,7 @@ impl From<Settings> for iced_winit::settings::Window {
resizable: settings.resizable, resizable: settings.resizable,
decorations: settings.decorations, decorations: settings.decorations,
transparent: settings.transparent, transparent: settings.transparent,
always_on_top: settings.always_on_top, level: settings.level,
icon: settings.icon.map(Icon::into), icon: settings.icon.map(Icon::into),
platform_specific: settings.platform_specific, platform_specific: settings.platform_specific,
} }

View file

@ -23,14 +23,15 @@ wayland-dlopen = ["winit/wayland-dlopen"]
wayland-csd-adwaita = ["winit/wayland-csd-adwaita"] wayland-csd-adwaita = ["winit/wayland-csd-adwaita"]
[dependencies] [dependencies]
window_clipboard = "0.2" window_clipboard = "0.3"
log = "0.4" log = "0.4"
thiserror = "1.0" thiserror = "1.0"
raw-window-handle = "0.5"
[dependencies.winit] [dependencies.winit]
version = "0.27" version = "0.28"
git = "https://github.com/iced-rs/winit.git" git = "https://github.com/iced-rs/winit.git"
rev = "940457522e9fb9f5dac228b0ecfafe0138b4048c" rev = "ac1ddfe0bd870910b3aa64a18d386fdd55b30a1d"
default-features = false default-features = false
[dependencies.iced_runtime] [dependencies.iced_runtime]

View file

@ -794,8 +794,8 @@ pub fn run_command<A, E>(
window::Action::GainFocus => { window::Action::GainFocus => {
window.focus_window(); window.focus_window();
} }
window::Action::ChangeAlwaysOnTop(on_top) => { window::Action::ChangeLevel(level) => {
window.set_always_on_top(on_top); window.set_window_level(conversion::window_level(level));
} }
window::Action::FetchId(tag) => { window::Action::FetchId(tag) => {
proxy proxy

View file

@ -140,6 +140,19 @@ pub fn window_event(
} }
} }
/// Converts a [`window::Level`] to a [`winit`] window level.
///
/// [`winit`]: https://github.com/rust-windowing/winit
pub fn window_level(level: window::Level) -> winit::window::WindowLevel {
match level {
window::Level::Normal => winit::window::WindowLevel::Normal,
window::Level::AlwaysOnBottom => {
winit::window::WindowLevel::AlwaysOnBottom
}
window::Level::AlwaysOnTop => winit::window::WindowLevel::AlwaysOnTop,
}
}
/// Converts a [`Position`] to a [`winit`] logical position for a given monitor. /// Converts a [`Position`] to a [`winit`] logical position for a given monitor.
/// ///
/// [`winit`]: https://github.com/rust-windowing/winit /// [`winit`]: https://github.com/rust-windowing/winit

View file

@ -25,9 +25,10 @@
clippy::from_over_into, clippy::from_over_into,
clippy::needless_borrow, clippy::needless_borrow,
clippy::new_without_default, clippy::new_without_default,
clippy::useless_conversion clippy::useless_conversion,
unsafe_code
)] )]
#![forbid(rust_2018_idioms, unsafe_code)] #![forbid(rust_2018_idioms)]
#![allow(clippy::inherent_to_string, clippy::type_complexity)] #![allow(clippy::inherent_to_string, clippy::type_complexity)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))] #![cfg_attr(docsrs, feature(doc_auto_cfg))]
pub use iced_graphics as graphics; pub use iced_graphics as graphics;

View file

@ -22,7 +22,7 @@ mod platform;
pub use platform::PlatformSpecific; pub use platform::PlatformSpecific;
use crate::conversion; use crate::conversion;
use crate::core::window::Icon; use crate::core::window::{Icon, Level};
use crate::Position; use crate::Position;
use winit::monitor::MonitorHandle; use winit::monitor::MonitorHandle;
@ -81,8 +81,8 @@ pub struct Window {
/// Whether the window should be transparent. /// Whether the window should be transparent.
pub transparent: bool, pub transparent: bool,
/// Whether the window will always be on top of other windows. /// The window [`Level`].
pub always_on_top: bool, pub level: Level,
/// The window icon, which is also usually used in the taskbar /// The window icon, which is also usually used in the taskbar
pub icon: Option<Icon>, pub icon: Option<Icon>,
@ -102,7 +102,7 @@ impl fmt::Debug for Window {
.field("resizable", &self.resizable) .field("resizable", &self.resizable)
.field("decorations", &self.decorations) .field("decorations", &self.decorations)
.field("transparent", &self.transparent) .field("transparent", &self.transparent)
.field("always_on_top", &self.always_on_top) .field("level", &self.level)
.field("icon", &self.icon.is_some()) .field("icon", &self.icon.is_some())
.field("platform_specific", &self.platform_specific) .field("platform_specific", &self.platform_specific)
.finish() .finish()
@ -128,7 +128,7 @@ impl Window {
.with_decorations(self.decorations) .with_decorations(self.decorations)
.with_transparent(self.transparent) .with_transparent(self.transparent)
.with_window_icon(self.icon.and_then(conversion::icon)) .with_window_icon(self.icon.and_then(conversion::icon))
.with_always_on_top(self.always_on_top) .with_window_level(conversion::window_level(self.level))
.with_visible(self.visible); .with_visible(self.visible);
if let Some(position) = conversion::position( if let Some(position) = conversion::position(
@ -157,7 +157,9 @@ impl Window {
target_os = "openbsd" target_os = "openbsd"
))] ))]
{ {
use ::winit::platform::unix::WindowBuilderExtUnix; // `with_name` is available on both `WindowBuilderExtWayland` and `WindowBuilderExtX11` and they do
// exactly the same thing. We arbitrarily choose `WindowBuilderExtWayland` here.
use ::winit::platform::wayland::WindowBuilderExtWayland;
if let Some(id) = _id { if let Some(id) = _id {
window_builder = window_builder.with_name(id.clone(), id); window_builder = window_builder.with_name(id.clone(), id);
@ -167,11 +169,11 @@ impl Window {
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
use winit::platform::windows::WindowBuilderExtWindows; use winit::platform::windows::WindowBuilderExtWindows;
#[allow(unsafe_code)]
if let Some(parent) = self.platform_specific.parent { unsafe {
window_builder = window_builder.with_parent_window(parent); window_builder = window_builder
.with_parent_window(self.platform_specific.parent);
} }
window_builder = window_builder window_builder = window_builder
.with_drag_and_drop(self.platform_specific.drag_and_drop); .with_drag_and_drop(self.platform_specific.drag_and_drop);
} }
@ -205,7 +207,7 @@ impl Default for Window {
resizable: true, resizable: true,
decorations: true, decorations: true,
transparent: false, transparent: false,
always_on_top: false, level: Level::default(),
icon: None, icon: None,
platform_specific: Default::default(), platform_specific: Default::default(),
} }

View file

@ -1,10 +1,11 @@
//! Platform specific settings for Windows. //! Platform specific settings for Windows.
use raw_window_handle::RawWindowHandle;
/// The platform specific window settings of an application. /// The platform specific window settings of an application.
#[derive(Debug, Clone, Copy, PartialEq, Eq)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct PlatformSpecific { pub struct PlatformSpecific {
/// Parent window /// Parent window
pub parent: Option<winit::platform::windows::HWND>, pub parent: Option<RawWindowHandle>,
/// Drag and drop support /// Drag and drop support
pub drag_and_drop: bool, pub drag_and_drop: bool,