Subject: bug#17408: 24.4.50; tooltips make ms-window go top

From: Jarek Czekalski <[email-masked]>
Date: Tue, 06 May 2014 16:46:37 +0200

Actually a complete solution was even easier. First I noticed that a 
Java app I use (muCommander) also retreats from displaying tooltips when 
the app is inactive. Then a Google search gave me this JDK bug report 
[1]. And once the SWP_NOOWNERZORDER flag was mentioned, the rest was a 
walk in a park.

Double checking what flags others use for their tooltips revealed 
nothing more, see this for example [3].

Attaching a patch that applies this flag to our tooltip SetWindowPos [2] 
invocations, in w32fns.c. Works for me. Tested on trunk and emacs24.

If you agree, I might commit this to emacs24.

Jarek

[1] http://bugs.java.com/view_bug.do?bug_id=6770457
[2] 
http://msdn.microsoft.com/en-us/library/windows/desktop/ms633545%28v=vs.85%29.aspx
[3] http://www.vtdev.com/net/tooltip.html

=== modified file 'src/ChangeLog'
--- src/ChangeLog	2014-05-05 17:37:43 +0000
+++ src/ChangeLog	2014-05-06 13:59:45 +0000
@@ -1,3 +1,9 @@
+2014-05-06  Jarek Czekalski  <[email-masked]>
+
+	Stop tooltips pulling Emacs window to front (Bug#17408).
+	* w32fns.c (Fx_show_tip): Add SWP_NOOWNERZORDER flag to
+	SetWindowPos invocations.
+
 2014-05-05  Jan DjĂ¤rv  <[email-masked]>
 
 	* nsselect.m (Fx_selection_exists_p): Just return Qnil if window system

=== modified file 'src/w32fns.c'
--- src/w32fns.c	2014-03-21 09:23:22 +0000
+++ src/w32fns.c	2014-05-06 13:50:02 +0000
@@ -5984,6 +5984,7 @@
   struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
   int old_windows_or_buffers_changed = windows_or_buffers_changed;
   ptrdiff_t count = SPECPDL_INDEX ();
+  #define SWP_EMACS_TOOLTIP (SWP_NOACTIVATE | SWP_NOOWNERZORDER)
 
   specbind (Qinhibit_redisplay, Qt);
 
@@ -6036,12 +6037,12 @@
 	  /* Put tooltip in topmost group and in position.  */
 	  SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST,
 			root_x, root_y, 0, 0,
-			SWP_NOSIZE | SWP_NOACTIVATE);
+			SWP_NOSIZE | SWP_EMACS_TOOLTIP);
 
 	  /* Ensure tooltip is on top of other topmost windows (eg menus).  */
 	  SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP,
 			0, 0, 0, 0,
-			SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+			SWP_NOMOVE | SWP_NOSIZE | SWP_EMACS_TOOLTIP);
 
 	  unblock_input ();
 	  goto start_timer;
@@ -6239,12 +6240,12 @@
     SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOPMOST,
 		  root_x, root_y,
 		  rect.right - rect.left + FRAME_COLUMN_WIDTH (f),
-		  rect.bottom - rect.top, SWP_NOACTIVATE);
+		  rect.bottom - rect.top, SWP_EMACS_TOOLTIP);
 
     /* Ensure tooltip is on top of other topmost windows (eg menus).  */
     SetWindowPos (FRAME_W32_WINDOW (f), HWND_TOP,
 		  0, 0, 0, 0,
-		  SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
+		  SWP_NOMOVE | SWP_NOSIZE | SWP_EMACS_TOOLTIP);
 
     /* Let redisplay know that we have made the frame visible already.  */
     SET_FRAME_VISIBLE (f, 1);