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

From: Helmut Eller <[email-masked]>
Date: Sat, 30 Aug 2008 13:06:36 +0200

* martin rudalics [2008-08-30 10:15+0200] writes:

>>>> I also found the gtk_window_set_focus_on_map function.  This seems to
>>>> rely on the _NET_WM_USER_TIME EWMH.  Sawfish ignores _NET_WM_USER_TIME,
>>>> but it could be useful for other window managers.
>
> How do you find out that Sawfish ignores that?

a) by looking at the _NET_SUPPORTS property on the root window.  I posted
the content of that in my last email.  It doesn't contain
_NET_WM_USER_TIME.
b) by grepping through Sawfish's source code.

>> For a window manager which supports it, _NET_SUPPORTED will contain
>> _NET_WM_USER_TIME.  But it wouldn't hurt to set _NET_WM_USER_TIME to 0,
>> because that should be interpreted as "disable focus-on-map".  At least
>> gtk_window_set_focus_on_map sets the property unconditionally.
>
> Do you have one window-manager setting where you can get Emacs
>
> (1) do a `display-buffer' making a new frame without that frame getting
> raised and/or input focus, and

If I call gtk_window_set_focus_on_map (GTK_WINDOW (wtop), FALSE) in
gtkutil.c:xg_create_frame_widgets, then Metacity dosn't give the focus
to new frames.  The initial Emacs frame is also not focused.

gtk_window_set_focus_on_map sets _NET_WM_USER_TIME to 0.  I know that
because I read the GTK source.  It can be verified by calling xprop on
the resulting Emacs frame.

> (2) give input focus to/raise a frame that hasn't input focus/is not
> raised.
>
> entirely using _NET_WM_USER_TIME?

I don't know how to that with _NET_WM_USER_TIME.  But the EWMH-spec says
this:

   _NET_ACTIVE_WINDOW, WINDOW/32
   
   The window ID of the currently active window or None if no window has
   the focus. This is a read-only property set by the Window Manager. If
   a Client wants to activate another window, it MUST send a
   _NET_ACTIVE_WINDOW client message to the root window:

   _NET_ACTIVE_WINDOW
     window  = window to activate
     message_type = _NET_ACTIVE_WINDOW
     format = 32
     data.l[0] = source indication 
     data.l[1] = timestamp
     data.l[2] = requestor's currently active window, 0 if none
     other data.l[] elements = 0
   
   Source indication should be 1 when the request comes from an
   application, and 2 when it comes from a pager. Clients using older
   version of this spec use 0 as source indication, see the section called
   "Source indication in request" for details. The timestamp is Client's
   last user activity timestamp (see _NET_WM_USER_TIME) at the time of the
   request, and the currently active window is the Client's active toplevel
   window, if any (the Window Manager may be e.g. more likely to obey the
   request if it will mean transferring focus from one active window to
   another).
   
   Depending on the information provided with the message, the Window
   Manager may decide to refuse the request (either completely ignore it,
   or e.g. use _NET_WM_STATE_DEMANDS_ATTENTION).

The current implementation of x_ewmh_activate_frame seems to work fine.

> I faintly recall a discussion about a
> misinterpretation of timestamps sent to the window-manager (Metacity?)
> by Emacs.

I've seen Metacity spit out warnings along the lines that XSetInputFocus
was called with a wrong timestamp.  But I can't reproduce that right now.

Helmut.