Mercurial > emacs
comparison lib-src/emacsclient.c @ 103641:48d529d3a5a4
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).
author | Jason Rumney <jasonr@gnu.org> |
---|---|
date | Tue, 30 Jun 2009 15:48:23 +0000 |
parents | 9265a8db20b3 |
children | 7bad97f82eb6 |
comparison
equal
deleted
inserted
replaced
103640:fd001b102e15 | 103641:48d529d3a5a4 |
---|---|
388 } | 388 } |
389 | 389 |
390 /* Not the right type, or not correctly expanded. */ | 390 /* Not the right type, or not correctly expanded. */ |
391 free (value); | 391 free (value); |
392 return NULL; | 392 return NULL; |
393 } | |
394 | |
395 void | |
396 w32_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 } | |
393 } | 420 } |
394 | 421 |
395 int | 422 int |
396 w32_window_app () | 423 w32_window_app () |
397 { | 424 { |
1413 * process id = emacs_pid. If found, allow it to grab the focus. | 1440 * process id = emacs_pid. If found, allow it to grab the focus. |
1414 */ | 1441 */ |
1415 void | 1442 void |
1416 w32_give_focus () | 1443 w32_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 |
1437 /* Start the emacs daemon and try to connect to it. */ | 1465 /* Start the emacs daemon and try to connect to it. */ |
1438 | 1466 |
1498 char string[BUFSIZ+1]; | 1526 char string[BUFSIZ+1]; |
1499 int null_socket_name, null_server_file, start_daemon_if_needed; | 1527 int null_socket_name, null_server_file, start_daemon_if_needed; |
1500 | 1528 |
1501 main_argv = argv; | 1529 main_argv = argv; |
1502 progname = argv[0]; | 1530 progname = argv[0]; |
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 | |
1503 | 1537 |
1504 /* Process options. */ | 1538 /* Process options. */ |
1505 decode_options (argc, argv); | 1539 decode_options (argc, argv); |
1506 | 1540 |
1507 if ((argc - optind < 1) && !eval && current_frame) | 1541 if ((argc - optind < 1) && !eval && current_frame) |