Skip to content

Commit 031aaec

Browse files
committed
fixing modifier state
1 parent a358fa0 commit 031aaec

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ event_loop
8888

8989
Licensed under either of
9090

91-
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or https://www.apache.org/licenses/LICENSE-2.0)
92-
- MIT license ([LICENSE-MIT](LICENSE-MIT) or https://opensource.org/licenses/MIT)
91+
- Apache License, Version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or <https://www.apache.org/licenses/LICENSE-2.0>)
92+
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <https://opensource.org/licenses/MIT>)
9393

9494
at your option.

src/lib.rs

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub use winit;
1010
use winit::{
1111
dpi::{LogicalPosition, LogicalSize},
1212
keyboard::{Key as WinitKey, KeyLocation, NamedKey},
13-
platform::modifier_supplement::KeyEventExtModifierSupplement,
1413
};
1514

1615
use winit::{
@@ -191,15 +190,14 @@ impl WinitPlatform {
191190
// We need to track modifiers separately because some system like macOS, will
192191
// not reliably send modifier states during certain events like ScreenCapture.
193192
// Gotta let the people show off their pretty imgui widgets!
194-
io.add_key_event(Key::LeftShift, state.shift_key());
195-
io.add_key_event(Key::LeftCtrl, state.control_key());
196-
io.add_key_event(Key::LeftAlt, state.alt_key());
197-
io.add_key_event(Key::LeftSuper, state.super_key());
193+
io.add_key_event(Key::ModShift, state.shift_key());
194+
io.add_key_event(Key::ModCtrl, state.control_key());
195+
io.add_key_event(Key::ModAlt, state.alt_key());
196+
io.add_key_event(Key::ModSuper, state.super_key());
198197
}
199198
WindowEvent::KeyboardInput { ref event, .. } => {
200199
let is_pressed = event.state.is_pressed();
201200
if is_pressed {
202-
//println!("{:#?}", event);
203201
if let Some(txt) = &event.text {
204202
for ch in txt.chars() {
205203
if ch != '\u{7f}' {
@@ -209,14 +207,6 @@ impl WinitPlatform {
209207
}
210208
}
211209

212-
// We map both left and right ctrl to `ModCtrl`, etc.
213-
// imgui is told both "left control is pressed" and
214-
// "consider the control key is pressed". Allows
215-
// applications to use either general "ctrl" or a
216-
// specific key. Same applies to other modifiers.
217-
// https://github.com/ocornut/imgui/issues/5047
218-
handle_key_modifier(io, &event.key_without_modifiers(), is_pressed);
219-
220210
// Add main key event
221211
if let Some(key) = to_imgui_key(&event.logical_key, event.location) {
222212
io.add_key_event(key, is_pressed);
@@ -502,13 +492,3 @@ fn to_imgui_key(key: &winit::keyboard::Key, location: KeyLocation) -> Option<Key
502492
_ => None,
503493
}
504494
}
505-
506-
fn handle_key_modifier(io: &mut Io, key: &WinitKey, down: bool) {
507-
match key {
508-
WinitKey::Named(NamedKey::Shift) => io.add_key_event(imgui::Key::LeftShift, down),
509-
WinitKey::Named(NamedKey::Control) => io.add_key_event(imgui::Key::LeftCtrl, down),
510-
WinitKey::Named(NamedKey::Alt) => io.add_key_event(imgui::Key::LeftAlt, down),
511-
WinitKey::Named(NamedKey::Super) => io.add_key_event(imgui::Key::LeftSuper, down),
512-
_ => {}
513-
}
514-
}

0 commit comments

Comments
 (0)