]> git.lyx.org Git - features.git/commitdiff
Move OS specific code to proper place. Also make sure that no other
authorEnrico Forestieri <forenr@lyx.org>
Fri, 14 Aug 2009 00:42:45 +0000 (00:42 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Fri, 14 Aug 2009 00:42:45 +0000 (00:42 +0000)
handler functions are called after processing shutdown events.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@31027 a592a061-630c-0410-9148-cb99ea01b6c8

src/LyX.cpp
src/support/os_cygwin.cpp
src/support/os_win32.cpp

index b7a409fedb4bad911fde2e801ffcddb488906c12..e2e5b0c925a9ab378eafcebc947449a845c0a93a 100644 (file)
@@ -71,9 +71,6 @@
 #include <stdlib.h>
 #include <string>
 #include <vector>
-#if defined(_WIN32) || defined(__CYGWIN__)
-#include <windows.h>
-#endif
 
 using namespace std;
 using namespace lyx::support;
@@ -653,18 +650,6 @@ static void error_handler(int err_sig)
        exit(0);
 }
 
-
-#if defined(_WIN32) || defined(__CYGWIN__)
-BOOL terminate_handler(DWORD event)
-{
-       if (event == CTRL_CLOSE_EVENT
-           || event == CTRL_LOGOFF_EVENT
-           || event == CTRL_SHUTDOWN_EVENT)
-               raise(SIGTERM);
-       return FALSE;
-}
-#endif
-
 }
 
 
@@ -686,10 +671,6 @@ bool LyX::init()
        signal(SIGINT, error_handler);
        signal(SIGTERM, error_handler);
        // SIGPIPE can be safely ignored.
-#if defined(_WIN32) || defined(__CYGWIN__)
-       // On Windows we have also to catch logging off or closing the console.
-       SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE);
-#endif
 
        lyxrc.tempdir_path = package().temp_dir().absFilename();
        lyxrc.document_path = package().document_dir().absFilename();
index 8ffaef55e4cd69ae9e62b9fa17f0a0d9f0008a20..e0343f63dba4120424f0706302f05719f4f5f43b 100644 (file)
@@ -123,15 +123,31 @@ string convert_path_list(string const & p, PathStyle const & target)
        return subst(p, '\\', '/');
 }
 
+
+BOOL terminate_handler(DWORD event)
+{
+       if (event == CTRL_CLOSE_EVENT
+           || event == CTRL_LOGOFF_EVENT
+           || event == CTRL_SHUTDOWN_EVENT) {
+               ::raise(SIGTERM);
+               // Relinquish our time slice.
+               sleep(0);
+               return TRUE;
+       }
+       return FALSE;
+}
+
 } // namespace anon
 
 void init(int, char *[])
 {
        // Make sure that the TEMP variable is set
        // and sync the Windows environment.
-
        setenv("TEMP", "/tmp", false);
        cygwin_internal(CW_SYNC_WINENV);
+
+       // Catch shutdown events.
+       SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE);
 }
 
 
index 018b5edd6e31f905bb7800471e07a7037e99396b..b450bf1100553040659989ca325a4cf5b1873292 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "support/lassert.h"
 
+#include <csignal>
 #include <cstdlib>
 #include <vector>
 
@@ -80,6 +81,19 @@ bool windows_style_tex_paths_ = true;
 
 string cygdrive = "/cygdrive";
 
+BOOL terminate_handler(DWORD event)
+{
+       if (event == CTRL_CLOSE_EVENT
+           || event == CTRL_LOGOFF_EVENT
+           || event == CTRL_SHUTDOWN_EVENT) {
+               ::raise(SIGTERM);
+               // Relinquish our time slice.
+               Sleep(0);
+               return TRUE;
+       }
+       return FALSE;
+}
+
 } // namespace anon
 
 void init(int /* argc */, char * argv[])
@@ -161,6 +175,9 @@ void init(int /* argc */, char * argv[])
                if ((retVal == ERROR_SUCCESS) && (bufSize <= MAX_PATH))
                        cygdrive = rtrim(string(buf), "/");
        }
+
+       // Catch shutdown events.
+       SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE);
 }