]> git.sesse.net Git - vlc/commitdiff
macosx: implement libvlc exit handler to properly terminate the app when requested
authorDavid Fuhrmann <david.fuhrmann@googlemail.com>
Sun, 2 Feb 2014 17:18:07 +0000 (18:18 +0100)
committerDavid Fuhrmann <david.fuhrmann@googlemail.com>
Mon, 3 Feb 2014 13:57:43 +0000 (14:57 +0100)
This is the only supported way to terminate an cocoa application and also ensure
that the gui settings are getting saved. Adapted from similar code in the qt
module.

bin/darwinvlc.c
modules/gui/macosx/intf.m

index 7b2db9d22b350a51ef80d454ceccf30ce5365841..40bd98380aa4255e73ca31c953ef5f0361d42a8a 100644 (file)
@@ -55,12 +55,6 @@ static bool signal_ignored (int signum)
             ? (void *)sa.sa_sigaction : (void *)sa.sa_handler) == SIG_IGN;
 }
 
-static void vlc_kill (void *data)
-{
-    pthread_t *ps = data;
-    pthread_kill (*ps, SIGTERM);
-}
-
 static void exit_timeout (int signum)
 {
     (void) signum;
@@ -148,7 +142,6 @@ int main( int i_argc, const char *ppsz_argv[] )
     sigaddset (&set, SIGCHLD);
 
     /* Block all these signals */
-    pthread_t self = pthread_self ();
     pthread_sigmask (SIG_SETMASK, &set, NULL);
 
     const char *argv[i_argc + 3];
@@ -217,7 +210,6 @@ int main( int i_argc, const char *ppsz_argv[] )
         return 1;
 
     int ret = 1;
-    libvlc_set_exit_handler (vlc, vlc_kill, &self);
     libvlc_set_app_id (vlc, "org.VideoLAN.VLC", PACKAGE_VERSION, PACKAGE_NAME);
     libvlc_set_user_agent (vlc, "VLC media player", "VLC/"PACKAGE_VERSION);
 
index bd4ae5e1f9f4bd909c462ae8247dae97a85dc069..a84424323f031cd45ca90b3cb625ec8cedee4953 100644 (file)
@@ -283,6 +283,13 @@ void WindowClose(vout_window_t *p_wnd)
     [o_pool release];
 }
 
+/* Used to abort the app.exec() on OSX after libvlc_Quit is called */
+#include "../../../lib/libvlc_internal.h" /* libvlc_SetExitHandler */
+static void QuitVLC( void *obj )
+{
+    [[VLCApplication sharedApplication] performSelectorOnMainThread:@selector(terminate:) withObject:nil waitUntilDone:NO];
+}
+
 /*****************************************************************************
  * Run: main loop
  *****************************************************************************/
@@ -298,6 +305,8 @@ static void Run(intf_thread_t *p_intf)
     o_plItemChangedLock = [[NSLock alloc] init];
     o_vout_provider_lock = [[NSLock alloc] init];
 
+    libvlc_SetExitHandler(p_intf->p_libvlc, QuitVLC, p_intf);
+
     [[VLCMain sharedInstance] setIntf: p_intf];
 
     [NSBundle loadNibNamed: @"MainMenu" owner: NSApp];