mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Move the Suspended event outside of WindowEvent (#284)
* Move Suspended event outside of WindowEvent * Adjust the iOS code
This commit is contained in:
parent
1d0b5bcfbd
commit
52a7b07c79
|
@ -12,6 +12,11 @@ pub enum Event {
|
||||||
event: DeviceEvent,
|
event: DeviceEvent,
|
||||||
},
|
},
|
||||||
Awakened,
|
Awakened,
|
||||||
|
|
||||||
|
/// The application has been suspended or resumed.
|
||||||
|
///
|
||||||
|
/// The parameter is true if app was suspended, and false if it has been resumed.
|
||||||
|
Suspended(bool),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
|
@ -78,13 +83,8 @@ pub enum WindowEvent {
|
||||||
/// The window needs to be redrawn.
|
/// The window needs to be redrawn.
|
||||||
Refresh,
|
Refresh,
|
||||||
|
|
||||||
/// App has been suspended or resumed.
|
|
||||||
///
|
|
||||||
/// The parameter is true if app was suspended, and false if it has been resumed.
|
|
||||||
Suspended(bool),
|
|
||||||
|
|
||||||
/// Touch event has been received
|
/// Touch event has been received
|
||||||
Touch(Touch)
|
Touch(Touch),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Represents raw hardware events that are not associated with any particular window.
|
/// Represents raw hardware events that are not associated with any particular window.
|
||||||
|
|
|
@ -48,25 +48,28 @@ impl EventsLoop {
|
||||||
{
|
{
|
||||||
let event = match self.event_rx.try_recv() {
|
let event = match self.event_rx.try_recv() {
|
||||||
Ok(android_glue::Event::EventMotion(motion)) => {
|
Ok(android_glue::Event::EventMotion(motion)) => {
|
||||||
Some(WindowEvent::Touch(Touch {
|
Some(Event::WindowEvent {
|
||||||
phase: match motion.action {
|
window_id: RootWindowId(WindowId),
|
||||||
android_glue::MotionAction::Down => TouchPhase::Started,
|
event: WindowEvent::Touch(Touch {
|
||||||
android_glue::MotionAction::Move => TouchPhase::Moved,
|
phase: match motion.action {
|
||||||
android_glue::MotionAction::Up => TouchPhase::Ended,
|
android_glue::MotionAction::Down => TouchPhase::Started,
|
||||||
android_glue::MotionAction::Cancel => TouchPhase::Cancelled,
|
android_glue::MotionAction::Move => TouchPhase::Moved,
|
||||||
},
|
android_glue::MotionAction::Up => TouchPhase::Ended,
|
||||||
location: (motion.x as f64, motion.y as f64),
|
android_glue::MotionAction::Cancel => TouchPhase::Cancelled,
|
||||||
id: motion.pointer_id as u64,
|
},
|
||||||
device_id: DEVICE_ID,
|
location: (motion.x as f64, motion.y as f64),
|
||||||
}))
|
id: motion.pointer_id as u64,
|
||||||
|
device_id: DEVICE_ID,
|
||||||
|
}),
|
||||||
|
})
|
||||||
},
|
},
|
||||||
Ok(android_glue::Event::InitWindow) => {
|
Ok(android_glue::Event::InitWindow) => {
|
||||||
// The activity went to foreground.
|
// The activity went to foreground.
|
||||||
Some(WindowEvent::Suspended(false))
|
Some(Event::Suspended(false))
|
||||||
},
|
},
|
||||||
Ok(android_glue::Event::TermWindow) => {
|
Ok(android_glue::Event::TermWindow) => {
|
||||||
// The activity went to background.
|
// The activity went to background.
|
||||||
Some(WindowEvent::Suspended(true))
|
Some(Event::Suspended(true))
|
||||||
},
|
},
|
||||||
Ok(android_glue::Event::WindowResized) |
|
Ok(android_glue::Event::WindowResized) |
|
||||||
Ok(android_glue::Event::ConfigChanged) => {
|
Ok(android_glue::Event::ConfigChanged) => {
|
||||||
|
@ -77,12 +80,18 @@ impl EventsLoop {
|
||||||
} else {
|
} else {
|
||||||
let w = unsafe { ffi::ANativeWindow_getWidth(native_window as *const _) } as u32;
|
let w = unsafe { ffi::ANativeWindow_getWidth(native_window as *const _) } as u32;
|
||||||
let h = unsafe { ffi::ANativeWindow_getHeight(native_window as *const _) } as u32;
|
let h = unsafe { ffi::ANativeWindow_getHeight(native_window as *const _) } as u32;
|
||||||
Some(WindowEvent::Resized(w, h))
|
Some(Event::WindowEvent {
|
||||||
|
window_id: RootWindowId(WindowId),
|
||||||
|
event: WindowEvent::Resized(w, h),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(android_glue::Event::WindowRedrawNeeded) => {
|
Ok(android_glue::Event::WindowRedrawNeeded) => {
|
||||||
// The activity needs to be redrawn.
|
// The activity needs to be redrawn.
|
||||||
Some(WindowEvent::Refresh)
|
Some(Event::WindowEvent {
|
||||||
|
window_id: RootWindowId(WindowId),
|
||||||
|
event: WindowEvent::Refresh,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
None
|
None
|
||||||
|
@ -90,10 +99,7 @@ impl EventsLoop {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(event) = event {
|
if let Some(event) = event {
|
||||||
callback(Event::WindowEvent {
|
callback(event);
|
||||||
window_id: RootWindowId(WindowId),
|
|
||||||
event: event
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,7 +108,7 @@ pub struct WindowProxy;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct DelegateState {
|
struct DelegateState {
|
||||||
events_queue: VecDeque<WindowEvent>,
|
events_queue: VecDeque<Event>,
|
||||||
window: id,
|
window: id,
|
||||||
controller: id,
|
controller: id,
|
||||||
size: (u32,u32),
|
size: (u32,u32),
|
||||||
|
@ -196,20 +196,14 @@ impl EventsLoop {
|
||||||
let state = &mut *self.delegate_state;
|
let state = &mut *self.delegate_state;
|
||||||
|
|
||||||
if let Some(event) = state.events_queue.pop_front() {
|
if let Some(event) = state.events_queue.pop_front() {
|
||||||
callback(Event::WindowEvent {
|
callback(event);
|
||||||
window_id: RootEventId(WindowId),
|
|
||||||
event: event,
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// jump hack, so we won't quit on willTerminate event before processing it
|
// jump hack, so we won't quit on willTerminate event before processing it
|
||||||
if setjmp(mem::transmute(&mut jmpbuf)) != 0 {
|
if setjmp(mem::transmute(&mut jmpbuf)) != 0 {
|
||||||
if let Some(event) = state.events_queue.pop_front() {
|
if let Some(event) = state.events_queue.pop_front() {
|
||||||
callback(Event::WindowEvent {
|
callback(event);
|
||||||
window_id: RootEventId(WindowId),
|
|
||||||
event: event,
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -219,10 +213,7 @@ impl EventsLoop {
|
||||||
while CFRunLoopRunInMode(kCFRunLoopDefaultMode, seconds, 1) == kCFRunLoopRunHandledSource {}
|
while CFRunLoopRunInMode(kCFRunLoopDefaultMode, seconds, 1) == kCFRunLoopRunHandledSource {}
|
||||||
|
|
||||||
if let Some(event) = state.events_queue.pop_front() {
|
if let Some(event) = state.events_queue.pop_front() {
|
||||||
callback(Event::WindowEvent {
|
callback(event)
|
||||||
window_id: RootEventId(WindowId),
|
|
||||||
event: event,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -404,7 +395,10 @@ fn create_delegate_class() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let state: *mut c_void = *this.get_ivar("glutinState");
|
let state: *mut c_void = *this.get_ivar("glutinState");
|
||||||
let state = &mut *(state as *mut DelegateState);
|
let state = &mut *(state as *mut DelegateState);
|
||||||
state.events_queue.push_back(WindowEvent::Focused(true));
|
state.events_queue.push_back(Event::WindowEvent {
|
||||||
|
window_id: RootEventId(WindowId),
|
||||||
|
event: WindowEvent::Focused(true),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -412,7 +406,10 @@ fn create_delegate_class() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let state: *mut c_void = *this.get_ivar("glutinState");
|
let state: *mut c_void = *this.get_ivar("glutinState");
|
||||||
let state = &mut *(state as *mut DelegateState);
|
let state = &mut *(state as *mut DelegateState);
|
||||||
state.events_queue.push_back(WindowEvent::Focused(false));
|
state.events_queue.push_back(Event::WindowEvent {
|
||||||
|
window_id: RootEventId(WindowId),
|
||||||
|
event: WindowEvent::Focused(false),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,7 +417,7 @@ fn create_delegate_class() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let state: *mut c_void = *this.get_ivar("glutinState");
|
let state: *mut c_void = *this.get_ivar("glutinState");
|
||||||
let state = &mut *(state as *mut DelegateState);
|
let state = &mut *(state as *mut DelegateState);
|
||||||
state.events_queue.push_back(WindowEvent::Suspended(false));
|
state.events_queue.push_back(Event::Suspended(false));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,7 +425,7 @@ fn create_delegate_class() {
|
||||||
unsafe {
|
unsafe {
|
||||||
let state: *mut c_void = *this.get_ivar("glutinState");
|
let state: *mut c_void = *this.get_ivar("glutinState");
|
||||||
let state = &mut *(state as *mut DelegateState);
|
let state = &mut *(state as *mut DelegateState);
|
||||||
state.events_queue.push_back(WindowEvent::Suspended(true));
|
state.events_queue.push_back(Event::Suspended(true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,7 +435,10 @@ fn create_delegate_class() {
|
||||||
let state = &mut *(state as *mut DelegateState);
|
let state = &mut *(state as *mut DelegateState);
|
||||||
// push event to the front to garantee that we'll process it
|
// push event to the front to garantee that we'll process it
|
||||||
// immidiatly after jump
|
// immidiatly after jump
|
||||||
state.events_queue.push_front(WindowEvent::Closed);
|
state.events_queue.push_front(Event::WindowEvent {
|
||||||
|
window_id: RootEventId(WindowId),
|
||||||
|
event: WindowEvent::Closed,
|
||||||
|
});
|
||||||
longjmp(mem::transmute(&mut jmpbuf),1);
|
longjmp(mem::transmute(&mut jmpbuf),1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -459,19 +459,22 @@ fn create_delegate_class() {
|
||||||
let touch_id = touch as u64;
|
let touch_id = touch as u64;
|
||||||
let phase: i32 = msg_send![touch, phase];
|
let phase: i32 = msg_send![touch, phase];
|
||||||
|
|
||||||
state.events_queue.push_back(WindowEvent::Touch(Touch {
|
state.events_queue.push_back(Event::WindowEvent {
|
||||||
device_id: DEVICE_ID,
|
window_id: RootEventId(WindowId),
|
||||||
id: touch_id,
|
event: WindowEvent::Touch(Touch {
|
||||||
location: (location.x as f64, location.y as f64),
|
device_id: DEVICE_ID,
|
||||||
phase: match phase {
|
id: touch_id,
|
||||||
0 => TouchPhase::Started,
|
location: (location.x as f64, location.y as f64),
|
||||||
1 => TouchPhase::Moved,
|
phase: match phase {
|
||||||
// 2 is UITouchPhaseStationary and is not expected here
|
0 => TouchPhase::Started,
|
||||||
3 => TouchPhase::Ended,
|
1 => TouchPhase::Moved,
|
||||||
4 => TouchPhase::Cancelled,
|
// 2 is UITouchPhaseStationary and is not expected here
|
||||||
_ => panic!("unexpected touch phase: {:?}", phase)
|
3 => TouchPhase::Ended,
|
||||||
}
|
4 => TouchPhase::Cancelled,
|
||||||
}));
|
_ => panic!("unexpected touch phase: {:?}", phase)
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue