return lisp_focus;
}
+/* Return the toplevel parent of F, if it is a child frame.
+ Otherwise, return NULL. */
+
+static struct frame *
+x_get_toplevel_parent (struct frame *f)
+{
+ struct frame *parent;
+
+ if (!FRAME_PARENT_FRAME (f))
+ return NULL;
+
+ parent = FRAME_PARENT_FRAME (f);
+
+ while (FRAME_PARENT_FRAME (parent))
+ parent = FRAME_PARENT_FRAME (parent);
+
+ return parent;
+}
+
/* In certain situations, when the window manager follows a
click-to-focus policy, there seems to be no way around calling
XSetInputFocus to give another frame the input focus.
else
{
if (!noactivate
+ /* If F is a child frame, use SetInputFocus instead. This
+ may not work if its parent is not activated. */
+ && !FRAME_PARENT_FRAME (f)
+ /* If the focus is being transferred from a child frame to
+ its toplevel parent, also use SetInputFocus. */
+ && (!dpyinfo->x_focus_frame
+ || (x_get_toplevel_parent (dpyinfo->x_focus_frame)
+ != f))
&& x_wm_supports (f, dpyinfo->Xatom_net_active_window))
{
/* When window manager activation is possible, use it