Subject: bug#745: pop-to-buffer, frames, and input focus

From: martin rudalics <[email-masked]>
Date: Fri, 22 Aug 2008 18:39:20 +0200

>>> 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?

 >>> I still think that display-buffer should neither select the other frame
 >>> nor give it the input focus.  (Whether the other frame should be raised
 >>> or not should probably be customizable, but that's a minor issue.)
 >> I agree with you but I'm afraid there were issues with this.  If you
 >> have some spare time please look at the threads starting with
 >>
 >> http://lists.gnu.org/archive/html/emacs-devel/2006-04/msg00922.html
 >>
 >> http://lists.gnu.org/archive/html/emacs-devel/2005-11/msg00107.html
 >>
 >> http://lists.gnu.org/archive/html/emacs-devel/2008-03/msg00946.html
 >>
 >> respectively.  At the very least you will find out that you're not
 >> alone.
 >
 > Those messages are several years old.  And it looks like nobody is
 > going to fix the issue this time.

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).

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.

martin