Skip to content

Commit

Permalink
Fix incorrect keycodes when using a non-US keyboard layout. (rust-win…
Browse files Browse the repository at this point in the history
…dowing#755)

* Fix incorrect keycodes when using a non-US keyboard layout.

This commit fixes the issue described in rust-windowing#752, and uses the advised
method to fix it.

* Style fixes

Co-Authored-By: Toqozz <[email protected]>

* Refactoring of macOS `virtualkeycode` fix (rust-windowing#752)

* Applies requested changes as per pull request discussion (rust-windowing#755).
  • Loading branch information
Toqozz authored and kosyak committed Jul 10, 2019
1 parent 37328d1 commit 3e20c32
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
- `LoopDestroyed` is emitted when the `run` or `run_return` method is about to exit.
- Rename `MonitorId` to `MonitorHandle`.
- Removed `serde` implementations from `ControlFlow`.
- On macOS, fix keycodes being incorrect when using a non-US keyboard layout.
- On Wayland, fix `with_title()` not setting the windows title
- On Wayland, add `set_wayland_theme()` to control client decoration color theme
- Added serde serialization to `os::unix::XWindowType`.
Expand Down
7 changes: 4 additions & 3 deletions src/platform_impl/macos/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ use objc::declare::ClassDecl;
use objc::runtime::{Class, Object, Protocol, Sel, BOOL, YES};

use {ElementState, Event, KeyboardInput, MouseButton, WindowEvent, WindowId};
use platform_impl::platform::event_loop::{DEVICE_ID, event_mods, Shared, to_virtual_key_code, check_additional_virtual_key_codes};
use platform_impl::platform::event_loop::{DEVICE_ID, event_mods, Shared, to_virtual_key_code, check_additional_virtual_key_codes, get_scancode};
use platform_impl::platform::util;
use platform_impl::platform::ffi::*;
use platform_impl::platform::window::{get_window_id, IdRef};
use event;

struct ViewState {
window: id,
Expand Down Expand Up @@ -412,9 +413,9 @@ fn get_characters(event: id, ignore_modifiers: bool) -> String {
}

// Retrieves a layout-independent keycode given an event.
fn retrieve_keycode(event: id) -> Option<events::VirtualKeyCode> {
fn retrieve_keycode(event: id) -> Option<event::VirtualKeyCode> {
#[inline]
fn get_code(ev: id, raw: bool) -> Option<events::VirtualKeyCode> {
fn get_code(ev: id, raw: bool) -> Option<event::VirtualKeyCode> {
let characters = get_characters(ev, raw);
characters.chars().next().map_or(None, |c| char_to_keycode(c))
}
Expand Down

0 comments on commit 3e20c32

Please sign in to comment.