[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: closing emacsclient always focuses another emacs window

From: Michael Heerdegen
Subject: Re: closing emacsclient always focuses another emacs window
Date: Mon, 10 Mar 2014 23:11:20 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Eli Zaretskii <address@hidden> writes:

> Also, selecting a frame doesn't mean that frame gets focus, even for
> GUI frames.  There's always a selected frame in Emacs, but focus might
> well belong to another application, so we could have a situation where
> none of the Emacs frames has focus.

I know that.  But in the problematic case, after the xterm has got
focus, `server-switch-buffer' explicitly sets focus back to the
selected frame:

(when server-raise-frame
      (select-frame-set-input-focus (window-frame)))

I have a recipe that reproduces the problem in 100% of the cases,
and I'm sure that the window manager isn't involved:

1. start xterm
2. emacs -Q
3. M-x server-start
4. Focus the xterm
5. emacsclient -c /path/to/file1 &
   A new emacs frame pops up and has focus
6. close the _other_ Emacs frame (the one showing the *scratch* buffer)
7. Focus the xterm
8. emacsclient -c /path/to/file2 &
   A new emacs frame pops up, showing file2, and has focus.
9. in this frame: C-x #

Now, the other Emacs frame has focus, not the xterm.

It would be very interesting if you could not reproduce this.  It is
IMHO inevitable when I look at the code.

Eli, if you really don't see this behavior, please try to find out which
of the following is not true for you, after hitting C-x # in 9.  These
steps _prove_ that what the OP sees will happen with the above recipe:

- `server-edit' evaluates (apply 'server-switch-buffer (server-done))
  because `server-clients is non-nil

- (server-done) is evaluated.  It deletes the current frame.  xterm gets
  focus.  `server-done' returns a list whose car is nil.  The
  `selected-frame' is now the one showing file1 (it's the only frame
  left), but it doesn't have focus.  But, of course, Emacs continues

- `server-switch-buffer' is applied to the result of (server-done).  It
  evaluates this:

if (null next-buffer)
        (let ((rest server-clients))
          (while (and rest (not next-buffer))
            (let ((proc (car rest)))
              ;; Only look at frameless clients, or those in the selected
              ;; frame.
              (when (or (not (process-get proc 'frame))
                        (eq (process-get proc 'frame) (selected-frame)))
                (setq next-buffer (car (process-get proc 'buffers))))
              (setq rest (cdr rest)))))
        (and next-buffer (server-switch-buffer next-buffer killed-one))

next-buffer is set to the buffer associated with file1, and
`server-switch-buffer' is called recursively.

- At the end of the recursive `server-switch-buffer' call, this is

(when server-raise-frame
      (select-frame-set-input-focus (window-frame)))

which sets input focus to the Emacs frame.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]