aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJuanma Barranquero2006-12-18 16:47:28 +0000
committerJuanma Barranquero2006-12-18 16:47:28 +0000
commit0e0dced58b185b05445ad288ae2a0578ec1bce96 (patch)
tree1f7299ead99e3f1589ee130db3a961eacaba4c3c
parent3f0c287f1f07f7909179b63d4602df4d7e404676 (diff)
downloademacs-0e0dced58b185b05445ad288ae2a0578ec1bce96.tar.gz
emacs-0e0dced58b185b05445ad288ae2a0578ec1bce96.zip
[WINDOWSNT] (set_fg, get_wc): New variables.
[WINDOWSNT] (w32_find_emacs_process, w32_give_focus): New functions. (main) [WINDOWSNT]: Remove code to release the focus; call w32_give_focus instead.
-rw-r--r--lib-src/ChangeLog30
-rw-r--r--lib-src/emacsclient.c77
2 files changed, 74 insertions, 33 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index f15644050d9..9c8a69f27f1 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,10 @@
12006-12-18 Juanma Barranquero <lekktu@gmail.com>
2
3 * emacsclient.c [WINDOWSNT] (set_fg, get_wc): New variables.
4 [WINDOWSNT] (w32_find_emacs_process, w32_give_focus): New functions.
5 (main) [WINDOWSNT]: Remove code to release the focus; call
6 w32_give_focus instead.
7
12006-12-15 Juanma Barranquero <lekktu@gmail.com> 82006-12-15 Juanma Barranquero <lekktu@gmail.com>
2 9
3 * emacsclient.c (w32_execvp): New function; wrapper for `execvp'. 10 * emacsclient.c (w32_execvp): New function; wrapper for `execvp'.
@@ -454,10 +461,9 @@
454 461
4552005-07-13 Ken Raeburn <raeburn@gnu.org> 4622005-07-13 Ken Raeburn <raeburn@gnu.org>
456 463
457 * pop.c: Don't include des.h (or variants thereof); krb.h will do 464 * pop.c: Don't include des.h (or variants thereof); krb.h will do it.
458 it. 465 (sendline): Add the \r\n to the line in a temporary buffer, and write
459 (sendline): Add the \r\n to the line in a temporary buffer, and 466 it all at once.
460 write it all at once.
461 467
4622005-07-04 Lute Kamstra <lute@gnu.org> 4682005-07-04 Lute Kamstra <lute@gnu.org>
463 469
@@ -497,10 +503,9 @@
497 503
4982005-02-04 Andreas Schwab <schwab@suse.de> 5042005-02-04 Andreas Schwab <schwab@suse.de>
499 505
500 * movemail.c (fatal): Accept third parameter and pass down to 506 * movemail.c (fatal): Accept third parameter and pass down to error.
501 error. 507 (pfatal_with_name): Pass error string as format parameter instead of
502 (pfatal_with_name): Pass error string as format parameter instead 508 as part of format string.
503 of as part of format string.
504 (pfatal_and_delete): Likewise. 509 (pfatal_and_delete): Likewise.
505 (main): Adjust call to fatal. 510 (main): Adjust call to fatal.
506 (xmalloc): Likewise. 511 (xmalloc): Likewise.
@@ -511,8 +516,7 @@
511 516
5122004-12-26 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> 5172004-12-26 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
513 518
514 * make-docfile.c: Include stdlib.h even if WINDOWSNT is not 519 * make-docfile.c: Include stdlib.h even if WINDOWSNT is not defined.
515 defined.
516 520
5172004-12-15 Andreas Schwab <schwab@suse.de> 5212004-12-15 Andreas Schwab <schwab@suse.de>
518 522
@@ -578,8 +582,7 @@
578 582
5792004-05-10 Thien-Thi Nguyen <ttn@gnu.org> 5832004-05-10 Thien-Thi Nguyen <ttn@gnu.org>
580 584
581 * test-distrib.c (main): For failing cases, exit with 585 * test-distrib.c (main): For failing cases, exit with `EXIT_FAILURE'.
582 `EXIT_FAILURE'.
583 586
5842004-05-08 Jason Rumney <jasonr@gnu.org> 5872004-05-08 Jason Rumney <jasonr@gnu.org>
585 588
@@ -752,8 +755,7 @@
752 755
7532003-04-27 Oliver Scholz <alkibiades@gmx.de> 7562003-04-27 Oliver Scholz <alkibiades@gmx.de>
754 757
755 * update-game-score.c (read_scores): Fix corruption of scores on 758 * update-game-score.c (read_scores): Fix corruption of scores on read.
756 read.
757 759
7582003-04-12 Stefan Monnier <monnier@cs.yale.edu> 7602003-04-12 Stefan Monnier <monnier@cs.yale.edu>
759 761
diff --git a/lib-src/emacsclient.c b/lib-src/emacsclient.c
index bbd6cbe239b..419cdd94b88 100644
--- a/lib-src/emacsclient.c
+++ b/lib-src/emacsclient.c
@@ -523,7 +523,7 @@ initialize_sockets ()
523/* 523/*
524 * Read the information needed to set up a TCP comm channel with 524 * Read the information needed to set up a TCP comm channel with
525 * the Emacs server: host, port, pid and authentication string. 525 * the Emacs server: host, port, pid and authentication string.
526*/ 526 */
527int 527int
528get_server_config (server, authentication) 528get_server_config (server, authentication)
529 struct sockaddr_in *server; 529 struct sockaddr_in *server;
@@ -845,6 +845,62 @@ set_socket ()
845 exit (EXIT_FAILURE); 845 exit (EXIT_FAILURE);
846} 846}
847 847
848#ifdef WINDOWSNT
849FARPROC set_fg; /* Pointer to AllowSetForegroundWindow. */
850FARPROC get_wc; /* Pointer to RealGetWindowClassA. */
851
852BOOL CALLBACK
853w32_find_emacs_process (hWnd, lParam)
854 HWND hWnd;
855 LPARAM lParam;
856{
857 DWORD pid;
858 char class[6];
859
860 /* Reject any window not of class "Emacs". */
861 if (! get_wc (hWnd, class, sizeof (class))
862 || strcmp (class, "Emacs"))
863 return TRUE;
864
865 /* We only need the process id, not the thread id. */
866 (void) GetWindowThreadProcessId (hWnd, &pid);
867
868 /* Not the one we're looking for. */
869 if (pid != (DWORD) emacs_pid) return TRUE;
870
871 /* OK, let's raise it. */
872 set_fg (emacs_pid);
873
874 /* Stop enumeration. */
875 return FALSE;
876}
877
878/*
879 * Search for a window of class "Emacs" and owned by a process with
880 * process id = emacs_pid. If found, allow it to grab the focus.
881 */
882void
883w32_give_focus ()
884{
885 HMODULE hUser32;
886
887 /* It should'nt happen when dealing with TCP sockets. */
888 if (!emacs_pid) return;
889
890 if (!(hUser32 = LoadLibrary ("user32.dll"))) return;
891
892 /* Modern Windows restrict which processes can set the foreground window.
893 emacsclient can allow Emacs to grab the focus by calling the function
894 AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98 and
895 NT) lack this function, so we have to check its availability. */
896 if ((set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
897 && (get_wc = GetProcAddress (hUser32, "RealGetWindowClassA")))
898 EnumWindows (w32_find_emacs_process, (LPARAM) 0);
899
900 FreeLibrary (hUser32);
901}
902#endif
903
848int 904int
849main (argc, argv) 905main (argc, argv)
850 int argc; 906 int argc;
@@ -889,24 +945,7 @@ main (argc, argv)
889 } 945 }
890 946
891#ifdef WINDOWSNT 947#ifdef WINDOWSNT
892 /* 948 w32_give_focus ();
893 Modern Windows restrict which processes can set the foreground window.
894 emacsclient can allow Emacs to grab the focus by calling the function
895 AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98
896 and NT) lack this function, so we have to check its availability.
897 */
898 if (emacs_pid)
899 {
900 HMODULE hUser32;
901
902 if (hUser32 = LoadLibrary ("user32.dll"))
903 {
904 FARPROC set_fg;
905 if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
906 set_fg (emacs_pid);
907 FreeLibrary (hUser32);
908 }
909 }
910#endif 949#endif
911 950
912 if (nowait) 951 if (nowait)