From 1c62cbe379b413325af58cb98bad942fa10c9aa0 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:04:01 +0900 Subject: [PATCH 01/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 418c39ece32..9b2fac91609 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -878,8 +878,9 @@ pub fn update_viewport_info( let pixels_per_point = pixels_per_point(egui_ctx, window); let has_a_position = match window.is_minimized() { - None | Some(true) => false, + Some(true) => false, Some(false) => true, + None => true, }; let inner_pos_px = if has_a_position { From 53bfe46f64392ce5c628462beb7f527e5836bddf Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 22 Mar 2024 22:22:50 +0900 Subject: [PATCH 02/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 9b2fac91609..ee16f47a0cb 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -879,8 +879,7 @@ pub fn update_viewport_info( let has_a_position = match window.is_minimized() { Some(true) => false, - Some(false) => true, - None => true, + Some(false) | None => true, }; let inner_pos_px = if has_a_position { From 418e287c108007487a5a70d0856e80984f845dac Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:48:47 +0900 Subject: [PATCH 03/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index ee16f47a0cb..0b0dd3c27f6 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1310,11 +1310,14 @@ fn process_viewport_command( ViewportCommand::InnerSize(size) => { let width_px = pixels_per_point * size.x.max(1.0); let height_px = pixels_per_point * size.y.max(1.0); - if window - .request_inner_size(PhysicalSize::new(width_px, height_px)) - .is_some() + if let Some(_inner_size) = + window.request_inner_size(PhysicalSize::new(width_px, height_px)) { - log::debug!("ViewportCommand::InnerSize ignored by winit"); + log::info!("ViewportCommand::InnerSize ignored by winit"); + } else { + log::trace!( + "the actual size will be delivered later with the [WindowEvent::Resized]" + ); } } ViewportCommand::BeginResize(direction) => { From 1b0ad1f7140d1516abccd38ae00dfedc62d3fbd3 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:52:30 +0900 Subject: [PATCH 04/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 90 +++----------------- 1 file changed, 10 insertions(+), 80 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 8b1f16ec807..839d41c6063 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1206,8 +1206,6 @@ impl GlutinWindowContext { ) { crate::profile_function!(); - let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); - for ( viewport_id, ViewportOutput { @@ -1218,7 +1216,7 @@ impl GlutinWindowContext { 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); @@ -1233,6 +1231,8 @@ impl GlutinWindowContext { ); if let Some(window) = &viewport.window { + let save_inner_size = window.inner_size(); + let is_viewport_focused = self.focused_viewport == Some(viewport_id); egui_winit::process_viewport_commands( egui_ctx, @@ -1242,89 +1242,19 @@ impl GlutinWindowContext { is_viewport_focused, &mut viewport.screenshot_requested, ); + + // For Wayland : https://github.com/emilk/egui/issues/4196 + let inner_size = window.inner_size(); + if inner_size != save_inner_size { + self.resize(viewport_id, 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)); - } -} - -fn initialize_or_update_viewport<'vp>( - egu_ctx: &egui::Context, - viewports: &'vp mut ViewportIdMap, - ids: ViewportIdPair, - class: ViewportClass, - mut builder: ViewportBuilder, - viewport_ui_cb: Option>, - focused_viewport: Option, -) -> &'vp mut Viewport { - crate::profile_function!(); - - if builder.icon.is_none() { - // Inherit icon from parent - builder.icon = viewports - .get_mut(&ids.parent) - .and_then(|vp| vp.builder.icon.clone()); - } - - match viewports.entry(ids.this) { - std::collections::hash_map::Entry::Vacant(entry) => { - // New viewport: - log::debug!("Creating new viewport {:?} ({:?})", ids.this, builder.title); - entry.insert(Viewport { - ids, - class, - builder, - info: Default::default(), - screenshot_requested: false, - viewport_ui_cb, - window: None, - egui_winit: None, - gl_surface: None, - }) - } - - std::collections::hash_map::Entry::Occupied(mut entry) => { - // Patch an existing viewport: - let viewport = entry.get_mut(); - - viewport.ids.parent = ids.parent; - viewport.class = class; - viewport.viewport_ui_cb = viewport_ui_cb; - - let (delta_commands, recreate) = viewport.builder.patch(builder); - - if recreate { - log::debug!( - "Recreating window for viewport {:?} ({:?})", - ids.this, - viewport.builder.title - ); - 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, - ); - } - - entry.into_mut() - } + self.active_viewports_retain(viewport_output); } } From 09eae9eeb1f0098c98b778a8c9927ed0aa335145 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:56:22 +0900 Subject: [PATCH 05/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 43 +++++++++++++++++--- 1 file changed, 37 insertions(+), 6 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 61bf157c007..f5c65a0a8e8 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -635,7 +635,7 @@ impl WgpuWinitRunning { // ------------------------------------------------------------ - let mut shared = shared.borrow_mut(); + let mut shared_mut = shared.borrow_mut(); let SharedState { egui_ctx, @@ -643,7 +643,7 @@ impl WgpuWinitRunning { painter, viewport_from_window, focused_viewport, - } = &mut *shared; + } = &mut *shared_mut; let Some(viewport) = viewports.get_mut(&viewport_id) else { return EventResult::Wait; @@ -696,9 +696,12 @@ impl WgpuWinitRunning { let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); handle_viewport_output( + shared, &integration.egui_ctx, viewport_output, viewports, + painter, + viewport_from_window, *focused_viewport, ); @@ -976,13 +979,13 @@ fn render_immediate_viewport( // ------------------------------------------ - let mut shared = shared.borrow_mut(); + let mut shared_mut = shared.borrow_mut(); let SharedState { viewports, painter, focused_viewport, .. - } = &mut *shared; + } = &mut *shared_mut; let Some(viewport) = viewports.get_mut(&ids.this) else { return; @@ -1014,14 +1017,25 @@ fn render_immediate_viewport( egui_winit.handle_platform_output(window, platform_output); - handle_viewport_output(&egui_ctx, viewport_output, viewports, *focused_viewport); + handle_viewport_output( + shared, + &egui_ctx, + viewport_output, + viewports, + painter, + viewport_from_window, + *focused_viewport, + ); } /// Add new viewports, and update existing ones: fn handle_viewport_output( + shared: &RefCell, egui_ctx: &egui::Context, viewport_output: ViewportIdMap, viewports: &mut ViewportIdMap, + painter: &mut egui_wgpu::winit::Painter, + viewport_from_window: &mut HashMap, focused_viewport: Option, ) { for ( @@ -1034,7 +1048,7 @@ fn handle_viewport_output( 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); @@ -1049,6 +1063,8 @@ fn handle_viewport_output( ); if let Some(window) = viewport.window.as_ref() { + let save_inner_size = window.inner_size(); + let is_viewport_focused = focused_viewport == Some(viewport_id); egui_winit::process_viewport_commands( egui_ctx, @@ -1058,8 +1074,23 @@ fn handle_viewport_output( is_viewport_focused, &mut viewport.screenshot_requested, ); + + // For Wayland : https://github.com/emilk/egui/issues/4196 + let inner_size = window.inner_size(); + if inner_size != save_inner_size { + use std::num::NonZeroU32; + if let (Some(width), Some(height)) = ( + NonZeroU32::new(inner_size.width), + NonZeroU32::new(inner_size.height), + ) { + let mut shared = shared.borrow_mut(); + shared.painter.on_window_resized(viewport_id, width, height); + } + } } } + + active_viewports_retain(viewports, painter, viewport_from_window, viewport_output); } fn initialize_or_update_viewport<'vp>( From 47337b5d90239c79b02cd5afdfaa0698069faf79 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:01:42 +0900 Subject: [PATCH 06/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 70 ++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 839d41c6063..8571763ac7e 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1258,6 +1258,76 @@ impl GlutinWindowContext { } } +fn initialize_or_update_viewport<'vp>( + egu_ctx: &egui::Context, + viewports: &'vp mut ViewportIdMap, + ids: ViewportIdPair, + class: ViewportClass, + mut builder: ViewportBuilder, + viewport_ui_cb: Option>, + focused_viewport: Option, +) -> &'vp mut Viewport { + crate::profile_function!(); + + if builder.icon.is_none() { + // Inherit icon from parent + builder.icon = viewports + .get_mut(&ids.parent) + .and_then(|vp| vp.builder.icon.clone()); + } + + match viewports.entry(ids.this) { + std::collections::hash_map::Entry::Vacant(entry) => { + // New viewport: + log::debug!("Creating new viewport {:?} ({:?})", ids.this, builder.title); + entry.insert(Viewport { + ids, + class, + builder, + info: Default::default(), + screenshot_requested: false, + viewport_ui_cb, + window: None, + egui_winit: None, + gl_surface: None, + }) + } + + std::collections::hash_map::Entry::Occupied(mut entry) => { + // Patch an existing viewport: + let viewport = entry.get_mut(); + + viewport.ids.parent = ids.parent; + viewport.class = class; + viewport.viewport_ui_cb = viewport_ui_cb; + + let (delta_commands, recreate) = viewport.builder.patch(builder); + + if recreate { + log::debug!( + "Recreating window for viewport {:?} ({:?})", + ids.this, + viewport.builder.title + ); + 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, + ); + } + + entry.into_mut() + } + } +} + /// This is called (via a callback) by user code to render immediate viewports, /// i.e. viewport that are directly nested inside a parent viewport. fn render_immediate_viewport( From 431b2442a1132db498b1ccf50c315e78fb16a048 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:03:13 +0900 Subject: [PATCH 07/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index f5c65a0a8e8..70019e53674 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1028,6 +1028,21 @@ fn render_immediate_viewport( ); } +#[allow(clippy::needless_pass_by_value)] +pub(crate) fn active_viewports_retain( + viewports: &mut ViewportIdMap, + painter: &mut egui_wgpu::winit::Painter, + viewport_from_window: &mut HashMap, + viewport_output: ViewportIdMap, +) { + let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); + + // Prune dead viewports: + viewports.retain(|id, _| active_viewports_ids.contains(id)); + viewport_from_window.retain(|_, id| active_viewports_ids.contains(id)); + painter.gc_viewports(&active_viewports_ids); +} + /// Add new viewports, and update existing ones: fn handle_viewport_output( shared: &RefCell, From ac1951ce583dbc8f1ca75ade83b6f966673346ee Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:04:37 +0900 Subject: [PATCH 08/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 8571763ac7e..18b82f343fb 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1198,6 +1198,22 @@ impl GlutinWindowContext { self.gl_config.display().get_proc_address(addr) } + #[allow(clippy::needless_pass_by_value)] + pub(crate) fn active_viewports_retain( + &mut self, + viewport_output: ViewportIdMap, + ) { + let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); + + // 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)); + } + fn handle_viewport_output( &mut self, event_loop: &EventLoopWindowTarget, From 302cb1b2b58566944574ef1d11bcfa57bbeeb1dd Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 23 Mar 2024 12:08:46 +0900 Subject: [PATCH 09/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 70019e53674..d2dc9ee0b8f 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -983,6 +983,7 @@ fn render_immediate_viewport( let SharedState { viewports, painter, + viewport_from_window, focused_viewport, .. } = &mut *shared_mut; From 6faa4ac6ba5e39c39281aa4018d331600922898d Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 00:51:36 +0900 Subject: [PATCH 10/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 136 ++++++++++++++++++++++------------- 1 file changed, 87 insertions(+), 49 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 0b0dd3c27f6..9475d9e891f 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -865,70 +865,89 @@ impl State { } } -/// Update the given viewport info with the current state of the window. -/// -/// Call before [`State::take_egui_input`]. -pub fn update_viewport_info( - viewport_info: &mut ViewportInfo, - egui_ctx: &egui::Context, - window: &Window, -) { - crate::profile_function!(); +pub fn math_inner_rect(window: &Window, pixels_per_point: Option) -> Option { + let pixels_per_point = match pixels_per_point { + Some(pixels_per_point) => pixels_per_point, + None => window.scale_factor() as f32, + }; - let pixels_per_point = pixels_per_point(egui_ctx, window); + let inner_pos_px = window + .inner_position() + .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) + .ok(); - let has_a_position = match window.is_minimized() { - Some(true) => false, - Some(false) | None => true, + let inner_size_px = { + let size = window.inner_size(); + Some(egui::Vec2::new(size.width as f32, size.height as f32)) }; - let inner_pos_px = if has_a_position { - window - .inner_position() - .map(|pos| Pos2::new(pos.x as f32, pos.y as f32)) - .ok() + let inner_rect_px = if let (Some(pos), Some(size)) = (inner_pos_px, inner_size_px) { + Some(egui::Rect::from_min_size(pos, size)) } else { None }; - let outer_pos_px = if has_a_position { - window - .outer_position() - .map(|pos| Pos2::new(pos.x as f32, pos.y as f32)) - .ok() - } else { - None - }; + let inner_rect = inner_rect_px.map(|r| r / pixels_per_point); - let inner_size_px = if has_a_position { - let size = window.inner_size(); - Some(Vec2::new(size.width as f32, size.height as f32)) - } else { - None + inner_rect +} + +pub fn math_outer_rect(window: &Window, pixels_per_point: Option) -> Option { + let pixels_per_point = match pixels_per_point { + Some(pixels_per_point) => pixels_per_point, + None => window.scale_factor() as f32, }; - let outer_size_px = if has_a_position { + let outer_pos_px = window + .outer_position() + .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) + .ok(); + + let outer_size_px = { let size = window.outer_size(); - Some(Vec2::new(size.width as f32, size.height as f32)) + Some(egui::Vec2::new(size.width as f32, size.height as f32)) + }; + + let outer_rect_px = if let (Some(pos), Some(size)) = (outer_pos_px, outer_size_px) { + Some(egui::Rect::from_min_size(pos, size)) } else { None }; - let inner_rect_px = if let (Some(pos), Some(size)) = (inner_pos_px, inner_size_px) { - Some(Rect::from_min_size(pos, size)) + let outer_rect = outer_rect_px.map(|r| r / pixels_per_point); + + outer_rect +} + +pub fn get_update_viewport_info( + viewport_info: &ViewportInfo, + window: &Window, + pixels_per_point: Option, +) -> ViewportInfo { + let mut update_info = viewport_info.clone(); + + let pixels_per_point = match pixels_per_point { + Some(pixels_per_point) => pixels_per_point, + None => window.scale_factor() as f32, + }; + + let has_a_position = match window.is_minimized() { + Some(true) => false, + Some(false) | None => true, + }; + + let inner_rect = if has_a_position { + math_inner_rect(window, Some(pixels_per_point)) } else { None }; - let outer_rect_px = if let (Some(pos), Some(size)) = (outer_pos_px, outer_size_px) { - Some(Rect::from_min_size(pos, size)) + let outer_rect = if has_a_position { + math_outer_rect(window, Some(pixels_per_point)) } else { None }; - let inner_rect = inner_rect_px.map(|r| r / pixels_per_point); - let outer_rect = outer_rect_px.map(|r| r / pixels_per_point); - let monitor_size = { crate::profile_scope!("monitor_size"); if let Some(monitor) = window.current_monitor() { @@ -939,21 +958,40 @@ pub fn update_viewport_info( } }; - viewport_info.focused = Some(window.has_focus()); - viewport_info.fullscreen = Some(window.fullscreen().is_some()); - viewport_info.inner_rect = inner_rect; - viewport_info.monitor_size = monitor_size; - viewport_info.native_pixels_per_point = Some(window.scale_factor() as f32); - viewport_info.outer_rect = outer_rect; - viewport_info.title = Some(window.title()); + update_info.title = Some(window.title()); + update_info.native_pixels_per_point = Some(window.scale_factor() as f32); + + update_info.monitor_size = monitor_size; + update_info.inner_rect = inner_rect; + update_info.outer_rect = outer_rect; if cfg!(target_os = "windows") { // It's tempting to do this, but it leads to a deadlock on Mac when running // `cargo run -p custom_window_frame`. // See https://github.com/emilk/egui/issues/3494 - viewport_info.maximized = Some(window.is_maximized()); - viewport_info.minimized = Some(window.is_minimized().unwrap_or(false)); + update_info.maximized = Some(window.is_maximized()); + update_info.minimized = Some(window.is_minimized().unwrap_or(false)); } + + update_info.fullscreen = Some(window.fullscreen().is_some()); + update_info.focused = Some(window.has_focus()); + + update_info +} + +/// Update the given viewport info with the current state of the window. +/// +/// Call before [`State::take_egui_input`]. +pub fn update_viewport_info( + viewport_info: &mut ViewportInfo, + egui_ctx: &egui::Context, + window: &Window, +) { + crate::profile_function!(); + + let pixels_per_point = Some(pixels_per_point(egui_ctx, window)); + + *viewport_info = get_update_viewport_info(viewport_info, window, pixels_per_point); } fn open_url_in_browser(_url: &str) { From f326abf93246172c1895d1170c6deff8101ce1d7 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 00:53:41 +0900 Subject: [PATCH 11/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 49 ++++++++++++++++---- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index d2dc9ee0b8f..6746596e89f 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1092,15 +1092,10 @@ fn handle_viewport_output( ); // For Wayland : https://github.com/emilk/egui/issues/4196 - let inner_size = window.inner_size(); - if inner_size != save_inner_size { - use std::num::NonZeroU32; - if let (Some(width), Some(height)) = ( - NonZeroU32::new(inner_size.width), - NonZeroU32::new(inner_size.height), - ) { - let mut shared = shared.borrow_mut(); - shared.painter.on_window_resized(viewport_id, width, height); + if cfg!(target_os = "linux") { + let inner_size = window.inner_size(); + if inner_size != save_inner_size { + resize_for_other_os(shared, egui_ctx, &viewport_id, window); } } } @@ -1109,6 +1104,42 @@ fn handle_viewport_output( active_viewports_retain(viewports, painter, viewport_from_window, viewport_output); } +fn resize_for_other_os( + shared: &RefCell, + egui_ctx: &egui::Context, + viewport_id: &ViewportId, + window: &Arc, +) { + use std::num::NonZeroU32; + + let inner_size = window.inner_size(); + + if let (Some(width), Some(height)) = ( + NonZeroU32::new(inner_size.width), + NonZeroU32::new(inner_size.height), + ) { + let mut shared = shared.borrow_mut(); + shared + .painter + .on_window_resized(*viewport_id, width, height); + shared.egui_ctx.input_mut(|input| { + let pixels_per_point = pixels_per_point(egui_ctx, window); + let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); + let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); + input + .raw + .viewports + .get_mut(viewport_id) + .map(|info| info.inner_rect = inner_rect); + input + .raw + .viewports + .get_mut(viewport_id) + .map(|info| info.outer_rect = outer_rect); + }); + } +} + fn initialize_or_update_viewport<'vp>( egui_ctx: &egui::Context, viewports: &'vp mut Viewports, From 1eabdffeb155a367e2f6a7b2c345ba80ee5e93aa Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:50:23 +0900 Subject: [PATCH 12/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 36 ++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 18b82f343fb..e32721112b3 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1260,9 +1260,11 @@ impl GlutinWindowContext { ); // For Wayland : https://github.com/emilk/egui/issues/4196 - let inner_size = window.inner_size(); - if inner_size != save_inner_size { - self.resize(viewport_id, inner_size); + if cfg!(target_os = "linux") { + let inner_size = window.inner_size(); + if inner_size != save_inner_size { + Self::resize_for_other_os(self, viewport_id, inner_size); + } } } } @@ -1272,6 +1274,34 @@ impl GlutinWindowContext { self.active_viewports_retain(viewport_output); } + + fn resize_for_other_os(&mut self, viewport_id: ViewportId, inner_size: PhysicalSize) { + self.resize(viewport_id, inner_size); + + let Some(viewport) = self.viewports.get(&viewport_id) else { + return; + }; + let Some(window) = &viewport.window else { + return; + }; + + let pixels_per_point = egui_winit::pixels_per_point(&self.egui_ctx, &window); + + self.egui_ctx.input_mut(|input| { + let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); + let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); + input + .raw + .viewports + .get_mut(&viewport_id) + .map(|info| info.inner_rect = inner_rect); + input + .raw + .viewports + .get_mut(&viewport_id) + .map(|info| info.outer_rect = outer_rect); + }); + } } fn initialize_or_update_viewport<'vp>( From 2f25d180babad93d47ae1769a095d1e9a84026aa Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:54:21 +0900 Subject: [PATCH 13/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 6746596e89f..251dba46db4 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1123,7 +1123,7 @@ fn resize_for_other_os( .painter .on_window_resized(*viewport_id, width, height); shared.egui_ctx.input_mut(|input| { - let pixels_per_point = pixels_per_point(egui_ctx, window); + let pixels_per_point = egui_winit::pixels_per_point(egui_ctx, window); let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); input From 19bd398c79e8384cc359a65b3e3dea9f47e9d79d Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 01:54:57 +0900 Subject: [PATCH 14/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index e32721112b3..35805f41772 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1275,7 +1275,11 @@ impl GlutinWindowContext { self.active_viewports_retain(viewport_output); } - fn resize_for_other_os(&mut self, viewport_id: ViewportId, inner_size: PhysicalSize) { + fn resize_for_other_os( + &mut self, + viewport_id: ViewportId, + inner_size: winit::dpi::PhysicalSize, + ) { self.resize(viewport_id, inner_size); let Some(viewport) = self.viewports.get(&viewport_id) else { From 91265214485b4a88883263c60460809b30945b9d Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 02:03:34 +0900 Subject: [PATCH 15/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 9475d9e891f..839c0b4d291 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -887,9 +887,7 @@ pub fn math_inner_rect(window: &Window, pixels_per_point: Option) -> Option None }; - let inner_rect = inner_rect_px.map(|r| r / pixels_per_point); - - inner_rect + inner_rect_px.map(|r| r / pixels_per_point) } pub fn math_outer_rect(window: &Window, pixels_per_point: Option) -> Option { @@ -914,9 +912,7 @@ pub fn math_outer_rect(window: &Window, pixels_per_point: Option) -> Option None }; - let outer_rect = outer_rect_px.map(|r| r / pixels_per_point); - - outer_rect + outer_rect_px.map(|r| r / pixels_per_point) } pub fn get_update_viewport_info( From c868f48017be28296f9e774b1d2af804113559c4 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 02:17:35 +0900 Subject: [PATCH 16/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 251dba46db4..10295e3a18f 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1126,16 +1126,10 @@ fn resize_for_other_os( let pixels_per_point = egui_winit::pixels_per_point(egui_ctx, window); let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); - input - .raw - .viewports - .get_mut(viewport_id) - .map(|info| info.inner_rect = inner_rect); - input - .raw - .viewports - .get_mut(viewport_id) - .map(|info| info.outer_rect = outer_rect); + if let Some(info) = input.raw.viewports.get_mut(&viewport_id) { + info.inner_rect = inner_rect; + info.outer_rect = outer_rect; + } }); } } From 1daa19fa12a584b4690a67658c06f77f7dd80035 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 02:19:17 +0900 Subject: [PATCH 17/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 35805f41772..99e9b14b83c 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1294,16 +1294,10 @@ impl GlutinWindowContext { self.egui_ctx.input_mut(|input| { let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); - input - .raw - .viewports - .get_mut(&viewport_id) - .map(|info| info.inner_rect = inner_rect); - input - .raw - .viewports - .get_mut(&viewport_id) - .map(|info| info.outer_rect = outer_rect); + if let Some(info) = input.raw.viewports.get_mut(&viewport_id) { + info.inner_rect = inner_rect; + info.outer_rect = outer_rect; + } }); } } From 2256cc2ca003ac788a94b527bb100ad37cf5c489 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 02:28:53 +0900 Subject: [PATCH 18/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 99e9b14b83c..858795bd6b2 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1289,7 +1289,7 @@ impl GlutinWindowContext { return; }; - let pixels_per_point = egui_winit::pixels_per_point(&self.egui_ctx, &window); + let pixels_per_point = egui_winit::pixels_per_point(&self.egui_ctx, window); self.egui_ctx.input_mut(|input| { let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); From 583199fb84c39aea990da75cf21d9e06dea9aa0f Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 02:29:46 +0900 Subject: [PATCH 19/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 10295e3a18f..1cfc7e7f277 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1126,7 +1126,7 @@ fn resize_for_other_os( let pixels_per_point = egui_winit::pixels_per_point(egui_ctx, window); let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); - if let Some(info) = input.raw.viewports.get_mut(&viewport_id) { + if let Some(info) = input.raw.viewports.get_mut(viewport_id) { info.inner_rect = inner_rect; info.outer_rect = outer_rect; } From 615ae911fa327dac4a1d3bc920f6866cb01355bb Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 09:57:13 +0900 Subject: [PATCH 20/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 839c0b4d291..ebaecc382d1 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -961,7 +961,7 @@ pub fn get_update_viewport_info( update_info.inner_rect = inner_rect; update_info.outer_rect = outer_rect; - if cfg!(target_os = "windows") { + if !cfg!(target_os = "macos") { // It's tempting to do this, but it leads to a deadlock on Mac when running // `cargo run -p custom_window_frame`. // See https://github.com/emilk/egui/issues/3494 From 79b91392b3f93dc0b90dc0313a39cffb26a89606 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sun, 24 Mar 2024 09:59:03 +0900 Subject: [PATCH 21/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 1cfc7e7f277..02900dc8ad1 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1095,7 +1095,7 @@ fn handle_viewport_output( if cfg!(target_os = "linux") { let inner_size = window.inner_size(); if inner_size != save_inner_size { - resize_for_other_os(shared, egui_ctx, &viewport_id, window); + resize_for_other_os(shared, egui_ctx, &viewport_id, window, inner_size); } } } @@ -1109,11 +1109,10 @@ fn resize_for_other_os( egui_ctx: &egui::Context, viewport_id: &ViewportId, window: &Arc, + inner_size: winit::dpi::PhysicalSize, ) { use std::num::NonZeroU32; - let inner_size = window.inner_size(); - if let (Some(width), Some(height)) = ( NonZeroU32::new(inner_size.width), NonZeroU32::new(inner_size.height), From 10057edc6a8e7c024e08fe06e8567a9d0b177fa0 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Mon, 25 Mar 2024 20:12:02 +0900 Subject: [PATCH 22/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 02900dc8ad1..3b322cfe143 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1030,7 +1030,7 @@ fn render_immediate_viewport( } #[allow(clippy::needless_pass_by_value)] -pub(crate) fn active_viewports_retain( +pub(crate) fn remove_viewports_not_in( viewports: &mut ViewportIdMap, painter: &mut egui_wgpu::winit::Painter, viewport_from_window: &mut HashMap, @@ -1101,7 +1101,7 @@ fn handle_viewport_output( } } - active_viewports_retain(viewports, painter, viewport_from_window, viewport_output); + remove_viewports_not_in(viewports, painter, viewport_from_window, viewport_output); } fn resize_for_other_os( From fd81ac1144e4571239ee34db465df5658151a582 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Mon, 25 Mar 2024 20:13:15 +0900 Subject: [PATCH 23/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 858795bd6b2..e456f3e20d4 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1199,7 +1199,7 @@ impl GlutinWindowContext { } #[allow(clippy::needless_pass_by_value)] - pub(crate) fn active_viewports_retain( + pub(crate) fn remove_viewports_not_in( &mut self, viewport_output: ViewportIdMap, ) { @@ -1272,7 +1272,7 @@ impl GlutinWindowContext { // Create windows for any new viewports: self.initialize_all_windows(event_loop); - self.active_viewports_retain(viewport_output); + self.remove_viewports_not_in(viewport_output); } fn resize_for_other_os( From 40bbc98df081536b08804c372859f99f12de4df7 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:50:31 +0900 Subject: [PATCH 24/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index ebaecc382d1..9aca019d167 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1347,12 +1347,15 @@ fn process_viewport_command( if let Some(_inner_size) = window.request_inner_size(PhysicalSize::new(width_px, height_px)) { - log::info!("ViewportCommand::InnerSize ignored by winit"); + // ex) linux + log::info!("ViewportCommand::InnerSize, not will be delivered later with the [WindowEvent::Resized]"); } else { - log::trace!( - "the actual size will be delivered later with the [WindowEvent::Resized]" - ); + // ex) Windows, MacOS + log::info!("ViewportCommand::InnerSize, will be delivered later with the [WindowEvent::Resized]"); } + + info.inner_rect = math_inner_rect(window, Some(pixels_per_point)); + info.outer_rect = math_outer_rect(window, Some(pixels_per_point)); } ViewportCommand::BeginResize(direction) => { if let Err(err) = window.drag_resize_window(match direction { From 06c2ab91da3cc34cc48f605b26c750d49e4ef2dc Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:52:52 +0900 Subject: [PATCH 25/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 3b322cfe143..86d735bcad4 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1121,15 +1121,6 @@ fn resize_for_other_os( shared .painter .on_window_resized(*viewport_id, width, height); - shared.egui_ctx.input_mut(|input| { - let pixels_per_point = egui_winit::pixels_per_point(egui_ctx, window); - let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); - let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); - if let Some(info) = input.raw.viewports.get_mut(viewport_id) { - info.inner_rect = inner_rect; - info.outer_rect = outer_rect; - } - }); } } From 6b247399b57324a5b4d77a12ce1727bdae3fb795 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Mon, 25 Mar 2024 23:54:13 +0900 Subject: [PATCH 26/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index e456f3e20d4..f087861608f 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1281,24 +1281,6 @@ impl GlutinWindowContext { inner_size: winit::dpi::PhysicalSize, ) { self.resize(viewport_id, inner_size); - - let Some(viewport) = self.viewports.get(&viewport_id) else { - return; - }; - let Some(window) = &viewport.window else { - return; - }; - - let pixels_per_point = egui_winit::pixels_per_point(&self.egui_ctx, window); - - self.egui_ctx.input_mut(|input| { - let inner_rect = egui_winit::math_inner_rect(window, Some(pixels_per_point)); - let outer_rect = egui_winit::math_outer_rect(window, Some(pixels_per_point)); - if let Some(info) = input.raw.viewports.get_mut(&viewport_id) { - info.inner_rect = inner_rect; - info.outer_rect = outer_rect; - } - }); } } From 7cab92dd36a1400c3a3f4a589861e69ca480804d Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:00:47 +0900 Subject: [PATCH 27/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 86d735bcad4..2d3bb8099fa 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1095,7 +1095,7 @@ fn handle_viewport_output( if cfg!(target_os = "linux") { let inner_size = window.inner_size(); if inner_size != save_inner_size { - resize_for_other_os(shared, egui_ctx, &viewport_id, window, inner_size); + resize_for_other_os(shared, &viewport_id, inner_size); } } } @@ -1106,9 +1106,7 @@ fn handle_viewport_output( fn resize_for_other_os( shared: &RefCell, - egui_ctx: &egui::Context, viewport_id: &ViewportId, - window: &Arc, inner_size: winit::dpi::PhysicalSize, ) { use std::num::NonZeroU32; From bb9f6f3a073e8871a2f4e6dc654243cbca3337a1 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 26 Mar 2024 00:51:51 +0900 Subject: [PATCH 28/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 2d3bb8099fa..79e54c9b207 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -696,7 +696,6 @@ impl WgpuWinitRunning { let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); handle_viewport_output( - shared, &integration.egui_ctx, viewport_output, viewports, @@ -1019,7 +1018,6 @@ fn render_immediate_viewport( egui_winit.handle_platform_output(window, platform_output); handle_viewport_output( - shared, &egui_ctx, viewport_output, viewports, @@ -1046,7 +1044,6 @@ pub(crate) fn remove_viewports_not_in( /// Add new viewports, and update existing ones: fn handle_viewport_output( - shared: &RefCell, egui_ctx: &egui::Context, viewport_output: ViewportIdMap, viewports: &mut ViewportIdMap, @@ -1095,7 +1092,7 @@ fn handle_viewport_output( if cfg!(target_os = "linux") { let inner_size = window.inner_size(); if inner_size != save_inner_size { - resize_for_other_os(shared, &viewport_id, inner_size); + resize_for_other_os(painter, &viewport_id, inner_size); } } } @@ -1105,7 +1102,7 @@ fn handle_viewport_output( } fn resize_for_other_os( - shared: &RefCell, + painter: &mut egui_wgpu::winit::Painter, viewport_id: &ViewportId, inner_size: winit::dpi::PhysicalSize, ) { @@ -1115,10 +1112,7 @@ fn resize_for_other_os( NonZeroU32::new(inner_size.width), NonZeroU32::new(inner_size.height), ) { - let mut shared = shared.borrow_mut(); - shared - .painter - .on_window_resized(*viewport_id, width, height); + painter.on_window_resized(*viewport_id, width, height); } } From 6d1e0c35d48e8719236c254e8e4b9ac3069dde6f Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:08:15 +0900 Subject: [PATCH 29/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 9aca019d167..ef9dd2617cc 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1349,13 +1349,13 @@ fn process_viewport_command( { // ex) linux log::info!("ViewportCommand::InnerSize, not will be delivered later with the [WindowEvent::Resized]"); + + info.inner_rect = math_inner_rect(window, Some(pixels_per_point)); + info.outer_rect = math_outer_rect(window, Some(pixels_per_point)); } else { // ex) Windows, MacOS log::info!("ViewportCommand::InnerSize, will be delivered later with the [WindowEvent::Resized]"); } - - info.inner_rect = math_inner_rect(window, Some(pixels_per_point)); - info.outer_rect = math_outer_rect(window, Some(pixels_per_point)); } ViewportCommand::BeginResize(direction) => { if let Err(err) = window.drag_resize_window(match direction { From e5376c76bb46ac3554165529b804744cafaaa442 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Wed, 27 Mar 2024 22:22:38 +0900 Subject: [PATCH 30/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index f087861608f..13996bd35df 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -976,8 +976,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()); + info = egui_winit::get_update_viewport_info(&ViewportInfo::default(), window, None); } let mut viewports = ViewportIdMap::default(); @@ -1068,8 +1067,8 @@ impl GlutinWindowContext { &window, &viewport.builder, ); - viewport.info.minimized = window.is_minimized(); - viewport.info.maximized = Some(window.is_maximized()); + + info = egui_winit::get_update_viewport_info(&ViewportInfo::default(), window, None); viewport.window.insert(Arc::new(window)) }; From 836a4e33af15b4257c42a73239ea58f2d42c21e9 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Wed, 27 Mar 2024 22:25:02 +0900 Subject: [PATCH 31/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 13996bd35df..c3881afb34d 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1068,7 +1068,7 @@ impl GlutinWindowContext { &viewport.builder, ); - info = egui_winit::get_update_viewport_info(&ViewportInfo::default(), window, None); + viewport.info = egui_winit::get_update_viewport_info(&viewport.info, &window, None); viewport.window.insert(Arc::new(window)) }; From a34b30b04bc6e0b657b2aeb58475167e82e8e9db Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Wed, 27 Mar 2024 22:27:29 +0900 Subject: [PATCH 32/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 79e54c9b207..4bc793dcb31 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -283,11 +283,7 @@ impl WgpuWinitApp { ids: ViewportIdPair::ROOT, class: ViewportClass::Root, builder, - info: ViewportInfo { - minimized: window.is_minimized(), - maximized: Some(window.is_maximized()), - ..Default::default() - }, + info: egui_winit::get_update_viewport_info(&ViewportInfo::default(), &window, None), screenshot_requested: false, viewport_ui_cb: None, window: Some(window), @@ -876,9 +872,7 @@ impl Viewport { painter.max_texture_side(), )); - self.info.minimized = window.is_minimized(); - self.info.maximized = Some(window.is_maximized()); - + self.info = egui_winit::get_update_viewport_info(&self.info, &window, None); self.window = Some(window); } Err(err) => { From 8d37a79d22c6ed06b510b3b019905d4d2df9f256 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:32:35 +0900 Subject: [PATCH 33/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index cc672d6103a..5a961306982 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -278,6 +278,9 @@ impl WgpuWinitApp { let mut viewport_from_window = HashMap::default(); viewport_from_window.insert(window.id(), ViewportId::ROOT); + let mut info = ViewportInfo::default(); + egui_winit::update_viewport_info_with_ppp(&mut info, &window, None); + let mut viewports = Viewports::default(); viewports.insert( ViewportId::ROOT, @@ -285,7 +288,7 @@ impl WgpuWinitApp { ids: ViewportIdPair::ROOT, class: ViewportClass::Root, builder, - info: egui_winit::get_update_viewport_info(&ViewportInfo::default(), &window, None), + info: info, screenshot_requested: false, viewport_ui_cb: None, window: Some(window), @@ -874,7 +877,7 @@ impl Viewport { painter.max_texture_side(), )); - self.info = egui_winit::get_update_viewport_info(&self.info, &window, None); + egui_winit::update_viewport_info(&mut self.info, egui_ctx, &window); self.window = Some(window); } Err(err) => { From 475f4f90c6804a64984a65af5729710e45a3df65 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:40:05 +0900 Subject: [PATCH 34/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index d77b6ceef94..6bdbf15aa13 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -980,7 +980,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 = egui_winit::get_update_viewport_info(&ViewportInfo::default(), window, None); + egui_winit::update_viewport_info(&mut info, egui_ctx, window); } let mut viewports = ViewportIdMap::default(); @@ -1072,7 +1072,7 @@ impl GlutinWindowContext { &viewport.builder, ); - viewport.info = egui_winit::get_update_viewport_info(&viewport.info, &window, None); + egui_winit::update_viewport_info(&mut viewport.info, &self.egui_ctx, &window); viewport.window.insert(Arc::new(window)) }; From dae963f1d6bf6c2283e5bca7f4acb4a4e161e29c Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:42:23 +0900 Subject: [PATCH 35/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 955bf31c3dc..a7df97354b4 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -915,13 +915,11 @@ pub fn math_outer_rect(window: &Window, pixels_per_point: Option) -> Option outer_rect_px.map(|r| r / pixels_per_point) } -pub fn get_update_viewport_info( - viewport_info: &ViewportInfo, +pub fn update_viewport_info_with_ppp( + viewport_info: &mut ViewportInfo, window: &Window, pixels_per_point: Option, -) -> ViewportInfo { - let mut update_info = viewport_info.clone(); - +) { let pixels_per_point = match pixels_per_point { Some(pixels_per_point) => pixels_per_point, None => window.scale_factor() as f32, @@ -954,25 +952,24 @@ pub fn get_update_viewport_info( } }; - update_info.title = Some(window.title()); - update_info.native_pixels_per_point = Some(window.scale_factor() as f32); + viewport_info.title = Some(window.title()); + viewport_info.native_pixels_per_point = Some(window.scale_factor() as f32); - update_info.monitor_size = monitor_size; - update_info.inner_rect = inner_rect; - update_info.outer_rect = outer_rect; + viewport_info.monitor_size = monitor_size; + viewport_info.inner_rect = inner_rect; + viewport_info.outer_rect = outer_rect; if !cfg!(target_os = "macos") { // It's tempting to do this, but it leads to a deadlock on Mac when running // `cargo run -p custom_window_frame`. // See https://github.com/emilk/egui/issues/3494 - update_info.maximized = Some(window.is_maximized()); - update_info.minimized = Some(window.is_minimized().unwrap_or(false)); + viewport_info.maximized = Some(window.is_maximized()); + viewport_info.minimized = Some(window.is_minimized().unwrap_or(false)); } - update_info.fullscreen = Some(window.fullscreen().is_some()); - update_info.focused = Some(window.has_focus()); - - update_info + viewport_info.fullscreen = Some(window.fullscreen().is_some()); + viewport_info.decorations = Some(window.is_decorated()); + viewport_info.focused = Some(window.has_focus()); } /// Update the given viewport info with the current state of the window. @@ -987,7 +984,7 @@ pub fn update_viewport_info( let pixels_per_point = Some(pixels_per_point(egui_ctx, window)); - *viewport_info = get_update_viewport_info(viewport_info, window, pixels_per_point); + update_viewport_info_with_ppp(viewport_info, window, pixels_per_point); } fn open_url_in_browser(_url: &str) { From c0846fbbee50fe186a79d81e02181cd9c8373de5 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:48:11 +0900 Subject: [PATCH 36/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 5a961306982..373b26c9816 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -279,7 +279,7 @@ impl WgpuWinitApp { viewport_from_window.insert(window.id(), ViewportId::ROOT); let mut info = ViewportInfo::default(); - egui_winit::update_viewport_info_with_ppp(&mut info, &window, None); + egui_winit::update_viewport_info(&mut info, &egui_ctx, &window); let mut viewports = Viewports::default(); viewports.insert( From ce6176932799bb00ed423feeb6c4b2f1a1e49b7d Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:54:04 +0900 Subject: [PATCH 37/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index a7df97354b4..3c22540cffc 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -915,15 +915,17 @@ pub fn math_outer_rect(window: &Window, pixels_per_point: Option) -> Option outer_rect_px.map(|r| r / pixels_per_point) } -pub fn update_viewport_info_with_ppp( +/// Update the given viewport info with the current state of the window. +/// +/// Call before [`State::take_egui_input`]. +pub fn update_viewport_info( viewport_info: &mut ViewportInfo, + egui_ctx: &egui::Context, window: &Window, - pixels_per_point: Option, ) { - let pixels_per_point = match pixels_per_point { - Some(pixels_per_point) => pixels_per_point, - None => window.scale_factor() as f32, - }; + crate::profile_function!(); + + let pixels_per_point = pixels_per_point(egui_ctx, window); let has_a_position = match window.is_minimized() { Some(true) => false, @@ -972,21 +974,6 @@ pub fn update_viewport_info_with_ppp( viewport_info.focused = Some(window.has_focus()); } -/// Update the given viewport info with the current state of the window. -/// -/// Call before [`State::take_egui_input`]. -pub fn update_viewport_info( - viewport_info: &mut ViewportInfo, - egui_ctx: &egui::Context, - window: &Window, -) { - crate::profile_function!(); - - let pixels_per_point = Some(pixels_per_point(egui_ctx, window)); - - update_viewport_info_with_ppp(viewport_info, window, pixels_per_point); -} - fn open_url_in_browser(_url: &str) { #[cfg(feature = "webbrowser")] if let Err(err) = webbrowser::open(_url) { From 833eeb4e213c09486cb38a71fc113feb6b8b3075 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 15:57:33 +0900 Subject: [PATCH 38/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 3c22540cffc..b3c5ff65271 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -970,7 +970,6 @@ pub fn update_viewport_info( } viewport_info.fullscreen = Some(window.fullscreen().is_some()); - viewport_info.decorations = Some(window.is_decorated()); viewport_info.focused = Some(window.has_focus()); } From a351d78b5c2bd54a911a53122056f7f117d2201c Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 16:13:37 +0900 Subject: [PATCH 39/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 373b26c9816..df72fe57cf7 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -288,7 +288,7 @@ impl WgpuWinitApp { ids: ViewportIdPair::ROOT, class: ViewportClass::Root, builder, - info: info, + info, screenshot_requested: false, viewport_ui_cb: None, window: Some(window), From 2c23d575a4eb3decae921dc1816e3a58606c0036 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:22:05 +0900 Subject: [PATCH 40/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 6bdbf15aa13..fe4713994d2 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1266,7 +1266,7 @@ impl GlutinWindowContext { if cfg!(target_os = "linux") { let inner_size = window.inner_size(); if inner_size != save_inner_size { - Self::resize_for_other_os(self, viewport_id, inner_size); + self.resize(viewport_id, inner_size); } } } @@ -1277,14 +1277,6 @@ impl GlutinWindowContext { self.remove_viewports_not_in(viewport_output); } - - fn resize_for_other_os( - &mut self, - viewport_id: ViewportId, - inner_size: winit::dpi::PhysicalSize, - ) { - self.resize(viewport_id, inner_size); - } } fn initialize_or_update_viewport<'vp>( From 196dbfeb2248ea4c518884d7cc28436da321921b Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:25:43 +0900 Subject: [PATCH 41/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 23 ++++++-------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index df72fe57cf7..40a6154dca5 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1091,7 +1091,13 @@ fn handle_viewport_output( if cfg!(target_os = "linux") { let inner_size = window.inner_size(); if inner_size != save_inner_size { - resize_for_other_os(painter, &viewport_id, inner_size); + use std::num::NonZeroU32; + if let (Some(width), Some(height)) = ( + NonZeroU32::new(inner_size.width), + NonZeroU32::new(inner_size.height), + ) { + painter.on_window_resized(viewport_id, width, height); + } } } } @@ -1100,21 +1106,6 @@ fn handle_viewport_output( remove_viewports_not_in(viewports, painter, viewport_from_window, viewport_output); } -fn resize_for_other_os( - painter: &mut egui_wgpu::winit::Painter, - viewport_id: &ViewportId, - inner_size: winit::dpi::PhysicalSize, -) { - use std::num::NonZeroU32; - - if let (Some(width), Some(height)) = ( - NonZeroU32::new(inner_size.width), - NonZeroU32::new(inner_size.height), - ) { - painter.on_window_resized(*viewport_id, width, height); - } -} - fn initialize_or_update_viewport<'vp>( egui_ctx: &egui::Context, viewports: &'vp mut Viewports, From 4dd9359cedb1a09de7cecd66888728c6c928e2ad Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:35:19 +0900 Subject: [PATCH 42/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index b3c5ff65271..cc44c45f91c 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -865,12 +865,7 @@ impl State { } } -pub fn math_inner_rect(window: &Window, pixels_per_point: Option) -> Option { - let pixels_per_point = match pixels_per_point { - Some(pixels_per_point) => pixels_per_point, - None => window.scale_factor() as f32, - }; - +pub fn math_inner_rect(window: &Window, pixels_per_point: f32) -> Option { let inner_pos_px = window .inner_position() .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) @@ -890,12 +885,7 @@ pub fn math_inner_rect(window: &Window, pixels_per_point: Option) -> Option inner_rect_px.map(|r| r / pixels_per_point) } -pub fn math_outer_rect(window: &Window, pixels_per_point: Option) -> Option { - let pixels_per_point = match pixels_per_point { - Some(pixels_per_point) => pixels_per_point, - None => window.scale_factor() as f32, - }; - +pub fn math_outer_rect(window: &Window, pixels_per_point: f32) -> Option { let outer_pos_px = window .outer_position() .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) @@ -933,13 +923,13 @@ pub fn update_viewport_info( }; let inner_rect = if has_a_position { - math_inner_rect(window, Some(pixels_per_point)) + math_inner_rect(window, pixels_per_point) } else { None }; let outer_rect = if has_a_position { - math_outer_rect(window, Some(pixels_per_point)) + math_outer_rect(window, pixels_per_point) } else { None }; @@ -1333,8 +1323,8 @@ fn process_viewport_command( // ex) linux log::info!("ViewportCommand::InnerSize, not will be delivered later with the [WindowEvent::Resized]"); - info.inner_rect = math_inner_rect(window, Some(pixels_per_point)); - info.outer_rect = math_outer_rect(window, Some(pixels_per_point)); + info.inner_rect = math_inner_rect(window, pixels_per_point); + info.outer_rect = math_outer_rect(window, pixels_per_point); } else { // ex) Windows, MacOS log::info!("ViewportCommand::InnerSize, will be delivered later with the [WindowEvent::Resized]"); From 699c919466d96ce251a391f8cae6e08b9c5193c2 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:42:57 +0900 Subject: [PATCH 43/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index cc44c45f91c..abc3ebffef7 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -865,7 +865,7 @@ impl State { } } -pub fn math_inner_rect(window: &Window, pixels_per_point: f32) -> Option { +pub fn inner_rect_in_points(window: &Window, pixels_per_point: f32) -> Option { let inner_pos_px = window .inner_position() .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) @@ -885,7 +885,7 @@ pub fn math_inner_rect(window: &Window, pixels_per_point: f32) -> Option { inner_rect_px.map(|r| r / pixels_per_point) } -pub fn math_outer_rect(window: &Window, pixels_per_point: f32) -> Option { +pub fn outer_rect_in_points(window: &Window, pixels_per_point: f32) -> Option { let outer_pos_px = window .outer_position() .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) @@ -923,13 +923,13 @@ pub fn update_viewport_info( }; let inner_rect = if has_a_position { - math_inner_rect(window, pixels_per_point) + inner_rect_in_points(window, pixels_per_point) } else { None }; let outer_rect = if has_a_position { - math_outer_rect(window, pixels_per_point) + outer_rect_in_points(window, pixels_per_point) } else { None }; @@ -1323,8 +1323,8 @@ fn process_viewport_command( // ex) linux log::info!("ViewportCommand::InnerSize, not will be delivered later with the [WindowEvent::Resized]"); - info.inner_rect = math_inner_rect(window, pixels_per_point); - info.outer_rect = math_outer_rect(window, pixels_per_point); + info.inner_rect = inner_rect_in_points(window, pixels_per_point); + info.outer_rect = outer_rect_in_points(window, pixels_per_point); } else { // ex) Windows, MacOS log::info!("ViewportCommand::InnerSize, will be delivered later with the [WindowEvent::Resized]"); From 6e06da2f3fe3939589bb8a852f4dfbc07af2ea6b Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 20:57:40 +0900 Subject: [PATCH 44/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 40a6154dca5..2cc66b3c454 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -669,6 +669,13 @@ impl WgpuWinitRunning { viewport_output, } = full_output; + remove_viewports_not_in( + viewports, + painter, + viewport_from_window, + &viewport_output, + ); + egui_winit.handle_platform_output(window, platform_output); let clipped_primitives = egui_ctx.tessellate(shapes, pixels_per_point); @@ -1026,12 +1033,11 @@ fn render_immediate_viewport( ); } -#[allow(clippy::needless_pass_by_value)] pub(crate) fn remove_viewports_not_in( viewports: &mut ViewportIdMap, painter: &mut egui_wgpu::winit::Painter, viewport_from_window: &mut HashMap, - viewport_output: ViewportIdMap, + viewport_output: &ViewportIdMap, ) { let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); @@ -1103,7 +1109,7 @@ fn handle_viewport_output( } } - remove_viewports_not_in(viewports, painter, viewport_from_window, viewport_output); + remove_viewports_not_in(viewports, painter, viewport_from_window, &viewport_output); } fn initialize_or_update_viewport<'vp>( From 59c41f96015cbfa46da2071b91a195e8ba55a49e Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:03:00 +0900 Subject: [PATCH 45/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index fe4713994d2..02b3a6625e2 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -632,6 +632,8 @@ impl GlowWinitRunning { viewport_output, } = full_output; + glutin.remove_viewports_not_in(&viewport_output); + let GlutinWindowContext { viewports, current_gl_context, @@ -1201,20 +1203,17 @@ impl GlutinWindowContext { self.gl_config.display().get_proc_address(addr) } - #[allow(clippy::needless_pass_by_value)] pub(crate) fn remove_viewports_not_in( &mut self, - viewport_output: ViewportIdMap, + viewport_output: &ViewportIdMap, ) { - let active_viewports_ids: ViewportIdSet = viewport_output.keys().copied().collect(); - // GC old viewports self.viewports - .retain(|id, _| active_viewports_ids.contains(id)); + .retain(|id, _| viewport_output.contains_key(id)); self.viewport_from_window - .retain(|_, id| active_viewports_ids.contains(id)); + .retain(|_, id| viewport_output.contains_key(id)); self.window_from_viewport - .retain(|id, _| active_viewports_ids.contains(id)); + .retain(|id, _| viewport_output.contains_key(id)); } fn handle_viewport_output( @@ -1275,7 +1274,7 @@ impl GlutinWindowContext { // Create windows for any new viewports: self.initialize_all_windows(event_loop); - self.remove_viewports_not_in(viewport_output); + self.remove_viewports_not_in(&viewport_output); } } From 4bb2f3b22053b51dcc2d2fb918f36fd873e69312 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:06:18 +0900 Subject: [PATCH 46/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 02b3a6625e2..3eda0133d05 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1249,7 +1249,7 @@ impl GlutinWindowContext { ); if let Some(window) = &viewport.window { - let save_inner_size = window.inner_size(); + let old_inner_size = window.inner_size(); let is_viewport_focused = self.focused_viewport == Some(viewport_id); egui_winit::process_viewport_commands( @@ -1263,9 +1263,9 @@ impl GlutinWindowContext { // For Wayland : https://github.com/emilk/egui/issues/4196 if cfg!(target_os = "linux") { - let inner_size = window.inner_size(); - if inner_size != save_inner_size { - self.resize(viewport_id, inner_size); + let new_inner_size = window.inner_size(); + if new_inner_size != old_inner_size { + self.resize(viewport_id, new_inner_size); } } } From 19f041853c86b24040b51bf83e3c1cd5a5357c01 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:08:14 +0900 Subject: [PATCH 47/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 2cc66b3c454..a8998b8c739 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1081,7 +1081,7 @@ fn handle_viewport_output( ); if let Some(window) = viewport.window.as_ref() { - let save_inner_size = window.inner_size(); + let old_inner_size = window.inner_size(); let is_viewport_focused = focused_viewport == Some(viewport_id); egui_winit::process_viewport_commands( @@ -1095,12 +1095,12 @@ fn handle_viewport_output( // For Wayland : https://github.com/emilk/egui/issues/4196 if cfg!(target_os = "linux") { - let inner_size = window.inner_size(); - if inner_size != save_inner_size { + let new_inner_size = window.inner_size(); + if new_inner_size != old_inner_size { use std::num::NonZeroU32; if let (Some(width), Some(height)) = ( - NonZeroU32::new(inner_size.width), - NonZeroU32::new(inner_size.height), + NonZeroU32::new(new_inner_size.width), + NonZeroU32::new(new_inner_size.height), ) { painter.on_window_resized(viewport_id, width, height); } From bc8bd7d2ef22e85aebca0f6d9d41d7a41c0533ec Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:25:57 +0900 Subject: [PATCH 48/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 3eda0133d05..a2dada6dfae 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -23,7 +23,7 @@ use winit::{ use egui::{ epaint::ahash::HashMap, DeferredViewportUiCallback, ImmediateViewport, NumExt as _, - ViewportBuilder, ViewportClass, ViewportId, ViewportIdMap, ViewportIdPair, ViewportIdSet, + ViewportBuilder, ViewportClass, ViewportId, ViewportIdMap, ViewportIdPair, ViewportInfo, ViewportOutput, }; #[cfg(feature = "accesskit")] @@ -548,13 +548,17 @@ impl GlowWinitRunning { let (raw_input, viewport_ui_cb) = { let mut glutin = self.glutin.borrow_mut(); let egui_ctx = glutin.egui_ctx.clone(); - let viewport = glutin.viewports.get_mut(&viewport_id).unwrap(); + let Some(viewport) = glutin.viewports.get_mut(&viewport_id) else { + return EventResult::Wait; + }; let Some(window) = viewport.window.as_ref() else { return EventResult::Wait; }; egui_winit::update_viewport_info(&mut viewport.info, &egui_ctx, window); - let egui_winit = viewport.egui_winit.as_mut().unwrap(); + let Some(egui_winit) = viewport.egui_winit.as_mut() else { + return EventResult::Wait; + }; let mut raw_input = egui_winit.take_egui_input(window); let viewport_ui_cb = viewport.viewport_ui_cb.clone(); @@ -640,7 +644,10 @@ impl GlowWinitRunning { .. } = &mut *glutin; - let viewport = viewports.get_mut(&viewport_id).unwrap(); + 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(); From 01e91b006e2f2dc99df7e46412eb3b86722e8bbf Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:45:48 +0900 Subject: [PATCH 49/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 30 ++++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index a8998b8c739..dff63286227 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -646,21 +646,6 @@ impl WgpuWinitRunning { focused_viewport, } = &mut *shared_mut; - let Some(viewport) = viewports.get_mut(&viewport_id) else { - return EventResult::Wait; - }; - - viewport.info.events.clear(); // they should have been processed - - let Viewport { - window: Some(window), - egui_winit: Some(egui_winit), - .. - } = viewport - else { - return EventResult::Wait; - }; - let FullOutput { platform_output, textures_delta, @@ -676,6 +661,21 @@ impl WgpuWinitRunning { &viewport_output, ); + let Some(viewport) = viewports.get_mut(&viewport_id) else { + return EventResult::Wait; + }; + + viewport.info.events.clear(); // they should have been processed + + let Viewport { + window: Some(window), + egui_winit: Some(egui_winit), + .. + } = viewport + else { + return EventResult::Wait; + }; + egui_winit.handle_platform_output(window, platform_output); let clipped_primitives = egui_ctx.tessellate(shapes, pixels_per_point); From 46b1abbb226ec079e56a9a5f6541307b46c9f3f7 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 11:30:00 +0900 Subject: [PATCH 50/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index abc3ebffef7..61b675240f7 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -866,43 +866,29 @@ impl State { } pub fn inner_rect_in_points(window: &Window, pixels_per_point: f32) -> Option { - let inner_pos_px = window - .inner_position() - .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) - .ok(); + let pos = window.inner_position().ok()?; + let inner_pos_px = egui::emath::Pos2::new(pos.x as f32, pos.y as f32); let inner_size_px = { let size = window.inner_size(); - Some(egui::Vec2::new(size.width as f32, size.height as f32)) + egui::Vec2::new(size.width as f32, size.height as f32) }; + let inner_rect_px = egui::Rect::from_min_size(inner_pos_px, inner_size_px); - let inner_rect_px = if let (Some(pos), Some(size)) = (inner_pos_px, inner_size_px) { - Some(egui::Rect::from_min_size(pos, size)) - } else { - None - }; - - inner_rect_px.map(|r| r / pixels_per_point) + Some(inner_rect_px / pixels_per_point) } pub fn outer_rect_in_points(window: &Window, pixels_per_point: f32) -> Option { - let outer_pos_px = window - .outer_position() - .map(|pos| egui::emath::Pos2::new(pos.x as f32, pos.y as f32)) - .ok(); + let pos = window.outer_position().ok()?; + let outer_pos_px = egui::emath::Pos2::new(pos.x as f32, pos.y as f32); let outer_size_px = { let size = window.outer_size(); - Some(egui::Vec2::new(size.width as f32, size.height as f32)) - }; - - let outer_rect_px = if let (Some(pos), Some(size)) = (outer_pos_px, outer_size_px) { - Some(egui::Rect::from_min_size(pos, size)) - } else { - None + egui::Vec2::new(size.width as f32, size.height as f32) }; + let outer_rect_px = egui::Rect::from_min_size(outer_pos_px, outer_size_px); - outer_rect_px.map(|r| r / pixels_per_point) + Some(outer_rect_px / pixels_per_point) } /// Update the given viewport info with the current state of the window. From 96c3da8529170148a9c1ba314a2b3fc2f3a6b3b6 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 11:37:40 +0900 Subject: [PATCH 51/72] Update lib.rs --- crates/egui-winit/src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 61b675240f7..36ecc2ccfbf 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1306,14 +1306,13 @@ fn process_viewport_command( if let Some(_inner_size) = window.request_inner_size(PhysicalSize::new(width_px, height_px)) { + // ViewportCommand::InnerSize, not will be delivered later with the [WindowEvent::Resized] // ex) linux - log::info!("ViewportCommand::InnerSize, not will be delivered later with the [WindowEvent::Resized]"); - info.inner_rect = inner_rect_in_points(window, pixels_per_point); info.outer_rect = outer_rect_in_points(window, pixels_per_point); } else { + // ViewportCommand::InnerSize, will be delivered later with the [WindowEvent::Resized] // ex) Windows, MacOS - log::info!("ViewportCommand::InnerSize, will be delivered later with the [WindowEvent::Resized]"); } } ViewportCommand::BeginResize(direction) => { From ed3ec7e7b70c8e15acf227f999544c5afc4a2b0c Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:06:04 +0900 Subject: [PATCH 52/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 21 ++++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index a2dada6dfae..f127e5d7172 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -103,6 +103,7 @@ struct Viewport { ids: ViewportIdPair, class: ViewportClass, builder: ViewportBuilder, + commands: Vec, info: ViewportInfo, screenshot_requested: bool, @@ -999,6 +1000,7 @@ impl GlutinWindowContext { ids: ViewportIdPair::ROOT, class: ViewportClass::Root, builder: viewport_builder, + commands: vec![], info, screenshot_requested: false, viewport_ui_cb: None, @@ -1237,6 +1239,7 @@ impl GlutinWindowContext { parent, class, builder, + mut commands, viewport_ui_cb, commands, repaint_delay: _, // ignored - we listened to the repaint callback instead @@ -1259,14 +1262,17 @@ impl GlutinWindowContext { let old_inner_size = window.inner_size(); let is_viewport_focused = self.focused_viewport == Some(viewport_id); + viewport.commands.append(&mut commands); + egui_winit::process_viewport_commands( egui_ctx, &mut viewport.info, - commands, + viewport.commands.clone(), window, is_viewport_focused, &mut viewport.screenshot_requested, ); + viewport.commands.clear(); // For Wayland : https://github.com/emilk/egui/issues/4196 if cfg!(target_os = "linux") { @@ -1311,6 +1317,7 @@ fn initialize_or_update_viewport<'vp>( ids, class, builder, + commands: vec![], info: Default::default(), screenshot_requested: false, viewport_ui_cb, @@ -1338,18 +1345,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.commands.append(&mut delta_commands); + entry.into_mut() } } From cd342bef8253c9164e962028f369310342523430 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:16:30 +0900 Subject: [PATCH 53/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 22 +++++++++----------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index dff63286227..185a9550292 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -76,6 +76,7 @@ pub struct Viewport { ids: ViewportIdPair, class: ViewportClass, builder: ViewportBuilder, + commands: Vec, info: ViewportInfo, screenshot_requested: bool, @@ -1063,7 +1064,7 @@ fn handle_viewport_output( class, builder, viewport_ui_cb, - commands, + mut commands, repaint_delay: _, // ignored - we listened to the repaint callback instead }, ) in viewport_output.clone() @@ -1084,14 +1085,18 @@ fn handle_viewport_output( let old_inner_size = window.inner_size(); let is_viewport_focused = focused_viewport == Some(viewport_id); + viewport.commands.append(&mut commands); + egui_winit::process_viewport_commands( egui_ctx, &mut viewport.info, + viewport.commands.clone(), commands, window, is_viewport_focused, &mut viewport.screenshot_requested, ); + viewport.commands.clear(); // For Wayland : https://github.com/emilk/egui/issues/4196 if cfg!(target_os = "linux") { @@ -1138,6 +1143,7 @@ fn initialize_or_update_viewport<'vp>( ids, class, builder, + commands: vec![], info: Default::default(), screenshot_requested: false, viewport_ui_cb, @@ -1154,7 +1160,7 @@ fn initialize_or_update_viewport<'vp>( viewport.ids.parent = ids.parent; 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!( @@ -1164,18 +1170,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( - egui_ctx, - &mut viewport.info, - delta_commands, - window, - is_viewport_focused, - &mut viewport.screenshot_requested, - ); } + viewport.commands.append(&mut delta_commands); + entry.into_mut() } } From f0526b78badb9087f1c60c8165a40fb4a8870f00 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:20:09 +0900 Subject: [PATCH 54/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index f127e5d7172..064e4023478 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1239,9 +1239,8 @@ impl GlutinWindowContext { parent, class, builder, - mut commands, viewport_ui_cb, - commands, + mut commands, repaint_delay: _, // ignored - we listened to the repaint callback instead }, ) in viewport_output.clone() From 916efea859b84006201ac770cdb315269fa4bbc4 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:22:48 +0900 Subject: [PATCH 55/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 185a9550292..2d1616abc41 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -289,6 +289,7 @@ impl WgpuWinitApp { ids: ViewportIdPair::ROOT, class: ViewportClass::Root, builder, + commands: vec![], info, screenshot_requested: false, viewport_ui_cb: None, From 8833a0509f84e9ffaa8cc6430571f7e3a1c84c71 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:30:17 +0900 Subject: [PATCH 56/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 2d1616abc41..b8ce70856ae 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1092,7 +1092,6 @@ fn handle_viewport_output( egui_ctx, &mut viewport.info, viewport.commands.clone(), - commands, window, is_viewport_focused, &mut viewport.screenshot_requested, From ea77e723a70aaa2505ffcc8a222ea1584b7f6433 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:35:54 +0900 Subject: [PATCH 57/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 064e4023478..3ad8369bfec 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1334,7 +1334,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!( From 41cb51f7bce86645e35b2882c0d4d0488aab094f Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:36:37 +0900 Subject: [PATCH 58/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index b8ce70856ae..fd03d91faec 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1118,13 +1118,13 @@ fn handle_viewport_output( } fn initialize_or_update_viewport<'vp>( - egui_ctx: &egui::Context, + _egui_ctx: &egui::Context, viewports: &'vp mut Viewports, ids: ViewportIdPair, class: ViewportClass, mut builder: ViewportBuilder, viewport_ui_cb: Option>, - focused_viewport: Option, + _focused_viewport: Option, ) -> &'vp mut Viewport { crate::profile_function!(); From b79d4a272cec556ad971e8a05c5e685ee58dccb4 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:38:15 +0900 Subject: [PATCH 59/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 3ad8369bfec..05bb140b0bc 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1291,13 +1291,13 @@ impl GlutinWindowContext { } fn initialize_or_update_viewport<'vp>( - egu_ctx: &egui::Context, + _egu_ctx: &egui::Context, viewports: &'vp mut ViewportIdMap, ids: ViewportIdPair, class: ViewportClass, mut builder: ViewportBuilder, viewport_ui_cb: Option>, - focused_viewport: Option, + _focused_viewport: Option, ) -> &'vp mut Viewport { crate::profile_function!(); From 2ff20c6f6fc428e8587958dd522dd7a911b7e5d9 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:43:50 +0900 Subject: [PATCH 60/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 05bb140b0bc..d86376888f9 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -23,8 +23,8 @@ use winit::{ use egui::{ epaint::ahash::HashMap, DeferredViewportUiCallback, ImmediateViewport, NumExt as _, - ViewportBuilder, ViewportClass, ViewportId, ViewportIdMap, ViewportIdPair, - ViewportInfo, ViewportOutput, + ViewportBuilder, ViewportClass, ViewportId, ViewportIdMap, ViewportIdPair, ViewportInfo, + ViewportOutput, }; #[cfg(feature = "accesskit")] use egui_winit::accesskit_winit; From 003c73a976d1394dd84e8a55828aec6034380ba9 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:44:28 +0900 Subject: [PATCH 61/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index fd03d91faec..f068357dc59 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -656,12 +656,7 @@ impl WgpuWinitRunning { viewport_output, } = full_output; - remove_viewports_not_in( - viewports, - painter, - viewport_from_window, - &viewport_output, - ); + remove_viewports_not_in(viewports, painter, viewport_from_window, &viewport_output); let Some(viewport) = viewports.get_mut(&viewport_id) else { return EventResult::Wait; From 1d8baa6aa681163d0a3de63a3ba49ff56fb013f3 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:55:13 +0900 Subject: [PATCH 62/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index d86376888f9..4a385cff7f5 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -715,7 +715,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 @@ -1229,7 +1229,7 @@ impl GlutinWindowContext { &mut self, event_loop: &EventLoopWindowTarget, egui_ctx: &egui::Context, - viewport_output: ViewportIdMap, + viewport_output: &ViewportIdMap, ) { crate::profile_function!(); @@ -1502,7 +1502,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")] From e63616dcab8cf80694326ab91abc3086bd78e5d2 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 15:57:12 +0900 Subject: [PATCH 63/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index f068357dc59..e6b2f2c0bdd 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -702,7 +702,7 @@ impl WgpuWinitRunning { handle_viewport_output( &integration.egui_ctx, - viewport_output, + &viewport_output, viewports, painter, viewport_from_window, @@ -1022,7 +1022,7 @@ fn render_immediate_viewport( handle_viewport_output( &egui_ctx, - viewport_output, + &viewport_output, viewports, painter, viewport_from_window, @@ -1047,7 +1047,7 @@ pub(crate) fn remove_viewports_not_in( /// Add new viewports, and update existing ones: fn handle_viewport_output( egui_ctx: &egui::Context, - viewport_output: ViewportIdMap, + viewport_output: &ViewportIdMap, viewports: &mut ViewportIdMap, painter: &mut egui_wgpu::winit::Painter, viewport_from_window: &mut HashMap, From 13deb071606a57153cc402ab74894b04d12fcf87 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 16:14:37 +0900 Subject: [PATCH 64/72] Update glow_integration.rs --- crates/eframe/src/native/glow_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index 4a385cff7f5..f220a2f551e 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1286,7 +1286,7 @@ impl GlutinWindowContext { // Create windows for any new viewports: self.initialize_all_windows(event_loop); - self.remove_viewports_not_in(&viewport_output); + self.remove_viewports_not_in(viewport_output); } } From 2056f02562a0ae3924fc826a4c5157d4ce60b841 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 16:15:34 +0900 Subject: [PATCH 65/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index e6b2f2c0bdd..a271489a5f5 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -1109,7 +1109,7 @@ fn handle_viewport_output( } } - remove_viewports_not_in(viewports, painter, viewport_from_window, &viewport_output); + remove_viewports_not_in(viewports, painter, viewport_from_window, viewport_output); } fn initialize_or_update_viewport<'vp>( From 0668f39e4180ad6814a68a6ac8f964718e522c44 Mon Sep 17 00:00:00 2001 From: rustbasic <127506429+rustbasic@users.noreply.github.com> Date: Sat, 30 Mar 2024 22:35:10 +0900 Subject: [PATCH 66/72] Update wgpu_integration.rs --- crates/eframe/src/native/wgpu_integration.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index a271489a5f5..b722dc44e00 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -616,7 +616,9 @@ impl WgpuWinitRunning { } } - let egui_winit = egui_winit.as_mut().unwrap(); + let Some(egui_winit) = egui_winit.as_mut() else { + return EventResult::Wait; + }; let mut raw_input = egui_winit.take_egui_input(window); integration.pre_update(); From d19c521ecd1707f773bb03075b65d7a2536a7835 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 Mar 2024 19:33:10 +0100 Subject: [PATCH 67/72] Rename `deferred_commands` and use `std::mem::take` --- crates/eframe/src/native/glow_integration.rs | 13 ++++++------- crates/eframe/src/native/wgpu_integration.rs | 13 ++++++------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index f220a2f551e..a1d4b187188 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -103,7 +103,7 @@ struct Viewport { ids: ViewportIdPair, class: ViewportClass, builder: ViewportBuilder, - commands: Vec, + deferred_commands: Vec, info: ViewportInfo, screenshot_requested: bool, @@ -1000,7 +1000,7 @@ impl GlutinWindowContext { ids: ViewportIdPair::ROOT, class: ViewportClass::Root, builder: viewport_builder, - commands: vec![], + deferred_commands: vec![], info, screenshot_requested: false, viewport_ui_cb: None, @@ -1261,17 +1261,16 @@ impl GlutinWindowContext { let old_inner_size = window.inner_size(); let is_viewport_focused = self.focused_viewport == Some(viewport_id); - viewport.commands.append(&mut commands); + viewport.deferred_commands.append(&mut commands); egui_winit::process_viewport_commands( egui_ctx, &mut viewport.info, - viewport.commands.clone(), + std::mem::take(&mut viewport.deferred_commands), window, is_viewport_focused, &mut viewport.screenshot_requested, ); - viewport.commands.clear(); // For Wayland : https://github.com/emilk/egui/issues/4196 if cfg!(target_os = "linux") { @@ -1316,7 +1315,7 @@ fn initialize_or_update_viewport<'vp>( ids, class, builder, - commands: vec![], + deferred_commands: vec![], info: Default::default(), screenshot_requested: false, viewport_ui_cb, @@ -1346,7 +1345,7 @@ fn initialize_or_update_viewport<'vp>( viewport.egui_winit = None; } - viewport.commands.append(&mut delta_commands); + viewport.deferred_commands.append(&mut delta_commands); entry.into_mut() } diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index b722dc44e00..2d1057792a6 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -76,7 +76,7 @@ pub struct Viewport { ids: ViewportIdPair, class: ViewportClass, builder: ViewportBuilder, - commands: Vec, + deferred_commands: Vec, info: ViewportInfo, screenshot_requested: bool, @@ -289,7 +289,7 @@ impl WgpuWinitApp { ids: ViewportIdPair::ROOT, class: ViewportClass::Root, builder, - commands: vec![], + deferred_commands: vec![], info, screenshot_requested: false, viewport_ui_cb: None, @@ -1083,17 +1083,16 @@ fn handle_viewport_output( let old_inner_size = window.inner_size(); let is_viewport_focused = focused_viewport == Some(viewport_id); - viewport.commands.append(&mut commands); + viewport.deferred_commands.append(&mut commands); egui_winit::process_viewport_commands( egui_ctx, &mut viewport.info, - viewport.commands.clone(), + std::mem::take(&mut viewport.deferred_commands), window, is_viewport_focused, &mut viewport.screenshot_requested, ); - viewport.commands.clear(); // For Wayland : https://github.com/emilk/egui/issues/4196 if cfg!(target_os = "linux") { @@ -1140,7 +1139,7 @@ fn initialize_or_update_viewport<'vp>( ids, class, builder, - commands: vec![], + deferred_commands: vec![], info: Default::default(), screenshot_requested: false, viewport_ui_cb, @@ -1169,7 +1168,7 @@ fn initialize_or_update_viewport<'vp>( viewport.egui_winit = None; } - viewport.commands.append(&mut delta_commands); + viewport.deferred_commands.append(&mut delta_commands); entry.into_mut() } From bf46a1d1df80d35f32cd4dd2199428e964cb0c49 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 Mar 2024 19:39:28 +0100 Subject: [PATCH 68/72] Initialize `minimized` and `maximized` correctly on Mac --- crates/eframe/src/native/glow_integration.rs | 8 ++++---- crates/eframe/src/native/wgpu_integration.rs | 8 ++++---- crates/egui-winit/src/lib.rs | 5 ++++- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index e999aaa734f..e5b67ffb005 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -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; @@ -1001,7 +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()); - egui_winit::update_viewport_info(&mut info, egui_ctx, window); + egui_winit::update_viewport_info(&mut info, egui_ctx, window, true); } let mut viewports = ViewportIdMap::default(); @@ -1094,7 +1094,7 @@ impl GlutinWindowContext { &viewport.builder, ); - egui_winit::update_viewport_info(&mut viewport.info, &self.egui_ctx, &window); + egui_winit::update_viewport_info(&mut viewport.info, &self.egui_ctx, &window, true); viewport.window.insert(Arc::new(window)) }; @@ -1405,7 +1405,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 diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 731bf532f63..71090b9b3ba 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -280,7 +280,7 @@ impl WgpuWinitApp { viewport_from_window.insert(window.id(), ViewportId::ROOT); let mut info = ViewportInfo::default(); - egui_winit::update_viewport_info(&mut info, &egui_ctx, &window); + egui_winit::update_viewport_info(&mut info, &egui_ctx, &window, true); let mut viewports = Viewports::default(); viewports.insert( @@ -604,7 +604,7 @@ impl WgpuWinitRunning { let Some(window) = window else { return EventResult::Wait; }; - egui_winit::update_viewport_info(info, &integration.egui_ctx, window); + egui_winit::update_viewport_info(info, &integration.egui_ctx, window, false); { crate::profile_scope!("set_window"); @@ -881,7 +881,7 @@ impl Viewport { painter.max_texture_side(), )); - egui_winit::update_viewport_info(&mut self.info, egui_ctx, &window); + egui_winit::update_viewport_info(&mut self.info, egui_ctx, &window, true); self.window = Some(window); } Err(err) => { @@ -952,7 +952,7 @@ fn render_immediate_viewport( let (Some(window), Some(egui_winit)) = (&viewport.window, &mut viewport.egui_winit) 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 input = egui_winit.take_egui_input(window); input.viewports = viewports diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 34d7ff42d54..c66d861aa38 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -903,10 +903,13 @@ pub fn outer_rect_in_points(window: &Window, pixels_per_point: f32) -> Option Date: Sat, 30 Mar 2024 19:41:31 +0100 Subject: [PATCH 69/72] Remove unused parameters --- crates/eframe/src/native/glow_integration.rs | 12 ++------ crates/eframe/src/native/wgpu_integration.rs | 30 +++++--------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/crates/eframe/src/native/glow_integration.rs b/crates/eframe/src/native/glow_integration.rs index e5b67ffb005..823e0b0201a 100644 --- a/crates/eframe/src/native/glow_integration.rs +++ b/crates/eframe/src/native/glow_integration.rs @@ -1251,13 +1251,11 @@ impl GlutinWindowContext { 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 { @@ -1292,15 +1290,13 @@ impl GlutinWindowContext { } } -fn initialize_or_update_viewport<'vp>( - _egu_ctx: &egui::Context, - viewports: &'vp mut ViewportIdMap, +fn initialize_or_update_viewport( + viewports: &mut ViewportIdMap, ids: ViewportIdPair, class: ViewportClass, mut builder: ViewportBuilder, viewport_ui_cb: Option>, - _focused_viewport: Option, -) -> &'vp mut Viewport { +) -> &mut Viewport { crate::profile_function!(); if builder.icon.is_none() { @@ -1379,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) { diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index 71090b9b3ba..e98a8743772 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -936,15 +936,8 @@ fn render_immediate_viewport( .. } = &mut *shared.borrow_mut(); - let viewport = initialize_or_update_viewport( - egui_ctx, - viewports, - ids, - ViewportClass::Immediate, - builder, - None, - None, - ); + let viewport = + initialize_or_update_viewport(viewports, ids, ViewportClass::Immediate, builder, None); if viewport.window.is_none() { viewport.initialize_window(event_loop, egui_ctx, viewport_from_window, painter); } @@ -1067,15 +1060,8 @@ fn handle_viewport_output( { let ids = ViewportIdPair::from_self_and_parent(viewport_id, parent); - let viewport = initialize_or_update_viewport( - egui_ctx, - viewports, - ids, - class, - builder, - viewport_ui_cb, - focused_viewport, - ); + let viewport = + initialize_or_update_viewport(viewports, ids, class, builder, viewport_ui_cb); if let Some(window) = viewport.window.as_ref() { let old_inner_size = window.inner_size(); @@ -1110,15 +1096,13 @@ fn handle_viewport_output( remove_viewports_not_in(viewports, painter, viewport_from_window, viewport_output); } -fn initialize_or_update_viewport<'vp>( - _egui_ctx: &egui::Context, - viewports: &'vp mut Viewports, +fn initialize_or_update_viewport( + viewports: &mut Viewports, ids: ViewportIdPair, class: ViewportClass, mut builder: ViewportBuilder, viewport_ui_cb: Option>, - _focused_viewport: Option, -) -> &'vp mut Viewport { +) -> &mut Viewport { crate::profile_function!(); if builder.icon.is_none() { From 4beea7bef84c68236db52b4cf404315dd8a28812 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 Mar 2024 19:47:16 +0100 Subject: [PATCH 70/72] Clean up inner_rect_in_points and outer_rect_in_points --- crates/egui-winit/src/lib.rs | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index c66d861aa38..74abafc2280 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -875,26 +875,24 @@ impl State { } pub fn inner_rect_in_points(window: &Window, pixels_per_point: f32) -> Option { - let pos = window.inner_position().ok()?; - let inner_pos_px = egui::emath::Pos2::new(pos.x as f32, pos.y as f32); + let inner_pos_px = window.inner_position().ok()?; + let inner_pos_px = egui::pos2(inner_pos_px.x as f32, inner_pos_px.y as f32); + + let inner_size_px = window.inner_size(); + let inner_size_px = egui::vec2(inner_size_px.width as f32, inner_size_px.height as f32); - let inner_size_px = { - let size = window.inner_size(); - egui::Vec2::new(size.width as f32, size.height as f32) - }; let inner_rect_px = egui::Rect::from_min_size(inner_pos_px, inner_size_px); Some(inner_rect_px / pixels_per_point) } pub fn outer_rect_in_points(window: &Window, pixels_per_point: f32) -> Option { - let pos = window.outer_position().ok()?; - let outer_pos_px = egui::emath::Pos2::new(pos.x as f32, pos.y as f32); + let outer_pos_px = window.outer_position().ok()?; + let outer_pos_px = egui::pos2(outer_pos_px.x as f32, outer_pos_px.y as f32); + + let outer_size_px = window.outer_size(); + let outer_size_px = egui::vec2(outer_size_px.width as f32, outer_size_px.height as f32); - let outer_size_px = { - let size = window.outer_size(); - egui::Vec2::new(size.width as f32, size.height as f32) - }; let outer_rect_px = egui::Rect::from_min_size(outer_pos_px, outer_size_px); Some(outer_rect_px / pixels_per_point) @@ -950,7 +948,7 @@ pub fn update_viewport_info( viewport_info.outer_rect = outer_rect; if is_init || !cfg!(target_os = "macos") { - // It's tempting to do this, but it leads to a deadlock on Mac when running + // Asking for minimized/maximized state at runtime leads to a deadlock on Mac when running // `cargo run -p custom_window_frame`. // See https://github.com/emilk/egui/issues/3494 viewport_info.maximized = Some(window.is_maximized()); From 882ce4a01ccd6c68234991b173398153f2040fcf Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 Mar 2024 19:56:48 +0100 Subject: [PATCH 71/72] Improve comments --- crates/egui-winit/src/lib.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/crates/egui-winit/src/lib.rs b/crates/egui-winit/src/lib.rs index 74abafc2280..5abfa0f6898 100644 --- a/crates/egui-winit/src/lib.rs +++ b/crates/egui-winit/src/lib.rs @@ -1313,16 +1313,27 @@ fn process_viewport_command( ViewportCommand::InnerSize(size) => { let width_px = pixels_per_point * size.x.max(1.0); let height_px = pixels_per_point * size.y.max(1.0); - if let Some(_inner_size) = - window.request_inner_size(PhysicalSize::new(width_px, height_px)) - { - // ViewportCommand::InnerSize, not will be delivered later with the [WindowEvent::Resized] - // ex) linux + let requested_size = PhysicalSize::new(width_px, height_px); + if let Some(_returned_inner_size) = window.request_inner_size(requested_size) { + // On platforms where the size is entirely controlled by the user the + // applied size will be returned immediately, resize event in such case + // may not be generated. + // e.g. Linux + + // On platforms where resizing is disallowed by the windowing system, the current + // inner size is returned immediately, and the user one is ignored. + // e.g. Android, iOS, … + + // However, comparing the results is prone to numerical errors + // because the linux backend converts physical to logical and back again. + // So let's just assume it worked: + info.inner_rect = inner_rect_in_points(window, pixels_per_point); info.outer_rect = outer_rect_in_points(window, pixels_per_point); } else { - // ViewportCommand::InnerSize, will be delivered later with the [WindowEvent::Resized] - // ex) Windows, MacOS + // e.g. macOS, Windows + // The request went to the display system, + // and the actual size will be delivered later with the [`WindowEvent::Resized`]. } } ViewportCommand::BeginResize(direction) => { From 3c9c23a7275c87e942767c0826fbe7cf3715a260 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 30 Mar 2024 20:02:09 +0100 Subject: [PATCH 72/72] Fix Android build --- crates/eframe/src/native/wgpu_integration.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/eframe/src/native/wgpu_integration.rs b/crates/eframe/src/native/wgpu_integration.rs index e98a8743772..9e0022489e7 100644 --- a/crates/eframe/src/native/wgpu_integration.rs +++ b/crates/eframe/src/native/wgpu_integration.rs @@ -155,13 +155,11 @@ impl WgpuWinitApp { } = &mut *running.shared.borrow_mut(); initialize_or_update_viewport( - egui_ctx, viewports, ViewportIdPair::ROOT, ViewportClass::Root, self.native_options.viewport.clone(), None, - None, ) .initialize_window(event_loop, egui_ctx, viewport_from_window, painter); }