Skip to content

Commit

Permalink
feat: make events fewer
Browse files Browse the repository at this point in the history
maybe can make the preformance better
  • Loading branch information
Decodetalkers committed Oct 23, 2024
1 parent 8293dcd commit eac3b83
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,7 @@ async fn run_instance<A, E, C>(

debug.event_processing_started();

let mut window_refresh_events = vec![];
let mut uis_stale = false;
let mut has_window_event = false;
for (id, window) in window_manager.iter_mut() {
Expand Down Expand Up @@ -755,7 +756,7 @@ async fn run_instance<A, E, C>(
&mut messages,
);

custom_actions.push(LayerShellAction::RedrawWindow(window.id));
window_refresh_events.push(LayerShellAction::RedrawWindow(window.id));
if !uis_stale {
uis_stale = matches!(ui_state, user_interface::State::Outdated);
}
Expand All @@ -771,11 +772,13 @@ async fn run_instance<A, E, C>(
}
}

let mut already_redraw_all = false;
// HACK: this logic is just from iced, but seems if there is no main window,
// any window will not get Outdated state.
// So here just check if there is window_events
if is_background_mode && has_window_event {
custom_actions.push(LayerShellAction::RedrawAll);
already_redraw_all = true;
}

// TODO mw application update returns which window IDs to update
Expand All @@ -794,6 +797,7 @@ async fn run_instance<A, E, C>(
}

if !is_background_mode {
already_redraw_all = true;
custom_actions.push(LayerShellAction::RedrawAll);
}

Expand All @@ -804,6 +808,12 @@ async fn run_instance<A, E, C>(
cached_interfaces,
));
}

// NOTE: only append the target window refresh event when not invoke the redrawAll
// event. This will make the events fewer.
if !already_redraw_all {
custom_actions.append(&mut window_refresh_events);
}
}
MultiWindowIcedLayerEvent(_, IcedLayerEvent::WindowRemoved(id)) => {
let mut cached_interfaces: HashMap<window::Id, user_interface::Cache> =
Expand Down

0 comments on commit eac3b83

Please sign in to comment.