mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Add ModifiersChanged event for macOS (#1268)
* Add ModifiersChanged event for macOS This implements the macOS portion of #1124. * Fix ModifiersChanged event import * Fix event passing window instead of device id
This commit is contained in:
parent
1f81e5c872
commit
c1b93fc3d0
|
@ -18,8 +18,8 @@ use objc::{
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
event::{
|
event::{
|
||||||
DeviceEvent, ElementState, Event, KeyboardInput, MouseButton, MouseScrollDelta, TouchPhase,
|
DeviceEvent, ElementState, Event, KeyboardInput, ModifiersState, MouseButton,
|
||||||
VirtualKeyCode, WindowEvent,
|
MouseScrollDelta, TouchPhase, VirtualKeyCode, WindowEvent,
|
||||||
},
|
},
|
||||||
platform_impl::platform::{
|
platform_impl::platform::{
|
||||||
app_state::AppState,
|
app_state::AppState,
|
||||||
|
@ -35,21 +35,13 @@ use crate::{
|
||||||
window::WindowId,
|
window::WindowId,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct Modifiers {
|
|
||||||
shift_pressed: bool,
|
|
||||||
ctrl_pressed: bool,
|
|
||||||
win_pressed: bool,
|
|
||||||
alt_pressed: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ViewState {
|
struct ViewState {
|
||||||
ns_window: id,
|
ns_window: id,
|
||||||
pub cursor: Arc<Mutex<util::Cursor>>,
|
pub cursor: Arc<Mutex<util::Cursor>>,
|
||||||
ime_spot: Option<(f64, f64)>,
|
ime_spot: Option<(f64, f64)>,
|
||||||
raw_characters: Option<String>,
|
raw_characters: Option<String>,
|
||||||
is_key_down: bool,
|
is_key_down: bool,
|
||||||
modifiers: Modifiers,
|
modifiers: ModifiersState,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_view(ns_window: id) -> (IdRef, Weak<Mutex<util::Cursor>>) {
|
pub fn new_view(ns_window: id) -> (IdRef, Weak<Mutex<util::Cursor>>) {
|
||||||
|
@ -654,36 +646,36 @@ extern "C" fn flags_changed(this: &Object, _sel: Sel, event: id) {
|
||||||
if let Some(window_event) = modifier_event(
|
if let Some(window_event) = modifier_event(
|
||||||
event,
|
event,
|
||||||
NSEventModifierFlags::NSShiftKeyMask,
|
NSEventModifierFlags::NSShiftKeyMask,
|
||||||
state.modifiers.shift_pressed,
|
state.modifiers.shift,
|
||||||
) {
|
) {
|
||||||
state.modifiers.shift_pressed = !state.modifiers.shift_pressed;
|
state.modifiers.shift = !state.modifiers.shift;
|
||||||
events.push_back(window_event);
|
events.push_back(window_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(window_event) = modifier_event(
|
if let Some(window_event) = modifier_event(
|
||||||
event,
|
event,
|
||||||
NSEventModifierFlags::NSControlKeyMask,
|
NSEventModifierFlags::NSControlKeyMask,
|
||||||
state.modifiers.ctrl_pressed,
|
state.modifiers.ctrl,
|
||||||
) {
|
) {
|
||||||
state.modifiers.ctrl_pressed = !state.modifiers.ctrl_pressed;
|
state.modifiers.ctrl = !state.modifiers.ctrl;
|
||||||
events.push_back(window_event);
|
events.push_back(window_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(window_event) = modifier_event(
|
if let Some(window_event) = modifier_event(
|
||||||
event,
|
event,
|
||||||
NSEventModifierFlags::NSCommandKeyMask,
|
NSEventModifierFlags::NSCommandKeyMask,
|
||||||
state.modifiers.win_pressed,
|
state.modifiers.logo,
|
||||||
) {
|
) {
|
||||||
state.modifiers.win_pressed = !state.modifiers.win_pressed;
|
state.modifiers.logo = !state.modifiers.logo;
|
||||||
events.push_back(window_event);
|
events.push_back(window_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(window_event) = modifier_event(
|
if let Some(window_event) = modifier_event(
|
||||||
event,
|
event,
|
||||||
NSEventModifierFlags::NSAlternateKeyMask,
|
NSEventModifierFlags::NSAlternateKeyMask,
|
||||||
state.modifiers.alt_pressed,
|
state.modifiers.alt,
|
||||||
) {
|
) {
|
||||||
state.modifiers.alt_pressed = !state.modifiers.alt_pressed;
|
state.modifiers.alt = !state.modifiers.alt;
|
||||||
events.push_back(window_event);
|
events.push_back(window_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,6 +685,13 @@ extern "C" fn flags_changed(this: &Object, _sel: Sel, event: id) {
|
||||||
event,
|
event,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AppState::queue_event(Event::DeviceEvent {
|
||||||
|
device_id: DEVICE_ID,
|
||||||
|
event: DeviceEvent::ModifiersChanged {
|
||||||
|
modifiers: state.modifiers,
|
||||||
|
},
|
||||||
|
});
|
||||||
}
|
}
|
||||||
trace!("Completed `flagsChanged`");
|
trace!("Completed `flagsChanged`");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue