fix selecting wrong window for key events
This commit is contained in:
parent
709247869d
commit
0333e1f676
5 changed files with 119 additions and 15 deletions
|
@ -31,7 +31,13 @@ impl ApplicationHandler for App<'_> {
|
|||
);
|
||||
let window_id = window.id();
|
||||
let wgpu_ctx = WgpuCtx::new_blocking(window.clone()).unwrap();
|
||||
self.windows.insert(window_id, WindowContext { window, ctx: wgpu_ctx });
|
||||
self.windows.insert(
|
||||
window_id,
|
||||
WindowContext {
|
||||
window,
|
||||
ctx: wgpu_ctx,
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +51,7 @@ impl ApplicationHandler for App<'_> {
|
|||
WindowEvent::CloseRequested => {
|
||||
if let Some(window_context) = self.windows.remove(&window_id) {
|
||||
drop(window_context);
|
||||
println!("Window: {:?} closed, exiting", window_id);
|
||||
debug!("Window: {:?} closed, exiting", window_id);
|
||||
}
|
||||
if self.windows.is_empty() {
|
||||
event_loop.exit();
|
||||
|
@ -63,10 +69,14 @@ impl ApplicationHandler for App<'_> {
|
|||
match code {
|
||||
winit::keyboard::KeyCode::Space => {
|
||||
debug!("Space key pressed");
|
||||
if let Some(window_context) = self.windows.values_mut().next() {
|
||||
if let Some(window_context) = self.windows.get_mut(&window_id){
|
||||
match window_context.ctx.bg_color() {
|
||||
wgpu::Color::WHITE => window_context.ctx.change_bg_color(wgpu::Color::BLACK),
|
||||
wgpu::Color::BLACK => window_context.ctx.change_bg_color(wgpu::Color::WHITE),
|
||||
wgpu::Color::WHITE => {
|
||||
window_context.ctx.change_bg_color(wgpu::Color::BLACK)
|
||||
}
|
||||
wgpu::Color::BLACK => {
|
||||
window_context.ctx.change_bg_color(wgpu::Color::WHITE)
|
||||
}
|
||||
_ => window_context.ctx.change_bg_color(wgpu::Color::WHITE),
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +92,13 @@ impl ApplicationHandler for App<'_> {
|
|||
);
|
||||
let window_id = new_window.id();
|
||||
let wgpu_ctx = WgpuCtx::new_blocking(new_window.clone()).unwrap();
|
||||
self.windows.insert(window_id, WindowContext { window: new_window, ctx: wgpu_ctx });
|
||||
self.windows.insert(
|
||||
window_id,
|
||||
WindowContext {
|
||||
window: new_window,
|
||||
ctx: wgpu_ctx,
|
||||
},
|
||||
);
|
||||
}
|
||||
_ => info!("Unimplemented keycode: {:?}", code),
|
||||
}
|
||||
|
@ -99,8 +115,7 @@ impl ApplicationHandler for App<'_> {
|
|||
if let Some(window_context) = self.windows.get_mut(&window_id) {
|
||||
window_context.ctx.resize(size.into());
|
||||
window_context.window.request_redraw();
|
||||
let size_str: String =
|
||||
size.height.to_string() + "x" + &size.width.to_string();
|
||||
let size_str: String = size.height.to_string() + "x" + &size.width.to_string();
|
||||
debug!("Window resized to {:?}", size_str);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue