From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#11513: 24.1.50; raise-frame never raise the foreground window on Windows Date: Mon, 28 May 2012 20:28:13 +0300 Message-ID: <83fwak1ahe.fsf@gnu.org> References: <20120518210617.D4D181E0043@msa101.auone-net.jp> <83obpkzjhs.fsf@gnu.org> <20120519120231.7181D2C037@msa104.auone-net.jp> <83havcz6i6.fsf@gnu.org> <4FB79899.8040408@gmx.at> <83sjetxs9d.fsf@gnu.org> <20120523104906.CAA5A34803A@msa103.auone-net.jp> <83aa0yyil2.fsf@gnu.org> <20120524060731.184722C037@msa104.auone-net.jp> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1338226139 14540 80.91.229.3 (28 May 2012 17:28:59 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 28 May 2012 17:28:59 +0000 (UTC) Cc: 11513-done@debbugs.gnu.org To: Kazuhiro Ito Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 28 19:28:58 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SZ3kY-0004uO-1p for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 May 2012 19:28:58 +0200 Original-Received: from localhost ([::1]:35733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZ3kX-00011b-Pp for geb-bug-gnu-emacs@m.gmane.org; Mon, 28 May 2012 13:28:57 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:52786) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZ3kQ-0000v2-Tw for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 13:28:55 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SZ3kK-0006Ol-Bf for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 13:28:50 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:37316) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SZ3kK-0006OA-4T for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 13:28:44 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SZ3la-00037d-61 for bug-gnu-emacs@gnu.org; Mon, 28 May 2012 13:30:02 -0400 Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Mon, 28 May 2012 17:30:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 11513 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 11513@debbugs.gnu.org, eliz@gnu.org Original-Received: via spool by 11513-done@debbugs.gnu.org id=D11513.133822619611962 (code D ref 11513); Mon, 28 May 2012 17:30:01 +0000 Original-Received: (at 11513-done) by debbugs.gnu.org; 28 May 2012 17:29:56 +0000 Original-Received: from localhost ([127.0.0.1]:46861 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SZ3lT-00036t-W1 for submit@debbugs.gnu.org; Mon, 28 May 2012 13:29:56 -0400 Original-Received: from mtaout20.012.net.il ([80.179.55.166]:60457) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SZ3l8-00036N-QF for 11513-done@debbugs.gnu.org; Mon, 28 May 2012 13:29:54 -0400 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0M4Q00A00TT7NQ00@a-mtaout20.012.net.il> for 11513-done@debbugs.gnu.org; Mon, 28 May 2012 20:28:10 +0300 (IDT) Original-Received: from HOME-C4E4A596F7 ([87.69.210.75]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0M4Q0091ITUXL5I0@a-mtaout20.012.net.il>; Mon, 28 May 2012 20:28:09 +0300 (IDT) In-reply-to: <20120524060731.184722C037@msa104.auone-net.jp> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:60424 Archived-At: > Date: Thu, 24 May 2012 15:04:59 +0900 > From: Kazuhiro Ito > Cc: rudalics@gmx.at, 11513@debbugs.gnu.org, drew.adams@oracle.com > > > > raise-frame always make the unexpected result when Emacs frame is > > > the foreground window (I mean Emacs frame is colored as active window) > > > and behind of other application window(s). And, as I described > > > previously, If Emacs frame is not the foreground window raise-frame > > > correctly works. > > > > But the default behavior on Windows is that a window that is lowered > > loses its focus. You need to click into it to get focus there. So > > how come a lowered window still has focus for you? > > When I run lower-frame function in Emacs frame interactively, Emacs > frame is brought behind of other application window(s) but has focus. > Key inputs are passed to lowered frame. I tested 4 Windows PC, and > all PCs show the same behavior. Sorry, I was confused. You are right, the focus isn't lost. Anyway, I don't think it is a good idea to modify the reaction to the WM_EMACS_SETFOREGROUND message, because it is also used by x-focus-frame, which is not supposed to raise the frame to the top of the Z-order, unless it is strictly necessary. And if the frame is already a foreground frame, raising it isn't necessary. So instead I introduced a new message, WM_EMACS_BRINGTOTOP, and used that in raise-frame. The diffs are below (installed as revision 108409 on the trunk). Thanks. I'm closing this bug report. === modified file 'src/ChangeLog' --- src/ChangeLog 2012-05-28 07:13:45 +0000 +++ src/ChangeLog 2012-05-28 17:22:40 +0000 @@ -1,3 +1,17 @@ +2012-05-28 Eli Zaretskii + + * w32term.c (my_bring_window_to_top): New function. + (x_raise_frame): Use handle returned by DeferWindowPos, which + could be different from the original one. Call + my_bring_window_to_top instead of my_set_foreground_window. + (Bug#11513) + + * w32fns.c (w32_wnd_proc): Accept and process WM_EMACS_BRINGTOTOP + by calling BringWindowToTop. + + * w32term.h (WM_EMACS_BRINGTOTOP): New message. + (WM_EMACS_END): Increase by one. + 2012-05-28 Paul Eggert * bidi.c (bidi_mirror_char): Put eassert before conversion to int. === modified file 'src/w32fns.c' --- src/w32fns.c 2012-05-25 18:19:24 +0000 +++ src/w32fns.c 2012-05-28 17:22:40 +0000 @@ -3663,6 +3663,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARA case WM_EMACS_SHOWWINDOW: return ShowWindow ((HWND) wParam, (WPARAM) lParam); + case WM_EMACS_BRINGTOTOP: case WM_EMACS_SETFOREGROUND: { HWND foreground_window; @@ -3680,6 +3681,8 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARA foreground_thread = 0; retval = SetForegroundWindow ((HWND) wParam); + if (msg == WM_EMACS_BRINGTOTOP) + retval = BringWindowToTop ((HWND) wParam); /* Detach from the previous foreground thread. */ if (foreground_thread) === modified file 'src/w32term.c' --- src/w32term.c 2012-05-18 08:36:50 +0000 +++ src/w32term.c 2012-05-28 17:22:40 +0000 @@ -3492,6 +3492,12 @@ my_destroy_window (struct frame * f, HWN (WPARAM) hwnd, 0); } +static void +my_bring_window_to_top (HWND hwnd) +{ + SendMessage (hwnd, WM_EMACS_BRINGTOTOP, (WPARAM) hwnd, 0); +} + /* Create a scroll bar and return the scroll bar vector for it. W is the Emacs window on which to create the scroll bar. TOP, LEFT, WIDTH and HEIGHT are the pixel coordinates and dimensions of the @@ -5600,24 +5606,27 @@ x_raise_frame (struct frame *f) HDWP handle = BeginDeferWindowPos (2); if (handle) { - DeferWindowPos (handle, - FRAME_W32_WINDOW (f), - HWND_TOP, - 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); - - DeferWindowPos (handle, - GetForegroundWindow (), - FRAME_W32_WINDOW (f), - 0, 0, 0, 0, - SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); - - EndDeferWindowPos (handle); + handle = DeferWindowPos (handle, + FRAME_W32_WINDOW (f), + HWND_TOP, + 0, 0, 0, 0, + SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE); + if (handle) + { + handle = DeferWindowPos (handle, + GetForegroundWindow (), + FRAME_W32_WINDOW (f), + 0, 0, 0, 0, + SWP_NOSIZE | SWP_NOMOVE | + SWP_NOACTIVATE); + if (handle) + EndDeferWindowPos (handle); + } } } else { - my_set_foreground_window (FRAME_W32_WINDOW (f)); + my_bring_window_to_top (FRAME_W32_WINDOW (f)); } UNBLOCK_INPUT; === modified file 'src/w32term.h' --- src/w32term.h 2012-01-19 07:21:25 +0000 +++ src/w32term.h 2012-05-28 17:22:40 +0000 @@ -576,7 +576,8 @@ do { \ #define WM_EMACS_HIDE_CARET (WM_EMACS_START + 18) #define WM_EMACS_SETCURSOR (WM_EMACS_START + 19) #define WM_EMACS_PAINT (WM_EMACS_START + 20) -#define WM_EMACS_END (WM_EMACS_START + 21) +#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 21) +#define WM_EMACS_END (WM_EMACS_START + 22) #define WND_FONTWIDTH_INDEX (0) #define WND_LINEHEIGHT_INDEX (4)