Skip to content

Commit c43c37b

Browse files
authored
fix!: Panic if the window is visible when the adapter is created, for adapters where this is a problem (#529)
1 parent 4aef05d commit c43c37b

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

platforms/windows/src/subclass.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,19 @@ impl SubclassingAdapter {
149149
/// This must be called on the thread that owns the window. The activation
150150
/// handler will always be called on that thread. The action handler
151151
/// may or may not be called on that thread.
152+
///
153+
/// # Panics
154+
///
155+
/// Panics if the window is already visible.
152156
pub fn new(
153157
hwnd: HWND,
154158
activation_handler: impl 'static + ActivationHandler,
155159
action_handler: impl 'static + ActionHandler + Send,
156160
) -> Self {
161+
if unsafe { IsWindowVisible(hwnd) }.into() {
162+
panic!("The AccessKit Windows subclassing adapter must be created before the window is shown (made visible) for the first time.");
163+
}
164+
157165
let mut r#impl = SubclassImpl::new(hwnd, activation_handler, action_handler);
158166
r#impl.install();
159167
Self(r#impl)

platforms/winit/src/lib.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ impl Adapter {
142142
/// until you send the first update. For an optimal implementation,
143143
/// consider using [`Adapter::with_direct_handlers`] or
144144
/// [`Adapter::with_mixed_handlers`] instead.
145+
///
146+
/// # Panics
147+
///
148+
/// Panics if the window is already visible.
145149
pub fn with_event_loop_proxy<T: From<Event> + Send + 'static>(
146150
event_loop: &ActiveEventLoop,
147151
window: &Window,
@@ -179,13 +183,21 @@ impl Adapter {
179183
/// some platform adapters to use a placeholder tree until you send
180184
/// the first update. However, remember that each of these handlers may be
181185
/// called on any thread, depending on the underlying platform adapter.
186+
///
187+
/// # Panics
188+
///
189+
/// Panics if the window is already visible.
182190
pub fn with_direct_handlers(
183191
event_loop: &ActiveEventLoop,
184192
window: &Window,
185193
activation_handler: impl 'static + ActivationHandler + Send,
186194
action_handler: impl 'static + ActionHandler + Send,
187195
deactivation_handler: impl 'static + DeactivationHandler + Send,
188196
) -> Self {
197+
if window.is_visible() == Some(true) {
198+
panic!("The AccessKit winit adapter must be created before the window is shown (made visible) for the first time.");
199+
}
200+
189201
let inner = platform_impl::Adapter::new(
190202
event_loop,
191203
window,
@@ -208,6 +220,10 @@ impl Adapter {
208220
/// while using a direct, caller-provided activation handler that can
209221
/// return the initial tree synchronously. Remember that the thread on which
210222
/// the activation handler is called is platform-dependent.
223+
///
224+
/// # Panics
225+
///
226+
/// Panics if the window is already visible.
211227
pub fn with_mixed_handlers<T: From<Event> + Send + 'static>(
212228
event_loop: &ActiveEventLoop,
213229
window: &Window,

0 commit comments

Comments
 (0)