macOS: Merge window and delegate state (#3391)

Previously we had a sort of artificial split between these, but both were accessing each other's state, since it's really the same state!
It was especially difficult to follow what happens to the fullscreen state.
So instead, we basically merge the window and the delegate files.

This does unfortunately screw a bit with the git history, apologies to whoever reads this in the future!
This commit is contained in:
Mads Marquart 2024-01-14 05:19:23 +01:00 committed by GitHub
parent c86b0daf7f
commit 14b418a3a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 1516 additions and 1520 deletions

View file

@ -75,7 +75,7 @@ impl PanicInfo {
#[derive(Debug)]
pub struct EventLoopWindowTarget {
delegate: Id<ApplicationDelegate>,
mtm: MainThreadMarker,
pub(super) mtm: MainThreadMarker,
}
impl EventLoopWindowTarget {

View file

@ -22,7 +22,8 @@ pub(crate) use self::{
EventLoop, EventLoopProxy, EventLoopWindowTarget, PlatformSpecificEventLoopAttributes,
},
monitor::{MonitorHandle, VideoModeHandle},
window::{PlatformSpecificWindowBuilderAttributes, WindowId},
window::WindowId,
window_delegate::PlatformSpecificWindowBuilderAttributes,
};
use crate::event::DeviceId as RootDeviceId;

View file

@ -34,7 +34,7 @@ use crate::{
WindowEvent,
},
keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey},
platform::macos::{OptionAsAlt, WindowExtMacOS},
platform::macos::OptionAsAlt,
};
#[derive(Debug)]
@ -141,6 +141,9 @@ pub struct ViewState {
// Weak reference because the window keeps a strong reference to the view
_ns_window: WeakId<WinitWindow>,
/// The state of the `Option` as `Alt`.
option_as_alt: Cell<OptionAsAlt>,
}
declare_class!(
@ -437,7 +440,7 @@ declare_class!(
// Get the characters from the event.
let old_ime_state = self.ivars().ime_state.get();
self.ivars().forward_key_to_app.set(false);
let event = replace_event(event, self.window().option_as_alt());
let event = replace_event(event, self.option_as_alt());
// The `interpretKeyEvents` function might call
// `setMarkedText`, `insertText`, and `doCommandBySelector`.
@ -483,7 +486,7 @@ declare_class!(
fn key_up(&self, event: &NSEvent) {
trace_scope!("keyUp:");
let event = replace_event(event, self.window().option_as_alt());
let event = replace_event(event, self.option_as_alt());
self.update_modifiers(&event, false);
// We want to send keyboard input when we are currently in the ground state.
@ -759,11 +762,16 @@ declare_class!(
);
impl WinitView {
pub(super) fn new(window: &WinitWindow, accepts_first_mouse: bool) -> Id<Self> {
pub(super) fn new(
window: &WinitWindow,
accepts_first_mouse: bool,
option_as_alt: OptionAsAlt,
) -> Id<Self> {
let mtm = MainThreadMarker::from(window);
let this = mtm.alloc().set_ivars(ViewState {
accepts_first_mouse,
_ns_window: WeakId::new(&window.retain()),
option_as_alt: Cell::new(option_as_alt),
..Default::default()
});
let this: Id<Self> = unsafe { msg_send_id![super(this), init] };
@ -883,6 +891,14 @@ impl WinitView {
}
}
pub(super) fn set_option_as_alt(&self, value: OptionAsAlt) {
self.ivars().option_as_alt.set(value)
}
pub(super) fn option_as_alt(&self) -> OptionAsAlt {
self.ivars().option_as_alt.get()
}
/// Update modifiers if `event` has something different
fn update_modifiers(&self, ns_event: &NSEvent, is_flags_changed_event: bool) {
use ElementState::{Pressed, Released};

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff