Skip to content

Commit

Permalink
fix: should refresh surface only after ui changed
Browse files Browse the repository at this point in the history
  • Loading branch information
Decodetalkers committed Jan 16, 2025
1 parent 76a9c0c commit e005014
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion iced_layershell/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,8 +576,8 @@ async fn run_instance<A, E, C>(
state.logical_size(),
&mut debug,
));
custom_actions.push(LayerShellAction::RedrawAll);
}
custom_actions.push(LayerShellAction::RedrawAll);
}
_ => unreachable!(),
}
Expand Down
20 changes: 12 additions & 8 deletions iced_layershell/src/multi_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,7 @@ async fn run_instance<A, E, C>(
if events.is_empty() && messages.is_empty() {
continue;
}
let message_empty = messages.is_empty();

debug.event_processing_started();

Expand Down Expand Up @@ -772,9 +773,12 @@ async fn run_instance<A, E, C>(
&mut messages,
);

window_refresh_events.push(LayerShellAction::RedrawWindow(window.id));
let uis_stale_oudated = matches!(ui_state, user_interface::State::Outdated);
if uis_stale_oudated && !message_empty {
window_refresh_events.push(LayerShellAction::RedrawWindow(window.id));
}
if !uis_stale {
uis_stale = matches!(ui_state, user_interface::State::Outdated);
uis_stale = uis_stale_oudated;
}

debug.event_processing_finished();
Expand All @@ -788,17 +792,17 @@ async fn run_instance<A, E, C>(
}
}

let mut already_redraw_all = false;
let mut 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;
redraw_all = true;
}

// TODO mw application update returns which window IDs to update
if !messages.is_empty() || uis_stale {
if !message_empty || uis_stale {
let cached_interfaces: HashMap<window::Id, user_interface::Cache> =
ManuallyDrop::into_inner(user_interfaces)
.drain()
Expand All @@ -812,8 +816,8 @@ async fn run_instance<A, E, C>(
window.state.synchronize(&application);
}

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

Expand All @@ -827,7 +831,7 @@ async fn run_instance<A, E, C>(

// NOTE: only append the target window refresh event when not invoke the redrawAll
// event. This will make the events fewer.
if !already_redraw_all {
if !redraw_all {
custom_actions.append(&mut window_refresh_events);
}
}
Expand Down

0 comments on commit e005014

Please sign in to comment.