summaryrefslogtreecommitdiff
path: root/engine/src/windowing.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-11-26 14:30:28 +0100
committerHampusM <hampus@hampusmat.com>2026-11-26 14:30:28 +0100
commita934a03738efd82a1fc1e28c6c01b414a0051f7e (patch)
treeb21670d1ecaf45d9e86d20290e30c69192c20e3c /engine/src/windowing.rs
parentaa6d314938e9a3e7898286663771ee014a6d523e (diff)
fix(engine): don't bombard windowing app msg queue when window is drag resized
Diffstat (limited to 'engine/src/windowing.rs')
-rw-r--r--engine/src/windowing.rs97
1 files changed, 68 insertions, 29 deletions
diff --git a/engine/src/windowing.rs b/engine/src/windowing.rs
index fee8755..8214515 100644
--- a/engine/src/windowing.rs
+++ b/engine/src/windowing.rs
@@ -195,17 +195,23 @@ fn handle_app_messages(context: &mut Context, actions: &mut Actions, world: &Wor
MessageFromApp::Window(WindowMessage::Created(
window_ent_id,
winit_window,
- window_creation_attrs,
+ window_settings,
)) => {
+ let window_id = WindowId::from_inner(winit_window.id());
+
+ tracing::info!(
+ window_id = ?window_id,
+ window_title = %window_settings.title,
+ "Window creation completed"
+ );
+
actions.add_components(
window_ent_id,
- (Window::new(&winit_window, &window_creation_attrs),),
+ (Window::new(&winit_window, &window_settings),),
);
actions.remove_comps::<(WindowCreationReady,)>(window_ent_id);
- let window_id = WindowId::from_inner(winit_window.id());
-
windows.insert(
window_id,
(
@@ -214,15 +220,10 @@ fn handle_app_messages(context: &mut Context, actions: &mut Actions, world: &Wor
pending_resize_req: None,
entity_id: window_ent_id,
flags: WindowFlags::empty(),
+ settings: window_settings,
},
),
);
-
- tracing::info!(
- window_id = ?window_id,
- window_title = %window_creation_attrs.title,
- "Window creation completed"
- );
}
MessageFromApp::Window(WindowMessage::Resized(window_id)) => {
let Some((_, window_metadata)) = windows.get_mut(window_id) else {
@@ -444,7 +445,8 @@ fn handle_window_changed(
continue;
};
- window.apply(winit_window);
+ let is_window_settings_changed =
+ window.apply_to_settings(&mut window_metadata.settings);
if window_metadata.pending_resize_req.is_none()
&& window.inner_size != window.real_inner_size
@@ -468,10 +470,14 @@ fn handle_window_changed(
}
}
- context.try_send_message_to_app(MessageToApp::SetWindowCursorGrabMode(
- window.wid(),
- window.cursor_grab_mode,
- ));
+ if is_window_settings_changed {
+ let new_window_settings = window_metadata.settings.clone();
+
+ context.try_send_message_to_app(MessageToApp::SetWindowSettings(
+ window.wid(),
+ new_window_settings,
+ ));
+ }
}
}
@@ -692,6 +698,7 @@ struct WindowMetadata
pending_resize_req: Option<PhysicalSize<u32>>,
entity_id: Uid,
flags: WindowFlags,
+ settings: WindowSettings,
}
bitflags! {
@@ -797,7 +804,7 @@ enum MessageFromApp
#[derive(Debug)]
enum WindowMessage
{
- Created(Uid, Arc<WinitWindow>, WindowCreationAttributes),
+ Created(Uid, Arc<WinitWindow>, WindowSettings),
Resized(WindowId),
CloseRequested(WindowId),
ScaleFactorChanged(WindowId, f64),
@@ -807,7 +814,7 @@ enum WindowMessage
enum MessageToApp
{
CreateWindow(Uid, WindowCreationAttributes),
- SetWindowCursorGrabMode(WindowId, CursorGrabMode),
+ SetWindowSettings(WindowId, WindowSettings),
}
#[derive(Debug)]
@@ -940,34 +947,40 @@ impl App
window_creation_attrs.apply_extra_attrs_to_window(&winit_window);
+ let window_settings =
+ WindowSettings::from_window_creation_attrs(window_creation_attrs);
+
self.windows.insert(
WindowId::from_inner(winit_window.id()),
- (
- Arc::downgrade(&winit_window),
- WindowSettings {
- cursor_grab_mode: window_creation_attrs.cursor_grab_mode,
- },
- ),
+ (Arc::downgrade(&winit_window), window_settings.clone()),
);
self.send_message(MessageFromApp::Window(WindowMessage::Created(
window_ent_id,
winit_window,
- window_creation_attrs,
+ window_settings,
)));
}
- MessageToApp::SetWindowCursorGrabMode(window_id, cursor_grab_mode) => {
- let Some((_, window_settings)) = self.windows.get_mut(window_id)
+ MessageToApp::SetWindowSettings(window_id, new_window_settings) => {
+ let Some((winit_window, window_settings)) =
+ self.windows.get_mut(window_id)
else {
tracing::warn!(
window_id=?window_id,
- "Cannot set window cursor grab mode. Window not found"
+ "Cannot set window settings. Window not found"
);
continue;
};
- window_settings.cursor_grab_mode = cursor_grab_mode;
+ let Some(winit_window) = winit_window.upgrade() else {
+ continue;
+ };
+
+ new_window_settings
+ .apply_to_winit_window(&winit_window, window_settings);
+
+ *window_settings = new_window_settings;
}
}
}
@@ -1259,12 +1272,38 @@ impl ApplicationHandler for App
}
}
-#[derive(Debug, Default)]
+#[derive(Debug, Default, Clone)]
struct WindowSettings
{
+ title: Box<str>,
+ cursor_visible: bool,
cursor_grab_mode: CursorGrabMode,
}
+impl WindowSettings
+{
+ fn from_window_creation_attrs(window_creation_attrs: WindowCreationAttributes)
+ -> Self
+ {
+ Self {
+ title: window_creation_attrs.title.into_owned().into_boxed_str(),
+ cursor_visible: window_creation_attrs.cursor_visible,
+ cursor_grab_mode: window_creation_attrs.cursor_grab_mode,
+ }
+ }
+
+ fn apply_to_winit_window(&self, winit_window: &WinitWindow, old_settings: &Self)
+ {
+ if self.title != old_settings.title {
+ winit_window.set_title(&self.title);
+ }
+
+ if self.cursor_visible != old_settings.cursor_visible {
+ winit_window.set_cursor_visible(self.cursor_visible);
+ }
+ }
+}
+
fn iter_array_queue<Item>(
queue: &ArrayQueue<Item>,
) -> impl Iterator<Item = Item> + use<'_, Item>