Make ns identifiers use snake_case on macOS (#904)

This makes the macOS API style consistent with that of iOS.
This commit is contained in:
Nikolai Vazquez 2019-06-11 01:09:38 +02:00 committed by Osspial
parent 07356b9634
commit f256ff7d58
7 changed files with 206 additions and 205 deletions

View file

@ -10,25 +10,25 @@ use dispatch::ffi::{dispatch_async_f, dispatch_get_main_queue, dispatch_sync_f};
use dpi::LogicalSize;
use platform_impl::platform::{ffi, window::SharedState};
unsafe fn set_style_mask(nswindow: id, nsview: id, mask: NSWindowStyleMask) {
nswindow.setStyleMask_(mask);
unsafe fn set_style_mask(ns_window: id, ns_view: id, mask: NSWindowStyleMask) {
ns_window.setStyleMask_(mask);
// If we don't do this, key handling will break
// (at least until the window is clicked again/etc.)
nswindow.makeFirstResponder_(nsview);
ns_window.makeFirstResponder_(ns_view);
}
struct SetStyleMaskData {
nswindow: id,
nsview: id,
ns_window: id,
ns_view: id,
mask: NSWindowStyleMask,
}
impl SetStyleMaskData {
fn new_ptr(
nswindow: id,
nsview: id,
ns_window: id,
ns_view: id,
mask: NSWindowStyleMask,
) -> *mut Self {
Box::into_raw(Box::new(SetStyleMaskData { nswindow, nsview, mask }))
Box::into_raw(Box::new(SetStyleMaskData { ns_window, ns_view, mask }))
}
}
extern fn set_style_mask_callback(context: *mut c_void) {
@ -36,7 +36,7 @@ extern fn set_style_mask_callback(context: *mut c_void) {
let context_ptr = context as *mut SetStyleMaskData;
{
let context = &*context_ptr;
set_style_mask(context.nswindow, context.nsview, context.mask);
set_style_mask(context.ns_window, context.ns_view, context.mask);
}
Box::from_raw(context_ptr);
}
@ -45,16 +45,16 @@ extern fn set_style_mask_callback(context: *mut c_void) {
// `setStyleMask:` isn't thread-safe, so we have to use Grand Central Dispatch.
// Otherwise, this would vomit out errors about not being on the main thread
// and fail to do anything.
pub unsafe fn set_style_mask_async(nswindow: id, nsview: id, mask: NSWindowStyleMask) {
let context = SetStyleMaskData::new_ptr(nswindow, nsview, mask);
pub unsafe fn set_style_mask_async(ns_window: id, ns_view: id, mask: NSWindowStyleMask) {
let context = SetStyleMaskData::new_ptr(ns_window, ns_view, mask);
dispatch_async_f(
dispatch_get_main_queue(),
context as *mut _,
set_style_mask_callback,
);
}
pub unsafe fn set_style_mask_sync(nswindow: id, nsview: id, mask: NSWindowStyleMask) {
let context = SetStyleMaskData::new_ptr(nswindow, nsview, mask);
pub unsafe fn set_style_mask_sync(ns_window: id, ns_view: id, mask: NSWindowStyleMask) {
let context = SetStyleMaskData::new_ptr(ns_window, ns_view, mask);
dispatch_sync_f(
dispatch_get_main_queue(),
context as *mut _,
@ -63,15 +63,15 @@ pub unsafe fn set_style_mask_sync(nswindow: id, nsview: id, mask: NSWindowStyleM
}
struct SetContentSizeData {
nswindow: id,
ns_window: id,
size: LogicalSize,
}
impl SetContentSizeData {
fn new_ptr(
nswindow: id,
ns_window: id,
size: LogicalSize,
) -> *mut Self {
Box::into_raw(Box::new(SetContentSizeData { nswindow, size }))
Box::into_raw(Box::new(SetContentSizeData { ns_window, size }))
}
}
extern fn set_content_size_callback(context: *mut c_void) {
@ -80,7 +80,7 @@ extern fn set_content_size_callback(context: *mut c_void) {
{
let context = &*context_ptr;
NSWindow::setContentSize_(
context.nswindow,
context.ns_window,
NSSize::new(
context.size.width as CGFloat,
context.size.height as CGFloat,
@ -92,8 +92,8 @@ extern fn set_content_size_callback(context: *mut c_void) {
}
// `setContentSize:` isn't thread-safe either, though it doesn't log any errors
// and just fails silently. Anyway, GCD to the rescue!
pub unsafe fn set_content_size_async(nswindow: id, size: LogicalSize) {
let context = SetContentSizeData::new_ptr(nswindow, size);
pub unsafe fn set_content_size_async(ns_window: id, size: LogicalSize) {
let context = SetContentSizeData::new_ptr(ns_window, size);
dispatch_async_f(
dispatch_get_main_queue(),
context as *mut _,
@ -102,15 +102,15 @@ pub unsafe fn set_content_size_async(nswindow: id, size: LogicalSize) {
}
struct SetFrameTopLeftPointData {
nswindow: id,
ns_window: id,
point: NSPoint,
}
impl SetFrameTopLeftPointData {
fn new_ptr(
nswindow: id,
ns_window: id,
point: NSPoint,
) -> *mut Self {
Box::into_raw(Box::new(SetFrameTopLeftPointData { nswindow, point }))
Box::into_raw(Box::new(SetFrameTopLeftPointData { ns_window, point }))
}
}
extern fn set_frame_top_left_point_callback(context: *mut c_void) {
@ -118,15 +118,15 @@ extern fn set_frame_top_left_point_callback(context: *mut c_void) {
let context_ptr = context as *mut SetFrameTopLeftPointData;
{
let context = &*context_ptr;
NSWindow::setFrameTopLeftPoint_(context.nswindow, context.point);
NSWindow::setFrameTopLeftPoint_(context.ns_window, context.point);
}
Box::from_raw(context_ptr);
}
}
// `setFrameTopLeftPoint:` isn't thread-safe, but fortunately has the courtesy
// to log errors.
pub unsafe fn set_frame_top_left_point_async(nswindow: id, point: NSPoint) {
let context = SetFrameTopLeftPointData::new_ptr(nswindow, point);
pub unsafe fn set_frame_top_left_point_async(ns_window: id, point: NSPoint) {
let context = SetFrameTopLeftPointData::new_ptr(ns_window, point);
dispatch_async_f(
dispatch_get_main_queue(),
context as *mut _,
@ -135,15 +135,15 @@ pub unsafe fn set_frame_top_left_point_async(nswindow: id, point: NSPoint) {
}
struct SetLevelData {
nswindow: id,
ns_window: id,
level: ffi::NSWindowLevel,
}
impl SetLevelData {
fn new_ptr(
nswindow: id,
ns_window: id,
level: ffi::NSWindowLevel,
) -> *mut Self {
Box::into_raw(Box::new(SetLevelData { nswindow, level }))
Box::into_raw(Box::new(SetLevelData { ns_window, level }))
}
}
extern fn set_level_callback(context: *mut c_void) {
@ -151,14 +151,14 @@ extern fn set_level_callback(context: *mut c_void) {
let context_ptr = context as *mut SetLevelData;
{
let context = &*context_ptr;
context.nswindow.setLevel_(context.level as _);
context.ns_window.setLevel_(context.level as _);
}
Box::from_raw(context_ptr);
}
}
// `setFrameTopLeftPoint:` isn't thread-safe, and fails silently.
pub unsafe fn set_level_async(nswindow: id, level: ffi::NSWindowLevel) {
let context = SetLevelData::new_ptr(nswindow, level);
pub unsafe fn set_level_async(ns_window: id, level: ffi::NSWindowLevel) {
let context = SetLevelData::new_ptr(ns_window, level);
dispatch_async_f(
dispatch_get_main_queue(),
context as *mut _,
@ -167,21 +167,21 @@ pub unsafe fn set_level_async(nswindow: id, level: ffi::NSWindowLevel) {
}
struct ToggleFullScreenData {
nswindow: id,
nsview: id,
ns_window: id,
ns_view: id,
not_fullscreen: bool,
shared_state: Weak<Mutex<SharedState>>,
}
impl ToggleFullScreenData {
fn new_ptr(
nswindow: id,
nsview: id,
ns_window: id,
ns_view: id,
not_fullscreen: bool,
shared_state: Weak<Mutex<SharedState>>,
) -> *mut Self {
Box::into_raw(Box::new(ToggleFullScreenData {
nswindow,
nsview,
ns_window,
ns_view,
not_fullscreen,
shared_state,
}))
@ -197,11 +197,11 @@ extern fn toggle_full_screen_callback(context: *mut c_void) {
// set a normal style temporarily. The previous state will be
// restored in `WindowDelegate::window_did_exit_fullscreen`.
if context.not_fullscreen {
let curr_mask = context.nswindow.styleMask();
let curr_mask = context.ns_window.styleMask();
let required = NSWindowStyleMask::NSTitledWindowMask
| NSWindowStyleMask::NSResizableWindowMask;
if !curr_mask.contains(required) {
set_style_mask(context.nswindow, context.nsview, required);
set_style_mask(context.ns_window, context.ns_view, required);
if let Some(shared_state) = context.shared_state.upgrade() {
trace!("Locked shared state in `toggle_full_screen_callback`");
let mut shared_state_lock = shared_state.lock().unwrap();
@ -211,7 +211,7 @@ extern fn toggle_full_screen_callback(context: *mut c_void) {
}
}
context.nswindow.toggleFullScreen_(nil);
context.ns_window.toggleFullScreen_(nil);
}
Box::from_raw(context_ptr);
}
@ -219,14 +219,14 @@ extern fn toggle_full_screen_callback(context: *mut c_void) {
// `toggleFullScreen` is thread-safe, but our additional logic to account for
// window styles isn't.
pub unsafe fn toggle_full_screen_async(
nswindow: id,
nsview: id,
ns_window: id,
ns_view: id,
not_fullscreen: bool,
shared_state: Weak<Mutex<SharedState>>,
) {
let context = ToggleFullScreenData::new_ptr(
nswindow,
nsview,
ns_window,
ns_view,
not_fullscreen,
shared_state,
);
@ -238,11 +238,11 @@ pub unsafe fn toggle_full_screen_async(
}
struct OrderOutData {
nswindow: id,
ns_window: id,
}
impl OrderOutData {
fn new_ptr(nswindow: id) -> *mut Self {
Box::into_raw(Box::new(OrderOutData { nswindow }))
fn new_ptr(ns_window: id) -> *mut Self {
Box::into_raw(Box::new(OrderOutData { ns_window }))
}
}
extern fn order_out_callback(context: *mut c_void) {
@ -250,15 +250,15 @@ extern fn order_out_callback(context: *mut c_void) {
let context_ptr = context as *mut OrderOutData;
{
let context = &*context_ptr;
context.nswindow.orderOut_(nil);
context.ns_window.orderOut_(nil);
}
Box::from_raw(context_ptr);
}
}
// `orderOut:` isn't thread-safe. Calling it from another thread actually works,
// but with an odd delay.
pub unsafe fn order_out_async(nswindow: id) {
let context = OrderOutData::new_ptr(nswindow);
pub unsafe fn order_out_async(ns_window: id) {
let context = OrderOutData::new_ptr(ns_window);
dispatch_async_f(
dispatch_get_main_queue(),
context as *mut _,
@ -267,11 +267,11 @@ pub unsafe fn order_out_async(nswindow: id) {
}
struct MakeKeyAndOrderFrontData {
nswindow: id,
ns_window: id,
}
impl MakeKeyAndOrderFrontData {
fn new_ptr(nswindow: id) -> *mut Self {
Box::into_raw(Box::new(MakeKeyAndOrderFrontData { nswindow }))
fn new_ptr(ns_window: id) -> *mut Self {
Box::into_raw(Box::new(MakeKeyAndOrderFrontData { ns_window }))
}
}
extern fn make_key_and_order_front_callback(context: *mut c_void) {
@ -279,15 +279,15 @@ extern fn make_key_and_order_front_callback(context: *mut c_void) {
let context_ptr = context as *mut MakeKeyAndOrderFrontData;
{
let context = &*context_ptr;
context.nswindow.makeKeyAndOrderFront_(nil);
context.ns_window.makeKeyAndOrderFront_(nil);
}
Box::from_raw(context_ptr);
}
}
// `makeKeyAndOrderFront:` isn't thread-safe. Calling it from another thread
// actually works, but with an odd delay.
pub unsafe fn make_key_and_order_front_async(nswindow: id) {
let context = MakeKeyAndOrderFrontData::new_ptr(nswindow);
pub unsafe fn make_key_and_order_front_async(ns_window: id) {
let context = MakeKeyAndOrderFrontData::new_ptr(ns_window);
dispatch_async_f(
dispatch_get_main_queue(),
context as *mut _,
@ -296,11 +296,11 @@ pub unsafe fn make_key_and_order_front_async(nswindow: id) {
}
struct CloseData {
nswindow: id,
ns_window: id,
}
impl CloseData {
fn new_ptr(nswindow: id) -> *mut Self {
Box::into_raw(Box::new(CloseData { nswindow }))
fn new_ptr(ns_window: id) -> *mut Self {
Box::into_raw(Box::new(CloseData { ns_window }))
}
}
extern fn close_callback(context: *mut c_void) {
@ -309,7 +309,7 @@ extern fn close_callback(context: *mut c_void) {
{
let context = &*context_ptr;
let pool = NSAutoreleasePool::new(nil);
context.nswindow.close();
context.ns_window.close();
pool.drain();
}
Box::from_raw(context_ptr);
@ -317,8 +317,8 @@ extern fn close_callback(context: *mut c_void) {
}
// `close:` is thread-safe, but we want the event to be triggered from the main
// thread. Though, it's a good idea to look into that more...
pub unsafe fn close_async(nswindow: id) {
let context = CloseData::new_ptr(nswindow);
pub unsafe fn close_async(ns_window: id) {
let context = CloseData::new_ptr(ns_window);
dispatch_async_f(
dispatch_get_main_queue(),
context as *mut _,