Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ViewportCommand::InnerSize not resizing viewport on Wayland (#4211) #4211

Merged
merged 83 commits into from
Mar 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
1c62cbe
Update lib.rs
rustbasic Mar 22, 2024
53bfe46
Update lib.rs
rustbasic Mar 22, 2024
bf8c031
Merge branch 'emilk:master' into patch28
rustbasic Mar 22, 2024
418e287
Update lib.rs
rustbasic Mar 23, 2024
1b0ad1f
Update glow_integration.rs
rustbasic Mar 23, 2024
09eae9e
Update wgpu_integration.rs
rustbasic Mar 23, 2024
47337b5
Update glow_integration.rs
rustbasic Mar 23, 2024
431b244
Update wgpu_integration.rs
rustbasic Mar 23, 2024
ac1951c
Update glow_integration.rs
rustbasic Mar 23, 2024
302cb1b
Update wgpu_integration.rs
rustbasic Mar 23, 2024
6faa4ac
Update lib.rs
rustbasic Mar 23, 2024
f326abf
Update wgpu_integration.rs
rustbasic Mar 23, 2024
1eabdff
Update glow_integration.rs
rustbasic Mar 23, 2024
2f25d18
Update wgpu_integration.rs
rustbasic Mar 23, 2024
19bd398
Update glow_integration.rs
rustbasic Mar 23, 2024
9126521
Update lib.rs
rustbasic Mar 23, 2024
c868f48
Update wgpu_integration.rs
rustbasic Mar 23, 2024
1daa19f
Update glow_integration.rs
rustbasic Mar 23, 2024
2256cc2
Update glow_integration.rs
rustbasic Mar 23, 2024
583199f
Update wgpu_integration.rs
rustbasic Mar 23, 2024
615ae91
Update lib.rs
rustbasic Mar 24, 2024
79b9139
Update wgpu_integration.rs
rustbasic Mar 24, 2024
10057ed
Update wgpu_integration.rs
rustbasic Mar 25, 2024
fd81ac1
Update glow_integration.rs
rustbasic Mar 25, 2024
6c61066
Merge branch 'emilk:master' into patch28
rustbasic Mar 25, 2024
40bbc98
Update lib.rs
rustbasic Mar 25, 2024
06c2ab9
Update wgpu_integration.rs
rustbasic Mar 25, 2024
6b24739
Update glow_integration.rs
rustbasic Mar 25, 2024
7cab92d
Update wgpu_integration.rs
rustbasic Mar 25, 2024
bb9f6f3
Update wgpu_integration.rs
rustbasic Mar 25, 2024
6d1e0c3
Update lib.rs
rustbasic Mar 26, 2024
072becb
Merge branch 'emilk:master' into patch28
rustbasic Mar 26, 2024
a95fc8a
Merge branch 'emilk:master' into patch28
rustbasic Mar 27, 2024
1e250c6
Merge branch 'emilk:master' into patch28
rustbasic Mar 27, 2024
e5376c7
Update glow_integration.rs
rustbasic Mar 27, 2024
836a4e3
Update glow_integration.rs
rustbasic Mar 27, 2024
a34b30b
Update wgpu_integration.rs
rustbasic Mar 27, 2024
898af8b
Merge branch 'emilk:master' into patch28
rustbasic Mar 28, 2024
8d37a79
Update wgpu_integration.rs
rustbasic Mar 29, 2024
475f4f9
Update glow_integration.rs
rustbasic Mar 29, 2024
dae963f
Update lib.rs
rustbasic Mar 29, 2024
c0846fb
Update wgpu_integration.rs
rustbasic Mar 29, 2024
ce61769
Update lib.rs
rustbasic Mar 29, 2024
833eeb4
Update lib.rs
rustbasic Mar 29, 2024
a351d78
Update wgpu_integration.rs
rustbasic Mar 29, 2024
2c23d57
Update glow_integration.rs
rustbasic Mar 29, 2024
196dbfe
Update wgpu_integration.rs
rustbasic Mar 29, 2024
4dd9359
Update lib.rs
rustbasic Mar 29, 2024
699c919
Update lib.rs
rustbasic Mar 29, 2024
6e06da2
Update wgpu_integration.rs
rustbasic Mar 29, 2024
59c41f9
Update glow_integration.rs
rustbasic Mar 29, 2024
4bb2f3b
Update glow_integration.rs
rustbasic Mar 29, 2024
19f0418
Update wgpu_integration.rs
rustbasic Mar 29, 2024
bc8bd7d
Update glow_integration.rs
rustbasic Mar 29, 2024
01e91b0
Update wgpu_integration.rs
rustbasic Mar 29, 2024
5974aad
Merge branch 'emilk:master' into patch28
rustbasic Mar 29, 2024
46b1abb
Update lib.rs
rustbasic Mar 30, 2024
96c3da8
Update lib.rs
rustbasic Mar 30, 2024
ed3ec7e
Update glow_integration.rs
rustbasic Mar 30, 2024
cd342be
Update wgpu_integration.rs
rustbasic Mar 30, 2024
f0526b7
Update glow_integration.rs
rustbasic Mar 30, 2024
916efea
Update wgpu_integration.rs
rustbasic Mar 30, 2024
8833a05
Update wgpu_integration.rs
rustbasic Mar 30, 2024
ea77e72
Update glow_integration.rs
rustbasic Mar 30, 2024
41cb51f
Update wgpu_integration.rs
rustbasic Mar 30, 2024
b79d4a2
Update glow_integration.rs
rustbasic Mar 30, 2024
2ff20c6
Update glow_integration.rs
rustbasic Mar 30, 2024
003c73a
Update wgpu_integration.rs
rustbasic Mar 30, 2024
1d8baa6
Update glow_integration.rs
rustbasic Mar 30, 2024
e63616d
Update wgpu_integration.rs
rustbasic Mar 30, 2024
13deb07
Update glow_integration.rs
rustbasic Mar 30, 2024
2056f02
Update wgpu_integration.rs
rustbasic Mar 30, 2024
72ccd11
Merge branch 'emilk:master' into patch28
rustbasic Mar 30, 2024
52ed45f
Merge branch 'emilk:master' into patch28
rustbasic Mar 30, 2024
0668f39
Update wgpu_integration.rs
rustbasic Mar 30, 2024
ddfefa6
Merge branch 'emilk:master' into patch28
rustbasic Mar 30, 2024
d19c521
Rename `deferred_commands` and use `std::mem::take`
emilk Mar 30, 2024
1be505b
Merge branch 'master' into patch28
emilk Mar 30, 2024
bf46a1d
Initialize `minimized` and `maximized` correctly on Mac
emilk Mar 30, 2024
ed443b7
Remove unused parameters
emilk Mar 30, 2024
4beea7b
Clean up inner_rect_in_points and outer_rect_in_points
emilk Mar 30, 2024
882ce4a
Improve comments
emilk Mar 30, 2024
3c9c23a
Fix Android build
emilk Mar 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 50 additions & 43 deletions crates/eframe/src/native/glow_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ use winit::{

use egui::{
epaint::ahash::HashMap, DeferredViewportUiCallback, ImmediateViewport, ViewportBuilder,
ViewportClass, ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, ViewportInfo,
ViewportOutput,
ViewportClass, ViewportId, ViewportIdMap, ViewportIdPair, ViewportInfo, ViewportOutput,
};
#[cfg(feature = "accesskit")]
use egui_winit::accesskit_winit;
Expand Down Expand Up @@ -103,6 +102,7 @@ struct Viewport {
ids: ViewportIdPair,
class: ViewportClass,
builder: ViewportBuilder,
deferred_commands: Vec<egui::viewport::ViewportCommand>,
info: ViewportInfo,
screenshot_requested: bool,

Expand Down Expand Up @@ -554,7 +554,7 @@ impl GlowWinitRunning {
let Some(window) = viewport.window.as_ref() else {
return EventResult::Wait;
};
egui_winit::update_viewport_info(&mut viewport.info, &egui_ctx, window);
egui_winit::update_viewport_info(&mut viewport.info, &egui_ctx, window, false);

let Some(egui_winit) = viewport.egui_winit.as_mut() else {
return EventResult::Wait;
Expand Down Expand Up @@ -640,6 +640,8 @@ impl GlowWinitRunning {
viewport_output,
} = full_output;

glutin.remove_viewports_not_in(&viewport_output);

let GlutinWindowContext {
viewports,
current_gl_context,
Expand All @@ -649,6 +651,7 @@ impl GlowWinitRunning {
let Some(viewport) = viewports.get_mut(&viewport_id) else {
return EventResult::Wait;
};

viewport.info.events.clear(); // they should have been processed
let window = viewport.window.clone().unwrap();
let gl_surface = viewport.gl_surface.as_ref().unwrap();
Expand Down Expand Up @@ -715,7 +718,7 @@ impl GlowWinitRunning {
}
}

glutin.handle_viewport_output(event_loop, &integration.egui_ctx, viewport_output);
glutin.handle_viewport_output(event_loop, &integration.egui_ctx, &viewport_output);

integration.report_frame_time(frame_timer.total_time_sec()); // don't count auto-save time as part of regular frame time

Expand Down Expand Up @@ -998,8 +1001,7 @@ impl GlutinWindowContext {
if let Some(window) = &window {
viewport_from_window.insert(window.id(), ViewportId::ROOT);
window_from_viewport.insert(ViewportId::ROOT, window.id());
info.minimized = window.is_minimized();
info.maximized = Some(window.is_maximized());
egui_winit::update_viewport_info(&mut info, egui_ctx, window, true);
}

let mut viewports = ViewportIdMap::default();
Expand All @@ -1009,6 +1011,7 @@ impl GlutinWindowContext {
ids: ViewportIdPair::ROOT,
class: ViewportClass::Root,
builder: viewport_builder,
deferred_commands: vec![],
info,
screenshot_requested: false,
viewport_ui_cb: None,
Expand Down Expand Up @@ -1090,8 +1093,8 @@ impl GlutinWindowContext {
&window,
&viewport.builder,
);
viewport.info.minimized = window.is_minimized();
viewport.info.maximized = Some(window.is_maximized());

egui_winit::update_viewport_info(&mut viewport.info, &self.egui_ctx, &window, true);
viewport.window.insert(Arc::new(window))
};

Expand Down Expand Up @@ -1212,75 +1215,88 @@ impl GlutinWindowContext {
self.gl_config.display().get_proc_address(addr)
}

pub(crate) fn remove_viewports_not_in(
&mut self,
viewport_output: &ViewportIdMap<ViewportOutput>,
) {
// GC old viewports
self.viewports
.retain(|id, _| viewport_output.contains_key(id));
self.viewport_from_window
.retain(|_, id| viewport_output.contains_key(id));
self.window_from_viewport
.retain(|id, _| viewport_output.contains_key(id));
}

fn handle_viewport_output(
&mut self,
event_loop: &EventLoopWindowTarget<UserEvent>,
egui_ctx: &egui::Context,
viewport_output: ViewportIdMap<ViewportOutput>,
viewport_output: &ViewportIdMap<ViewportOutput>,
) {
crate::profile_function!();

let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect();

for (
viewport_id,
ViewportOutput {
parent,
class,
builder,
viewport_ui_cb,
commands,
mut commands,
repaint_delay: _, // ignored - we listened to the repaint callback instead
},
) in viewport_output
) in viewport_output.clone()
{
let ids = ViewportIdPair::from_self_and_parent(viewport_id, parent);

let viewport = initialize_or_update_viewport(
egui_ctx,
&mut self.viewports,
ids,
class,
builder,
viewport_ui_cb,
self.focused_viewport,
);

if let Some(window) = &viewport.window {
let old_inner_size = window.inner_size();

let is_viewport_focused = self.focused_viewport == Some(viewport_id);
viewport.deferred_commands.append(&mut commands);

egui_winit::process_viewport_commands(
egui_ctx,
&mut viewport.info,
commands,
std::mem::take(&mut viewport.deferred_commands),
window,
is_viewport_focused,
&mut viewport.screenshot_requested,
);

// For Wayland : https://github.com/emilk/egui/issues/4196
if cfg!(target_os = "linux") {
let new_inner_size = window.inner_size();
if new_inner_size != old_inner_size {
self.resize(viewport_id, new_inner_size);
}
}
}
}

// Create windows for any new viewports:
self.initialize_all_windows(event_loop);

// GC old viewports
self.viewports
.retain(|id, _| active_viewports_ids.contains(id));
self.viewport_from_window
.retain(|_, id| active_viewports_ids.contains(id));
self.window_from_viewport
.retain(|id, _| active_viewports_ids.contains(id));
self.remove_viewports_not_in(viewport_output);
}
}

fn initialize_or_update_viewport<'vp>(
egu_ctx: &egui::Context,
viewports: &'vp mut ViewportIdMap<Viewport>,
fn initialize_or_update_viewport(
viewports: &mut ViewportIdMap<Viewport>,
ids: ViewportIdPair,
class: ViewportClass,
mut builder: ViewportBuilder,
viewport_ui_cb: Option<Arc<dyn Fn(&egui::Context) + Send + Sync>>,
focused_viewport: Option<ViewportId>,
) -> &'vp mut Viewport {
) -> &mut Viewport {
crate::profile_function!();

if builder.icon.is_none() {
Expand All @@ -1298,6 +1314,7 @@ fn initialize_or_update_viewport<'vp>(
ids,
class,
builder,
deferred_commands: vec![],
info: Default::default(),
screenshot_requested: false,
viewport_ui_cb,
Expand All @@ -1315,7 +1332,7 @@ fn initialize_or_update_viewport<'vp>(
viewport.class = class;
viewport.viewport_ui_cb = viewport_ui_cb;

let (delta_commands, recreate) = viewport.builder.patch(builder);
let (mut delta_commands, recreate) = viewport.builder.patch(builder);

if recreate {
log::debug!(
Expand All @@ -1325,18 +1342,10 @@ fn initialize_or_update_viewport<'vp>(
);
viewport.window = None;
viewport.egui_winit = None;
} else if let Some(window) = &viewport.window {
let is_viewport_focused = focused_viewport == Some(ids.this);
egui_winit::process_viewport_commands(
egu_ctx,
&mut viewport.info,
delta_commands,
window,
is_viewport_focused,
&mut viewport.screenshot_requested,
);
}

viewport.deferred_commands.append(&mut delta_commands);

entry.into_mut()
}
}
Expand Down Expand Up @@ -1366,13 +1375,11 @@ fn render_immediate_viewport(
let mut glutin = glutin.borrow_mut();

initialize_or_update_viewport(
egui_ctx,
&mut glutin.viewports,
ids,
ViewportClass::Immediate,
builder,
None,
None,
);

if let Err(err) = glutin.initialize_window(viewport_id, event_loop) {
Expand All @@ -1392,7 +1399,7 @@ fn render_immediate_viewport(
let (Some(egui_winit), Some(window)) = (&mut viewport.egui_winit, &viewport.window) else {
return;
};
egui_winit::update_viewport_info(&mut viewport.info, egui_ctx, window);
egui_winit::update_viewport_info(&mut viewport.info, egui_ctx, window, false);

let mut raw_input = egui_winit.take_egui_input(window);
raw_input.viewports = glutin
Expand Down Expand Up @@ -1480,7 +1487,7 @@ fn render_immediate_viewport(

egui_winit.handle_platform_output(window, platform_output);

glutin.handle_viewport_output(event_loop, egui_ctx, viewport_output);
glutin.handle_viewport_output(event_loop, egui_ctx, &viewport_output);
}

#[cfg(feature = "__screenshot")]
Expand Down
Loading
Loading