unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Helmut Eller <eller.helmut@gmail.com>
To: martin rudalics <rudalics@gmx.at>
Cc: 745@emacsbugs.donarmstrong.com
Subject: bug#745: pop-to-buffer, frames, and input focus
Date: Sat, 23 Aug 2008 10:55:04 +0200	[thread overview]
Message-ID: <m2abf4qffb.fsf@gmail.com> (raw)
In-Reply-To: <48AEEBB8.50201@gmx.at> (martin rudalics's message of "Fri, 22 Aug 2008 18:39:20 +0200")

[-- Attachment #1: Type: text/plain, Size: 4821 bytes --]

* martin rudalics [2008-08-22 18:39+0200] writes:

>>>> pop-to-buffer doesn't switch input focus with: Sawfish, kwin,
>>>> metacity, fluxbox, twm.
>>>> It does with icewm.
>>>>
>>>> display-buffer seems to switch focus with: Sawfish, kwin, fluxbox,
>>>> icewm, twm.
>>> You probably mean display-buffer does _not_ switch focus with these.
>>
>> I meant to say: display-buffer _does_ switch focus when creating a new
>> frame with those window managers: Sawfish, kwin, fluxbox, icewm, twm.
>
> I still don't understand.  Simplistically spoken, `pop-to-buffer' is
> `display-buffer' + `select-window'.  How can, using Sawfish say,
> `display-buffer' switch focus and `pop-to-buffer' not switch focus?

Sorry, that was indeed confusing.
The problematic cases are

  (let ((pop-up-frames t)) (display-buffer ...)) 

for display-buffer, if the buffer was not visible before.  In this case
a new frame appears, which (wrongly) has the input focus.  (If the
buffer is already visible in some frame, that frame is raised but the
focus is not moved to that frame.  This is IMO correct.)

For pop-to-buffer:

  (let ((display-buffer-reuse-frames t)) (pop-to-buffer ...))

if the buffer is already visible in a frame which has not the input
focus.  This should move input focus to that frame, but it currently
doesn't.  (If the frame has already the focus, pop-to-buffer works as it
should.)

Let's call the display-buffer case, situation A and the pop-to-buffer
case, situation B.

>
> We should fix it this time.  Please try again two things with the
> window-managers you listed above and `pop-up-frames' non-nil:
>
> - tell whether `display-buffer' does switch focus.
>
> - tell whether `pop-to-buffer' does switch focus.
>
> - try both, if possible, with click-to-focus and a focus-follows-mouse
>   settings (maybe you have to set the value of the Emacs variable
>   `focus-follows-mouse' appropriately).

OK, here is what I see:

A  B  WM         WM focus mode
--------------------------------------- 
Y  N  Sawfish    follow-mouse (enter-only + focus-window-when-mapped)
N  N  Sawfish    follow-mouse (enter-only + !focus-window-when-mapped)
Y  N  Sawfish    follow-mouse (enter-exit + focus-window-when-mapped)
N  N  Sawfish    follow-mouse (enter-exit + !focus-window-when-mapped)
Y  N  Sawfish    click-to-focus (click + focus-window-when-mapped)
N  N  Sawfish    click-to-focus (click + !focus-window-when-mapped)
Y  N  Sawfish    click-to-focus (click + focus-window-when-mapped + focus-click-through)
N  N  Sawfish    click-to-focus (click + !focus-window-when-mapped + focus-click-through)
?  N  Metacity   follow-mouse (mouse)
?  N  Metacity   follow-mouse (sloppy)
?  N  Metacity   click-to-focus (click)
Y  N  KWin       follow-mouse
Y  N  KWin       click-to-focus
Y  M  FluxBox    follow-mouse (Sloppy Focus)
Y  M  FluxBox    follow-mouse (Auto Raise)
Y  N  FluxBox    click-to-focus
Y  Y  IceWM      click-to-focus
Y  N  Twm        follow-mouse (new frames need mouse click for placement)

A and B are the scenarios described above.
Y means: Yes, does switch focus.
N means: No, doesn't switch focus.
? means: sometimes (probably depending on mouse and window positions)
M means: No, doesn't switch focus, except when raising the frame 
         also moves the mouse pointer into the frame.

I set Emacs' focus-follows-mouse according to the WM focus mode (except 
when I forgot it :-)

The Ys for Sawfish are apparently directly related to the
focus-window-when-mapped option.  So, it's probably not Emacs that
switches the focus in the A scenario, but the window managers.

