Skip to content

Commit

Permalink
Fix keyboard modifiers in Winit with the new ImGui version.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorc committed Jan 14, 2023
1 parent 23a07ab commit 2106e17
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
8 changes: 4 additions & 4 deletions imgui-sdl2-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ fn handle_key(io: &mut Io, key: &Scancode, pressed: bool) {

/// Handle changes in the key modifier states.
fn handle_key_modifier(io: &mut Io, keymod: &Mod) {
io.key_shift = keymod.intersects(Mod::LSHIFTMOD | Mod::RSHIFTMOD);
io.key_ctrl = keymod.intersects(Mod::LCTRLMOD | Mod::RCTRLMOD);
io.key_alt = keymod.intersects(Mod::LALTMOD | Mod::RALTMOD);
io.key_super = keymod.intersects(Mod::LGUIMOD | Mod::RGUIMOD);
io.add_key_event(Key::ModShift, keymod.intersects(Mod::LSHIFTMOD | Mod::RSHIFTMOD));
io.add_key_event(Key::ModCtrl, keymod.intersects(Mod::LCTRLMOD | Mod::RCTRLMOD));
io.add_key_event(Key::ModAlt, keymod.intersects(Mod::LALTMOD | Mod::RALTMOD));
io.add_key_event(Key::ModSuper, keymod.intersects(Mod::LGUIMOD | Mod::RGUIMOD));
}

/// Map an imgui::MouseCursor to an equivalent sdl2::mouse::SystemCursor.
Expand Down
8 changes: 4 additions & 4 deletions imgui-winit-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,10 @@ impl WinitPlatform {
// not reliably send modifier states during certain events like ScreenCapture.
// Gotta let the people show off their pretty imgui widgets!
if let WindowEvent::ModifiersChanged(modifiers) = event {
io.key_shift = modifiers.shift();
io.key_ctrl = modifiers.ctrl();
io.key_alt = modifiers.alt();
io.key_super = modifiers.logo();
io.add_key_event(Key::ModShift, modifiers.shift());
io.add_key_event(Key::ModCtrl, modifiers.ctrl());
io.add_key_event(Key::ModAlt, modifiers.alt());
io.add_key_event(Key::ModSuper, modifiers.logo());
}

self.handle_window_event(io, window, event);
Expand Down
5 changes: 5 additions & 0 deletions imgui/src/input/keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,11 @@ pub enum Key {
ReservedForModShift = sys::ImGuiKey_ReservedForModShift,
ReservedForModAlt = sys::ImGuiKey_ReservedForModAlt,
ReservedForModSuper = sys::ImGuiKey_ReservedForModSuper,
ModCtrl = sys::ImGuiMod_Ctrl,
ModShift = sys::ImGuiMod_Shift,
ModAlt = sys::ImGuiMod_Alt,
ModSuper = sys::ImGuiMod_Super,
ModShortcut = sys::ImGuiMod_Shortcut,
}

impl Key {
Expand Down

0 comments on commit 2106e17

Please sign in to comment.