mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2024-11-22 01:21:05 +00:00
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer-rs/-/merge_requests/1162>
This commit is contained in:
parent
0fa8d0d62f
commit
e579eb5d84
2 changed files with 3 additions and 18 deletions
|
@ -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"]
|
||||
|
|
|
@ -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
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue