From e579eb5d8438a8156afc833ad1316ed7b28492c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Brzezi=C5=84ski?= Date: Sun, 11 Dec 2022 22:09:54 +0100 Subject: [PATCH] examples/tutorials: Use NSApp terminate() instead of sending an event Has the same effect while being much more concise. Unfortunately the cocoa crate doesn't (yet?) have bindings for this function, so objc::msg_send! had to be used directly. Part-of: --- tutorials/Cargo.toml | 1 + tutorials/src/tutorials-common.rs | 20 ++------------------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/tutorials/Cargo.toml b/tutorials/Cargo.toml index 74f0f707d..3a799079c 100644 --- a/tutorials/Cargo.toml +++ b/tutorials/Cargo.toml @@ -21,6 +21,7 @@ termion = { version = "2", optional = true } [target.'cfg(target_os = "macos")'.dependencies] cocoa = "0.24" +objc = "0.2.7" [features] tutorial5 = ["gtk", "gdk", "gst-video"] diff --git a/tutorials/src/tutorials-common.rs b/tutorials/src/tutorials-common.rs index 889d0c263..76db893d0 100644 --- a/tutorials/src/tutorials-common.rs +++ b/tutorials/src/tutorials-common.rs @@ -18,6 +18,7 @@ where T: Send + 'static, { use cocoa::appkit::NSApplication; + use objc::{msg_send, sel, sel_impl}; use std::thread; @@ -27,24 +28,7 @@ where let res = main(); let app = cocoa::appkit::NSApp(); - app.stop_(cocoa::base::nil); - - // Stopping the event loop requires an actual event - let event = cocoa::appkit::NSEvent::otherEventWithType_location_modifierFlags_timestamp_windowNumber_context_subtype_data1_data2_( - cocoa::base::nil, - cocoa::appkit::NSEventType::NSApplicationDefined, - cocoa::foundation::NSPoint { x: 0.0, y: 0.0 }, - cocoa::appkit::NSEventModifierFlags::empty(), - 0.0, - 0, - cocoa::base::nil, - cocoa::appkit::NSEventSubtype::NSApplicationActivatedEventType, - 0, - 0, - ); - app.postEvent_atStart_(event, cocoa::base::YES); - - std::process::exit(0); + let _: () = msg_send![app, terminate: cocoa::base::nil]; res });