mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer-rs.git
synced 2025-02-18 03:55:36 +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]
|
[target.'cfg(target_os = "macos")'.dependencies]
|
||||||
cocoa = "0.24"
|
cocoa = "0.24"
|
||||||
|
objc = "0.2.7"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tutorial5 = ["gtk", "gdk", "gst-video"]
|
tutorial5 = ["gtk", "gdk", "gst-video"]
|
||||||
|
|
|
@ -18,6 +18,7 @@ where
|
||||||
T: Send + 'static,
|
T: Send + 'static,
|
||||||
{
|
{
|
||||||
use cocoa::appkit::NSApplication;
|
use cocoa::appkit::NSApplication;
|
||||||
|
use objc::{msg_send, sel, sel_impl};
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
|
|
||||||
|
@ -27,24 +28,7 @@ where
|
||||||
let res = main();
|
let res = main();
|
||||||
|
|
||||||
let app = cocoa::appkit::NSApp();
|
let app = cocoa::appkit::NSApp();
|
||||||
app.stop_(cocoa::base::nil);
|
let _: () = msg_send![app, terminate: 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);
|
|
||||||
|
|
||||||
res
|
res
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue