Skip to content

Commit

Permalink
Send the WindowHandle with AppDelegate::window_added. (#2119)
Browse files Browse the repository at this point in the history
Co-authored-by: jneem <joeneeman@gmail.com>
  • Loading branch information
zedseven and jneem committed Feb 27, 2022
1 parent f261306 commit b684dd6
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<T>>`, `(S, Arc<Vec<T>>)`, `Arc<VecDequeue<T>>` and `(S, Arc<VecDequeue<T>>)` ([#1967] by [@xarvic])
- Closures passed to `Label::new` can now return any type that implements `Into<ArcStr>` ([#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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion druid/examples/multiwin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -170,6 +170,7 @@ impl AppDelegate<State> for Delegate {
fn window_added(
&mut self,
id: WindowId,
_handle: WindowHandle,
_data: &mut State,
_env: &Env,
_ctx: &mut DelegateCtx,
Expand Down
12 changes: 10 additions & 2 deletions druid/src/app_delegate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -128,7 +128,15 @@ pub trait AppDelegate<T: Data> {
/// 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.
Expand Down
4 changes: 2 additions & 2 deletions druid/src/win_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ impl<T: Data> InnerAppState<T> {

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.
if self.ext_event_host.handle_window_id.is_none() {
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.
Expand Down

0 comments on commit b684dd6

Please sign in to comment.