Subject: Re: bug#57012: Activating versus raising frames

From: Po Lu <[email-masked]>
Date: Sun, 07 Aug 2022 09:55:24 +0800

Daniel Colascione <[email-masked]> writes:

> Hoo boy. I spent a bit of time digging into the event code. The root
> cause of the inability of emacsclient to raise the frame is that
> we've been getting X11 event timestamps wrong for some time. In
> particular, 1) in GTK builds, we're not updating the X timestamps for
> keyboard and mouse input events

The reason for that is because GTK is supposed to do that itself, after
the event ends up dispatched to GDK.  I will investigate this further.

> , and 2) we're not updating the X timestamp when we get an emacsclient
> request.  Because of #2, when we call x-focus-window in
> select-frame-set-input-focus, the timestamp we send along with the
> _NET_ACTIVE_WINDOW request is stale, causing some window managers
> (e.g. cinnamon and kwin) to just ignore the _NET_ACTIVE_WINDOW. But
> because we use _NET_ACTIVE_WINDOW *and* XSetInputFocus and the latter
> works, the overall effect is that the call to
> select-frame-set-input-focus in server.el focuses the Emacs window,
> but doesn't raise it.

That sounds likely to me, thanks for investigating.

> The following patch should fix both problems:

Right, but I saw a similar problem in the DND code, so I'd prefer you
modified `x-display-set-last-user-time' instead.  I think adding a
separate FRAME argument to that function would be in order.  Aside from
that, this is too X-specific to warrant a terminal hook.

The rest of the code is fine by me (tho there is a
dpyinfo->server_time_monotonic_p flag that can be used to avoid a sync
with the X server when trying to obtain the server time), but needs
coding style fixes.  I'm sure you already know how to do that.