Subject: bug#15469: 24.3; emacsclient -c fails to grab focus when asking “Revert buffer from file?”

From: Anders Kaseorg <[email-masked]>
Date: Thu, 26 Sep 2013 20:01:15 -0400

When using Emacs in server mode and ‘emacsclient -c’ as my preferred 
editor, new windows opened by emacsclient often fail to grab keyboard 
focus, correlated with Emacs asking minibuffer questions like “Revert 
buffer from file?” as the file is opened (e.g. on .git/COMMIT_EDITMSG 
which is frequently modified both inside and outside Emacs).  I can 
reproduce this reliably as follows:

1. emacs -Q /tmp/foo
2. M-x server-start
3. Type some text into the buffer; do not save.
4. Click outside the Emacs window to unfocus it.
5. Click inside the Emacs window to focus it.
6. Click outside the Emacs window to unfocus it.
7. Modify /tmp/foo outside Emacs.
8. emacsclient -c /tmp/foo
9. An _unfocused_ Emacs window pops up to ask “Revert buffer from file 
/tmp/foo?”.

(If I skip step 5, or if I replace step 5 with clicking on the _title 
bar_ of the first Emacs window to focus it, then the new window has no 
trouble grabbing focus; I can only reproduce when clicking _inside_ the 
Emacs window to focus it.)

My window manager, if it matters, is gnome-shell 3.8.4-0ubuntu5.

In GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.8.2)
  of 2013-07-26 on roseapple, modified by Debian
Windowing system distributor `The X.Org Foundation', version 11.0.11402901
System Description:	Ubuntu Saucy Salamander (development branch)

Configured using:
  `configure '--build' 'x86_64-linux-gnu' '--build' 'x86_64-linux-gnu'
  '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib'
  '--localstatedir=/var/lib' '--infodir=/usr/share/info'
  '--mandir=/usr/share/man' '--with-pop=yes'
 
'--enable-locallisppath=/etc/emacs24:/etc/emacs:/usr/local/share/emacs/24.3/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/24.3/site-lisp:/usr/share/emacs/site-lisp'
  '--with-crt-dir=/usr/lib/x86_64-linux-gnu' '--with-x=yes'
  '--with-x-toolkit=gtk3' '--with-toolkit-scroll-bars'
  'build_alias=x86_64-linux-gnu' 'CFLAGS=-g -O2 -fstack-protector
  --param=ssp-buffer-size=4 -Wformat -Werror=format-security -Wall'
  'LDFLAGS=-Wl,-Bsymbolic-functions -Wl,-z,relro'
  'CPPFLAGS=-D_FORTIFY_SOURCE=2''

Important settings:
   value of $LC_MONETARY: en_US.UTF-8
   value of $LC_NUMERIC: en_US.UTF-8
   value of $LC_TIME: en_US.UTF-8
   value of $LANG: en_US.UTF-8
   value of $XMODIFIERS: @im=none
   locale-coding-system: utf-8-unix
   default enable-multibyte-characters: t

Major mode: Fundamental

Minor modes in effect:
   tooltip-mode: t
   mouse-wheel-mode: t
   tool-bar-mode: t
   menu-bar-mode: t
   file-name-shadow-mode: t
   global-font-lock-mode: t
   font-lock-mode: t
   blink-cursor-mode: t
   auto-composition-mode: t
   auto-encryption-mode: t
   auto-compression-mode: t
   line-number-mode: t
   transient-mark-mode: t

Recent input:
M-x s e r v e r - s t a r t <return> f o o <return>=20
<down-mouse-1> <mouse-1> <help-echo> <down-mouse-1>=20
<mouse-movement> <mouse-1> n o <return> M-x r e p o=20
r t - e m a c s - b u g <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
(New file)
When done with a buffer, type C-x #

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util mail-prsvr mail-utils server time-date tooltip ediff-hook
vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar dnd fontset image
regexp-opt fringe tabulated-list newcomment lisp-mode register page
menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock font-lock
syntax facemenu font-core frame cham georgian utf-8-lang misc-lang
vietnamese tibetan thai tai-viet lao korean japanese hebrew greek
romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face macroexp files text-properties overlay sha1 md5
base64 format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process dbusbind dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty emacs)