From b684dd65687dd3b6920bfecc45eb6e895bff1733 Mon Sep 17 00:00:00 2001 From: Zacchary Dempsey-Plante Date: Sun, 27 Feb 2022 17:06:04 -0500 Subject: [PATCH] Send the `WindowHandle` with `AppDelegate::window_added`. (#2119) Co-authored-by: jneem --- CHANGELOG.md | 3 +++ druid/examples/multiwin.rs | 3 ++- druid/src/app_delegate.rs | 12 ++++++++++-- druid/src/win_handler.rs | 4 ++-- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1415a5cb57..5a21d82c89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ You can find its changes [documented below](#070---2021-01-01). - Add parent windows to non-main windows. (Coordinate space is now from their origin) ([#1919] by [@JAicewizard]) - `ListIter` implementations for `Arc>`, `(S, Arc>)`, `Arc>` and `(S, Arc>)` ([#1967] by [@xarvic]) - Closures passed to `Label::new` can now return any type that implements `Into` ([#2064] by [@jplatte]) +- `AppDelegate::window_added` now receives the new window's `WindowHandle`. ([#2119] by [@zedseven]) - Removed line of code that prevented window miximalization. ([#2113] by [@Pavel-N]) ### Deprecated @@ -536,6 +537,7 @@ Last release without a changelog :( [@klemensn]: https://github.com/klemensn [@agentsim]: https://github.com/agentsim [@jplatte]: https://github.com/jplatte +[@zedseven]: https://github.com/zedseven [@Pavel-N]: https://github.com/Pavel-N [@maurerdietmar]: https://github.com/maurerdietmar @@ -821,6 +823,7 @@ Last release without a changelog :( [#2036]: https://github.com/linebender/druid/pull/2036 [#2064]: https://github.com/linebender/druid/pull/2064 [#1979]: https://github.com/linebender/druid/pull/1979 +[#2119]: https://github.com/linebender/druid/pull/2119 [#2111]: https://github.com/linebender/druid/pull/2111 [#2117]: https://github.com/linebender/druid/pull/2117 diff --git a/druid/examples/multiwin.rs b/druid/examples/multiwin.rs index 051c8af624..1ccf4c7625 100644 --- a/druid/examples/multiwin.rs +++ b/druid/examples/multiwin.rs @@ -24,7 +24,7 @@ use druid::widget::{ use druid::Target::Global; use druid::{ commands as sys_cmds, AppDelegate, AppLauncher, Application, Color, Command, Data, DelegateCtx, - Handled, LocalizedString, Menu, MenuItem, Target, WindowDesc, WindowId, + Handled, LocalizedString, Menu, MenuItem, Target, WindowDesc, WindowHandle, WindowId, }; use tracing::info; @@ -170,6 +170,7 @@ impl AppDelegate for Delegate { fn window_added( &mut self, id: WindowId, + _handle: WindowHandle, _data: &mut State, _env: &Env, _ctx: &mut DelegateCtx, diff --git a/druid/src/app_delegate.rs b/druid/src/app_delegate.rs index ab444d1677..87ff69248c 100644 --- a/druid/src/app_delegate.rs +++ b/druid/src/app_delegate.rs @@ -18,7 +18,7 @@ use std::any::{Any, TypeId}; use crate::{ commands, core::CommandQueue, ext_event::ExtEventHost, Command, Data, Env, Event, ExtEventSink, - Handled, SingleUse, Target, WindowDesc, WindowId, + Handled, SingleUse, Target, WindowDesc, WindowHandle, WindowId, }; /// A context passed in to [`AppDelegate`] functions. @@ -128,7 +128,15 @@ pub trait AppDelegate { /// The handler for window creation events. /// This function is called after a window has been added, /// allowing you to customize the window creation behavior of your app. - fn window_added(&mut self, id: WindowId, data: &mut T, env: &Env, ctx: &mut DelegateCtx) {} + fn window_added( + &mut self, + id: WindowId, + handle: WindowHandle, + data: &mut T, + env: &Env, + ctx: &mut DelegateCtx, + ) { + } /// The handler for window deletion events. /// This function is called after a window has been removed. diff --git a/druid/src/win_handler.rs b/druid/src/win_handler.rs index 4465aaa3b8..1c8e26cac1 100644 --- a/druid/src/win_handler.rs +++ b/druid/src/win_handler.rs @@ -244,7 +244,7 @@ impl InnerAppState { fn connect(&mut self, id: WindowId, handle: WindowHandle) { self.windows - .connect(id, handle, self.ext_event_host.make_sink()); + .connect(id, handle.clone(), self.ext_event_host.make_sink()); // If the external event host has no handle, it cannot wake us // when an event arrives. @@ -252,7 +252,7 @@ impl InnerAppState { self.set_ext_event_idle_handler(id); } - self.with_delegate(|del, data, env, ctx| del.window_added(id, data, env, ctx)); + self.with_delegate(|del, data, env, ctx| del.window_added(id, handle, data, env, ctx)); } /// Called after this window has been closed by the platform.