aboutsummaryrefslogtreecommitdiffstats
path: root/src/w32proc.c
diff options
context:
space:
mode:
authorAndrew Innes1999-05-02 10:27:27 +0000
committerAndrew Innes1999-05-02 10:27:27 +0000
commitf446016fdb7f8b85891ea351799e115dad44304e (patch)
treef652a66e03064b9720a2d135321d8d74f969ee11 /src/w32proc.c
parent55dcfc158861268dcc1bb2c524d6612f5aa86192 (diff)
downloademacs-f446016fdb7f8b85891ea351799e115dad44304e.tar.gz
emacs-f446016fdb7f8b85891ea351799e115dad44304e.zip
(sys_kill): Attach to current foreground thread
when grabbing focus; necessary on NT 5.0.
Diffstat (limited to 'src/w32proc.c')
-rw-r--r--src/w32proc.c69
1 files changed, 51 insertions, 18 deletions
diff --git a/src/w32proc.c b/src/w32proc.c
index abc61455594..8fcf3382da9 100644
--- a/src/w32proc.c
+++ b/src/w32proc.c
@@ -1359,25 +1359,58 @@ sys_kill (int pid, int sig)
1359 } 1359 }
1360 1360
1361 foreground_window = GetForegroundWindow (); 1361 foreground_window = GetForegroundWindow ();
1362 if (foreground_window && SetForegroundWindow (cp->hwnd)) 1362 if (foreground_window)
1363 { 1363 {
1364 /* Generate keystrokes as if user had typed Ctrl-Break or 1364 /* NT 5.0, and apparently also Windows 98, will not allow
1365 Ctrl-C. */ 1365 a Window to be set to foreground directly without the
1366 keybd_event (VK_CONTROL, control_scan_code, 0, 0); 1366 user's involvement. The workaround is to attach
1367 keybd_event (vk_break_code, break_scan_code, 1367 ourselves to the thread that owns the foreground
1368 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY), 0); 1368 window, since that is the only thread that can set the
1369 keybd_event (vk_break_code, break_scan_code, 1369 foreground window. */
1370 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY) 1370 DWORD foreground_thread, child_thread;
1371 | KEYEVENTF_KEYUP, 0); 1371 foreground_thread =
1372 keybd_event (VK_CONTROL, control_scan_code, KEYEVENTF_KEYUP, 0); 1372 GetWindowThreadProcessId (foreground_window, NULL);
1373 1373 if (foreground_thread == GetCurrentThreadId ()
1374 /* Sleep for a bit to give time for Emacs frame to respond 1374 || !AttachThreadInput (GetCurrentThreadId (),
1375 to focus change events (if Emacs was active app). */ 1375 foreground_thread, TRUE))
1376 Sleep (10); 1376 foreground_thread = 0;
1377 1377
1378 SetForegroundWindow (foreground_window); 1378 child_thread = GetWindowThreadProcessId (cp->hwnd, NULL);
1379 } 1379 if (child_thread == GetCurrentThreadId ()
1380 } 1380 || !AttachThreadInput (GetCurrentThreadId (),
1381 child_thread, TRUE))
1382 child_thread = 0;
1383
1384 /* Set the foreground window to the child. */
1385 if (SetForegroundWindow (cp->hwnd))
1386 {
1387 /* Generate keystrokes as if user had typed Ctrl-Break or
1388 Ctrl-C. */
1389 keybd_event (VK_CONTROL, control_scan_code, 0, 0);
1390 keybd_event (vk_break_code, break_scan_code,
1391 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY), 0);
1392 keybd_event (vk_break_code, break_scan_code,
1393 (vk_break_code == 'C' ? 0 : KEYEVENTF_EXTENDEDKEY)
1394 | KEYEVENTF_KEYUP, 0);
1395 keybd_event (VK_CONTROL, control_scan_code,
1396 KEYEVENTF_KEYUP, 0);
1397
1398 /* Sleep for a bit to give time for Emacs frame to respond
1399 to focus change events (if Emacs was active app). */
1400 Sleep (100);
1401
1402 SetForegroundWindow (foreground_window);
1403 }
1404 /* Detach from the foreground and child threads now that
1405 the foreground switching is over. */
1406 if (foreground_thread)
1407 AttachThreadInput (GetCurrentThreadId (),
1408 foreground_thread, FALSE);
1409 if (child_thread)
1410 AttachThreadInput (GetCurrentThreadId (),
1411 child_thread, FALSE);
1412 }
1413 }
1381 /* Ctrl-Break is NT equivalent of SIGINT. */ 1414 /* Ctrl-Break is NT equivalent of SIGINT. */
1382 else if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid)) 1415 else if (!GenerateConsoleCtrlEvent (CTRL_BREAK_EVENT, pid))
1383 { 1416 {