From 8c2431d27146dd72513f1997d786d1f4909e4752 Mon Sep 17 00:00:00 2001 From: Ashley Wulber Date: Fri, 23 Feb 2024 10:16:50 -0500 Subject: [PATCH] fix(sctk): broadcast events after update when broadcasting events for no specific surface, it should be done after update so that the runtime subscription is current --- sctk/src/application.rs | 68 +++++++++++++++++++++++------------------ 1 file changed, 38 insertions(+), 30 deletions(-) diff --git a/sctk/src/application.rs b/sctk/src/application.rs index 7c10decfd9..c319202515 100644 --- a/sctk/src/application.rs +++ b/sctk/src/application.rs @@ -926,36 +926,7 @@ where { continue; } - - let mut i = 0; - while i < sctk_events.len() { - let remove = matches!( - sctk_events[i], - SctkEvent::NewOutput { .. } - | SctkEvent::UpdateOutput { .. } - | SctkEvent::RemovedOutput(_) - | SctkEvent::SessionLocked - | SctkEvent::SessionLockFinished - | SctkEvent::SessionUnlocked - | SctkEvent::PopupEvent { .. } - | SctkEvent::LayerSurfaceEvent { .. } - | SctkEvent::WindowEvent { .. } - ); - if remove { - let event = sctk_events.remove(i); - for native_event in event.to_native( - &mut mods, - &surface_ids, - &destroyed_surface_ids, - ) { - runtime.broadcast(native_event, Status::Ignored); - } - } else { - i += 1; - } - } - - if surface_ids.is_empty() && !messages.is_empty() { + if surface_ids.is_empty() { // Update application let pure_states: HashMap<_, _> = ManuallyDrop::into_inner(interfaces) @@ -1242,6 +1213,43 @@ where redraw_pending = false; } + let mut i = 0; + while i < sctk_events.len() { + let remove = matches!( + sctk_events[i], + SctkEvent::NewOutput { .. } + | SctkEvent::UpdateOutput { .. } + | SctkEvent::RemovedOutput(_) + | SctkEvent::SessionLocked + | SctkEvent::SessionLockFinished + | SctkEvent::SessionUnlocked + | SctkEvent::PopupEvent { .. } + | SctkEvent::LayerSurfaceEvent { .. } + | SctkEvent::WindowEvent { .. } + ); + if remove { + let event = sctk_events.remove(i); + if matches!( + &event, + SctkEvent::NewOutput { .. } + | SctkEvent::UpdateOutput { .. } + | SctkEvent::RemovedOutput(_) + ) { + println!("Output event..."); + // dbg!(&event); + } + for native_event in event.to_native( + &mut mods, + &surface_ids, + &destroyed_surface_ids, + ) { + runtime.broadcast(native_event, Status::Ignored); + } + } else { + i += 1; + } + } + sctk_events.clear(); // clear the destroyed surfaces after they have been handled destroyed_surface_ids.clear();