summaryrefslogtreecommitdiff
path: root/ide/ide_win32_stubs.c
diff options
context:
space:
mode:
Diffstat (limited to 'ide/ide_win32_stubs.c')
-rw-r--r--ide/ide_win32_stubs.c44
1 files changed, 21 insertions, 23 deletions
diff --git a/ide/ide_win32_stubs.c b/ide/ide_win32_stubs.c
index c170b1a9..c09bf37d 100644
--- a/ide/ide_win32_stubs.c
+++ b/ide/ide_win32_stubs.c
@@ -19,33 +19,31 @@ CAMLprim value win32_kill(value pseudopid) {
CAMLreturn(Val_unit);
}
-/* Win32 emulation of a kill -2 (SIGINT) */
-/* For simplicity, we signal all processes sharing a console with coqide.
- This shouldn't be an issue since currently at most one coqtop is busy
- at a given time. Earlier, we tried to be more precise via
- FreeConsole and AttachConsole before generating the Ctrl-C, but
- that wasn't working so well (see #2869).
- This code rely now on the fact that coqide is a console app,
- and that coqide itself ignores Ctrl-C.
-*/
+/* Win32 emulation of a kill -2 (SIGINT) */
-CAMLprim value win32_interrupt_all(value unit) {
- CAMLparam1(unit);
- GenerateConsoleCtrlEvent(CTRL_C_EVENT,0);
- CAMLreturn(Val_unit);
-}
+/* This code rely of the fact that coqide is now without initial console.
+ Otherwise, no console creation in win32unix/createprocess.c, hence
+ the same console for coqide and all coqtop, and everybody will be
+ signaled at the same time by the code below. */
-/* Get rid of the nasty console window (only if we created it) */
+/* Moreover, AttachConsole exists only since WinXP, and GetProcessId
+ since WinXP SP1. For avoiding the GetProcessId, we could adapt code
+ from win32unix/createprocess.c to make it return both the pid and the
+ handle. For avoiding the AttachConsole, I don't know, maybe having
+ an intermediate process between coqide and coqtop ? */
-CAMLprim value win32_hide_console (value unit) {
- CAMLparam1(unit);
+CAMLprim value win32_interrupt(value pseudopid) {
+ CAMLparam1(pseudopid);
+ HANDLE h;
DWORD pid;
- HWND hw = GetConsoleWindow();
- if (hw != NULL) {
- GetWindowThreadProcessId(hw, &pid);
- if (pid == GetCurrentProcessId())
- ShowWindow(hw, SW_HIDE);
- }
+ FreeConsole(); /* Normally unnecessary, just to be sure... */
+ h = (HANDLE)(Long_val(pseudopid));
+ pid = GetProcessId(h);
+ AttachConsole(pid);
+ /* We want to survive the Ctrl-C that will also concerns us */
+ SetConsoleCtrlHandler(NULL,TRUE); /* NULL + TRUE means ignore */
+ GenerateConsoleCtrlEvent(CTRL_C_EVENT,0); /* signal our co-console */
+ FreeConsole();
CAMLreturn(Val_unit);
}