Subject: bug#22549: 25.0.50; Tooltips placed outside of screen limits

From: Óscar Fuentes <[email-masked]>
Date: Fri, 05 Feb 2016 23:34:52 +0100

martin rudalics <[email-masked]> writes:

> Please try the attached patch.  Glenn gave a recipe how to emulate
> multiple monitors with a single one but I'm a bit reluctant to test it.
> My display resolution setup is somewhat fragile.

The first problem with the patch is that it crashes when there is not an
Emacs frame on some of the monitors. This is solved changing the `if'
to:

          if (CONSP (frames) && !NILP (XCDR (frames))
              && EQ (frame, XCAR (XCDR (frames))))
	    {

The next problem is that the condition

EQ (frame, XCAR (XCDR (frames)))

is always false, which makes sense because `frame' is the tooltip frame
(unless I'm misunderstanding what XSETFRAME does) and it is not listed
on `frames'.

For going ahead I "corrected" this with

      struct frame *sf = XFRAME (selected_frame);
      XSETFRAME (frame, sf);

which is wrong when there is more than one frame, because the tooltip
may be shown for a frame that is not the selected one (showing tooltips
for other than the selected frame seems inappropriate to me, but that's
how Emacs behaves right now).

Then, as the comparision only takes into account the first frame listed
on `frames', even if `frame' where correct (the frame that triggered the
tooltip) it could fail when there is more than one Emacs frame on the
same monitor.

I observed that the tooltip is correctly placed when the right
conditions (see below) are satisfied.

What is missing is to determine the parent frame of the tooltip frame,
instead of using just the selected one as I did, and to search for that
frame on the list of frames associated to the current monitor, instead
of just testing the first frame on the list.