summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuanma Barranquero <lekktu@gmail.com>2006-12-18 16:47:28 +0000
committerJuanma Barranquero <lekktu@gmail.com>2006-12-18 16:47:28 +0000
commit0e0dced58b185b05445ad288ae2a0578ec1bce96 (patch)
tree1f7299ead99e3f1589ee130db3a961eacaba4c3c
parent3f0c287f1f07f7909179b63d4602df4d7e404676 (diff)
downloademacs-0e0dced58b185b05445ad288ae2a0578ec1bce96.tar.gz
[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 @@
+2006-12-18 Juanma Barranquero <lekktu@gmail.com>
+
+ * emacsclient.c [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.
+
2006-12-15 Juanma Barranquero <lekktu@gmail.com>
* emacsclient.c (w32_execvp): New function; wrapper for `execvp'.
@@ -454,10 +461,9 @@
2005-07-13 Ken Raeburn <raeburn@gnu.org>
- * pop.c: Don't include des.h (or variants thereof); krb.h will do
- it.
- (sendline): Add the \r\n to the line in a temporary buffer, and
- write it all at once.
+ * pop.c: Don't include des.h (or variants thereof); krb.h will do it.
+ (sendline): Add the \r\n to the line in a temporary buffer, and write
+ it all at once.
2005-07-04 Lute Kamstra <lute@gnu.org>
@@ -497,10 +503,9 @@
2005-02-04 Andreas Schwab <schwab@suse.de>
- * movemail.c (fatal): Accept third parameter and pass down to
- error.
- (pfatal_with_name): Pass error string as format parameter instead
- of as part of format string.
+ * movemail.c (fatal): Accept third parameter and pass down to error.
+ (pfatal_with_name): Pass error string as format parameter instead of
+ as part of format string.
(pfatal_and_delete): Likewise.
(main): Adjust call to fatal.
(xmalloc): Likewise.
@@ -511,8 +516,7 @@
2004-12-26 YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
- * make-docfile.c: Include stdlib.h even if WINDOWSNT is not
- defined.
+ * make-docfile.c: Include stdlib.h even if WINDOWSNT is not defined.
2004-12-15 Andreas Schwab <schwab@suse.de>
@@ -578,8 +582,7 @@
2004-05-10 Thien-Thi Nguyen <ttn@gnu.org>
- * test-distrib.c (main): For failing cases, exit with
- `EXIT_FAILURE'.
+ * test-distrib.c (main): For failing cases, exit with `EXIT_FAILURE'.
2004-05-08 Jason Rumney <jasonr@gnu.org>
@@ -752,8 +755,7 @@
2003-04-27 Oliver Scholz <alkibiades@gmx.de>
- * update-game-score.c (read_scores): Fix corruption of scores on
- read.
+ * update-game-score.c (read_scores): Fix corruption of scores on read.
2003-04-12 Stefan Monnier <monnier@cs.yale.edu>
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 ()
/*
* Read the information needed to set up a TCP comm channel with
* the Emacs server: host, port, pid and authentication string.
-*/
+ */
int
get_server_config (server, authentication)
struct sockaddr_in *server;
@@ -845,6 +845,62 @@ set_socket ()
exit (EXIT_FAILURE);
}
+#ifdef WINDOWSNT
+FARPROC set_fg; /* Pointer to AllowSetForegroundWindow. */
+FARPROC get_wc; /* Pointer to RealGetWindowClassA. */
+
+BOOL CALLBACK
+w32_find_emacs_process (hWnd, lParam)
+ HWND hWnd;
+ LPARAM lParam;
+{
+ DWORD pid;
+ char class[6];
+
+ /* Reject any window not of class "Emacs". */
+ if (! get_wc (hWnd, class, sizeof (class))
+ || strcmp (class, "Emacs"))
+ return TRUE;
+
+ /* We only need the process id, not the thread id. */
+ (void) GetWindowThreadProcessId (hWnd, &pid);
+
+ /* Not the one we're looking for. */
+ if (pid != (DWORD) emacs_pid) return TRUE;
+
+ /* OK, let's raise it. */
+ set_fg (emacs_pid);
+
+ /* Stop enumeration. */
+ return FALSE;
+}
+
+/*
+ * Search for a window of class "Emacs" and owned by a process with
+ * process id = emacs_pid. If found, allow it to grab the focus.
+ */
+void
+w32_give_focus ()
+{
+ HMODULE hUser32;
+
+ /* It should'nt happen when dealing with TCP sockets. */
+ if (!emacs_pid) return;
+
+ if (!(hUser32 = LoadLibrary ("user32.dll"))) return;
+
+ /* Modern Windows restrict which processes can set the foreground window.
+ emacsclient can allow Emacs to grab the focus by calling the function
+ AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98 and
+ NT) lack this function, so we have to check its availability. */
+ if ((set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
+ && (get_wc = GetProcAddress (hUser32, "RealGetWindowClassA")))
+ EnumWindows (w32_find_emacs_process, (LPARAM) 0);
+
+ FreeLibrary (hUser32);
+}
+#endif
+
int
main (argc, argv)
int argc;
@@ -889,24 +945,7 @@ main (argc, argv)
}
#ifdef WINDOWSNT
- /*
- Modern Windows restrict which processes can set the foreground window.
- emacsclient can allow Emacs to grab the focus by calling the function
- AllowSetForegroundWindow. Unfortunately, older Windows (W95, W98
- and NT) lack this function, so we have to check its availability.
- */
- if (emacs_pid)
- {
- HMODULE hUser32;
-
- if (hUser32 = LoadLibrary ("user32.dll"))
- {
- FARPROC set_fg;
- if (set_fg = GetProcAddress (hUser32, "AllowSetForegroundWindow"))
- set_fg (emacs_pid);
- FreeLibrary (hUser32);
- }
- }
+ w32_give_focus ();
#endif
if (nowait)