aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src/emacsclient.c
diff options
context:
space:
mode:
authorJason Rumney2009-06-30 15:48:23 +0000
committerJason Rumney2009-06-30 15:48:23 +0000
commitff90fbdecc6ffb1e34fe5ee9c1f080106c0739df (patch)
tree220a6ca0665b2ed33868247c02949704fa510335 /lib-src/emacsclient.c
parent974647ac913e1280e7142321a19e3b7eaabefc25 (diff)
downloademacs-ff90fbdecc6ffb1e34fe5ee9c1f080106c0739df.tar.gz
emacs-ff90fbdecc6ffb1e34fe5ee9c1f080106c0739df.zip
bug#1849 - Windows 7 Taskbar Support
* w32term.c (w32_initialize): Use GetModuleHandle for library that is already loaded. Set user model ID if supported (bug#1849). * runemacs.c (set_user_model_id): New function. (WinMain): Use it. * emacsclient.c (w32_give_focus): Use GetModuleHandle for library that is already loaded. (w32_set_user_model_id): New function. (main): Use it to associate emacsclient with emacs (bug#1849).
Diffstat (limited to 'lib-src/emacsclient.c')
-rw-r--r--lib-src/emacsclient.c46
1 files changed, 40 insertions, 6 deletions
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index a451c1b9ba4..5e6db54a902 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -392,6 +392,33 @@ w32_getenv (envvar)
392 return NULL; 392 return NULL;
393} 393}
394 394
395void
396w32_set_user_model_id ()
397{
398 HMODULE shell;
399 HRESULT (WINAPI * set_user_model) (PWCSTR);
400
401 /* On Windows 7 and later, we need to set the user model ID
402 to associate emacsclient launched files with Emacs frames
403 in the UI. */
404 shell = LoadLibrary("shell32.dll");
405 if (shell)
406 {
407 set_user_model
408 = (void *) GetProcAddress (shell,
409 "SetCurrentProcessExplicitAppUserModelID");
410 /* If the function is defined, then we are running on Windows 7
411 or newer, and the UI uses this to group related windows
412 together. Since emacs, runemacs, emacsclient are related, we
413 want them grouped even though the executables are different,
414 so we need to set a consistent ID between them. */
415 if (set_user_model)
416 set_user_model (L"GNU.Emacs");
417
418 FreeLibrary (shell);
419 }
420}
421
395int 422int
396w32_window_app () 423w32_window_app ()
397{ 424{
@@ -1415,22 +1442,23 @@ w32_find_emacs_process (hWnd, lParam)
1415void 1442void
1416w32_give_focus () 1443w32_give_focus ()
1417{ 1444{
1418 HMODULE hUser32; 1445 HANDLE user32;
1419 1446
1420 /* It shouldn't happen when dealing with TCP sockets. */ 1447 /* It shouldn't happen when dealing with TCP sockets. */
1421 if (!emacs_pid) return; 1448 if (!emacs_pid) return;
1422 1449
1423 if (!(hUser32 = LoadLibrary ("user32.dll"))) return; 1450 user32 = GetModuleHandle ("user32.dll");
1451
1452 if (!user32)
1453 return;
1424 1454
1425 /* Modern Windows restrict which processes can set the foreground window. 1455 /* Modern Windows restrict which processes can set the foreground window.
1426 emacsclient can allow Emacs to grab the focus by calling the function 1456 emacsclient can allow Emacs to grab the focus by calling the function
1427 AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98 and 1457 AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98 and
1428 NT) lack this function, so we have to check its availability. */ 1458 NT) lack this function, so we have to check its availability. */
1429 if ((set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow")) 1459 if ((set_fg = GetProcAddress (user32, "AllowSetForegroundWindow"))
1430 && (get_wc = GetProcAddress (hUser32, "RealGetWindowClassA"))) 1460 && (get_wc = GetProcAddress (user32, "RealGetWindowClassA")))
1431 EnumWindows (w32_find_emacs_process, (LPARAM) 0); 1461 EnumWindows (w32_find_emacs_process, (LPARAM) 0);
1432
1433 FreeLibrary (hUser32);
1434} 1462}
1435#endif 1463#endif
1436 1464
@@ -1501,6 +1529,12 @@ main (argc, argv)
1501 main_argv = argv; 1529 main_argv = argv;
1502 progname = argv[0]; 1530 progname = argv[0];
1503 1531
1532#ifdef WINDOWSNT
1533 /* On Windows 7 and later, we need to explicitly associate emacsclient
1534 with emacs so the UI behaves sensibly. */
1535 w32_set_user_model_id ();
1536#endif
1537
1504 /* Process options. */ 1538 /* Process options. */
1505 decode_options (argc, argv); 1539 decode_options (argc, argv);
1506 1540