Subject: Re: bug#23568: 25.0.94; Mode line menus appear incorrectly in some monitor configurations

From: Alex <[email-masked]>
Date: Fri, 02 Jun 2017 01:18:46 -0600

martin rudalics <[email-masked]> writes:

>> I just noticed that frame.el also includes frame-monitor-attributes,
>> which also makes me think that frame.el is a nice place for these
>> procedures.
>
> For the moment putting them in frame.el should be OK.  Eventually these
> functions should be in frame.c and represent stripped down versions of
> ‘display-monitor-attributes-list’ where only the dominating monitor for
> the given frame or coordinates is investigated.  Other monitors and
> things like lists of frames dominated by a monitor, mm values, name and
> source would not be calculated by the respective backends.  These values
> are not needed for checking tip frame or menu positions and repeatedly
> evaluating and returning the same values seems rather silly.

I agree that you shouldn't have to calculate everything each time,
though I don't know enough about the C code to achieve that right now.

In the end, we would still leave the function interface so that users
can still call the discussed procedures from lisp code, right? I don't
want to introduce an interface just for it to be removed later on if I
can avoid it.

In any case, I altered display-monitor-attribute to use
frame-monitor-attributes and to not succeed on {x, y} = max-{x, y}:

(defun display-monitor-attribute (attribute &optional frame x y)
  "Return the value of the attribute of the 'current' monitor.
By default, use the frame info to determine the current monitor,
but if x and y are non-nil then use the given coordinates to
determine it."
  (if (and x y)
      (cl-loop for monitor in (display-monitor-attributes-list)
               for geometry = (alist-get 'geometry monitor)
               for min-x = (pop geometry)
               for min-y = (pop geometry)
               for max-x = (+ min-x (pop geometry))
               for max-y = (+ min-y (car geometry))
               when (and (<= min-x x)
                         (< x max-x)
                         (<= min-y y)
                         (< y max-y))
               return (alist-get attribute monitor))
    (alist-get attribute (frame-monitor-attributes frame))))