>
> Here on Windos XP with a focus-follows-mouse policy, `display-buffer'
> and `pop-to-buffer' both switch focus.  IIRC, people reported troubles
> with the standard click-to-focus policy.  Honestly, I'm a bit reluctant
> to try out click-to-focus here, maybe someone else can try?
>
>> Maybe we could move the input focus to the selected frame in a lazy
>> fashion.  E.g. when Emacs waits for new events, we could compare the
>> currently focused frame with the selected frame, and if they differ we
>> could switch the focus to the selected frame.  This would make
>> select-frame more useful.
>
> I suppose we should introduce a customizable variable which allows to
> call `select-frame-set-input-focus' (or something similar) at least in
> `pop-to-buffer' but maybe also in `display-buffer'.  But we should also
> provide a doc-string recommending what setting this variable should have
> on which platform.

Yes, that would be good.  The docstring for select-window could perhaps
also state a bit more prominently that the "selected window" and the
"input focus" are different things or at least refer to
select-frame-set-input-focus.

BTW, below is a proof of concept implementation for the
update-focus-lazily idea.

Helmut.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: lazy-focus.diff --]
[-- Type: text/x-diff, Size: 836 bytes --]

--- keyboard.c.~1.969.~	2008-08-15 14:47:16.000000000 +0200
+++ keyboard.c	2008-08-23 10:23:12.000000000 +0200
@@ -1602,6 +1602,21 @@ (at your option) any later version.
 	  && !EQ (internal_last_event_frame, selected_frame))
 	Fselect_frame (internal_last_event_frame);
 #endif
+#if 1
+      {
+	if (!detect_input_pending()
+	    && NILP(internal_last_event_frame)) {
+	  Display *dpy = FRAME_X_DISPLAY (check_x_frame(selected_frame));
+	  Window focus;
+	  int revert_to;
+	  XGetInputFocus (dpy, &focus, &revert_to);
+	  if (focus != None
+	      && focus != FRAME_X_WINDOW (check_x_frame(selected_frame)))
+	    Fx_focus_frame (selected_frame);
+	}
+      }
+#endif
+
       /* If it has changed current-menubar from previous value,
 	 really recompute the menubar from the value.  */
       if (! NILP (Vlucid_menu_bar_dirty_flag)

  reply	other threads:[~2008-08-23  8:55 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <48C8C046.50203@gmx.at>
2008-08-20  7:35 ` bug#745: pop-to-buffer, frames, and input focus Helmut Eller
2008-08-20 14:50   ` martin rudalics
2008-08-20 18:42     ` Helmut Eller
2008-08-20 20:42       ` David Reitter
2008-08-20 20:56       ` martin rudalics
2008-08-21  8:07         ` Helmut Eller
2008-08-21  9:04           ` martin rudalics
2008-08-21 13:20             ` Helmut Eller
2008-08-21 20:31               ` martin rudalics
2008-08-22 14:27                 ` Helmut Eller
2008-08-22 16:39                   ` martin rudalics
2008-08-23  8:55                     ` Helmut Eller [this message]
2008-08-23 12:05                       ` martin rudalics
2008-08-24 13:14                         ` Helmut Eller
2008-08-25 13:45                           ` martin rudalics
2008-08-26 21:45                             ` Helmut Eller
2008-08-27  8:12                               ` martin rudalics
2008-08-27 12:54                                 ` Helmut Eller
2008-08-28 11:46                                   ` martin rudalics
2008-08-28 16:47                                     ` Helmut Eller
2008-08-28 21:26                                       ` martin rudalics
2008-08-29  7:39                                         ` Helmut Eller
2008-08-29  9:26                                           ` martin rudalics
2008-08-29 15:02                                             ` Helmut Eller
2008-08-30  8:15                                               ` martin rudalics
2008-08-30 11:06                                                 ` Helmut Eller
2008-08-30 13:42                                                   ` martin rudalics
2008-08-31  8:55                                                     ` Helmut Eller
2008-09-06 11:56                                                       ` martin rudalics
2008-09-09  6:24                                                         ` Helmut Eller
2008-09-11  7:05   ` bug#745: marked as done (pop-to-buffer, frames, and input focus) Emacs bug Tracking System

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2abf4qffb.fsf@gmail.com \
    --to=eller.helmut@gmail.com \
    --cc=745@emacsbugs.donarmstrong.com \
    --cc=rudalics@gmx.at \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).