Skip to content

Commit

Permalink
try to fix apple and orbital
Browse files Browse the repository at this point in the history
  • Loading branch information
jgcodes2020 committed Oct 22, 2024
1 parent 3c7e5b0 commit 9c7aae3
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 121 deletions.
14 changes: 7 additions & 7 deletions src/platform_impl/apple/appkit/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use super::event_loop::{stop_app_immediately, ActiveEventLoop, PanicInfo};
use super::menu;
use super::observer::{EventLoopWaker, RunLoop};
use crate::application::ApplicationHandler;
use crate::event::{StartCause, WindowEvent};
use crate::event::{StartCause, SurfaceEvent};
use crate::event_loop::ControlFlow;
use crate::window::WindowId;
use crate::window::SurfaceId;

#[derive(Debug)]
pub(super) struct AppState {
Expand All @@ -40,7 +40,7 @@ pub(super) struct AppState {
waker: RefCell<EventLoopWaker>,
start_time: Cell<Option<Instant>>,
wait_timeout: Cell<Option<Instant>>,
pending_redraw: RefCell<Vec<WindowId>>,
pending_redraw: RefCell<Vec<SurfaceId>>,
// NOTE: This is strongly referenced by our `NSWindowDelegate` and our `NSView` subclass, and
// as such should be careful to not add fields that, in turn, strongly reference those.
}
Expand Down Expand Up @@ -240,12 +240,12 @@ impl AppState {
self.control_flow.get()
}

pub fn handle_redraw(self: &Rc<Self>, window_id: WindowId) {
pub fn handle_redraw(self: &Rc<Self>, window_id: SurfaceId) {
// Redraw request might come out of order from the OS.
// -> Don't go back into the event handler when our callstack originates from there
if !self.event_handler.in_use() {
self.with_handler(|app, event_loop| {
app.window_event(event_loop, window_id, WindowEvent::RedrawRequested);
app.window_event(event_loop, window_id, SurfaceEvent::RedrawRequested);
});

// `pump_events` will request to stop immediately _after_ dispatching RedrawRequested
Expand All @@ -258,7 +258,7 @@ impl AppState {
}
}

pub fn queue_redraw(&self, window_id: WindowId) {
pub fn queue_redraw(&self, window_id: SurfaceId) {
let mut pending_redraw = self.pending_redraw.borrow_mut();
if !pending_redraw.contains(&window_id) {
pending_redraw.push(window_id);
Expand Down Expand Up @@ -357,7 +357,7 @@ impl AppState {
let redraw = mem::take(&mut *self.pending_redraw.borrow_mut());
for window_id in redraw {
self.with_handler(|app, event_loop| {
app.window_event(event_loop, window_id, WindowEvent::RedrawRequested);
app.window_event(event_loop, window_id, SurfaceEvent::RedrawRequested);
});
}
self.with_handler(|app, event_loop| {
Expand Down
56 changes: 28 additions & 28 deletions src/platform_impl/apple/appkit/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use super::window::WinitWindow;
use crate::dpi::{LogicalPosition, LogicalSize};
use crate::event::{
DeviceEvent, ElementState, Ime, Modifiers, MouseButton, MouseScrollDelta, PointerKind,
PointerSource, TouchPhase, WindowEvent,
PointerSource, TouchPhase, SurfaceEvent,
};
use crate::keyboard::{Key, KeyCode, KeyLocation, ModifiersState, NamedKey};
use crate::platform::macos::OptionAsAlt;
Expand Down Expand Up @@ -196,7 +196,7 @@ declare_class!(
// 2. Even when a window resize does occur on a new tabbed window, it contains the wrong size (includes tab height).
let logical_size = LogicalSize::new(rect.size.width as f64, rect.size.height as f64);
let size = logical_size.to_physical::<u32>(self.scale_factor());
self.queue_event(WindowEvent::SurfaceResized(size));
self.queue_event(SurfaceEvent::SurfaceResized(size));
}

#[method(drawRect:)]
Expand Down Expand Up @@ -301,7 +301,7 @@ declare_class!(
// Notify IME is active if application still doesn't know it.
if self.ivars().ime_state.get() == ImeState::Disabled {
*self.ivars().input_source.borrow_mut() = self.current_input_source();
self.queue_event(WindowEvent::Ime(Ime::Enabled));
self.queue_event(SurfaceEvent::Ime(Ime::Enabled));
}

if unsafe { self.hasMarkedText() } {
Expand All @@ -324,8 +324,8 @@ declare_class!(
Some((lowerbound_utf8, upperbound_utf8))
};

// Send WindowEvent for updating marked text
self.queue_event(WindowEvent::Ime(Ime::Preedit(string.to_string(), cursor_range)));
// Send SurfaceEvent for updating marked text
self.queue_event(SurfaceEvent::Ime(Ime::Preedit(string.to_string(), cursor_range)));
}

#[method(unmarkText)]
Expand All @@ -336,7 +336,7 @@ declare_class!(
let input_context = self.inputContext().expect("input context");
input_context.discardMarkedText();

self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None)));
self.queue_event(SurfaceEvent::Ime(Ime::Preedit(String::new(), None)));
if self.is_ime_enabled() {
// Leave the Preedit self.ivars()
self.ivars().ime_state.set(ImeState::Ground);
Expand Down Expand Up @@ -403,8 +403,8 @@ declare_class!(

// Commit only if we have marked text.
if unsafe { self.hasMarkedText() } && self.is_ime_enabled() && !is_control {
self.queue_event(WindowEvent::Ime(Ime::Preedit(String::new(), None)));
self.queue_event(WindowEvent::Ime(Ime::Commit(string)));
self.queue_event(SurfaceEvent::Ime(Ime::Preedit(String::new(), None)));
self.queue_event(SurfaceEvent::Ime(Ime::Commit(string)));
self.ivars().ime_state.set(ImeState::Committed);
}
}
Expand Down Expand Up @@ -442,7 +442,7 @@ declare_class!(
*prev_input_source = current_input_source;
drop(prev_input_source);
self.ivars().ime_state.set(ImeState::Disabled);
self.queue_event(WindowEvent::Ime(Ime::Disabled));
self.queue_event(SurfaceEvent::Ime(Ime::Disabled));
}
}

Expand Down Expand Up @@ -483,7 +483,7 @@ declare_class!(

if !had_ime_input || self.ivars().forward_key_to_app.get() {
let key_event = create_key_event(&event, true, unsafe { event.isARepeat() }, None);
self.queue_event(WindowEvent::KeyboardInput {
self.queue_event(SurfaceEvent::KeyboardInput {
device_id: None,
event: key_event,
is_synthetic: false,
Expand All @@ -503,7 +503,7 @@ declare_class!(
self.ivars().ime_state.get(),
ImeState::Ground | ImeState::Disabled
) {
self.queue_event(WindowEvent::KeyboardInput {
self.queue_event(SurfaceEvent::KeyboardInput {
device_id: None,
event: create_key_event(&event, false, false, None),
is_synthetic: false,
Expand Down Expand Up @@ -554,7 +554,7 @@ declare_class!(
self.update_modifiers(&event, false);
let event = create_key_event(&event, true, unsafe { event.isARepeat() }, None);

self.queue_event(WindowEvent::KeyboardInput {
self.queue_event(SurfaceEvent::KeyboardInput {
device_id: None,
event,
is_synthetic: false,
Expand Down Expand Up @@ -642,7 +642,7 @@ declare_class!(

let position = self.mouse_view_point(event).to_physical(self.scale_factor());

self.queue_event(WindowEvent::PointerEntered {
self.queue_event(SurfaceEvent::PointerEntered {
device_id: None,
position,
kind: PointerKind::Mouse,
Expand All @@ -655,7 +655,7 @@ declare_class!(

let position = self.mouse_view_point(event).to_physical(self.scale_factor());

self.queue_event(WindowEvent::PointerLeft {
self.queue_event(SurfaceEvent::PointerLeft {
device_id: None,
position: Some(position),
kind: PointerKind::Mouse,
Expand Down Expand Up @@ -698,7 +698,7 @@ declare_class!(
self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop|
app.device_event(event_loop, None, DeviceEvent::MouseWheel { delta })
);
self.queue_event(WindowEvent::MouseWheel {
self.queue_event(SurfaceEvent::MouseWheel {
device_id: None,
delta,
phase,
Expand All @@ -720,7 +720,7 @@ declare_class!(
_ => return,
};

self.queue_event(WindowEvent::PinchGesture {
self.queue_event(SurfaceEvent::PinchGesture {
device_id: None,
delta: unsafe { event.magnification() },
phase,
Expand All @@ -733,7 +733,7 @@ declare_class!(

self.mouse_motion(event);

self.queue_event(WindowEvent::DoubleTapGesture {
self.queue_event(SurfaceEvent::DoubleTapGesture {
device_id: None,
});
}
Expand All @@ -753,7 +753,7 @@ declare_class!(
_ => return,
};

self.queue_event(WindowEvent::RotationGesture {
self.queue_event(SurfaceEvent::RotationGesture {
device_id: None,
delta: unsafe { event.rotation() },
phase,
Expand All @@ -764,7 +764,7 @@ declare_class!(
fn pressure_change_with_event(&self, event: &NSEvent) {
trace_scope!("pressureChangeWithEvent:");

self.queue_event(WindowEvent::TouchpadPressure {
self.queue_event(SurfaceEvent::TouchpadPressure {
device_id: None,
pressure: unsafe { event.pressure() },
stage: unsafe { event.stage() } as i64,
Expand Down Expand Up @@ -840,7 +840,7 @@ impl WinitView {
self.ivars()._ns_window.load().expect("view to have a window")
}

fn queue_event(&self, event: WindowEvent) {
fn queue_event(&self, event: SurfaceEvent) {
let window_id = self.window().id();
self.ivars().app_state.maybe_queue_with_handler(move |app, event_loop| {
app.window_event(event_loop, window_id, event);
Expand Down Expand Up @@ -899,7 +899,7 @@ impl WinitView {

if self.ivars().ime_state.get() != ImeState::Disabled {
self.ivars().ime_state.set(ImeState::Disabled);
self.queue_event(WindowEvent::Ime(Ime::Disabled));
self.queue_event(SurfaceEvent::Ime(Ime::Disabled));
}
}

Expand All @@ -914,7 +914,7 @@ impl WinitView {
pub(super) fn reset_modifiers(&self) {
if !self.ivars().modifiers.get().state().is_empty() {
self.ivars().modifiers.set(Modifiers::default());
self.queue_event(WindowEvent::ModifiersChanged(self.ivars().modifiers.get()));
self.queue_event(SurfaceEvent::ModifiersChanged(self.ivars().modifiers.get()));
}
}

Expand Down Expand Up @@ -978,7 +978,7 @@ impl WinitView {
let mut event = event.clone();
event.location = KeyLocation::Left;
event.physical_key = get_left_modifier_code(&event.logical_key).into();
events.push_back(WindowEvent::KeyboardInput {
events.push_back(SurfaceEvent::KeyboardInput {
device_id: None,
event,
is_synthetic: false,
Expand All @@ -987,7 +987,7 @@ impl WinitView {
if phys_mod.contains(ModLocationMask::RIGHT) {
event.location = KeyLocation::Right;
event.physical_key = get_right_modifier_code(&event.logical_key).into();
events.push_back(WindowEvent::KeyboardInput {
events.push_back(SurfaceEvent::KeyboardInput {
device_id: None,
event,
is_synthetic: false,
Expand Down Expand Up @@ -1018,7 +1018,7 @@ impl WinitView {
event.state = if is_pressed { Pressed } else { Released };
}

events.push_back(WindowEvent::KeyboardInput {
events.push_back(SurfaceEvent::KeyboardInput {
device_id: None,
event,
is_synthetic: false,
Expand All @@ -1037,7 +1037,7 @@ impl WinitView {
return;
}

self.queue_event(WindowEvent::ModifiersChanged(self.ivars().modifiers.get()));
self.queue_event(SurfaceEvent::ModifiersChanged(self.ivars().modifiers.get()));
}

fn mouse_click(&self, event: &NSEvent, button_state: ElementState) {
Expand All @@ -1046,7 +1046,7 @@ impl WinitView {

self.update_modifiers(event, false);

self.queue_event(WindowEvent::PointerButton {
self.queue_event(SurfaceEvent::PointerButton {
device_id: None,
state: button_state,
position,
Expand All @@ -1072,7 +1072,7 @@ impl WinitView {

self.update_modifiers(event, false);

self.queue_event(WindowEvent::PointerMoved {
self.queue_event(SurfaceEvent::PointerMoved {
device_id: None,
position: view_point.to_physical(self.scale_factor()),
source: PointerSource::Mouse,
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/apple/appkit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::error::RequestError;
use crate::monitor::MonitorHandle as CoreMonitorHandle;
use crate::window::{
Cursor, Fullscreen, Icon, ImePurpose, Theme, UserAttentionType, Window as CoreWindow,
WindowAttributes, WindowButtons, WindowId, WindowLevel,
WindowAttributes, WindowButtons, SurfaceId, WindowLevel,
};

pub(crate) struct Window {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl rwh_06::HasWindowHandle for Window {
}

impl CoreWindow for Window {
fn id(&self) -> crate::window::WindowId {
fn id(&self) -> crate::window::SurfaceId {
self.maybe_wait_on_main(|delegate| delegate.id())
}

Expand Down Expand Up @@ -364,7 +364,7 @@ declare_class!(
);

impl WinitWindow {
pub(super) fn id(&self) -> WindowId {
WindowId::from_raw(self as *const Self as usize)
pub(super) fn id(&self) -> SurfaceId {
SurfaceId::from_raw(self as *const Self as usize)
}
}
Loading

0 comments on commit 9c7aae3

Please sign in to comment.