Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos: modified key issues #625

Closed
sodiumjoe opened this issue Aug 11, 2018 · 10 comments · Fixed by #629
Closed

macos: modified key issues #625

sodiumjoe opened this issue Aug 11, 2018 · 10 comments · Fixed by #629

Comments

@sodiumjoe
Copy link
Contributor

Not totally sure these are all related, but:

alacritty/alacritty#1336
alacritty/alacritty#1358
alacritty/alacritty#1428
#623

I suspect these all started with #518

@francesca64 has given some direction here

@sodiumjoe
Copy link
Contributor Author

just confirmed these all started with #518 by git bisecting.

@sodiumjoe
Copy link
Contributor Author

One interesting thing to note is for alacritty/alacritty#1336, this might be working as intended? When I run the multiwindow example, <CMD-`> correctly cycles me through the open windows. I say "correctly," because this is normal macos app behavior.

Apparently <CMD-.> is used for cancel (though I can't find official documentation for that anywhere), and <C-TAB> is Move to the next control when a text field is selected .

Since <C-TAB> and <CMD-.> is sort of application dependent behavior, I guess winit should just pass these key events through to the consuming application.

But for <CMD-`>, I'm not sure, since this is standard app/window behavior. Should winit just handle this? Should it be default behavior with an option to opt out from an application?

@francesca64
Copy link
Member

I'm generally in favor of winit conforming to the conventions of the platform, which would entail letting the OS handle <CMD-`>. The only reason winit could previously override it was because our keyboard handling was overtly non-standard.

@sodiumjoe
Copy link
Contributor Author

@francesca64 So would you consider alacritty/alacritty#1336 a wontfix then? (I think that's a reasonable position.)

@francesca64
Copy link
Member

Yes. Even if I weren't against it conceptually, the potential fix is unreasonably convoluted.

@sodiumjoe
Copy link
Contributor Author

So I found this, which in my testing appears to fix the <C-Tab> issue:

before:

WindowEvent { window_id: WindowId(Id(140332214940576)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 59, state: Pressed, virtual_keycode: Some(LControl), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
WindowEvent { window_id: WindowId(Id(140332214940576)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 48, state: Released, virtual_keycode: Some(Tab), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
WindowEvent { window_id: WindowId(Id(140332214940576)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 59, state: Released, virtual_keycode: Some(LControl), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } } }

after:

WindowEvent { window_id: WindowId(Id(140623425336880)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 59, state: Pressed, virtual_keycode: Some(LControl), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
WindowEvent { window_id: WindowId(Id(140623425336880)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 48, state: Pressed, virtual_keycode: Some(Tab), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
WindowEvent { window_id: WindowId(Id(140623425336880)), event: ReceivedCharacter('\t') }
WindowEvent { window_id: WindowId(Id(140623425336880)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 48, state: Released, virtual_keycode: Some(Tab), modifiers: ModifiersState { shift: false, ctrl: true, alt: false, logo: false } } } }
WindowEvent { window_id: WindowId(Id(140623425336880)), event: KeyboardInput { device_id: DeviceId(DeviceId), input: KeyboardInput { scancode: 59, state: Released, virtual_keycode: Some(LControl), modifiers: ModifiersState { shift: false, ctrl: false, alt: false, logo: false } } } }

But it doesn't fix the <Cmd-.> issue. But I did find this, which appears to be addressing the same issue. I haven't quite figured out how to port this over yet, but I'm working on it.

@sodiumjoe
Copy link
Contributor Author

#629

@sodiumjoe
Copy link
Contributor Author

that branch fixes <C-Tab> and <Cmd-{key}> release, but not <Cmd-.>.

@sodiumjoe
Copy link
Contributor Author

Interestingly, with <Cmd-.>, it's the keydown that's suppressed and the keyup that fires. Unfortunately, the same trick doesn't seem to work:

                if let Some(key_window) = maybe_key_window() {
                    if event_mods(ns_event).logo && ns_event.keyCode() == 47 {
                        println!("keycode: {}", ns_event.keyCode());
                        msg_send![*key_window.window, sendEvent:ns_event];
                    }
                }

the println fires, but the key event does not.

@sodiumjoe
Copy link
Contributor Author

Ok, added special handling for <Cmd-.> that appears to work.

@sodiumjoe sodiumjoe mentioned this issue Aug 15, 2018
4 tasks
raphamorim added a commit to raphamorim/rio that referenced this issue May 19, 2023
Sets whether the window should get IME events. When IME is not allowed, the window won’t receive Ime events, and will receive KeyboardInput events for every keypress instead. Without allowing IME, the window will also get ReceivedCharacter events for certain keyboard input. Not allowing IME is useful for games for example.

https://docs.rs/winit/latest/winit/window/struct.Window.html#method.set_ime_purpose

rust-windowing/winit#518
rust-windowing/winit#625
alacritty/alacritty#2017
servo/servo#20770
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

2 participants