Subject: emacs not responding to keyboard events

From: Mohammad Toossi <[email-masked]>
Date: Sat, 28 Nov 2015 00:02:04 -0800

I am most likely affected by the same issue: when emacs is launched to
compose a git commit message, it sometimes ignores all keyboard input, but
mouse input works normally.  I am using Emacs 24.5.1, Ubuntu 14.04, and I3
WM.

Even more surprisingly, emacs responds to X KeyPress events sent to it
through "xdotool", but not through the real keyboard.  Also, "xev"
indicates that emacs is receiving all KeyPress events and just dropping
them internally.

After spending some time attaching GDB and stepping through code, I have
found that x_filter_event() is the point in which the KeyPress event gets
dropped.  In a good emacs instance, event_handler_gtk receives the event
and passes it on to handle_one_xevent.  In a bad instance,
event_handler_gdk still receives the event but never passes any KeyPress
event to handle_one_xevent.  In bad instances, x_filter_event always
returns true for real key presses, but returns false for fake key presses
from xdotool.

My best guess at this point is that the issue is something along the lines
of [1].  Slowing down the system increases the likelihood of this race
condition(?) happening.

To take it even further, I used xscope to intercept the emacs messages
to/from X, and put a breakpoint on SYNC-Request messages.  Stepping through
the subsequent X messages one by one triggered the bug (1 out of 1 times)
further suggesting that this is a timing issue.

I'm skipping a lot of detail here in order to keep this short.  Feel free
to ask me for more specifics.

[1] XIM SYNC_REPLY not sent when switching input contexts <
https://bugs.freedesktop.org/show_bug.cgi?id=7869>
[2] http://ftp.x.org/pub/individual/app/xscope-1.4.1.tar.gz