Skip to content

Commit

Permalink
fix(sctk): broadcast events after update
Browse files Browse the repository at this point in the history
when broadcasting events for no specific surface, it should be done after update so that the runtime subscription is current
  • Loading branch information
wash2 committed Feb 23, 2024
1 parent d2dc827 commit 8c2431d
Showing 1 changed file with 38 additions and 30 deletions.
68 changes: 38 additions & 30 deletions sctk/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 8c2431d

Please sign in to comment.