mirror of
https://github.com/italicsjenga/winit-sonoma-fix.git
synced 2025-01-11 21:31:29 +11:00
Allow preventing the creation of the default menu (#1923)
* Allow preventing the creation of the default menu * Use more grammar friendly naming * Update the changelog
This commit is contained in:
parent
cdeb1c3828
commit
0152508a39
|
@ -26,7 +26,7 @@
|
||||||
- On Windows, added `WindowExtWindows::set_enable` to allow creating modal popup windows.
|
- On Windows, added `WindowExtWindows::set_enable` to allow creating modal popup windows.
|
||||||
- On macOS, emit `RedrawRequested` events immediately while the window is being resized.
|
- On macOS, emit `RedrawRequested` events immediately while the window is being resized.
|
||||||
- Implement `Default`, `Hash`, and `Eq` for `LogicalPosition`, `PhysicalPosition`, `LogicalSize`, and `PhysicalSize`.
|
- Implement `Default`, `Hash`, and `Eq` for `LogicalPosition`, `PhysicalPosition`, `LogicalSize`, and `PhysicalSize`.
|
||||||
- On macOS, initialize the Menu Bar with minimal defaults.
|
- On macOS, initialize the Menu Bar with minimal defaults. (Can be prevented using `enable_default_menu_creation`)
|
||||||
- On macOS, change the default behavior for first click when the window was unfocused. Now the window becomes focused and then emits a `MouseInput` event on a "first mouse click".
|
- On macOS, change the default behavior for first click when the window was unfocused. Now the window becomes focused and then emits a `MouseInput` event on a "first mouse click".
|
||||||
|
|
||||||
# 0.24.0 (2020-12-09)
|
# 0.24.0 (2020-12-09)
|
||||||
|
|
|
@ -186,6 +186,15 @@ pub trait EventLoopExtMacOS {
|
||||||
/// This function only takes effect if it's called before calling [`run`](crate::event_loop::EventLoop::run) or
|
/// This function only takes effect if it's called before calling [`run`](crate::event_loop::EventLoop::run) or
|
||||||
/// [`run_return`](crate::platform::run_return::EventLoopExtRunReturn::run_return)
|
/// [`run_return`](crate::platform::run_return::EventLoopExtRunReturn::run_return)
|
||||||
fn set_activation_policy(&mut self, activation_policy: ActivationPolicy);
|
fn set_activation_policy(&mut self, activation_policy: ActivationPolicy);
|
||||||
|
|
||||||
|
/// Used to prevent a default menubar menu from getting created
|
||||||
|
///
|
||||||
|
/// The default menu creation is enabled by default.
|
||||||
|
///
|
||||||
|
/// This function only takes effect if it's called before calling
|
||||||
|
/// [`run`](crate::event_loop::EventLoop::run) or
|
||||||
|
/// [`run_return`](crate::platform::run_return::EventLoopExtRunReturn::run_return)
|
||||||
|
fn enable_default_menu_creation(&mut self, enable: bool);
|
||||||
}
|
}
|
||||||
impl<T> EventLoopExtMacOS for EventLoop<T> {
|
impl<T> EventLoopExtMacOS for EventLoop<T> {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -194,6 +203,13 @@ impl<T> EventLoopExtMacOS for EventLoop<T> {
|
||||||
get_aux_state_mut(&**self.event_loop.delegate).activation_policy = activation_policy;
|
get_aux_state_mut(&**self.event_loop.delegate).activation_policy = activation_policy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn enable_default_menu_creation(&mut self, enable: bool) {
|
||||||
|
unsafe {
|
||||||
|
get_aux_state_mut(&**self.event_loop.delegate).create_default_menu = enable;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Additional methods on `MonitorHandle` that are specific to MacOS.
|
/// Additional methods on `MonitorHandle` that are specific to MacOS.
|
||||||
|
|
|
@ -17,6 +17,8 @@ pub struct AuxDelegateState {
|
||||||
/// after the app has finished launching. If the activation policy is set earlier, the
|
/// after the app has finished launching. If the activation policy is set earlier, the
|
||||||
/// menubar is initially unresponsive on macOS 10.15 for example.
|
/// menubar is initially unresponsive on macOS 10.15 for example.
|
||||||
pub activation_policy: ActivationPolicy,
|
pub activation_policy: ActivationPolicy,
|
||||||
|
|
||||||
|
pub create_default_menu: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct AppDelegateClass(pub *const Class);
|
pub struct AppDelegateClass(pub *const Class);
|
||||||
|
@ -56,6 +58,7 @@ extern "C" fn new(class: &Class, _: Sel) -> id {
|
||||||
AUX_DELEGATE_STATE_NAME,
|
AUX_DELEGATE_STATE_NAME,
|
||||||
Box::into_raw(Box::new(RefCell::new(AuxDelegateState {
|
Box::into_raw(Box::new(RefCell::new(AuxDelegateState {
|
||||||
activation_policy: ActivationPolicy::Regular,
|
activation_policy: ActivationPolicy::Regular,
|
||||||
|
create_default_menu: true,
|
||||||
}))) as *mut c_void,
|
}))) as *mut c_void,
|
||||||
);
|
);
|
||||||
this
|
this
|
||||||
|
|
|
@ -289,9 +289,12 @@ impl AppState {
|
||||||
};
|
};
|
||||||
HANDLER.set_ready();
|
HANDLER.set_ready();
|
||||||
HANDLER.waker().start();
|
HANDLER.waker().start();
|
||||||
// The menubar initialization should be before the `NewEvents` event, to allow overriding
|
let create_default_menu = unsafe { get_aux_state_mut(app_delegate).create_default_menu };
|
||||||
// of the default menu in the event
|
if create_default_menu {
|
||||||
|
// The menubar initialization should be before the `NewEvents` event, to allow
|
||||||
|
// overriding of the default menu even if it's created
|
||||||
menu::initialize();
|
menu::initialize();
|
||||||
|
}
|
||||||
HANDLER.set_in_callback(true);
|
HANDLER.set_in_callback(true);
|
||||||
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::NewEvents(
|
HANDLER.handle_nonuser_event(EventWrapper::StaticEvent(Event::NewEvents(
|
||||||
StartCause::Init,
|
StartCause::Init,
|
||||||
|
|
Loading…
Reference in a new issue