From d56013b137109c3d4ff802926261b6bec40e702c Mon Sep 17 00:00:00 2001 From: Aritro Date: Wed, 17 Jun 2026 14:22:12 -0400 Subject: [PATCH 1/9] ch --- crates/processing_glfw/src/lib.rs | 13 +++++++ crates/processing_pyo3/src/lib.rs | 16 +++++---- crates/processing_render/src/graphics.rs | 2 ++ crates/processing_render/src/lib.rs | 18 ++++++++++ crates/processing_render/src/surface.rs | 45 ++++++++++++++++++++++-- 5 files changed, 85 insertions(+), 9 deletions(-) diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index 6b63c6b4..737ae8b8 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -300,6 +300,19 @@ impl GlfwContext { WindowEvent::Focus(focused) => { input_set_focus(surface, focused).unwrap(); } + WindowEvent::Size(width, height) => { + let scale = self.content_scale(); + let logical_w = ((width as f32) / scale).max(1.0) as i32; + let logical_h = ((height as f32) / scale).max(1.0) as i32; + if logical_w != width || logical_h != height { + // processing_render::surface_resize( + // surface, + // logical_w as u32, + // logical_h as u32, + // ) + // .unwrap(); + } + } _ => {} } } diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index 59024d4f..6aa3274a 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -34,6 +34,7 @@ use graphics::{ }; use material::Material; +use processing_render::surface_logical_width; use pyo3::{ BoundObject, exceptions::PyRuntimeError, @@ -120,13 +121,14 @@ pub(crate) fn reset_tracked_globals() { fn sync_globals(module: &Bound<'_, PyModule>, globals: &Bound<'_, PyAny>) -> PyResult<()> { let graphics = get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?; - input::sync_globals( - globals, - graphics.surface.entity, - graphics.width, - graphics.height, - )?; - surface::sync_globals(globals, &graphics.surface, graphics.width, graphics.height)?; + // let width = ::processing::prelude::surface_logical_width(graphics.surface.entity) + // .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; + // let height = ::processing::prelude::surface_logical_height(graphics.surface.entity) + // .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; + let width = graphics.width; + let height = graphics.height; + input::sync_globals(globals, graphics.surface.entity, width, height)?; + surface::sync_globals(globals, &graphics.surface, width, height)?; time::sync_globals(globals)?; Ok(()) } diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index 001f9f5d..5f385ffc 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -118,6 +118,8 @@ impl CameraProjection for ProcessingProjection { // this gets called with the render target's physical dimensions (i.e. accounting for // scale factor), but our projection is in logical pixel units // TODO: handle resizes? + // self.width = _width; + // self.height = _height; } fn far(&self) -> f32 { diff --git a/crates/processing_render/src/lib.rs b/crates/processing_render/src/lib.rs index f68f5d93..e01e9cc6 100644 --- a/crates/processing_render/src/lib.rs +++ b/crates/processing_render/src/lib.rs @@ -1702,6 +1702,24 @@ pub fn surface_physical_height(entity: Entity) -> error::Result { }) } +pub fn surface_logical_width(entity: Entity) -> error::Result { + app_mut(|app| { + Ok(app + .world_mut() + .run_system_cached_with(surface::logical_width, entity) + .unwrap()) + }) +} + +pub fn surface_logical_height(entity: Entity) -> error::Result { + app_mut(|app| { + Ok(app + .world_mut() + .run_system_cached_with(surface::logical_height, entity) + .unwrap()) + }) +} + pub fn monitor_list() -> error::Result> { app_mut(|app| Ok(app.world_mut().run_system_cached(monitor::list).unwrap())) } diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index 248ac1ee..eaf1e543 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -21,13 +21,14 @@ use bevy::{ app::{App, Plugin}, asset::Assets, + camera::{CameraProjection, Projection, RenderTarget}, ecs::query::QueryEntityError, math::{IRect, IVec2}, prelude::{Commands, Component, Entity, In, Query, ResMut, Window, With, default}, render::render_resource::{Extent3d, TextureFormat}, window::{ CompositeAlphaMode, Monitor, RawHandleWrapper, WindowLevel, WindowMode, WindowPosition, - WindowResolution, WindowWrapper, + WindowRef, WindowResolution, WindowWrapper, }, }; use raw_window_handle::{ @@ -39,7 +40,10 @@ use processing_core::error::{self, ProcessingError, Result}; #[cfg(not(target_os = "windows"))] use std::ptr::NonNull; -use crate::image::Image; +use crate::{ + graphics::{ProcessingProjection, SurfaceSize}, + image::Image, +}; #[derive(Component, Debug, Clone)] pub struct Surface; @@ -394,7 +398,19 @@ pub fn destroy( pub fn resize( In((window_entity, width, height)): In<(Entity, u32, u32)>, mut windows: Query<&mut Window>, + mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize, &mut Projection)>, ) -> Result<()> { + let width = width.max(1); + let height = height.max(1); + + // let Ok(window) = windows.get_mut(window_entity) else { + // return Ok(()); + // }; + // + // if window.mode != WindowMode::Windowed { + // return Ok(()); + // } + if let Ok(mut window) = windows.get_mut(window_entity) { let scale = window.resolution.scale_factor(); let physical_w = (width as f32 * scale) as u32; @@ -403,6 +419,17 @@ pub fn resize( .resolution .set_physical_resolution(physical_w, physical_h); } + + // for (target, mut surface_size, mut projection) in graphics_query.iter_mut() { + // if let RenderTarget::Window(WindowRef::Entity(surface)) = *target { + // if surface == window_entity { + // *surface_size = SurfaceSize(width, height); + // if let Projection::Custom(ref mut custom) = *projection { + // custom.update(width as f32, height as f32); + // } + // } + // } + // } Ok(()) } @@ -448,6 +475,20 @@ pub fn physical_height(In(entity): In, query: Query<&Window>) -> u32 { .unwrap_or(0) } +pub fn logical_width(In(entity): In, query: Query<&Window>) -> u32 { + query + .get(entity) + .map(|w| w.resolution.width() as u32) + .unwrap_or(0) +} + +pub fn logical_height(In(entity): In, query: Query<&Window>) -> u32 { + query + .get(entity) + .map(|w| w.resolution.height() as u32) + .unwrap_or(0) +} + pub fn set_title( In((entity, title)): In<(Entity, String)>, mut windows: Query<&mut Window>, From a02f34f4a158f01d54dc78707ad8099dc1aadb3b Mon Sep 17 00:00:00 2001 From: Aritro Date: Wed, 24 Jun 2026 00:42:01 -0400 Subject: [PATCH 2/9] working v1 --- crates/processing_glfw/src/lib.rs | 13 +++++------ crates/processing_pyo3/src/lib.rs | 10 ++++----- crates/processing_render/src/graphics.rs | 4 ++-- crates/processing_render/src/surface.rs | 28 +++++++++--------------- 4 files changed, 21 insertions(+), 34 deletions(-) diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index 737ae8b8..eed82cf5 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -304,14 +304,11 @@ impl GlfwContext { let scale = self.content_scale(); let logical_w = ((width as f32) / scale).max(1.0) as i32; let logical_h = ((height as f32) / scale).max(1.0) as i32; - if logical_w != width || logical_h != height { - // processing_render::surface_resize( - // surface, - // logical_w as u32, - // logical_h as u32, - // ) - // .unwrap(); - } + processing_render::surface_resize( + surface, + logical_w as u32, + logical_h as u32, + ).unwrap(); } _ => {} } diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index 6aa3274a..cf90d043 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -121,12 +121,10 @@ pub(crate) fn reset_tracked_globals() { fn sync_globals(module: &Bound<'_, PyModule>, globals: &Bound<'_, PyAny>) -> PyResult<()> { let graphics = get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?; - // let width = ::processing::prelude::surface_logical_width(graphics.surface.entity) - // .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; - // let height = ::processing::prelude::surface_logical_height(graphics.surface.entity) - // .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; - let width = graphics.width; - let height = graphics.height; + let width = ::processing::prelude::surface_logical_width(graphics.surface.entity) + .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; + let height = ::processing::prelude::surface_logical_height(graphics.surface.entity) + .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; input::sync_globals(globals, graphics.surface.entity, width, height)?; surface::sync_globals(globals, &graphics.surface, width, height)?; time::sync_globals(globals)?; diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index 5f385ffc..dffcabe1 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -118,8 +118,8 @@ impl CameraProjection for ProcessingProjection { // this gets called with the render target's physical dimensions (i.e. accounting for // scale factor), but our projection is in logical pixel units // TODO: handle resizes? - // self.width = _width; - // self.height = _height; + self.width = _width; + self.height = _height; } fn far(&self) -> f32 { diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index eaf1e543..d0b1949f 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -403,14 +403,6 @@ pub fn resize( let width = width.max(1); let height = height.max(1); - // let Ok(window) = windows.get_mut(window_entity) else { - // return Ok(()); - // }; - // - // if window.mode != WindowMode::Windowed { - // return Ok(()); - // } - if let Ok(mut window) = windows.get_mut(window_entity) { let scale = window.resolution.scale_factor(); let physical_w = (width as f32 * scale) as u32; @@ -420,16 +412,16 @@ pub fn resize( .set_physical_resolution(physical_w, physical_h); } - // for (target, mut surface_size, mut projection) in graphics_query.iter_mut() { - // if let RenderTarget::Window(WindowRef::Entity(surface)) = *target { - // if surface == window_entity { - // *surface_size = SurfaceSize(width, height); - // if let Projection::Custom(ref mut custom) = *projection { - // custom.update(width as f32, height as f32); - // } - // } - // } - // } + for (target, mut surface_size, mut projection) in graphics_query.iter_mut() { + if let RenderTarget::Window(WindowRef::Entity(surface)) = *target { + if surface == window_entity { + *surface_size = SurfaceSize(width, height); + if let Projection::Custom(ref mut custom) = *projection { + custom.update(width as f32, height as f32); + } + } + } + } Ok(()) } From 9edce91e3370a256fcc04db90ae4100184922954 Mon Sep 17 00:00:00 2001 From: Aritro Date: Wed, 24 Jun 2026 01:15:11 -0400 Subject: [PATCH 3/9] working v2 --- crates/processing_glfw/src/lib.rs | 14 ++++---------- crates/processing_render/src/surface.rs | 7 ++----- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index eed82cf5..f0060d87 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -301,14 +301,8 @@ impl GlfwContext { input_set_focus(surface, focused).unwrap(); } WindowEvent::Size(width, height) => { - let scale = self.content_scale(); - let logical_w = ((width as f32) / scale).max(1.0) as i32; - let logical_h = ((height as f32) / scale).max(1.0) as i32; - processing_render::surface_resize( - surface, - logical_w as u32, - logical_h as u32, - ).unwrap(); + processing_render::surface_resize(surface, width.max(1) as u32, height.max(1) as u32) + .unwrap(); } _ => {} } @@ -539,8 +533,8 @@ fn read_desired_window(surface: Entity) -> Option { _ => None, }, size: bevy::math::UVec2::new( - window.resolution.physical_width(), - window.resolution.physical_height(), + window.resolution.width() as u32, + window.resolution.height() as u32, ), visible: window.visible, resizable: window.resizable, diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index d0b1949f..3ca803f0 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -21,7 +21,7 @@ use bevy::{ app::{App, Plugin}, asset::Assets, - camera::{CameraProjection, Projection, RenderTarget}, + camera::{Projection, RenderTarget}, ecs::query::QueryEntityError, math::{IRect, IVec2}, prelude::{Commands, Component, Entity, In, Query, ResMut, Window, With, default}, @@ -41,7 +41,7 @@ use processing_core::error::{self, ProcessingError, Result}; use std::ptr::NonNull; use crate::{ - graphics::{ProcessingProjection, SurfaceSize}, + graphics::SurfaceSize, image::Image, }; @@ -400,9 +400,6 @@ pub fn resize( mut windows: Query<&mut Window>, mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize, &mut Projection)>, ) -> Result<()> { - let width = width.max(1); - let height = height.max(1); - if let Ok(mut window) = windows.get_mut(window_entity) { let scale = window.resolution.scale_factor(); let physical_w = (width as f32 * scale) as u32; From 5ea6f2a0e4d33ef5c4cdad575adf4169c6f2cb6f Mon Sep 17 00:00:00 2001 From: Aritro Date: Wed, 24 Jun 2026 01:20:35 -0400 Subject: [PATCH 4/9] working v3 --- crates/processing_glfw/src/lib.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index f0060d87..14980e05 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -359,6 +359,9 @@ impl GlfwContext { Ok(()) }); self.last_applied.position = frame_pos; + + let (w, h) = self.window.get_size(); + self.last_applied.size = bevy::math::UVec2::new(w.max(0) as u32, h.max(0) as u32); } #[cfg(not(feature = "wayland"))] From ac28b292c3a7810ba761cb54c15f7bd02b6de73b Mon Sep 17 00:00:00 2001 From: Aritro Date: Wed, 24 Jun 2026 01:42:48 -0400 Subject: [PATCH 5/9] working --- crates/processing_glfw/src/lib.rs | 8 ++++++-- crates/processing_pyo3/src/lib.rs | 5 ++--- crates/processing_render/src/lib.rs | 8 ++++---- crates/processing_render/src/surface.rs | 9 +++------ 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index 14980e05..1581fcbb 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -301,8 +301,12 @@ impl GlfwContext { input_set_focus(surface, focused).unwrap(); } WindowEvent::Size(width, height) => { - processing_render::surface_resize(surface, width.max(1) as u32, height.max(1) as u32) - .unwrap(); + processing_render::surface_resize( + surface, + width.max(1) as u32, + height.max(1) as u32, + ) + .unwrap(); } _ => {} } diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index cf90d043..7bd72157 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -34,7 +34,6 @@ use graphics::{ }; use material::Material; -use processing_render::surface_logical_width; use pyo3::{ BoundObject, exceptions::PyRuntimeError, @@ -121,9 +120,9 @@ pub(crate) fn reset_tracked_globals() { fn sync_globals(module: &Bound<'_, PyModule>, globals: &Bound<'_, PyAny>) -> PyResult<()> { let graphics = get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?; - let width = ::processing::prelude::surface_logical_width(graphics.surface.entity) + let width = ::processing::prelude::surface_width(graphics.surface.entity) .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; - let height = ::processing::prelude::surface_logical_height(graphics.surface.entity) + let height = ::processing::prelude::surface_height(graphics.surface.entity) .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; input::sync_globals(globals, graphics.surface.entity, width, height)?; surface::sync_globals(globals, &graphics.surface, width, height)?; diff --git a/crates/processing_render/src/lib.rs b/crates/processing_render/src/lib.rs index e01e9cc6..e6ac5d78 100644 --- a/crates/processing_render/src/lib.rs +++ b/crates/processing_render/src/lib.rs @@ -1702,20 +1702,20 @@ pub fn surface_physical_height(entity: Entity) -> error::Result { }) } -pub fn surface_logical_width(entity: Entity) -> error::Result { +pub fn surface_width(entity: Entity) -> error::Result { app_mut(|app| { Ok(app .world_mut() - .run_system_cached_with(surface::logical_width, entity) + .run_system_cached_with(surface::width, entity) .unwrap()) }) } -pub fn surface_logical_height(entity: Entity) -> error::Result { +pub fn surface_height(entity: Entity) -> error::Result { app_mut(|app| { Ok(app .world_mut() - .run_system_cached_with(surface::logical_height, entity) + .run_system_cached_with(surface::height, entity) .unwrap()) }) } diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index 3ca803f0..efcaace8 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -40,10 +40,7 @@ use processing_core::error::{self, ProcessingError, Result}; #[cfg(not(target_os = "windows"))] use std::ptr::NonNull; -use crate::{ - graphics::SurfaceSize, - image::Image, -}; +use crate::{graphics::SurfaceSize, image::Image}; #[derive(Component, Debug, Clone)] pub struct Surface; @@ -464,14 +461,14 @@ pub fn physical_height(In(entity): In, query: Query<&Window>) -> u32 { .unwrap_or(0) } -pub fn logical_width(In(entity): In, query: Query<&Window>) -> u32 { +pub fn width(In(entity): In, query: Query<&Window>) -> u32 { query .get(entity) .map(|w| w.resolution.width() as u32) .unwrap_or(0) } -pub fn logical_height(In(entity): In, query: Query<&Window>) -> u32 { +pub fn height(In(entity): In, query: Query<&Window>) -> u32 { query .get(entity) .map(|w| w.resolution.height() as u32) From 02d60e7635c4fc62caa441c0f9b02d4d24a21bd9 Mon Sep 17 00:00:00 2001 From: Aritro Date: Wed, 24 Jun 2026 02:23:10 -0400 Subject: [PATCH 6/9] libprocessing/issues/127 --- crates/processing_glfw/src/lib.rs | 15 ++++++++++-- crates/processing_pyo3/src/lib.rs | 13 +++++----- crates/processing_render/src/graphics.rs | 2 ++ crates/processing_render/src/lib.rs | 18 ++++++++++++++ crates/processing_render/src/surface.rs | 31 ++++++++++++++++++++++-- 5 files changed, 68 insertions(+), 11 deletions(-) diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index 6b63c6b4..1581fcbb 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -300,6 +300,14 @@ impl GlfwContext { WindowEvent::Focus(focused) => { input_set_focus(surface, focused).unwrap(); } + WindowEvent::Size(width, height) => { + processing_render::surface_resize( + surface, + width.max(1) as u32, + height.max(1) as u32, + ) + .unwrap(); + } _ => {} } } @@ -355,6 +363,9 @@ impl GlfwContext { Ok(()) }); self.last_applied.position = frame_pos; + + let (w, h) = self.window.get_size(); + self.last_applied.size = bevy::math::UVec2::new(w.max(0) as u32, h.max(0) as u32); } #[cfg(not(feature = "wayland"))] @@ -529,8 +540,8 @@ fn read_desired_window(surface: Entity) -> Option { _ => None, }, size: bevy::math::UVec2::new( - window.resolution.physical_width(), - window.resolution.physical_height(), + window.resolution.width() as u32, + window.resolution.height() as u32, ), visible: window.visible, resizable: window.resizable, diff --git a/crates/processing_pyo3/src/lib.rs b/crates/processing_pyo3/src/lib.rs index 59024d4f..7bd72157 100644 --- a/crates/processing_pyo3/src/lib.rs +++ b/crates/processing_pyo3/src/lib.rs @@ -120,13 +120,12 @@ pub(crate) fn reset_tracked_globals() { fn sync_globals(module: &Bound<'_, PyModule>, globals: &Bound<'_, PyAny>) -> PyResult<()> { let graphics = get_graphics(module)?.ok_or_else(|| PyRuntimeError::new_err("call size() first"))?; - input::sync_globals( - globals, - graphics.surface.entity, - graphics.width, - graphics.height, - )?; - surface::sync_globals(globals, &graphics.surface, graphics.width, graphics.height)?; + let width = ::processing::prelude::surface_width(graphics.surface.entity) + .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; + let height = ::processing::prelude::surface_height(graphics.surface.entity) + .map_err(|e| PyRuntimeError::new_err(format!("{e}")))?; + input::sync_globals(globals, graphics.surface.entity, width, height)?; + surface::sync_globals(globals, &graphics.surface, width, height)?; time::sync_globals(globals)?; Ok(()) } diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index 001f9f5d..dffcabe1 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -118,6 +118,8 @@ impl CameraProjection for ProcessingProjection { // this gets called with the render target's physical dimensions (i.e. accounting for // scale factor), but our projection is in logical pixel units // TODO: handle resizes? + self.width = _width; + self.height = _height; } fn far(&self) -> f32 { diff --git a/crates/processing_render/src/lib.rs b/crates/processing_render/src/lib.rs index f68f5d93..e6ac5d78 100644 --- a/crates/processing_render/src/lib.rs +++ b/crates/processing_render/src/lib.rs @@ -1702,6 +1702,24 @@ pub fn surface_physical_height(entity: Entity) -> error::Result { }) } +pub fn surface_width(entity: Entity) -> error::Result { + app_mut(|app| { + Ok(app + .world_mut() + .run_system_cached_with(surface::width, entity) + .unwrap()) + }) +} + +pub fn surface_height(entity: Entity) -> error::Result { + app_mut(|app| { + Ok(app + .world_mut() + .run_system_cached_with(surface::height, entity) + .unwrap()) + }) +} + pub fn monitor_list() -> error::Result> { app_mut(|app| Ok(app.world_mut().run_system_cached(monitor::list).unwrap())) } diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index 248ac1ee..efcaace8 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -21,13 +21,14 @@ use bevy::{ app::{App, Plugin}, asset::Assets, + camera::{Projection, RenderTarget}, ecs::query::QueryEntityError, math::{IRect, IVec2}, prelude::{Commands, Component, Entity, In, Query, ResMut, Window, With, default}, render::render_resource::{Extent3d, TextureFormat}, window::{ CompositeAlphaMode, Monitor, RawHandleWrapper, WindowLevel, WindowMode, WindowPosition, - WindowResolution, WindowWrapper, + WindowRef, WindowResolution, WindowWrapper, }, }; use raw_window_handle::{ @@ -39,7 +40,7 @@ use processing_core::error::{self, ProcessingError, Result}; #[cfg(not(target_os = "windows"))] use std::ptr::NonNull; -use crate::image::Image; +use crate::{graphics::SurfaceSize, image::Image}; #[derive(Component, Debug, Clone)] pub struct Surface; @@ -394,6 +395,7 @@ pub fn destroy( pub fn resize( In((window_entity, width, height)): In<(Entity, u32, u32)>, mut windows: Query<&mut Window>, + mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize, &mut Projection)>, ) -> Result<()> { if let Ok(mut window) = windows.get_mut(window_entity) { let scale = window.resolution.scale_factor(); @@ -403,6 +405,17 @@ pub fn resize( .resolution .set_physical_resolution(physical_w, physical_h); } + + for (target, mut surface_size, mut projection) in graphics_query.iter_mut() { + if let RenderTarget::Window(WindowRef::Entity(surface)) = *target { + if surface == window_entity { + *surface_size = SurfaceSize(width, height); + if let Projection::Custom(ref mut custom) = *projection { + custom.update(width as f32, height as f32); + } + } + } + } Ok(()) } @@ -448,6 +461,20 @@ pub fn physical_height(In(entity): In, query: Query<&Window>) -> u32 { .unwrap_or(0) } +pub fn width(In(entity): In, query: Query<&Window>) -> u32 { + query + .get(entity) + .map(|w| w.resolution.width() as u32) + .unwrap_or(0) +} + +pub fn height(In(entity): In, query: Query<&Window>) -> u32 { + query + .get(entity) + .map(|w| w.resolution.height() as u32) + .unwrap_or(0) +} + pub fn set_title( In((entity, title)): In<(Entity, String)>, mut windows: Query<&mut Window>, From b2ad13089c88aca6a4e2539e50389b9e9d874192 Mon Sep 17 00:00:00 2001 From: Aritro Date: Thu, 25 Jun 2026 18:24:52 -0400 Subject: [PATCH 7/9] Handled resizing by emittig WindowResized --- crates/processing_glfw/src/lib.rs | 8 ++------ crates/processing_render/src/graphics.rs | 9 ++++++++- crates/processing_render/src/surface.rs | 15 ++++++++------- 3 files changed, 18 insertions(+), 14 deletions(-) diff --git a/crates/processing_glfw/src/lib.rs b/crates/processing_glfw/src/lib.rs index 1581fcbb..cbfe8db5 100644 --- a/crates/processing_glfw/src/lib.rs +++ b/crates/processing_glfw/src/lib.rs @@ -301,12 +301,8 @@ impl GlfwContext { input_set_focus(surface, focused).unwrap(); } WindowEvent::Size(width, height) => { - processing_render::surface_resize( - surface, - width.max(1) as u32, - height.max(1) as u32, - ) - .unwrap(); + processing_render::surface_resize(surface, width as u32, height as u32) + .unwrap(); } _ => {} } diff --git a/crates/processing_render/src/graphics.rs b/crates/processing_render/src/graphics.rs index dffcabe1..8adc5e18 100644 --- a/crates/processing_render/src/graphics.rs +++ b/crates/processing_render/src/graphics.rs @@ -22,7 +22,7 @@ use bevy::{ sync_world::MainEntity, view::ViewTarget, }, - window::WindowRef, + window::{WindowRef, WindowResized}, }; use crate::{ @@ -260,6 +260,7 @@ pub fn sync_to_surface( mut graphics_query: Query<(&mut Graphics, &RenderTarget)>, windows: Query<&Window, (With, Changed)>, render_device: Res, + mut resize_messages: MessageWriter, ) { for (mut graphics, target) in graphics_query.iter_mut() { let RenderTarget::Window(WindowRef::Entity(surface_entity)) = *target else { @@ -273,6 +274,12 @@ pub fn sync_to_surface( if graphics.size.width == physical_w && graphics.size.height == physical_h { continue; } + //winit plugin disabled, so WindowResized is never triggered automatically + resize_messages.write(WindowResized { + window: surface_entity, + width: window.width(), + height: window.height(), + }); graphics.size = Extent3d { width: physical_w, height: physical_h, diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index efcaace8..4ab9e679 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -21,7 +21,7 @@ use bevy::{ app::{App, Plugin}, asset::Assets, - camera::{Projection, RenderTarget}, + camera::RenderTarget, ecs::query::QueryEntityError, math::{IRect, IVec2}, prelude::{Commands, Component, Entity, In, Query, ResMut, Window, With, default}, @@ -395,8 +395,11 @@ pub fn destroy( pub fn resize( In((window_entity, width, height)): In<(Entity, u32, u32)>, mut windows: Query<&mut Window>, - mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize, &mut Projection)>, + mut graphics_query: Query<(&RenderTarget, &mut SurfaceSize)>, ) -> Result<()> { + let width = width.max(1); + let height = height.max(1); + if let Ok(mut window) = windows.get_mut(window_entity) { let scale = window.resolution.scale_factor(); let physical_w = (width as f32 * scale) as u32; @@ -405,14 +408,12 @@ pub fn resize( .resolution .set_physical_resolution(physical_w, physical_h); } - - for (target, mut surface_size, mut projection) in graphics_query.iter_mut() { + + // SurfaceSize changes on resize, if not handled will break APIs dependent on correct SurfaceSize + for (target, mut surface_size) in graphics_query.iter_mut() { if let RenderTarget::Window(WindowRef::Entity(surface)) = *target { if surface == window_entity { *surface_size = SurfaceSize(width, height); - if let Projection::Custom(ref mut custom) = *projection { - custom.update(width as f32, height as f32); - } } } } From b6893013a7d89336a970a3f4007bd5d1add3e69e Mon Sep 17 00:00:00 2001 From: Aritro Date: Thu, 25 Jun 2026 19:28:09 -0400 Subject: [PATCH 8/9] Clippy --- crates/processing_render/src/surface.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index c073b3db..593d63d8 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -411,10 +411,9 @@ pub fn resize( // SurfaceSize changes on resize, if not handled will break APIs dependent on correct SurfaceSize for (target, mut surface_size) in graphics_query.iter_mut() { - if let RenderTarget::Window(WindowRef::Entity(surface)) = *target { - if surface == window_entity { - *surface_size = SurfaceSize(width, height); - } + if let RenderTarget::Window(WindowRef::Entity(surface)) = *target + && surface == window_entity { + *surface_size = SurfaceSize(width, height); } } Ok(()) From e30801cadfac65cbad3064a2ed746982e3544879 Mon Sep 17 00:00:00 2001 From: Aritro Date: Thu, 25 Jun 2026 19:57:53 -0400 Subject: [PATCH 9/9] fmt --- crates/processing_render/src/surface.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/processing_render/src/surface.rs b/crates/processing_render/src/surface.rs index 593d63d8..144dfd79 100644 --- a/crates/processing_render/src/surface.rs +++ b/crates/processing_render/src/surface.rs @@ -412,7 +412,8 @@ pub fn resize( // SurfaceSize changes on resize, if not handled will break APIs dependent on correct SurfaceSize for (target, mut surface_size) in graphics_query.iter_mut() { if let RenderTarget::Window(WindowRef::Entity(surface)) = *target - && surface == window_entity { + && surface == window_entity + { *surface_size = SurfaceSize(width, height); } }