move keyboard input to WindowEvent to fix Wayland
This commit is contained in:
parent
af750151f7
commit
eaaa0b6a0b
24
src/main.rs
24
src/main.rs
@ -842,6 +842,7 @@ impl framework::Example for GraphicsData {
|
|||||||
|
|
||||||
#[allow(clippy::single_match)]
|
#[allow(clippy::single_match)]
|
||||||
fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
|
fn update(&mut self, window: &winit::window::Window, device: &wgpu::Device, queue: &wgpu::Queue, event: winit::event::WindowEvent) {
|
||||||
|
let time=self.start_time.elapsed().as_nanos() as i64;
|
||||||
match event {
|
match event {
|
||||||
winit::event::WindowEvent::DroppedFile(path) => self.load_file(path,device,queue),
|
winit::event::WindowEvent::DroppedFile(path) => self.load_file(path,device,queue),
|
||||||
winit::event::WindowEvent::KeyboardInput {
|
winit::event::WindowEvent::KeyboardInput {
|
||||||
@ -864,6 +865,27 @@ impl framework::Example for GraphicsData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
Some(keycode)=>{
|
||||||
|
if let Some(input_instruction)=match keycode {
|
||||||
|
winit::event::VirtualKeyCode::W => Some(InputInstruction::MoveForward(s)),
|
||||||
|
winit::event::VirtualKeyCode::A => Some(InputInstruction::MoveLeft(s)),
|
||||||
|
winit::event::VirtualKeyCode::S => Some(InputInstruction::MoveBack(s)),
|
||||||
|
winit::event::VirtualKeyCode::D => Some(InputInstruction::MoveRight(s)),
|
||||||
|
winit::event::VirtualKeyCode::E => Some(InputInstruction::MoveUp(s)),
|
||||||
|
winit::event::VirtualKeyCode::Q => Some(InputInstruction::MoveDown(s)),
|
||||||
|
winit::event::VirtualKeyCode::Space => Some(InputInstruction::Jump(s)),
|
||||||
|
winit::event::VirtualKeyCode::Z => Some(InputInstruction::Zoom(s)),
|
||||||
|
winit::event::VirtualKeyCode::R => if s{Some(InputInstruction::Reset)}else{None},
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
{
|
||||||
|
self.physics.run(time);
|
||||||
|
self.physics.process_instruction(TimedInstruction{
|
||||||
|
time,
|
||||||
|
instruction:PhysicsInstruction::Input(input_instruction),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
_=>(),
|
_=>(),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -875,6 +897,7 @@ impl framework::Example for GraphicsData {
|
|||||||
//there's no way this is the best way get a timestamp.
|
//there's no way this is the best way get a timestamp.
|
||||||
let time=self.start_time.elapsed().as_nanos() as i64;
|
let time=self.start_time.elapsed().as_nanos() as i64;
|
||||||
match event {
|
match event {
|
||||||
|
/* use WindowEvent for input for now because DeviceEvent doesn't work on wayland
|
||||||
winit::event::DeviceEvent::Key(winit::event::KeyboardInput {
|
winit::event::DeviceEvent::Key(winit::event::KeyboardInput {
|
||||||
state,
|
state,
|
||||||
scancode: keycode,
|
scancode: keycode,
|
||||||
@ -904,6 +927,7 @@ impl framework::Example for GraphicsData {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
*/
|
||||||
winit::event::DeviceEvent::MouseMotion {
|
winit::event::DeviceEvent::MouseMotion {
|
||||||
delta,//these (f64,f64) are integers on my machine
|
delta,//these (f64,f64) are integers on my machine
|
||||||
} => {
|
} => {
|
||||||
|
Loading…
Reference in New Issue
Block a user